date-and-time
Advanced tools
Comparing version 0.4.1 to 0.4.2
@@ -124,15 +124,15 @@ /** | ||
length = result.length; | ||
if (!length) { | ||
return NaN; | ||
} | ||
} else if (i < 7) { | ||
str = (str.match(exp[i]) || [''])[0]; | ||
if (!str) { | ||
return NaN; | ||
} | ||
dt[p] = (p === 'S' ? (str + '000').slice(0, -token.length) : str) | 0; | ||
length = str.length; | ||
result = (str.match(exp[i]) || [''])[0]; | ||
dt[p] = (p === 'S' ? (result + '000').slice(0, -token.length) : result) | 0; | ||
length = result.length; | ||
} | ||
if (!length) { | ||
return NaN; | ||
} | ||
offset += length; | ||
} | ||
if (offset !== dString.length || !result) { | ||
return NaN; | ||
} | ||
dt.Y += dt.Y < 70 ? 2000 : dt.Y < 100 ? 1900 : 0; | ||
@@ -139,0 +139,0 @@ dt.H = dt.H || locale.parser.h(dt.h || 0, dt.A || 0); |
/* | ||
date-and-time.js (c) KNOWLEDGECODE | MIT | ||
*/ | ||
(function(t){var b={},n="en",l={en:{MMMM:"January February March April May June July August September October November December".split(" "),MMM:"Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" "),dddd:"Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "),ddd:"Sun Mon Tue Wed Thu Fri Sat".split(" "),dd:"Su Mo Tu We Th Fr Sa".split(" "),A:["a.m.","p.m."],formatter:{YYYY:function(a){return("000"+a.getFullYear()).slice(-4)},YY:function(a){return("0"+a.getFullYear()).slice(-2)}, | ||
(function(u){var b={},m="en",k={en:{MMMM:"January February March April May June July August September October November December".split(" "),MMM:"Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" "),dddd:"Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "),ddd:"Sun Mon Tue Wed Thu Fri Sat".split(" "),dd:"Su Mo Tu We Th Fr Sa".split(" "),A:["a.m.","p.m."],formatter:{YYYY:function(a){return("000"+a.getFullYear()).slice(-4)},YY:function(a){return("0"+a.getFullYear()).slice(-2)}, | ||
Y:function(a){return""+a.getFullYear()},MMMM:function(a){return this.MMMM[a.getMonth()]},MMM:function(a){return this.MMM[a.getMonth()]},MM:function(a){return("0"+(a.getMonth()+1)).slice(-2)},M:function(a){return""+(a.getMonth()+1)},DD:function(a){return("0"+a.getDate()).slice(-2)},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.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.dddd[a.getDay()]},ddd:function(a){return this.ddd[a.getDay()]},dd:function(a){return this.dd[a.getDay()]}, | ||
Z:function(a){a=a.utc?0:a.getTimezoneOffset()/.6;return(0<a?"-":"+")+("000"+Math.abs(a-a%100*.4)).slice(-4)},post:function(a){return a}},parser:{find:function(a,c){for(var b=-1,d=0,e=0,g=a.length,f;e<g;e++)f=a[e],!c.indexOf(f)&&f.length>d&&(b=e,d=f.length);return{index:b,length:d}},MMMM:function(a){return this.parser.find(this.MMMM,a)},MMM:function(a){return this.parser.find(this.MMM,a)},A:function(a){return this.parser.find(this.A,a)},h:function(a,c){return(12===a?0:a)+12*c},pre:function(a){return a}}}}, | ||
q=function(){return"object"===typeof module&&"object"===typeof module.exports};b.format=function(a,c,p){var d=b.addMinutes(a,p?a.getTimezoneOffset():0),e=l[n],g=e.formatter;d.utc=p;return c.replace(/(\[[^\[\]]*]|\[.*\][^\[]*\]|YYYY|YY|MMM?M?|DD|HH|hh|mm|ss|SSS?|ddd?d?|.)/g,function(a){var b=g[a];return b?g.post(b.call(e,d,c)):a.replace(/\[(.*)]/,"$1")})};b.parse=function(a,c,p){var d=l[n],e=d.parser.pre(a),g=0,f,m,u=/(MMMM?|A)|(YYYY)|(SSS)|(MM|DD|HH|hh|mm|ss)|(YY|M|D|H|h|m|s|SS)|(S)|(.)/g,q={2:/^\d{1,4}/, | ||
3:/^\d{1,3}/,4:/^\d\d/,5:/^\d\d?/,6:/^\d/};for(a={Y:1970,M:1,D:1,H:0,m:0,s:0,S:0};f=u.exec(c);){var h=0;var r=1;for(m="";!m;)m=f[++h];f=m.charAt(0);var k=e.slice(g);if(2>h){if(h=d.parser[m].call(d,k,c),a[f]=h.index,"M"===f&&a[f]++,r=h.length,!r)return NaN}else if(7>h){k=(k.match(q[h])||[""])[0];if(!k)return NaN;a[f]=("S"===f?(k+"000").slice(0,-m.length):k)|0;r=k.length}g+=r}a.Y+=70>a.Y?2E3:100>a.Y?1900:0;a.H=a.H||d.parser.h(a.h||0,a.A||0);c=new Date(a.Y,a.M-1,a.D,a.H,a.m,a.s,a.S);return a.Y!==c.getFullYear()|| | ||
a.M-1!==c.getMonth()||a.D!==c.getDate()||a.H!==c.getHours()||a.m!==c.getMinutes()||a.s!==c.getSeconds()||a.S!==c.getMilliseconds()?NaN:p?b.addMinutes(c,-c.getTimezoneOffset()):c};b.isValid=function(a,c){return!!b.parse(a,c)};b.addYears=function(a,c){return b.addMonths(a,12*c)};b.addMonths=function(a,c){var b=new Date(a.getTime());b.setMonth(b.getMonth()+c);return b};b.addDays=function(a,c){var b=new Date(a.getTime());b.setDate(b.getDate()+c);return b};b.addHours=function(a,c){return b.addMilliseconds(a, | ||
36E5*c)};b.addMinutes=function(a,c){return b.addMilliseconds(a,6E4*c)};b.addSeconds=function(a,c){return b.addMilliseconds(a,1E3*c)};b.addMilliseconds=function(a,c){return new Date(a.getTime()+c)};b.subtract=function(a,c){var b=a.getTime()-c.getTime();return{toMilliseconds:function(){return b},toSeconds:function(){return b/1E3|0},toMinutes:function(){return b/6E4|0},toHours:function(){return b/36E5|0},toDays:function(){return b/864E5|0}}};b.isLeapYear=function(a){a=a.getFullYear();return!(a%4)&&!!(a% | ||
100)||!(a%400)};b.isSameDay=function(a,c){return b.format(a,"YYYYMMDD")===b.format(c,"YYYYMMDD")};b.locale=function(a){a&&("en"!==a&&q()&&require("./locale/"+a),n=a);return n};b.getLocales=function(a){return l[a||n]};b.setLocales=function(a,b){var c=function(a,b){var c=function(){},d;c.prototype=b;c=new c;for(d in a)a.hasOwnProperty(d)&&(c[d]=a[d]);return c},d=l[a]||l.en,e=c(b,d);b.formatter&&(e.formatter=c(b.formatter,d.formatter));b.parser&&(e.parser=c(b.parser,d.parser));l[a]=e};q()?module.exports= | ||
b:"function"===typeof define&&define.amd?define([],function(){return b}):t.date=b})(this); | ||
p=function(){return"object"===typeof module&&"object"===typeof module.exports};b.format=function(a,c,n){var d=b.addMinutes(a,n?a.getTimezoneOffset():0),e=k[m],g=e.formatter;d.utc=n;return c.replace(/(\[[^\[\]]*]|\[.*\][^\[]*\]|YYYY|YY|MMM?M?|DD|HH|hh|mm|ss|SSS?|ddd?d?|.)/g,function(a){var b=g[a];return b?g.post(b.call(e,d,c)):a.replace(/\[(.*)]/,"$1")})};b.parse=function(a,c,n){var d=k[m],e=d.parser.pre(a),g=0,f,l,v=/(MMMM?|A)|(YYYY)|(SSS)|(MM|DD|HH|hh|mm|ss)|(YY|M|D|H|h|m|s|SS)|(S)|(.)/g,p={2:/^\d{1,4}/, | ||
3:/^\d{1,3}/,4:/^\d\d/,5:/^\d\d?/,6:/^\d/};for(a={Y:1970,M:1,D:1,H:0,m:0,s:0,S:0};f=v.exec(c);){var q=0;var r=1;for(l="";!l;)l=f[++q];f=l.charAt(0);var t=e.slice(g);if(2>q){var h=d.parser[l].call(d,t,c);a[f]=h.index;"M"===f&&a[f]++;r=h.length}else 7>q&&(h=(t.match(p[q])||[""])[0],a[f]=("S"===f?(h+"000").slice(0,-l.length):h)|0,r=h.length);if(!r)return NaN;g+=r}if(g!==e.length||!h)return NaN;a.Y+=70>a.Y?2E3:100>a.Y?1900:0;a.H=a.H||d.parser.h(a.h||0,a.A||0);c=new Date(a.Y,a.M-1,a.D,a.H,a.m,a.s,a.S); | ||
return a.Y!==c.getFullYear()||a.M-1!==c.getMonth()||a.D!==c.getDate()||a.H!==c.getHours()||a.m!==c.getMinutes()||a.s!==c.getSeconds()||a.S!==c.getMilliseconds()?NaN:n?b.addMinutes(c,-c.getTimezoneOffset()):c};b.isValid=function(a,c){return!!b.parse(a,c)};b.addYears=function(a,c){return b.addMonths(a,12*c)};b.addMonths=function(a,c){var b=new Date(a.getTime());b.setMonth(b.getMonth()+c);return b};b.addDays=function(a,c){var b=new Date(a.getTime());b.setDate(b.getDate()+c);return b};b.addHours=function(a, | ||
c){return b.addMilliseconds(a,36E5*c)};b.addMinutes=function(a,c){return b.addMilliseconds(a,6E4*c)};b.addSeconds=function(a,c){return b.addMilliseconds(a,1E3*c)};b.addMilliseconds=function(a,c){return new Date(a.getTime()+c)};b.subtract=function(a,c){var b=a.getTime()-c.getTime();return{toMilliseconds:function(){return b},toSeconds:function(){return b/1E3|0},toMinutes:function(){return b/6E4|0},toHours:function(){return b/36E5|0},toDays:function(){return b/864E5|0}}};b.isLeapYear=function(a){a=a.getFullYear(); | ||
return!(a%4)&&!!(a%100)||!(a%400)};b.isSameDay=function(a,c){return b.format(a,"YYYYMMDD")===b.format(c,"YYYYMMDD")};b.locale=function(a){a&&("en"!==a&&p()&&require("./locale/"+a),m=a);return m};b.getLocales=function(a){return k[a||m]};b.setLocales=function(a,b){var c=function(a,b){var c=function(){},d;c.prototype=b;c=new c;for(d in a)a.hasOwnProperty(d)&&(c[d]=a[d]);return c},d=k[a]||k.en,e=c(b,d);b.formatter&&(e.formatter=c(b.formatter,d.formatter));b.parser&&(e.parser=c(b.parser,d.parser));k[a]= | ||
e};p()?module.exports=b:"function"===typeof define&&define.amd?define([],function(){return b}):u.date=b})(this); |
{ | ||
"name": "date-and-time", | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"description": "A Minimalist DateTime utility for Node.js and the browser", | ||
@@ -5,0 +5,0 @@ "main": "date-and-time.js", |
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
85085