UNPKG

@gidw/rfc3339-parser

Version:
1 lines 827 B
!function(e){var t;(t={}).parseRFC3339=function(e){var t,s,n,r,i,p,a,u,f,l,o,d;if("string"!=typeof e)return new Date(e);t=e.trim().toUpperCase(),s=t.split(t.includes("T")?"T":" "),n=s[0].split("-"),r=s[1],l="",o=1,d=0,r&&(i=r.length-1,"Z"===r.charAt(i)?f=r.substring(0,i):(p=r.indexOf("+"))>-1?(f=r.substring(0,p),l=r.substring(p+1),o=1):(p=r.indexOf("-"))>-1?(f=r.substring(0,p),l=r.substring(p+1),o=-1):f=r);if(!f)return new Date(e);f=f.split(":"),s=f[2].split("."),a=s[1],u=Date.UTC(parseInt(n[0],10),parseInt(n[1],10)-1,parseInt(n[2],10),parseInt(f[0],10),parseInt(f[1],10),parseInt(s[0],10),a?parseInt(a,10):0),l&&(s=l.split(":"),d=o*(60*parseInt(s[0],10)*60*1e3+60*parseInt(s[1],10)*1e3));return new Date(u-d)},"object"==typeof module&&module.exports?module.exports=t:e.GidwRFC3339=t}("undefined"!=typeof self?self:this);