From e2c25663ea0834d43cd2752a653f6e7db76d8d4b Mon Sep 17 00:00:00 2001 From: Sophie Kirschner Date: Sun, 20 May 2018 12:31:13 +0300 Subject: [PATCH] Build release source files --- dist/strtime.js | 14 +++++++++++++- dist/strtime.min.js | 2 +- src/format-time.js | 3 --- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/dist/strtime.js b/dist/strtime.js index 189bf81..2232961 100644 --- a/dist/strtime.js +++ b/dist/strtime.js @@ -2,6 +2,7 @@ // MIT license, Copyright (c) 2018 Sophie Kirschner (sophiek@pineapplemachine.com) // References: // https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_71/rtref/strpti.htm +// https://www.gnu.org/software/libc/manual/html_node/Formatting-Calendar-Time.html // https://www.gnu.org/software/libc/manual/html_node/Low_002dLevel-Time-String-Parsing.html // http://man7.org/linux/man-pages/man3/strptime.3.html // https://apidock.com/ruby/DateTime/strftime @@ -62,6 +63,7 @@ function strftime(date, format, timezone, options){ if(!(date instanceof Date)){ throw new Error("Failed to get Date instance from date input."); } + const tokens = TimestampParser.parseFormatString(format); const useOptions = getFormatOptions(timezone, options); const timezoneOffsetMinutes = getTimezoneOffsetMinutes(date, useOptions.tz); const tzDate = new Date(date); @@ -71,9 +73,14 @@ function strftime(date, format, timezone, options){ date.getTimezoneOffset() + timezoneOffsetMinutes ); + }else if(tokens.zuluTimezone){ + tzDate.setUTCMinutes( + date.getUTCMinutes() + + date.getTimezoneOffset() + ); } let output = ""; - for(let token of TimestampParser.parseFormatString(format)){ + for(let token of tokens){ if(token instanceof Directive){ output += token.write(tzDate, "", useOptions.options, timezoneOffsetMinutes); }else if(token instanceof Directive.Token){ @@ -1422,6 +1429,11 @@ TimestampParser.parseFormatString = function parseFormatString(format){ addCharacter(ch); } } + if(directive) throw new TimestampParseError( + "Found unterminated directive at the end of the format string.", { + format: formatString + } + ); if(tokens.length && tokens[tokens.length - 1].string === "Z"){ tokens.zuluTimezone = true; } diff --git a/dist/strtime.min.js b/dist/strtime.min.js index af8ecd9..ae5729b 100644 --- a/dist/strtime.min.js +++ b/dist/strtime.min.js @@ -1,3 +1,3 @@ // github.com/pineapplemachine/strtime-js // MIT license, Copyright (c) 2018 Sophie Kirschner (sophiek@pineapplemachine.com) -function getFormatOptions(e,t){let i,n=void 0;return null===e||void 0===e||Number.isFinite(e)||"string"==typeof e?(n=e,i=t||{}):e&&!t?n=(i=e).tz:i={},{tz:n,options:i}}function getTimezoneOffsetMinutes(e,t){if(null!==t&&void 0!==t){if(t>=-16&&t<=16)return Math.floor(60*t);if(Number.isFinite(t))return Math.floor(t);if("local"===t)return-(e||new Date).getTimezoneOffset();if(t in defaultTimezoneNames)return Math.floor(60*defaultTimezoneNames[t]);throw new Error(`Unrecognized timezone option "${t}".`)}}function strftime(e,t,i,n){if(Number.isFinite(e))e=new Date(e);else{if(!e)throw new Error("No date input was provided.");"function"==typeof e.toDate?e=e.toDate():"function"==typeof e.toJSDate&&(e=e.toJSDate())}if(!(e instanceof Date))throw new Error("Failed to get Date instance from date input.");const r=getFormatOptions(i,n),s=getTimezoneOffsetMinutes(e,r.tz),o=new Date(e);void 0!==s&&o.setUTCMinutes(e.getUTCMinutes()+e.getTimezoneOffset()+s);let a="";for(let e of TimestampParser.parseFormatString(t))e instanceof Directive?a+=e.write(o,"",r.options,s):e instanceof Directive.Token?a+=e.write(o,r.options,s):a+=e;return a}function strptime(e,t,i,n){const r=getFormatOptions(i,n),s=new TimestampParser(e,t),o=getTimezoneOffsetMinutes(void 0,r.tz);if(void 0!==o?s.timezoneOffsetMinutes=o:s.tokens.zuluTimezone&&(s.timezoneOffsetMinutes=0),r.options)for(let e in r.options)s[e]=r.options[e];return s.parse().getDate()}const strtime={strftime:strftime,strptime:strptime},english={eraNames:["CE","BCE"],meridiemNames:["AM","PM"],shortWeekdayNames:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],longWeekdayNames:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortMonthNames:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],longMonthNames:["January","February","March","April","May","June","July","August","September","October","November","December"],ordinalTransform:function(e){const t=Math.floor(e%10);return e>3&&e<=20?`${e}th`:1===t?`${e}st`:2===t?`${e}nd`:3===t?`${e}rd`:`${e}th`}};function leftPad(e,t,i){let n=String(i);for(;n.length=0?"+":"-",r=leftPad("0",2,Math.floor(i/60)),s=leftPad("0",2,i%60);return"::"===t?n+r+":"+s+":00":":"===t?n+r+":"+s:n+r+s}function getDayOfWeek(e){let t=e.getFullYear(),i=e.getMonth(),n=e.getDate();return i<2&&t--,([0,3,2,5,0,3,5,1,4,6,2,4][i]+t+n+Math.floor(t/4)-Math.floor(t/100)+Math.floor(t/400))%7}function getDayOfYear(e){const t=monthLengths.forYear(e.getFullYear()).slice(0,e.getMonth());return e.getDate()+(t.length&&t.reduce((e,t)=>e+t)||0)}function getWeekOfYearFromSunday(e){const t=getDayOfYear(e),i=getFirstWeekdayInYear(e.getFullYear());return Math.floor((t+(i||7)-1)/7)}function getWeekOfYearFromMonday(e){const t=getDayOfYear(e),i=getDayOfWeek(e),n=getFirstWeekdayInYear(e.getFullYear());return Math.floor((t+(n||7)-1)/7)-(0===i?1:0)+(1===n?1:0)}function getISOWeeksInYear(e){const t=e-1,i=(e+Math.floor(e/4)-Math.floor(e/100)+Math.floor(e/400))%7,n=(t+Math.floor(t/4)-Math.floor(t/100)+Math.floor(t/400))%7;return 4===i||3===n?53:52}function getISOWeekOfYear(e){const t=e.getFullYear(),i=getDayOfYear(e),n=getDayOfWeek(e),r=Math.floor((10+i-(n||7))/7);return r<1?getISOWeeksInYear(t-1):r>getISOWeeksInYear(t)?1:r}function getISOWeekDateYear(e){const t=e.getFullYear(),i=getDayOfYear(e),n=getDayOfWeek(e),r=Math.floor((10+i-(n||7))/7);return r<1?t-1:r>getISOWeeksInYear(t)?t+1:t}class Directive{constructor(e){this.names=e.names,this.padLength=e.padLength,this.likelyLength=e.likelyLength,this.text=e.text,this.minimum=e.minimum,this.maximum=e.maximum,this.canBeNegative=e.canBeNegative,this.rewrite=e.rewrite,this.parseFunction=e.parse,this.writeFunction=e.write,this.storeFunction=e.store}static getByName(e){for(let t of Directive.list)if(t.names.indexOf(e)>=0)return t}isOrdinal(){return!1}getCanBeNegative(){return this.canBeNegative}getLikelyLength(){return this.likelyLength}getRewriteParsed(e){if(!this.rewriteParsedValue){this.rewriteParsedValue=e(this.rewrite);for(let e of this.rewriteParsedValue)e.expandedFrom=this}return this.rewriteParsedValue}hasParseFunction(){return!!this.parseFunction}hasStoreFunction(){return!!this.storeFunction}parse(e){return this.parseFunction.call(e)}store(e,t){this.storeFunction.call(e,t)}write(e,t,i,n){return this.writeFunction(e,t,i,n)}numberInBounds(e){return(!Number.isFinite(this.minimum)||e>=this.minimum)&&(!Number.isFinite(this.maximum)||e<=this.maximum)}getBoundsString(){return Number.isFinite(this.minimum)&&Number.isFinite(this.maximum)?`[${this.minimum}, ${this.maximum}]`:Number.isFinite(this.minimum)?`[${this.minimum}, ...]`:Number.isFinite(this.maximum)?`[..., ${this.maximum}]`:void 0}toString(){return"%"+this.names[0]}}function TimestampParseError(e,t){if(Error.call(this),this.reason=e,this.format=t.format,this.timestamp=t.string,this.token=t.currentToken,this.index=t.index,this.token&&this.token.expandedFrom&&void 0!==this.index?this.message=`Failed to parse token "${this.token}" `+`(expanded from "${this.token.expandedFrom}") at position [${this.index}] `+`in timestamp "${this.timestamp}" with format "${this.format}": `+`${this.reason}`:this.token&&void 0!==this.index?this.message=`Failed to parse token "${this.token}" at position [${this.index}] `+`in timestamp "${this.timestamp}" with format "${this.format}": `+`${this.reason}`:this.token?this.message=`Failed to parse token "${this.token}" `+`in format "${this.format}": ${this.reason}`:this.message=`Failed with format "${this.format}": ${this.reason}`,Error.captureStackTrace)Error.captureStackTrace(this,this.constructor);else try{throw new Error}catch(e){this.stack=e.stack}}function isDigit(e){return"0"===e||"1"===e||"2"===e||"3"===e||"4"===e||"5"===e||"6"===e||"7"===e||"8"===e||"9"===e}function getYearFromTwoDigits(e){return e+(e<=68?2e3:1900)}function getMonthFromDayOfYear(e,t){const i=monthLengths.forYear(e);let n=0;for(let e=0;e=t)return e;n+=i[e]}return 12}function getDayOfMonthFromDayOfYear(e,t){const i=monthLengths.forYear(e);let n=0;for(let e=0;es?(e.year=1+t,o-=s):e.year=t,e.month=getMonthFromDayOfYear(e.year,o),e.dayOfMonth=getDayOfMonthFromDayOfYear(e.year,o)}function getDateFromSundayWeekDate(e,t,i,n){const r=1+7*i-(getFirstWeekdayInYear(t)||7)+n;e.year=t,e.month=getMonthFromDayOfYear(t,r),e.dayOfMonth=getDayOfMonthFromDayOfYear(t,r)}function getDateFromMondayWeekDate(e,t,i,n){const r=getFirstWeekdayInYear(t),s=1+7*i-(r||7)+n+((0===n?7:0)-(1===r?7:0));e.year=t,e.month=getMonthFromDayOfYear(t,s),e.dayOfMonth=getDayOfMonthFromDayOfYear(t,s)}Directive.Token=class{constructor(e,t){this.modifier=e,this.directive=t,this.expandedFrom=void 0}isOrdinal(){return":"===this.modifier}getCanBeNegative(){return this.directive.canBeNegative}getLikelyLength(){return this.directive.likelyLength}hasParseFunction(){return this.directive.hasParseFunction()}hasStoreFunction(){return this.directive.hasStoreFunction()}parse(e){return this.directive.parseFunction.call(e,this.modifier)}store(e,t){this.directive.storeFunction.call(e,t)}write(e,t,i){const n=this.directive.write(e,this.modifier,t,i);if("^"===this.modifier){const e=String(n);if("number"==typeof n)return e;const t=e.toUpperCase();return t!==e?t:e.toLowerCase()}if("_"===this.modifier&&this.directive.padLength)return leftPad(" ",this.directive.padLength,n);if("_"===this.modifier&&this.directive.text)return String(n).toLowerCase();if("-"===this.modifier&&this.directive.padLength)return String(n);if(":"!==this.modifier||this.directive.text)return!this.directive.text&&this.directive.padLength?n>=0?leftPad("0",this.directive.padLength,n):`-${leftPad("0",this.directive.padLength,-n)}`:String(n);return(t&&t.ordinalTransform||english.ordinalTransform)(n)}numberInBounds(e){return this.directive.numberInBounds(e)}getBoundsString(){return this.directive.getBoundsString()}toString(){return"%"+this.modifier+this.directive.names[0]}},Directive.StringToken=class{constructor(e){this.string=e||"",this.expandedFrom=void 0}addCharacter(e){this.string+=e}toString(){return this.string}},Directive.list=[new Directive({names:["a"],text:!0,parse:function(){this.dayOfWeek=this.parseWeekdayName(this)},write:function(e,t,i){return(i&&i.shortWeekdayNames||english.shortWeekdayNames)[e.getDay()%7]}}),new Directive({names:["A"],text:!0,parse:function(){this.dayOfWeek=this.parseWeekdayName(this)},write:function(e,t,i){return(i&&i.longWeekdayNames||english.longWeekdayNames)[e.getDay()%7]}}),new Directive({names:["b","h"],text:!0,parse:function(){this.month=1+this.parseMonthName(this)},write:function(e,t,i){return(i&&i.shortMonthNames||english.shortMonthNames)[e.getMonth()%12]}}),new Directive({names:["B"],text:!0,parse:function(){this.month=1+this.parseMonthName(this)},write:function(e,t,i){return(i&&i.longMonthNames||english.longMonthNames)[e.getMonth()%12]}}),new Directive({names:["c"],rewrite:"%a %b %e %H:%M:%S %Y"}),new Directive({names:["C"],likelyLength:2,canBeNegative:!0,store:function(e){this.century=e},write:function(e){return Math.floor(e.getFullYear()/100)}}),new Directive({names:["d"],padLength:2,likelyLength:2,minimum:1,maximum:31,store:function(e){this.dayOfMonth=e},write:function(e){return e.getDate()}}),new Directive({names:["D","x"],rewrite:"%m/%d/%y"}),new Directive({names:["e"],likelyLength:2,minimum:1,maximum:31,store:function(e){this.dayOfMonth=e},write:function(e,t){return t?e.getDate():leftPad(" ",2,e.getDate())}}),new Directive({names:["f"],padLength:6,likelyLength:6,minimum:0,maximum:999999,store:function(e){this.microsecond=e},write:function(e){return 1e3*e.getMilliseconds()}}),new Directive({names:["F"],rewrite:"%Y-%m-%d"}),new Directive({names:["g"],likelyLength:2,store:function(e){this.isoTwoDigitYear=e},write:function(e){return getISOWeekDateYear(e)%100}}),new Directive({names:["G"],likelyLength:4,canBeNegative:!0,store:function(e){this.isoYear=e},write:function(e){return getISOWeekDateYear(e)}}),new Directive({names:["H","k"],padLength:2,likelyLength:2,minimum:0,maximum:23,store:function(e){this.hour=e},write:function(e){return e.getHours()}}),new Directive({names:["I","l"],padLength:2,likelyLength:2,minimum:1,maximum:12,store:function(e){this.hour=e},write:function(e){return e.getHours()%12||12}}),new Directive({names:["j"],padLength:3,likelyLength:3,minimum:1,maximum:366,store:function(e){this.dayOfYear=e},write:function(e){return getDayOfYear(e)}}),new Directive({names:["L"],padLength:3,likelyLength:3,minimum:0,maximum:999,store:function(e){this.millisecond=e},write:function(e){return e.getMilliseconds()}}),new Directive({names:["m"],padLength:2,likelyLength:2,minimum:1,maximum:12,store:function(e){this.month=e},write:function(e){return 1+e.getMonth()}}),new Directive({names:["M"],padLength:2,likelyLength:2,minimum:0,maximum:59,store:function(e){this.minute=e},write:function(e){return e.getMinutes()}}),new Directive({names:["p"],text:!0,parse:function(){this.meridiem=this.parseMeridiemName()},write:function(e,t,i){const n=e.getHours()<12?0:1;return(i&&i.meridiemNames||english.meridiemNames)[n]}}),new Directive({names:["P"],likelyLength:2,text:!0,parse:function(){this.meridiem=this.parseMeridiemName()},write:function(e,t,i){const n=e.getHours()<12?0:1;return(i&&i.meridiemNames||english.meridiemNames)[n].toLowerCase()}}),new Directive({names:["Q"],canBeNegative:!0,store:function(e){this.microsecondsSinceEpoch=e},write:function(e){const t=e.getTime()-6e4*e.getTimezoneOffset();return Math.floor(1e3*t)}}),new Directive({names:["r"],rewrite:"%I:%M:%S %p"}),new Directive({names:["R"],rewrite:"%H:%M"}),new Directive({names:["s"],canBeNegative:!0,store:function(e){this.secondsSinceEpoch=e},write:function(e){const t=e.getTime()-6e4*e.getTimezoneOffset();return Math.floor(t/1e3)}}),new Directive({names:["S"],padLength:2,likelyLength:2,minimum:0,maximum:61,store:function(e){this.second=e},write:function(e){return Math.min(59,e.getSeconds())}}),new Directive({names:["T","X"],rewrite:"%H:%M:%S"}),new Directive({names:["u"],likelyLength:1,minimum:1,maximum:7,store:function(e){this.dayOfWeek=e%7},write:function(e){return getDayOfWeek(e)||7}}),new Directive({names:["U"],padLength:2,likelyLength:2,minimum:0,maximum:53,store:function(e){this.weekOfYearFromSunday=e},write:function(e){return getWeekOfYearFromSunday(e)}}),new Directive({names:["v"],rewrite:"%e-%b-%Y"}),new Directive({names:["V"],padLength:2,likelyLength:2,minimum:1,maximum:53,store:function(e){this.isoWeekOfYear=e},write:function(e){return getISOWeekOfYear(e)}}),new Directive({names:["w"],likelyLength:1,minimum:0,maximum:6,store:function(e){this.dayOfWeek=e%7},write:function(e){return getDayOfWeek(e)}}),new Directive({names:["W"],padLength:2,likelyLength:2,minimum:0,maximum:53,store:function(e){this.weekOfYearFromMonday=e},write:function(e){return getWeekOfYearFromMonday(e)}}),new Directive({names:["y"],padLength:2,likelyLength:2,store:function(e){this.twoDigitYear=e},write:function(e){return e.getFullYear()%100}}),new Directive({names:["Y"],padLength:4,likelyLength:4,canBeNegative:!0,store:function(e){this.year=e},write:function(e,t){const i=e.getFullYear();return i<=0&&"^"===t?1-i:i}}),new Directive({names:["z"],text:!0,parse:function(e){this.timezoneOffsetMinutes=this.parseTimezoneOffset(e)},write:function(e,t,i,n){return writeTimezoneOffset(Number.isFinite(n)?n:-e.getTimezoneOffset(),t)}}),new Directive({names:["Z"],likelyLength:5,text:!0,parse:function(e){const t=this.getTimezoneNameList(),i=this.parseIndexInList(t);this.timezoneOffsetMinutes=void 0!==i?60*this.timezoneNames[t[i]]:this.parseTimezoneOffset(e)},write:function(e,t,i,n){const r=Number.isFinite(n)?n:-e.getTimezoneOffset();return 0===r?"UTC":writeTimezoneOffset(r,t)}}),new Directive({names:["+"],rewrite:"%a %b %e %H:%M:%S %Z %Y"}),new Directive({names:["#"],text:!0,parse:function(){this.era=this.parseEraName()},write:function(e,t,i){const n=e.getFullYear()<=0?1:0;return(i&&i.eraNames||english.eraNames)[n]}})],TimestampParseError.prototype=Object.create(Error.prototype),TimestampParseError.prototype.name="TimestampParseError",TimestampParseError.prototype.constructor=TimestampParseError;class TimestampParser{constructor(e,t,i){this.index=0,this.string=String(e),this.format=String(t),this.tokens=i||TimestampParser.parseFormatString(this.format),this.forkLength=0,this.currentToken=void 0,this.shortWeekdayNames=english.shortWeekdayNames,this.longWeekdayNames=english.longWeekdayNames,this.shortMonthNames=english.shortMonthNames,this.longMonthNames=english.longMonthNames,this.eraNames=english.eraNames,this.meridiemNames=english.meridiemNames,this.ordinalTransform=english.ordinalTransform,this.timezoneNames=defaultTimezoneNames,this.era=void 0,this.century=void 0,this.year=void 0,this.twoDigitYear=void 0,this.isoYear=void 0,this.isoTwoDigitYear=void 0,this.month=void 0,this.isoWeekOfYear=void 0,this.weekOfYearFromSunday=void 0,this.weekOfYearFromMonday=void 0,this.dayOfYear=void 0,this.dayOfMonth=void 0,this.dayOfWeek=void 0,this.hour=void 0,this.minute=void 0,this.second=void 0,this.millisecond=void 0,this.microsecond=void 0,this.meridiem=void 0,this.timezoneOffsetMinutes=void 0,this.secondsSinceEpoch=void 0,this.millisecondsSinceEpoch=void 0,this.microsecondsSinceEpoch=void 0}getTimezoneOffsetOfDate(e){const t=void 0===this.timezoneOffsetMinutes?-e.getTimezoneOffset():this.timezoneOffsetMinutes,i=t>=0?1:-1,n=Math.abs(t);return{hour:i*Math.floor(n/60),minute:i*Math.floor(n%60),totalMinutes:t}}getDate(){if(void 0===this.microsecondsSinceEpoch&&(void 0!==this.millisecondsSinceEpoch?this.microsecondsSinceEpoch=1e3*this.millisecondsSinceEpoch:void 0!==this.secondsSinceEpoch&&(this.microsecondsSinceEpoch=1e6*this.secondsSinceEpoch)),void 0!==this.microsecondsSinceEpoch){const e=new Date(this.microsecondsSinceEpoch/1e3),t=this.getTimezoneOffsetOfDate(e);return e.setUTCMinutes(e.getUTCMinutes()-t.totalMinutes),e}const e=new Date;if(void 0===this.year&&void 0!==this.twoDigitYear?void 0===this.century?this.year=getYearFromTwoDigits(this.twoDigitYear):this.year=100*this.century+this.twoDigitYear:void 0===this.isoYear&&void 0!==this.isoTwoDigitYear?this.isoYear=getYearFromTwoDigits(this.isoTwoDigitYear):void 0===this.year&&void 0!==this.century&&(this.year=100*this.century),this.era&&void 0!==this.year&&(this.year=1-this.year),void 0!==this.hour&&void 0!==this.meridiem&&(this.hour=this.hour%12+(this.meridiem?12:0)),void 0===this.microsecond&&void 0!==this.millisecond&&(this.microsecond=1e3*this.millisecond),void 0===this.isoYear||void 0===this.isoWeekOfYear||void 0!==this.month&&void 0!==this.dayOfMonth)if(void 0!==this.dayOfYear){const t=void 0!==this.year?this.year:e.getFullYear();void 0===this.month&&(this.month=getMonthFromDayOfYear(t,this.dayOfYear)),void 0===this.dayOfMonth&&(this.dayOfMonth=getDayOfMonthFromDayOfYear(t,this.dayOfYear))}else if(void 0===this.weekOfYearFromSunday||void 0!==this.month&&void 0!==this.dayOfMonth){if(void 0!==this.weekOfYearFromMonday&&(void 0===this.month||void 0===this.dayOfMonth)){getDateFromMondayWeekDate(this,void 0!==this.year?this.year:e.getFullYear(),this.weekOfYearFromMonday,this.dayOfWeek||0)}}else{getDateFromSundayWeekDate(this,void 0!==this.year?this.year:e.getFullYear(),this.weekOfYearFromSunday,this.dayOfWeek||0)}else getDateFromISOWeekDate(this,this.isoYear,this.isoWeekOfYear,this.dayOfWeek||0);void 0!==this.year&&e.setUTCFullYear(this.year),void 0!==this.month&&e.setUTCMonth(this.month-1),void 0!==this.dayOfMonth&&e.setUTCDate(this.dayOfMonth);const t=this.getTimezoneOffsetOfDate(e);return t.totalMinutes&&(this.hour=(this.hour||0)-t.hour,this.minute=(this.minute||0)-t.minute),e.setUTCHours(this.hour||0),e.setUTCMinutes(this.minute||0),e.setUTCSeconds(this.second||0),e.setUTCMilliseconds(this.microsecond?this.microsecond/1e3:0),e}copy(){const e=new TimestampParser(this.string,this.format,this.tokens);for(let t in this)e[t]=this[t];return e}fork(e,t){const i=this.copy();return i.forkLength=e,i.parse(t)}parse(e){for(let t=e||0;t=this.string.length)throw new TimestampParseError("Timestamp is too short to match the whole format.",this);if(e instanceof Directive.StringToken)this.parseStringToken(e.string);else if(e.hasParseFunction())e.parse(this);else{if(!e.hasStoreFunction()||e.text)throw new TimestampParseError("Invalid directive.",this);{const i=this.tokens[1+t];if(i instanceof Directive.StringToken&&isDigit(i.string[0])||(i instanceof Directive||i instanceof Directive.Token)&&!i.text){const i=this.parseAmbiguousNumber(e,t);if(i)return i}else e.store(this,this.parseNumber(e))}}}if(this.currentToken=void 0,1+this.index=a.length||a[e].toLowerCase()!==s?(t[o]=null,i--):1+e===a.length&&(n=o,r=1+e))}}return void 0===n?void 0:(this.index+=r,n)}getTimezoneNameList(){if(!this.timezoneNameList){this.timezoneNameList=[];for(let e in this.timezoneNames)this.timezoneNameList.push(e)}return this.timezoneNameList}parseTimezoneOffset(e){const t=this.index,i=this.string[this.index],n=+this.string.slice(this.index+1,this.index+3);let r;if(":"===this.string[this.index+3]?(r=+this.string.slice(this.index+4,this.index+6),this.index+=6):(r=+this.string.slice(this.index+3,this.index+5),this.index+=5),!Number.isInteger(n)||!Number.isInteger(r))throw new TimestampParseError("Failed to parse timezone offset from string "+`"${this.string.slice(t,this.index)}".`,this);const s=r+60*n;if("+"===i||"±"===i)return+s;if("-"===i)return-s;throw new TimestampParseError(`Unknown timezone offset sign "${i}".`,this)}}function isLeapYear(e){return e%4==0&&(e%100!=0||e%400==0)}TimestampParser.parseFormatString=function(e){const t=[];let i=!1,n=void 0;const r=String(e);if(!r)throw new TimestampParseError("Empty format string.",{format:r});function s(e){t.length&&t[t.length-1]instanceof Directive.StringToken&&isDigit(e)===isDigit(t[t.length-1].string[0])?t[t.length-1].addCharacter(e):t.push(new Directive.StringToken(e))}for(let e of r)if(i&&"%"===e)s("%"),n="",i=!1;else if(i&&"n"===e)s("\n"),n="",i=!1;else if(i&&"t"===e)s("\t"),n="",i=!1;else if(!i||n||"-"!==e&&"_"!==e&&"^"!==e&&":"!==e)if(i){const s=Directive.getByName(e);if(!s)throw new TimestampParseError(`Unknown directive "%${n}${e}".`,{format:r});s.rewrite?t.push(...s.getRewriteParsed(TimestampParser.parseFormatString)):t.push(new Directive.Token(n,s)),n="",i=!1}else"%"===e?(n="",i=!0):s(e);else n+=e;return t.length&&"Z"===t[t.length-1].string&&(t.zuluTimezone=!0),t};const monthLengths={common:[31,28,31,30,31,30,31,31,30,31,30,31],leap:[31,29,31,30,31,30,31,31,30,31,30,31],forYear:function(e){return isLeapYear(e)?monthLengths.leap:monthLengths.common}};function getFirstWeekdayInYear(e){const t=e-1;return(365*e+Math.floor(t/4)-Math.floor(t/100)+Math.floor(t/400))%7}const defaultTimezoneNames={ACDT:10.5,ACST:9.5,ACT:-5,ACWST:8.75,ADT:-3,AEDT:11,AEST:10,AFT:4.5,AKDT:-8,AKST:-9,AMST:-3,AMT:-4,AMT:4,ART:-3,AST:3,AST:-4,AWST:8,AZOST:0,AZOT:-1,AZT:4,BDT:8,BIOT:6,BIT:-12,BOT:-4,BRST:-2,BRT:-3,BST:6,BST:11,BST:1,BTT:6,CAT:2,CCT:6.5,CDT:-5,CDT:-4,CEST:2,CET:1,CHADT:13.75,CHAST:12.75,CHOT:8,CHOST:9,CHST:10,CHUT:10,CIST:-8,CIT:8,CKT:-10,CLST:-3,CLT:-4,COST:-4,COT:-5,CST:-6,CST:8,CST:-5,CT:8,CVT:-1,CWST:8.75,CXT:7,DAVT:7,DDUT:10,DFT:1,EASST:-5,EAST:-6,EAT:3,ECT:-4,ECT:-5,EDT:-4,EEST:3,EET:2,EGST:0,EGT:-1,EIT:9,EST:-5,FET:3,FJT:12,FKST:-3,FKT:-4,FNT:-2,GALT:-6,GAMT:-9,GET:4,GFT:-3,GILT:12,GIT:-9,GMT:0,GST:-2,GST:4,GYT:-4,HDT:-9,HAEC:2,HST:-10,HKT:8,HMT:5,HOVST:8,HOVT:7,ICT:7,IDLW:-12,IDT:3,IOT:3,IRDT:4.5,IRKT:8,IRST:3.5,IST:5.5,IST:1,IST:2,JST:9,KGT:6,KOST:11,KRAT:7,KST:9,LHST:10.5,LHST:11,LINT:14,MAGT:12,MART:-9.5,MAWT:5,MDT:-6,MET:1,MEST:2,MHT:12,MIST:11,MIT:-9.5,MMT:6.5,MSK:3,MST:8,MST:-7,MUT:4,MVT:5,MYT:8,NCT:11,NDT:-2.5,NFT:11,NPT:5.75,NST:-3.5,NT:-3.5,NUT:-11,NZDT:13,NZST:12,OMST:6,ORAT:5,PDT:-7,PET:-5,PETT:12,PGT:10,PHOT:13,PHT:8,PKT:5,PMDT:-2,PMST:-3,PONT:11,PST:-8,PST:8,PYST:-3,PYT:-4,RET:4,ROTT:-3,SAKT:11,SAMT:4,SAST:2,SBT:11,SCT:4,SDT:-10,SGT:8,SLST:5.5,SRET:11,SRT:-3,SST:-11,SST:8,SYOT:3,TAHT:-10,THA:7,TFT:5,TJT:5,TKT:13,TLT:9,TMT:5,TRT:3,TOT:13,TVT:12,ULAST:9,ULAT:8,USZ:2,UTC:0,UYST:-2,UYT:-3,UZT:5,VET:-4,VLAT:10,VOLT:4,VOST:6,VUT:11,WAKT:12,WAST:2,WAT:1,WEST:1,WET:0,WIT:7,WST:8,YAKT:9,YEKT:5,Z:0};"undefined"!=typeof module?module.exports=strtime:"undefined"!=typeof window&&(window.strtime=strtime); +function getFormatOptions(e,t){let i,n=void 0;return null===e||void 0===e||Number.isFinite(e)||"string"==typeof e?(n=e,i=t||{}):e&&!t?n=(i=e).tz:i={},{tz:n,options:i}}function getTimezoneOffsetMinutes(e,t){if(null!==t&&void 0!==t){if(t>=-16&&t<=16)return Math.floor(60*t);if(Number.isFinite(t))return Math.floor(t);if("local"===t)return-(e||new Date).getTimezoneOffset();if(t in defaultTimezoneNames)return Math.floor(60*defaultTimezoneNames[t]);throw new Error(`Unrecognized timezone option "${t}".`)}}function strftime(e,t,i,n){if(Number.isFinite(e))e=new Date(e);else{if(!e)throw new Error("No date input was provided.");"function"==typeof e.toDate?e=e.toDate():"function"==typeof e.toJSDate&&(e=e.toJSDate())}if(!(e instanceof Date))throw new Error("Failed to get Date instance from date input.");const r=TimestampParser.parseFormatString(t),s=getFormatOptions(i,n),o=getTimezoneOffsetMinutes(e,s.tz),a=new Date(e);void 0!==o?a.setUTCMinutes(e.getUTCMinutes()+e.getTimezoneOffset()+o):r.zuluTimezone&&a.setUTCMinutes(e.getUTCMinutes()+e.getTimezoneOffset());let h="";for(let e of r)e instanceof Directive?h+=e.write(a,"",s.options,o):e instanceof Directive.Token?h+=e.write(a,s.options,o):h+=e;return h}function strptime(e,t,i,n){const r=getFormatOptions(i,n),s=new TimestampParser(e,t),o=getTimezoneOffsetMinutes(void 0,r.tz);if(void 0!==o?s.timezoneOffsetMinutes=o:s.tokens.zuluTimezone&&(s.timezoneOffsetMinutes=0),r.options)for(let e in r.options)s[e]=r.options[e];return s.parse().getDate()}const strtime={strftime:strftime,strptime:strptime},english={eraNames:["CE","BCE"],meridiemNames:["AM","PM"],shortWeekdayNames:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],longWeekdayNames:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortMonthNames:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],longMonthNames:["January","February","March","April","May","June","July","August","September","October","November","December"],ordinalTransform:function(e){const t=Math.floor(e%10);return e>3&&e<=20?`${e}th`:1===t?`${e}st`:2===t?`${e}nd`:3===t?`${e}rd`:`${e}th`}};function leftPad(e,t,i){let n=String(i);for(;n.length=0?"+":"-",r=leftPad("0",2,Math.floor(i/60)),s=leftPad("0",2,i%60);return"::"===t?n+r+":"+s+":00":":"===t?n+r+":"+s:n+r+s}function getDayOfWeek(e){let t=e.getFullYear(),i=e.getMonth(),n=e.getDate();return i<2&&t--,([0,3,2,5,0,3,5,1,4,6,2,4][i]+t+n+Math.floor(t/4)-Math.floor(t/100)+Math.floor(t/400))%7}function getDayOfYear(e){const t=monthLengths.forYear(e.getFullYear()).slice(0,e.getMonth());return e.getDate()+(t.length&&t.reduce((e,t)=>e+t)||0)}function getWeekOfYearFromSunday(e){const t=getDayOfYear(e),i=getFirstWeekdayInYear(e.getFullYear());return Math.floor((t+(i||7)-1)/7)}function getWeekOfYearFromMonday(e){const t=getDayOfYear(e),i=getDayOfWeek(e),n=getFirstWeekdayInYear(e.getFullYear());return Math.floor((t+(n||7)-1)/7)-(0===i?1:0)+(1===n?1:0)}function getISOWeeksInYear(e){const t=e-1,i=(e+Math.floor(e/4)-Math.floor(e/100)+Math.floor(e/400))%7,n=(t+Math.floor(t/4)-Math.floor(t/100)+Math.floor(t/400))%7;return 4===i||3===n?53:52}function getISOWeekOfYear(e){const t=e.getFullYear(),i=getDayOfYear(e),n=getDayOfWeek(e),r=Math.floor((10+i-(n||7))/7);return r<1?getISOWeeksInYear(t-1):r>getISOWeeksInYear(t)?1:r}function getISOWeekDateYear(e){const t=e.getFullYear(),i=getDayOfYear(e),n=getDayOfWeek(e),r=Math.floor((10+i-(n||7))/7);return r<1?t-1:r>getISOWeeksInYear(t)?t+1:t}class Directive{constructor(e){this.names=e.names,this.padLength=e.padLength,this.likelyLength=e.likelyLength,this.text=e.text,this.minimum=e.minimum,this.maximum=e.maximum,this.canBeNegative=e.canBeNegative,this.rewrite=e.rewrite,this.parseFunction=e.parse,this.writeFunction=e.write,this.storeFunction=e.store}static getByName(e){for(let t of Directive.list)if(t.names.indexOf(e)>=0)return t}isOrdinal(){return!1}getCanBeNegative(){return this.canBeNegative}getLikelyLength(){return this.likelyLength}getRewriteParsed(e){if(!this.rewriteParsedValue){this.rewriteParsedValue=e(this.rewrite);for(let e of this.rewriteParsedValue)e.expandedFrom=this}return this.rewriteParsedValue}hasParseFunction(){return!!this.parseFunction}hasStoreFunction(){return!!this.storeFunction}parse(e){return this.parseFunction.call(e)}store(e,t){this.storeFunction.call(e,t)}write(e,t,i,n){return this.writeFunction(e,t,i,n)}numberInBounds(e){return(!Number.isFinite(this.minimum)||e>=this.minimum)&&(!Number.isFinite(this.maximum)||e<=this.maximum)}getBoundsString(){return Number.isFinite(this.minimum)&&Number.isFinite(this.maximum)?`[${this.minimum}, ${this.maximum}]`:Number.isFinite(this.minimum)?`[${this.minimum}, ...]`:Number.isFinite(this.maximum)?`[..., ${this.maximum}]`:void 0}toString(){return"%"+this.names[0]}}function TimestampParseError(e,t){if(Error.call(this),this.reason=e,this.format=t.format,this.timestamp=t.string,this.token=t.currentToken,this.index=t.index,this.token&&this.token.expandedFrom&&void 0!==this.index?this.message=`Failed to parse token "${this.token}" `+`(expanded from "${this.token.expandedFrom}") at position [${this.index}] `+`in timestamp "${this.timestamp}" with format "${this.format}": `+`${this.reason}`:this.token&&void 0!==this.index?this.message=`Failed to parse token "${this.token}" at position [${this.index}] `+`in timestamp "${this.timestamp}" with format "${this.format}": `+`${this.reason}`:this.token?this.message=`Failed to parse token "${this.token}" `+`in format "${this.format}": ${this.reason}`:this.message=`Failed with format "${this.format}": ${this.reason}`,Error.captureStackTrace)Error.captureStackTrace(this,this.constructor);else try{throw new Error}catch(e){this.stack=e.stack}}function isDigit(e){return"0"===e||"1"===e||"2"===e||"3"===e||"4"===e||"5"===e||"6"===e||"7"===e||"8"===e||"9"===e}function getYearFromTwoDigits(e){return e+(e<=68?2e3:1900)}function getMonthFromDayOfYear(e,t){const i=monthLengths.forYear(e);let n=0;for(let e=0;e=t)return e;n+=i[e]}return 12}function getDayOfMonthFromDayOfYear(e,t){const i=monthLengths.forYear(e);let n=0;for(let e=0;es?(e.year=1+t,o-=s):e.year=t,e.month=getMonthFromDayOfYear(e.year,o),e.dayOfMonth=getDayOfMonthFromDayOfYear(e.year,o)}function getDateFromSundayWeekDate(e,t,i,n){const r=1+7*i-(getFirstWeekdayInYear(t)||7)+n;e.year=t,e.month=getMonthFromDayOfYear(t,r),e.dayOfMonth=getDayOfMonthFromDayOfYear(t,r)}function getDateFromMondayWeekDate(e,t,i,n){const r=getFirstWeekdayInYear(t),s=1+7*i-(r||7)+n+((0===n?7:0)-(1===r?7:0));e.year=t,e.month=getMonthFromDayOfYear(t,s),e.dayOfMonth=getDayOfMonthFromDayOfYear(t,s)}Directive.Token=class{constructor(e,t){this.modifier=e,this.directive=t,this.expandedFrom=void 0}isOrdinal(){return":"===this.modifier}getCanBeNegative(){return this.directive.canBeNegative}getLikelyLength(){return this.directive.likelyLength}hasParseFunction(){return this.directive.hasParseFunction()}hasStoreFunction(){return this.directive.hasStoreFunction()}parse(e){return this.directive.parseFunction.call(e,this.modifier)}store(e,t){this.directive.storeFunction.call(e,t)}write(e,t,i){const n=this.directive.write(e,this.modifier,t,i);if("^"===this.modifier){const e=String(n);if("number"==typeof n)return e;const t=e.toUpperCase();return t!==e?t:e.toLowerCase()}if("_"===this.modifier&&this.directive.padLength)return leftPad(" ",this.directive.padLength,n);if("_"===this.modifier&&this.directive.text)return String(n).toLowerCase();if("-"===this.modifier&&this.directive.padLength)return String(n);if(":"!==this.modifier||this.directive.text)return!this.directive.text&&this.directive.padLength?n>=0?leftPad("0",this.directive.padLength,n):`-${leftPad("0",this.directive.padLength,-n)}`:String(n);return(t&&t.ordinalTransform||english.ordinalTransform)(n)}numberInBounds(e){return this.directive.numberInBounds(e)}getBoundsString(){return this.directive.getBoundsString()}toString(){return"%"+this.modifier+this.directive.names[0]}},Directive.StringToken=class{constructor(e){this.string=e||"",this.expandedFrom=void 0}addCharacter(e){this.string+=e}toString(){return this.string}},Directive.list=[new Directive({names:["a"],text:!0,parse:function(){this.dayOfWeek=this.parseWeekdayName(this)},write:function(e,t,i){return(i&&i.shortWeekdayNames||english.shortWeekdayNames)[e.getDay()%7]}}),new Directive({names:["A"],text:!0,parse:function(){this.dayOfWeek=this.parseWeekdayName(this)},write:function(e,t,i){return(i&&i.longWeekdayNames||english.longWeekdayNames)[e.getDay()%7]}}),new Directive({names:["b","h"],text:!0,parse:function(){this.month=1+this.parseMonthName(this)},write:function(e,t,i){return(i&&i.shortMonthNames||english.shortMonthNames)[e.getMonth()%12]}}),new Directive({names:["B"],text:!0,parse:function(){this.month=1+this.parseMonthName(this)},write:function(e,t,i){return(i&&i.longMonthNames||english.longMonthNames)[e.getMonth()%12]}}),new Directive({names:["c"],rewrite:"%a %b %e %H:%M:%S %Y"}),new Directive({names:["C"],likelyLength:2,canBeNegative:!0,store:function(e){this.century=e},write:function(e){return Math.floor(e.getFullYear()/100)}}),new Directive({names:["d"],padLength:2,likelyLength:2,minimum:1,maximum:31,store:function(e){this.dayOfMonth=e},write:function(e){return e.getDate()}}),new Directive({names:["D","x"],rewrite:"%m/%d/%y"}),new Directive({names:["e"],likelyLength:2,minimum:1,maximum:31,store:function(e){this.dayOfMonth=e},write:function(e,t){return t?e.getDate():leftPad(" ",2,e.getDate())}}),new Directive({names:["f"],padLength:6,likelyLength:6,minimum:0,maximum:999999,store:function(e){this.microsecond=e},write:function(e){return 1e3*e.getMilliseconds()}}),new Directive({names:["F"],rewrite:"%Y-%m-%d"}),new Directive({names:["g"],likelyLength:2,store:function(e){this.isoTwoDigitYear=e},write:function(e){return getISOWeekDateYear(e)%100}}),new Directive({names:["G"],likelyLength:4,canBeNegative:!0,store:function(e){this.isoYear=e},write:function(e){return getISOWeekDateYear(e)}}),new Directive({names:["H","k"],padLength:2,likelyLength:2,minimum:0,maximum:23,store:function(e){this.hour=e},write:function(e){return e.getHours()}}),new Directive({names:["I","l"],padLength:2,likelyLength:2,minimum:1,maximum:12,store:function(e){this.hour=e},write:function(e){return e.getHours()%12||12}}),new Directive({names:["j"],padLength:3,likelyLength:3,minimum:1,maximum:366,store:function(e){this.dayOfYear=e},write:function(e){return getDayOfYear(e)}}),new Directive({names:["L"],padLength:3,likelyLength:3,minimum:0,maximum:999,store:function(e){this.millisecond=e},write:function(e){return e.getMilliseconds()}}),new Directive({names:["m"],padLength:2,likelyLength:2,minimum:1,maximum:12,store:function(e){this.month=e},write:function(e){return 1+e.getMonth()}}),new Directive({names:["M"],padLength:2,likelyLength:2,minimum:0,maximum:59,store:function(e){this.minute=e},write:function(e){return e.getMinutes()}}),new Directive({names:["p"],text:!0,parse:function(){this.meridiem=this.parseMeridiemName()},write:function(e,t,i){const n=e.getHours()<12?0:1;return(i&&i.meridiemNames||english.meridiemNames)[n]}}),new Directive({names:["P"],likelyLength:2,text:!0,parse:function(){this.meridiem=this.parseMeridiemName()},write:function(e,t,i){const n=e.getHours()<12?0:1;return(i&&i.meridiemNames||english.meridiemNames)[n].toLowerCase()}}),new Directive({names:["Q"],canBeNegative:!0,store:function(e){this.microsecondsSinceEpoch=e},write:function(e){const t=e.getTime()-6e4*e.getTimezoneOffset();return Math.floor(1e3*t)}}),new Directive({names:["r"],rewrite:"%I:%M:%S %p"}),new Directive({names:["R"],rewrite:"%H:%M"}),new Directive({names:["s"],canBeNegative:!0,store:function(e){this.secondsSinceEpoch=e},write:function(e){const t=e.getTime()-6e4*e.getTimezoneOffset();return Math.floor(t/1e3)}}),new Directive({names:["S"],padLength:2,likelyLength:2,minimum:0,maximum:61,store:function(e){this.second=e},write:function(e){return Math.min(59,e.getSeconds())}}),new Directive({names:["T","X"],rewrite:"%H:%M:%S"}),new Directive({names:["u"],likelyLength:1,minimum:1,maximum:7,store:function(e){this.dayOfWeek=e%7},write:function(e){return getDayOfWeek(e)||7}}),new Directive({names:["U"],padLength:2,likelyLength:2,minimum:0,maximum:53,store:function(e){this.weekOfYearFromSunday=e},write:function(e){return getWeekOfYearFromSunday(e)}}),new Directive({names:["v"],rewrite:"%e-%b-%Y"}),new Directive({names:["V"],padLength:2,likelyLength:2,minimum:1,maximum:53,store:function(e){this.isoWeekOfYear=e},write:function(e){return getISOWeekOfYear(e)}}),new Directive({names:["w"],likelyLength:1,minimum:0,maximum:6,store:function(e){this.dayOfWeek=e%7},write:function(e){return getDayOfWeek(e)}}),new Directive({names:["W"],padLength:2,likelyLength:2,minimum:0,maximum:53,store:function(e){this.weekOfYearFromMonday=e},write:function(e){return getWeekOfYearFromMonday(e)}}),new Directive({names:["y"],padLength:2,likelyLength:2,store:function(e){this.twoDigitYear=e},write:function(e){return e.getFullYear()%100}}),new Directive({names:["Y"],padLength:4,likelyLength:4,canBeNegative:!0,store:function(e){this.year=e},write:function(e,t){const i=e.getFullYear();return i<=0&&"^"===t?1-i:i}}),new Directive({names:["z"],text:!0,parse:function(e){this.timezoneOffsetMinutes=this.parseTimezoneOffset(e)},write:function(e,t,i,n){return writeTimezoneOffset(Number.isFinite(n)?n:-e.getTimezoneOffset(),t)}}),new Directive({names:["Z"],likelyLength:5,text:!0,parse:function(e){const t=this.getTimezoneNameList(),i=this.parseIndexInList(t);this.timezoneOffsetMinutes=void 0!==i?60*this.timezoneNames[t[i]]:this.parseTimezoneOffset(e)},write:function(e,t,i,n){const r=Number.isFinite(n)?n:-e.getTimezoneOffset();return 0===r?"UTC":writeTimezoneOffset(r,t)}}),new Directive({names:["+"],rewrite:"%a %b %e %H:%M:%S %Z %Y"}),new Directive({names:["#"],text:!0,parse:function(){this.era=this.parseEraName()},write:function(e,t,i){const n=e.getFullYear()<=0?1:0;return(i&&i.eraNames||english.eraNames)[n]}})],TimestampParseError.prototype=Object.create(Error.prototype),TimestampParseError.prototype.name="TimestampParseError",TimestampParseError.prototype.constructor=TimestampParseError;class TimestampParser{constructor(e,t,i){this.index=0,this.string=String(e),this.format=String(t),this.tokens=i||TimestampParser.parseFormatString(this.format),this.forkLength=0,this.currentToken=void 0,this.shortWeekdayNames=english.shortWeekdayNames,this.longWeekdayNames=english.longWeekdayNames,this.shortMonthNames=english.shortMonthNames,this.longMonthNames=english.longMonthNames,this.eraNames=english.eraNames,this.meridiemNames=english.meridiemNames,this.ordinalTransform=english.ordinalTransform,this.timezoneNames=defaultTimezoneNames,this.era=void 0,this.century=void 0,this.year=void 0,this.twoDigitYear=void 0,this.isoYear=void 0,this.isoTwoDigitYear=void 0,this.month=void 0,this.isoWeekOfYear=void 0,this.weekOfYearFromSunday=void 0,this.weekOfYearFromMonday=void 0,this.dayOfYear=void 0,this.dayOfMonth=void 0,this.dayOfWeek=void 0,this.hour=void 0,this.minute=void 0,this.second=void 0,this.millisecond=void 0,this.microsecond=void 0,this.meridiem=void 0,this.timezoneOffsetMinutes=void 0,this.secondsSinceEpoch=void 0,this.millisecondsSinceEpoch=void 0,this.microsecondsSinceEpoch=void 0}getTimezoneOffsetOfDate(e){const t=void 0===this.timezoneOffsetMinutes?-e.getTimezoneOffset():this.timezoneOffsetMinutes,i=t>=0?1:-1,n=Math.abs(t);return{hour:i*Math.floor(n/60),minute:i*Math.floor(n%60),totalMinutes:t}}getDate(){if(void 0===this.microsecondsSinceEpoch&&(void 0!==this.millisecondsSinceEpoch?this.microsecondsSinceEpoch=1e3*this.millisecondsSinceEpoch:void 0!==this.secondsSinceEpoch&&(this.microsecondsSinceEpoch=1e6*this.secondsSinceEpoch)),void 0!==this.microsecondsSinceEpoch){const e=new Date(this.microsecondsSinceEpoch/1e3),t=this.getTimezoneOffsetOfDate(e);return e.setUTCMinutes(e.getUTCMinutes()-t.totalMinutes),e}const e=new Date;if(void 0===this.year&&void 0!==this.twoDigitYear?void 0===this.century?this.year=getYearFromTwoDigits(this.twoDigitYear):this.year=100*this.century+this.twoDigitYear:void 0===this.isoYear&&void 0!==this.isoTwoDigitYear?this.isoYear=getYearFromTwoDigits(this.isoTwoDigitYear):void 0===this.year&&void 0!==this.century&&(this.year=100*this.century),this.era&&void 0!==this.year&&(this.year=1-this.year),void 0!==this.hour&&void 0!==this.meridiem&&(this.hour=this.hour%12+(this.meridiem?12:0)),void 0===this.microsecond&&void 0!==this.millisecond&&(this.microsecond=1e3*this.millisecond),void 0===this.isoYear||void 0===this.isoWeekOfYear||void 0!==this.month&&void 0!==this.dayOfMonth)if(void 0!==this.dayOfYear){const t=void 0!==this.year?this.year:e.getFullYear();void 0===this.month&&(this.month=getMonthFromDayOfYear(t,this.dayOfYear)),void 0===this.dayOfMonth&&(this.dayOfMonth=getDayOfMonthFromDayOfYear(t,this.dayOfYear))}else if(void 0===this.weekOfYearFromSunday||void 0!==this.month&&void 0!==this.dayOfMonth){if(void 0!==this.weekOfYearFromMonday&&(void 0===this.month||void 0===this.dayOfMonth)){getDateFromMondayWeekDate(this,void 0!==this.year?this.year:e.getFullYear(),this.weekOfYearFromMonday,this.dayOfWeek||0)}}else{getDateFromSundayWeekDate(this,void 0!==this.year?this.year:e.getFullYear(),this.weekOfYearFromSunday,this.dayOfWeek||0)}else getDateFromISOWeekDate(this,this.isoYear,this.isoWeekOfYear,this.dayOfWeek||0);void 0!==this.year&&e.setUTCFullYear(this.year),void 0!==this.month&&e.setUTCMonth(this.month-1),void 0!==this.dayOfMonth&&e.setUTCDate(this.dayOfMonth);const t=this.getTimezoneOffsetOfDate(e);return t.totalMinutes&&(this.hour=(this.hour||0)-t.hour,this.minute=(this.minute||0)-t.minute),e.setUTCHours(this.hour||0),e.setUTCMinutes(this.minute||0),e.setUTCSeconds(this.second||0),e.setUTCMilliseconds(this.microsecond?this.microsecond/1e3:0),e}copy(){const e=new TimestampParser(this.string,this.format,this.tokens);for(let t in this)e[t]=this[t];return e}fork(e,t){const i=this.copy();return i.forkLength=e,i.parse(t)}parse(e){for(let t=e||0;t=this.string.length)throw new TimestampParseError("Timestamp is too short to match the whole format.",this);if(e instanceof Directive.StringToken)this.parseStringToken(e.string);else if(e.hasParseFunction())e.parse(this);else{if(!e.hasStoreFunction()||e.text)throw new TimestampParseError("Invalid directive.",this);{const i=this.tokens[1+t];if(i instanceof Directive.StringToken&&isDigit(i.string[0])||(i instanceof Directive||i instanceof Directive.Token)&&!i.text){const i=this.parseAmbiguousNumber(e,t);if(i)return i}else e.store(this,this.parseNumber(e))}}}if(this.currentToken=void 0,1+this.index=a.length||a[e].toLowerCase()!==s?(t[o]=null,i--):1+e===a.length&&(n=o,r=1+e))}}return void 0===n?void 0:(this.index+=r,n)}getTimezoneNameList(){if(!this.timezoneNameList){this.timezoneNameList=[];for(let e in this.timezoneNames)this.timezoneNameList.push(e)}return this.timezoneNameList}parseTimezoneOffset(e){const t=this.index,i=this.string[this.index],n=+this.string.slice(this.index+1,this.index+3);let r;if(":"===this.string[this.index+3]?(r=+this.string.slice(this.index+4,this.index+6),this.index+=6):(r=+this.string.slice(this.index+3,this.index+5),this.index+=5),!Number.isInteger(n)||!Number.isInteger(r))throw new TimestampParseError("Failed to parse timezone offset from string "+`"${this.string.slice(t,this.index)}".`,this);const s=r+60*n;if("+"===i||"±"===i)return+s;if("-"===i)return-s;throw new TimestampParseError(`Unknown timezone offset sign "${i}".`,this)}}function isLeapYear(e){return e%4==0&&(e%100!=0||e%400==0)}TimestampParser.parseFormatString=function(e){const t=[];let i=!1,n=void 0;const r=String(e);if(!r)throw new TimestampParseError("Empty format string.",{format:r});function s(e){t.length&&t[t.length-1]instanceof Directive.StringToken&&isDigit(e)===isDigit(t[t.length-1].string[0])?t[t.length-1].addCharacter(e):t.push(new Directive.StringToken(e))}for(let e of r)if(i&&"%"===e)s("%"),n="",i=!1;else if(i&&"n"===e)s("\n"),n="",i=!1;else if(i&&"t"===e)s("\t"),n="",i=!1;else if(!i||n||"-"!==e&&"_"!==e&&"^"!==e&&":"!==e)if(i){const s=Directive.getByName(e);if(!s)throw new TimestampParseError(`Unknown directive "%${n}${e}".`,{format:r});s.rewrite?t.push(...s.getRewriteParsed(TimestampParser.parseFormatString)):t.push(new Directive.Token(n,s)),n="",i=!1}else"%"===e?(n="",i=!0):s(e);else n+=e;if(i)throw new TimestampParseError("Found unterminated directive at the end of the format string.",{format:r});return t.length&&"Z"===t[t.length-1].string&&(t.zuluTimezone=!0),t};const monthLengths={common:[31,28,31,30,31,30,31,31,30,31,30,31],leap:[31,29,31,30,31,30,31,31,30,31,30,31],forYear:function(e){return isLeapYear(e)?monthLengths.leap:monthLengths.common}};function getFirstWeekdayInYear(e){const t=e-1;return(365*e+Math.floor(t/4)-Math.floor(t/100)+Math.floor(t/400))%7}const defaultTimezoneNames={ACDT:10.5,ACST:9.5,ACT:-5,ACWST:8.75,ADT:-3,AEDT:11,AEST:10,AFT:4.5,AKDT:-8,AKST:-9,AMST:-3,AMT:-4,AMT:4,ART:-3,AST:3,AST:-4,AWST:8,AZOST:0,AZOT:-1,AZT:4,BDT:8,BIOT:6,BIT:-12,BOT:-4,BRST:-2,BRT:-3,BST:6,BST:11,BST:1,BTT:6,CAT:2,CCT:6.5,CDT:-5,CDT:-4,CEST:2,CET:1,CHADT:13.75,CHAST:12.75,CHOT:8,CHOST:9,CHST:10,CHUT:10,CIST:-8,CIT:8,CKT:-10,CLST:-3,CLT:-4,COST:-4,COT:-5,CST:-6,CST:8,CST:-5,CT:8,CVT:-1,CWST:8.75,CXT:7,DAVT:7,DDUT:10,DFT:1,EASST:-5,EAST:-6,EAT:3,ECT:-4,ECT:-5,EDT:-4,EEST:3,EET:2,EGST:0,EGT:-1,EIT:9,EST:-5,FET:3,FJT:12,FKST:-3,FKT:-4,FNT:-2,GALT:-6,GAMT:-9,GET:4,GFT:-3,GILT:12,GIT:-9,GMT:0,GST:-2,GST:4,GYT:-4,HDT:-9,HAEC:2,HST:-10,HKT:8,HMT:5,HOVST:8,HOVT:7,ICT:7,IDLW:-12,IDT:3,IOT:3,IRDT:4.5,IRKT:8,IRST:3.5,IST:5.5,IST:1,IST:2,JST:9,KGT:6,KOST:11,KRAT:7,KST:9,LHST:10.5,LHST:11,LINT:14,MAGT:12,MART:-9.5,MAWT:5,MDT:-6,MET:1,MEST:2,MHT:12,MIST:11,MIT:-9.5,MMT:6.5,MSK:3,MST:8,MST:-7,MUT:4,MVT:5,MYT:8,NCT:11,NDT:-2.5,NFT:11,NPT:5.75,NST:-3.5,NT:-3.5,NUT:-11,NZDT:13,NZST:12,OMST:6,ORAT:5,PDT:-7,PET:-5,PETT:12,PGT:10,PHOT:13,PHT:8,PKT:5,PMDT:-2,PMST:-3,PONT:11,PST:-8,PST:8,PYST:-3,PYT:-4,RET:4,ROTT:-3,SAKT:11,SAMT:4,SAST:2,SBT:11,SCT:4,SDT:-10,SGT:8,SLST:5.5,SRET:11,SRT:-3,SST:-11,SST:8,SYOT:3,TAHT:-10,THA:7,TFT:5,TJT:5,TKT:13,TLT:9,TMT:5,TRT:3,TOT:13,TVT:12,ULAST:9,ULAT:8,USZ:2,UTC:0,UYST:-2,UYT:-3,UZT:5,VET:-4,VLAT:10,VOLT:4,VOST:6,VUT:11,WAKT:12,WAST:2,WAT:1,WEST:1,WET:0,WIT:7,WST:8,YAKT:9,YEKT:5,Z:0};"undefined"!=typeof module?module.exports=strtime:"undefined"!=typeof window&&(window.strtime=strtime); diff --git a/src/format-time.js b/src/format-time.js index 16f91c9..11ce8ef 100644 --- a/src/format-time.js +++ b/src/format-time.js @@ -117,6 +117,3 @@ const strtime = { }; module.exports = strtime; - -console.log(strftime(new Date("2000-01-01"), "%Y-%m-%dT%H:%M:%S.%LZ")); -console.log(strptime("2000-01-01T00:00:00.000Z", "%Y-%m-%dT%H:%M:%S.%LZ").toISOString());