1.1.2 • Published 2 years ago

date-plus v1.1.2

Weekly downloads
53
License
MIT
Repository
github
Last release
2 years ago

date-plus

CI

Javascript dates extended with dateformat

  • Tiny wrapper function to create dates
  • returns normal Date objects extended with .format()
  • uses the built-in date parser, fixes a parser annoyance in ES5
  • unlike dateformat, format() doesn't throw if the date is invalid
  • choice of language strings - currently de and en are included

installation

$ npm install date-plus

usage

var date = require('date-plus');

// parse using native javascript parser
var d = date('5/10/2015');

// format
var output = d.format('ddd, dd mmm yyyy HH:MM:ss Z');

// or use a predefined mask
var output = d.format('expiresHeaderFormat');

// shortcut for date(d).format(fmt) - 2nd arg format string
var output = date(d, fmt);

// non-truthy input means current date/time
var now = date('');

var d = date('inva/lid/date');
var isValid = d.valid;          // false
var output = d.format();        // 'No Date'

// set language to german
date.lang('de');

// access dateformat masks
date.dateformat.masks.shortDate = ('yyyy.mm.dd');

format patterns

patterninterpretation
dday
ddday with leading 0
dddday of week abbreviated
ddddday of week full
mmonth
mmmonth with leading 0
mmmmonth abbreviated
mmmmmonth full
yyyear 2 digit
yyyyyear 4 digit
hhours (12)
hhhours (12) with leading 0
Hhours (24)
HHhours (24) with leading 0
Mminutes
MMminutes with leading 0
sseconds
ssseconds with leading 0
lmilliseconds 3 digits
Lmilliseconds 2 digits
ta or p for am or pm
ttam or pm
TA or P for am or pm
TTAM or PM
ZUS timezone or GMT-????
oUTC offset e.g. +1000 or -0230
Sday suffix e.g. 'nd' for 2
Wweek in year
Nday in week
UTC:fmtrender UTC instead of local

format masks

mask nameinterpretation
defaultddd mmm dd yyyy HH:MM:ss
shortDatem/d/yy
mediumDatemmm d, yyyy
longDatemmmm d, yyyy
fullDatedddd, mmmm d, yyyy
shortTimeh:MM TT
mediumTimeh:MM:ss TT
longTimeh:MM:ss TT Z
isoDateyyyy-mm-dd
isoTimeHH:MM:ss
isoDateTimeyyyy-mm-dd'T'HH:MM:sso
isoUtcDateTimeUTC:yyyy-mm-dd'T'HH:MM:ss'Z'
expiresHeaderFormatddd, dd mmm yyyy HH:MM:ss Z

parsing yyyy-mm-dd

ES5 interprets strings matching yyyy-mm-dd as UTC even when running in other timezones.

E.g. 2015-9-15 is assumed to be midnight on that date in the local timezone

But 2015-10-15 is interpreted as midnight on that date in the UTC timezone because the date uses an ISO format and has a 2-digit month. This is problematic e.g. for code parsing unpadded dates passed via JSON.

This module provides a small polyfill to parse yyyy-mm-dd dates as local even in ES5.

credits

1.1.2

2 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.10

4 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

6 years ago

1.0.1

9 years ago

1.0.0

9 years ago

0.6.3

9 years ago

0.6.2

9 years ago

0.6.1

9 years ago

0.6.0

9 years ago

0.5.3

9 years ago

0.5.2

9 years ago

0.5.1

9 years ago

0.5.0

9 years ago