0.1.0 • Published 7 years ago

intl-dt v0.1.0

Weekly downloads
7
License
MIT
Repository
github
Last release
7 years ago

intl-dt build status Coverage Status

Light date time library based on the ECMA-402 Internationalization API. It allows to use localized date time formats without the need to import a language package.

Installation

npm install --save intl-dt

Usage

const intlDT = require('intl-dt');

const date = new Date(2010, 0, 9, 8, 7, 6);
intlDT.format(date, 'dddd, D. MMMM YYYY HH:mm:ss', 'en');
// Saturday, 9. January 2010 08:07:06
intlDT.format(date, 'dddd, D. MMMM YYYY HH:mm:ss', 'de');
// Samstag, 9. Januar 2010 08:07:06

intlDT.months('en')[0]
// January
intlDT.months('de')[0]
// Januar

intlDT.days('en')[0]
// Monday
intlDT.days('de')[0]
// Montag

API

intlDT.format

Uses a given date and transformes it by a given template into a localized string.

intlDT.format(date, template[, locales])
intlDT([date[, locales]]).format(template[, locales])
intlDT([locales]).format(date, template[, locales])

intlDT.months

Returns a localized array of all months.

intlDT.months([locales, [type]])
intlDT([locales]).months([type])
intlDT([date[, locales]]).months([type])

intlDT.days

Returns a localized array of all days of the week.

intlDT.days([locales, [type]])
intlDT([locales]).days([type])
intlDT([date[, locales]]).days([type])

Parameters

date: Date

A valid JavaScript date object.

locales: String

A valid locales argument.

Locales are always optional. If not provided the system default local is used.

At the moment only strings are supported.

template: String

A template string defining a template a date may be formated into. The following table defines the valid template tags.

InputExampleDescription
YY16Last two digits of a year
YYYY or Y2016Full digits of a year
M2, 12Month as digits
MM02, 12Month as digits with leading zero
MMMJanMonth as word in short form
MMMMJanuaryMonth as word in long form
Q4Number of quarter
D1, 28Day of month as digits
DD01, 28Day of month as digits with leading zero
dddMonDay of week as word in short form
ddddMondayDay of week as word in long form
H6, 112 hour time
HH06, 0112 hour time with leading zero
h6, 1324 hour time
hh06, 1324 hour time with leading zero
a or Aam, pmAnte or post meridiem
m6, 56Minutes
mm06, 56Minutes with leading zero
s6, 56Seconds
ss06, 56Seconds with leading zero

type: String

Defines the type of the return value. Default value is long.

Valid types are

  • long converts to tag MMMM
  • short converts to tag MMM

License

Licensed under the MIT License.