UNPKG

timezonecomplete

Version:

DateTime, TimeZone, Duration and Period library aimed at providing a consistent and complete date-time interface, away from the original JavaScript Date class.

1 lines 169 kB
!function(f){"object"==typeof exports&&"undefined"!=typeof module?module.exports=f():"function"==typeof define&&define.amd?define([],f):("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).tc=f()}(function(){return function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);throw(f=new Error("Cannot find module '"+i+"'")).code="MODULE_NOT_FOUND",f}c=n[i]={exports:{}},e[i][0].call(c.exports,function(r){return o(e[i][1][r]||r)},c,c.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}({1:[function(require,module,exports){var __spreadArray=this&&this.__spreadArray||function(to,from,pack){if(pack||2===arguments.length)for(var ar,i=0,l=from.length;i<l;i++)!ar&&i in from||((ar=ar||Array.prototype.slice.call(from,0,i))[i]=from[i]);return to.concat(ar||Array.prototype.slice.call(from))},error_1=(Object.defineProperty(exports,"__esModule",{value:!0}),require("./error"));exports.default=function(condition,name,format){for(var args=[],_i=3;_i<arguments.length;_i++)args[_i-3]=arguments[_i];condition||error_1.throwError.apply(void 0,__spreadArray([name,format],args,!1))}},{"./error":5}],2:[function(require,module,exports){Object.defineProperty(exports,"__esModule",{value:!0}),exports.binaryInsertionIndex=exports.TimeStruct=exports.secondOfDay=exports.weekDayNoLeapSecs=exports.timeToUnixNoLeapSecs=exports.unixToTimeNoLeapSecs=exports.weekNumber=exports.weekDayInstanceInMonth=exports.calendarWeekInMonth=exports.weekOfMonth=exports.weekDayOnOrBefore=exports.weekDayOnOrAfter=exports.nthWeekDayOfMonth=exports.firstWeekDayOfMonth=exports.lastWeekDayOfMonth=exports.dayOfYear=exports.daysInMonth=exports.daysInYear=exports.isLeapYear=exports.stringToTimeUnit=exports.timeUnitToString=exports.timeUnitToMilliseconds=exports.TimeUnit=exports.WeekDay=void 0;var WeekDay,TimeUnit,assert_1=require("./assert"),error_1=require("./error"),javascript_1=require("./javascript"),math=require("./math"),strings=require("./strings");function timeUnitToString(unit,amount){return void 0===amount&&(amount=1),!Number.isInteger(unit)||unit<0||unit>=TimeUnit.MAX?(0,error_1.throwError)("Argument.Unit","invalid time unit %d",unit):(unit=TimeUnit[unit].toLowerCase(),1===amount||-1===amount?unit:unit+"s")}function isLeapYear(year){return(0,assert_1.default)(Number.isInteger(year),"Argument.Year","Invalid year %d",year),year%4==0&&(year%100!=0||year%400==0)}function daysInYear(year){return isLeapYear(year)?366:365}function daysInMonth(year,month){switch(month){case 1:case 3:case 5:case 7:case 8:case 10:case 12:return 31;case 2:return isLeapYear(year)?29:28;case 4:case 6:case 9:case 11:return 30;default:return(0,error_1.throwError)("Argument.Month","Invalid month: %d",month)}}function dayOfYear(year,month,day){(0,assert_1.default)(Number.isInteger(year),"Argument.Year","Year out of range: %d",year),(0,assert_1.default)(Number.isInteger(month)&&1<=month&&month<=12,"Argument.Month","Month out of range: %d",month),(0,assert_1.default)(Number.isInteger(day)&&1<=day&&day<=daysInMonth(year,month),"Argument.Day","day out of range");for(var yearDay=0,i=1;i<month;i++)yearDay+=daysInMonth(year,i);return yearDay+=day-1}function lastWeekDayOfMonth(year,month,weekDay){(0,assert_1.default)(Number.isInteger(year),"Argument.Year","Year out of range: %d",year),(0,assert_1.default)(Number.isInteger(month)&&1<=month&&month<=12,"Argument.Month","Month out of range: %d",month),(0,assert_1.default)(Number.isInteger(weekDay)&&0<=weekDay&&weekDay<=6,"Argument.WeekDay","weekDay out of range: %d",weekDay);year=new TimeStruct({year:year,month:month,day:daysInMonth(year,month)}),month=weekDay-weekDayNoLeapSecs(year.unixMillis);return 0<month&&(month-=7),year.components.day+month}function firstWeekDayOfMonth(year,month,weekDay){(0,assert_1.default)(Number.isInteger(year),"Argument.Year","Year out of range: %d",year),(0,assert_1.default)(Number.isInteger(month)&&1<=month&&month<=12,"Argument.Month","Month out of range: %d",month),(0,assert_1.default)(Number.isInteger(weekDay)&&0<=weekDay&&weekDay<=6,"Argument.WeekDay","weekDay out of range: %d",weekDay);year=new TimeStruct({year:year,month:month,day:1}),month=weekDay-weekDayNoLeapSecs(year.unixMillis);return month<0&&(month+=7),year.components.day+month}function weekDayOnOrAfter(year,month,day,weekDay){(0,assert_1.default)(Number.isInteger(year),"Argument.Year","Year out of range: %d",year),(0,assert_1.default)(Number.isInteger(month)&&1<=month&&month<=12,"Argument.Month","Month out of range: %d",month),(0,assert_1.default)(Number.isInteger(day)&&1<=day&&day<=daysInMonth(year,month),"Argument.Day","day out of range"),(0,assert_1.default)(Number.isInteger(weekDay)&&0<=weekDay&&weekDay<=6,"Argument.WeekDay","weekDay out of range: %d",weekDay);day=new TimeStruct({year:year,month:month,day:day}),weekDay-=weekDayNoLeapSecs(day.unixMillis);return weekDay<0&&(weekDay+=7),(0,assert_1.default)(day.components.day+weekDay<=daysInMonth(year,month),"NotFound","The given month has no such weekday"),day.components.day+weekDay}function getWeekOneDayOfYear(year){var result=weekDayOnOrAfter(year,1,1,WeekDay.Monday)-1;return 3<result&&(result-=7)<0&&(result+=exports.daysInYear(year-1)),result}function unixToTimeNoLeapSecs(unixMillis){(0,assert_1.default)(Number.isInteger(unixMillis),"Argument.UnixMillis","unixMillis should be an integer number");var year,month,temp=unixMillis,result={year:0,month:0,day:0,hour:0,minute:0,second:0,milli:0};if(0<=unixMillis){for(result.milli=math.positiveModulo(temp,1e3),temp=Math.floor(temp/1e3),result.second=math.positiveModulo(temp,60),temp=Math.floor(temp/60),result.minute=math.positiveModulo(temp,60),temp=Math.floor(temp/60),result.hour=math.positiveModulo(temp,24),temp=Math.floor(temp/24),year=1970;temp>=daysInYear(year);)temp-=daysInYear(year),year++;for(result.year=year,month=1;temp>=daysInMonth(year,month);)temp-=daysInMonth(year,month),month++;result.month=month,result.day=temp+1}else{for(result.milli=math.positiveModulo(temp,1e3),temp=Math.floor(temp/1e3),result.second=math.positiveModulo(temp,60),temp=Math.floor(temp/60),result.minute=math.positiveModulo(temp,60),temp=Math.floor(temp/60),result.hour=math.positiveModulo(temp,24),temp=Math.floor(temp/24),year=1969;temp<-daysInYear(year);)temp+=daysInYear(year),year--;for(result.year=year,month=12;temp<-daysInMonth(year,month);)temp+=daysInMonth(year,month),month--;result.month=month,result.day=temp+1+daysInMonth(year,month)}return result}function normalizeTimeComponents(components){components={year:"number"==typeof components.year?components.year:1970,month:"number"==typeof components.month?components.month:1,day:"number"==typeof components.day?components.day:1,hour:"number"==typeof components.hour?components.hour:0,minute:"number"==typeof components.minute?components.minute:0,second:"number"==typeof components.second?components.second:0,milli:"number"==typeof components.milli?components.milli:0};return(0,assert_1.default)(Number.isInteger(components.year),"Argument.Year","invalid year %d",components.year),(0,assert_1.default)(Number.isInteger(components.month)&&1<=components.month&&components.month<=12,"Argument.Month","invalid month %d",components.month),(0,assert_1.default)(Number.isInteger(components.day)&&1<=components.day&&components.day<=daysInMonth(components.year,components.month),"Argument.Day","invalid day %d",components.day),(0,assert_1.default)(Number.isInteger(components.hour)&&0<=components.hour&&components.hour<=23,"Argument.Hour","invalid hour %d",components.hour),(0,assert_1.default)(Number.isInteger(components.minute)&&0<=components.minute&&components.minute<=59,"Argument.Minute","invalid minute %d",components.minute),(0,assert_1.default)(Number.isInteger(components.second)&&0<=components.second&&components.second<=59,"Argument.Second","invalid second %d",components.second),(0,assert_1.default)(Number.isInteger(components.milli)&&0<=components.milli&&components.milli<=999,"Argument.Milli","invalid milli %d",components.milli),components}function timeToUnixNoLeapSecs(a,month,day,hour,minute,second,milli){month=normalizeTimeComponents("number"==typeof a?{year:a,month:month,day:day,hour:hour,minute:minute,second:second,milli:milli}:a);return month.milli+1e3*(month.second+60*month.minute+3600*month.hour+86400*dayOfYear(month.year,month.month,month.day)+31536e3*(month.year-1970)+86400*Math.floor((month.year-1969)/4)-86400*Math.floor((month.year-1901)/100)+86400*Math.floor((month.year-1900+299)/400))}function weekDayNoLeapSecs(unixMillis){(0,assert_1.default)(Number.isInteger(unixMillis),"Argument.UnixMillis","unixMillis should be an integer number");var epochDay=WeekDay.Thursday,unixMillis=Math.floor(unixMillis/1e3/86400);return math.positiveModulo(epochDay+unixMillis,7)}(WeekDay=>{WeekDay[WeekDay.Sunday=0]="Sunday",WeekDay[WeekDay.Monday=1]="Monday",WeekDay[WeekDay.Tuesday=2]="Tuesday",WeekDay[WeekDay.Wednesday=3]="Wednesday",WeekDay[WeekDay.Thursday=4]="Thursday",WeekDay[WeekDay.Friday=5]="Friday",WeekDay[WeekDay.Saturday=6]="Saturday"})(WeekDay||(exports.WeekDay=WeekDay={})),(TimeUnit=>{TimeUnit[TimeUnit.Millisecond=0]="Millisecond",TimeUnit[TimeUnit.Second=1]="Second",TimeUnit[TimeUnit.Minute=2]="Minute",TimeUnit[TimeUnit.Hour=3]="Hour",TimeUnit[TimeUnit.Day=4]="Day",TimeUnit[TimeUnit.Week=5]="Week",TimeUnit[TimeUnit.Month=6]="Month",TimeUnit[TimeUnit.Year=7]="Year",TimeUnit[TimeUnit.MAX=8]="MAX"})(TimeUnit||(exports.TimeUnit=TimeUnit={})),exports.timeUnitToMilliseconds=function(unit){switch(unit){case TimeUnit.Millisecond:return 1;case TimeUnit.Second:return 1e3;case TimeUnit.Minute:return 6e4;case TimeUnit.Hour:return 36e5;case TimeUnit.Day:return 864e5;case TimeUnit.Week:return 6048e5;case TimeUnit.Month:return 2592e6;case TimeUnit.Year:return 31104e6;default:return(0,error_1.throwError)("Argument.Unit","unknown time unit %d",unit)}},exports.timeUnitToString=timeUnitToString,exports.stringToTimeUnit=function(s){for(var trimmed=s.trim().toLowerCase(),i=0;i<TimeUnit.MAX;++i){var other=timeUnitToString(i,1);if(other===trimmed||other+"s"===trimmed)return i}return(0,error_1.throwError)("Argument.S","Unknown time unit string '%s'",s)},exports.isLeapYear=isLeapYear,exports.daysInYear=daysInYear,exports.daysInMonth=daysInMonth,exports.dayOfYear=dayOfYear,exports.lastWeekDayOfMonth=lastWeekDayOfMonth,exports.firstWeekDayOfMonth=firstWeekDayOfMonth,exports.nthWeekDayOfMonth=function(year,month,weekDay,dayInstance){(0,assert_1.default)(Number.isInteger(year),"Argument.Year","Year out of range: %d",year),(0,assert_1.default)(Number.isInteger(month)&&1<=month&&month<=12,"Argument.Month","Month out of range: %d",month),(0,assert_1.default)(Number.isInteger(weekDay)&&0<=weekDay&&weekDay<=6,"Argument.WeekDay","weekDay out of range: %d",weekDay),(0,assert_1.default)(Number.isInteger(dayInstance)&&1<=dayInstance&&dayInstance<=5,"Argument.DayInstance","dayInstance out of range: %d",dayInstance);var beginOfMonth=new TimeStruct({year:year,month:month,day:1});return(weekDay=weekDay-weekDayNoLeapSecs(beginOfMonth.unixMillis))<0&&(weekDay+=7),(0,assert_1.default)(beginOfMonth.components.day+(weekDay+=7*(dayInstance-1))<=daysInMonth(year,month),"NotFound","The given month has no such day"),beginOfMonth.components.day+weekDay},exports.weekDayOnOrAfter=weekDayOnOrAfter,exports.weekDayOnOrBefore=function(year,month,day,weekDay){return(0,assert_1.default)(Number.isInteger(year),"Argument.Year","Year out of range: %d",year),(0,assert_1.default)(Number.isInteger(month)&&1<=month&&month<=12,"Argument.Month","Month out of range: %d",month),(0,assert_1.default)(Number.isInteger(day)&&1<=day&&day<=daysInMonth(year,month),"Argument.Day","day out of range"),(0,assert_1.default)(Number.isInteger(weekDay)&&0<=weekDay&&weekDay<=6,"Argument.WeekDay","weekDay out of range: %d",weekDay),year=new TimeStruct({year:year,month:month,day:day}),0<(month=weekDay-weekDayNoLeapSecs(year.unixMillis))&&(month-=7),(0,assert_1.default)(1<=year.components.day+month,"NotFound","The given month has no such weekday"),year.components.day+month},exports.weekOfMonth=function weekOfMonth(year,month,day){(0,assert_1.default)(Number.isInteger(day)&&1<=day&&day<=daysInMonth(year,month),"Argument.Day","day out of range");var lastMonday,firstThursday=firstWeekDayOfMonth(year,month,WeekDay.Thursday),firstMonday=firstWeekDayOfMonth(year,month,WeekDay.Monday);return day<firstMonday?firstThursday<firstMonday?1:1<month?weekOfMonth(year,month-1,daysInMonth(year,month-1)):weekOfMonth(year-1,12,31):(lastMonday=lastWeekDayOfMonth(year,month,WeekDay.Monday),year=lastWeekDayOfMonth(year,month,WeekDay.Thursday),lastMonday<=day&&year<lastMonday?1:(month=Math.floor((day-firstMonday)/7)+1,firstThursday<4&&(month+=1),month))},exports.calendarWeekInMonth=function(year,month,day,weekStartDay){return void 0===weekStartDay&&(weekStartDay=WeekDay.Monday),(0,assert_1.default)(Number.isInteger(day)&&1<=day&&day<=daysInMonth(year,month),"Argument.Day","day out of range"),year=weekDayOnOrAfter(year,month,1,weekStartDay),month=Math.floor((day-year+7)/7),1<year&&month++,month},exports.weekDayInstanceInMonth=function(year,month,day){return(day-firstWeekDayOfMonth(year,month,weekDayNoLeapSecs(new TimeStruct({year:year,month:month,day:day}).unixMillis)))/7+1},exports.weekNumber=function weekNumber(year,month,day){month=dayOfYear(year,month,day);if(month>=dayOfYear(year,12,29)&&4<(day=getWeekOneDayOfYear(year+1))&&day<=month)return 1;var weekTwo,day=getWeekOneDayOfYear(year);return 4<day?month<(weekTwo=day+7-daysInYear(year-1))?1:Math.floor((month-weekTwo)/7)+2:month<day?weekNumber(year-1,12,31):Math.floor((month-day)/7)+1},exports.unixToTimeNoLeapSecs=unixToTimeNoLeapSecs,exports.timeToUnixNoLeapSecs=timeToUnixNoLeapSecs,exports.weekDayNoLeapSecs=weekDayNoLeapSecs,exports.secondOfDay=function(hour,minute,second){return(0,assert_1.default)(Number.isInteger(hour)&&0<=hour&&hour<=23,"Argument.Hour","invalid hour %d",hour),(0,assert_1.default)(Number.isInteger(minute)&&0<=minute&&minute<=59,"Argument.Minute","invalid minute %d",minute),(0,assert_1.default)(Number.isInteger(second)&&0<=second&&second<=61,"Argument.Second","invalid second %d",second),60*(60*hour+minute)+second};var TimeStruct=(()=>{function TimeStruct(a){"number"==typeof a?((0,assert_1.default)(Number.isInteger(a),"Argument.UnixMillis","invalid unix millis %d",a),this._unixMillis=a):((0,assert_1.default)("object"==typeof a&&null!==a,"Argument.Components","invalid components object"),this._components=normalizeTimeComponents(a))}return TimeStruct.fromComponents=function(year,month,day,hour,minute,second,milli){return new TimeStruct({year:year,month:month,day:day,hour:hour,minute:minute,second:second,milli:milli})},TimeStruct.fromUnix=function(unixMillis){return new TimeStruct(unixMillis)},TimeStruct.fromDate=function(d,df){return df===javascript_1.DateFunctions.Get?new TimeStruct({year:d.getFullYear(),month:d.getMonth()+1,day:d.getDate(),hour:d.getHours(),minute:d.getMinutes(),second:d.getSeconds(),milli:d.getMilliseconds()}):new TimeStruct({year:d.getUTCFullYear(),month:d.getUTCMonth()+1,day:d.getUTCDate(),hour:d.getUTCHours(),minute:d.getUTCMinutes(),second:d.getUTCSeconds(),milli:d.getUTCMilliseconds()})},TimeStruct.fromString=function(s){try{var dateAndTime,year=1970,month=1,day=1,hour=0,minute=0,second=0,fractionMillis=0,lastUnit=TimeUnit.Year,split=s.trim().split(".");if((0,assert_1.default)(1<=split.length&&split.length<=2,"Argument.S","Empty string or multiple dots."),-1===s.indexOf("-")?((0,assert_1.default)(split[0].match(/^((\d)+)|(\d\d\d\d\d\d\d\dT(\d)+)$/),"Argument.S","ISO string in basic notation may only contain numbers before the fractional part"),split[0]=split[0].replace("T",""),(0,assert_1.default)(-1!==[4,8,10,12,14].indexOf(split[0].length),"Argument.S","Padding or required components are missing. Note that YYYYMM is not valid per ISO 8601"),4<=split[0].length&&(year=parseInt(split[0].substr(0,4),10),lastUnit=TimeUnit.Year),8<=split[0].length&&(month=parseInt(split[0].substr(4,2),10),day=parseInt(split[0].substr(6,2),10),lastUnit=TimeUnit.Day),10<=split[0].length&&(hour=parseInt(split[0].substr(8,2),10),lastUnit=TimeUnit.Hour),12<=split[0].length&&(minute=parseInt(split[0].substr(10,2),10),lastUnit=TimeUnit.Minute),14<=split[0].length&&(second=parseInt(split[0].substr(12,2),10),lastUnit=TimeUnit.Second)):((0,assert_1.default)(split[0].match(/^\d\d\d\d(-\d\d-\d\d((T)?\d\d(\:\d\d(:\d\d)?)?)?)?$/),"Argument.S","Invalid ISO string"),dateAndTime=[],dateAndTime=-1!==s.indexOf("T")?split[0].split("T"):10<s.length?[split[0].substr(0,10),split[0].substr(10)]:[split[0],""],(0,assert_1.default)(-1!==[4,10].indexOf(dateAndTime[0].length),"Argument.S","Padding or required components are missing. Note that YYYYMM is not valid per ISO 8601"),4<=dateAndTime[0].length&&(year=parseInt(dateAndTime[0].substr(0,4),10),lastUnit=TimeUnit.Year),10<=dateAndTime[0].length&&(month=parseInt(dateAndTime[0].substr(5,2),10),day=parseInt(dateAndTime[0].substr(8,2),10),lastUnit=TimeUnit.Day),2<=dateAndTime[1].length&&(hour=parseInt(dateAndTime[1].substr(0,2),10),lastUnit=TimeUnit.Hour),5<=dateAndTime[1].length&&(minute=parseInt(dateAndTime[1].substr(3,2),10),lastUnit=TimeUnit.Minute),8<=dateAndTime[1].length&&(second=parseInt(dateAndTime[1].substr(6,2),10),lastUnit=TimeUnit.Second)),1<split.length&&0<split[1].length){var fraction=parseFloat("0."+split[1]);switch(lastUnit){case TimeUnit.Year:fractionMillis=864e5*daysInYear(year)*fraction;break;case TimeUnit.Day:fractionMillis=864e5*fraction;break;case TimeUnit.Hour:fractionMillis=36e5*fraction;break;case TimeUnit.Minute:fractionMillis=6e4*fraction;break;case TimeUnit.Second:fractionMillis=1e3*fraction}}var unixMillis=timeToUnixNoLeapSecs({year:year=math.roundSym(year),month:month=math.roundSym(month),day:day=math.roundSym(day),hour:hour=math.roundSym(hour),minute:minute=math.roundSym(minute),second:second=math.roundSym(second)});return new TimeStruct(math.roundSym(unixMillis+fractionMillis))}catch(e){if((0,error_1.errorIs)(e,["Argument.S","Argument.Year","Argument.Month","Argument.Day","Argument.Hour","Argument.Minute","Argument.Second","Argument.Milli"]))return(0,error_1.throwError)("Argument.S",'Invalid ISO 8601 string: "%s": %s',s,e.message);throw e}},Object.defineProperty(TimeStruct.prototype,"unixMillis",{get:function(){return void 0===this._unixMillis&&(this._unixMillis=timeToUnixNoLeapSecs(this._components)),this._unixMillis},enumerable:!1,configurable:!0}),Object.defineProperty(TimeStruct.prototype,"components",{get:function(){return this._components||(this._components=unixToTimeNoLeapSecs(this._unixMillis)),this._components},enumerable:!1,configurable:!0}),Object.defineProperty(TimeStruct.prototype,"year",{get:function(){return this.components.year},enumerable:!1,configurable:!0}),Object.defineProperty(TimeStruct.prototype,"month",{get:function(){return this.components.month},enumerable:!1,configurable:!0}),Object.defineProperty(TimeStruct.prototype,"day",{get:function(){return this.components.day},enumerable:!1,configurable:!0}),Object.defineProperty(TimeStruct.prototype,"hour",{get:function(){return this.components.hour},enumerable:!1,configurable:!0}),Object.defineProperty(TimeStruct.prototype,"minute",{get:function(){return this.components.minute},enumerable:!1,configurable:!0}),Object.defineProperty(TimeStruct.prototype,"second",{get:function(){return this.components.second},enumerable:!1,configurable:!0}),Object.defineProperty(TimeStruct.prototype,"milli",{get:function(){return this.components.milli},enumerable:!1,configurable:!0}),TimeStruct.prototype.yearDay=function(){return dayOfYear(this.components.year,this.components.month,this.components.day)},TimeStruct.prototype.equals=function(other){return this.valueOf()===other.valueOf()},TimeStruct.prototype.valueOf=function(){return this.unixMillis},TimeStruct.prototype.clone=function(){return this._components?new TimeStruct(this._components):new TimeStruct(this._unixMillis)},TimeStruct.prototype.validate=function(){return!this._components||1<=this.components.month&&this.components.month<=12&&1<=this.components.day&&this.components.day<=daysInMonth(this.components.year,this.components.month)&&0<=this.components.hour&&this.components.hour<=23&&0<=this.components.minute&&this.components.minute<=59&&0<=this.components.second&&this.components.second<=59&&0<=this.components.milli&&this.components.milli<=999},TimeStruct.prototype.toString=function(){return strings.padLeft(this.components.year.toString(10),4,"0")+"-"+strings.padLeft(this.components.month.toString(10),2,"0")+"-"+strings.padLeft(this.components.day.toString(10),2,"0")+"T"+strings.padLeft(this.components.hour.toString(10),2,"0")+":"+strings.padLeft(this.components.minute.toString(10),2,"0")+":"+strings.padLeft(this.components.second.toString(10),2,"0")+"."+strings.padLeft(this.components.milli.toString(10),3,"0")},TimeStruct})();exports.TimeStruct=TimeStruct,exports.binaryInsertionIndex=function(arr,compare){var currentIndex,currentElement,minIndex=0,maxIndex=arr.length-1;if(!arr)return 0;if(0===arr.length)return 0;if(0<compare(arr[0]))return 0;if(compare(arr[maxIndex])<0)return maxIndex+1;for(;minIndex<=maxIndex;)if(compare(currentElement=arr[currentIndex=Math.floor((minIndex+maxIndex)/2)])<0)minIndex=currentIndex+1;else{if(!(0<compare(currentElement)))return currentIndex;maxIndex=currentIndex-1}return maxIndex}},{"./assert":1,"./error":5,"./javascript":8,"./math":10,"./strings":13}],3:[function(require,module,exports){Object.defineProperty(exports,"__esModule",{value:!0}),exports.isDateTime=exports.DateTime=exports.now=exports.nowUtc=exports.nowLocal=void 0;var assert_1=require("./assert"),basics=require("./basics"),basics_1=require("./basics"),duration_1=require("./duration"),error_1=require("./error"),format=require("./format"),javascript_1=require("./javascript"),math=require("./math"),parseFuncs=require("./parse"),timesource_1=require("./timesource"),timezone_1=require("./timezone"),tz_database_1=require("./tz-database");function convertToUtc(localTime,fromZone){return fromZone?(fromZone=fromZone.offsetForZone(localTime),new basics_1.TimeStruct(localTime.unixMillis-6e4*fromZone)):localTime.clone()}function convertFromUtc(utcTime,toZone){var offset;return toZone?(offset=toZone.offsetForUtc(utcTime),toZone.normalizeZoneTime(new basics_1.TimeStruct(utcTime.unixMillis+6e4*offset))):utcTime.clone()}exports.nowLocal=function(){return DateTime.nowLocal()},exports.nowUtc=function(){return DateTime.nowUtc()},exports.now=function(timeZone){return void 0===timeZone&&(timeZone=timezone_1.TimeZone.utc()),DateTime.now(timeZone)};var DateTime=(()=>{function DateTime(a1,a2,a3,h,m,s,ms,timeZone){switch(this.kind="DateTime",typeof a1){case"number":var year_1,month_1,day_1,hour_1,minute_1,second_1,milli_1;"number"!=typeof a2?((0,assert_1.default)(void 0===a3&&void 0===h&&void 0===m&&void 0===s&&void 0===ms&&void 0===timeZone,"Argument.A3","for unix timestamp datetime constructor, third through 8th argument must be undefined"),(0,assert_1.default)(null==a2||isTimeZone(a2),"Argument.TimeZone","DateTime.DateTime(): second arg should be a TimeZone object."),this._zone="object"==typeof a2&&isTimeZone(a2)?a2:void 0,unixMillis=(0,error_1.convertError)("Argument.UnixMillis",function(){return math.roundSym(a1)}),this._zone?this._zoneDate=this._zone.normalizeZoneTime(new basics_1.TimeStruct(unixMillis)):this._zoneDate=new basics_1.TimeStruct(unixMillis)):((0,assert_1.default)("number"==typeof a2,"Argument.Year","DateTime.DateTime(): Expect month to be a number."),(0,assert_1.default)("number"==typeof a3,"Argument.Month","DateTime.DateTime(): Expect day to be a number."),(0,assert_1.default)(null==timeZone||isTimeZone(timeZone),"Argument.TimeZone","DateTime.DateTime(): eighth arg should be a TimeZone object."),year_1=a1,month_1=a2,day_1=a3,hour_1="number"==typeof h?h:0,minute_1="number"==typeof m?m:0,second_1="number"==typeof s?s:0,milli_1="number"==typeof ms?ms:0,year_1=(0,error_1.convertError)("Argument.Year",function(){return math.roundSym(year_1)}),month_1=(0,error_1.convertError)("Argument.Month",function(){return math.roundSym(month_1)}),day_1=(0,error_1.convertError)("Argument.Day",function(){return math.roundSym(day_1)}),hour_1=(0,error_1.convertError)("Argument.Hour",function(){return math.roundSym(hour_1)}),minute_1=(0,error_1.convertError)("Argument.Minute",function(){return math.roundSym(minute_1)}),second_1=(0,error_1.convertError)("Argument.Second",function(){return math.roundSym(second_1)}),milli_1=(0,error_1.convertError)("Argument.Milli",function(){return math.roundSym(milli_1)}),unixMillis=new basics_1.TimeStruct({year:year_1,month:month_1,day:day_1,hour:hour_1,minute:minute_1,second:second_1,milli:milli_1}),this._zone="object"==typeof timeZone&&isTimeZone(timeZone)?timeZone:void 0,this._zone?this._zoneDate=this._zone.normalizeZoneTime(unixMillis):this._zoneDate=unixMillis);break;case"string":"string"==typeof a2?((0,assert_1.default)(void 0===h&&void 0===m&&void 0===s&&void 0===ms&&void 0===timeZone,"Argument.A4","first two arguments are a string, therefore the fourth through 8th argument must be undefined"),(0,assert_1.default)(null==a3||isTimeZone(a3),"Argument.TimeZone","DateTime.DateTime(): third arg should be a TimeZone object."),unixMillis=void 0,"object"==typeof a3&&isTimeZone(a3)&&(unixMillis=a3),unixMillis=parseFuncs.parse(a1,a2,unixMillis),this._zoneDate=unixMillis.time,this._zone=unixMillis.zone):((0,assert_1.default)(void 0===a3&&void 0===h&&void 0===m&&void 0===s&&void 0===ms&&void 0===timeZone,"Argument.A3","first arguments is a string and the second is not, therefore the third through 8th argument must be undefined"),(0,assert_1.default)(null==a2||isTimeZone(a2),"Argument.TimeZone","DateTime.DateTime(): second arg should be a TimeZone object."),unixMillis=a1.trim(),unixMillis=DateTime._splitDateFromTimeZone(unixMillis),(0,assert_1.default)(2===unixMillis.length,"Argument.S",'Invalid date string given: "'+a1+'"'),isTimeZone(a2)?this._zone=a2:this._zone=unixMillis[1].trim()?timezone_1.TimeZone.zone(unixMillis[1]):void 0,this._zoneDate=basics_1.TimeStruct.fromString(unixMillis[0]),this._zone&&(this._zoneDate=this._zone.normalizeZoneTime(this._zoneDate)));break;case"object":var unixMillis,dk;a1 instanceof Date?((0,assert_1.default)(void 0===h&&void 0===m&&void 0===s&&void 0===ms&&void 0===timeZone,"Argument.A4","first argument is a Date, therefore the fourth through 8th argument must be undefined"),(0,assert_1.default)("number"==typeof a2&&(a2===javascript_1.DateFunctions.Get||a2===javascript_1.DateFunctions.GetUTC),"Argument.GetFuncs","DateTime.DateTime(): for a Date object a DateFunctions must be passed as second argument"),(0,assert_1.default)(null==a3||isTimeZone(a3),"Argument.TimeZone","DateTime.DateTime(): third arg should be a TimeZone object."),unixMillis=a1,dk=a2,this._zone=a3||void 0,this._zoneDate=basics_1.TimeStruct.fromDate(unixMillis,dk),this._zone&&(this._zoneDate=this._zone.normalizeZoneTime(this._zoneDate))):((0,assert_1.default)(void 0===a3&&void 0===h&&void 0===m&&void 0===s&&void 0===ms&&void 0===timeZone,"Argument.A3","first argument is a TimeStruct, therefore the third through 8th argument must be undefined"),(0,assert_1.default)(null==a2||isTimeZone(a2),"Argument.TimeZone","expect a TimeZone as second argument"),this._zoneDate=a1.clone(),this._zone=a2||void 0);break;case"undefined":(0,assert_1.default)(void 0===a2&&void 0===a3&&void 0===h&&void 0===m&&void 0===s&&void 0===ms&&void 0===timeZone,"Argument.A2","first argument is undefined, therefore the rest must also be undefined"),this._zone=timezone_1.TimeZone.local(),this._utcDate=basics_1.TimeStruct.fromDate(DateTime.timeSource.now(),javascript_1.DateFunctions.GetUTC);break;default:throw(0,error_1.error)("Argument.A1","DateTime.DateTime(): unexpected first argument type.")}}return Object.defineProperty(DateTime.prototype,"utcDate",{get:function(){return this._utcDate||(this._utcDate=convertToUtc(this._zoneDate,this._zone)),this._utcDate},set:function(value){this._utcDate=value,this._zoneDate=void 0},enumerable:!1,configurable:!0}),Object.defineProperty(DateTime.prototype,"zoneDate",{get:function(){return this._zoneDate||(this._zoneDate=convertFromUtc(this._utcDate,this._zone)),this._zoneDate},set:function(value){this._zoneDate=value,this._utcDate=void 0},enumerable:!1,configurable:!0}),DateTime.nowLocal=function(){var n=DateTime.timeSource.now();return new DateTime(n,javascript_1.DateFunctions.Get,timezone_1.TimeZone.local())},DateTime.nowUtc=function(){return new DateTime(DateTime.timeSource.now(),javascript_1.DateFunctions.GetUTC,timezone_1.TimeZone.utc())},DateTime.now=function(timeZone){return void 0===timeZone&&(timeZone=timezone_1.TimeZone.utc()),new DateTime(DateTime.timeSource.now(),javascript_1.DateFunctions.GetUTC,timezone_1.TimeZone.utc()).toZone(timeZone)},DateTime.fromExcel=function(n,timeZone){return(0,assert_1.default)(Number.isFinite(n),"Argument.N","invalid number"),new DateTime(Math.round(24*(n-25569)*60*60*1e3),timeZone)},DateTime.exists=function(year,month,day,hour,minute,second,millisecond,zone,allowPre1970){if(void 0===month&&(month=1),void 0===day&&(day=1),void 0===hour&&(hour=0),void 0===minute&&(minute=0),void 0===second&&(second=0),void 0===millisecond&&(millisecond=0),void 0===allowPre1970&&(allowPre1970=!1),!(isFinite(year)&&isFinite(month)&&isFinite(day)&&isFinite(hour)&&isFinite(minute)&&isFinite(second)&&isFinite(millisecond)))return!1;if(!allowPre1970&&year<1970)return!1;try{var dt=new DateTime(year,month,day,hour,minute,second,millisecond,zone);return year===dt.year()&&month===dt.month()&&day===dt.day()&&hour===dt.hour()&&minute===dt.minute()&&second===dt.second()&&millisecond===dt.millisecond()}catch(e){return!1}},DateTime.prototype.clone=function(){return new DateTime(this.zoneDate,this._zone)},DateTime.prototype.zone=function(){return this._zone},DateTime.prototype.zoneAbbreviation=function(dstDependent){return void 0===dstDependent&&(dstDependent=!0),this._zone?this._zone.abbreviationForUtc(this.utcDate,dstDependent):""},DateTime.prototype.offset=function(){return Math.round((this.zoneDate.unixMillis-this.utcDate.unixMillis)/6e4)},DateTime.prototype.offsetDuration=function(){return duration_1.Duration.milliseconds(Math.round(this.zoneDate.unixMillis-this.utcDate.unixMillis))},DateTime.prototype.standardOffsetDuration=function(){return this._zone?duration_1.Duration.minutes(this._zone.standardOffsetForUtc(this.utcDate)):duration_1.Duration.minutes(0)},DateTime.prototype.year=function(){return this.zoneDate.components.year},DateTime.prototype.month=function(){return this.zoneDate.components.month},DateTime.prototype.day=function(){return this.zoneDate.components.day},DateTime.prototype.hour=function(){return this.zoneDate.components.hour},DateTime.prototype.minute=function(){return this.zoneDate.components.minute},DateTime.prototype.second=function(){return this.zoneDate.components.second},DateTime.prototype.millisecond=function(){return this.zoneDate.components.milli},DateTime.prototype.weekDay=function(){return basics.weekDayNoLeapSecs(this.zoneDate.unixMillis)},DateTime.prototype.dayOfYear=function(){return this.zoneDate.yearDay()},DateTime.prototype.weekNumber=function(){return basics.weekNumber(this.year(),this.month(),this.day())},DateTime.prototype.weekOfMonth=function(){return basics.weekOfMonth(this.year(),this.month(),this.day())},DateTime.prototype.secondOfDay=function(){return basics.secondOfDay(this.hour(),this.minute(),this.second())},DateTime.prototype.unixUtcMillis=function(){return this.utcDate.unixMillis},DateTime.prototype.utcYear=function(){return this.utcDate.components.year},DateTime.prototype.utcMonth=function(){return this.utcDate.components.month},DateTime.prototype.utcDay=function(){return this.utcDate.components.day},DateTime.prototype.utcHour=function(){return this.utcDate.components.hour},DateTime.prototype.utcMinute=function(){return this.utcDate.components.minute},DateTime.prototype.utcSecond=function(){return this.utcDate.components.second},DateTime.prototype.utcDayOfYear=function(){return basics.dayOfYear(this.utcYear(),this.utcMonth(),this.utcDay())},DateTime.prototype.utcMillisecond=function(){return this.utcDate.components.milli},DateTime.prototype.utcWeekDay=function(){return basics.weekDayNoLeapSecs(this.utcDate.unixMillis)},DateTime.prototype.utcWeekNumber=function(){return basics.weekNumber(this.utcYear(),this.utcMonth(),this.utcDay())},DateTime.prototype.utcWeekOfMonth=function(){return basics.weekOfMonth(this.utcYear(),this.utcMonth(),this.utcDay())},DateTime.prototype.utcSecondOfDay=function(){return basics.secondOfDay(this.utcHour(),this.utcMinute(),this.utcSecond())},DateTime.prototype.withZone=function(zone){return new DateTime(this.year(),this.month(),this.day(),this.hour(),this.minute(),this.second(),this.millisecond(),zone)},DateTime.prototype.convert=function(zone){if(zone){if(!this._zone)return(0,error_1.throwError)("UnawareToAwareConversion","DateTime.toZone(): Cannot convert unaware date to an aware date");this._zone.equals(zone)?this._zone=zone:(this._utcDate||(this._utcDate=convertToUtc(this._zoneDate,this._zone)),this._zone=zone,this._zoneDate=void 0)}else{if(!this._zone)return this;this._zoneDate||(this._zoneDate=convertFromUtc(this._utcDate,this._zone)),this._zone=void 0,this._utcDate=void 0}return this},DateTime.prototype.toZone=function(zone){var result;return zone?((0,assert_1.default)(this._zone,"UnawareToAwareConversion","DateTime.toZone(): Cannot convert unaware date to an aware date"),(result=new DateTime).utcDate=this.utcDate,result._zone=zone,result):new DateTime(this.zoneDate,void 0)},DateTime.prototype.toDate=function(){return new Date(this.year(),this.month()-1,this.day(),this.hour(),this.minute(),this.second(),this.millisecond())},DateTime.prototype.toExcel=function(timeZone){var dt=this,timeZone=60*(dt=!timeZone||this._zone&&timeZone.equals(this._zone)?dt:this.toZone(timeZone)).offset()*1e3,dt=dt.unixUtcMillis();return this._unixTimeStampToExcel(dt+timeZone)},DateTime.prototype.toUtcExcel=function(){var unixTimestamp=this.unixUtcMillis();return this._unixTimeStampToExcel(unixTimestamp)},DateTime.prototype._unixTimeStampToExcel=function(n){return Math.round((n/864e5+25569)/(1/864e5))*(1/864e5)},DateTime.prototype.add=function(a1,unit){var amount,duration;return duration="object"==typeof a1?(amount=(duration=a1).amount(),duration.unit()):(amount=a1,unit),new DateTime(this._addToTimeStruct(this.utcDate,amount,duration),timezone_1.TimeZone.utc()).toZone(this._zone)},DateTime.prototype.addLocal=function(a1,unit){duration="object"==typeof a1?(amount=(duration=a1).amount(),duration.unit()):(amount=a1,unit);var amount,duration,a1=this._addToTimeStruct(this.zoneDate,amount,duration);return this._zone?(unit=0<=amount?tz_database_1.NormalizeOption.Up:tz_database_1.NormalizeOption.Down,new DateTime(this._zone.normalizeZoneTime(a1,unit),this._zone)):new DateTime(a1,void 0)},DateTime.prototype._addToTimeStruct=function(tm,amount,unit){var year,month,day,hour,minute,second,milli;switch((0,assert_1.default)(Number.isFinite(amount),"Argument.Amount","amount must be a finite number"),unit){case basics_1.TimeUnit.Millisecond:return new basics_1.TimeStruct(math.roundSym(tm.unixMillis+amount));case basics_1.TimeUnit.Second:return new basics_1.TimeStruct(math.roundSym(tm.unixMillis+1e3*amount));case basics_1.TimeUnit.Minute:return new basics_1.TimeStruct(math.roundSym(tm.unixMillis+6e4*amount));case basics_1.TimeUnit.Hour:return new basics_1.TimeStruct(math.roundSym(tm.unixMillis+36e5*amount));case basics_1.TimeUnit.Day:return new basics_1.TimeStruct(math.roundSym(tm.unixMillis+864e5*amount));case basics_1.TimeUnit.Week:return new basics_1.TimeStruct(math.roundSym(tm.unixMillis+7*amount*864e5));case basics_1.TimeUnit.Month:return(0,assert_1.default)(math.isInt(amount),"Argument.Amount","Cannot add/sub a non-integer amount of months"),month=0<=amount?(year=tm.components.year+Math.ceil((amount-(12-tm.components.month))/12),1+math.positiveModulo(tm.components.month-1+Math.floor(amount),12)):(year=tm.components.year+Math.floor((amount+(tm.components.month-1))/12),1+math.positiveModulo(tm.components.month-1+Math.ceil(amount),12)),day=Math.min(tm.components.day,basics.daysInMonth(year,month)),hour=tm.components.hour,minute=tm.components.minute,second=tm.components.second,milli=tm.components.milli,new basics_1.TimeStruct({year:year,month:month,day:day,hour:hour,minute:minute,second:second,milli:milli});case basics_1.TimeUnit.Year:return(0,assert_1.default)(math.isInt(amount),"Argument.Amount","Cannot add/sub a non-integer amount of years"),year=tm.components.year+amount,month=tm.components.month,day=Math.min(tm.components.day,basics.daysInMonth(year,month)),hour=tm.components.hour,minute=tm.components.minute,second=tm.components.second,milli=tm.components.milli,new basics_1.TimeStruct({year:year,month:month,day:day,hour:hour,minute:minute,second:second,milli:milli});default:return(0,error_1.throwError)("Argument.Unit","invalid time unit")}},DateTime.prototype.sub=function(a1,unit){return"number"==typeof a1?this.add(-1*a1,unit):this.add(a1.multiply(-1))},DateTime.prototype.subLocal=function(a1,unit){return"number"==typeof a1?this.addLocal(-1*a1,unit):this.addLocal(a1.multiply(-1))},DateTime.prototype.diff=function(other){return new duration_1.Duration(this.utcDate.unixMillis-other.utcDate.unixMillis)},DateTime.prototype.startOfDay=function(){return new DateTime(this.year(),this.month(),this.day(),0,0,0,0,this.zone())},DateTime.prototype.startOfMonth=function(){return new DateTime(this.year(),this.month(),1,0,0,0,0,this.zone())},DateTime.prototype.startOfYear=function(){return new DateTime(this.year(),1,1,0,0,0,0,this.zone())},DateTime.prototype.lessThan=function(other){return this.utcDate.unixMillis<other.utcDate.unixMillis},DateTime.prototype.lessEqual=function(other){return this.utcDate.unixMillis<=other.utcDate.unixMillis},DateTime.prototype.equals=function(other){return this.utcDate.equals(other.utcDate)},DateTime.prototype.identical=function(other){return!(!this.zoneDate.equals(other.zoneDate)||!this._zone!=!other._zone||!(!this._zone&&!other._zone||this._zone&&other._zone&&this._zone.identical(other._zone)))},DateTime.prototype.greaterThan=function(other){return this.utcDate.unixMillis>other.utcDate.unixMillis},DateTime.prototype.greaterEqual=function(other){return this.utcDate.unixMillis>=other.utcDate.unixMillis},DateTime.prototype.min=function(other){return(this.lessThan(other)?this:other).clone()},DateTime.prototype.max=function(other){return(this.greaterThan(other)?this:other).clone()},DateTime.prototype.toIsoString=function(){var s=this.zoneDate.toString();return this._zone?s+timezone_1.TimeZone.offsetToString(this.offset()):s},DateTime.prototype.toUtcIsoString=function(){return(this._zone?this.toZone(timezone_1.TimeZone.utc()):this.withZone(timezone_1.TimeZone.utc())).format("yyyy-MM-ddTHH:mm:ss.SSSZZZZZ")},DateTime.prototype.format=function(formatString,locale){return format.format(this.zoneDate,this.utcDate,this._zone,formatString,locale)},DateTime.parse=function(s,format,zone,locale,allowTrailing){s=parseFuncs.parse(s,format,zone,allowTrailing||!1,locale);try{return new DateTime(s.time,s.zone)}catch(e){throw e=(0,error_1.errorIs)(e,"InvalidTimeZoneData")?e:(0,error_1.error)("ParseError",e.message)}},DateTime.prototype.toString=function(){var s=this.zoneDate.toString();return this._zone?this._zone.kind()!==timezone_1.TimeZoneKind.Offset?s+" "+this._zone.toString():s+this._zone.toString():s},DateTime.prototype.valueOf=function(){return this.unixUtcMillis()},DateTime.prototype.toUtcString=function(){return this.utcDate.toString()},DateTime._splitDateFromTimeZone=function(s){var trimmed=s.trim(),result=["",""],index=trimmed.lastIndexOf("without DST");return-1<index?((s=DateTime._splitDateFromTimeZone(s.slice(0,index-1)))[1]+=" without DST",s):(-1<(index=trimmed.lastIndexOf(" "))?(result[0]=trimmed.substr(0,index),result[1]=trimmed.substr(index+1)):-1<(index=trimmed.lastIndexOf("Z"))?(result[0]=trimmed.substr(0,index),result[1]=trimmed.substr(index,1)):-1<(index=trimmed.lastIndexOf("+"))||-1<(index=(index=trimmed.lastIndexOf("-"))<8?-1:index)?(result[0]=trimmed.substr(0,index),result[1]=trimmed.substr(index)):result[0]=trimmed,result)},DateTime.timeSource=new timesource_1.RealTimeSource,DateTime})();function isTimeZone(a){return!(!a||"object"!=typeof a||"function"!=typeof a.normalizeZoneTime||"function"!=typeof a.abbreviationForUtc||"function"!=typeof a.standardOffsetForUtc||"function"!=typeof a.identical||"function"!=typeof a.equals||"function"!=typeof a.kind||"function"!=typeof a.clone)}exports.DateTime=DateTime,exports.isDateTime=function(value){return"object"==typeof value&&null!==value&&"DateTime"===value.kind}},{"./assert":1,"./basics":2,"./duration":4,"./error":5,"./format":6,"./javascript":8,"./math":10,"./parse":11,"./timesource":14,"./timezone":15,"./tz-database":17}],4:[function(require,module,exports){Object.defineProperty(exports,"__esModule",{value:!0}),exports.isDuration=exports.Duration=exports.milliseconds=exports.seconds=exports.minutes=exports.hours=exports.days=exports.months=exports.years=void 0;var assert_1=require("./assert"),basics_1=require("./basics"),basics=require("./basics"),strings=require("./strings");exports.years=function(n){return Duration.years(n)},exports.months=function(n){return Duration.months(n)},exports.days=function(n){return Duration.days(n)},exports.hours=function(n){return Duration.hours(n)},exports.minutes=function(n){return Duration.minutes(n)},exports.seconds=function(n){return Duration.seconds(n)},exports.milliseconds=function(n){return Duration.milliseconds(n)};var Duration=(()=>{function Duration(i1,unit){var s,trimmed,hours_1,minutes_1,milliseconds_1,seconds_1,parts,sign,amount;this.kind="Duration","number"==typeof i1?(amount=i1,(0,assert_1.default)(Number.isFinite(amount),"Argument.Amount","amount should be finite: %d",amount),this._amount=amount,this._unit="number"==typeof unit?unit:basics_1.TimeUnit.Millisecond,(0,assert_1.default)(Number.isInteger(this._unit)&&0<=this._unit&&this._unit<basics_1.TimeUnit.MAX,"Argument.Unit","Invalid time unit %d",this._unit)):"string"==typeof i1?(trimmed=(s=i1).trim()).match(/^-?\d\d?(:\d\d?(:\d\d?(.\d\d?\d?)?)?)?$/)?(sign=1,milliseconds_1=seconds_1=minutes_1=hours_1=0,parts=trimmed.split(":"),(0,assert_1.default)(0<parts.length&&parts.length<4,"Argument.S",'Not a proper time duration string: "'+trimmed+'"'),"-"===trimmed.charAt(0)&&(sign=-1,parts[0]=parts[0].substr(1)),0<parts.length&&(hours_1=+parts[0]),1<parts.length&&(minutes_1=+parts[1]),2<parts.length&&(seconds_1=+(parts=parts[2].split("."))[0],1<parts.length)&&(milliseconds_1=+strings.padRight(parts[1],3,"0")),parts=sign*Math.round(milliseconds_1+1e3*seconds_1+6e4*minutes_1+36e5*hours_1),this._unit=0!==milliseconds_1?basics_1.TimeUnit.Millisecond:0!==seconds_1?basics_1.TimeUnit.Second:0!==minutes_1?basics_1.TimeUnit.Minute:0!==hours_1?basics_1.TimeUnit.Hour:basics_1.TimeUnit.Millisecond,this._amount=parts/basics.timeUnitToMilliseconds(this._unit)):(sign=trimmed.toLowerCase().split(" "),(0,assert_1.default)(2===sign.length,"Argument.S","Invalid time string '%s'",s),amount=parseFloat(sign[0]),(0,assert_1.default)(Number.isFinite(amount),"Argument.S","Invalid time string '%s', cannot parse amount",s),this._amount=amount,this._unit=basics.stringToTimeUnit(sign[1])):void 0===i1&&void 0===unit?(this._amount=0,this._unit=basics_1.TimeUnit.Millisecond):(0,assert_1.default)(!1,"Argument.Amount","invalid constructor arguments")}return Duration.years=function(amount){return new Duration(amount,basics_1.TimeUnit.Year)},Duration.months=function(amount){return new Duration(amount,basics_1.TimeUnit.Month)},Duration.days=function(amount){return new Duration(amount,basics_1.TimeUnit.Day)},Duration.hours=function(amount){return new Duration(amount,basics_1.TimeUnit.Hour)},Duration.minutes=function(amount){return new Duration(amount,basics_1.TimeUnit.Minute)},Duration.seconds=function(amount){return new Duration(amount,basics_1.TimeUnit.Second)},Duration.milliseconds=function(amount){return new Duration(amount,basics_1.TimeUnit.Millisecond)},Duration.prototype.clone=function(){return new Duration(this._amount,this._unit)},Duration.prototype.as=function(unit){var thisMonths,reqMonths;return this._unit===unit?this._amount:this._unit>=basics_1.TimeUnit.Month&&unit>=basics_1.TimeUnit.Month?(thisMonths=this._unit===basics_1.TimeUnit.Year?12:1,reqMonths=unit===basics_1.TimeUnit.Year?12:1,this._amount*thisMonths/reqMonths):(thisMonths=basics.timeUnitToMilliseconds(this._unit),reqMonths=basics.timeUnitToMilliseconds(unit),this._amount*thisMonths/reqMonths)},Duration.prototype.convert=function(unit){return new Duration(this.as(unit),unit)},Duration.prototype.milliseconds=function(){return this.as(basics_1.TimeUnit.Millisecond)},Duration.prototype.millisecond=function(){return this._part(basics_1.TimeUnit.Millisecond)},Duration.prototype.seconds=function(){return this.as(basics_1.TimeUnit.Second)},Duration.prototype.second=function(){return this._part(basics_1.TimeUnit.Second)},Duration.prototype.minutes=function(){return this.as(basics_1.TimeUnit.Minute)},Duration.prototype.minute=function(){return this._part(basics_1.TimeUnit.Minute)},Duration.prototype.hours=function(){return this.as(basics_1.TimeUnit.Hour)},Duration.prototype.hour=function(){return this._part(basics_1.TimeUnit.Hour)},Duration.prototype.wholeHours=function(){return Math.floor(basics.timeUnitToMilliseconds(this._unit)*Math.abs(this._amount)/36e5)},Duration.prototype.days=function(){return this.as(basics_1.TimeUnit.Day)},Duration.prototype.day=function(){return this._part(basics_1.TimeUnit.Day)},Duration.prototype.months=function(){return this.as(basics_1.TimeUnit.Month)},Duration.prototype.month=function(){return this._part(basics_1.TimeUnit.Month)},Duration.prototype.years=function(){return this.as(basics_1.TimeUnit.Year)},Duration.prototype.wholeYears=function(){return this._unit===basics_1.TimeUnit.Year?Math.floor(Math.abs(this._amount)):this._unit===basics_1.TimeUnit.Month?Math.floor(Math.abs(this._amount)/12):Math.floor(basics.timeUnitToMilliseconds(this._unit)*Math.abs(this._amount)/basics.timeUnitToMilliseconds(basics_1.TimeUnit.Year))},Duration.prototype.amount=function(){return this._amount},Duration.prototype.unit=function(){return this._unit},Duration.prototype.sign=function(){return this._amount<0?"-":""},Duration.prototype.lessThan=function(other){return this.milliseconds()<other.milliseconds()},Duration.prototype.lessEqual=function(other){return this.milliseconds()<=other.milliseconds()},Duration.prototype.equals=function(other){other=other.convert(this._unit);return this._amount===other.amount()&&this._unit===other.unit()},Duration.prototype.equalsExact=function(other){return this._unit===other._unit?this._amount===other._amount:(this._unit>=basics_1.TimeUnit.Month&&other.unit()>=basics_1.TimeUnit.Month||this._unit<basics_1.TimeUnit.Day&&other.unit()<basics_1.TimeUnit.Day)&&this.equals(other)},Duration.prototype.identical=function(other){return this._amount===other.amount()&&this._unit===other.unit()},Duration.prototype.nonZero=function(){return 0!==this._amount},Duration.prototype.zero=function(){return 0===this._amount},Duration.prototype.greaterThan=function(other){return this.milliseconds()>other.milliseconds()},Duration.prototype.greaterEqual=function(other){return this.milliseconds()>=other.milliseconds()},Duration.prototype.min=function(other){return(this.lessThan(other)?this:other).clone()},Duration.prototype.max=function(other){return(this.greaterThan(other)?this:other).clone()},Duration.prototype.multiply=function(value){return new Duration(this._amount*value,this._unit)},Duration.prototype.divide=function(value){return"number"==typeof value?((0,assert_1.default)(Number.isFinite(value)&&0!==value,"Argument.Value","cannot divide by %d",value),new Duration(this._amount/value,this._unit)):((0,assert_1.default)(0!==value.amount(),"Argument.Value","cannot divide by 0"),this.milliseconds()/value.milliseconds())},Duration.prototype.add=function(value){return new Duration(this._amount+value.as(this._unit),this._unit)},Duration.prototype.sub=function(value){return new Duration(this._amount-value.as(this._unit),this._unit)},Duration.prototype.abs=function(){return 0<=this._amount?this.clone():this.multiply(-1)},Duration.prototype.toFullString=function(){return this.toHmsString(!0)},Duration.prototype.toHmsString=function(full){var result="";return((full=void 0===full?!1:full)||0<this.millisecond())&&(result="."+strings.padLeft(this.millisecond().toString(10),3,"0")),(full||0<result.length||0<this.second())&&(result=":"+strings.padLeft(this.second().toString(10),2,"0")+result),(full||0<result.length||0<this.minute())&&(result=":"+strings.padLeft(this.minute().toString(10),2,"0")+result),this.sign()+strings.padLeft(this.wholeHours().toString(10),2,"0")+result},Duration.prototype.toIsoString=function(){switch(this._unit){case basics_1.TimeUnit.Millisecond:return"P"+(this._amount/1e3).toFixed(3)+"S";case basics_1.TimeUnit.Second:return"P"+this._amount.toString(10)+"S";case basics_1.TimeUnit.Minute:return"PT"+this._amount.toString(10)+"M";case basics_1.TimeUnit.Hour:return"P"+this._amount.toString(10)+"H";case basics_1.TimeUnit.Day:return"P"+this._amount.toString(10)+"D";case basics_1.TimeUnit.Week:return"P"+this._amount.toString(10)+"W";case basics_1.TimeUnit.Month:return"P"+this._amount.toString(10)+"M";case basics_1.TimeUnit.Year:return"P"+this._amount.toString(10)+"Y";default:throw new Error("Unknown time unit.")}},Duration.prototype.toString=function(){return this._amount.toString(10)+" "+basics.timeUnitToString(this._unit,this._amount)},Duration.prototype.valueOf=function(){return thi