1.1.0 • Published 3 years ago

@vizia/humanize-date-range v1.1.0

Weekly downloads
-
License
-
Repository
github
Last release
3 years ago

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.