1.4.0 • Published 5 years ago

bright-dates v1.4.0

Weekly downloads
164
License
ISC
Repository
github
Last release
5 years ago

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:

1.4.0

5 years ago

1.3.1

5 years ago

1.3.0

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.0.0

6 years ago