Socket
Socket
Sign inDemoInstall

date-and-time

Package Overview
Dependencies
Maintainers
1
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

date-and-time - npm Package Compare versions

Comparing version 2.1.2 to 2.2.0

9

date-and-time.js

@@ -51,2 +51,7 @@ (function (global, factory) {

},
ZZ: function (d/*, formatString*/) {
var offset = d.getTimezoneOffset();
var mod = Math.abs(offset);
return (offset > 0 ? '-' : '+') + ('0' + (mod / 60 | 0)).slice(-2) + ':' + ('0' + mod % 60).slice(-2);
},
post: function (str) { return str; },

@@ -97,2 +102,6 @@ res: _res

},
ZZ: function (str/*, formatString */) {
var arr = /^([\+-])(\d{2}):([0-5]\d)/.exec(str) || ['', '', '', ''];
return { value: 0 - ((arr[1] + arr[2] | 0) * 60 + (arr[1] + arr[3] | 0)), length: arr[0].length };
},
h12: function (h, a) { return (h === 12 ? 0 : h) + a * 12; },

@@ -99,0 +108,0 @@ exec: function (re, str) {

21

date-and-time.min.js

@@ -7,11 +7,12 @@ /*

D:function(a){return""+a.getDate()},HH:function(a){return("0"+a.getHours()).slice(-2)},H:function(a){return""+a.getHours()},A:function(a){return this.res.A[11<a.getHours()|0]},hh:function(a){return("0"+(a.getHours()%12||12)).slice(-2)},h:function(a){return""+(a.getHours()%12||12)},mm:function(a){return("0"+a.getMinutes()).slice(-2)},m:function(a){return""+a.getMinutes()},ss:function(a){return("0"+a.getSeconds()).slice(-2)},s:function(a){return""+a.getSeconds()},SSS:function(a){return("00"+a.getMilliseconds()).slice(-3)},
SS:function(a){return("0"+(a.getMilliseconds()/10|0)).slice(-2)},S:function(a){return""+(a.getMilliseconds()/100|0)},dddd:function(a){return this.res.dddd[a.getDay()]},ddd:function(a){return this.res.ddd[a.getDay()]},dd:function(a){return this.res.dd[a.getDay()]},Z:function(a){a=a.getTimezoneOffset()/.6|0;return(0<a?"-":"+")+("000"+Math.abs(a-(a%100*.4|0))).slice(-4)},post:function(a){return a},res:t},x={YYYY:function(a){return this.exec(/^\d{4}/,a)},Y:function(a){return this.exec(/^\d{1,4}/,a)},
MMMM:function(a){a=this.find(this.res.MMMM,a);a.value++;return a},MMM:function(a){a=this.find(this.res.MMM,a);a.value++;return a},MM:function(a){return this.exec(/^\d\d/,a)},M:function(a){return this.exec(/^\d\d?/,a)},DD:function(a){return this.exec(/^\d\d/,a)},D:function(a){return this.exec(/^\d\d?/,a)},HH:function(a){return this.exec(/^\d\d/,a)},H:function(a){return this.exec(/^\d\d?/,a)},A:function(a){return this.find(this.res.A,a)},hh:function(a){return this.exec(/^\d\d/,a)},h:function(a){return this.exec(/^\d\d?/,
a)},mm:function(a){return this.exec(/^\d\d/,a)},m:function(a){return this.exec(/^\d\d?/,a)},ss:function(a){return this.exec(/^\d\d/,a)},s:function(a){return this.exec(/^\d\d?/,a)},SSS:function(a){return this.exec(/^\d{1,3}/,a)},SS:function(a){a=this.exec(/^\d\d?/,a);a.value*=10;return a},S:function(a){a=this.exec(/^\d/,a);a.value*=100;return a},Z:function(a){a=this.exec(/^[\+-]\d{2}[0-5]\d/,a);a.value=-60*(a.value/100|0)-a.value%100;return a},h12:function(a,b){return(12===a?0:a)+12*b},exec:function(a,
b){a=(a.exec(b)||[""])[0];return{value:a|0,length:a.length}},find:function(a,b){for(var c=-1,d=0,h=0,g=a.length,l;h<g;h++)l=a[h],!b.indexOf(l)&&l.length>d&&(c=h,d=l.length);return{value:c,length:d}},pre:function(a){return a},res:t},n=function(a,b,c,d){var h={},g;for(g in a)h[g]=a[g];for(g in b||{})!!c^!!h[g]||(h[g]=b[g]);d&&(h.res=d);return h},f={_formatter:w,_parser:x};f.compile=function(a){for(var b=/\[([^\[\]]|\[[^\[\]]*])*]|([A-Za-z])\2+|\.{3}|./g,c,d=[a];c=b.exec(a);)d[d.length]=c[0];return d};
f.format=function(a,b,c){var d=this||e;b="string"===typeof b?d.compile(b):b;var h=a.getTimezoneOffset();a=d.addMinutes(a,c?h:0);d=d._formatter;var g="";a.getTimezoneOffset=function(){return c?0:h};for(var l=1,u=b.length,k;l<u;l++)k=b[l],g+=d[k]?d.post(d[k](a,b[0])):k.replace(/\[(.*)]/,"$1");return g};f.preparse=function(a,b){var c=this||e;b="string"===typeof b?c.compile(b):b;var d={Y:1970,M:1,D:1,H:0,A:0,h:0,m:0,s:0,S:0,Z:0,_index:0,_length:0,_match:0},h=/\[(.*)]/;c=c._parser;var g=0;a=c.pre(a);for(var l=
1,u=b.length,k,q;l<u;l++)if(k=b[l],c[k]){q=c[k](a.slice(g),b[0]);if(!q.length)break;g+=q.length;d[q.token||k.charAt(0)]=q.value;d._match++}else if(k===a.charAt(g)||" "===k)g++;else if(h.test(k)&&!a.slice(g).indexOf(h.exec(k)[1]))g+=k.length-2;else{"..."===k&&(g=a.length);break}d.H=d.H||c.h12(d.h,d.A);d._index=g;d._length=a.length;return d};f.parse=function(a,b,c){var d=this||e;a=d.preparse(a,b);return d.isValid(a)?(a.M-=100>a.Y?22801:1,c||a.Z?new Date(Date.UTC(a.Y,a.M,a.D,a.H,a.m+a.Z,a.s,a.S)):new Date(a.Y,
a.M,a.D,a.H,a.m,a.s,a.S)):new Date(NaN)};f.isValid=function(a,b){var c=this||e;a="string"===typeof a?c.preparse(a,b):a;c=[31,28+c.isLeapYear(a.Y)|0,31,30,31,30,31,31,30,31,30,31][a.M-1];return!(1>a._index||1>a._length||a._index-a._length||1>a._match||1>a.Y||9999<a.Y||1>a.M||12<a.M||1>a.D||a.D>c||0>a.H||23<a.H||0>a.m||59<a.m||0>a.s||59<a.s||0>a.S||999<a.S||-840>a.Z||720<a.Z)};f.transform=function(a,b,c,d){let h=this||e;return h.format(h.parse(a,b),c,d)};f.addYears=function(a,b){return(this||e).addMonths(a,
12*b)};f.addMonths=function(a,b){a=new Date(a.getTime());a.setMonth(a.getMonth()+b);return a};f.addDays=function(a,b){a=new Date(a.getTime());a.setDate(a.getDate()+b);return a};f.addHours=function(a,b){return(this||e).addMinutes(a,60*b)};f.addMinutes=function(a,b){return(this||e).addSeconds(a,60*b)};f.addSeconds=function(a,b){return(this||e).addMilliseconds(a,1E3*b)};f.addMilliseconds=function(a,b){return new Date(a.getTime()+b)};f.subtract=function(a,b){var c=a.getTime()-b.getTime();return{toMilliseconds:function(){return c},
toSeconds:function(){return c/1E3},toMinutes:function(){return c/6E4},toHours:function(){return c/36E5},toDays:function(){return c/864E5}}};f.isLeapYear=function(a){return!(a%4)&&!!(a%100)||!(a%400)};f.isSameDay=function(a,b){return a.toDateString()===b.toDateString()};f.locale=function(a,b){p[a]||(p[a]=b)};f.plugin=function(a,b){m[a]||(m[a]=b)};var v=n(f);var e=n(f);e.locale=function(a){a="function"===typeof a?a:e.locale[a];if(!a)return r;r=a(f);var b=p[r]||{},c=n(t,b.res,!0);a=n(w,b.formatter,!0,
c);b=n(x,b.parser,!0,c);e._formatter=v._formatter=a;e._parser=v._parser=b;for(var d in m)e.extend(m[d]);return r};e.extend=function(a){var b=n(e._parser.res,a.res),c=a.extender||{};e._formatter=n(e._formatter,a.formatter,!1,b);e._parser=n(e._parser,a.parser,!1,b);for(var d in c)e[d]||(e[d]=c[d])};e.plugin=function(a){(a="function"===typeof a?a:e.plugin[a])&&e.extend(m[a(f,v)]||{})};return e})
SS:function(a){return("0"+(a.getMilliseconds()/10|0)).slice(-2)},S:function(a){return""+(a.getMilliseconds()/100|0)},dddd:function(a){return this.res.dddd[a.getDay()]},ddd:function(a){return this.res.ddd[a.getDay()]},dd:function(a){return this.res.dd[a.getDay()]},Z:function(a){a=a.getTimezoneOffset()/.6|0;return(0<a?"-":"+")+("000"+Math.abs(a-(a%100*.4|0))).slice(-4)},ZZ:function(a){a=a.getTimezoneOffset();var b=Math.abs(a);return(0<a?"-":"+")+("0"+(b/60|0)).slice(-2)+":"+("0"+b%60).slice(-2)},post:function(a){return a},
res:t},x={YYYY:function(a){return this.exec(/^\d{4}/,a)},Y:function(a){return this.exec(/^\d{1,4}/,a)},MMMM:function(a){a=this.find(this.res.MMMM,a);a.value++;return a},MMM:function(a){a=this.find(this.res.MMM,a);a.value++;return a},MM:function(a){return this.exec(/^\d\d/,a)},M:function(a){return this.exec(/^\d\d?/,a)},DD:function(a){return this.exec(/^\d\d/,a)},D:function(a){return this.exec(/^\d\d?/,a)},HH:function(a){return this.exec(/^\d\d/,a)},H:function(a){return this.exec(/^\d\d?/,a)},A:function(a){return this.find(this.res.A,
a)},hh:function(a){return this.exec(/^\d\d/,a)},h:function(a){return this.exec(/^\d\d?/,a)},mm:function(a){return this.exec(/^\d\d/,a)},m:function(a){return this.exec(/^\d\d?/,a)},ss:function(a){return this.exec(/^\d\d/,a)},s:function(a){return this.exec(/^\d\d?/,a)},SSS:function(a){return this.exec(/^\d{1,3}/,a)},SS:function(a){a=this.exec(/^\d\d?/,a);a.value*=10;return a},S:function(a){a=this.exec(/^\d/,a);a.value*=100;return a},Z:function(a){a=this.exec(/^[\+-]\d{2}[0-5]\d/,a);a.value=-60*(a.value/
100|0)-a.value%100;return a},ZZ:function(a){a=/^([\+-])(\d{2}):([0-5]\d)/.exec(a)||["","","",""];return{value:-(60*(a[1]+a[2]|0)+(a[1]+a[3]|0)),length:a[0].length}},h12:function(a,b){return(12===a?0:a)+12*b},exec:function(a,b){a=(a.exec(b)||[""])[0];return{value:a|0,length:a.length}},find:function(a,b){for(var c=-1,d=0,h=0,g=a.length,l;h<g;h++)l=a[h],!b.indexOf(l)&&l.length>d&&(c=h,d=l.length);return{value:c,length:d}},pre:function(a){return a},res:t},n=function(a,b,c,d){var h={},g;for(g in a)h[g]=
a[g];for(g in b||{})!!c^!!h[g]||(h[g]=b[g]);d&&(h.res=d);return h},f={_formatter:w,_parser:x};f.compile=function(a){for(var b=/\[([^\[\]]|\[[^\[\]]*])*]|([A-Za-z])\2+|\.{3}|./g,c,d=[a];c=b.exec(a);)d[d.length]=c[0];return d};f.format=function(a,b,c){var d=this||e;b="string"===typeof b?d.compile(b):b;var h=a.getTimezoneOffset();a=d.addMinutes(a,c?h:0);d=d._formatter;var g="";a.getTimezoneOffset=function(){return c?0:h};for(var l=1,u=b.length,k;l<u;l++)k=b[l],g+=d[k]?d.post(d[k](a,b[0])):k.replace(/\[(.*)]/,
"$1");return g};f.preparse=function(a,b){var c=this||e;b="string"===typeof b?c.compile(b):b;var d={Y:1970,M:1,D:1,H:0,A:0,h:0,m:0,s:0,S:0,Z:0,_index:0,_length:0,_match:0},h=/\[(.*)]/;c=c._parser;var g=0;a=c.pre(a);for(var l=1,u=b.length,k,q;l<u;l++)if(k=b[l],c[k]){q=c[k](a.slice(g),b[0]);if(!q.length)break;g+=q.length;d[q.token||k.charAt(0)]=q.value;d._match++}else if(k===a.charAt(g)||" "===k)g++;else if(h.test(k)&&!a.slice(g).indexOf(h.exec(k)[1]))g+=k.length-2;else{"..."===k&&(g=a.length);break}d.H=
d.H||c.h12(d.h,d.A);d._index=g;d._length=a.length;return d};f.parse=function(a,b,c){var d=this||e;a=d.preparse(a,b);return d.isValid(a)?(a.M-=100>a.Y?22801:1,c||a.Z?new Date(Date.UTC(a.Y,a.M,a.D,a.H,a.m+a.Z,a.s,a.S)):new Date(a.Y,a.M,a.D,a.H,a.m,a.s,a.S)):new Date(NaN)};f.isValid=function(a,b){var c=this||e;a="string"===typeof a?c.preparse(a,b):a;c=[31,28+c.isLeapYear(a.Y)|0,31,30,31,30,31,31,30,31,30,31][a.M-1];return!(1>a._index||1>a._length||a._index-a._length||1>a._match||1>a.Y||9999<a.Y||1>a.M||
12<a.M||1>a.D||a.D>c||0>a.H||23<a.H||0>a.m||59<a.m||0>a.s||59<a.s||0>a.S||999<a.S||-840>a.Z||720<a.Z)};f.transform=function(a,b,c,d){let h=this||e;return h.format(h.parse(a,b),c,d)};f.addYears=function(a,b){return(this||e).addMonths(a,12*b)};f.addMonths=function(a,b){a=new Date(a.getTime());a.setMonth(a.getMonth()+b);return a};f.addDays=function(a,b){a=new Date(a.getTime());a.setDate(a.getDate()+b);return a};f.addHours=function(a,b){return(this||e).addMinutes(a,60*b)};f.addMinutes=function(a,b){return(this||
e).addSeconds(a,60*b)};f.addSeconds=function(a,b){return(this||e).addMilliseconds(a,1E3*b)};f.addMilliseconds=function(a,b){return new Date(a.getTime()+b)};f.subtract=function(a,b){var c=a.getTime()-b.getTime();return{toMilliseconds:function(){return c},toSeconds:function(){return c/1E3},toMinutes:function(){return c/6E4},toHours:function(){return c/36E5},toDays:function(){return c/864E5}}};f.isLeapYear=function(a){return!(a%4)&&!!(a%100)||!(a%400)};f.isSameDay=function(a,b){return a.toDateString()===
b.toDateString()};f.locale=function(a,b){p[a]||(p[a]=b)};f.plugin=function(a,b){m[a]||(m[a]=b)};var v=n(f);var e=n(f);e.locale=function(a){a="function"===typeof a?a:e.locale[a];if(!a)return r;r=a(f);var b=p[r]||{},c=n(t,b.res,!0);a=n(w,b.formatter,!0,c);b=n(x,b.parser,!0,c);e._formatter=v._formatter=a;e._parser=v._parser=b;for(var d in m)e.extend(m[d]);return r};e.extend=function(a){var b=n(e._parser.res,a.res),c=a.extender||{};e._formatter=n(e._formatter,a.formatter,!1,b);e._parser=n(e._parser,a.parser,
!1,b);for(var d in c)e[d]||(e[d]=c[d])};e.plugin=function(a){(a="function"===typeof a?a:e.plugin[a])&&e.extend(m[a(f,v)]||{})};return e})

@@ -45,2 +45,7 @@ /**

},
ZZ: function (d/*, formatString*/) {
var offset = d.getTimezoneOffset();
var mod = Math.abs(offset);
return (offset > 0 ? '-' : '+') + ('0' + (mod / 60 | 0)).slice(-2) + ':' + ('0' + mod % 60).slice(-2);
},
post: function (str) { return str; },

