@vizia/humanize-date-range

1.1.0 • Public • Published

Humanize Date-range

Humanises a query's date range; to be used when displaying the date query from a component's config. Uses @vizia/date-ranges and Luxon for calculations.

Usage

const humanizeDateRange = require('@vizia/humanize-date-range');

// Fixed date-range
const label = humanizeDateRange({
    startDate: '2019-01-01T00:00:00.000+00:00',
    endDate: '2020-01-01T00:00:00.000+00:00',
    timezone: 'Etc/UTC',
    locale: 'en-US'
});
// Output: 'Jan 1 – Dec 31'

// Rolling date duration
const label = humanizeDateRange({
    dateDuration: 'P1D',
    timezone: 'Etc/UTC',
    locale: 'en-US'
});
// Output: 'Today'

Options

Uses standard options from @vizia/date-ranges.

Tests

Tests use a locale of en-US, because Node does not currently provide all the locale fixtures in the Intl API. This is not an issue for the browser.

Build

An AMD build is generated on prepublishOnly, to use with RequireJS within Bootstrap. This can be removed when Bootstrap is sunset.

/@vizia/humanize-date-range/

    Package Sidebar

    Install

    npm i @vizia/humanize-date-range

    Weekly Downloads

    4

    Version

    1.1.0

    License

    none

    Unpacked Size

    165 kB

    Total Files

    13

    Last publish

    Collaborators

    • brandwatch
    • lcapel
    • chrisn
    • antibaconmachine
    • vizia-bot
    • jdelight
    • dog-house
    • benbrandwood
    • satvinder-hullait
    • dave73