date-and-time
Advanced tools
Comparing version 3.3.0 to 3.4.0
@@ -299,3 +299,3 @@ /** | ||
/** Plugin installer */ | ||
export type Plugin = (proto: unknown, localized_proto?: unknown) => string; | ||
export type Plugin = (proto: unknown, date?: unknown) => string; | ||
@@ -302,0 +302,0 @@ /** |
@@ -145,3 +145,2 @@ (function (global, factory) { | ||
}, | ||
localized_proto, | ||
date; | ||
@@ -181,2 +180,3 @@ | ||
u.getTimezoneOffset = function () { return 0; }; | ||
u.getTimezoneName = function () { return 'UTC'; }; | ||
return u; | ||
@@ -458,3 +458,2 @@ } | ||
localized_proto = extend(proto); | ||
date = extend(proto); | ||
@@ -480,4 +479,4 @@ | ||
date._formatter = localized_proto._formatter = formatter; | ||
date._parser = localized_proto._parser = parser; | ||
date._formatter = formatter; | ||
date._parser = parser; | ||
@@ -519,3 +518,3 @@ for (var plugin in plugins) { | ||
if (install) { | ||
date.extend(plugins[install(proto, localized_proto)] || {}); | ||
date.extend(plugins[install(proto, date)] || {}); | ||
} | ||
@@ -522,0 +521,0 @@ }; |
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).date=t()}(this,(function(){"use strict"; | ||
/** | ||
* @preserve date-and-time (c) KNOWLEDGECODE | MIT | ||
*/var e,t,n={},r={},i="en",u={MMMM:["January","February","March","April","May","June","July","August","September","October","November","December"],MMM:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],dddd:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],ddd:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],dd:["Su","Mo","Tu","We","Th","Fr","Sa"],A:["AM","PM"]},s={YYYY:function(e){return("000"+e.getFullYear()).slice(-4)},YY:function(e){return("0"+e.getFullYear()).slice(-2)},Y:function(e){return""+e.getFullYear()},MMMM:function(e){return this.res.MMMM[e.getMonth()]},MMM:function(e){return this.res.MMM[e.getMonth()]},MM:function(e){return("0"+(e.getMonth()+1)).slice(-2)},M:function(e){return""+(e.getMonth()+1)},DD:function(e){return("0"+e.getDate()).slice(-2)},D:function(e){return""+e.getDate()},HH:function(e){return("0"+e.getHours()).slice(-2)},H:function(e){return""+e.getHours()},A:function(e){return this.res.A[e.getHours()>11|0]},hh:function(e){return("0"+(e.getHours()%12||12)).slice(-2)},h:function(e){return""+(e.getHours()%12||12)},mm:function(e){return("0"+e.getMinutes()).slice(-2)},m:function(e){return""+e.getMinutes()},ss:function(e){return("0"+e.getSeconds()).slice(-2)},s:function(e){return""+e.getSeconds()},SSS:function(e){return("00"+e.getMilliseconds()).slice(-3)},SS:function(e){return("0"+(e.getMilliseconds()/10|0)).slice(-2)},S:function(e){return""+(e.getMilliseconds()/100|0)},dddd:function(e){return this.res.dddd[e.getDay()]},ddd:function(e){return this.res.ddd[e.getDay()]},dd:function(e){return this.res.dd[e.getDay()]},Z:function(e){var t=e.getTimezoneOffset()/.6|0;return(t>0?"-":"+")+("000"+Math.abs(t-(t%100*.4|0))).slice(-4)},ZZ:function(e){var t=e.getTimezoneOffset(),n=Math.abs(t);return(t>0?"-":"+")+("0"+(n/60|0)).slice(-2)+":"+("0"+n%60).slice(-2)},post:function(e){return e},res:u},o={YYYY:function(e){return this.exec(/^\d{4}/,e)},Y:function(e){return this.exec(/^\d{1,4}/,e)},MMMM:function(e){var t=this.find(this.res.MMMM,e);return t.value++,t},MMM:function(e){var t=this.find(this.res.MMM,e);return t.value++,t},MM:function(e){return this.exec(/^\d\d/,e)},M:function(e){return this.exec(/^\d\d?/,e)},DD:function(e){return this.exec(/^\d\d/,e)},D:function(e){return this.exec(/^\d\d?/,e)},HH:function(e){return this.exec(/^\d\d/,e)},H:function(e){return this.exec(/^\d\d?/,e)},A:function(e){return this.find(this.res.A,e)},hh:function(e){return this.exec(/^\d\d/,e)},h:function(e){return this.exec(/^\d\d?/,e)},mm:function(e){return this.exec(/^\d\d/,e)},m:function(e){return this.exec(/^\d\d?/,e)},ss:function(e){return this.exec(/^\d\d/,e)},s:function(e){return this.exec(/^\d\d?/,e)},SSS:function(e){return this.exec(/^\d{1,3}/,e)},SS:function(e){var t=this.exec(/^\d\d?/,e);return t.value*=10,t},S:function(e){var t=this.exec(/^\d/,e);return t.value*=100,t},Z:function(e){var t=this.exec(/^[+-]\d{2}[0-5]\d/,e);return t.value=-60*(t.value/100|0)-t.value%100,t},ZZ:function(e){var t=/^([+-])(\d{2}):([0-5]\d)/.exec(e)||["","","",""];return{value:0-(60*(t[1]+t[2]|0)+(t[1]+t[3]|0)),length:t[0].length}},h12:function(e,t){return(12===e?0:e)+12*t},exec:function(e,t){var n=(e.exec(t)||[""])[0];return{value:0|n,length:n.length}},find:function(e,t){for(var n,r=-1,i=0,u=0,s=e.length;u<s;u++)n=e[u],!t.indexOf(n)&&n.length>i&&(r=u,i=n.length);return{value:r,length:i}},pre:function(e){return e},res:u},c=function(e,t,n,r){var i,u={};for(i in e)u[i]=e[i];for(i in t||{})!!n^!!u[i]||(u[i]=t[i]);return r&&(u.res=r),u},a={_formatter:s,_parser:o};return a.compile=function(e){return[e].concat(e.match(/\[(?:[^[\]]|\[[^[\]]*])*]|([A-Za-z])\1*|\.{3}|./g)||[])},a.format=function(e,n,r){for(var i,u=this||t,s="string"==typeof n?u.compile(n):n,o=u._formatter,c=function(){if(r){var t=new Date(e.getTime());return t.getFullYear=t.getUTCFullYear,t.getMonth=t.getUTCMonth,t.getDate=t.getUTCDate,t.getHours=t.getUTCHours,t.getMinutes=t.getUTCMinutes,t.getSeconds=t.getUTCSeconds,t.getMilliseconds=t.getUTCMilliseconds,t.getDay=t.getUTCDay,t.getTimezoneOffset=function(){return 0},t}return e}(),a=/^\[(.*)\]$/,d="",f=1,l=s.length;f<l;f++)d+=o[i=s[f]]?o.post(o[i](c,s[0])):a.test(i)?i.replace(a,"$1"):i;return d},a.preparse=function(e,n){var r=this||t,i="string"==typeof n?r.compile(n):n,u=r._parser,s={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},o=/^\[(.*)\]$/;e=u.pre(e);for(var c,a,d,f=1,l=i.length;f<l;f++)if(c=i[f],a=e.substring(s._index),u[c]){if(!(d=u[c](a,i[0])).length)break;s[d.token||c.charAt(0)]=d.value,s._index+=d.length,s._match++}else if(c===a.charAt(0)||" "===c)s._index++;else{if(!o.test(c)||a.indexOf(c.replace(o,"$1"))){if("..."===c){s._index=e.length;break}break}s._index+=c.length-2}return s.H=s.H||u.h12(s.h,s.A),s._length=e.length,s},a.parse=function(e,n,r){var i=this||t,u="string"==typeof n?i.compile(n):n,s=i.preparse(e,u);return i.isValid(s)?(s.M-=s.Y<100?22801:1,r||~i._parser.find(u,"ZZ").value?new Date(Date.UTC(s.Y,s.M,s.D,s.H,s.m+s.Z,s.s,s.S)):new Date(s.Y,s.M,s.D,s.H,s.m,s.s,s.S)):new Date(NaN)},a.isValid=function(e,n){var r="string"==typeof e?(this||t).preparse(e,n):e;return!(r._index<1||r._length<1||r._index-r._length||r._match<1||r.Y<1||r.Y>9999||r.M<1||r.M>12||r.D<1||r.D>new Date(r.Y,r.M,0).getDate()||r.H<0||r.H>23||r.m<0||r.m>59||r.s<0||r.s>59||r.S<0||r.S>999||r.Z<-840||r.Z>720)},a.transform=function(e,n,r,i){const u=this||t;return u.format(u.parse(e,n),r,i)},a.addYears=function(e,n,r){return(this||t).addMonths(e,12*n,r)},a.addMonths=function(e,n,r){var i=new Date(e.getTime());if(r){if(i.setUTCMonth(i.getUTCMonth()+n),i.getUTCDate()<e.getUTCDate())return(this||t).addDays(i,-i.getUTCDate(),r)}else if(i.setMonth(i.getMonth()+n),i.getDate()<e.getDate())return(this||t).addDays(i,-i.getDate(),r);return i},a.addDays=function(e,n,r){return(this||t).addHours(e,24*n,r)},a.addHours=function(e,n,r){return(this||t).addMinutes(e,60*n,r)},a.addMinutes=function(e,n,r){return(this||t).addSeconds(e,60*n,r)},a.addSeconds=function(e,n,r){return(this||t).addMilliseconds(e,1e3*n,r)},a.addMilliseconds=function(e,t,n){var r=new Date(e.getTime());return n?r.setUTCMilliseconds(r.getUTCMilliseconds()+t):r.setMilliseconds(r.getMilliseconds()+t),r},a.subtract=function(e,t){var n=e.getTime()-t.getTime();return{toMilliseconds:function(){return n},toSeconds:function(){return n/1e3},toMinutes:function(){return n/6e4},toHours:function(){return n/36e5},toDays:function(){return n/864e5}}},a.isLeapYear=function(e){return!((e%4||!(e%100))&&e%400)},a.isSameDay=function(e,t){return e.toDateString()===t.toDateString()},a.locale=function(e,t){n[e]||(n[e]=t)},a.plugin=function(e,t){r[e]||(r[e]=t)},e=c(a),(t=c(a)).locale=function(d){var f="function"==typeof d?d:t.locale[d];if(!f)return i;i=f(a);var l=n[i]||{},h=c(u,l.res,!0),g=c(s,l.formatter,!0,h),M=c(o,l.parser,!0,h);for(var p in t._formatter=e._formatter=g,t._parser=e._parser=M,r)t.extend(r[p]);return i},t.extend=function(e){var n=c(t._parser.res,e.res),r=e.extender||{};for(var i in t._formatter=c(t._formatter,e.formatter,!1,n),t._parser=c(t._parser,e.parser,!1,n),r)t[i]||(t[i]=r[i])},t.plugin=function(n){var i="function"==typeof n?n:t.plugin[n];i&&t.extend(r[i(a,e)]||{})},t})); | ||
*/var e,t={},n={},r="en",i={MMMM:["January","February","March","April","May","June","July","August","September","October","November","December"],MMM:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],dddd:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],ddd:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],dd:["Su","Mo","Tu","We","Th","Fr","Sa"],A:["AM","PM"]},u={YYYY:function(e){return("000"+e.getFullYear()).slice(-4)},YY:function(e){return("0"+e.getFullYear()).slice(-2)},Y:function(e){return""+e.getFullYear()},MMMM:function(e){return this.res.MMMM[e.getMonth()]},MMM:function(e){return this.res.MMM[e.getMonth()]},MM:function(e){return("0"+(e.getMonth()+1)).slice(-2)},M:function(e){return""+(e.getMonth()+1)},DD:function(e){return("0"+e.getDate()).slice(-2)},D:function(e){return""+e.getDate()},HH:function(e){return("0"+e.getHours()).slice(-2)},H:function(e){return""+e.getHours()},A:function(e){return this.res.A[e.getHours()>11|0]},hh:function(e){return("0"+(e.getHours()%12||12)).slice(-2)},h:function(e){return""+(e.getHours()%12||12)},mm:function(e){return("0"+e.getMinutes()).slice(-2)},m:function(e){return""+e.getMinutes()},ss:function(e){return("0"+e.getSeconds()).slice(-2)},s:function(e){return""+e.getSeconds()},SSS:function(e){return("00"+e.getMilliseconds()).slice(-3)},SS:function(e){return("0"+(e.getMilliseconds()/10|0)).slice(-2)},S:function(e){return""+(e.getMilliseconds()/100|0)},dddd:function(e){return this.res.dddd[e.getDay()]},ddd:function(e){return this.res.ddd[e.getDay()]},dd:function(e){return this.res.dd[e.getDay()]},Z:function(e){var t=e.getTimezoneOffset()/.6|0;return(t>0?"-":"+")+("000"+Math.abs(t-(t%100*.4|0))).slice(-4)},ZZ:function(e){var t=e.getTimezoneOffset(),n=Math.abs(t);return(t>0?"-":"+")+("0"+(n/60|0)).slice(-2)+":"+("0"+n%60).slice(-2)},post:function(e){return e},res:i},o={YYYY:function(e){return this.exec(/^\d{4}/,e)},Y:function(e){return this.exec(/^\d{1,4}/,e)},MMMM:function(e){var t=this.find(this.res.MMMM,e);return t.value++,t},MMM:function(e){var t=this.find(this.res.MMM,e);return t.value++,t},MM:function(e){return this.exec(/^\d\d/,e)},M:function(e){return this.exec(/^\d\d?/,e)},DD:function(e){return this.exec(/^\d\d/,e)},D:function(e){return this.exec(/^\d\d?/,e)},HH:function(e){return this.exec(/^\d\d/,e)},H:function(e){return this.exec(/^\d\d?/,e)},A:function(e){return this.find(this.res.A,e)},hh:function(e){return this.exec(/^\d\d/,e)},h:function(e){return this.exec(/^\d\d?/,e)},mm:function(e){return this.exec(/^\d\d/,e)},m:function(e){return this.exec(/^\d\d?/,e)},ss:function(e){return this.exec(/^\d\d/,e)},s:function(e){return this.exec(/^\d\d?/,e)},SSS:function(e){return this.exec(/^\d{1,3}/,e)},SS:function(e){var t=this.exec(/^\d\d?/,e);return t.value*=10,t},S:function(e){var t=this.exec(/^\d/,e);return t.value*=100,t},Z:function(e){var t=this.exec(/^[+-]\d{2}[0-5]\d/,e);return t.value=-60*(t.value/100|0)-t.value%100,t},ZZ:function(e){var t=/^([+-])(\d{2}):([0-5]\d)/.exec(e)||["","","",""];return{value:0-(60*(t[1]+t[2]|0)+(t[1]+t[3]|0)),length:t[0].length}},h12:function(e,t){return(12===e?0:e)+12*t},exec:function(e,t){var n=(e.exec(t)||[""])[0];return{value:0|n,length:n.length}},find:function(e,t){for(var n,r=-1,i=0,u=0,o=e.length;u<o;u++)n=e[u],!t.indexOf(n)&&n.length>i&&(r=u,i=n.length);return{value:r,length:i}},pre:function(e){return e},res:i},s=function(e,t,n,r){var i,u={};for(i in e)u[i]=e[i];for(i in t||{})!!n^!!u[i]||(u[i]=t[i]);return r&&(u.res=r),u},c={_formatter:u,_parser:o};return c.compile=function(e){return[e].concat(e.match(/\[(?:[^[\]]|\[[^[\]]*])*]|([A-Za-z])\1*|\.{3}|./g)||[])},c.format=function(t,n,r){for(var i,u=this||e,o="string"==typeof n?u.compile(n):n,s=u._formatter,c=function(){if(r){var e=new Date(t.getTime());return e.getFullYear=e.getUTCFullYear,e.getMonth=e.getUTCMonth,e.getDate=e.getUTCDate,e.getHours=e.getUTCHours,e.getMinutes=e.getUTCMinutes,e.getSeconds=e.getUTCSeconds,e.getMilliseconds=e.getUTCMilliseconds,e.getDay=e.getUTCDay,e.getTimezoneOffset=function(){return 0},e.getTimezoneName=function(){return"UTC"},e}return t}(),a=/^\[(.*)\]$/,d="",f=1,l=o.length;f<l;f++)d+=s[i=o[f]]?s.post(s[i](c,o[0])):a.test(i)?i.replace(a,"$1"):i;return d},c.preparse=function(t,n){var r=this||e,i="string"==typeof n?r.compile(n):n,u=r._parser,o={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},s=/^\[(.*)\]$/;t=u.pre(t);for(var c,a,d,f=1,l=i.length;f<l;f++)if(c=i[f],a=t.substring(o._index),u[c]){if(!(d=u[c](a,i[0])).length)break;o[d.token||c.charAt(0)]=d.value,o._index+=d.length,o._match++}else if(c===a.charAt(0)||" "===c)o._index++;else{if(!s.test(c)||a.indexOf(c.replace(s,"$1"))){if("..."===c){o._index=t.length;break}break}o._index+=c.length-2}return o.H=o.H||u.h12(o.h,o.A),o._length=t.length,o},c.parse=function(t,n,r){var i=this||e,u="string"==typeof n?i.compile(n):n,o=i.preparse(t,u);return i.isValid(o)?(o.M-=o.Y<100?22801:1,r||~i._parser.find(u,"ZZ").value?new Date(Date.UTC(o.Y,o.M,o.D,o.H,o.m+o.Z,o.s,o.S)):new Date(o.Y,o.M,o.D,o.H,o.m,o.s,o.S)):new Date(NaN)},c.isValid=function(t,n){var r="string"==typeof t?(this||e).preparse(t,n):t;return!(r._index<1||r._length<1||r._index-r._length||r._match<1||r.Y<1||r.Y>9999||r.M<1||r.M>12||r.D<1||r.D>new Date(r.Y,r.M,0).getDate()||r.H<0||r.H>23||r.m<0||r.m>59||r.s<0||r.s>59||r.S<0||r.S>999||r.Z<-840||r.Z>720)},c.transform=function(t,n,r,i){const u=this||e;return u.format(u.parse(t,n),r,i)},c.addYears=function(t,n,r){return(this||e).addMonths(t,12*n,r)},c.addMonths=function(t,n,r){var i=new Date(t.getTime());if(r){if(i.setUTCMonth(i.getUTCMonth()+n),i.getUTCDate()<t.getUTCDate())return(this||e).addDays(i,-i.getUTCDate(),r)}else if(i.setMonth(i.getMonth()+n),i.getDate()<t.getDate())return(this||e).addDays(i,-i.getDate(),r);return i},c.addDays=function(t,n,r){return(this||e).addHours(t,24*n,r)},c.addHours=function(t,n,r){return(this||e).addMinutes(t,60*n,r)},c.addMinutes=function(t,n,r){return(this||e).addSeconds(t,60*n,r)},c.addSeconds=function(t,n,r){return(this||e).addMilliseconds(t,1e3*n,r)},c.addMilliseconds=function(e,t,n){var r=new Date(e.getTime());return n?r.setUTCMilliseconds(r.getUTCMilliseconds()+t):r.setMilliseconds(r.getMilliseconds()+t),r},c.subtract=function(e,t){var n=e.getTime()-t.getTime();return{toMilliseconds:function(){return n},toSeconds:function(){return n/1e3},toMinutes:function(){return n/6e4},toHours:function(){return n/36e5},toDays:function(){return n/864e5}}},c.isLeapYear=function(e){return!((e%4||!(e%100))&&e%400)},c.isSameDay=function(e,t){return e.toDateString()===t.toDateString()},c.locale=function(e,n){t[e]||(t[e]=n)},c.plugin=function(e,t){n[e]||(n[e]=t)},(e=s(c)).locale=function(a){var d="function"==typeof a?a:e.locale[a];if(!d)return r;r=d(c);var f=t[r]||{},l=s(i,f.res,!0),h=s(u,f.formatter,!0,l),g=s(o,f.parser,!0,l);for(var M in e._formatter=h,e._parser=g,n)e.extend(n[M]);return r},e.extend=function(t){var n=s(e._parser.res,t.res),r=t.extender||{};for(var i in e._formatter=s(e._formatter,t.formatter,!1,n),e._parser=s(e._parser,t.parser,!1,n),r)e[i]||(e[i]=r[i])},e.plugin=function(t){var r="function"==typeof t?t:e.plugin[t];r&&e.extend(n[r(c,e)]||{})},e})); |
@@ -139,3 +139,2 @@ /** | ||
}, | ||
localized_proto, | ||
date; | ||
@@ -175,2 +174,3 @@ | ||
u.getTimezoneOffset = function () { return 0; }; | ||
u.getTimezoneName = function () { return 'UTC'; }; | ||
return u; | ||
@@ -452,3 +452,2 @@ } | ||
localized_proto = extend(proto); | ||
date = extend(proto); | ||
@@ -474,4 +473,4 @@ | ||
date._formatter = localized_proto._formatter = formatter; | ||
date._parser = localized_proto._parser = parser; | ||
date._formatter = formatter; | ||
date._parser = parser; | ||
@@ -513,3 +512,3 @@ for (var plugin in plugins) { | ||
if (install) { | ||
date.extend(plugins[install(proto, localized_proto)] || {}); | ||
date.extend(plugins[install(proto, date)] || {}); | ||
} | ||
@@ -516,0 +515,0 @@ }; |
/** | ||
* @preserve date-and-time (c) KNOWLEDGECODE | MIT | ||
*/ | ||
var e,t,n={},r={},i="en",u={MMMM:["January","February","March","April","May","June","July","August","September","October","November","December"],MMM:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],dddd:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],ddd:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],dd:["Su","Mo","Tu","We","Th","Fr","Sa"],A:["AM","PM"]},s={YYYY:function(e){return("000"+e.getFullYear()).slice(-4)},YY:function(e){return("0"+e.getFullYear()).slice(-2)},Y:function(e){return""+e.getFullYear()},MMMM:function(e){return this.res.MMMM[e.getMonth()]},MMM:function(e){return this.res.MMM[e.getMonth()]},MM:function(e){return("0"+(e.getMonth()+1)).slice(-2)},M:function(e){return""+(e.getMonth()+1)},DD:function(e){return("0"+e.getDate()).slice(-2)},D:function(e){return""+e.getDate()},HH:function(e){return("0"+e.getHours()).slice(-2)},H:function(e){return""+e.getHours()},A:function(e){return this.res.A[e.getHours()>11|0]},hh:function(e){return("0"+(e.getHours()%12||12)).slice(-2)},h:function(e){return""+(e.getHours()%12||12)},mm:function(e){return("0"+e.getMinutes()).slice(-2)},m:function(e){return""+e.getMinutes()},ss:function(e){return("0"+e.getSeconds()).slice(-2)},s:function(e){return""+e.getSeconds()},SSS:function(e){return("00"+e.getMilliseconds()).slice(-3)},SS:function(e){return("0"+(e.getMilliseconds()/10|0)).slice(-2)},S:function(e){return""+(e.getMilliseconds()/100|0)},dddd:function(e){return this.res.dddd[e.getDay()]},ddd:function(e){return this.res.ddd[e.getDay()]},dd:function(e){return this.res.dd[e.getDay()]},Z:function(e){var t=e.getTimezoneOffset()/.6|0;return(t>0?"-":"+")+("000"+Math.abs(t-(t%100*.4|0))).slice(-4)},ZZ:function(e){var t=e.getTimezoneOffset(),n=Math.abs(t);return(t>0?"-":"+")+("0"+(n/60|0)).slice(-2)+":"+("0"+n%60).slice(-2)},post:function(e){return e},res:u},o={YYYY:function(e){return this.exec(/^\d{4}/,e)},Y:function(e){return this.exec(/^\d{1,4}/,e)},MMMM:function(e){var t=this.find(this.res.MMMM,e);return t.value++,t},MMM:function(e){var t=this.find(this.res.MMM,e);return t.value++,t},MM:function(e){return this.exec(/^\d\d/,e)},M:function(e){return this.exec(/^\d\d?/,e)},DD:function(e){return this.exec(/^\d\d/,e)},D:function(e){return this.exec(/^\d\d?/,e)},HH:function(e){return this.exec(/^\d\d/,e)},H:function(e){return this.exec(/^\d\d?/,e)},A:function(e){return this.find(this.res.A,e)},hh:function(e){return this.exec(/^\d\d/,e)},h:function(e){return this.exec(/^\d\d?/,e)},mm:function(e){return this.exec(/^\d\d/,e)},m:function(e){return this.exec(/^\d\d?/,e)},ss:function(e){return this.exec(/^\d\d/,e)},s:function(e){return this.exec(/^\d\d?/,e)},SSS:function(e){return this.exec(/^\d{1,3}/,e)},SS:function(e){var t=this.exec(/^\d\d?/,e);return t.value*=10,t},S:function(e){var t=this.exec(/^\d/,e);return t.value*=100,t},Z:function(e){var t=this.exec(/^[+-]\d{2}[0-5]\d/,e);return t.value=-60*(t.value/100|0)-t.value%100,t},ZZ:function(e){var t=/^([+-])(\d{2}):([0-5]\d)/.exec(e)||["","","",""];return{value:0-(60*(t[1]+t[2]|0)+(t[1]+t[3]|0)),length:t[0].length}},h12:function(e,t){return(12===e?0:e)+12*t},exec:function(e,t){var n=(e.exec(t)||[""])[0];return{value:0|n,length:n.length}},find:function(e,t){for(var n,r=-1,i=0,u=0,s=e.length;u<s;u++)n=e[u],!t.indexOf(n)&&n.length>i&&(r=u,i=n.length);return{value:r,length:i}},pre:function(e){return e},res:u},a=function(e,t,n,r){var i,u={};for(i in e)u[i]=e[i];for(i in t||{})!!n^!!u[i]||(u[i]=t[i]);return r&&(u.res=r),u},c={_formatter:s,_parser:o};c.compile=function(e){return[e].concat(e.match(/\[(?:[^[\]]|\[[^[\]]*])*]|([A-Za-z])\1*|\.{3}|./g)||[])},c.format=function(e,n,r){for(var i,u=this||t,s="string"==typeof n?u.compile(n):n,o=u._formatter,a=function(){if(r){var t=new Date(e.getTime());return t.getFullYear=t.getUTCFullYear,t.getMonth=t.getUTCMonth,t.getDate=t.getUTCDate,t.getHours=t.getUTCHours,t.getMinutes=t.getUTCMinutes,t.getSeconds=t.getUTCSeconds,t.getMilliseconds=t.getUTCMilliseconds,t.getDay=t.getUTCDay,t.getTimezoneOffset=function(){return 0},t}return e}(),c=/^\[(.*)\]$/,d="",f=1,l=s.length;f<l;f++)d+=o[i=s[f]]?o.post(o[i](a,s[0])):c.test(i)?i.replace(c,"$1"):i;return d},c.preparse=function(e,n){var r=this||t,i="string"==typeof n?r.compile(n):n,u=r._parser,s={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},o=/^\[(.*)\]$/;e=u.pre(e);for(var a,c,d,f=1,l=i.length;f<l;f++)if(a=i[f],c=e.substring(s._index),u[a]){if(!(d=u[a](c,i[0])).length)break;s[d.token||a.charAt(0)]=d.value,s._index+=d.length,s._match++}else if(a===c.charAt(0)||" "===a)s._index++;else{if(!o.test(a)||c.indexOf(a.replace(o,"$1"))){if("..."===a){s._index=e.length;break}break}s._index+=a.length-2}return s.H=s.H||u.h12(s.h,s.A),s._length=e.length,s},c.parse=function(e,n,r){var i=this||t,u="string"==typeof n?i.compile(n):n,s=i.preparse(e,u);return i.isValid(s)?(s.M-=s.Y<100?22801:1,r||~i._parser.find(u,"ZZ").value?new Date(Date.UTC(s.Y,s.M,s.D,s.H,s.m+s.Z,s.s,s.S)):new Date(s.Y,s.M,s.D,s.H,s.m,s.s,s.S)):new Date(NaN)},c.isValid=function(e,n){var r="string"==typeof e?(this||t).preparse(e,n):e;return!(r._index<1||r._length<1||r._index-r._length||r._match<1||r.Y<1||r.Y>9999||r.M<1||r.M>12||r.D<1||r.D>new Date(r.Y,r.M,0).getDate()||r.H<0||r.H>23||r.m<0||r.m>59||r.s<0||r.s>59||r.S<0||r.S>999||r.Z<-840||r.Z>720)},c.transform=function(e,n,r,i){const u=this||t;return u.format(u.parse(e,n),r,i)},c.addYears=function(e,n,r){return(this||t).addMonths(e,12*n,r)},c.addMonths=function(e,n,r){var i=new Date(e.getTime());if(r){if(i.setUTCMonth(i.getUTCMonth()+n),i.getUTCDate()<e.getUTCDate())return(this||t).addDays(i,-i.getUTCDate(),r)}else if(i.setMonth(i.getMonth()+n),i.getDate()<e.getDate())return(this||t).addDays(i,-i.getDate(),r);return i},c.addDays=function(e,n,r){return(this||t).addHours(e,24*n,r)},c.addHours=function(e,n,r){return(this||t).addMinutes(e,60*n,r)},c.addMinutes=function(e,n,r){return(this||t).addSeconds(e,60*n,r)},c.addSeconds=function(e,n,r){return(this||t).addMilliseconds(e,1e3*n,r)},c.addMilliseconds=function(e,t,n){var r=new Date(e.getTime());return n?r.setUTCMilliseconds(r.getUTCMilliseconds()+t):r.setMilliseconds(r.getMilliseconds()+t),r},c.subtract=function(e,t){var n=e.getTime()-t.getTime();return{toMilliseconds:function(){return n},toSeconds:function(){return n/1e3},toMinutes:function(){return n/6e4},toHours:function(){return n/36e5},toDays:function(){return n/864e5}}},c.isLeapYear=function(e){return!((e%4||!(e%100))&&e%400)},c.isSameDay=function(e,t){return e.toDateString()===t.toDateString()},c.locale=function(e,t){n[e]||(n[e]=t)},c.plugin=function(e,t){r[e]||(r[e]=t)},e=a(c),(t=a(c)).locale=function(d){var f="function"==typeof d?d:t.locale[d];if(!f)return i;i=f(c);var l=n[i]||{},h=a(u,l.res,!0),g=a(s,l.formatter,!0,h),M=a(o,l.parser,!0,h);for(var D in t._formatter=e._formatter=g,t._parser=e._parser=M,r)t.extend(r[D]);return i},t.extend=function(e){var n=a(t._parser.res,e.res),r=e.extender||{};for(var i in t._formatter=a(t._formatter,e.formatter,!1,n),t._parser=a(t._parser,e.parser,!1,n),r)t[i]||(t[i]=r[i])},t.plugin=function(n){var i="function"==typeof n?n:t.plugin[n];i&&t.extend(r[i(c,e)]||{})};var d=t;export{d as default}; | ||
var e,t={},n={},r="en",i={MMMM:["January","February","March","April","May","June","July","August","September","October","November","December"],MMM:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],dddd:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],ddd:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],dd:["Su","Mo","Tu","We","Th","Fr","Sa"],A:["AM","PM"]},u={YYYY:function(e){return("000"+e.getFullYear()).slice(-4)},YY:function(e){return("0"+e.getFullYear()).slice(-2)},Y:function(e){return""+e.getFullYear()},MMMM:function(e){return this.res.MMMM[e.getMonth()]},MMM:function(e){return this.res.MMM[e.getMonth()]},MM:function(e){return("0"+(e.getMonth()+1)).slice(-2)},M:function(e){return""+(e.getMonth()+1)},DD:function(e){return("0"+e.getDate()).slice(-2)},D:function(e){return""+e.getDate()},HH:function(e){return("0"+e.getHours()).slice(-2)},H:function(e){return""+e.getHours()},A:function(e){return this.res.A[e.getHours()>11|0]},hh:function(e){return("0"+(e.getHours()%12||12)).slice(-2)},h:function(e){return""+(e.getHours()%12||12)},mm:function(e){return("0"+e.getMinutes()).slice(-2)},m:function(e){return""+e.getMinutes()},ss:function(e){return("0"+e.getSeconds()).slice(-2)},s:function(e){return""+e.getSeconds()},SSS:function(e){return("00"+e.getMilliseconds()).slice(-3)},SS:function(e){return("0"+(e.getMilliseconds()/10|0)).slice(-2)},S:function(e){return""+(e.getMilliseconds()/100|0)},dddd:function(e){return this.res.dddd[e.getDay()]},ddd:function(e){return this.res.ddd[e.getDay()]},dd:function(e){return this.res.dd[e.getDay()]},Z:function(e){var t=e.getTimezoneOffset()/.6|0;return(t>0?"-":"+")+("000"+Math.abs(t-(t%100*.4|0))).slice(-4)},ZZ:function(e){var t=e.getTimezoneOffset(),n=Math.abs(t);return(t>0?"-":"+")+("0"+(n/60|0)).slice(-2)+":"+("0"+n%60).slice(-2)},post:function(e){return e},res:i},s={YYYY:function(e){return this.exec(/^\d{4}/,e)},Y:function(e){return this.exec(/^\d{1,4}/,e)},MMMM:function(e){var t=this.find(this.res.MMMM,e);return t.value++,t},MMM:function(e){var t=this.find(this.res.MMM,e);return t.value++,t},MM:function(e){return this.exec(/^\d\d/,e)},M:function(e){return this.exec(/^\d\d?/,e)},DD:function(e){return this.exec(/^\d\d/,e)},D:function(e){return this.exec(/^\d\d?/,e)},HH:function(e){return this.exec(/^\d\d/,e)},H:function(e){return this.exec(/^\d\d?/,e)},A:function(e){return this.find(this.res.A,e)},hh:function(e){return this.exec(/^\d\d/,e)},h:function(e){return this.exec(/^\d\d?/,e)},mm:function(e){return this.exec(/^\d\d/,e)},m:function(e){return this.exec(/^\d\d?/,e)},ss:function(e){return this.exec(/^\d\d/,e)},s:function(e){return this.exec(/^\d\d?/,e)},SSS:function(e){return this.exec(/^\d{1,3}/,e)},SS:function(e){var t=this.exec(/^\d\d?/,e);return t.value*=10,t},S:function(e){var t=this.exec(/^\d/,e);return t.value*=100,t},Z:function(e){var t=this.exec(/^[+-]\d{2}[0-5]\d/,e);return t.value=-60*(t.value/100|0)-t.value%100,t},ZZ:function(e){var t=/^([+-])(\d{2}):([0-5]\d)/.exec(e)||["","","",""];return{value:0-(60*(t[1]+t[2]|0)+(t[1]+t[3]|0)),length:t[0].length}},h12:function(e,t){return(12===e?0:e)+12*t},exec:function(e,t){var n=(e.exec(t)||[""])[0];return{value:0|n,length:n.length}},find:function(e,t){for(var n,r=-1,i=0,u=0,s=e.length;u<s;u++)n=e[u],!t.indexOf(n)&&n.length>i&&(r=u,i=n.length);return{value:r,length:i}},pre:function(e){return e},res:i},o=function(e,t,n,r){var i,u={};for(i in e)u[i]=e[i];for(i in t||{})!!n^!!u[i]||(u[i]=t[i]);return r&&(u.res=r),u},a={_formatter:u,_parser:s};a.compile=function(e){return[e].concat(e.match(/\[(?:[^[\]]|\[[^[\]]*])*]|([A-Za-z])\1*|\.{3}|./g)||[])},a.format=function(t,n,r){for(var i,u=this||e,s="string"==typeof n?u.compile(n):n,o=u._formatter,a=function(){if(r){var e=new Date(t.getTime());return e.getFullYear=e.getUTCFullYear,e.getMonth=e.getUTCMonth,e.getDate=e.getUTCDate,e.getHours=e.getUTCHours,e.getMinutes=e.getUTCMinutes,e.getSeconds=e.getUTCSeconds,e.getMilliseconds=e.getUTCMilliseconds,e.getDay=e.getUTCDay,e.getTimezoneOffset=function(){return 0},e.getTimezoneName=function(){return"UTC"},e}return t}(),c=/^\[(.*)\]$/,d="",f=1,l=s.length;f<l;f++)d+=o[i=s[f]]?o.post(o[i](a,s[0])):c.test(i)?i.replace(c,"$1"):i;return d},a.preparse=function(t,n){var r=this||e,i="string"==typeof n?r.compile(n):n,u=r._parser,s={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},o=/^\[(.*)\]$/;t=u.pre(t);for(var a,c,d,f=1,l=i.length;f<l;f++)if(a=i[f],c=t.substring(s._index),u[a]){if(!(d=u[a](c,i[0])).length)break;s[d.token||a.charAt(0)]=d.value,s._index+=d.length,s._match++}else if(a===c.charAt(0)||" "===a)s._index++;else{if(!o.test(a)||c.indexOf(a.replace(o,"$1"))){if("..."===a){s._index=t.length;break}break}s._index+=a.length-2}return s.H=s.H||u.h12(s.h,s.A),s._length=t.length,s},a.parse=function(t,n,r){var i=this||e,u="string"==typeof n?i.compile(n):n,s=i.preparse(t,u);return i.isValid(s)?(s.M-=s.Y<100?22801:1,r||~i._parser.find(u,"ZZ").value?new Date(Date.UTC(s.Y,s.M,s.D,s.H,s.m+s.Z,s.s,s.S)):new Date(s.Y,s.M,s.D,s.H,s.m,s.s,s.S)):new Date(NaN)},a.isValid=function(t,n){var r="string"==typeof t?(this||e).preparse(t,n):t;return!(r._index<1||r._length<1||r._index-r._length||r._match<1||r.Y<1||r.Y>9999||r.M<1||r.M>12||r.D<1||r.D>new Date(r.Y,r.M,0).getDate()||r.H<0||r.H>23||r.m<0||r.m>59||r.s<0||r.s>59||r.S<0||r.S>999||r.Z<-840||r.Z>720)},a.transform=function(t,n,r,i){const u=this||e;return u.format(u.parse(t,n),r,i)},a.addYears=function(t,n,r){return(this||e).addMonths(t,12*n,r)},a.addMonths=function(t,n,r){var i=new Date(t.getTime());if(r){if(i.setUTCMonth(i.getUTCMonth()+n),i.getUTCDate()<t.getUTCDate())return(this||e).addDays(i,-i.getUTCDate(),r)}else if(i.setMonth(i.getMonth()+n),i.getDate()<t.getDate())return(this||e).addDays(i,-i.getDate(),r);return i},a.addDays=function(t,n,r){return(this||e).addHours(t,24*n,r)},a.addHours=function(t,n,r){return(this||e).addMinutes(t,60*n,r)},a.addMinutes=function(t,n,r){return(this||e).addSeconds(t,60*n,r)},a.addSeconds=function(t,n,r){return(this||e).addMilliseconds(t,1e3*n,r)},a.addMilliseconds=function(e,t,n){var r=new Date(e.getTime());return n?r.setUTCMilliseconds(r.getUTCMilliseconds()+t):r.setMilliseconds(r.getMilliseconds()+t),r},a.subtract=function(e,t){var n=e.getTime()-t.getTime();return{toMilliseconds:function(){return n},toSeconds:function(){return n/1e3},toMinutes:function(){return n/6e4},toHours:function(){return n/36e5},toDays:function(){return n/864e5}}},a.isLeapYear=function(e){return!((e%4||!(e%100))&&e%400)},a.isSameDay=function(e,t){return e.toDateString()===t.toDateString()},a.locale=function(e,n){t[e]||(t[e]=n)},a.plugin=function(e,t){n[e]||(n[e]=t)},(e=o(a)).locale=function(c){var d="function"==typeof c?c:e.locale[c];if(!d)return r;r=d(a);var f=t[r]||{},l=o(i,f.res,!0),h=o(u,f.formatter,!0,l),g=o(s,f.parser,!0,l);for(var M in e._formatter=h,e._parser=g,n)e.extend(n[M]);return r},e.extend=function(t){var n=o(e._parser.res,t.res),r=t.extender||{};for(var i in e._formatter=o(e._formatter,t.formatter,!1,n),e._parser=o(e._parser,t.parser,!1,n),r)e[i]||(e[i]=r[i])},e.plugin=function(t){var r="function"==typeof t?t:e.plugin[t];r&&e.extend(n[r(a,e)]||{})};var c=e;export{c as default}; |
@@ -6,8 +6,3 @@ /** | ||
var plugin = function (date, localized_date) { | ||
var options = { | ||
year: 'numeric', month: 'numeric', day: 'numeric', | ||
hour: 'numeric', minute: 'numeric', second: 'numeric' | ||
}; | ||
var pattern = date.compile('M/D/Y, h:mm:ss A'); | ||
var plugin = function (proto, date) { | ||
var timeZones = { | ||
@@ -459,28 +454,154 @@ africa: { | ||
}; | ||
var timeZoneNames = { | ||
'Acre Standard Time': 'ACT', 'Acre Summer Time': 'ACST', 'Afghanistan Time': 'AFT', | ||
'Alaska Daylight Time': 'AKDT', 'Alaska Standard Time': 'AKST', 'Almaty Standard Time': 'ALMT', | ||
'Almaty Summer Time': 'ALMST', 'Amazon Standard Time': 'AMT', 'Amazon Summer Time': 'AMST', | ||
'Anadyr Standard Time': 'ANAT', 'Anadyr Summer Time': 'ANAST', 'Apia Daylight Time': 'WSDT', | ||
'Apia Standard Time': 'WSST', 'Aqtau Standard Time': 'AQTT', 'Aqtau Summer Time': 'AQTT', | ||
'Aqtobe Standard Time': 'AQTT', 'Aqtobe Summer Time': 'AQST', 'Arabian Daylight Time': 'ADT', | ||
'Arabian Standard Time': 'AST', 'Argentina Standard Time': 'ART', 'Argentina Summer Time': 'ARST', | ||
'Armenia Standard Time': 'AMT', 'Armenia Summer Time': 'AMST', 'Atlantic Daylight Time': 'ADT', | ||
'Atlantic Standard Time': 'AST', 'Australian Central Daylight Time': 'ACDT', 'Australian Central Standard Time': 'ACST', | ||
'Australian Central Western Daylight Time': 'ACWDT', 'Australian Central Western Standard Time': 'ACWST', 'Australian Eastern Daylight Time': 'AEDT', | ||
'Australian Eastern Standard Time': 'AEST', 'Australian Western Daylight Time': 'AWDT', 'Australian Western Standard Time': 'AWST', | ||
'Azerbaijan Standard Time': 'AZT', 'Azerbaijan Summer Time': 'AZST', 'Azores Standard Time': 'AZOT', | ||
'Azores Summer Time': 'AZOST', 'Bangladesh Standard Time': 'BST', 'Bangladesh Summer Time': 'BDST', | ||
'Bhutan Time': 'BTT', 'Bolivia Time': 'BOT', 'Brasilia Standard Time': 'BRT', | ||
'Brasilia Summer Time': 'BRST', 'British Summer Time': 'BST', 'Brunei Darussalam Time': 'BNT', | ||
'Cape Verde Standard Time': 'CVT', 'Casey Time': 'CAST', 'Central Africa Time': 'CAT', | ||
'Central Daylight Time': 'CDT', 'Central European Standard Time': 'CET', 'Central European Summer Time': 'CEST', | ||
'Central Indonesia Time': 'WITA', 'Central Standard Time': 'CST', 'Chamorro Standard Time': 'ChST', | ||
'Chatham Daylight Time': 'CHADT', 'Chatham Standard Time': 'CHAST', 'Chile Standard Time': 'CLT', | ||
'Chile Summer Time': 'CLST', 'China Daylight Time': 'CDT', 'China Standard Time': 'CST', | ||
'Choibalsan Standard Time': 'CHOT', 'Choibalsan Summer Time': 'CHOST', 'Christmas Island Time': 'CXT', | ||
'Chuuk Time': 'CHUT', 'Cocos Islands Time': 'CCT', 'Colombia Standard Time': 'COT', | ||
'Colombia Summer Time': 'COST', 'Cook Islands Half Summer Time': 'CKHST', 'Cook Islands Standard Time': 'CKT', | ||
'Coordinated Universal Time': 'UTC', 'Cuba Daylight Time': 'CDT', 'Cuba Standard Time': 'CST', | ||
'Davis Time': 'DAVT', 'Dumont-d’Urville Time': 'DDUT', 'East Africa Time': 'EAT', | ||
'East Greenland Standard Time': 'EGST', 'East Greenland Summer Time': 'EGST', 'East Kazakhstan Time': 'ALMT', | ||
'East Timor Time': 'TLT', 'Easter Island Standard Time': 'EAST', 'Easter Island Summer Time': 'EASST', | ||
'Eastern Daylight Time': 'EDT', 'Eastern European Standard Time': 'EET', 'Eastern European Summer Time': 'EEST', | ||
'Eastern Indonesia Time': 'WIT', 'Eastern Standard Time': 'EST', 'Ecuador Time': 'ECT', | ||
'Falkland Islands Standard Time': 'FKST', 'Falkland Islands Summer Time': 'FKDT', 'Fernando de Noronha Standard Time': 'FNT', | ||
'Fernando de Noronha Summer Time': 'FNST', 'Fiji Standard Time': 'FJT', 'Fiji Summer Time': 'FJST', | ||
'French Guiana Time': 'GFT', 'French Southern & Antarctic Time': 'TFT', 'Further-eastern European Time': 'FET', | ||
'GMT': 'GMT', 'Galapagos Time': 'GALT', 'Gambier Time': 'GAMT', | ||
'Georgia Standard Time': 'GET', 'Georgia Summer Time': 'GEST', 'Gilbert Islands Time': 'GILT', | ||
'Greenwich Mean Time': 'GMT', 'Guam Standard Time': 'ChST', 'Gulf Standard Time': 'GST', | ||
'Guyana Time': 'GYT', 'Hawaii-Aleutian Daylight Time': 'HADT', 'Hawaii-Aleutian Standard Time': 'HAST', | ||
'Hong Kong Standard Time': 'HKT', 'Hong Kong Summer Time': 'HKST', 'Hovd Standard Time': 'HOVT', | ||
'Hovd Summer Time': 'HOVST', 'India Standard Time': 'IST', 'Indian Ocean Time': 'IOT', | ||
'Indochina Time': 'ICT', 'Iran Daylight Time': 'IRDT', 'Iran Standard Time': 'IRST', | ||
'Irish Standard Time': 'IST', 'Irkutsk Standard Time': 'IRKT', 'Irkutsk Summer Time': 'IRKST', | ||
'Israel Daylight Time': 'IDT', 'Israel Standard Time': 'IST', 'Japan Standard Time': 'JST', | ||
'Korean Daylight Time': 'KDT', 'Korean Standard Time': 'KST', 'Kosrae Time': 'KOST', | ||
'Krasnoyarsk Standard Time': 'KRAT', 'Krasnoyarsk Summer Time': 'KRAST', 'Kyrgyzstan Time': 'KGT', | ||
'Lanka Time': 'LKT', 'Line Islands Time': 'LINT', 'Lord Howe Daylight Time': 'LHDT', | ||
'Lord Howe Standard Time': 'LHST', 'Macao Standard Time': 'CST', 'Macao Summer Time': 'CDST', | ||
'Magadan Standard Time': 'MAGT', 'Magadan Summer Time': 'MAGST', 'Malaysia Time': 'MYT', | ||
'Maldives Time': 'MVT', 'Marquesas Time': 'MART', 'Marshall Islands Time': 'MHT', | ||
'Mauritius Standard Time': 'MUT', 'Mauritius Summer Time': 'MUST', 'Mawson Time': 'MAWT', | ||
'Mexican Pacific Daylight Time': 'PDT', 'Mexican Pacific Standard Time': 'PST', 'Moscow Standard Time': 'MSK', | ||
'Moscow Summer Time': 'MSD', 'Mountain Daylight Time': 'MDT', 'Mountain Standard Time': 'MST', | ||
'Myanmar Time': 'MMT', 'Nauru Time': 'NRT', 'Nepal Time': 'NPT', | ||
'New Caledonia Standard Time': 'NCT', 'New Caledonia Summer Time': 'NCST', 'New Zealand Daylight Time': 'NZDT', | ||
'New Zealand Standard Time': 'NZST', 'Newfoundland Daylight Time': 'NDT', 'Newfoundland Standard Time': 'NST', | ||
'Niue Time': 'NUT', 'Norfolk Island Daylight Time': 'NFDT', 'Norfolk Island Standard Time': 'NFT', | ||
'North Mariana Islands Time': 'ChST', 'Novosibirsk Standard Time': 'NOVT', 'Novosibirsk Summer Time': 'NOVST', | ||
'Omsk Standard Time': 'OMST', 'Omsk Summer Time': 'OMSST', 'Pacific Daylight Time': 'PDT', | ||
'Pacific Standard Time': 'PST', 'Pakistan Standard Time': 'PKT', 'Pakistan Summer Time': 'PKST', | ||
'Palau Time': 'PWT', 'Papua New Guinea Time': 'PGT', 'Paraguay Standard Time': 'PYST', | ||
'Paraguay Summer Time': 'PYST', 'Peru Standard Time': 'PET', 'Peru Summer Time': 'PEST', | ||
'Petropavlovsk-Kamchatski Standard Time': 'PETT', 'Petropavlovsk-Kamchatski Summer Time': 'PETST', 'Philippine Standard Time': 'PST', | ||
'Philippine Summer Time': 'PHST', 'Phoenix Islands Time': 'PHOT', 'Pitcairn Time': 'PIT', | ||
'Ponape Time': 'PONT', 'Pyongyang Time': 'KST', 'Qyzylorda Standard Time': 'QYZT', | ||
'Qyzylorda Summer Time': 'QYZST', 'Rothera Time': 'ROOTT', 'Réunion Time': 'RET', | ||
'Sakhalin Standard Time': 'SAKT', 'Sakhalin Summer Time': 'SAKST', 'Samara Standard Time': 'SAMT', | ||
'Samara Summer Time': 'SAMST', 'Samoa Standard Time': 'SST', 'Seychelles Time': 'SCT', | ||
'Singapore Standard Time': 'SGT', 'Solomon Islands Time': 'SBT', 'South Africa Standard Time': 'SAST', | ||
'South Georgia Time': 'GST', 'St. Pierre & Miquelon Daylight Time': 'PMDT', 'St. Pierre & Miquelon Standard Time': 'PMST', | ||
'Suriname Time': 'SRT', 'Syowa Time': 'SYOT', 'Tahiti Time': 'TAHT', | ||
'Taipei Daylight Time': 'TDT', 'Taipei Standard Time': 'CST', 'Tajikistan Time': 'TJT', | ||
'Tokelau Time': 'TKT', 'Tonga Standard Time': 'TOT', 'Tonga Summer Time': 'TOST', | ||
'Turkmenistan Standard Time': 'TMT', 'Tuvalu Time': 'TVT', 'Ulaanbaatar Standard Time': 'ULAT', | ||
'Ulaanbaatar Summer Time': 'ULAST', 'Uruguay Standard Time': 'UYT', 'Uruguay Summer Time': 'UYST', | ||
'Uzbekistan Standard Time': 'UZT', 'Uzbekistan Summer Time': 'UZST', 'Vanuatu Standard Time': 'VUT', | ||
'Vanuatu Summer Time': 'VUST', 'Venezuela Time': 'VET', 'Vladivostok Standard Time': 'VLAT', | ||
'Vladivostok Summer Time': 'VLAST', 'Volgograd Standard Time': 'VOLT', 'Volgograd Summer Time': 'VOLST', | ||
'Vostok Time': 'VOST', 'Wake Island Time': 'WAKT', 'Wallis & Futuna Time': 'WFT', | ||
'West Africa Standard Time': 'WAT', 'West Africa Summer Time': 'WAST', 'West Greenland Standard Time': 'WGST', | ||
'West Greenland Summer Time': 'WGST', 'West Kazakhstan Time': 'AQTT', 'Western Argentina Standard Time': 'ART', | ||
'Western Argentina Summer Time': 'ARST', 'Western European Standard Time': 'WET', 'Western European Summer Time': 'WEST', | ||
'Western Indonesia Time': 'WIB', 'Yakutsk Standard Time': 'YAKT', 'Yakutsk Summer Time': 'YAKST', | ||
'Yekaterinburg Standard Time': 'YEKT', 'Yekaterinburg Summer Time': 'YEKST', 'Yukon Time': 'YT' | ||
}; | ||
var options = { | ||
hour12: false, weekday: 'short', year: 'numeric', month: 'numeric', day: 'numeric', | ||
hour: 'numeric', minute: 'numeric', second: 'numeric', fractionalSecondDigits: 3 | ||
}; | ||
var formatTZ = function (dateObj, arg, timeZone) { | ||
options.timeZone = 'UTC'; | ||
var utcObj = date.parse(new Intl.DateTimeFormat('en-US', options).format(dateObj), pattern); | ||
utcObj.setMilliseconds(dateObj.getMilliseconds()); | ||
var parts = (function () { | ||
options.timeZone = timeZone || undefined; | ||
var array = new Intl.DateTimeFormat('en-US', options).formatToParts(dateObj); | ||
var values = {}; | ||
options.timeZone = timeZone; | ||
var dateObj2 = date.parse(new Intl.DateTimeFormat('en-US', options).format(dateObj), pattern); | ||
dateObj2.setMilliseconds(dateObj.getMilliseconds()); | ||
for (var i = 0, len = array.length; i < len; i++) { | ||
var type = array[i].type; | ||
var value = array[i].value; | ||
dateObj2.getTimezoneOffset = function () { return (utcObj.getTime() - dateObj2.getTime()) / 60000 | 0; }; | ||
switch (type) { | ||
case 'weekday': | ||
values[type] = 'SunMonTueWedThuFriSat'.indexOf(value) / 3; | ||
break; | ||
case 'year': | ||
case 'month': | ||
case 'day': | ||
case 'hour': | ||
case 'minute': | ||
case 'second': | ||
case 'fractionalSecond': | ||
values[type] = value | 0; | ||
} | ||
} | ||
return values; | ||
}()); | ||
return localized_date.format(dateObj2, arg); | ||
return date.format({ | ||
getFullYear: function () { return parts.year; }, | ||
getMonth: function () { return parts.month - 1; }, | ||
getDate: function () { return parts.day; }, | ||
getHours: function () { return parts.hour; }, | ||
getMinutes: function () { return parts.minute; }, | ||
getSeconds: function () { return parts.second; }, | ||
getMilliseconds: function () { return parts.fractionalSecond; }, | ||
getDay: function () { return parts.weekday; }, | ||
getTime: function () { return dateObj.getTime(); }, | ||
getTimezoneOffset: function () { | ||
return (dateObj.getTime() - Date.UTC( | ||
parts.year, parts.month - (parts.year < 100 ? 1900 * 12 + 1 : 1), parts.day, | ||
parts.hour, parts.minute, parts.second, parts.fractionalSecond | ||
)) / 60000 | 0; | ||
}, | ||
getTimezoneName: function () { return timeZone || undefined; } | ||
}, arg); | ||
}; | ||
var parseTZ = function (dateString, arg, timeZone) { | ||
var pattern2 = typeof arg === 'string' ? date.compile(arg) : arg; | ||
var dateObj = localized_date.parse(dateString, pattern2, !!timeZone); | ||
var pattern = typeof arg === 'string' ? date.compile(arg) : arg; | ||
var dateObj = date.parse(dateString, pattern, !!timeZone); | ||
if (!timeZone || ~date._parser.find(pattern2, 'ZZ').value || timeZone.toLowerCase() === 'utc') { | ||
var hasZ = function (array) { | ||
for (var i = 1, len = array.length; i < len; i++) { | ||
if (!array[i].indexOf('Z')) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
if (!timeZone || hasZ(pattern) || timeZone.toUpperCase() === 'UTC') { | ||
return dateObj; | ||
} | ||
options.timeZone = timeZone; | ||
var dateTimeFormat = new Intl.DateTimeFormat('en-US', options); | ||
var dateString2 = date.format(dateObj, pattern, true); | ||
var offset = (function () { | ||
var keys = timeZone.toLowerCase().split('/'); | ||
var getOffset = function (timeZoneName) { | ||
var keys = (timeZoneName || '').toLowerCase().split('/'); | ||
var value = timeZones[keys[0]] || {}; | ||
@@ -492,5 +613,11 @@ | ||
return Array.isArray(value) ? value : []; | ||
})(); | ||
}; | ||
options.timeZone = 'UTC'; | ||
var dateString2 = new Intl.DateTimeFormat('en-US', options).format(dateObj); | ||
options.timeZone = timeZone || undefined; | ||
var dateTimeFormat = new Intl.DateTimeFormat('en-US', options); | ||
var offset = getOffset(timeZone); | ||
var comparer = function (d) { | ||
return dateString2 === dateTimeFormat.format(d).replace(/[\u202f]/, ' '); | ||
return dateString2 === dateTimeFormat.format(d); | ||
}; | ||
@@ -507,3 +634,3 @@ | ||
var transformTZ = function (dateString, arg1, arg2, timeZone) { | ||
return formatTZ(localized_date.parse(dateString, arg1), arg2, timeZone); | ||
return formatTZ(date.parse(dateString, arg1), arg2, timeZone); | ||
}; | ||
@@ -513,3 +640,27 @@ | ||
date.plugin(name, { | ||
var getName = function (d) { | ||
var parts = new Intl.DateTimeFormat('en-US', { | ||
timeZone: typeof d.getTimezoneName === 'function' ? d.getTimezoneName() : undefined, | ||
timeZoneName: 'long' | ||
}).formatToParts(d.getTime()); | ||
for (var i = 0, len = parts.length; i < len; i++) { | ||
if (parts[i].type === 'timeZoneName') { | ||
return parts[i].value; | ||
} | ||
} | ||
return ''; | ||
}; | ||
proto.plugin(name, { | ||
formatter: { | ||
z: function (d) { | ||
var name = getName(d); | ||
return timeZoneNames[name] || ''; | ||
}, | ||
zz: function (d) { | ||
var name = getName(d); | ||
return /^GMT[+-].+$/.test(name) ? '' : name; | ||
} | ||
}, | ||
extender: { | ||
@@ -516,0 +667,0 @@ formatTZ: formatTZ, |
{ | ||
"name": "date-and-time", | ||
"version": "3.3.0", | ||
"version": "3.4.0", | ||
"description": "A Minimalist DateTime utility for Node.js and the browser", | ||
@@ -54,6 +54,6 @@ "main": "date-and-time.js", | ||
"expect.js": "^0.3.1", | ||
"mocha": "^10.4.0", | ||
"rollup": "^4.17.2", | ||
"tsd": "^0.31.0" | ||
"mocha": "^10.6.0", | ||
"rollup": "^4.18.0", | ||
"tsd": "^0.31.1" | ||
} | ||
} |
@@ -1,1 +0,1 @@ | ||
export default function (date: unknown, localized_date?: unknown): string; | ||
export default function (proto: unknown, date?: unknown): string; |
@@ -1,1 +0,1 @@ | ||
export default function (date: unknown, localized_date?: unknown): string; | ||
export default function (proto: unknown, date?: unknown): string; |
@@ -1,1 +0,1 @@ | ||
export default function (date: unknown, localized_date?: unknown): string; | ||
export default function (proto: unknown, date?: unknown): string; |
@@ -1,1 +0,1 @@ | ||
export default function (date: unknown, localized_date?: unknown): string; | ||
export default function (proto: unknown, date?: unknown): string; |
@@ -24,2 +24,2 @@ declare module '../date-and-time' { | ||
export default function (date: unknown, localized_date?: unknown): string; | ||
export default function (proto: unknown, date?: unknown): string; |
@@ -79,2 +79,2 @@ declare module '../date-and-time' { | ||
export default function (date: unknown, localized_date?: unknown): string; | ||
export default function (proto: unknown, date?: unknown): string; |
@@ -12,8 +12,3 @@ (function (global, factory) { | ||
var plugin = function (date, localized_date) { | ||
var options = { | ||
year: 'numeric', month: 'numeric', day: 'numeric', | ||
hour: 'numeric', minute: 'numeric', second: 'numeric' | ||
}; | ||
var pattern = date.compile('M/D/Y, h:mm:ss A'); | ||
var plugin = function (proto, date) { | ||
var timeZones = { | ||
@@ -465,28 +460,154 @@ africa: { | ||
}; | ||
var timeZoneNames = { | ||
'Acre Standard Time': 'ACT', 'Acre Summer Time': 'ACST', 'Afghanistan Time': 'AFT', | ||
'Alaska Daylight Time': 'AKDT', 'Alaska Standard Time': 'AKST', 'Almaty Standard Time': 'ALMT', | ||
'Almaty Summer Time': 'ALMST', 'Amazon Standard Time': 'AMT', 'Amazon Summer Time': 'AMST', | ||
'Anadyr Standard Time': 'ANAT', 'Anadyr Summer Time': 'ANAST', 'Apia Daylight Time': 'WSDT', | ||
'Apia Standard Time': 'WSST', 'Aqtau Standard Time': 'AQTT', 'Aqtau Summer Time': 'AQTT', | ||
'Aqtobe Standard Time': 'AQTT', 'Aqtobe Summer Time': 'AQST', 'Arabian Daylight Time': 'ADT', | ||
'Arabian Standard Time': 'AST', 'Argentina Standard Time': 'ART', 'Argentina Summer Time': 'ARST', | ||
'Armenia Standard Time': 'AMT', 'Armenia Summer Time': 'AMST', 'Atlantic Daylight Time': 'ADT', | ||
'Atlantic Standard Time': 'AST', 'Australian Central Daylight Time': 'ACDT', 'Australian Central Standard Time': 'ACST', | ||
'Australian Central Western Daylight Time': 'ACWDT', 'Australian Central Western Standard Time': 'ACWST', 'Australian Eastern Daylight Time': 'AEDT', | ||
'Australian Eastern Standard Time': 'AEST', 'Australian Western Daylight Time': 'AWDT', 'Australian Western Standard Time': 'AWST', | ||
'Azerbaijan Standard Time': 'AZT', 'Azerbaijan Summer Time': 'AZST', 'Azores Standard Time': 'AZOT', | ||
'Azores Summer Time': 'AZOST', 'Bangladesh Standard Time': 'BST', 'Bangladesh Summer Time': 'BDST', | ||
'Bhutan Time': 'BTT', 'Bolivia Time': 'BOT', 'Brasilia Standard Time': 'BRT', | ||
'Brasilia Summer Time': 'BRST', 'British Summer Time': 'BST', 'Brunei Darussalam Time': 'BNT', | ||
'Cape Verde Standard Time': 'CVT', 'Casey Time': 'CAST', 'Central Africa Time': 'CAT', | ||
'Central Daylight Time': 'CDT', 'Central European Standard Time': 'CET', 'Central European Summer Time': 'CEST', | ||
'Central Indonesia Time': 'WITA', 'Central Standard Time': 'CST', 'Chamorro Standard Time': 'ChST', | ||
'Chatham Daylight Time': 'CHADT', 'Chatham Standard Time': 'CHAST', 'Chile Standard Time': 'CLT', | ||
'Chile Summer Time': 'CLST', 'China Daylight Time': 'CDT', 'China Standard Time': 'CST', | ||
'Choibalsan Standard Time': 'CHOT', 'Choibalsan Summer Time': 'CHOST', 'Christmas Island Time': 'CXT', | ||
'Chuuk Time': 'CHUT', 'Cocos Islands Time': 'CCT', 'Colombia Standard Time': 'COT', | ||
'Colombia Summer Time': 'COST', 'Cook Islands Half Summer Time': 'CKHST', 'Cook Islands Standard Time': 'CKT', | ||
'Coordinated Universal Time': 'UTC', 'Cuba Daylight Time': 'CDT', 'Cuba Standard Time': 'CST', | ||
'Davis Time': 'DAVT', 'Dumont-d’Urville Time': 'DDUT', 'East Africa Time': 'EAT', | ||
'East Greenland Standard Time': 'EGST', 'East Greenland Summer Time': 'EGST', 'East Kazakhstan Time': 'ALMT', | ||
'East Timor Time': 'TLT', 'Easter Island Standard Time': 'EAST', 'Easter Island Summer Time': 'EASST', | ||
'Eastern Daylight Time': 'EDT', 'Eastern European Standard Time': 'EET', 'Eastern European Summer Time': 'EEST', | ||
'Eastern Indonesia Time': 'WIT', 'Eastern Standard Time': 'EST', 'Ecuador Time': 'ECT', | ||
'Falkland Islands Standard Time': 'FKST', 'Falkland Islands Summer Time': 'FKDT', 'Fernando de Noronha Standard Time': 'FNT', | ||
'Fernando de Noronha Summer Time': 'FNST', 'Fiji Standard Time': 'FJT', 'Fiji Summer Time': 'FJST', | ||
'French Guiana Time': 'GFT', 'French Southern & Antarctic Time': 'TFT', 'Further-eastern European Time': 'FET', | ||
'GMT': 'GMT', 'Galapagos Time': 'GALT', 'Gambier Time': 'GAMT', | ||
'Georgia Standard Time': 'GET', 'Georgia Summer Time': 'GEST', 'Gilbert Islands Time': 'GILT', | ||
'Greenwich Mean Time': 'GMT', 'Guam Standard Time': 'ChST', 'Gulf Standard Time': 'GST', | ||
'Guyana Time': 'GYT', 'Hawaii-Aleutian Daylight Time': 'HADT', 'Hawaii-Aleutian Standard Time': 'HAST', | ||
'Hong Kong Standard Time': 'HKT', 'Hong Kong Summer Time': 'HKST', 'Hovd Standard Time': 'HOVT', | ||
'Hovd Summer Time': 'HOVST', 'India Standard Time': 'IST', 'Indian Ocean Time': 'IOT', | ||
'Indochina Time': 'ICT', 'Iran Daylight Time': 'IRDT', 'Iran Standard Time': 'IRST', | ||
'Irish Standard Time': 'IST', 'Irkutsk Standard Time': 'IRKT', 'Irkutsk Summer Time': 'IRKST', | ||
'Israel Daylight Time': 'IDT', 'Israel Standard Time': 'IST', 'Japan Standard Time': 'JST', | ||
'Korean Daylight Time': 'KDT', 'Korean Standard Time': 'KST', 'Kosrae Time': 'KOST', | ||
'Krasnoyarsk Standard Time': 'KRAT', 'Krasnoyarsk Summer Time': 'KRAST', 'Kyrgyzstan Time': 'KGT', | ||
'Lanka Time': 'LKT', 'Line Islands Time': 'LINT', 'Lord Howe Daylight Time': 'LHDT', | ||
'Lord Howe Standard Time': 'LHST', 'Macao Standard Time': 'CST', 'Macao Summer Time': 'CDST', | ||
'Magadan Standard Time': 'MAGT', 'Magadan Summer Time': 'MAGST', 'Malaysia Time': 'MYT', | ||
'Maldives Time': 'MVT', 'Marquesas Time': 'MART', 'Marshall Islands Time': 'MHT', | ||
'Mauritius Standard Time': 'MUT', 'Mauritius Summer Time': 'MUST', 'Mawson Time': 'MAWT', | ||
'Mexican Pacific Daylight Time': 'PDT', 'Mexican Pacific Standard Time': 'PST', 'Moscow Standard Time': 'MSK', | ||
'Moscow Summer Time': 'MSD', 'Mountain Daylight Time': 'MDT', 'Mountain Standard Time': 'MST', | ||
'Myanmar Time': 'MMT', 'Nauru Time': 'NRT', 'Nepal Time': 'NPT', | ||
'New Caledonia Standard Time': 'NCT', 'New Caledonia Summer Time': 'NCST', 'New Zealand Daylight Time': 'NZDT', | ||
'New Zealand Standard Time': 'NZST', 'Newfoundland Daylight Time': 'NDT', 'Newfoundland Standard Time': 'NST', | ||
'Niue Time': 'NUT', 'Norfolk Island Daylight Time': 'NFDT', 'Norfolk Island Standard Time': 'NFT', | ||
'North Mariana Islands Time': 'ChST', 'Novosibirsk Standard Time': 'NOVT', 'Novosibirsk Summer Time': 'NOVST', | ||
'Omsk Standard Time': 'OMST', 'Omsk Summer Time': 'OMSST', 'Pacific Daylight Time': 'PDT', | ||
'Pacific Standard Time': 'PST', 'Pakistan Standard Time': 'PKT', 'Pakistan Summer Time': 'PKST', | ||
'Palau Time': 'PWT', 'Papua New Guinea Time': 'PGT', 'Paraguay Standard Time': 'PYST', | ||
'Paraguay Summer Time': 'PYST', 'Peru Standard Time': 'PET', 'Peru Summer Time': 'PEST', | ||
'Petropavlovsk-Kamchatski Standard Time': 'PETT', 'Petropavlovsk-Kamchatski Summer Time': 'PETST', 'Philippine Standard Time': 'PST', | ||
'Philippine Summer Time': 'PHST', 'Phoenix Islands Time': 'PHOT', 'Pitcairn Time': 'PIT', | ||
'Ponape Time': 'PONT', 'Pyongyang Time': 'KST', 'Qyzylorda Standard Time': 'QYZT', | ||
'Qyzylorda Summer Time': 'QYZST', 'Rothera Time': 'ROOTT', 'Réunion Time': 'RET', | ||
'Sakhalin Standard Time': 'SAKT', 'Sakhalin Summer Time': 'SAKST', 'Samara Standard Time': 'SAMT', | ||
'Samara Summer Time': 'SAMST', 'Samoa Standard Time': 'SST', 'Seychelles Time': 'SCT', | ||
'Singapore Standard Time': 'SGT', 'Solomon Islands Time': 'SBT', 'South Africa Standard Time': 'SAST', | ||
'South Georgia Time': 'GST', 'St. Pierre & Miquelon Daylight Time': 'PMDT', 'St. Pierre & Miquelon Standard Time': 'PMST', | ||
'Suriname Time': 'SRT', 'Syowa Time': 'SYOT', 'Tahiti Time': 'TAHT', | ||
'Taipei Daylight Time': 'TDT', 'Taipei Standard Time': 'CST', 'Tajikistan Time': 'TJT', | ||
'Tokelau Time': 'TKT', 'Tonga Standard Time': 'TOT', 'Tonga Summer Time': 'TOST', | ||
'Turkmenistan Standard Time': 'TMT', 'Tuvalu Time': 'TVT', 'Ulaanbaatar Standard Time': 'ULAT', | ||
'Ulaanbaatar Summer Time': 'ULAST', 'Uruguay Standard Time': 'UYT', 'Uruguay Summer Time': 'UYST', | ||
'Uzbekistan Standard Time': 'UZT', 'Uzbekistan Summer Time': 'UZST', 'Vanuatu Standard Time': 'VUT', | ||
'Vanuatu Summer Time': 'VUST', 'Venezuela Time': 'VET', 'Vladivostok Standard Time': 'VLAT', | ||
'Vladivostok Summer Time': 'VLAST', 'Volgograd Standard Time': 'VOLT', 'Volgograd Summer Time': 'VOLST', | ||
'Vostok Time': 'VOST', 'Wake Island Time': 'WAKT', 'Wallis & Futuna Time': 'WFT', | ||
'West Africa Standard Time': 'WAT', 'West Africa Summer Time': 'WAST', 'West Greenland Standard Time': 'WGST', | ||
'West Greenland Summer Time': 'WGST', 'West Kazakhstan Time': 'AQTT', 'Western Argentina Standard Time': 'ART', | ||
'Western Argentina Summer Time': 'ARST', 'Western European Standard Time': 'WET', 'Western European Summer Time': 'WEST', | ||
'Western Indonesia Time': 'WIB', 'Yakutsk Standard Time': 'YAKT', 'Yakutsk Summer Time': 'YAKST', | ||
'Yekaterinburg Standard Time': 'YEKT', 'Yekaterinburg Summer Time': 'YEKST', 'Yukon Time': 'YT' | ||
}; | ||
var options = { | ||
hour12: false, weekday: 'short', year: 'numeric', month: 'numeric', day: 'numeric', | ||
hour: 'numeric', minute: 'numeric', second: 'numeric', fractionalSecondDigits: 3 | ||
}; | ||
var formatTZ = function (dateObj, arg, timeZone) { | ||
options.timeZone = 'UTC'; | ||
var utcObj = date.parse(new Intl.DateTimeFormat('en-US', options).format(dateObj), pattern); | ||
utcObj.setMilliseconds(dateObj.getMilliseconds()); | ||
var parts = (function () { | ||
options.timeZone = timeZone || undefined; | ||
var array = new Intl.DateTimeFormat('en-US', options).formatToParts(dateObj); | ||
var values = {}; | ||
options.timeZone = timeZone; | ||
var dateObj2 = date.parse(new Intl.DateTimeFormat('en-US', options).format(dateObj), pattern); | ||
dateObj2.setMilliseconds(dateObj.getMilliseconds()); | ||
for (var i = 0, len = array.length; i < len; i++) { | ||
var type = array[i].type; | ||
var value = array[i].value; | ||
dateObj2.getTimezoneOffset = function () { return (utcObj.getTime() - dateObj2.getTime()) / 60000 | 0; }; | ||
switch (type) { | ||
case 'weekday': | ||
values[type] = 'SunMonTueWedThuFriSat'.indexOf(value) / 3; | ||
break; | ||
case 'year': | ||
case 'month': | ||
case 'day': | ||
case 'hour': | ||
case 'minute': | ||
case 'second': | ||
case 'fractionalSecond': | ||
values[type] = value | 0; | ||
} | ||
} | ||
return values; | ||
}()); | ||
return localized_date.format(dateObj2, arg); | ||
return date.format({ | ||
getFullYear: function () { return parts.year; }, | ||
getMonth: function () { return parts.month - 1; }, | ||
getDate: function () { return parts.day; }, | ||
getHours: function () { return parts.hour; }, | ||
getMinutes: function () { return parts.minute; }, | ||
getSeconds: function () { return parts.second; }, | ||
getMilliseconds: function () { return parts.fractionalSecond; }, | ||
getDay: function () { return parts.weekday; }, | ||
getTime: function () { return dateObj.getTime(); }, | ||
getTimezoneOffset: function () { | ||
return (dateObj.getTime() - Date.UTC( | ||
parts.year, parts.month - (parts.year < 100 ? 1900 * 12 + 1 : 1), parts.day, | ||
parts.hour, parts.minute, parts.second, parts.fractionalSecond | ||
)) / 60000 | 0; | ||
}, | ||
getTimezoneName: function () { return timeZone || undefined; } | ||
}, arg); | ||
}; | ||
var parseTZ = function (dateString, arg, timeZone) { | ||
var pattern2 = typeof arg === 'string' ? date.compile(arg) : arg; | ||
var dateObj = localized_date.parse(dateString, pattern2, !!timeZone); | ||
var pattern = typeof arg === 'string' ? date.compile(arg) : arg; | ||
var dateObj = date.parse(dateString, pattern, !!timeZone); | ||
if (!timeZone || ~date._parser.find(pattern2, 'ZZ').value || timeZone.toLowerCase() === 'utc') { | ||
var hasZ = function (array) { | ||
for (var i = 1, len = array.length; i < len; i++) { | ||
if (!array[i].indexOf('Z')) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
if (!timeZone || hasZ(pattern) || timeZone.toUpperCase() === 'UTC') { | ||
return dateObj; | ||
} | ||
options.timeZone = timeZone; | ||
var dateTimeFormat = new Intl.DateTimeFormat('en-US', options); | ||
var dateString2 = date.format(dateObj, pattern, true); | ||
var offset = (function () { | ||
var keys = timeZone.toLowerCase().split('/'); | ||
var getOffset = function (timeZoneName) { | ||
var keys = (timeZoneName || '').toLowerCase().split('/'); | ||
var value = timeZones[keys[0]] || {}; | ||
@@ -498,5 +619,11 @@ | ||
return Array.isArray(value) ? value : []; | ||
})(); | ||
}; | ||
options.timeZone = 'UTC'; | ||
var dateString2 = new Intl.DateTimeFormat('en-US', options).format(dateObj); | ||
options.timeZone = timeZone || undefined; | ||
var dateTimeFormat = new Intl.DateTimeFormat('en-US', options); | ||
var offset = getOffset(timeZone); | ||
var comparer = function (d) { | ||
return dateString2 === dateTimeFormat.format(d).replace(/[\u202f]/, ' '); | ||
return dateString2 === dateTimeFormat.format(d); | ||
}; | ||
@@ -513,3 +640,3 @@ | ||
var transformTZ = function (dateString, arg1, arg2, timeZone) { | ||
return formatTZ(localized_date.parse(dateString, arg1), arg2, timeZone); | ||
return formatTZ(date.parse(dateString, arg1), arg2, timeZone); | ||
}; | ||
@@ -519,3 +646,27 @@ | ||
date.plugin(name, { | ||
var getName = function (d) { | ||
var parts = new Intl.DateTimeFormat('en-US', { | ||
timeZone: typeof d.getTimezoneName === 'function' ? d.getTimezoneName() : undefined, | ||
timeZoneName: 'long' | ||
}).formatToParts(d.getTime()); | ||
for (var i = 0, len = parts.length; i < len; i++) { | ||
if (parts[i].type === 'timeZoneName') { | ||
return parts[i].value; | ||
} | ||
} | ||
return ''; | ||
}; | ||
proto.plugin(name, { | ||
formatter: { | ||
z: function (d) { | ||
var name = getName(d); | ||
return timeZoneNames[name] || ''; | ||
}, | ||
zz: function (d) { | ||
var name = getName(d); | ||
return /^GMT[+-].+$/.test(name) ? '' : name; | ||
} | ||
}, | ||
extender: { | ||
@@ -522,0 +673,0 @@ formatTZ: formatTZ, |
@@ -1,1 +0,1 @@ | ||
export default function (date: unknown, localized_date?: unknown): string; | ||
export default function (proto: unknown, date?: unknown): string; |
@@ -383,2 +383,41 @@ # Plugins | ||
#### Token Extension | ||
This plugin also adds tokens for time zone name to the formatter. | ||
**formatter:** | ||
| token | meaning | output examples | | ||
|:------|:----------------------------|:----------------------| | ||
| z | time zone name abbreviation | PST, EST | | ||
| zz | time zone name | Pacific Standard Time | | ||
The `z` and `zz` are lowercase. Also, currently it does not support output other than English. | ||
**parser:** | ||
There is no change. | ||
```javascript | ||
const date = require('date-and-time'); | ||
// Import "timezone" plugin. | ||
const timezone = require('date-and-time/plugin/timezone'); | ||
// Apply "timezone" plugin to the library. | ||
date.plugin(timezone); | ||
const d1 = new Date(Date.UTC(2021, 2, 14, 9, 59, 59, 999)); | ||
date.format(d1, 'MMMM DD YYYY H:mm:ss.SSS zz'); | ||
// March 14 2021 1:59:59.999 Pacific Standard Time | ||
date.format(d1, 'MMMM DD YYYY H:mm:ss.SSS zz', true); | ||
// March 14 2021 9:59:59.999 Coordinated Universal Time | ||
date.formatTZ(d1, 'MMMM DD YYYY H:mm:ss.SSS z', 'Asia/Tokyo'); | ||
// March 14 2021 18:59:59.999 JST | ||
// Transforms the date string from EST (Eastern Standard Time) to PDT (Pacific Daylight Time). | ||
date.transform('2021-11-07T03:59:59 UTC-0500', 'YYYY-MM-DD[T]HH:mm:ss [UTC]Z', 'MMMM D YYYY H:mm:ss z'); | ||
// November 7 2021 1:59:59 PDT | ||
``` | ||
--- | ||
@@ -385,0 +424,0 @@ |
@@ -28,2 +28,6 @@ # date-and-time | ||
- 3.4.0 | ||
- Added `zz` (time zone name) and `z` (time zone name abbreviation) tokens to the `timezone` plugin. | ||
- Fixed an issue where token extensions by other plugins were not reflected in functions provided by the `timezone` plugin. | ||
- 3.3.0 | ||
@@ -35,6 +39,2 @@ - Refactored `format()`, `isValid()`, and `preparse()`, further improved performance. | ||
- 3.1.1 | ||
- Fixed an issue where `format()` could output incorrect UTC times in locales with daylight savings time. | ||
- Refactored `formatTZ()` of `timezone` plugin. | ||
## Usage | ||
@@ -184,8 +184,10 @@ | ||
| token | meaning | examples of output | | ||
|:------|:-------------------------------------|:-------------------| | ||
| DDD | ordinal notation of date | 1st, 2nd, 3rd | | ||
| AA | meridiem (uppercase with ellipsis) | A.M., P.M. | | ||
| a | meridiem (lowercase) | am, pm | | ||
| aa | meridiem (lowercase with ellipsis) | a.m., p.m. | | ||
| token | meaning | examples of output | | ||
|:------|:-------------------------------------|:----------------------| | ||
| DDD | ordinal notation of date | 1st, 2nd, 3rd | | ||
| AA | meridiem (uppercase with ellipsis) | A.M., P.M. | | ||
| a | meridiem (lowercase) | am, pm | | ||
| aa | meridiem (lowercase with ellipsis) | a.m., p.m. | | ||
| z | time zone name abbreviation | PST, EST | | ||
| zz | time zone name | Pacific Standard Time | | ||
@@ -192,0 +194,0 @@ #### Note 1. Comments |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
429938
8002
621