@@ -91,2 +96,6 @@ res: _res

},
ZZ: function (str/*, formatString */) {
var arr = /^([\+-])(\d{2}):([0-5]\d)/.exec(str) || ['', '', '', ''];
return { value: 0 - ((arr[1] + arr[2] | 0) * 60 + (arr[1] + arr[3] | 0)), length: arr[0].length };
},
h12: function (h, a) { return (h === 12 ? 0 : h) + a * 12; },

@@ -93,0 +102,0 @@ exec: function (re, str) {

@@ -7,7 +7,7 @@ /*

h:function(a){return""+(a.getHours()%12||12)},mm:function(a){return("0"+a.getMinutes()).slice(-2)},m:function(a){return""+a.getMinutes()},ss:function(a){return("0"+a.getSeconds()).slice(-2)},s:function(a){return""+a.getSeconds()},SSS:function(a){return("00"+a.getMilliseconds()).slice(-3)},SS:function(a){return("0"+(a.getMilliseconds()/10|0)).slice(-2)},S:function(a){return""+(a.getMilliseconds()/100|0)},dddd:function(a){return this.res.dddd[a.getDay()]},ddd:function(a){return this.res.ddd[a.getDay()]},
dd:function(a){return this.res.dd[a.getDay()]},Z:function(a){a=a.getTimezoneOffset()/.6|0;return(0<a?"-":"+")+("000"+Math.abs(a-(a%100*.4|0))).slice(-4)},post:function(a){return a},res:n},r={YYYY:function(a){return this.exec(/^\d{4}/,a)},Y:function(a){return this.exec(/^\d{1,4}/,a)},MMMM:function(a){a=this.find(this.res.MMMM,a);a.value++;return a},MMM:function(a){a=this.find(this.res.MMM,a);a.value++;return a},MM:function(a){return this.exec(/^\d\d/,a)},M:function(a){return this.exec(/^\d\d?/,a)},
DD:function(a){return this.exec(/^\d\d/,a)},D:function(a){return this.exec(/^\d\d?/,a)},HH:function(a){return this.exec(/^\d\d/,a)},H:function(a){return this.exec(/^\d\d?/,a)},A:function(a){return this.find(this.res.A,a)},hh:function(a){return this.exec(/^\d\d/,a)},h:function(a){return this.exec(/^\d\d?/,a)},mm:function(a){return this.exec(/^\d\d/,a)},m:function(a){return this.exec(/^\d\d?/,a)},ss:function(a){return this.exec(/^\d\d/,a)},s:function(a){return this.exec(/^\d\d?/,a)},SSS:function(a){return this.exec(/^\d{1,3}/,
a)},SS:function(a){a=this.exec(/^\d\d?/,a);a.value*=10;return a},S:function(a){a=this.exec(/^\d/,a);a.value*=100;return a},Z:function(a){a=this.exec(/^[\+-]\d{2}[0-5]\d/,a);a.value=-60*(a.value/100|0)-a.value%100;return a},h12:function(a,b){return(12===a?0:a)+12*b},exec:function(a,b){a=(a.exec(b)||[""])[0];return{value:a|0,length:a.length}},find:function(a,b){for(var c=-1,d=0,h=0,g=a.length,l;h<g;h++)l=a[h],!b.indexOf(l)&&l.length>d&&(c=h,d=l.length);return{value:c,length:d}},pre:function(a){return a},
res:n};function t(a,b,c,d){var h={},g;for(g in a)h[g]=a[g];for(g in b||{})!!c^!!h[g]||(h[g]=b[g]);d&&(h.res=d);return h}var u={_formatter:q,_parser:r},w,x;u.compile=function(a){for(var b=/\[([^\[\]]|\[[^\[\]]*])*]|([A-Za-z])\2+|\.{3}|./g,c,d=[a];c=b.exec(a);)d[d.length]=c[0];return d};
u.format=function(a,b,c){var d=this||x;b="string"===typeof b?d.compile(b):b;var h=a.getTimezoneOffset();a=d.addMinutes(a,c?h:0);d=d._formatter;var g="";a.getTimezoneOffset=function(){return c?0:h};for(var l=1,v=b.length,k;l<v;l++)k=b[l],g+=d[k]?d.post(d[k](a,b[0])):k.replace(/\[(.*)]/,"$1");return g};
dd:function(a){return this.res.dd[a.getDay()]},Z:function(a){a=a.getTimezoneOffset()/.6|0;return(0<a?"-":"+")+("000"+Math.abs(a-(a%100*.4|0))).slice(-4)},ZZ:function(a){a=a.getTimezoneOffset();var b=Math.abs(a);return(0<a?"-":"+")+("0"+(b/60|0)).slice(-2)+":"+("0"+b%60).slice(-2)},post:function(a){return a},res:n},r={YYYY:function(a){return this.exec(/^\d{4}/,a)},Y:function(a){return this.exec(/^\d{1,4}/,a)},MMMM:function(a){a=this.find(this.res.MMMM,a);a.value++;return a},MMM:function(a){a=this.find(this.res.MMM,
a);a.value++;return a},MM:function(a){return this.exec(/^\d\d/,a)},M:function(a){return this.exec(/^\d\d?/,a)},DD:function(a){return this.exec(/^\d\d/,a)},D:function(a){return this.exec(/^\d\d?/,a)},HH:function(a){return this.exec(/^\d\d/,a)},H:function(a){return this.exec(/^\d\d?/,a)},A:function(a){return this.find(this.res.A,a)},hh:function(a){return this.exec(/^\d\d/,a)},h:function(a){return this.exec(/^\d\d?/,a)},mm:function(a){return this.exec(/^\d\d/,a)},m:function(a){return this.exec(/^\d\d?/,
a)},ss:function(a){return this.exec(/^\d\d/,a)},s:function(a){return this.exec(/^\d\d?/,a)},SSS:function(a){return this.exec(/^\d{1,3}/,a)},SS:function(a){a=this.exec(/^\d\d?/,a);a.value*=10;return a},S:function(a){a=this.exec(/^\d/,a);a.value*=100;return a},Z:function(a){a=this.exec(/^[\+-]\d{2}[0-5]\d/,a);a.value=-60*(a.value/100|0)-a.value%100;return a},ZZ:function(a){a=/^([\+-])(\d{2}):([0-5]\d)/.exec(a)||["","","",""];return{value:-(60*(a[1]+a[2]|0)+(a[1]+a[3]|0)),length:a[0].length}},h12:function(a,
b){return(12===a?0:a)+12*b},exec:function(a,b){a=(a.exec(b)||[""])[0];return{value:a|0,length:a.length}},find:function(a,b){for(var c=-1,d=0,h=0,g=a.length,l;h<g;h++)l=a[h],!b.indexOf(l)&&l.length>d&&(c=h,d=l.length);return{value:c,length:d}},pre:function(a){return a},res:n};function t(a,b,c,d){var h={},g;for(g in a)h[g]=a[g];for(g in b||{})!!c^!!h[g]||(h[g]=b[g]);d&&(h.res=d);return h}var u={_formatter:q,_parser:r},w,x;
u.compile=function(a){for(var b=/\[([^\[\]]|\[[^\[\]]*])*]|([A-Za-z])\2+|\.{3}|./g,c,d=[a];c=b.exec(a);)d[d.length]=c[0];return d};u.format=function(a,b,c){var d=this||x;b="string"===typeof b?d.compile(b):b;var h=a.getTimezoneOffset();a=d.addMinutes(a,c?h:0);d=d._formatter;var g="";a.getTimezoneOffset=function(){return c?0:h};for(var l=1,v=b.length,k;l<v;l++)k=b[l],g+=d[k]?d.post(d[k](a,b[0])):k.replace(/\[(.*)]/,"$1");return g};
u.preparse=function(a,b){var c=this||x;b="string"===typeof b?c.compile(b):b;var d={Y:1970,M:1,D:1,H:0,A:0,h:0,m:0,s:0,S:0,Z:0,_index:0,_length:0,_match:0},h=/\[(.*)]/;c=c._parser;var g=0;a=c.pre(a);for(var l=1,v=b.length,k,p;l<v;l++)if(k=b[l],c[k]){p=c[k](a.slice(g),b[0]);if(!p.length)break;g+=p.length;d[p.token||k.charAt(0)]=p.value;d._match++}else if(k===a.charAt(g)||" "===k)g++;else if(h.test(k)&&!a.slice(g).indexOf(h.exec(k)[1]))g+=k.length-2;else{"..."===k&&(g=a.length);break}d.H=d.H||c.h12(d.h,

@@ -14,0 +14,0 @@ d.A);d._index=g;d._length=a.length;return d};u.parse=function(a,b,c){var d=this||x;a=d.preparse(a,b);return d.isValid(a)?(a.M-=100>a.Y?22801:1,c||a.Z?new Date(Date.UTC(a.Y,a.M,a.D,a.H,a.m+a.Z,a.s,a.S)):new Date(a.Y,a.M,a.D,a.H,a.m,a.s,a.S)):new Date(NaN)};

@@ -61,2 +61,5 @@ /**

};
var transformTZ = function (dateString, arg1, arg2, timeZone) {
return formatTZ(localized_date.parse(dateString, arg1), arg2, timeZone);
};

@@ -68,3 +71,4 @@ var name = 'timezone';

formatTZ: formatTZ,
parseTZ: parseTZ
parseTZ: parseTZ,
transformTZ: transformTZ
}

@@ -71,0 +75,0 @@ });

{
"name": "date-and-time",
"version": "2.1.2",
"version": "2.2.0",
"description": "A Minimalist DateTime utility for Node.js and the browser",

@@ -49,6 +49,6 @@ "main": "date-and-time.js",

"expect.js": "^0.3.1",
"mocha": "^9.2.0",
"mocha": "^9.2.1",
"mocha-headless-chrome": "^4.0.0",
"rollup": "^2.67.2"
"rollup": "^2.68.0"
}
}

@@ -67,2 +67,5 @@ (function (global, factory) {

};
var transformTZ = function (dateString, arg1, arg2, timeZone) {
return formatTZ(localized_date.parse(dateString, arg1), arg2, timeZone);
};

@@ -74,3 +77,4 @@ var name = 'timezone';

formatTZ: formatTZ,
parseTZ: parseTZ
parseTZ: parseTZ,
transformTZ: transformTZ
}

@@ -77,0 +81,0 @@ });

@@ -79,3 +79,3 @@ # Plugins

- [timezone](#timezone)
- It adds `formatTZ()` and `parseTZ()` functions that support `IANA time zone names` to the library.
- It adds `formatTZ()`, `parseTZ()` and `transformTZ()` that support `IANA time zone names` to the library.

@@ -294,3 +294,3 @@ - [two-digit-year](#two-digit-year)

It adds `formatTZ()` and `parseTZ()` functions that support `IANA time zone names` (`America/Los_Angeles`, `Asia/Tokyo`, and so on) to the library.
It adds `formatTZ()`, `parseTZ()` and `transformTZ()` that support `IANA time zone names` (`America/Los_Angeles`, `Asia/Tokyo`, and so on) to the library.

@@ -304,3 +304,3 @@ #### formatTZ(dateObj, arg[, timeZone])

The `formatTZ()` is upward compatible with `format()`. Tokens available here are the same as for the `format()`. If the `timeZone` is omitted, it output the date string with local time zone.
`formatTZ()` is upward compatible with `format()`. Tokens available for `arg` are the same as those for `format()`. If `timeZone` is omitted, this function assumes `timeZone` to be a local time zone and outputs a string. This means that the result is the same as when `format()` is used.

@@ -314,4 +314,14 @@ #### parseTZ(dateString, arg[, timeZone])

The `parseTZ()` is upward compatible with `parse()`. Tokens available here are the same as for the `parse()`. If the `timeZone` is omitted, the time zone of the date string is assumed to be local time zone.
`parseTZ()` is upward compatible with `parse()`. Tokens available for `arg` are the same as those for `parse()`. `timeZone` in this function is used as supplemental information. if `dateString` contains a time zone offset value (i.e. -0800, +0900), `timeZone` is not be used. If `dateString` doesn't contain a time zone offset value and `timeZone` is omitted, this function assumes `timeZone` to be a local time zone. This means that the result is the same as when `parse()` is used.
#### transformTZ(dateString, arg1, arg2[, timeZone])
- @param {**string**} dateString - a date string
- @param {**string|Array.\<string\>**} arg1 - a format string or its compiled object
- @param {**string|Array.\<string\>**} arg2 - a transformed format string or its compiled object
- @param {**string**} [timeZone] - output as this time zone
- @returns {**string**} a formatted string
`transformTZ()` is upward compatible with `transform()`. `dateString` must itself contain a time zone offset value (i.e. -0800, +0900), otherwise this function assumes it is a local time zone. Tokens available for `arg1` are the same as those for `parse()`, also tokens available for `arg2` are the same as those for `format()`. `timeZone` is a `IANA time zone names`, which is required to output a new formatted string. If it is omitted, this function assumes `timeZone` to be a local time zone. This means that the result is the same as when `transform()` is used.
```javascript

@@ -336,2 +346,8 @@ const date = require('date-and-time');

date.parseTZ('Sep 25 2021 4:00:00', 'MMM D YYYY H:mm:ss', 'Europe/London'); // 2021-09-25T03:00:00.000Z
// Transforms the date string from EST (Eastern Standard Time) to PDT (Pacific Daylight Time).
date.transformTZ('2021-11-07T03:59:59 UTC-0500', 'YYYY-MM-DD[T]HH:mm:ss [UTC]Z', 'MMMM D YYYY H:mm:ss UTC[Z]', 'America/Los_Angeles'); // November 7 2021 1:59:59 UTC-0700
// Transforms the date string from PDT(Pacific Daylight Time) to JST (Japan Standard Time).
date.transformTZ('2021-03-14T03:00:00 UTC-0700', 'YYYY-MM-DD[T]HH:mm:ss [UTC]Z', 'MMMM D YYYY H:mm:ss UTC[Z]', 'Asia/Tokyo'); // March 14 2021 19:00:00 UTC+0900
```

@@ -342,7 +358,7 @@

- This plugin uses the [Intl](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl) object to parse `IANA time zone names`. Note that if you use this plugin in older browsers, this may **NOT** be supported there. At least it does not work in IE.
- If you don't need to use `IANA time zone names`, you should not use this plugin for performance reasons. The `format()` and the `parse()` are enough.
- If you don't need to use `IANA time zone names`, you should not use this plugin for performance reasons. Recommended to use `format()` and `parse()`.
#### Start of DST (Daylight Saving Time)
For example, in the US, when local standard time is about to reach Sunday, 14 March 2021, `02:00:00` clocks are turned `forward` 1 hour to Sunday, 14 March 2021, `03:00:00` local daylight time instead. Thus, there is no `02:00:00` to `02:59:59` on 14 March 2021. In such edge cases, the `parseTZ()` will parse like this:
For example, in the US, when local standard time is about to reach Sunday, 14 March 2021, `02:00:00` clocks are turned `forward` 1 hour to Sunday, 14 March 2021, `03:00:00` local daylight time instead. Thus there is no `02:00:00` to `02:59:59` on 14 March 2021. In such edge cases, `parseTZ()` will parse like this:

@@ -358,6 +374,6 @@ ```javascript

Also, when local daylight time is about to reach Sunday, 7 November 2021, `02:00:00` clocks are turned `backward` 1 hour to Sunday, 7 November 2021, `01:00:00` local standard time instead. Thus, `01:00:00` to `01:59:59` on November 7 2021 is repeated twice. Since there are two possible times between them, DST or not, the `parseTZ()` assumes that the time is former to make the result unique:
Also, when local daylight time is about to reach Sunday, 7 November 2021, `02:00:00` clocks are turned `backward` 1 hour to Sunday, 7 November 2021, `01:00:00` local standard time instead. Thus `01:00:00` to `01:59:59` on November 7 2021 is repeated twice. Since there are two possible times here, `parseTZ()` assumes that the time is the former (DST) in order to make the result unique:
```javascript
// The parseTZ() assumes that this time is DST.
// This time is DST or PST? The parseTZ() always assumes that it is DST.
date.parseTZ('Nov 7 2021 1:59:59', 'MMM D YYYY H:mm:ss', 'America/Los_Angeles'); // => 2021-11-07T08:59:59Z

@@ -368,3 +384,3 @@ // This time is already PST.

At the first example above, if you want the parser to parse the time as PST (Pacific Standard Time), use the `parse()` with a time offset instead:
In the first example above, if you want `parseTZ()` to parse the time as PST, you need to pass a date string containing the time zone offset value. In this case, it is better to use `parse()` instead:

@@ -371,0 +387,0 @@ ```javascript

@@ -27,4 +27,8 @@ # date-and-time

- 2.2.0
- Added `tranformTZ()` to `timezone` plugin. See [PLUGINS.md](./PLUGINS.md) for details.
- Added `ZZ` token to supports time zone values like `-08:00` `+09:00` to `format()` and `parse()`.
- 2.1.2
- Fixed an issue that the lib's validation logic would condider an error when a timezone offset value of a datetime string was greater then +12 hours.
- Fixed an issue that the lib's validation logic would consider an error when a time zone offset value of a date-time string was greater than +12 hours.

@@ -34,16 +38,2 @@ - 2.1.1

- 2.1.0
- Fixed an issue that the lib's functions assigned to variables using ES6 destructuring assignment cause an error.
```javascript
// Destructuring assignment
const { format, parse } = require('date-and-time');
// These used to be errors in 2.0.x.
format(new Date(), 'MMM DD YYYY');
parse('Jan 11 2022', 'MMM DD YYYY');
```
- Added Swedish support.
## Usage

@@ -186,3 +176,4 @@

| S | millisecond (low accuracy) | 7, 0 |
| Z | timezone offset | +0100, -0800 |
| Z | time zone offset value | +0100, -0800 |
| ZZ | time zone offset value with colon | +01:00, -08:00 |

@@ -261,3 +252,4 @@ You can also use the following tokens by importing plugins. See [PLUGINS.md](./PLUGINS.md) for details.

| S | millisecond (low accuracy) | 7, 0 |
| Z | timezone offset | +0100, -0800 |
| Z | time zone offset value | +0100, -0800 |
| ZZ | time zone offset value with colon | +01:00, -08:00 |

@@ -293,3 +285,3 @@ You can also use the following tokens by importing plugins. See [PLUGINS.md](./PLUGINS.md) for details.

This function usually assumes the `dateString` is a local date-time. Set to true the `utc` option (the 3rd parameter) if it is a UTC date-time.
This function assumes the `dateString` is a local date-time unless it contains a time zone offset value. Set to true the `utc` option (the 3rd parameter) if it is a UTC date-time.

@@ -296,0 +288,0 @@ ```javascript

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc