bright-dates

1.4.0 • Public • Published

BrightDates

Timezone aware date parsing and formatting

Test Bench

There is a live demo on CodePen which you can fiddle with. Once the CodePen page loads, open browser's development console and follow the instructions.

Methods

All date and datetime methods accept an optional timezone overide as the last argument

brightDates.setTimezone(tz)

Set the default timezone

brightDates.setTimezone('Canada/Eastern');

brightDates.getTimezone

Get the set timezone

brightDates.getTimezone(); // Europe/London
brightDates.setTimezone('Canada/Eastern');
brightDates.getTimezone(); // Canada/Eastern

brightDates.date(date, timezone)

Convert a string or native date into a timezone aware date moment

brightDates.date(new Date(2016, 11, 13, 21, 4, 3)); // 2016-10-13T00:00:00Z (moment)
 
brightDates.date('2017-10-13'); // 2016-10-13T00:00:00Z (moment)

brightDates.dateTime(dateTimeInput, timezone)

Convert a string or native date into a timezone aware datetime moment

brightDates.dateTime(new Date(2016, 11, 13, 21, 4, 3)); // 2016-10-13T21:04:03Z (moment)
 
brightDates.dateTime('2017-10-13T21:04:03Z'); // 2016-10-13T21:04:03Z (moment)

brightDates.dateAndTime(dateInput, timeInput, timezone = userTimezone)

Convert individual date and time elements to a datetime moment

brightDates.dateAndTime(new Date(2016, 11, 13, 21, 4, 3), '01:43'); // 2016-10-13T01:43:00Z (moment)
 
brightDates.dateAndTime('2017-10-13', '01:43'); // 2016-10-13T01:43:00Z (moment)

brightDates.today

Get a moment of today

brightDates.today();

brightDates.formatDate(date, format)

Format a string or native date, returns ISO 8601 if no format is specified.

  • short: 'DD/MM/YYYY'
  • friendly: 'ddd Do MMM YYYY'
  • friendlyShort: 'ddd Do MMM'
  • timezone: 'zz'
  • offset: 'Z'
brightDates.formatDate('2016-10-13T01:43:00Z', 'short'); // 13/10/2016

brightDates.formatDateTime

Format a string or native date, returns ISO 8601 if no format is specified.

  • short: 'YYYY-MM-DD'
  • friendly: 'dddd Do MMM YYYY'
  • friendlyShort: 'ddd Do MMM'
  • time: 'hh:mm'
  • timezone: 'zz'
  • offset: 'Z'
  • datetime: 'YYYY-MM-DD hh:mm'
brightDates.formatDateTime('2016-10-13T01:43:00Z', 'time'); // 01:43

moment static methods

The following static methods from moment are also exported:

Readme

Keywords

none

Package Sidebar

Install

npm i bright-dates

Weekly Downloads

149

Version

1.4.0

License

ISC

Unpacked Size

43.1 kB

Total Files

23

Last publish

Collaborators

  • bright.hr