Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

luxon.js 287KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. function _defineProperties(target, props) {
  4. for (var i = 0; i < props.length; i++) {
  5. var descriptor = props[i];
  6. descriptor.enumerable = descriptor.enumerable || false;
  7. descriptor.configurable = true;
  8. if ("value" in descriptor) descriptor.writable = true;
  9. Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
  10. }
  11. }
  12. function _createClass(Constructor, protoProps, staticProps) {
  13. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  14. if (staticProps) _defineProperties(Constructor, staticProps);
  15. Object.defineProperty(Constructor, "prototype", {
  16. writable: false
  17. });
  18. return Constructor;
  19. }
  20. function _extends() {
  21. _extends = Object.assign ? Object.assign.bind() : function (target) {
  22. for (var i = 1; i < arguments.length; i++) {
  23. var source = arguments[i];
  24. for (var key in source) {
  25. if (Object.prototype.hasOwnProperty.call(source, key)) {
  26. target[key] = source[key];
  27. }
  28. }
  29. }
  30. return target;
  31. };
  32. return _extends.apply(this, arguments);
  33. }
  34. function _inheritsLoose(subClass, superClass) {
  35. subClass.prototype = Object.create(superClass.prototype);
  36. subClass.prototype.constructor = subClass;
  37. _setPrototypeOf(subClass, superClass);
  38. }
  39. function _getPrototypeOf(o) {
  40. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
  41. return o.__proto__ || Object.getPrototypeOf(o);
  42. };
  43. return _getPrototypeOf(o);
  44. }
  45. function _setPrototypeOf(o, p) {
  46. _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
  47. o.__proto__ = p;
  48. return o;
  49. };
  50. return _setPrototypeOf(o, p);
  51. }
  52. function _isNativeReflectConstruct() {
  53. if (typeof Reflect === "undefined" || !Reflect.construct) return false;
  54. if (Reflect.construct.sham) return false;
  55. if (typeof Proxy === "function") return true;
  56. try {
  57. Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
  58. return true;
  59. } catch (e) {
  60. return false;
  61. }
  62. }
  63. function _construct(Parent, args, Class) {
  64. if (_isNativeReflectConstruct()) {
  65. _construct = Reflect.construct.bind();
  66. } else {
  67. _construct = function _construct(Parent, args, Class) {
  68. var a = [null];
  69. a.push.apply(a, args);
  70. var Constructor = Function.bind.apply(Parent, a);
  71. var instance = new Constructor();
  72. if (Class) _setPrototypeOf(instance, Class.prototype);
  73. return instance;
  74. };
  75. }
  76. return _construct.apply(null, arguments);
  77. }
  78. function _isNativeFunction(fn) {
  79. return Function.toString.call(fn).indexOf("[native code]") !== -1;
  80. }
  81. function _wrapNativeSuper(Class) {
  82. var _cache = typeof Map === "function" ? new Map() : undefined;
  83. _wrapNativeSuper = function _wrapNativeSuper(Class) {
  84. if (Class === null || !_isNativeFunction(Class)) return Class;
  85. if (typeof Class !== "function") {
  86. throw new TypeError("Super expression must either be null or a function");
  87. }
  88. if (typeof _cache !== "undefined") {
  89. if (_cache.has(Class)) return _cache.get(Class);
  90. _cache.set(Class, Wrapper);
  91. }
  92. function Wrapper() {
  93. return _construct(Class, arguments, _getPrototypeOf(this).constructor);
  94. }
  95. Wrapper.prototype = Object.create(Class.prototype, {
  96. constructor: {
  97. value: Wrapper,
  98. enumerable: false,
  99. writable: true,
  100. configurable: true
  101. }
  102. });
  103. return _setPrototypeOf(Wrapper, Class);
  104. };
  105. return _wrapNativeSuper(Class);
  106. }
  107. function _objectWithoutPropertiesLoose(source, excluded) {
  108. if (source == null) return {};
  109. var target = {};
  110. var sourceKeys = Object.keys(source);
  111. var key, i;
  112. for (i = 0; i < sourceKeys.length; i++) {
  113. key = sourceKeys[i];
  114. if (excluded.indexOf(key) >= 0) continue;
  115. target[key] = source[key];
  116. }
  117. return target;
  118. }
  119. function _unsupportedIterableToArray(o, minLen) {
  120. if (!o) return;
  121. if (typeof o === "string") return _arrayLikeToArray(o, minLen);
  122. var n = Object.prototype.toString.call(o).slice(8, -1);
  123. if (n === "Object" && o.constructor) n = o.constructor.name;
  124. if (n === "Map" || n === "Set") return Array.from(o);
  125. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
  126. }
  127. function _arrayLikeToArray(arr, len) {
  128. if (len == null || len > arr.length) len = arr.length;
  129. for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
  130. return arr2;
  131. }
  132. function _createForOfIteratorHelperLoose(o, allowArrayLike) {
  133. var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
  134. if (it) return (it = it.call(o)).next.bind(it);
  135. if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
  136. if (it) o = it;
  137. var i = 0;
  138. return function () {
  139. if (i >= o.length) return {
  140. done: true
  141. };
  142. return {
  143. done: false,
  144. value: o[i++]
  145. };
  146. };
  147. }
  148. throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  149. }
  150. function _toPrimitive(input, hint) {
  151. if (typeof input !== "object" || input === null) return input;
  152. var prim = input[Symbol.toPrimitive];
  153. if (prim !== undefined) {
  154. var res = prim.call(input, hint || "default");
  155. if (typeof res !== "object") return res;
  156. throw new TypeError("@@toPrimitive must return a primitive value.");
  157. }
  158. return (hint === "string" ? String : Number)(input);
  159. }
  160. function _toPropertyKey(arg) {
  161. var key = _toPrimitive(arg, "string");
  162. return typeof key === "symbol" ? key : String(key);
  163. }
  164. // these aren't really private, but nor are they really useful to document
  165. /**
  166. * @private
  167. */
  168. var LuxonError = /*#__PURE__*/function (_Error) {
  169. _inheritsLoose(LuxonError, _Error);
  170. function LuxonError() {
  171. return _Error.apply(this, arguments) || this;
  172. }
  173. return LuxonError;
  174. }( /*#__PURE__*/_wrapNativeSuper(Error));
  175. /**
  176. * @private
  177. */
  178. var InvalidDateTimeError = /*#__PURE__*/function (_LuxonError) {
  179. _inheritsLoose(InvalidDateTimeError, _LuxonError);
  180. function InvalidDateTimeError(reason) {
  181. return _LuxonError.call(this, "Invalid DateTime: " + reason.toMessage()) || this;
  182. }
  183. return InvalidDateTimeError;
  184. }(LuxonError);
  185. /**
  186. * @private
  187. */
  188. var InvalidIntervalError = /*#__PURE__*/function (_LuxonError2) {
  189. _inheritsLoose(InvalidIntervalError, _LuxonError2);
  190. function InvalidIntervalError(reason) {
  191. return _LuxonError2.call(this, "Invalid Interval: " + reason.toMessage()) || this;
  192. }
  193. return InvalidIntervalError;
  194. }(LuxonError);
  195. /**
  196. * @private
  197. */
  198. var InvalidDurationError = /*#__PURE__*/function (_LuxonError3) {
  199. _inheritsLoose(InvalidDurationError, _LuxonError3);
  200. function InvalidDurationError(reason) {
  201. return _LuxonError3.call(this, "Invalid Duration: " + reason.toMessage()) || this;
  202. }
  203. return InvalidDurationError;
  204. }(LuxonError);
  205. /**
  206. * @private
  207. */
  208. var ConflictingSpecificationError = /*#__PURE__*/function (_LuxonError4) {
  209. _inheritsLoose(ConflictingSpecificationError, _LuxonError4);
  210. function ConflictingSpecificationError() {
  211. return _LuxonError4.apply(this, arguments) || this;
  212. }
  213. return ConflictingSpecificationError;
  214. }(LuxonError);
  215. /**
  216. * @private
  217. */
  218. var InvalidUnitError = /*#__PURE__*/function (_LuxonError5) {
  219. _inheritsLoose(InvalidUnitError, _LuxonError5);
  220. function InvalidUnitError(unit) {
  221. return _LuxonError5.call(this, "Invalid unit " + unit) || this;
  222. }
  223. return InvalidUnitError;
  224. }(LuxonError);
  225. /**
  226. * @private
  227. */
  228. var InvalidArgumentError = /*#__PURE__*/function (_LuxonError6) {
  229. _inheritsLoose(InvalidArgumentError, _LuxonError6);
  230. function InvalidArgumentError() {
  231. return _LuxonError6.apply(this, arguments) || this;
  232. }
  233. return InvalidArgumentError;
  234. }(LuxonError);
  235. /**
  236. * @private
  237. */
  238. var ZoneIsAbstractError = /*#__PURE__*/function (_LuxonError7) {
  239. _inheritsLoose(ZoneIsAbstractError, _LuxonError7);
  240. function ZoneIsAbstractError() {
  241. return _LuxonError7.call(this, "Zone is an abstract class") || this;
  242. }
  243. return ZoneIsAbstractError;
  244. }(LuxonError);
  245. /**
  246. * @private
  247. */
  248. var n = "numeric",
  249. s = "short",
  250. l = "long";
  251. var DATE_SHORT = {
  252. year: n,
  253. month: n,
  254. day: n
  255. };
  256. var DATE_MED = {
  257. year: n,
  258. month: s,
  259. day: n
  260. };
  261. var DATE_MED_WITH_WEEKDAY = {
  262. year: n,
  263. month: s,
  264. day: n,
  265. weekday: s
  266. };
  267. var DATE_FULL = {
  268. year: n,
  269. month: l,
  270. day: n
  271. };
  272. var DATE_HUGE = {
  273. year: n,
  274. month: l,
  275. day: n,
  276. weekday: l
  277. };
  278. var TIME_SIMPLE = {
  279. hour: n,
  280. minute: n
  281. };
  282. var TIME_WITH_SECONDS = {
  283. hour: n,
  284. minute: n,
  285. second: n
  286. };
  287. var TIME_WITH_SHORT_OFFSET = {
  288. hour: n,
  289. minute: n,
  290. second: n,
  291. timeZoneName: s
  292. };
  293. var TIME_WITH_LONG_OFFSET = {
  294. hour: n,
  295. minute: n,
  296. second: n,
  297. timeZoneName: l
  298. };
  299. var TIME_24_SIMPLE = {
  300. hour: n,
  301. minute: n,
  302. hourCycle: "h23"
  303. };
  304. var TIME_24_WITH_SECONDS = {
  305. hour: n,
  306. minute: n,
  307. second: n,
  308. hourCycle: "h23"
  309. };
  310. var TIME_24_WITH_SHORT_OFFSET = {
  311. hour: n,
  312. minute: n,
  313. second: n,
  314. hourCycle: "h23",
  315. timeZoneName: s
  316. };
  317. var TIME_24_WITH_LONG_OFFSET = {
  318. hour: n,
  319. minute: n,
  320. second: n,
  321. hourCycle: "h23",
  322. timeZoneName: l
  323. };
  324. var DATETIME_SHORT = {
  325. year: n,
  326. month: n,
  327. day: n,
  328. hour: n,
  329. minute: n
  330. };
  331. var DATETIME_SHORT_WITH_SECONDS = {
  332. year: n,
  333. month: n,
  334. day: n,
  335. hour: n,
  336. minute: n,
  337. second: n
  338. };
  339. var DATETIME_MED = {
  340. year: n,
  341. month: s,
  342. day: n,
  343. hour: n,
  344. minute: n
  345. };
  346. var DATETIME_MED_WITH_SECONDS = {
  347. year: n,
  348. month: s,
  349. day: n,
  350. hour: n,
  351. minute: n,
  352. second: n
  353. };
  354. var DATETIME_MED_WITH_WEEKDAY = {
  355. year: n,
  356. month: s,
  357. day: n,
  358. weekday: s,
  359. hour: n,
  360. minute: n
  361. };
  362. var DATETIME_FULL = {
  363. year: n,
  364. month: l,
  365. day: n,
  366. hour: n,
  367. minute: n,
  368. timeZoneName: s
  369. };
  370. var DATETIME_FULL_WITH_SECONDS = {
  371. year: n,
  372. month: l,
  373. day: n,
  374. hour: n,
  375. minute: n,
  376. second: n,
  377. timeZoneName: s
  378. };
  379. var DATETIME_HUGE = {
  380. year: n,
  381. month: l,
  382. day: n,
  383. weekday: l,
  384. hour: n,
  385. minute: n,
  386. timeZoneName: l
  387. };
  388. var DATETIME_HUGE_WITH_SECONDS = {
  389. year: n,
  390. month: l,
  391. day: n,
  392. weekday: l,
  393. hour: n,
  394. minute: n,
  395. second: n,
  396. timeZoneName: l
  397. };
  398. /**
  399. * @interface
  400. */
  401. var Zone = /*#__PURE__*/function () {
  402. function Zone() {}
  403. var _proto = Zone.prototype;
  404. /**
  405. * Returns the offset's common name (such as EST) at the specified timestamp
  406. * @abstract
  407. * @param {number} ts - Epoch milliseconds for which to get the name
  408. * @param {Object} opts - Options to affect the format
  409. * @param {string} opts.format - What style of offset to return. Accepts 'long' or 'short'.
  410. * @param {string} opts.locale - What locale to return the offset name in.
  411. * @return {string}
  412. */
  413. _proto.offsetName = function offsetName(ts, opts) {
  414. throw new ZoneIsAbstractError();
  415. }
  416. /**
  417. * Returns the offset's value as a string
  418. * @abstract
  419. * @param {number} ts - Epoch milliseconds for which to get the offset
  420. * @param {string} format - What style of offset to return.
  421. * Accepts 'narrow', 'short', or 'techie'. Returning '+6', '+06:00', or '+0600' respectively
  422. * @return {string}
  423. */;
  424. _proto.formatOffset = function formatOffset(ts, format) {
  425. throw new ZoneIsAbstractError();
  426. }
  427. /**
  428. * Return the offset in minutes for this zone at the specified timestamp.
  429. * @abstract
  430. * @param {number} ts - Epoch milliseconds for which to compute the offset
  431. * @return {number}
  432. */;
  433. _proto.offset = function offset(ts) {
  434. throw new ZoneIsAbstractError();
  435. }
  436. /**
  437. * Return whether this Zone is equal to another zone
  438. * @abstract
  439. * @param {Zone} otherZone - the zone to compare
  440. * @return {boolean}
  441. */;
  442. _proto.equals = function equals(otherZone) {
  443. throw new ZoneIsAbstractError();
  444. }
  445. /**
  446. * Return whether this Zone is valid.
  447. * @abstract
  448. * @type {boolean}
  449. */;
  450. _createClass(Zone, [{
  451. key: "type",
  452. get:
  453. /**
  454. * The type of zone
  455. * @abstract
  456. * @type {string}
  457. */
  458. function get() {
  459. throw new ZoneIsAbstractError();
  460. }
  461. /**
  462. * The name of this zone.
  463. * @abstract
  464. * @type {string}
  465. */
  466. }, {
  467. key: "name",
  468. get: function get() {
  469. throw new ZoneIsAbstractError();
  470. }
  471. /**
  472. * The IANA name of this zone.
  473. * Defaults to `name` if not overwritten by a subclass.
  474. * @abstract
  475. * @type {string}
  476. */
  477. }, {
  478. key: "ianaName",
  479. get: function get() {
  480. return this.name;
  481. }
  482. /**
  483. * Returns whether the offset is known to be fixed for the whole year.
  484. * @abstract
  485. * @type {boolean}
  486. */
  487. }, {
  488. key: "isUniversal",
  489. get: function get() {
  490. throw new ZoneIsAbstractError();
  491. }
  492. }, {
  493. key: "isValid",
  494. get: function get() {
  495. throw new ZoneIsAbstractError();
  496. }
  497. }]);
  498. return Zone;
  499. }();
  500. var singleton$1 = null;
  501. /**
  502. * Represents the local zone for this JavaScript environment.
  503. * @implements {Zone}
  504. */
  505. var SystemZone = /*#__PURE__*/function (_Zone) {
  506. _inheritsLoose(SystemZone, _Zone);
  507. function SystemZone() {
  508. return _Zone.apply(this, arguments) || this;
  509. }
  510. var _proto = SystemZone.prototype;
  511. /** @override **/
  512. _proto.offsetName = function offsetName(ts, _ref) {
  513. var format = _ref.format,
  514. locale = _ref.locale;
  515. return parseZoneInfo(ts, format, locale);
  516. }
  517. /** @override **/;
  518. _proto.formatOffset = function formatOffset$1(ts, format) {
  519. return formatOffset(this.offset(ts), format);
  520. }
  521. /** @override **/;
  522. _proto.offset = function offset(ts) {
  523. return -new Date(ts).getTimezoneOffset();
  524. }
  525. /** @override **/;
  526. _proto.equals = function equals(otherZone) {
  527. return otherZone.type === "system";
  528. }
  529. /** @override **/;
  530. _createClass(SystemZone, [{
  531. key: "type",
  532. get: /** @override **/
  533. function get() {
  534. return "system";
  535. }
  536. /** @override **/
  537. }, {
  538. key: "name",
  539. get: function get() {
  540. return new Intl.DateTimeFormat().resolvedOptions().timeZone;
  541. }
  542. /** @override **/
  543. }, {
  544. key: "isUniversal",
  545. get: function get() {
  546. return false;
  547. }
  548. }, {
  549. key: "isValid",
  550. get: function get() {
  551. return true;
  552. }
  553. }], [{
  554. key: "instance",
  555. get:
  556. /**
  557. * Get a singleton instance of the local zone
  558. * @return {SystemZone}
  559. */
  560. function get() {
  561. if (singleton$1 === null) {
  562. singleton$1 = new SystemZone();
  563. }
  564. return singleton$1;
  565. }
  566. }]);
  567. return SystemZone;
  568. }(Zone);
  569. var dtfCache = {};
  570. function makeDTF(zone) {
  571. if (!dtfCache[zone]) {
  572. dtfCache[zone] = new Intl.DateTimeFormat("en-US", {
  573. hour12: false,
  574. timeZone: zone,
  575. year: "numeric",
  576. month: "2-digit",
  577. day: "2-digit",
  578. hour: "2-digit",
  579. minute: "2-digit",
  580. second: "2-digit",
  581. era: "short"
  582. });
  583. }
  584. return dtfCache[zone];
  585. }
  586. var typeToPos = {
  587. year: 0,
  588. month: 1,
  589. day: 2,
  590. era: 3,
  591. hour: 4,
  592. minute: 5,
  593. second: 6
  594. };
  595. function hackyOffset(dtf, date) {
  596. var formatted = dtf.format(date).replace(/\u200E/g, ""),
  597. parsed = /(\d+)\/(\d+)\/(\d+) (AD|BC),? (\d+):(\d+):(\d+)/.exec(formatted),
  598. fMonth = parsed[1],
  599. fDay = parsed[2],
  600. fYear = parsed[3],
  601. fadOrBc = parsed[4],
  602. fHour = parsed[5],
  603. fMinute = parsed[6],
  604. fSecond = parsed[7];
  605. return [fYear, fMonth, fDay, fadOrBc, fHour, fMinute, fSecond];
  606. }
  607. function partsOffset(dtf, date) {
  608. var formatted = dtf.formatToParts(date);
  609. var filled = [];
  610. for (var i = 0; i < formatted.length; i++) {
  611. var _formatted$i = formatted[i],
  612. type = _formatted$i.type,
  613. value = _formatted$i.value;
  614. var pos = typeToPos[type];
  615. if (type === "era") {
  616. filled[pos] = value;
  617. } else if (!isUndefined(pos)) {
  618. filled[pos] = parseInt(value, 10);
  619. }
  620. }
  621. return filled;
  622. }
  623. var ianaZoneCache = {};
  624. /**
  625. * A zone identified by an IANA identifier, like America/New_York
  626. * @implements {Zone}
  627. */
  628. var IANAZone = /*#__PURE__*/function (_Zone) {
  629. _inheritsLoose(IANAZone, _Zone);
  630. /**
  631. * @param {string} name - Zone name
  632. * @return {IANAZone}
  633. */
  634. IANAZone.create = function create(name) {
  635. if (!ianaZoneCache[name]) {
  636. ianaZoneCache[name] = new IANAZone(name);
  637. }
  638. return ianaZoneCache[name];
  639. }
  640. /**
  641. * Reset local caches. Should only be necessary in testing scenarios.
  642. * @return {void}
  643. */;
  644. IANAZone.resetCache = function resetCache() {
  645. ianaZoneCache = {};
  646. dtfCache = {};
  647. }
  648. /**
  649. * Returns whether the provided string is a valid specifier. This only checks the string's format, not that the specifier identifies a known zone; see isValidZone for that.
  650. * @param {string} s - The string to check validity on
  651. * @example IANAZone.isValidSpecifier("America/New_York") //=> true
  652. * @example IANAZone.isValidSpecifier("Sport~~blorp") //=> false
  653. * @deprecated For backward compatibility, this forwards to isValidZone, better use `isValidZone()` directly instead.
  654. * @return {boolean}
  655. */;
  656. IANAZone.isValidSpecifier = function isValidSpecifier(s) {
  657. return this.isValidZone(s);
  658. }
  659. /**
  660. * Returns whether the provided string identifies a real zone
  661. * @param {string} zone - The string to check
  662. * @example IANAZone.isValidZone("America/New_York") //=> true
  663. * @example IANAZone.isValidZone("Fantasia/Castle") //=> false
  664. * @example IANAZone.isValidZone("Sport~~blorp") //=> false
  665. * @return {boolean}
  666. */;
  667. IANAZone.isValidZone = function isValidZone(zone) {
  668. if (!zone) {
  669. return false;
  670. }
  671. try {
  672. new Intl.DateTimeFormat("en-US", {
  673. timeZone: zone
  674. }).format();
  675. return true;
  676. } catch (e) {
  677. return false;
  678. }
  679. };
  680. function IANAZone(name) {
  681. var _this;
  682. _this = _Zone.call(this) || this;
  683. /** @private **/
  684. _this.zoneName = name;
  685. /** @private **/
  686. _this.valid = IANAZone.isValidZone(name);
  687. return _this;
  688. }
  689. /**
  690. * The type of zone. `iana` for all instances of `IANAZone`.
  691. * @override
  692. * @type {string}
  693. */
  694. var _proto = IANAZone.prototype;
  695. /**
  696. * Returns the offset's common name (such as EST) at the specified timestamp
  697. * @override
  698. * @param {number} ts - Epoch milliseconds for which to get the name
  699. * @param {Object} opts - Options to affect the format
  700. * @param {string} opts.format - What style of offset to return. Accepts 'long' or 'short'.
  701. * @param {string} opts.locale - What locale to return the offset name in.
  702. * @return {string}
  703. */
  704. _proto.offsetName = function offsetName(ts, _ref) {
  705. var format = _ref.format,
  706. locale = _ref.locale;
  707. return parseZoneInfo(ts, format, locale, this.name);
  708. }
  709. /**
  710. * Returns the offset's value as a string
  711. * @override
  712. * @param {number} ts - Epoch milliseconds for which to get the offset
  713. * @param {string} format - What style of offset to return.
  714. * Accepts 'narrow', 'short', or 'techie'. Returning '+6', '+06:00', or '+0600' respectively
  715. * @return {string}
  716. */;
  717. _proto.formatOffset = function formatOffset$1(ts, format) {
  718. return formatOffset(this.offset(ts), format);
  719. }
  720. /**
  721. * Return the offset in minutes for this zone at the specified timestamp.
  722. * @override
  723. * @param {number} ts - Epoch milliseconds for which to compute the offset
  724. * @return {number}
  725. */;
  726. _proto.offset = function offset(ts) {
  727. var date = new Date(ts);
  728. if (isNaN(date)) return NaN;
  729. var dtf = makeDTF(this.name);
  730. var _ref2 = dtf.formatToParts ? partsOffset(dtf, date) : hackyOffset(dtf, date),
  731. year = _ref2[0],
  732. month = _ref2[1],
  733. day = _ref2[2],
  734. adOrBc = _ref2[3],
  735. hour = _ref2[4],
  736. minute = _ref2[5],
  737. second = _ref2[6];
  738. if (adOrBc === "BC") {
  739. year = -Math.abs(year) + 1;
  740. }
  741. // because we're using hour12 and https://bugs.chromium.org/p/chromium/issues/detail?id=1025564&can=2&q=%2224%3A00%22%20datetimeformat
  742. var adjustedHour = hour === 24 ? 0 : hour;
  743. var asUTC = objToLocalTS({
  744. year: year,
  745. month: month,
  746. day: day,
  747. hour: adjustedHour,
  748. minute: minute,
  749. second: second,
  750. millisecond: 0
  751. });
  752. var asTS = +date;
  753. var over = asTS % 1000;
  754. asTS -= over >= 0 ? over : 1000 + over;
  755. return (asUTC - asTS) / (60 * 1000);
  756. }
  757. /**
  758. * Return whether this Zone is equal to another zone
  759. * @override
  760. * @param {Zone} otherZone - the zone to compare
  761. * @return {boolean}
  762. */;
  763. _proto.equals = function equals(otherZone) {
  764. return otherZone.type === "iana" && otherZone.name === this.name;
  765. }
  766. /**
  767. * Return whether this Zone is valid.
  768. * @override
  769. * @type {boolean}
  770. */;
  771. _createClass(IANAZone, [{
  772. key: "type",
  773. get: function get() {
  774. return "iana";
  775. }
  776. /**
  777. * The name of this zone (i.e. the IANA zone name).
  778. * @override
  779. * @type {string}
  780. */
  781. }, {
  782. key: "name",
  783. get: function get() {
  784. return this.zoneName;
  785. }
  786. /**
  787. * Returns whether the offset is known to be fixed for the whole year:
  788. * Always returns false for all IANA zones.
  789. * @override
  790. * @type {boolean}
  791. */
  792. }, {
  793. key: "isUniversal",
  794. get: function get() {
  795. return false;
  796. }
  797. }, {
  798. key: "isValid",
  799. get: function get() {
  800. return this.valid;
  801. }
  802. }]);
  803. return IANAZone;
  804. }(Zone);
  805. var _excluded = ["base"],
  806. _excluded2 = ["padTo", "floor"];
  807. // todo - remap caching
  808. var intlLFCache = {};
  809. function getCachedLF(locString, opts) {
  810. if (opts === void 0) {
  811. opts = {};
  812. }
  813. var key = JSON.stringify([locString, opts]);
  814. var dtf = intlLFCache[key];
  815. if (!dtf) {
  816. dtf = new Intl.ListFormat(locString, opts);
  817. intlLFCache[key] = dtf;
  818. }
  819. return dtf;
  820. }
  821. var intlDTCache = {};
  822. function getCachedDTF(locString, opts) {
  823. if (opts === void 0) {
  824. opts = {};
  825. }
  826. var key = JSON.stringify([locString, opts]);
  827. var dtf = intlDTCache[key];
  828. if (!dtf) {
  829. dtf = new Intl.DateTimeFormat(locString, opts);
  830. intlDTCache[key] = dtf;
  831. }
  832. return dtf;
  833. }
  834. var intlNumCache = {};
  835. function getCachedINF(locString, opts) {
  836. if (opts === void 0) {
  837. opts = {};
  838. }
  839. var key = JSON.stringify([locString, opts]);
  840. var inf = intlNumCache[key];
  841. if (!inf) {
  842. inf = new Intl.NumberFormat(locString, opts);
  843. intlNumCache[key] = inf;
  844. }
  845. return inf;
  846. }
  847. var intlRelCache = {};
  848. function getCachedRTF(locString, opts) {
  849. if (opts === void 0) {
  850. opts = {};
  851. }
  852. var _opts = opts;
  853. _opts.base;
  854. var cacheKeyOpts = _objectWithoutPropertiesLoose(_opts, _excluded); // exclude `base` from the options
  855. var key = JSON.stringify([locString, cacheKeyOpts]);
  856. var inf = intlRelCache[key];
  857. if (!inf) {
  858. inf = new Intl.RelativeTimeFormat(locString, opts);
  859. intlRelCache[key] = inf;
  860. }
  861. return inf;
  862. }
  863. var sysLocaleCache = null;
  864. function systemLocale() {
  865. if (sysLocaleCache) {
  866. return sysLocaleCache;
  867. } else {
  868. sysLocaleCache = new Intl.DateTimeFormat().resolvedOptions().locale;
  869. return sysLocaleCache;
  870. }
  871. }
  872. var weekInfoCache = {};
  873. function getCachedWeekInfo(locString) {
  874. var data = weekInfoCache[locString];
  875. if (!data) {
  876. var locale = new Intl.Locale(locString);
  877. // browsers currently implement this as a property, but spec says it should be a getter function
  878. data = "getWeekInfo" in locale ? locale.getWeekInfo() : locale.weekInfo;
  879. weekInfoCache[locString] = data;
  880. }
  881. return data;
  882. }
  883. function parseLocaleString(localeStr) {
  884. // I really want to avoid writing a BCP 47 parser
  885. // see, e.g. https://github.com/wooorm/bcp-47
  886. // Instead, we'll do this:
  887. // a) if the string has no -u extensions, just leave it alone
  888. // b) if it does, use Intl to resolve everything
  889. // c) if Intl fails, try again without the -u
  890. // private subtags and unicode subtags have ordering requirements,
  891. // and we're not properly parsing this, so just strip out the
  892. // private ones if they exist.
  893. var xIndex = localeStr.indexOf("-x-");
  894. if (xIndex !== -1) {
  895. localeStr = localeStr.substring(0, xIndex);
  896. }
  897. var uIndex = localeStr.indexOf("-u-");
  898. if (uIndex === -1) {
  899. return [localeStr];
  900. } else {
  901. var options;
  902. var selectedStr;
  903. try {
  904. options = getCachedDTF(localeStr).resolvedOptions();
  905. selectedStr = localeStr;
  906. } catch (e) {
  907. var smaller = localeStr.substring(0, uIndex);
  908. options = getCachedDTF(smaller).resolvedOptions();
  909. selectedStr = smaller;
  910. }
  911. var _options = options,
  912. numberingSystem = _options.numberingSystem,
  913. calendar = _options.calendar;
  914. return [selectedStr, numberingSystem, calendar];
  915. }
  916. }
  917. function intlConfigString(localeStr, numberingSystem, outputCalendar) {
  918. if (outputCalendar || numberingSystem) {
  919. if (!localeStr.includes("-u-")) {
  920. localeStr += "-u";
  921. }
  922. if (outputCalendar) {
  923. localeStr += "-ca-" + outputCalendar;
  924. }
  925. if (numberingSystem) {
  926. localeStr += "-nu-" + numberingSystem;
  927. }
  928. return localeStr;
  929. } else {
  930. return localeStr;
  931. }
  932. }
  933. function mapMonths(f) {
  934. var ms = [];
  935. for (var i = 1; i <= 12; i++) {
  936. var dt = DateTime.utc(2009, i, 1);
  937. ms.push(f(dt));
  938. }
  939. return ms;
  940. }
  941. function mapWeekdays(f) {
  942. var ms = [];
  943. for (var i = 1; i <= 7; i++) {
  944. var dt = DateTime.utc(2016, 11, 13 + i);
  945. ms.push(f(dt));
  946. }
  947. return ms;
  948. }
  949. function listStuff(loc, length, englishFn, intlFn) {
  950. var mode = loc.listingMode();
  951. if (mode === "error") {
  952. return null;
  953. } else if (mode === "en") {
  954. return englishFn(length);
  955. } else {
  956. return intlFn(length);
  957. }
  958. }
  959. function supportsFastNumbers(loc) {
  960. if (loc.numberingSystem && loc.numberingSystem !== "latn") {
  961. return false;
  962. } else {
  963. return loc.numberingSystem === "latn" || !loc.locale || loc.locale.startsWith("en") || new Intl.DateTimeFormat(loc.intl).resolvedOptions().numberingSystem === "latn";
  964. }
  965. }
  966. /**
  967. * @private
  968. */
  969. var PolyNumberFormatter = /*#__PURE__*/function () {
  970. function PolyNumberFormatter(intl, forceSimple, opts) {
  971. this.padTo = opts.padTo || 0;
  972. this.floor = opts.floor || false;
  973. opts.padTo;
  974. opts.floor;
  975. var otherOpts = _objectWithoutPropertiesLoose(opts, _excluded2);
  976. if (!forceSimple || Object.keys(otherOpts).length > 0) {
  977. var intlOpts = _extends({
  978. useGrouping: false
  979. }, opts);
  980. if (opts.padTo > 0) intlOpts.minimumIntegerDigits = opts.padTo;
  981. this.inf = getCachedINF(intl, intlOpts);
  982. }
  983. }
  984. var _proto = PolyNumberFormatter.prototype;
  985. _proto.format = function format(i) {
  986. if (this.inf) {
  987. var fixed = this.floor ? Math.floor(i) : i;
  988. return this.inf.format(fixed);
  989. } else {
  990. // to match the browser's numberformatter defaults
  991. var _fixed = this.floor ? Math.floor(i) : roundTo(i, 3);
  992. return padStart(_fixed, this.padTo);
  993. }
  994. };
  995. return PolyNumberFormatter;
  996. }();
  997. /**
  998. * @private
  999. */
  1000. var PolyDateFormatter = /*#__PURE__*/function () {
  1001. function PolyDateFormatter(dt, intl, opts) {
  1002. this.opts = opts;
  1003. this.originalZone = undefined;
  1004. var z = undefined;
  1005. if (this.opts.timeZone) {
  1006. // Don't apply any workarounds if a timeZone is explicitly provided in opts
  1007. this.dt = dt;
  1008. } else if (dt.zone.type === "fixed") {
  1009. // UTC-8 or Etc/UTC-8 are not part of tzdata, only Etc/GMT+8 and the like.
  1010. // That is why fixed-offset TZ is set to that unless it is:
  1011. // 1. Representing offset 0 when UTC is used to maintain previous behavior and does not become GMT.
  1012. // 2. Unsupported by the browser:
  1013. // - some do not support Etc/
  1014. // - < Etc/GMT-14, > Etc/GMT+12, and 30-minute or 45-minute offsets are not part of tzdata
  1015. var gmtOffset = -1 * (dt.offset / 60);
  1016. var offsetZ = gmtOffset >= 0 ? "Etc/GMT+" + gmtOffset : "Etc/GMT" + gmtOffset;
  1017. if (dt.offset !== 0 && IANAZone.create(offsetZ).valid) {
  1018. z = offsetZ;
  1019. this.dt = dt;
  1020. } else {
  1021. // Not all fixed-offset zones like Etc/+4:30 are present in tzdata so
  1022. // we manually apply the offset and substitute the zone as needed.
  1023. z = "UTC";
  1024. this.dt = dt.offset === 0 ? dt : dt.setZone("UTC").plus({
  1025. minutes: dt.offset
  1026. });
  1027. this.originalZone = dt.zone;
  1028. }
  1029. } else if (dt.zone.type === "system") {
  1030. this.dt = dt;
  1031. } else if (dt.zone.type === "iana") {
  1032. this.dt = dt;
  1033. z = dt.zone.name;
  1034. } else {
  1035. // Custom zones can have any offset / offsetName so we just manually
  1036. // apply the offset and substitute the zone as needed.
  1037. z = "UTC";
  1038. this.dt = dt.setZone("UTC").plus({
  1039. minutes: dt.offset
  1040. });
  1041. this.originalZone = dt.zone;
  1042. }
  1043. var intlOpts = _extends({}, this.opts);
  1044. intlOpts.timeZone = intlOpts.timeZone || z;
  1045. this.dtf = getCachedDTF(intl, intlOpts);
  1046. }
  1047. var _proto2 = PolyDateFormatter.prototype;
  1048. _proto2.format = function format() {
  1049. if (this.originalZone) {
  1050. // If we have to substitute in the actual zone name, we have to use
  1051. // formatToParts so that the timezone can be replaced.
  1052. return this.formatToParts().map(function (_ref) {
  1053. var value = _ref.value;
  1054. return value;
  1055. }).join("");
  1056. }
  1057. return this.dtf.format(this.dt.toJSDate());
  1058. };
  1059. _proto2.formatToParts = function formatToParts() {
  1060. var _this = this;
  1061. var parts = this.dtf.formatToParts(this.dt.toJSDate());
  1062. if (this.originalZone) {
  1063. return parts.map(function (part) {
  1064. if (part.type === "timeZoneName") {
  1065. var offsetName = _this.originalZone.offsetName(_this.dt.ts, {
  1066. locale: _this.dt.locale,
  1067. format: _this.opts.timeZoneName
  1068. });
  1069. return _extends({}, part, {
  1070. value: offsetName
  1071. });
  1072. } else {
  1073. return part;
  1074. }
  1075. });
  1076. }
  1077. return parts;
  1078. };
  1079. _proto2.resolvedOptions = function resolvedOptions() {
  1080. return this.dtf.resolvedOptions();
  1081. };
  1082. return PolyDateFormatter;
  1083. }();
  1084. /**
  1085. * @private
  1086. */
  1087. var PolyRelFormatter = /*#__PURE__*/function () {
  1088. function PolyRelFormatter(intl, isEnglish, opts) {
  1089. this.opts = _extends({
  1090. style: "long"
  1091. }, opts);
  1092. if (!isEnglish && hasRelative()) {
  1093. this.rtf = getCachedRTF(intl, opts);
  1094. }
  1095. }
  1096. var _proto3 = PolyRelFormatter.prototype;
  1097. _proto3.format = function format(count, unit) {
  1098. if (this.rtf) {
  1099. return this.rtf.format(count, unit);
  1100. } else {
  1101. return formatRelativeTime(unit, count, this.opts.numeric, this.opts.style !== "long");
  1102. }
  1103. };
  1104. _proto3.formatToParts = function formatToParts(count, unit) {
  1105. if (this.rtf) {
  1106. return this.rtf.formatToParts(count, unit);
  1107. } else {
  1108. return [];
  1109. }
  1110. };
  1111. return PolyRelFormatter;
  1112. }();
  1113. var fallbackWeekSettings = {
  1114. firstDay: 1,
  1115. minimalDays: 4,
  1116. weekend: [6, 7]
  1117. };
  1118. /**
  1119. * @private
  1120. */
  1121. var Locale = /*#__PURE__*/function () {
  1122. Locale.fromOpts = function fromOpts(opts) {
  1123. return Locale.create(opts.locale, opts.numberingSystem, opts.outputCalendar, opts.weekSettings, opts.defaultToEN);
  1124. };
  1125. Locale.create = function create(locale, numberingSystem, outputCalendar, weekSettings, defaultToEN) {
  1126. if (defaultToEN === void 0) {
  1127. defaultToEN = false;
  1128. }
  1129. var specifiedLocale = locale || Settings.defaultLocale;
  1130. // the system locale is useful for human-readable strings but annoying for parsing/formatting known formats
  1131. var localeR = specifiedLocale || (defaultToEN ? "en-US" : systemLocale());
  1132. var numberingSystemR = numberingSystem || Settings.defaultNumberingSystem;
  1133. var outputCalendarR = outputCalendar || Settings.defaultOutputCalendar;
  1134. var weekSettingsR = validateWeekSettings(weekSettings) || Settings.defaultWeekSettings;
  1135. return new Locale(localeR, numberingSystemR, outputCalendarR, weekSettingsR, specifiedLocale);
  1136. };
  1137. Locale.resetCache = function resetCache() {
  1138. sysLocaleCache = null;
  1139. intlDTCache = {};
  1140. intlNumCache = {};
  1141. intlRelCache = {};
  1142. };
  1143. Locale.fromObject = function fromObject(_temp) {
  1144. var _ref2 = _temp === void 0 ? {} : _temp,
  1145. locale = _ref2.locale,
  1146. numberingSystem = _ref2.numberingSystem,
  1147. outputCalendar = _ref2.outputCalendar,
  1148. weekSettings = _ref2.weekSettings;
  1149. return Locale.create(locale, numberingSystem, outputCalendar, weekSettings);
  1150. };
  1151. function Locale(locale, numbering, outputCalendar, weekSettings, specifiedLocale) {
  1152. var _parseLocaleString = parseLocaleString(locale),
  1153. parsedLocale = _parseLocaleString[0],
  1154. parsedNumberingSystem = _parseLocaleString[1],
  1155. parsedOutputCalendar = _parseLocaleString[2];
  1156. this.locale = parsedLocale;
  1157. this.numberingSystem = numbering || parsedNumberingSystem || null;
  1158. this.outputCalendar = outputCalendar || parsedOutputCalendar || null;
  1159. this.weekSettings = weekSettings;
  1160. this.intl = intlConfigString(this.locale, this.numberingSystem, this.outputCalendar);
  1161. this.weekdaysCache = {
  1162. format: {},
  1163. standalone: {}
  1164. };
  1165. this.monthsCache = {
  1166. format: {},
  1167. standalone: {}
  1168. };
  1169. this.meridiemCache = null;
  1170. this.eraCache = {};
  1171. this.specifiedLocale = specifiedLocale;
  1172. this.fastNumbersCached = null;
  1173. }
  1174. var _proto4 = Locale.prototype;
  1175. _proto4.listingMode = function listingMode() {
  1176. var isActuallyEn = this.isEnglish();
  1177. var hasNoWeirdness = (this.numberingSystem === null || this.numberingSystem === "latn") && (this.outputCalendar === null || this.outputCalendar === "gregory");
  1178. return isActuallyEn && hasNoWeirdness ? "en" : "intl";
  1179. };
  1180. _proto4.clone = function clone(alts) {
  1181. if (!alts || Object.getOwnPropertyNames(alts).length === 0) {
  1182. return this;
  1183. } else {
  1184. return Locale.create(alts.locale || this.specifiedLocale, alts.numberingSystem || this.numberingSystem, alts.outputCalendar || this.outputCalendar, validateWeekSettings(alts.weekSettings) || this.weekSettings, alts.defaultToEN || false);
  1185. }
  1186. };
  1187. _proto4.redefaultToEN = function redefaultToEN(alts) {
  1188. if (alts === void 0) {
  1189. alts = {};
  1190. }
  1191. return this.clone(_extends({}, alts, {
  1192. defaultToEN: true
  1193. }));
  1194. };
  1195. _proto4.redefaultToSystem = function redefaultToSystem(alts) {
  1196. if (alts === void 0) {
  1197. alts = {};
  1198. }
  1199. return this.clone(_extends({}, alts, {
  1200. defaultToEN: false
  1201. }));
  1202. };
  1203. _proto4.months = function months$1(length, format) {
  1204. var _this2 = this;
  1205. if (format === void 0) {
  1206. format = false;
  1207. }
  1208. return listStuff(this, length, months, function () {
  1209. var intl = format ? {
  1210. month: length,
  1211. day: "numeric"
  1212. } : {
  1213. month: length
  1214. },
  1215. formatStr = format ? "format" : "standalone";
  1216. if (!_this2.monthsCache[formatStr][length]) {
  1217. _this2.monthsCache[formatStr][length] = mapMonths(function (dt) {
  1218. return _this2.extract(dt, intl, "month");
  1219. });
  1220. }
  1221. return _this2.monthsCache[formatStr][length];
  1222. });
  1223. };
  1224. _proto4.weekdays = function weekdays$1(length, format) {
  1225. var _this3 = this;
  1226. if (format === void 0) {
  1227. format = false;
  1228. }
  1229. return listStuff(this, length, weekdays, function () {
  1230. var intl = format ? {
  1231. weekday: length,
  1232. year: "numeric",
  1233. month: "long",
  1234. day: "numeric"
  1235. } : {
  1236. weekday: length
  1237. },
  1238. formatStr = format ? "format" : "standalone";
  1239. if (!_this3.weekdaysCache[formatStr][length]) {
  1240. _this3.weekdaysCache[formatStr][length] = mapWeekdays(function (dt) {
  1241. return _this3.extract(dt, intl, "weekday");
  1242. });
  1243. }
  1244. return _this3.weekdaysCache[formatStr][length];
  1245. });
  1246. };
  1247. _proto4.meridiems = function meridiems$1() {
  1248. var _this4 = this;
  1249. return listStuff(this, undefined, function () {
  1250. return meridiems;
  1251. }, function () {
  1252. // In theory there could be aribitrary day periods. We're gonna assume there are exactly two
  1253. // for AM and PM. This is probably wrong, but it's makes parsing way easier.
  1254. if (!_this4.meridiemCache) {
  1255. var intl = {
  1256. hour: "numeric",
  1257. hourCycle: "h12"
  1258. };
  1259. _this4.meridiemCache = [DateTime.utc(2016, 11, 13, 9), DateTime.utc(2016, 11, 13, 19)].map(function (dt) {
  1260. return _this4.extract(dt, intl, "dayperiod");
  1261. });
  1262. }
  1263. return _this4.meridiemCache;
  1264. });
  1265. };
  1266. _proto4.eras = function eras$1(length) {
  1267. var _this5 = this;
  1268. return listStuff(this, length, eras, function () {
  1269. var intl = {
  1270. era: length
  1271. };
  1272. // This is problematic. Different calendars are going to define eras totally differently. What I need is the minimum set of dates
  1273. // to definitely enumerate them.
  1274. if (!_this5.eraCache[length]) {
  1275. _this5.eraCache[length] = [DateTime.utc(-40, 1, 1), DateTime.utc(2017, 1, 1)].map(function (dt) {
  1276. return _this5.extract(dt, intl, "era");
  1277. });
  1278. }
  1279. return _this5.eraCache[length];
  1280. });
  1281. };
  1282. _proto4.extract = function extract(dt, intlOpts, field) {
  1283. var df = this.dtFormatter(dt, intlOpts),
  1284. results = df.formatToParts(),
  1285. matching = results.find(function (m) {
  1286. return m.type.toLowerCase() === field;
  1287. });
  1288. return matching ? matching.value : null;
  1289. };
  1290. _proto4.numberFormatter = function numberFormatter(opts) {
  1291. if (opts === void 0) {
  1292. opts = {};
  1293. }
  1294. // this forcesimple option is never used (the only caller short-circuits on it, but it seems safer to leave)
  1295. // (in contrast, the rest of the condition is used heavily)
  1296. return new PolyNumberFormatter(this.intl, opts.forceSimple || this.fastNumbers, opts);
  1297. };
  1298. _proto4.dtFormatter = function dtFormatter(dt, intlOpts) {
  1299. if (intlOpts === void 0) {
  1300. intlOpts = {};
  1301. }
  1302. return new PolyDateFormatter(dt, this.intl, intlOpts);
  1303. };
  1304. _proto4.relFormatter = function relFormatter(opts) {
  1305. if (opts === void 0) {
  1306. opts = {};
  1307. }
  1308. return new PolyRelFormatter(this.intl, this.isEnglish(), opts);
  1309. };
  1310. _proto4.listFormatter = function listFormatter(opts) {
  1311. if (opts === void 0) {
  1312. opts = {};
  1313. }
  1314. return getCachedLF(this.intl, opts);
  1315. };
  1316. _proto4.isEnglish = function isEnglish() {
  1317. return this.locale === "en" || this.locale.toLowerCase() === "en-us" || new Intl.DateTimeFormat(this.intl).resolvedOptions().locale.startsWith("en-us");
  1318. };
  1319. _proto4.getWeekSettings = function getWeekSettings() {
  1320. if (this.weekSettings) {
  1321. return this.weekSettings;
  1322. } else if (!hasLocaleWeekInfo()) {
  1323. return fallbackWeekSettings;
  1324. } else {
  1325. return getCachedWeekInfo(this.locale);
  1326. }
  1327. };
  1328. _proto4.getStartOfWeek = function getStartOfWeek() {
  1329. return this.getWeekSettings().firstDay;
  1330. };
  1331. _proto4.getMinDaysInFirstWeek = function getMinDaysInFirstWeek() {
  1332. return this.getWeekSettings().minimalDays;
  1333. };
  1334. _proto4.getWeekendDays = function getWeekendDays() {
  1335. return this.getWeekSettings().weekend;
  1336. };
  1337. _proto4.equals = function equals(other) {
  1338. return this.locale === other.locale && this.numberingSystem === other.numberingSystem && this.outputCalendar === other.outputCalendar;
  1339. };
  1340. _proto4.toString = function toString() {
  1341. return "Locale(" + this.locale + ", " + this.numberingSystem + ", " + this.outputCalendar + ")";
  1342. };
  1343. _createClass(Locale, [{
  1344. key: "fastNumbers",
  1345. get: function get() {
  1346. if (this.fastNumbersCached == null) {
  1347. this.fastNumbersCached = supportsFastNumbers(this);
  1348. }
  1349. return this.fastNumbersCached;
  1350. }
  1351. }]);
  1352. return Locale;
  1353. }();
  1354. var singleton = null;
  1355. /**
  1356. * A zone with a fixed offset (meaning no DST)
  1357. * @implements {Zone}
  1358. */
  1359. var FixedOffsetZone = /*#__PURE__*/function (_Zone) {
  1360. _inheritsLoose(FixedOffsetZone, _Zone);
  1361. /**
  1362. * Get an instance with a specified offset
  1363. * @param {number} offset - The offset in minutes
  1364. * @return {FixedOffsetZone}
  1365. */
  1366. FixedOffsetZone.instance = function instance(offset) {
  1367. return offset === 0 ? FixedOffsetZone.utcInstance : new FixedOffsetZone(offset);
  1368. }
  1369. /**
  1370. * Get an instance of FixedOffsetZone from a UTC offset string, like "UTC+6"
  1371. * @param {string} s - The offset string to parse
  1372. * @example FixedOffsetZone.parseSpecifier("UTC+6")
  1373. * @example FixedOffsetZone.parseSpecifier("UTC+06")
  1374. * @example FixedOffsetZone.parseSpecifier("UTC-6:00")
  1375. * @return {FixedOffsetZone}
  1376. */;
  1377. FixedOffsetZone.parseSpecifier = function parseSpecifier(s) {
  1378. if (s) {
  1379. var r = s.match(/^utc(?:([+-]\d{1,2})(?::(\d{2}))?)?$/i);
  1380. if (r) {
  1381. return new FixedOffsetZone(signedOffset(r[1], r[2]));
  1382. }
  1383. }
  1384. return null;
  1385. };
  1386. function FixedOffsetZone(offset) {
  1387. var _this;
  1388. _this = _Zone.call(this) || this;
  1389. /** @private **/
  1390. _this.fixed = offset;
  1391. return _this;
  1392. }
  1393. /**
  1394. * The type of zone. `fixed` for all instances of `FixedOffsetZone`.
  1395. * @override
  1396. * @type {string}
  1397. */
  1398. var _proto = FixedOffsetZone.prototype;
  1399. /**
  1400. * Returns the offset's common name at the specified timestamp.
  1401. *
  1402. * For fixed offset zones this equals to the zone name.
  1403. * @override
  1404. */
  1405. _proto.offsetName = function offsetName() {
  1406. return this.name;
  1407. }
  1408. /**
  1409. * Returns the offset's value as a string
  1410. * @override
  1411. * @param {number} ts - Epoch milliseconds for which to get the offset
  1412. * @param {string} format - What style of offset to return.
  1413. * Accepts 'narrow', 'short', or 'techie'. Returning '+6', '+06:00', or '+0600' respectively
  1414. * @return {string}
  1415. */;
  1416. _proto.formatOffset = function formatOffset$1(ts, format) {
  1417. return formatOffset(this.fixed, format);
  1418. }
  1419. /**
  1420. * Returns whether the offset is known to be fixed for the whole year:
  1421. * Always returns true for all fixed offset zones.
  1422. * @override
  1423. * @type {boolean}
  1424. */;
  1425. /**
  1426. * Return the offset in minutes for this zone at the specified timestamp.
  1427. *
  1428. * For fixed offset zones, this is constant and does not depend on a timestamp.
  1429. * @override
  1430. * @return {number}
  1431. */
  1432. _proto.offset = function offset() {
  1433. return this.fixed;
  1434. }
  1435. /**
  1436. * Return whether this Zone is equal to another zone (i.e. also fixed and same offset)
  1437. * @override
  1438. * @param {Zone} otherZone - the zone to compare
  1439. * @return {boolean}
  1440. */;
  1441. _proto.equals = function equals(otherZone) {
  1442. return otherZone.type === "fixed" && otherZone.fixed === this.fixed;
  1443. }
  1444. /**
  1445. * Return whether this Zone is valid:
  1446. * All fixed offset zones are valid.
  1447. * @override
  1448. * @type {boolean}
  1449. */;
  1450. _createClass(FixedOffsetZone, [{
  1451. key: "type",
  1452. get: function get() {
  1453. return "fixed";
  1454. }
  1455. /**
  1456. * The name of this zone.
  1457. * All fixed zones' names always start with "UTC" (plus optional offset)
  1458. * @override
  1459. * @type {string}
  1460. */
  1461. }, {
  1462. key: "name",
  1463. get: function get() {
  1464. return this.fixed === 0 ? "UTC" : "UTC" + formatOffset(this.fixed, "narrow");
  1465. }
  1466. /**
  1467. * The IANA name of this zone, i.e. `Etc/UTC` or `Etc/GMT+/-nn`
  1468. *
  1469. * @override
  1470. * @type {string}
  1471. */
  1472. }, {
  1473. key: "ianaName",
  1474. get: function get() {
  1475. if (this.fixed === 0) {
  1476. return "Etc/UTC";
  1477. } else {
  1478. return "Etc/GMT" + formatOffset(-this.fixed, "narrow");
  1479. }
  1480. }
  1481. }, {
  1482. key: "isUniversal",
  1483. get: function get() {
  1484. return true;
  1485. }
  1486. }, {
  1487. key: "isValid",
  1488. get: function get() {
  1489. return true;
  1490. }
  1491. }], [{
  1492. key: "utcInstance",
  1493. get:
  1494. /**
  1495. * Get a singleton instance of UTC
  1496. * @return {FixedOffsetZone}
  1497. */
  1498. function get() {
  1499. if (singleton === null) {
  1500. singleton = new FixedOffsetZone(0);
  1501. }
  1502. return singleton;
  1503. }
  1504. }]);
  1505. return FixedOffsetZone;
  1506. }(Zone);
  1507. /**
  1508. * A zone that failed to parse. You should never need to instantiate this.
  1509. * @implements {Zone}
  1510. */
  1511. var InvalidZone = /*#__PURE__*/function (_Zone) {
  1512. _inheritsLoose(InvalidZone, _Zone);
  1513. function InvalidZone(zoneName) {
  1514. var _this;
  1515. _this = _Zone.call(this) || this;
  1516. /** @private */
  1517. _this.zoneName = zoneName;
  1518. return _this;
  1519. }
  1520. /** @override **/
  1521. var _proto = InvalidZone.prototype;
  1522. /** @override **/
  1523. _proto.offsetName = function offsetName() {
  1524. return null;
  1525. }
  1526. /** @override **/;
  1527. _proto.formatOffset = function formatOffset() {
  1528. return "";
  1529. }
  1530. /** @override **/;
  1531. _proto.offset = function offset() {
  1532. return NaN;
  1533. }
  1534. /** @override **/;
  1535. _proto.equals = function equals() {
  1536. return false;
  1537. }
  1538. /** @override **/;
  1539. _createClass(InvalidZone, [{
  1540. key: "type",
  1541. get: function get() {
  1542. return "invalid";
  1543. }
  1544. /** @override **/
  1545. }, {
  1546. key: "name",
  1547. get: function get() {
  1548. return this.zoneName;
  1549. }
  1550. /** @override **/
  1551. }, {
  1552. key: "isUniversal",
  1553. get: function get() {
  1554. return false;
  1555. }
  1556. }, {
  1557. key: "isValid",
  1558. get: function get() {
  1559. return false;
  1560. }
  1561. }]);
  1562. return InvalidZone;
  1563. }(Zone);
  1564. /**
  1565. * @private
  1566. */
  1567. function normalizeZone(input, defaultZone) {
  1568. if (isUndefined(input) || input === null) {
  1569. return defaultZone;
  1570. } else if (input instanceof Zone) {
  1571. return input;
  1572. } else if (isString(input)) {
  1573. var lowered = input.toLowerCase();
  1574. if (lowered === "default") return defaultZone;else if (lowered === "local" || lowered === "system") return SystemZone.instance;else if (lowered === "utc" || lowered === "gmt") return FixedOffsetZone.utcInstance;else return FixedOffsetZone.parseSpecifier(lowered) || IANAZone.create(input);
  1575. } else if (isNumber(input)) {
  1576. return FixedOffsetZone.instance(input);
  1577. } else if (typeof input === "object" && "offset" in input && typeof input.offset === "function") {
  1578. // This is dumb, but the instanceof check above doesn't seem to really work
  1579. // so we're duck checking it
  1580. return input;
  1581. } else {
  1582. return new InvalidZone(input);
  1583. }
  1584. }
  1585. var numberingSystems = {
  1586. arab: "[\u0660-\u0669]",
  1587. arabext: "[\u06F0-\u06F9]",
  1588. bali: "[\u1B50-\u1B59]",
  1589. beng: "[\u09E6-\u09EF]",
  1590. deva: "[\u0966-\u096F]",
  1591. fullwide: "[\uFF10-\uFF19]",
  1592. gujr: "[\u0AE6-\u0AEF]",
  1593. hanidec: "[〇|一|二|三|四|五|六|七|八|九]",
  1594. khmr: "[\u17E0-\u17E9]",
  1595. knda: "[\u0CE6-\u0CEF]",
  1596. laoo: "[\u0ED0-\u0ED9]",
  1597. limb: "[\u1946-\u194F]",
  1598. mlym: "[\u0D66-\u0D6F]",
  1599. mong: "[\u1810-\u1819]",
  1600. mymr: "[\u1040-\u1049]",
  1601. orya: "[\u0B66-\u0B6F]",
  1602. tamldec: "[\u0BE6-\u0BEF]",
  1603. telu: "[\u0C66-\u0C6F]",
  1604. thai: "[\u0E50-\u0E59]",
  1605. tibt: "[\u0F20-\u0F29]",
  1606. latn: "\\d"
  1607. };
  1608. var numberingSystemsUTF16 = {
  1609. arab: [1632, 1641],
  1610. arabext: [1776, 1785],
  1611. bali: [6992, 7001],
  1612. beng: [2534, 2543],
  1613. deva: [2406, 2415],
  1614. fullwide: [65296, 65303],
  1615. gujr: [2790, 2799],
  1616. khmr: [6112, 6121],
  1617. knda: [3302, 3311],
  1618. laoo: [3792, 3801],
  1619. limb: [6470, 6479],
  1620. mlym: [3430, 3439],
  1621. mong: [6160, 6169],
  1622. mymr: [4160, 4169],
  1623. orya: [2918, 2927],
  1624. tamldec: [3046, 3055],
  1625. telu: [3174, 3183],
  1626. thai: [3664, 3673],
  1627. tibt: [3872, 3881]
  1628. };
  1629. var hanidecChars = numberingSystems.hanidec.replace(/[\[|\]]/g, "").split("");
  1630. function parseDigits(str) {
  1631. var value = parseInt(str, 10);
  1632. if (isNaN(value)) {
  1633. value = "";
  1634. for (var i = 0; i < str.length; i++) {
  1635. var code = str.charCodeAt(i);
  1636. if (str[i].search(numberingSystems.hanidec) !== -1) {
  1637. value += hanidecChars.indexOf(str[i]);
  1638. } else {
  1639. for (var key in numberingSystemsUTF16) {
  1640. var _numberingSystemsUTF = numberingSystemsUTF16[key],
  1641. min = _numberingSystemsUTF[0],
  1642. max = _numberingSystemsUTF[1];
  1643. if (code >= min && code <= max) {
  1644. value += code - min;
  1645. }
  1646. }
  1647. }
  1648. }
  1649. return parseInt(value, 10);
  1650. } else {
  1651. return value;
  1652. }
  1653. }
  1654. // cache of {numberingSystem: {append: regex}}
  1655. var digitRegexCache = {};
  1656. function resetDigitRegexCache() {
  1657. digitRegexCache = {};
  1658. }
  1659. function digitRegex(_ref, append) {
  1660. var numberingSystem = _ref.numberingSystem;
  1661. if (append === void 0) {
  1662. append = "";
  1663. }
  1664. var ns = numberingSystem || "latn";
  1665. if (!digitRegexCache[ns]) {
  1666. digitRegexCache[ns] = {};
  1667. }
  1668. if (!digitRegexCache[ns][append]) {
  1669. digitRegexCache[ns][append] = new RegExp("" + numberingSystems[ns] + append);
  1670. }
  1671. return digitRegexCache[ns][append];
  1672. }
  1673. var now = function now() {
  1674. return Date.now();
  1675. },
  1676. defaultZone = "system",
  1677. defaultLocale = null,
  1678. defaultNumberingSystem = null,
  1679. defaultOutputCalendar = null,
  1680. twoDigitCutoffYear = 60,
  1681. throwOnInvalid,
  1682. defaultWeekSettings = null;
  1683. /**
  1684. * Settings contains static getters and setters that control Luxon's overall behavior. Luxon is a simple library with few options, but the ones it does have live here.
  1685. */
  1686. var Settings = /*#__PURE__*/function () {
  1687. function Settings() {}
  1688. /**
  1689. * Reset Luxon's global caches. Should only be necessary in testing scenarios.
  1690. * @return {void}
  1691. */
  1692. Settings.resetCaches = function resetCaches() {
  1693. Locale.resetCache();
  1694. IANAZone.resetCache();
  1695. DateTime.resetCache();
  1696. resetDigitRegexCache();
  1697. };
  1698. _createClass(Settings, null, [{
  1699. key: "now",
  1700. get:
  1701. /**
  1702. * Get the callback for returning the current timestamp.
  1703. * @type {function}
  1704. */
  1705. function get() {
  1706. return now;
  1707. }
  1708. /**
  1709. * Set the callback for returning the current timestamp.
  1710. * The function should return a number, which will be interpreted as an Epoch millisecond count
  1711. * @type {function}
  1712. * @example Settings.now = () => Date.now() + 3000 // pretend it is 3 seconds in the future
  1713. * @example Settings.now = () => 0 // always pretend it's Jan 1, 1970 at midnight in UTC time
  1714. */,
  1715. set: function set(n) {
  1716. now = n;
  1717. }
  1718. /**
  1719. * Set the default time zone to create DateTimes in. Does not affect existing instances.
  1720. * Use the value "system" to reset this value to the system's time zone.
  1721. * @type {string}
  1722. */
  1723. }, {
  1724. key: "defaultZone",
  1725. get:
  1726. /**
  1727. * Get the default time zone object currently used to create DateTimes. Does not affect existing instances.
  1728. * The default value is the system's time zone (the one set on the machine that runs this code).
  1729. * @type {Zone}
  1730. */
  1731. function get() {
  1732. return normalizeZone(defaultZone, SystemZone.instance);
  1733. }
  1734. /**
  1735. * Get the default locale to create DateTimes with. Does not affect existing instances.
  1736. * @type {string}
  1737. */,
  1738. set: function set(zone) {
  1739. defaultZone = zone;
  1740. }
  1741. }, {
  1742. key: "defaultLocale",
  1743. get: function get() {
  1744. return defaultLocale;
  1745. }
  1746. /**
  1747. * Set the default locale to create DateTimes with. Does not affect existing instances.
  1748. * @type {string}
  1749. */,
  1750. set: function set(locale) {
  1751. defaultLocale = locale;
  1752. }
  1753. /**
  1754. * Get the default numbering system to create DateTimes with. Does not affect existing instances.
  1755. * @type {string}
  1756. */
  1757. }, {
  1758. key: "defaultNumberingSystem",
  1759. get: function get() {
  1760. return defaultNumberingSystem;
  1761. }
  1762. /**
  1763. * Set the default numbering system to create DateTimes with. Does not affect existing instances.
  1764. * @type {string}
  1765. */,
  1766. set: function set(numberingSystem) {
  1767. defaultNumberingSystem = numberingSystem;
  1768. }
  1769. /**
  1770. * Get the default output calendar to create DateTimes with. Does not affect existing instances.
  1771. * @type {string}
  1772. */
  1773. }, {
  1774. key: "defaultOutputCalendar",
  1775. get: function get() {
  1776. return defaultOutputCalendar;
  1777. }
  1778. /**
  1779. * Set the default output calendar to create DateTimes with. Does not affect existing instances.
  1780. * @type {string}
  1781. */,
  1782. set: function set(outputCalendar) {
  1783. defaultOutputCalendar = outputCalendar;
  1784. }
  1785. /**
  1786. * @typedef {Object} WeekSettings
  1787. * @property {number} firstDay
  1788. * @property {number} minimalDays
  1789. * @property {number[]} weekend
  1790. */
  1791. /**
  1792. * @return {WeekSettings|null}
  1793. */
  1794. }, {
  1795. key: "defaultWeekSettings",
  1796. get: function get() {
  1797. return defaultWeekSettings;
  1798. }
  1799. /**
  1800. * Allows overriding the default locale week settings, i.e. the start of the week, the weekend and
  1801. * how many days are required in the first week of a year.
  1802. * Does not affect existing instances.
  1803. *
  1804. * @param {WeekSettings|null} weekSettings
  1805. */,
  1806. set: function set(weekSettings) {
  1807. defaultWeekSettings = validateWeekSettings(weekSettings);
  1808. }
  1809. /**
  1810. * Get the cutoff year for whether a 2-digit year string is interpreted in the current or previous century. Numbers higher than the cutoff will be considered to mean 19xx and numbers lower or equal to the cutoff will be considered 20xx.
  1811. * @type {number}
  1812. */
  1813. }, {
  1814. key: "twoDigitCutoffYear",
  1815. get: function get() {
  1816. return twoDigitCutoffYear;
  1817. }
  1818. /**
  1819. * Set the cutoff year for whether a 2-digit year string is interpreted in the current or previous century. Numbers higher than the cutoff will be considered to mean 19xx and numbers lower or equal to the cutoff will be considered 20xx.
  1820. * @type {number}
  1821. * @example Settings.twoDigitCutoffYear = 0 // all 'yy' are interpreted as 20th century
  1822. * @example Settings.twoDigitCutoffYear = 99 // all 'yy' are interpreted as 21st century
  1823. * @example Settings.twoDigitCutoffYear = 50 // '49' -> 2049; '50' -> 1950
  1824. * @example Settings.twoDigitCutoffYear = 1950 // interpreted as 50
  1825. * @example Settings.twoDigitCutoffYear = 2050 // ALSO interpreted as 50
  1826. */,
  1827. set: function set(cutoffYear) {
  1828. twoDigitCutoffYear = cutoffYear % 100;
  1829. }
  1830. /**
  1831. * Get whether Luxon will throw when it encounters invalid DateTimes, Durations, or Intervals
  1832. * @type {boolean}
  1833. */
  1834. }, {
  1835. key: "throwOnInvalid",
  1836. get: function get() {
  1837. return throwOnInvalid;
  1838. }
  1839. /**
  1840. * Set whether Luxon will throw when it encounters invalid DateTimes, Durations, or Intervals
  1841. * @type {boolean}
  1842. */,
  1843. set: function set(t) {
  1844. throwOnInvalid = t;
  1845. }
  1846. }]);
  1847. return Settings;
  1848. }();
  1849. var Invalid = /*#__PURE__*/function () {
  1850. function Invalid(reason, explanation) {
  1851. this.reason = reason;
  1852. this.explanation = explanation;
  1853. }
  1854. var _proto = Invalid.prototype;
  1855. _proto.toMessage = function toMessage() {
  1856. if (this.explanation) {
  1857. return this.reason + ": " + this.explanation;
  1858. } else {
  1859. return this.reason;
  1860. }
  1861. };
  1862. return Invalid;
  1863. }();
  1864. var nonLeapLadder = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334],
  1865. leapLadder = [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335];
  1866. function unitOutOfRange(unit, value) {
  1867. return new Invalid("unit out of range", "you specified " + value + " (of type " + typeof value + ") as a " + unit + ", which is invalid");
  1868. }
  1869. function dayOfWeek(year, month, day) {
  1870. var d = new Date(Date.UTC(year, month - 1, day));
  1871. if (year < 100 && year >= 0) {
  1872. d.setUTCFullYear(d.getUTCFullYear() - 1900);
  1873. }
  1874. var js = d.getUTCDay();
  1875. return js === 0 ? 7 : js;
  1876. }
  1877. function computeOrdinal(year, month, day) {
  1878. return day + (isLeapYear(year) ? leapLadder : nonLeapLadder)[month - 1];
  1879. }
  1880. function uncomputeOrdinal(year, ordinal) {
  1881. var table = isLeapYear(year) ? leapLadder : nonLeapLadder,
  1882. month0 = table.findIndex(function (i) {
  1883. return i < ordinal;
  1884. }),
  1885. day = ordinal - table[month0];
  1886. return {
  1887. month: month0 + 1,
  1888. day: day
  1889. };
  1890. }
  1891. function isoWeekdayToLocal(isoWeekday, startOfWeek) {
  1892. return (isoWeekday - startOfWeek + 7) % 7 + 1;
  1893. }
  1894. /**
  1895. * @private
  1896. */
  1897. function gregorianToWeek(gregObj, minDaysInFirstWeek, startOfWeek) {
  1898. if (minDaysInFirstWeek === void 0) {
  1899. minDaysInFirstWeek = 4;
  1900. }
  1901. if (startOfWeek === void 0) {
  1902. startOfWeek = 1;
  1903. }
  1904. var year = gregObj.year,
  1905. month = gregObj.month,
  1906. day = gregObj.day,
  1907. ordinal = computeOrdinal(year, month, day),
  1908. weekday = isoWeekdayToLocal(dayOfWeek(year, month, day), startOfWeek);
  1909. var weekNumber = Math.floor((ordinal - weekday + 14 - minDaysInFirstWeek) / 7),
  1910. weekYear;
  1911. if (weekNumber < 1) {
  1912. weekYear = year - 1;
  1913. weekNumber = weeksInWeekYear(weekYear, minDaysInFirstWeek, startOfWeek);
  1914. } else if (weekNumber > weeksInWeekYear(year, minDaysInFirstWeek, startOfWeek)) {
  1915. weekYear = year + 1;
  1916. weekNumber = 1;
  1917. } else {
  1918. weekYear = year;
  1919. }
  1920. return _extends({
  1921. weekYear: weekYear,
  1922. weekNumber: weekNumber,
  1923. weekday: weekday
  1924. }, timeObject(gregObj));
  1925. }
  1926. function weekToGregorian(weekData, minDaysInFirstWeek, startOfWeek) {
  1927. if (minDaysInFirstWeek === void 0) {
  1928. minDaysInFirstWeek = 4;
  1929. }
  1930. if (startOfWeek === void 0) {
  1931. startOfWeek = 1;
  1932. }
  1933. var weekYear = weekData.weekYear,
  1934. weekNumber = weekData.weekNumber,
  1935. weekday = weekData.weekday,
  1936. weekdayOfJan4 = isoWeekdayToLocal(dayOfWeek(weekYear, 1, minDaysInFirstWeek), startOfWeek),
  1937. yearInDays = daysInYear(weekYear);
  1938. var ordinal = weekNumber * 7 + weekday - weekdayOfJan4 - 7 + minDaysInFirstWeek,
  1939. year;
  1940. if (ordinal < 1) {
  1941. year = weekYear - 1;
  1942. ordinal += daysInYear(year);
  1943. } else if (ordinal > yearInDays) {
  1944. year = weekYear + 1;
  1945. ordinal -= daysInYear(weekYear);
  1946. } else {
  1947. year = weekYear;
  1948. }
  1949. var _uncomputeOrdinal = uncomputeOrdinal(year, ordinal),
  1950. month = _uncomputeOrdinal.month,
  1951. day = _uncomputeOrdinal.day;
  1952. return _extends({
  1953. year: year,
  1954. month: month,
  1955. day: day
  1956. }, timeObject(weekData));
  1957. }
  1958. function gregorianToOrdinal(gregData) {
  1959. var year = gregData.year,
  1960. month = gregData.month,
  1961. day = gregData.day;
  1962. var ordinal = computeOrdinal(year, month, day);
  1963. return _extends({
  1964. year: year,
  1965. ordinal: ordinal
  1966. }, timeObject(gregData));
  1967. }
  1968. function ordinalToGregorian(ordinalData) {
  1969. var year = ordinalData.year,
  1970. ordinal = ordinalData.ordinal;
  1971. var _uncomputeOrdinal2 = uncomputeOrdinal(year, ordinal),
  1972. month = _uncomputeOrdinal2.month,
  1973. day = _uncomputeOrdinal2.day;
  1974. return _extends({
  1975. year: year,
  1976. month: month,
  1977. day: day
  1978. }, timeObject(ordinalData));
  1979. }
  1980. /**
  1981. * Check if local week units like localWeekday are used in obj.
  1982. * If so, validates that they are not mixed with ISO week units and then copies them to the normal week unit properties.
  1983. * Modifies obj in-place!
  1984. * @param obj the object values
  1985. */
  1986. function usesLocalWeekValues(obj, loc) {
  1987. var hasLocaleWeekData = !isUndefined(obj.localWeekday) || !isUndefined(obj.localWeekNumber) || !isUndefined(obj.localWeekYear);
  1988. if (hasLocaleWeekData) {
  1989. var hasIsoWeekData = !isUndefined(obj.weekday) || !isUndefined(obj.weekNumber) || !isUndefined(obj.weekYear);
  1990. if (hasIsoWeekData) {
  1991. throw new ConflictingSpecificationError("Cannot mix locale-based week fields with ISO-based week fields");
  1992. }
  1993. if (!isUndefined(obj.localWeekday)) obj.weekday = obj.localWeekday;
  1994. if (!isUndefined(obj.localWeekNumber)) obj.weekNumber = obj.localWeekNumber;
  1995. if (!isUndefined(obj.localWeekYear)) obj.weekYear = obj.localWeekYear;
  1996. delete obj.localWeekday;
  1997. delete obj.localWeekNumber;
  1998. delete obj.localWeekYear;
  1999. return {
  2000. minDaysInFirstWeek: loc.getMinDaysInFirstWeek(),
  2001. startOfWeek: loc.getStartOfWeek()
  2002. };
  2003. } else {
  2004. return {
  2005. minDaysInFirstWeek: 4,
  2006. startOfWeek: 1
  2007. };
  2008. }
  2009. }
  2010. function hasInvalidWeekData(obj, minDaysInFirstWeek, startOfWeek) {
  2011. if (minDaysInFirstWeek === void 0) {
  2012. minDaysInFirstWeek = 4;
  2013. }
  2014. if (startOfWeek === void 0) {
  2015. startOfWeek = 1;
  2016. }
  2017. var validYear = isInteger(obj.weekYear),
  2018. validWeek = integerBetween(obj.weekNumber, 1, weeksInWeekYear(obj.weekYear, minDaysInFirstWeek, startOfWeek)),
  2019. validWeekday = integerBetween(obj.weekday, 1, 7);
  2020. if (!validYear) {
  2021. return unitOutOfRange("weekYear", obj.weekYear);
  2022. } else if (!validWeek) {
  2023. return unitOutOfRange("week", obj.weekNumber);
  2024. } else if (!validWeekday) {
  2025. return unitOutOfRange("weekday", obj.weekday);
  2026. } else return false;
  2027. }
  2028. function hasInvalidOrdinalData(obj) {
  2029. var validYear = isInteger(obj.year),
  2030. validOrdinal = integerBetween(obj.ordinal, 1, daysInYear(obj.year));
  2031. if (!validYear) {
  2032. return unitOutOfRange("year", obj.year);
  2033. } else if (!validOrdinal) {
  2034. return unitOutOfRange("ordinal", obj.ordinal);
  2035. } else return false;
  2036. }
  2037. function hasInvalidGregorianData(obj) {
  2038. var validYear = isInteger(obj.year),
  2039. validMonth = integerBetween(obj.month, 1, 12),
  2040. validDay = integerBetween(obj.day, 1, daysInMonth(obj.year, obj.month));
  2041. if (!validYear) {
  2042. return unitOutOfRange("year", obj.year);
  2043. } else if (!validMonth) {
  2044. return unitOutOfRange("month", obj.month);
  2045. } else if (!validDay) {
  2046. return unitOutOfRange("day", obj.day);
  2047. } else return false;
  2048. }
  2049. function hasInvalidTimeData(obj) {
  2050. var hour = obj.hour,
  2051. minute = obj.minute,
  2052. second = obj.second,
  2053. millisecond = obj.millisecond;
  2054. var validHour = integerBetween(hour, 0, 23) || hour === 24 && minute === 0 && second === 0 && millisecond === 0,
  2055. validMinute = integerBetween(minute, 0, 59),
  2056. validSecond = integerBetween(second, 0, 59),
  2057. validMillisecond = integerBetween(millisecond, 0, 999);
  2058. if (!validHour) {
  2059. return unitOutOfRange("hour", hour);
  2060. } else if (!validMinute) {
  2061. return unitOutOfRange("minute", minute);
  2062. } else if (!validSecond) {
  2063. return unitOutOfRange("second", second);
  2064. } else if (!validMillisecond) {
  2065. return unitOutOfRange("millisecond", millisecond);
  2066. } else return false;
  2067. }
  2068. /**
  2069. * @private
  2070. */
  2071. // TYPES
  2072. function isUndefined(o) {
  2073. return typeof o === "undefined";
  2074. }
  2075. function isNumber(o) {
  2076. return typeof o === "number";
  2077. }
  2078. function isInteger(o) {
  2079. return typeof o === "number" && o % 1 === 0;
  2080. }
  2081. function isString(o) {
  2082. return typeof o === "string";
  2083. }
  2084. function isDate(o) {
  2085. return Object.prototype.toString.call(o) === "[object Date]";
  2086. }
  2087. // CAPABILITIES
  2088. function hasRelative() {
  2089. try {
  2090. return typeof Intl !== "undefined" && !!Intl.RelativeTimeFormat;
  2091. } catch (e) {
  2092. return false;
  2093. }
  2094. }
  2095. function hasLocaleWeekInfo() {
  2096. try {
  2097. return typeof Intl !== "undefined" && !!Intl.Locale && ("weekInfo" in Intl.Locale.prototype || "getWeekInfo" in Intl.Locale.prototype);
  2098. } catch (e) {
  2099. return false;
  2100. }
  2101. }
  2102. // OBJECTS AND ARRAYS
  2103. function maybeArray(thing) {
  2104. return Array.isArray(thing) ? thing : [thing];
  2105. }
  2106. function bestBy(arr, by, compare) {
  2107. if (arr.length === 0) {
  2108. return undefined;
  2109. }
  2110. return arr.reduce(function (best, next) {
  2111. var pair = [by(next), next];
  2112. if (!best) {
  2113. return pair;
  2114. } else if (compare(best[0], pair[0]) === best[0]) {
  2115. return best;
  2116. } else {
  2117. return pair;
  2118. }
  2119. }, null)[1];
  2120. }
  2121. function pick(obj, keys) {
  2122. return keys.reduce(function (a, k) {
  2123. a[k] = obj[k];
  2124. return a;
  2125. }, {});
  2126. }
  2127. function hasOwnProperty(obj, prop) {
  2128. return Object.prototype.hasOwnProperty.call(obj, prop);
  2129. }
  2130. function validateWeekSettings(settings) {
  2131. if (settings == null) {
  2132. return null;
  2133. } else if (typeof settings !== "object") {
  2134. throw new InvalidArgumentError("Week settings must be an object");
  2135. } else {
  2136. if (!integerBetween(settings.firstDay, 1, 7) || !integerBetween(settings.minimalDays, 1, 7) || !Array.isArray(settings.weekend) || settings.weekend.some(function (v) {
  2137. return !integerBetween(v, 1, 7);
  2138. })) {
  2139. throw new InvalidArgumentError("Invalid week settings");
  2140. }
  2141. return {
  2142. firstDay: settings.firstDay,
  2143. minimalDays: settings.minimalDays,
  2144. weekend: Array.from(settings.weekend)
  2145. };
  2146. }
  2147. }
  2148. // NUMBERS AND STRINGS
  2149. function integerBetween(thing, bottom, top) {
  2150. return isInteger(thing) && thing >= bottom && thing <= top;
  2151. }
  2152. // x % n but takes the sign of n instead of x
  2153. function floorMod(x, n) {
  2154. return x - n * Math.floor(x / n);
  2155. }
  2156. function padStart(input, n) {
  2157. if (n === void 0) {
  2158. n = 2;
  2159. }
  2160. var isNeg = input < 0;
  2161. var padded;
  2162. if (isNeg) {
  2163. padded = "-" + ("" + -input).padStart(n, "0");
  2164. } else {
  2165. padded = ("" + input).padStart(n, "0");
  2166. }
  2167. return padded;
  2168. }
  2169. function parseInteger(string) {
  2170. if (isUndefined(string) || string === null || string === "") {
  2171. return undefined;
  2172. } else {
  2173. return parseInt(string, 10);
  2174. }
  2175. }
  2176. function parseFloating(string) {
  2177. if (isUndefined(string) || string === null || string === "") {
  2178. return undefined;
  2179. } else {
  2180. return parseFloat(string);
  2181. }
  2182. }
  2183. function parseMillis(fraction) {
  2184. // Return undefined (instead of 0) in these cases, where fraction is not set
  2185. if (isUndefined(fraction) || fraction === null || fraction === "") {
  2186. return undefined;
  2187. } else {
  2188. var f = parseFloat("0." + fraction) * 1000;
  2189. return Math.floor(f);
  2190. }
  2191. }
  2192. function roundTo(number, digits, towardZero) {
  2193. if (towardZero === void 0) {
  2194. towardZero = false;
  2195. }
  2196. var factor = Math.pow(10, digits),
  2197. rounder = towardZero ? Math.trunc : Math.round;
  2198. return rounder(number * factor) / factor;
  2199. }
  2200. // DATE BASICS
  2201. function isLeapYear(year) {
  2202. return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
  2203. }
  2204. function daysInYear(year) {
  2205. return isLeapYear(year) ? 366 : 365;
  2206. }
  2207. function daysInMonth(year, month) {
  2208. var modMonth = floorMod(month - 1, 12) + 1,
  2209. modYear = year + (month - modMonth) / 12;
  2210. if (modMonth === 2) {
  2211. return isLeapYear(modYear) ? 29 : 28;
  2212. } else {
  2213. return [31, null, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][modMonth - 1];
  2214. }
  2215. }
  2216. // convert a calendar object to a local timestamp (epoch, but with the offset baked in)
  2217. function objToLocalTS(obj) {
  2218. var d = Date.UTC(obj.year, obj.month - 1, obj.day, obj.hour, obj.minute, obj.second, obj.millisecond);
  2219. // for legacy reasons, years between 0 and 99 are interpreted as 19XX; revert that
  2220. if (obj.year < 100 && obj.year >= 0) {
  2221. d = new Date(d);
  2222. // set the month and day again, this is necessary because year 2000 is a leap year, but year 100 is not
  2223. // so if obj.year is in 99, but obj.day makes it roll over into year 100,
  2224. // the calculations done by Date.UTC are using year 2000 - which is incorrect
  2225. d.setUTCFullYear(obj.year, obj.month - 1, obj.day);
  2226. }
  2227. return +d;
  2228. }
  2229. // adapted from moment.js: https://github.com/moment/moment/blob/000ac1800e620f770f4eb31b5ae908f6167b0ab2/src/lib/units/week-calendar-utils.js
  2230. function firstWeekOffset(year, minDaysInFirstWeek, startOfWeek) {
  2231. var fwdlw = isoWeekdayToLocal(dayOfWeek(year, 1, minDaysInFirstWeek), startOfWeek);
  2232. return -fwdlw + minDaysInFirstWeek - 1;
  2233. }
  2234. function weeksInWeekYear(weekYear, minDaysInFirstWeek, startOfWeek) {
  2235. if (minDaysInFirstWeek === void 0) {
  2236. minDaysInFirstWeek = 4;
  2237. }
  2238. if (startOfWeek === void 0) {
  2239. startOfWeek = 1;
  2240. }
  2241. var weekOffset = firstWeekOffset(weekYear, minDaysInFirstWeek, startOfWeek);
  2242. var weekOffsetNext = firstWeekOffset(weekYear + 1, minDaysInFirstWeek, startOfWeek);
  2243. return (daysInYear(weekYear) - weekOffset + weekOffsetNext) / 7;
  2244. }
  2245. function untruncateYear(year) {
  2246. if (year > 99) {
  2247. return year;
  2248. } else return year > Settings.twoDigitCutoffYear ? 1900 + year : 2000 + year;
  2249. }
  2250. // PARSING
  2251. function parseZoneInfo(ts, offsetFormat, locale, timeZone) {
  2252. if (timeZone === void 0) {
  2253. timeZone = null;
  2254. }
  2255. var date = new Date(ts),
  2256. intlOpts = {
  2257. hourCycle: "h23",
  2258. year: "numeric",
  2259. month: "2-digit",
  2260. day: "2-digit",
  2261. hour: "2-digit",
  2262. minute: "2-digit"
  2263. };
  2264. if (timeZone) {
  2265. intlOpts.timeZone = timeZone;
  2266. }
  2267. var modified = _extends({
  2268. timeZoneName: offsetFormat
  2269. }, intlOpts);
  2270. var parsed = new Intl.DateTimeFormat(locale, modified).formatToParts(date).find(function (m) {
  2271. return m.type.toLowerCase() === "timezonename";
  2272. });
  2273. return parsed ? parsed.value : null;
  2274. }
  2275. // signedOffset('-5', '30') -> -330
  2276. function signedOffset(offHourStr, offMinuteStr) {
  2277. var offHour = parseInt(offHourStr, 10);
  2278. // don't || this because we want to preserve -0
  2279. if (Number.isNaN(offHour)) {
  2280. offHour = 0;
  2281. }
  2282. var offMin = parseInt(offMinuteStr, 10) || 0,
  2283. offMinSigned = offHour < 0 || Object.is(offHour, -0) ? -offMin : offMin;
  2284. return offHour * 60 + offMinSigned;
  2285. }
  2286. // COERCION
  2287. function asNumber(value) {
  2288. var numericValue = Number(value);
  2289. if (typeof value === "boolean" || value === "" || Number.isNaN(numericValue)) throw new InvalidArgumentError("Invalid unit value " + value);
  2290. return numericValue;
  2291. }
  2292. function normalizeObject(obj, normalizer) {
  2293. var normalized = {};
  2294. for (var u in obj) {
  2295. if (hasOwnProperty(obj, u)) {
  2296. var v = obj[u];
  2297. if (v === undefined || v === null) continue;
  2298. normalized[normalizer(u)] = asNumber(v);
  2299. }
  2300. }
  2301. return normalized;
  2302. }
  2303. /**
  2304. * Returns the offset's value as a string
  2305. * @param {number} ts - Epoch milliseconds for which to get the offset
  2306. * @param {string} format - What style of offset to return.
  2307. * Accepts 'narrow', 'short', or 'techie'. Returning '+6', '+06:00', or '+0600' respectively
  2308. * @return {string}
  2309. */
  2310. function formatOffset(offset, format) {
  2311. var hours = Math.trunc(Math.abs(offset / 60)),
  2312. minutes = Math.trunc(Math.abs(offset % 60)),
  2313. sign = offset >= 0 ? "+" : "-";
  2314. switch (format) {
  2315. case "short":
  2316. return "" + sign + padStart(hours, 2) + ":" + padStart(minutes, 2);
  2317. case "narrow":
  2318. return "" + sign + hours + (minutes > 0 ? ":" + minutes : "");
  2319. case "techie":
  2320. return "" + sign + padStart(hours, 2) + padStart(minutes, 2);
  2321. default:
  2322. throw new RangeError("Value format " + format + " is out of range for property format");
  2323. }
  2324. }
  2325. function timeObject(obj) {
  2326. return pick(obj, ["hour", "minute", "second", "millisecond"]);
  2327. }
  2328. /**
  2329. * @private
  2330. */
  2331. var monthsLong = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
  2332. var monthsShort = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
  2333. var monthsNarrow = ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"];
  2334. function months(length) {
  2335. switch (length) {
  2336. case "narrow":
  2337. return [].concat(monthsNarrow);
  2338. case "short":
  2339. return [].concat(monthsShort);
  2340. case "long":
  2341. return [].concat(monthsLong);
  2342. case "numeric":
  2343. return ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"];
  2344. case "2-digit":
  2345. return ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"];
  2346. default:
  2347. return null;
  2348. }
  2349. }
  2350. var weekdaysLong = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
  2351. var weekdaysShort = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
  2352. var weekdaysNarrow = ["M", "T", "W", "T", "F", "S", "S"];
  2353. function weekdays(length) {
  2354. switch (length) {
  2355. case "narrow":
  2356. return [].concat(weekdaysNarrow);
  2357. case "short":
  2358. return [].concat(weekdaysShort);
  2359. case "long":
  2360. return [].concat(weekdaysLong);
  2361. case "numeric":
  2362. return ["1", "2", "3", "4", "5", "6", "7"];
  2363. default:
  2364. return null;
  2365. }
  2366. }
  2367. var meridiems = ["AM", "PM"];
  2368. var erasLong = ["Before Christ", "Anno Domini"];
  2369. var erasShort = ["BC", "AD"];
  2370. var erasNarrow = ["B", "A"];
  2371. function eras(length) {
  2372. switch (length) {
  2373. case "narrow":
  2374. return [].concat(erasNarrow);
  2375. case "short":
  2376. return [].concat(erasShort);
  2377. case "long":
  2378. return [].concat(erasLong);
  2379. default:
  2380. return null;
  2381. }
  2382. }
  2383. function meridiemForDateTime(dt) {
  2384. return meridiems[dt.hour < 12 ? 0 : 1];
  2385. }
  2386. function weekdayForDateTime(dt, length) {
  2387. return weekdays(length)[dt.weekday - 1];
  2388. }
  2389. function monthForDateTime(dt, length) {
  2390. return months(length)[dt.month - 1];
  2391. }
  2392. function eraForDateTime(dt, length) {
  2393. return eras(length)[dt.year < 0 ? 0 : 1];
  2394. }
  2395. function formatRelativeTime(unit, count, numeric, narrow) {
  2396. if (numeric === void 0) {
  2397. numeric = "always";
  2398. }
  2399. if (narrow === void 0) {
  2400. narrow = false;
  2401. }
  2402. var units = {
  2403. years: ["year", "yr."],
  2404. quarters: ["quarter", "qtr."],
  2405. months: ["month", "mo."],
  2406. weeks: ["week", "wk."],
  2407. days: ["day", "day", "days"],
  2408. hours: ["hour", "hr."],
  2409. minutes: ["minute", "min."],
  2410. seconds: ["second", "sec."]
  2411. };
  2412. var lastable = ["hours", "minutes", "seconds"].indexOf(unit) === -1;
  2413. if (numeric === "auto" && lastable) {
  2414. var isDay = unit === "days";
  2415. switch (count) {
  2416. case 1:
  2417. return isDay ? "tomorrow" : "next " + units[unit][0];
  2418. case -1:
  2419. return isDay ? "yesterday" : "last " + units[unit][0];
  2420. case 0:
  2421. return isDay ? "today" : "this " + units[unit][0];
  2422. }
  2423. }
  2424. var isInPast = Object.is(count, -0) || count < 0,
  2425. fmtValue = Math.abs(count),
  2426. singular = fmtValue === 1,
  2427. lilUnits = units[unit],
  2428. fmtUnit = narrow ? singular ? lilUnits[1] : lilUnits[2] || lilUnits[1] : singular ? units[unit][0] : unit;
  2429. return isInPast ? fmtValue + " " + fmtUnit + " ago" : "in " + fmtValue + " " + fmtUnit;
  2430. }
  2431. function stringifyTokens(splits, tokenToString) {
  2432. var s = "";
  2433. for (var _iterator = _createForOfIteratorHelperLoose(splits), _step; !(_step = _iterator()).done;) {
  2434. var token = _step.value;
  2435. if (token.literal) {
  2436. s += token.val;
  2437. } else {
  2438. s += tokenToString(token.val);
  2439. }
  2440. }
  2441. return s;
  2442. }
  2443. var _macroTokenToFormatOpts = {
  2444. D: DATE_SHORT,
  2445. DD: DATE_MED,
  2446. DDD: DATE_FULL,
  2447. DDDD: DATE_HUGE,
  2448. t: TIME_SIMPLE,
  2449. tt: TIME_WITH_SECONDS,
  2450. ttt: TIME_WITH_SHORT_OFFSET,
  2451. tttt: TIME_WITH_LONG_OFFSET,
  2452. T: TIME_24_SIMPLE,
  2453. TT: TIME_24_WITH_SECONDS,
  2454. TTT: TIME_24_WITH_SHORT_OFFSET,
  2455. TTTT: TIME_24_WITH_LONG_OFFSET,
  2456. f: DATETIME_SHORT,
  2457. ff: DATETIME_MED,
  2458. fff: DATETIME_FULL,
  2459. ffff: DATETIME_HUGE,
  2460. F: DATETIME_SHORT_WITH_SECONDS,
  2461. FF: DATETIME_MED_WITH_SECONDS,
  2462. FFF: DATETIME_FULL_WITH_SECONDS,
  2463. FFFF: DATETIME_HUGE_WITH_SECONDS
  2464. };
  2465. /**
  2466. * @private
  2467. */
  2468. var Formatter = /*#__PURE__*/function () {
  2469. Formatter.create = function create(locale, opts) {
  2470. if (opts === void 0) {
  2471. opts = {};
  2472. }
  2473. return new Formatter(locale, opts);
  2474. };
  2475. Formatter.parseFormat = function parseFormat(fmt) {
  2476. // white-space is always considered a literal in user-provided formats
  2477. // the " " token has a special meaning (see unitForToken)
  2478. var current = null,
  2479. currentFull = "",
  2480. bracketed = false;
  2481. var splits = [];
  2482. for (var i = 0; i < fmt.length; i++) {
  2483. var c = fmt.charAt(i);
  2484. if (c === "'") {
  2485. if (currentFull.length > 0) {
  2486. splits.push({
  2487. literal: bracketed || /^\s+$/.test(currentFull),
  2488. val: currentFull
  2489. });
  2490. }
  2491. current = null;
  2492. currentFull = "";
  2493. bracketed = !bracketed;
  2494. } else if (bracketed) {
  2495. currentFull += c;
  2496. } else if (c === current) {
  2497. currentFull += c;
  2498. } else {
  2499. if (currentFull.length > 0) {
  2500. splits.push({
  2501. literal: /^\s+$/.test(currentFull),
  2502. val: currentFull
  2503. });
  2504. }
  2505. currentFull = c;
  2506. current = c;
  2507. }
  2508. }
  2509. if (currentFull.length > 0) {
  2510. splits.push({
  2511. literal: bracketed || /^\s+$/.test(currentFull),
  2512. val: currentFull
  2513. });
  2514. }
  2515. return splits;
  2516. };
  2517. Formatter.macroTokenToFormatOpts = function macroTokenToFormatOpts(token) {
  2518. return _macroTokenToFormatOpts[token];
  2519. };
  2520. function Formatter(locale, formatOpts) {
  2521. this.opts = formatOpts;
  2522. this.loc = locale;
  2523. this.systemLoc = null;
  2524. }
  2525. var _proto = Formatter.prototype;
  2526. _proto.formatWithSystemDefault = function formatWithSystemDefault(dt, opts) {
  2527. if (this.systemLoc === null) {
  2528. this.systemLoc = this.loc.redefaultToSystem();
  2529. }
  2530. var df = this.systemLoc.dtFormatter(dt, _extends({}, this.opts, opts));
  2531. return df.format();
  2532. };
  2533. _proto.dtFormatter = function dtFormatter(dt, opts) {
  2534. if (opts === void 0) {
  2535. opts = {};
  2536. }
  2537. return this.loc.dtFormatter(dt, _extends({}, this.opts, opts));
  2538. };
  2539. _proto.formatDateTime = function formatDateTime(dt, opts) {
  2540. return this.dtFormatter(dt, opts).format();
  2541. };
  2542. _proto.formatDateTimeParts = function formatDateTimeParts(dt, opts) {
  2543. return this.dtFormatter(dt, opts).formatToParts();
  2544. };
  2545. _proto.formatInterval = function formatInterval(interval, opts) {
  2546. var df = this.dtFormatter(interval.start, opts);
  2547. return df.dtf.formatRange(interval.start.toJSDate(), interval.end.toJSDate());
  2548. };
  2549. _proto.resolvedOptions = function resolvedOptions(dt, opts) {
  2550. return this.dtFormatter(dt, opts).resolvedOptions();
  2551. };
  2552. _proto.num = function num(n, p) {
  2553. if (p === void 0) {
  2554. p = 0;
  2555. }
  2556. // we get some perf out of doing this here, annoyingly
  2557. if (this.opts.forceSimple) {
  2558. return padStart(n, p);
  2559. }
  2560. var opts = _extends({}, this.opts);
  2561. if (p > 0) {
  2562. opts.padTo = p;
  2563. }
  2564. return this.loc.numberFormatter(opts).format(n);
  2565. };
  2566. _proto.formatDateTimeFromString = function formatDateTimeFromString(dt, fmt) {
  2567. var _this = this;
  2568. var knownEnglish = this.loc.listingMode() === "en",
  2569. useDateTimeFormatter = this.loc.outputCalendar && this.loc.outputCalendar !== "gregory",
  2570. string = function string(opts, extract) {
  2571. return _this.loc.extract(dt, opts, extract);
  2572. },
  2573. formatOffset = function formatOffset(opts) {
  2574. if (dt.isOffsetFixed && dt.offset === 0 && opts.allowZ) {
  2575. return "Z";
  2576. }
  2577. return dt.isValid ? dt.zone.formatOffset(dt.ts, opts.format) : "";
  2578. },
  2579. meridiem = function meridiem() {
  2580. return knownEnglish ? meridiemForDateTime(dt) : string({
  2581. hour: "numeric",
  2582. hourCycle: "h12"
  2583. }, "dayperiod");
  2584. },
  2585. month = function month(length, standalone) {
  2586. return knownEnglish ? monthForDateTime(dt, length) : string(standalone ? {
  2587. month: length
  2588. } : {
  2589. month: length,
  2590. day: "numeric"
  2591. }, "month");
  2592. },
  2593. weekday = function weekday(length, standalone) {
  2594. return knownEnglish ? weekdayForDateTime(dt, length) : string(standalone ? {
  2595. weekday: length
  2596. } : {
  2597. weekday: length,
  2598. month: "long",
  2599. day: "numeric"
  2600. }, "weekday");
  2601. },
  2602. maybeMacro = function maybeMacro(token) {
  2603. var formatOpts = Formatter.macroTokenToFormatOpts(token);
  2604. if (formatOpts) {
  2605. return _this.formatWithSystemDefault(dt, formatOpts);
  2606. } else {
  2607. return token;
  2608. }
  2609. },
  2610. era = function era(length) {
  2611. return knownEnglish ? eraForDateTime(dt, length) : string({
  2612. era: length
  2613. }, "era");
  2614. },
  2615. tokenToString = function tokenToString(token) {
  2616. // Where possible: https://cldr.unicode.org/translation/date-time/date-time-symbols
  2617. switch (token) {
  2618. // ms
  2619. case "S":
  2620. return _this.num(dt.millisecond);
  2621. case "u":
  2622. // falls through
  2623. case "SSS":
  2624. return _this.num(dt.millisecond, 3);
  2625. // seconds
  2626. case "s":
  2627. return _this.num(dt.second);
  2628. case "ss":
  2629. return _this.num(dt.second, 2);
  2630. // fractional seconds
  2631. case "uu":
  2632. return _this.num(Math.floor(dt.millisecond / 10), 2);
  2633. case "uuu":
  2634. return _this.num(Math.floor(dt.millisecond / 100));
  2635. // minutes
  2636. case "m":
  2637. return _this.num(dt.minute);
  2638. case "mm":
  2639. return _this.num(dt.minute, 2);
  2640. // hours
  2641. case "h":
  2642. return _this.num(dt.hour % 12 === 0 ? 12 : dt.hour % 12);
  2643. case "hh":
  2644. return _this.num(dt.hour % 12 === 0 ? 12 : dt.hour % 12, 2);
  2645. case "H":
  2646. return _this.num(dt.hour);
  2647. case "HH":
  2648. return _this.num(dt.hour, 2);
  2649. // offset
  2650. case "Z":
  2651. // like +6
  2652. return formatOffset({
  2653. format: "narrow",
  2654. allowZ: _this.opts.allowZ
  2655. });
  2656. case "ZZ":
  2657. // like +06:00
  2658. return formatOffset({
  2659. format: "short",
  2660. allowZ: _this.opts.allowZ
  2661. });
  2662. case "ZZZ":
  2663. // like +0600
  2664. return formatOffset({
  2665. format: "techie",
  2666. allowZ: _this.opts.allowZ
  2667. });
  2668. case "ZZZZ":
  2669. // like EST
  2670. return dt.zone.offsetName(dt.ts, {
  2671. format: "short",
  2672. locale: _this.loc.locale
  2673. });
  2674. case "ZZZZZ":
  2675. // like Eastern Standard Time
  2676. return dt.zone.offsetName(dt.ts, {
  2677. format: "long",
  2678. locale: _this.loc.locale
  2679. });
  2680. // zone
  2681. case "z":
  2682. // like America/New_York
  2683. return dt.zoneName;
  2684. // meridiems
  2685. case "a":
  2686. return meridiem();
  2687. // dates
  2688. case "d":
  2689. return useDateTimeFormatter ? string({
  2690. day: "numeric"
  2691. }, "day") : _this.num(dt.day);
  2692. case "dd":
  2693. return useDateTimeFormatter ? string({
  2694. day: "2-digit"
  2695. }, "day") : _this.num(dt.day, 2);
  2696. // weekdays - standalone
  2697. case "c":
  2698. // like 1
  2699. return _this.num(dt.weekday);
  2700. case "ccc":
  2701. // like 'Tues'
  2702. return weekday("short", true);
  2703. case "cccc":
  2704. // like 'Tuesday'
  2705. return weekday("long", true);
  2706. case "ccccc":
  2707. // like 'T'
  2708. return weekday("narrow", true);
  2709. // weekdays - format
  2710. case "E":
  2711. // like 1
  2712. return _this.num(dt.weekday);
  2713. case "EEE":
  2714. // like 'Tues'
  2715. return weekday("short", false);
  2716. case "EEEE":
  2717. // like 'Tuesday'
  2718. return weekday("long", false);
  2719. case "EEEEE":
  2720. // like 'T'
  2721. return weekday("narrow", false);
  2722. // months - standalone
  2723. case "L":
  2724. // like 1
  2725. return useDateTimeFormatter ? string({
  2726. month: "numeric",
  2727. day: "numeric"
  2728. }, "month") : _this.num(dt.month);
  2729. case "LL":
  2730. // like 01, doesn't seem to work
  2731. return useDateTimeFormatter ? string({
  2732. month: "2-digit",
  2733. day: "numeric"
  2734. }, "month") : _this.num(dt.month, 2);
  2735. case "LLL":
  2736. // like Jan
  2737. return month("short", true);
  2738. case "LLLL":
  2739. // like January
  2740. return month("long", true);
  2741. case "LLLLL":
  2742. // like J
  2743. return month("narrow", true);
  2744. // months - format
  2745. case "M":
  2746. // like 1
  2747. return useDateTimeFormatter ? string({
  2748. month: "numeric"
  2749. }, "month") : _this.num(dt.month);
  2750. case "MM":
  2751. // like 01
  2752. return useDateTimeFormatter ? string({
  2753. month: "2-digit"
  2754. }, "month") : _this.num(dt.month, 2);
  2755. case "MMM":
  2756. // like Jan
  2757. return month("short", false);
  2758. case "MMMM":
  2759. // like January
  2760. return month("long", false);
  2761. case "MMMMM":
  2762. // like J
  2763. return month("narrow", false);
  2764. // years
  2765. case "y":
  2766. // like 2014
  2767. return useDateTimeFormatter ? string({
  2768. year: "numeric"
  2769. }, "year") : _this.num(dt.year);
  2770. case "yy":
  2771. // like 14
  2772. return useDateTimeFormatter ? string({
  2773. year: "2-digit"
  2774. }, "year") : _this.num(dt.year.toString().slice(-2), 2);
  2775. case "yyyy":
  2776. // like 0012
  2777. return useDateTimeFormatter ? string({
  2778. year: "numeric"
  2779. }, "year") : _this.num(dt.year, 4);
  2780. case "yyyyyy":
  2781. // like 000012
  2782. return useDateTimeFormatter ? string({
  2783. year: "numeric"
  2784. }, "year") : _this.num(dt.year, 6);
  2785. // eras
  2786. case "G":
  2787. // like AD
  2788. return era("short");
  2789. case "GG":
  2790. // like Anno Domini
  2791. return era("long");
  2792. case "GGGGG":
  2793. return era("narrow");
  2794. case "kk":
  2795. return _this.num(dt.weekYear.toString().slice(-2), 2);
  2796. case "kkkk":
  2797. return _this.num(dt.weekYear, 4);
  2798. case "W":
  2799. return _this.num(dt.weekNumber);
  2800. case "WW":
  2801. return _this.num(dt.weekNumber, 2);
  2802. case "n":
  2803. return _this.num(dt.localWeekNumber);
  2804. case "nn":
  2805. return _this.num(dt.localWeekNumber, 2);
  2806. case "ii":
  2807. return _this.num(dt.localWeekYear.toString().slice(-2), 2);
  2808. case "iiii":
  2809. return _this.num(dt.localWeekYear, 4);
  2810. case "o":
  2811. return _this.num(dt.ordinal);
  2812. case "ooo":
  2813. return _this.num(dt.ordinal, 3);
  2814. case "q":
  2815. // like 1
  2816. return _this.num(dt.quarter);
  2817. case "qq":
  2818. // like 01
  2819. return _this.num(dt.quarter, 2);
  2820. case "X":
  2821. return _this.num(Math.floor(dt.ts / 1000));
  2822. case "x":
  2823. return _this.num(dt.ts);
  2824. default:
  2825. return maybeMacro(token);
  2826. }
  2827. };
  2828. return stringifyTokens(Formatter.parseFormat(fmt), tokenToString);
  2829. };
  2830. _proto.formatDurationFromString = function formatDurationFromString(dur, fmt) {
  2831. var _this2 = this;
  2832. var tokenToField = function tokenToField(token) {
  2833. switch (token[0]) {
  2834. case "S":
  2835. return "millisecond";
  2836. case "s":
  2837. return "second";
  2838. case "m":
  2839. return "minute";
  2840. case "h":
  2841. return "hour";
  2842. case "d":
  2843. return "day";
  2844. case "w":
  2845. return "week";
  2846. case "M":
  2847. return "month";
  2848. case "y":
  2849. return "year";
  2850. default:
  2851. return null;
  2852. }
  2853. },
  2854. tokenToString = function tokenToString(lildur) {
  2855. return function (token) {
  2856. var mapped = tokenToField(token);
  2857. if (mapped) {
  2858. return _this2.num(lildur.get(mapped), token.length);
  2859. } else {
  2860. return token;
  2861. }
  2862. };
  2863. },
  2864. tokens = Formatter.parseFormat(fmt),
  2865. realTokens = tokens.reduce(function (found, _ref) {
  2866. var literal = _ref.literal,
  2867. val = _ref.val;
  2868. return literal ? found : found.concat(val);
  2869. }, []),
  2870. collapsed = dur.shiftTo.apply(dur, realTokens.map(tokenToField).filter(function (t) {
  2871. return t;
  2872. }));
  2873. return stringifyTokens(tokens, tokenToString(collapsed));
  2874. };
  2875. return Formatter;
  2876. }();
  2877. /*
  2878. * This file handles parsing for well-specified formats. Here's how it works:
  2879. * Two things go into parsing: a regex to match with and an extractor to take apart the groups in the match.
  2880. * An extractor is just a function that takes a regex match array and returns a { year: ..., month: ... } object
  2881. * parse() does the work of executing the regex and applying the extractor. It takes multiple regex/extractor pairs to try in sequence.
  2882. * Extractors can take a "cursor" representing the offset in the match to look at. This makes it easy to combine extractors.
  2883. * combineExtractors() does the work of combining them, keeping track of the cursor through multiple extractions.
  2884. * Some extractions are super dumb and simpleParse and fromStrings help DRY them.
  2885. */
  2886. var ianaRegex = /[A-Za-z_+-]{1,256}(?::?\/[A-Za-z0-9_+-]{1,256}(?:\/[A-Za-z0-9_+-]{1,256})?)?/;
  2887. function combineRegexes() {
  2888. for (var _len = arguments.length, regexes = new Array(_len), _key = 0; _key < _len; _key++) {
  2889. regexes[_key] = arguments[_key];
  2890. }
  2891. var full = regexes.reduce(function (f, r) {
  2892. return f + r.source;
  2893. }, "");
  2894. return RegExp("^" + full + "$");
  2895. }
  2896. function combineExtractors() {
  2897. for (var _len2 = arguments.length, extractors = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  2898. extractors[_key2] = arguments[_key2];
  2899. }
  2900. return function (m) {
  2901. return extractors.reduce(function (_ref, ex) {
  2902. var mergedVals = _ref[0],
  2903. mergedZone = _ref[1],
  2904. cursor = _ref[2];
  2905. var _ex = ex(m, cursor),
  2906. val = _ex[0],
  2907. zone = _ex[1],
  2908. next = _ex[2];
  2909. return [_extends({}, mergedVals, val), zone || mergedZone, next];
  2910. }, [{}, null, 1]).slice(0, 2);
  2911. };
  2912. }
  2913. function parse(s) {
  2914. if (s == null) {
  2915. return [null, null];
  2916. }
  2917. for (var _len3 = arguments.length, patterns = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
  2918. patterns[_key3 - 1] = arguments[_key3];
  2919. }
  2920. for (var _i = 0, _patterns = patterns; _i < _patterns.length; _i++) {
  2921. var _patterns$_i = _patterns[_i],
  2922. regex = _patterns$_i[0],
  2923. extractor = _patterns$_i[1];
  2924. var m = regex.exec(s);
  2925. if (m) {
  2926. return extractor(m);
  2927. }
  2928. }
  2929. return [null, null];
  2930. }
  2931. function simpleParse() {
  2932. for (var _len4 = arguments.length, keys = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
  2933. keys[_key4] = arguments[_key4];
  2934. }
  2935. return function (match, cursor) {
  2936. var ret = {};
  2937. var i;
  2938. for (i = 0; i < keys.length; i++) {
  2939. ret[keys[i]] = parseInteger(match[cursor + i]);
  2940. }
  2941. return [ret, null, cursor + i];
  2942. };
  2943. }
  2944. // ISO and SQL parsing
  2945. var offsetRegex = /(?:(Z)|([+-]\d\d)(?::?(\d\d))?)/;
  2946. var isoExtendedZone = "(?:" + offsetRegex.source + "?(?:\\[(" + ianaRegex.source + ")\\])?)?";
  2947. var isoTimeBaseRegex = /(\d\d)(?::?(\d\d)(?::?(\d\d)(?:[.,](\d{1,30}))?)?)?/;
  2948. var isoTimeRegex = RegExp("" + isoTimeBaseRegex.source + isoExtendedZone);
  2949. var isoTimeExtensionRegex = RegExp("(?:T" + isoTimeRegex.source + ")?");
  2950. var isoYmdRegex = /([+-]\d{6}|\d{4})(?:-?(\d\d)(?:-?(\d\d))?)?/;
  2951. var isoWeekRegex = /(\d{4})-?W(\d\d)(?:-?(\d))?/;
  2952. var isoOrdinalRegex = /(\d{4})-?(\d{3})/;
  2953. var extractISOWeekData = simpleParse("weekYear", "weekNumber", "weekDay");
  2954. var extractISOOrdinalData = simpleParse("year", "ordinal");
  2955. var sqlYmdRegex = /(\d{4})-(\d\d)-(\d\d)/; // dumbed-down version of the ISO one
  2956. var sqlTimeRegex = RegExp(isoTimeBaseRegex.source + " ?(?:" + offsetRegex.source + "|(" + ianaRegex.source + "))?");
  2957. var sqlTimeExtensionRegex = RegExp("(?: " + sqlTimeRegex.source + ")?");
  2958. function int(match, pos, fallback) {
  2959. var m = match[pos];
  2960. return isUndefined(m) ? fallback : parseInteger(m);
  2961. }
  2962. function extractISOYmd(match, cursor) {
  2963. var item = {
  2964. year: int(match, cursor),
  2965. month: int(match, cursor + 1, 1),
  2966. day: int(match, cursor + 2, 1)
  2967. };
  2968. return [item, null, cursor + 3];
  2969. }
  2970. function extractISOTime(match, cursor) {
  2971. var item = {
  2972. hours: int(match, cursor, 0),
  2973. minutes: int(match, cursor + 1, 0),
  2974. seconds: int(match, cursor + 2, 0),
  2975. milliseconds: parseMillis(match[cursor + 3])
  2976. };
  2977. return [item, null, cursor + 4];
  2978. }
  2979. function extractISOOffset(match, cursor) {
  2980. var local = !match[cursor] && !match[cursor + 1],
  2981. fullOffset = signedOffset(match[cursor + 1], match[cursor + 2]),
  2982. zone = local ? null : FixedOffsetZone.instance(fullOffset);
  2983. return [{}, zone, cursor + 3];
  2984. }
  2985. function extractIANAZone(match, cursor) {
  2986. var zone = match[cursor] ? IANAZone.create(match[cursor]) : null;
  2987. return [{}, zone, cursor + 1];
  2988. }
  2989. // ISO time parsing
  2990. var isoTimeOnly = RegExp("^T?" + isoTimeBaseRegex.source + "$");
  2991. // ISO duration parsing
  2992. var isoDuration = /^-?P(?:(?:(-?\d{1,20}(?:\.\d{1,20})?)Y)?(?:(-?\d{1,20}(?:\.\d{1,20})?)M)?(?:(-?\d{1,20}(?:\.\d{1,20})?)W)?(?:(-?\d{1,20}(?:\.\d{1,20})?)D)?(?:T(?:(-?\d{1,20}(?:\.\d{1,20})?)H)?(?:(-?\d{1,20}(?:\.\d{1,20})?)M)?(?:(-?\d{1,20})(?:[.,](-?\d{1,20}))?S)?)?)$/;
  2993. function extractISODuration(match) {
  2994. var s = match[0],
  2995. yearStr = match[1],
  2996. monthStr = match[2],
  2997. weekStr = match[3],
  2998. dayStr = match[4],
  2999. hourStr = match[5],
  3000. minuteStr = match[6],
  3001. secondStr = match[7],
  3002. millisecondsStr = match[8];
  3003. var hasNegativePrefix = s[0] === "-";
  3004. var negativeSeconds = secondStr && secondStr[0] === "-";
  3005. var maybeNegate = function maybeNegate(num, force) {
  3006. if (force === void 0) {
  3007. force = false;
  3008. }
  3009. return num !== undefined && (force || num && hasNegativePrefix) ? -num : num;
  3010. };
  3011. return [{
  3012. years: maybeNegate(parseFloating(yearStr)),
  3013. months: maybeNegate(parseFloating(monthStr)),
  3014. weeks: maybeNegate(parseFloating(weekStr)),
  3015. days: maybeNegate(parseFloating(dayStr)),
  3016. hours: maybeNegate(parseFloating(hourStr)),
  3017. minutes: maybeNegate(parseFloating(minuteStr)),
  3018. seconds: maybeNegate(parseFloating(secondStr), secondStr === "-0"),
  3019. milliseconds: maybeNegate(parseMillis(millisecondsStr), negativeSeconds)
  3020. }];
  3021. }
  3022. // These are a little braindead. EDT *should* tell us that we're in, say, America/New_York
  3023. // and not just that we're in -240 *right now*. But since I don't think these are used that often
  3024. // I'm just going to ignore that
  3025. var obsOffsets = {
  3026. GMT: 0,
  3027. EDT: -4 * 60,
  3028. EST: -5 * 60,
  3029. CDT: -5 * 60,
  3030. CST: -6 * 60,
  3031. MDT: -6 * 60,
  3032. MST: -7 * 60,
  3033. PDT: -7 * 60,
  3034. PST: -8 * 60
  3035. };
  3036. function fromStrings(weekdayStr, yearStr, monthStr, dayStr, hourStr, minuteStr, secondStr) {
  3037. var result = {
  3038. year: yearStr.length === 2 ? untruncateYear(parseInteger(yearStr)) : parseInteger(yearStr),
  3039. month: monthsShort.indexOf(monthStr) + 1,
  3040. day: parseInteger(dayStr),
  3041. hour: parseInteger(hourStr),
  3042. minute: parseInteger(minuteStr)
  3043. };
  3044. if (secondStr) result.second = parseInteger(secondStr);
  3045. if (weekdayStr) {
  3046. result.weekday = weekdayStr.length > 3 ? weekdaysLong.indexOf(weekdayStr) + 1 : weekdaysShort.indexOf(weekdayStr) + 1;
  3047. }
  3048. return result;
  3049. }
  3050. // RFC 2822/5322
  3051. var rfc2822 = /^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),\s)?(\d{1,2})\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(\d{2,4})\s(\d\d):(\d\d)(?::(\d\d))?\s(?:(UT|GMT|[ECMP][SD]T)|([Zz])|(?:([+-]\d\d)(\d\d)))$/;
  3052. function extractRFC2822(match) {
  3053. var weekdayStr = match[1],
  3054. dayStr = match[2],
  3055. monthStr = match[3],
  3056. yearStr = match[4],
  3057. hourStr = match[5],
  3058. minuteStr = match[6],
  3059. secondStr = match[7],
  3060. obsOffset = match[8],
  3061. milOffset = match[9],
  3062. offHourStr = match[10],
  3063. offMinuteStr = match[11],
  3064. result = fromStrings(weekdayStr, yearStr, monthStr, dayStr, hourStr, minuteStr, secondStr);
  3065. var offset;
  3066. if (obsOffset) {
  3067. offset = obsOffsets[obsOffset];
  3068. } else if (milOffset) {
  3069. offset = 0;
  3070. } else {
  3071. offset = signedOffset(offHourStr, offMinuteStr);
  3072. }
  3073. return [result, new FixedOffsetZone(offset)];
  3074. }
  3075. function preprocessRFC2822(s) {
  3076. // Remove comments and folding whitespace and replace multiple-spaces with a single space
  3077. return s.replace(/\([^()]*\)|[\n\t]/g, " ").replace(/(\s\s+)/g, " ").trim();
  3078. }
  3079. // http date
  3080. var rfc1123 = /^(Mon|Tue|Wed|Thu|Fri|Sat|Sun), (\d\d) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (\d{4}) (\d\d):(\d\d):(\d\d) GMT$/,
  3081. rfc850 = /^(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (\d\d)-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-(\d\d) (\d\d):(\d\d):(\d\d) GMT$/,
  3082. ascii = /^(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ( \d|\d\d) (\d\d):(\d\d):(\d\d) (\d{4})$/;
  3083. function extractRFC1123Or850(match) {
  3084. var weekdayStr = match[1],
  3085. dayStr = match[2],
  3086. monthStr = match[3],
  3087. yearStr = match[4],
  3088. hourStr = match[5],
  3089. minuteStr = match[6],
  3090. secondStr = match[7],
  3091. result = fromStrings(weekdayStr, yearStr, monthStr, dayStr, hourStr, minuteStr, secondStr);
  3092. return [result, FixedOffsetZone.utcInstance];
  3093. }
  3094. function extractASCII(match) {
  3095. var weekdayStr = match[1],
  3096. monthStr = match[2],
  3097. dayStr = match[3],
  3098. hourStr = match[4],
  3099. minuteStr = match[5],
  3100. secondStr = match[6],
  3101. yearStr = match[7],
  3102. result = fromStrings(weekdayStr, yearStr, monthStr, dayStr, hourStr, minuteStr, secondStr);
  3103. return [result, FixedOffsetZone.utcInstance];
  3104. }
  3105. var isoYmdWithTimeExtensionRegex = combineRegexes(isoYmdRegex, isoTimeExtensionRegex);
  3106. var isoWeekWithTimeExtensionRegex = combineRegexes(isoWeekRegex, isoTimeExtensionRegex);
  3107. var isoOrdinalWithTimeExtensionRegex = combineRegexes(isoOrdinalRegex, isoTimeExtensionRegex);
  3108. var isoTimeCombinedRegex = combineRegexes(isoTimeRegex);
  3109. var extractISOYmdTimeAndOffset = combineExtractors(extractISOYmd, extractISOTime, extractISOOffset, extractIANAZone);
  3110. var extractISOWeekTimeAndOffset = combineExtractors(extractISOWeekData, extractISOTime, extractISOOffset, extractIANAZone);
  3111. var extractISOOrdinalDateAndTime = combineExtractors(extractISOOrdinalData, extractISOTime, extractISOOffset, extractIANAZone);
  3112. var extractISOTimeAndOffset = combineExtractors(extractISOTime, extractISOOffset, extractIANAZone);
  3113. /*
  3114. * @private
  3115. */
  3116. function parseISODate(s) {
  3117. return parse(s, [isoYmdWithTimeExtensionRegex, extractISOYmdTimeAndOffset], [isoWeekWithTimeExtensionRegex, extractISOWeekTimeAndOffset], [isoOrdinalWithTimeExtensionRegex, extractISOOrdinalDateAndTime], [isoTimeCombinedRegex, extractISOTimeAndOffset]);
  3118. }
  3119. function parseRFC2822Date(s) {
  3120. return parse(preprocessRFC2822(s), [rfc2822, extractRFC2822]);
  3121. }
  3122. function parseHTTPDate(s) {
  3123. return parse(s, [rfc1123, extractRFC1123Or850], [rfc850, extractRFC1123Or850], [ascii, extractASCII]);
  3124. }
  3125. function parseISODuration(s) {
  3126. return parse(s, [isoDuration, extractISODuration]);
  3127. }
  3128. var extractISOTimeOnly = combineExtractors(extractISOTime);
  3129. function parseISOTimeOnly(s) {
  3130. return parse(s, [isoTimeOnly, extractISOTimeOnly]);
  3131. }
  3132. var sqlYmdWithTimeExtensionRegex = combineRegexes(sqlYmdRegex, sqlTimeExtensionRegex);
  3133. var sqlTimeCombinedRegex = combineRegexes(sqlTimeRegex);
  3134. var extractISOTimeOffsetAndIANAZone = combineExtractors(extractISOTime, extractISOOffset, extractIANAZone);
  3135. function parseSQL(s) {
  3136. return parse(s, [sqlYmdWithTimeExtensionRegex, extractISOYmdTimeAndOffset], [sqlTimeCombinedRegex, extractISOTimeOffsetAndIANAZone]);
  3137. }
  3138. var INVALID$2 = "Invalid Duration";
  3139. // unit conversion constants
  3140. var lowOrderMatrix = {
  3141. weeks: {
  3142. days: 7,
  3143. hours: 7 * 24,
  3144. minutes: 7 * 24 * 60,
  3145. seconds: 7 * 24 * 60 * 60,
  3146. milliseconds: 7 * 24 * 60 * 60 * 1000
  3147. },
  3148. days: {
  3149. hours: 24,
  3150. minutes: 24 * 60,
  3151. seconds: 24 * 60 * 60,
  3152. milliseconds: 24 * 60 * 60 * 1000
  3153. },
  3154. hours: {
  3155. minutes: 60,
  3156. seconds: 60 * 60,
  3157. milliseconds: 60 * 60 * 1000
  3158. },
  3159. minutes: {
  3160. seconds: 60,
  3161. milliseconds: 60 * 1000
  3162. },
  3163. seconds: {
  3164. milliseconds: 1000
  3165. }
  3166. },
  3167. casualMatrix = _extends({
  3168. years: {
  3169. quarters: 4,
  3170. months: 12,
  3171. weeks: 52,
  3172. days: 365,
  3173. hours: 365 * 24,
  3174. minutes: 365 * 24 * 60,
  3175. seconds: 365 * 24 * 60 * 60,
  3176. milliseconds: 365 * 24 * 60 * 60 * 1000
  3177. },
  3178. quarters: {
  3179. months: 3,
  3180. weeks: 13,
  3181. days: 91,
  3182. hours: 91 * 24,
  3183. minutes: 91 * 24 * 60,
  3184. seconds: 91 * 24 * 60 * 60,
  3185. milliseconds: 91 * 24 * 60 * 60 * 1000
  3186. },
  3187. months: {
  3188. weeks: 4,
  3189. days: 30,
  3190. hours: 30 * 24,
  3191. minutes: 30 * 24 * 60,
  3192. seconds: 30 * 24 * 60 * 60,
  3193. milliseconds: 30 * 24 * 60 * 60 * 1000
  3194. }
  3195. }, lowOrderMatrix),
  3196. daysInYearAccurate = 146097.0 / 400,
  3197. daysInMonthAccurate = 146097.0 / 4800,
  3198. accurateMatrix = _extends({
  3199. years: {
  3200. quarters: 4,
  3201. months: 12,
  3202. weeks: daysInYearAccurate / 7,
  3203. days: daysInYearAccurate,
  3204. hours: daysInYearAccurate * 24,
  3205. minutes: daysInYearAccurate * 24 * 60,
  3206. seconds: daysInYearAccurate * 24 * 60 * 60,
  3207. milliseconds: daysInYearAccurate * 24 * 60 * 60 * 1000
  3208. },
  3209. quarters: {
  3210. months: 3,
  3211. weeks: daysInYearAccurate / 28,
  3212. days: daysInYearAccurate / 4,
  3213. hours: daysInYearAccurate * 24 / 4,
  3214. minutes: daysInYearAccurate * 24 * 60 / 4,
  3215. seconds: daysInYearAccurate * 24 * 60 * 60 / 4,
  3216. milliseconds: daysInYearAccurate * 24 * 60 * 60 * 1000 / 4
  3217. },
  3218. months: {
  3219. weeks: daysInMonthAccurate / 7,
  3220. days: daysInMonthAccurate,
  3221. hours: daysInMonthAccurate * 24,
  3222. minutes: daysInMonthAccurate * 24 * 60,
  3223. seconds: daysInMonthAccurate * 24 * 60 * 60,
  3224. milliseconds: daysInMonthAccurate * 24 * 60 * 60 * 1000
  3225. }
  3226. }, lowOrderMatrix);
  3227. // units ordered by size
  3228. var orderedUnits$1 = ["years", "quarters", "months", "weeks", "days", "hours", "minutes", "seconds", "milliseconds"];
  3229. var reverseUnits = orderedUnits$1.slice(0).reverse();
  3230. // clone really means "create another instance just like this one, but with these changes"
  3231. function clone$1(dur, alts, clear) {
  3232. if (clear === void 0) {
  3233. clear = false;
  3234. }
  3235. // deep merge for vals
  3236. var conf = {
  3237. values: clear ? alts.values : _extends({}, dur.values, alts.values || {}),
  3238. loc: dur.loc.clone(alts.loc),
  3239. conversionAccuracy: alts.conversionAccuracy || dur.conversionAccuracy,
  3240. matrix: alts.matrix || dur.matrix
  3241. };
  3242. return new Duration(conf);
  3243. }
  3244. function durationToMillis(matrix, vals) {
  3245. var _vals$milliseconds;
  3246. var sum = (_vals$milliseconds = vals.milliseconds) != null ? _vals$milliseconds : 0;
  3247. for (var _iterator = _createForOfIteratorHelperLoose(reverseUnits.slice(1)), _step; !(_step = _iterator()).done;) {
  3248. var unit = _step.value;
  3249. if (vals[unit]) {
  3250. sum += vals[unit] * matrix[unit]["milliseconds"];
  3251. }
  3252. }
  3253. return sum;
  3254. }
  3255. // NB: mutates parameters
  3256. function normalizeValues(matrix, vals) {
  3257. // the logic below assumes the overall value of the duration is positive
  3258. // if this is not the case, factor is used to make it so
  3259. var factor = durationToMillis(matrix, vals) < 0 ? -1 : 1;
  3260. orderedUnits$1.reduceRight(function (previous, current) {
  3261. if (!isUndefined(vals[current])) {
  3262. if (previous) {
  3263. var previousVal = vals[previous] * factor;
  3264. var conv = matrix[current][previous];
  3265. // if (previousVal < 0):
  3266. // lower order unit is negative (e.g. { years: 2, days: -2 })
  3267. // normalize this by reducing the higher order unit by the appropriate amount
  3268. // and increasing the lower order unit
  3269. // this can never make the higher order unit negative, because this function only operates
  3270. // on positive durations, so the amount of time represented by the lower order unit cannot
  3271. // be larger than the higher order unit
  3272. // else:
  3273. // lower order unit is positive (e.g. { years: 2, days: 450 } or { years: -2, days: 450 })
  3274. // in this case we attempt to convert as much as possible from the lower order unit into
  3275. // the higher order one
  3276. //
  3277. // Math.floor takes care of both of these cases, rounding away from 0
  3278. // if previousVal < 0 it makes the absolute value larger
  3279. // if previousVal >= it makes the absolute value smaller
  3280. var rollUp = Math.floor(previousVal / conv);
  3281. vals[current] += rollUp * factor;
  3282. vals[previous] -= rollUp * conv * factor;
  3283. }
  3284. return current;
  3285. } else {
  3286. return previous;
  3287. }
  3288. }, null);
  3289. // try to convert any decimals into smaller units if possible
  3290. // for example for { years: 2.5, days: 0, seconds: 0 } we want to get { years: 2, days: 182, hours: 12 }
  3291. orderedUnits$1.reduce(function (previous, current) {
  3292. if (!isUndefined(vals[current])) {
  3293. if (previous) {
  3294. var fraction = vals[previous] % 1;
  3295. vals[previous] -= fraction;
  3296. vals[current] += fraction * matrix[previous][current];
  3297. }
  3298. return current;
  3299. } else {
  3300. return previous;
  3301. }
  3302. }, null);
  3303. }
  3304. // Remove all properties with a value of 0 from an object
  3305. function removeZeroes(vals) {
  3306. var newVals = {};
  3307. for (var _i = 0, _Object$entries = Object.entries(vals); _i < _Object$entries.length; _i++) {
  3308. var _Object$entries$_i = _Object$entries[_i],
  3309. key = _Object$entries$_i[0],
  3310. value = _Object$entries$_i[1];
  3311. if (value !== 0) {
  3312. newVals[key] = value;
  3313. }
  3314. }
  3315. return newVals;
  3316. }
  3317. /**
  3318. * A Duration object represents a period of time, like "2 months" or "1 day, 1 hour". Conceptually, it's just a map of units to their quantities, accompanied by some additional configuration and methods for creating, parsing, interrogating, transforming, and formatting them. They can be used on their own or in conjunction with other Luxon types; for example, you can use {@link DateTime#plus} to add a Duration object to a DateTime, producing another DateTime.
  3319. *
  3320. * Here is a brief overview of commonly used methods and getters in Duration:
  3321. *
  3322. * * **Creation** To create a Duration, use {@link Duration.fromMillis}, {@link Duration.fromObject}, or {@link Duration.fromISO}.
  3323. * * **Unit values** See the {@link Duration#years}, {@link Duration#months}, {@link Duration#weeks}, {@link Duration#days}, {@link Duration#hours}, {@link Duration#minutes}, {@link Duration#seconds}, {@link Duration#milliseconds} accessors.
  3324. * * **Configuration** See {@link Duration#locale} and {@link Duration#numberingSystem} accessors.
  3325. * * **Transformation** To create new Durations out of old ones use {@link Duration#plus}, {@link Duration#minus}, {@link Duration#normalize}, {@link Duration#set}, {@link Duration#reconfigure}, {@link Duration#shiftTo}, and {@link Duration#negate}.
  3326. * * **Output** To convert the Duration into other representations, see {@link Duration#as}, {@link Duration#toISO}, {@link Duration#toFormat}, and {@link Duration#toJSON}
  3327. *
  3328. * There's are more methods documented below. In addition, for more information on subtler topics like internationalization and validity, see the external documentation.
  3329. */
  3330. var Duration = /*#__PURE__*/function (_Symbol$for) {
  3331. /**
  3332. * @private
  3333. */
  3334. function Duration(config) {
  3335. var accurate = config.conversionAccuracy === "longterm" || false;
  3336. var matrix = accurate ? accurateMatrix : casualMatrix;
  3337. if (config.matrix) {
  3338. matrix = config.matrix;
  3339. }
  3340. /**
  3341. * @access private
  3342. */
  3343. this.values = config.values;
  3344. /**
  3345. * @access private
  3346. */
  3347. this.loc = config.loc || Locale.create();
  3348. /**
  3349. * @access private
  3350. */
  3351. this.conversionAccuracy = accurate ? "longterm" : "casual";
  3352. /**
  3353. * @access private
  3354. */
  3355. this.invalid = config.invalid || null;
  3356. /**
  3357. * @access private
  3358. */
  3359. this.matrix = matrix;
  3360. /**
  3361. * @access private
  3362. */
  3363. this.isLuxonDuration = true;
  3364. }
  3365. /**
  3366. * Create Duration from a number of milliseconds.
  3367. * @param {number} count of milliseconds
  3368. * @param {Object} opts - options for parsing
  3369. * @param {string} [opts.locale='en-US'] - the locale to use
  3370. * @param {string} opts.numberingSystem - the numbering system to use
  3371. * @param {string} [opts.conversionAccuracy='casual'] - the conversion system to use
  3372. * @return {Duration}
  3373. */
  3374. Duration.fromMillis = function fromMillis(count, opts) {
  3375. return Duration.fromObject({
  3376. milliseconds: count
  3377. }, opts);
  3378. }
  3379. /**
  3380. * Create a Duration from a JavaScript object with keys like 'years' and 'hours'.
  3381. * If this object is empty then a zero milliseconds duration is returned.
  3382. * @param {Object} obj - the object to create the DateTime from
  3383. * @param {number} obj.years
  3384. * @param {number} obj.quarters
  3385. * @param {number} obj.months
  3386. * @param {number} obj.weeks
  3387. * @param {number} obj.days
  3388. * @param {number} obj.hours
  3389. * @param {number} obj.minutes
  3390. * @param {number} obj.seconds
  3391. * @param {number} obj.milliseconds
  3392. * @param {Object} [opts=[]] - options for creating this Duration
  3393. * @param {string} [opts.locale='en-US'] - the locale to use
  3394. * @param {string} opts.numberingSystem - the numbering system to use
  3395. * @param {string} [opts.conversionAccuracy='casual'] - the preset conversion system to use
  3396. * @param {string} [opts.matrix=Object] - the custom conversion system to use
  3397. * @return {Duration}
  3398. */;
  3399. Duration.fromObject = function fromObject(obj, opts) {
  3400. if (opts === void 0) {
  3401. opts = {};
  3402. }
  3403. if (obj == null || typeof obj !== "object") {
  3404. throw new InvalidArgumentError("Duration.fromObject: argument expected to be an object, got " + (obj === null ? "null" : typeof obj));
  3405. }
  3406. return new Duration({
  3407. values: normalizeObject(obj, Duration.normalizeUnit),
  3408. loc: Locale.fromObject(opts),
  3409. conversionAccuracy: opts.conversionAccuracy,
  3410. matrix: opts.matrix
  3411. });
  3412. }
  3413. /**
  3414. * Create a Duration from DurationLike.
  3415. *
  3416. * @param {Object | number | Duration} durationLike
  3417. * One of:
  3418. * - object with keys like 'years' and 'hours'.
  3419. * - number representing milliseconds
  3420. * - Duration instance
  3421. * @return {Duration}
  3422. */;
  3423. Duration.fromDurationLike = function fromDurationLike(durationLike) {
  3424. if (isNumber(durationLike)) {
  3425. return Duration.fromMillis(durationLike);
  3426. } else if (Duration.isDuration(durationLike)) {
  3427. return durationLike;
  3428. } else if (typeof durationLike === "object") {
  3429. return Duration.fromObject(durationLike);
  3430. } else {
  3431. throw new InvalidArgumentError("Unknown duration argument " + durationLike + " of type " + typeof durationLike);
  3432. }
  3433. }
  3434. /**
  3435. * Create a Duration from an ISO 8601 duration string.
  3436. * @param {string} text - text to parse
  3437. * @param {Object} opts - options for parsing
  3438. * @param {string} [opts.locale='en-US'] - the locale to use
  3439. * @param {string} opts.numberingSystem - the numbering system to use
  3440. * @param {string} [opts.conversionAccuracy='casual'] - the preset conversion system to use
  3441. * @param {string} [opts.matrix=Object] - the preset conversion system to use
  3442. * @see https://en.wikipedia.org/wiki/ISO_8601#Durations
  3443. * @example Duration.fromISO('P3Y6M1W4DT12H30M5S').toObject() //=> { years: 3, months: 6, weeks: 1, days: 4, hours: 12, minutes: 30, seconds: 5 }
  3444. * @example Duration.fromISO('PT23H').toObject() //=> { hours: 23 }
  3445. * @example Duration.fromISO('P5Y3M').toObject() //=> { years: 5, months: 3 }
  3446. * @return {Duration}
  3447. */;
  3448. Duration.fromISO = function fromISO(text, opts) {
  3449. var _parseISODuration = parseISODuration(text),
  3450. parsed = _parseISODuration[0];
  3451. if (parsed) {
  3452. return Duration.fromObject(parsed, opts);
  3453. } else {
  3454. return Duration.invalid("unparsable", "the input \"" + text + "\" can't be parsed as ISO 8601");
  3455. }
  3456. }
  3457. /**
  3458. * Create a Duration from an ISO 8601 time string.
  3459. * @param {string} text - text to parse
  3460. * @param {Object} opts - options for parsing
  3461. * @param {string} [opts.locale='en-US'] - the locale to use
  3462. * @param {string} opts.numberingSystem - the numbering system to use
  3463. * @param {string} [opts.conversionAccuracy='casual'] - the preset conversion system to use
  3464. * @param {string} [opts.matrix=Object] - the conversion system to use
  3465. * @see https://en.wikipedia.org/wiki/ISO_8601#Times
  3466. * @example Duration.fromISOTime('11:22:33.444').toObject() //=> { hours: 11, minutes: 22, seconds: 33, milliseconds: 444 }
  3467. * @example Duration.fromISOTime('11:00').toObject() //=> { hours: 11, minutes: 0, seconds: 0 }
  3468. * @example Duration.fromISOTime('T11:00').toObject() //=> { hours: 11, minutes: 0, seconds: 0 }
  3469. * @example Duration.fromISOTime('1100').toObject() //=> { hours: 11, minutes: 0, seconds: 0 }
  3470. * @example Duration.fromISOTime('T1100').toObject() //=> { hours: 11, minutes: 0, seconds: 0 }
  3471. * @return {Duration}
  3472. */;
  3473. Duration.fromISOTime = function fromISOTime(text, opts) {
  3474. var _parseISOTimeOnly = parseISOTimeOnly(text),
  3475. parsed = _parseISOTimeOnly[0];
  3476. if (parsed) {
  3477. return Duration.fromObject(parsed, opts);
  3478. } else {
  3479. return Duration.invalid("unparsable", "the input \"" + text + "\" can't be parsed as ISO 8601");
  3480. }
  3481. }
  3482. /**
  3483. * Create an invalid Duration.
  3484. * @param {string} reason - simple string of why this datetime is invalid. Should not contain parameters or anything else data-dependent
  3485. * @param {string} [explanation=null] - longer explanation, may include parameters and other useful debugging information
  3486. * @return {Duration}
  3487. */;
  3488. Duration.invalid = function invalid(reason, explanation) {
  3489. if (explanation === void 0) {
  3490. explanation = null;
  3491. }
  3492. if (!reason) {
  3493. throw new InvalidArgumentError("need to specify a reason the Duration is invalid");
  3494. }
  3495. var invalid = reason instanceof Invalid ? reason : new Invalid(reason, explanation);
  3496. if (Settings.throwOnInvalid) {
  3497. throw new InvalidDurationError(invalid);
  3498. } else {
  3499. return new Duration({
  3500. invalid: invalid
  3501. });
  3502. }
  3503. }
  3504. /**
  3505. * @private
  3506. */;
  3507. Duration.normalizeUnit = function normalizeUnit(unit) {
  3508. var normalized = {
  3509. year: "years",
  3510. years: "years",
  3511. quarter: "quarters",
  3512. quarters: "quarters",
  3513. month: "months",
  3514. months: "months",
  3515. week: "weeks",
  3516. weeks: "weeks",
  3517. day: "days",
  3518. days: "days",
  3519. hour: "hours",
  3520. hours: "hours",
  3521. minute: "minutes",
  3522. minutes: "minutes",
  3523. second: "seconds",
  3524. seconds: "seconds",
  3525. millisecond: "milliseconds",
  3526. milliseconds: "milliseconds"
  3527. }[unit ? unit.toLowerCase() : unit];
  3528. if (!normalized) throw new InvalidUnitError(unit);
  3529. return normalized;
  3530. }
  3531. /**
  3532. * Check if an object is a Duration. Works across context boundaries
  3533. * @param {object} o
  3534. * @return {boolean}
  3535. */;
  3536. Duration.isDuration = function isDuration(o) {
  3537. return o && o.isLuxonDuration || false;
  3538. }
  3539. /**
  3540. * Get the locale of a Duration, such 'en-GB'
  3541. * @type {string}
  3542. */;
  3543. var _proto = Duration.prototype;
  3544. /**
  3545. * Returns a string representation of this Duration formatted according to the specified format string. You may use these tokens:
  3546. * * `S` for milliseconds
  3547. * * `s` for seconds
  3548. * * `m` for minutes
  3549. * * `h` for hours
  3550. * * `d` for days
  3551. * * `w` for weeks
  3552. * * `M` for months
  3553. * * `y` for years
  3554. * Notes:
  3555. * * Add padding by repeating the token, e.g. "yy" pads the years to two digits, "hhhh" pads the hours out to four digits
  3556. * * Tokens can be escaped by wrapping with single quotes.
  3557. * * The duration will be converted to the set of units in the format string using {@link Duration#shiftTo} and the Durations's conversion accuracy setting.
  3558. * @param {string} fmt - the format string
  3559. * @param {Object} opts - options
  3560. * @param {boolean} [opts.floor=true] - floor numerical values
  3561. * @example Duration.fromObject({ years: 1, days: 6, seconds: 2 }).toFormat("y d s") //=> "1 6 2"
  3562. * @example Duration.fromObject({ years: 1, days: 6, seconds: 2 }).toFormat("yy dd sss") //=> "01 06 002"
  3563. * @example Duration.fromObject({ years: 1, days: 6, seconds: 2 }).toFormat("M S") //=> "12 518402000"
  3564. * @return {string}
  3565. */
  3566. _proto.toFormat = function toFormat(fmt, opts) {
  3567. if (opts === void 0) {
  3568. opts = {};
  3569. }
  3570. // reverse-compat since 1.2; we always round down now, never up, and we do it by default
  3571. var fmtOpts = _extends({}, opts, {
  3572. floor: opts.round !== false && opts.floor !== false
  3573. });
  3574. return this.isValid ? Formatter.create(this.loc, fmtOpts).formatDurationFromString(this, fmt) : INVALID$2;
  3575. }
  3576. /**
  3577. * Returns a string representation of a Duration with all units included.
  3578. * To modify its behavior, use `listStyle` and any Intl.NumberFormat option, though `unitDisplay` is especially relevant.
  3579. * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options
  3580. * @param {Object} opts - Formatting options. Accepts the same keys as the options parameter of the native `Intl.NumberFormat` constructor, as well as `listStyle`.
  3581. * @param {string} [opts.listStyle='narrow'] - How to format the merged list. Corresponds to the `style` property of the options parameter of the native `Intl.ListFormat` constructor.
  3582. * @example
  3583. * ```js
  3584. * var dur = Duration.fromObject({ days: 1, hours: 5, minutes: 6 })
  3585. * dur.toHuman() //=> '1 day, 5 hours, 6 minutes'
  3586. * dur.toHuman({ listStyle: "long" }) //=> '1 day, 5 hours, and 6 minutes'
  3587. * dur.toHuman({ unitDisplay: "short" }) //=> '1 day, 5 hr, 6 min'
  3588. * ```
  3589. */;
  3590. _proto.toHuman = function toHuman(opts) {
  3591. var _this = this;
  3592. if (opts === void 0) {
  3593. opts = {};
  3594. }
  3595. if (!this.isValid) return INVALID$2;
  3596. var l = orderedUnits$1.map(function (unit) {
  3597. var val = _this.values[unit];
  3598. if (isUndefined(val)) {
  3599. return null;
  3600. }
  3601. return _this.loc.numberFormatter(_extends({
  3602. style: "unit",
  3603. unitDisplay: "long"
  3604. }, opts, {
  3605. unit: unit.slice(0, -1)
  3606. })).format(val);
  3607. }).filter(function (n) {
  3608. return n;
  3609. });
  3610. return this.loc.listFormatter(_extends({
  3611. type: "conjunction",
  3612. style: opts.listStyle || "narrow"
  3613. }, opts)).format(l);
  3614. }
  3615. /**
  3616. * Returns a JavaScript object with this Duration's values.
  3617. * @example Duration.fromObject({ years: 1, days: 6, seconds: 2 }).toObject() //=> { years: 1, days: 6, seconds: 2 }
  3618. * @return {Object}
  3619. */;
  3620. _proto.toObject = function toObject() {
  3621. if (!this.isValid) return {};
  3622. return _extends({}, this.values);
  3623. }
  3624. /**
  3625. * Returns an ISO 8601-compliant string representation of this Duration.
  3626. * @see https://en.wikipedia.org/wiki/ISO_8601#Durations
  3627. * @example Duration.fromObject({ years: 3, seconds: 45 }).toISO() //=> 'P3YT45S'
  3628. * @example Duration.fromObject({ months: 4, seconds: 45 }).toISO() //=> 'P4MT45S'
  3629. * @example Duration.fromObject({ months: 5 }).toISO() //=> 'P5M'
  3630. * @example Duration.fromObject({ minutes: 5 }).toISO() //=> 'PT5M'
  3631. * @example Duration.fromObject({ milliseconds: 6 }).toISO() //=> 'PT0.006S'
  3632. * @return {string}
  3633. */;
  3634. _proto.toISO = function toISO() {
  3635. // we could use the formatter, but this is an easier way to get the minimum string
  3636. if (!this.isValid) return null;
  3637. var s = "P";
  3638. if (this.years !== 0) s += this.years + "Y";
  3639. if (this.months !== 0 || this.quarters !== 0) s += this.months + this.quarters * 3 + "M";
  3640. if (this.weeks !== 0) s += this.weeks + "W";
  3641. if (this.days !== 0) s += this.days + "D";
  3642. if (this.hours !== 0 || this.minutes !== 0 || this.seconds !== 0 || this.milliseconds !== 0) s += "T";
  3643. if (this.hours !== 0) s += this.hours + "H";
  3644. if (this.minutes !== 0) s += this.minutes + "M";
  3645. if (this.seconds !== 0 || this.milliseconds !== 0)
  3646. // this will handle "floating point madness" by removing extra decimal places
  3647. // https://stackoverflow.com/questions/588004/is-floating-point-math-broken
  3648. s += roundTo(this.seconds + this.milliseconds / 1000, 3) + "S";
  3649. if (s === "P") s += "T0S";
  3650. return s;
  3651. }
  3652. /**
  3653. * Returns an ISO 8601-compliant string representation of this Duration, formatted as a time of day.
  3654. * Note that this will return null if the duration is invalid, negative, or equal to or greater than 24 hours.
  3655. * @see https://en.wikipedia.org/wiki/ISO_8601#Times
  3656. * @param {Object} opts - options
  3657. * @param {boolean} [opts.suppressMilliseconds=false] - exclude milliseconds from the format if they're 0
  3658. * @param {boolean} [opts.suppressSeconds=false] - exclude seconds from the format if they're 0
  3659. * @param {boolean} [opts.includePrefix=false] - include the `T` prefix
  3660. * @param {string} [opts.format='extended'] - choose between the basic and extended format
  3661. * @example Duration.fromObject({ hours: 11 }).toISOTime() //=> '11:00:00.000'
  3662. * @example Duration.fromObject({ hours: 11 }).toISOTime({ suppressMilliseconds: true }) //=> '11:00:00'
  3663. * @example Duration.fromObject({ hours: 11 }).toISOTime({ suppressSeconds: true }) //=> '11:00'
  3664. * @example Duration.fromObject({ hours: 11 }).toISOTime({ includePrefix: true }) //=> 'T11:00:00.000'
  3665. * @example Duration.fromObject({ hours: 11 }).toISOTime({ format: 'basic' }) //=> '110000.000'
  3666. * @return {string}
  3667. */;
  3668. _proto.toISOTime = function toISOTime(opts) {
  3669. if (opts === void 0) {
  3670. opts = {};
  3671. }
  3672. if (!this.isValid) return null;
  3673. var millis = this.toMillis();
  3674. if (millis < 0 || millis >= 86400000) return null;
  3675. opts = _extends({
  3676. suppressMilliseconds: false,
  3677. suppressSeconds: false,
  3678. includePrefix: false,
  3679. format: "extended"
  3680. }, opts, {
  3681. includeOffset: false
  3682. });
  3683. var dateTime = DateTime.fromMillis(millis, {
  3684. zone: "UTC"
  3685. });
  3686. return dateTime.toISOTime(opts);
  3687. }
  3688. /**
  3689. * Returns an ISO 8601 representation of this Duration appropriate for use in JSON.
  3690. * @return {string}
  3691. */;
  3692. _proto.toJSON = function toJSON() {
  3693. return this.toISO();
  3694. }
  3695. /**
  3696. * Returns an ISO 8601 representation of this Duration appropriate for use in debugging.
  3697. * @return {string}
  3698. */;
  3699. _proto.toString = function toString() {
  3700. return this.toISO();
  3701. }
  3702. /**
  3703. * Returns a string representation of this Duration appropriate for the REPL.
  3704. * @return {string}
  3705. */;
  3706. _proto[_Symbol$for] = function () {
  3707. if (this.isValid) {
  3708. return "Duration { values: " + JSON.stringify(this.values) + " }";
  3709. } else {
  3710. return "Duration { Invalid, reason: " + this.invalidReason + " }";
  3711. }
  3712. }
  3713. /**
  3714. * Returns an milliseconds value of this Duration.
  3715. * @return {number}
  3716. */;
  3717. _proto.toMillis = function toMillis() {
  3718. if (!this.isValid) return NaN;
  3719. return durationToMillis(this.matrix, this.values);
  3720. }
  3721. /**
  3722. * Returns an milliseconds value of this Duration. Alias of {@link toMillis}
  3723. * @return {number}
  3724. */;
  3725. _proto.valueOf = function valueOf() {
  3726. return this.toMillis();
  3727. }
  3728. /**
  3729. * Make this Duration longer by the specified amount. Return a newly-constructed Duration.
  3730. * @param {Duration|Object|number} duration - The amount to add. Either a Luxon Duration, a number of milliseconds, the object argument to Duration.fromObject()
  3731. * @return {Duration}
  3732. */;
  3733. _proto.plus = function plus(duration) {
  3734. if (!this.isValid) return this;
  3735. var dur = Duration.fromDurationLike(duration),
  3736. result = {};
  3737. for (var _i2 = 0, _orderedUnits = orderedUnits$1; _i2 < _orderedUnits.length; _i2++) {
  3738. var k = _orderedUnits[_i2];
  3739. if (hasOwnProperty(dur.values, k) || hasOwnProperty(this.values, k)) {
  3740. result[k] = dur.get(k) + this.get(k);
  3741. }
  3742. }
  3743. return clone$1(this, {
  3744. values: result
  3745. }, true);
  3746. }
  3747. /**
  3748. * Make this Duration shorter by the specified amount. Return a newly-constructed Duration.
  3749. * @param {Duration|Object|number} duration - The amount to subtract. Either a Luxon Duration, a number of milliseconds, the object argument to Duration.fromObject()
  3750. * @return {Duration}
  3751. */;
  3752. _proto.minus = function minus(duration) {
  3753. if (!this.isValid) return this;
  3754. var dur = Duration.fromDurationLike(duration);
  3755. return this.plus(dur.negate());
  3756. }
  3757. /**
  3758. * Scale this Duration by the specified amount. Return a newly-constructed Duration.
  3759. * @param {function} fn - The function to apply to each unit. Arity is 1 or 2: the value of the unit and, optionally, the unit name. Must return a number.
  3760. * @example Duration.fromObject({ hours: 1, minutes: 30 }).mapUnits(x => x * 2) //=> { hours: 2, minutes: 60 }
  3761. * @example Duration.fromObject({ hours: 1, minutes: 30 }).mapUnits((x, u) => u === "hours" ? x * 2 : x) //=> { hours: 2, minutes: 30 }
  3762. * @return {Duration}
  3763. */;
  3764. _proto.mapUnits = function mapUnits(fn) {
  3765. if (!this.isValid) return this;
  3766. var result = {};
  3767. for (var _i3 = 0, _Object$keys = Object.keys(this.values); _i3 < _Object$keys.length; _i3++) {
  3768. var k = _Object$keys[_i3];
  3769. result[k] = asNumber(fn(this.values[k], k));
  3770. }
  3771. return clone$1(this, {
  3772. values: result
  3773. }, true);
  3774. }
  3775. /**
  3776. * Get the value of unit.
  3777. * @param {string} unit - a unit such as 'minute' or 'day'
  3778. * @example Duration.fromObject({years: 2, days: 3}).get('years') //=> 2
  3779. * @example Duration.fromObject({years: 2, days: 3}).get('months') //=> 0
  3780. * @example Duration.fromObject({years: 2, days: 3}).get('days') //=> 3
  3781. * @return {number}
  3782. */;
  3783. _proto.get = function get(unit) {
  3784. return this[Duration.normalizeUnit(unit)];
  3785. }
  3786. /**
  3787. * "Set" the values of specified units. Return a newly-constructed Duration.
  3788. * @param {Object} values - a mapping of units to numbers
  3789. * @example dur.set({ years: 2017 })
  3790. * @example dur.set({ hours: 8, minutes: 30 })
  3791. * @return {Duration}
  3792. */;
  3793. _proto.set = function set(values) {
  3794. if (!this.isValid) return this;
  3795. var mixed = _extends({}, this.values, normalizeObject(values, Duration.normalizeUnit));
  3796. return clone$1(this, {
  3797. values: mixed
  3798. });
  3799. }
  3800. /**
  3801. * "Set" the locale and/or numberingSystem. Returns a newly-constructed Duration.
  3802. * @example dur.reconfigure({ locale: 'en-GB' })
  3803. * @return {Duration}
  3804. */;
  3805. _proto.reconfigure = function reconfigure(_temp) {
  3806. var _ref = _temp === void 0 ? {} : _temp,
  3807. locale = _ref.locale,
  3808. numberingSystem = _ref.numberingSystem,
  3809. conversionAccuracy = _ref.conversionAccuracy,
  3810. matrix = _ref.matrix;
  3811. var loc = this.loc.clone({
  3812. locale: locale,
  3813. numberingSystem: numberingSystem
  3814. });
  3815. var opts = {
  3816. loc: loc,
  3817. matrix: matrix,
  3818. conversionAccuracy: conversionAccuracy
  3819. };
  3820. return clone$1(this, opts);
  3821. }
  3822. /**
  3823. * Return the length of the duration in the specified unit.
  3824. * @param {string} unit - a unit such as 'minutes' or 'days'
  3825. * @example Duration.fromObject({years: 1}).as('days') //=> 365
  3826. * @example Duration.fromObject({years: 1}).as('months') //=> 12
  3827. * @example Duration.fromObject({hours: 60}).as('days') //=> 2.5
  3828. * @return {number}
  3829. */;
  3830. _proto.as = function as(unit) {
  3831. return this.isValid ? this.shiftTo(unit).get(unit) : NaN;
  3832. }
  3833. /**
  3834. * Reduce this Duration to its canonical representation in its current units.
  3835. * Assuming the overall value of the Duration is positive, this means:
  3836. * - excessive values for lower-order units are converted to higher-order units (if possible, see first and second example)
  3837. * - negative lower-order units are converted to higher order units (there must be such a higher order unit, otherwise
  3838. * the overall value would be negative, see third example)
  3839. * - fractional values for higher-order units are converted to lower-order units (if possible, see fourth example)
  3840. *
  3841. * If the overall value is negative, the result of this method is equivalent to `this.negate().normalize().negate()`.
  3842. * @example Duration.fromObject({ years: 2, days: 5000 }).normalize().toObject() //=> { years: 15, days: 255 }
  3843. * @example Duration.fromObject({ days: 5000 }).normalize().toObject() //=> { days: 5000 }
  3844. * @example Duration.fromObject({ hours: 12, minutes: -45 }).normalize().toObject() //=> { hours: 11, minutes: 15 }
  3845. * @example Duration.fromObject({ years: 2.5, days: 0, hours: 0 }).normalize().toObject() //=> { years: 2, days: 182, hours: 12 }
  3846. * @return {Duration}
  3847. */;
  3848. _proto.normalize = function normalize() {
  3849. if (!this.isValid) return this;
  3850. var vals = this.toObject();
  3851. normalizeValues(this.matrix, vals);
  3852. return clone$1(this, {
  3853. values: vals
  3854. }, true);
  3855. }
  3856. /**
  3857. * Rescale units to its largest representation
  3858. * @example Duration.fromObject({ milliseconds: 90000 }).rescale().toObject() //=> { minutes: 1, seconds: 30 }
  3859. * @return {Duration}
  3860. */;
  3861. _proto.rescale = function rescale() {
  3862. if (!this.isValid) return this;
  3863. var vals = removeZeroes(this.normalize().shiftToAll().toObject());
  3864. return clone$1(this, {
  3865. values: vals
  3866. }, true);
  3867. }
  3868. /**
  3869. * Convert this Duration into its representation in a different set of units.
  3870. * @example Duration.fromObject({ hours: 1, seconds: 30 }).shiftTo('minutes', 'milliseconds').toObject() //=> { minutes: 60, milliseconds: 30000 }
  3871. * @return {Duration}
  3872. */;
  3873. _proto.shiftTo = function shiftTo() {
  3874. for (var _len = arguments.length, units = new Array(_len), _key = 0; _key < _len; _key++) {
  3875. units[_key] = arguments[_key];
  3876. }
  3877. if (!this.isValid) return this;
  3878. if (units.length === 0) {
  3879. return this;
  3880. }
  3881. units = units.map(function (u) {
  3882. return Duration.normalizeUnit(u);
  3883. });
  3884. var built = {},
  3885. accumulated = {},
  3886. vals = this.toObject();
  3887. var lastUnit;
  3888. for (var _i4 = 0, _orderedUnits2 = orderedUnits$1; _i4 < _orderedUnits2.length; _i4++) {
  3889. var k = _orderedUnits2[_i4];
  3890. if (units.indexOf(k) >= 0) {
  3891. lastUnit = k;
  3892. var own = 0;
  3893. // anything we haven't boiled down yet should get boiled to this unit
  3894. for (var ak in accumulated) {
  3895. own += this.matrix[ak][k] * accumulated[ak];
  3896. accumulated[ak] = 0;
  3897. }
  3898. // plus anything that's already in this unit
  3899. if (isNumber(vals[k])) {
  3900. own += vals[k];
  3901. }
  3902. // only keep the integer part for now in the hopes of putting any decimal part
  3903. // into a smaller unit later
  3904. var i = Math.trunc(own);
  3905. built[k] = i;
  3906. accumulated[k] = (own * 1000 - i * 1000) / 1000;
  3907. // otherwise, keep it in the wings to boil it later
  3908. } else if (isNumber(vals[k])) {
  3909. accumulated[k] = vals[k];
  3910. }
  3911. }
  3912. // anything leftover becomes the decimal for the last unit
  3913. // lastUnit must be defined since units is not empty
  3914. for (var key in accumulated) {
  3915. if (accumulated[key] !== 0) {
  3916. built[lastUnit] += key === lastUnit ? accumulated[key] : accumulated[key] / this.matrix[lastUnit][key];
  3917. }
  3918. }
  3919. normalizeValues(this.matrix, built);
  3920. return clone$1(this, {
  3921. values: built
  3922. }, true);
  3923. }
  3924. /**
  3925. * Shift this Duration to all available units.
  3926. * Same as shiftTo("years", "months", "weeks", "days", "hours", "minutes", "seconds", "milliseconds")
  3927. * @return {Duration}
  3928. */;
  3929. _proto.shiftToAll = function shiftToAll() {
  3930. if (!this.isValid) return this;
  3931. return this.shiftTo("years", "months", "weeks", "days", "hours", "minutes", "seconds", "milliseconds");
  3932. }
  3933. /**
  3934. * Return the negative of this Duration.
  3935. * @example Duration.fromObject({ hours: 1, seconds: 30 }).negate().toObject() //=> { hours: -1, seconds: -30 }
  3936. * @return {Duration}
  3937. */;
  3938. _proto.negate = function negate() {
  3939. if (!this.isValid) return this;
  3940. var negated = {};
  3941. for (var _i5 = 0, _Object$keys2 = Object.keys(this.values); _i5 < _Object$keys2.length; _i5++) {
  3942. var k = _Object$keys2[_i5];
  3943. negated[k] = this.values[k] === 0 ? 0 : -this.values[k];
  3944. }
  3945. return clone$1(this, {
  3946. values: negated
  3947. }, true);
  3948. }
  3949. /**
  3950. * Get the years.
  3951. * @type {number}
  3952. */;
  3953. /**
  3954. * Equality check
  3955. * Two Durations are equal iff they have the same units and the same values for each unit.
  3956. * @param {Duration} other
  3957. * @return {boolean}
  3958. */
  3959. _proto.equals = function equals(other) {
  3960. if (!this.isValid || !other.isValid) {
  3961. return false;
  3962. }
  3963. if (!this.loc.equals(other.loc)) {
  3964. return false;
  3965. }
  3966. function eq(v1, v2) {
  3967. // Consider 0 and undefined as equal
  3968. if (v1 === undefined || v1 === 0) return v2 === undefined || v2 === 0;
  3969. return v1 === v2;
  3970. }
  3971. for (var _i6 = 0, _orderedUnits3 = orderedUnits$1; _i6 < _orderedUnits3.length; _i6++) {
  3972. var u = _orderedUnits3[_i6];
  3973. if (!eq(this.values[u], other.values[u])) {
  3974. return false;
  3975. }
  3976. }
  3977. return true;
  3978. };
  3979. _createClass(Duration, [{
  3980. key: "locale",
  3981. get: function get() {
  3982. return this.isValid ? this.loc.locale : null;
  3983. }
  3984. /**
  3985. * Get the numbering system of a Duration, such 'beng'. The numbering system is used when formatting the Duration
  3986. *
  3987. * @type {string}
  3988. */
  3989. }, {
  3990. key: "numberingSystem",
  3991. get: function get() {
  3992. return this.isValid ? this.loc.numberingSystem : null;
  3993. }
  3994. }, {
  3995. key: "years",
  3996. get: function get() {
  3997. return this.isValid ? this.values.years || 0 : NaN;
  3998. }
  3999. /**
  4000. * Get the quarters.
  4001. * @type {number}
  4002. */
  4003. }, {
  4004. key: "quarters",
  4005. get: function get() {
  4006. return this.isValid ? this.values.quarters || 0 : NaN;
  4007. }
  4008. /**
  4009. * Get the months.
  4010. * @type {number}
  4011. */
  4012. }, {
  4013. key: "months",
  4014. get: function get() {
  4015. return this.isValid ? this.values.months || 0 : NaN;
  4016. }
  4017. /**
  4018. * Get the weeks
  4019. * @type {number}
  4020. */
  4021. }, {
  4022. key: "weeks",
  4023. get: function get() {
  4024. return this.isValid ? this.values.weeks || 0 : NaN;
  4025. }
  4026. /**
  4027. * Get the days.
  4028. * @type {number}
  4029. */
  4030. }, {
  4031. key: "days",
  4032. get: function get() {
  4033. return this.isValid ? this.values.days || 0 : NaN;
  4034. }
  4035. /**
  4036. * Get the hours.
  4037. * @type {number}
  4038. */
  4039. }, {
  4040. key: "hours",
  4041. get: function get() {
  4042. return this.isValid ? this.values.hours || 0 : NaN;
  4043. }
  4044. /**
  4045. * Get the minutes.
  4046. * @type {number}
  4047. */
  4048. }, {
  4049. key: "minutes",
  4050. get: function get() {
  4051. return this.isValid ? this.values.minutes || 0 : NaN;
  4052. }
  4053. /**
  4054. * Get the seconds.
  4055. * @return {number}
  4056. */
  4057. }, {
  4058. key: "seconds",
  4059. get: function get() {
  4060. return this.isValid ? this.values.seconds || 0 : NaN;
  4061. }
  4062. /**
  4063. * Get the milliseconds.
  4064. * @return {number}
  4065. */
  4066. }, {
  4067. key: "milliseconds",
  4068. get: function get() {
  4069. return this.isValid ? this.values.milliseconds || 0 : NaN;
  4070. }
  4071. /**
  4072. * Returns whether the Duration is invalid. Invalid durations are returned by diff operations
  4073. * on invalid DateTimes or Intervals.
  4074. * @return {boolean}
  4075. */
  4076. }, {
  4077. key: "isValid",
  4078. get: function get() {
  4079. return this.invalid === null;
  4080. }
  4081. /**
  4082. * Returns an error code if this Duration became invalid, or null if the Duration is valid
  4083. * @return {string}
  4084. */
  4085. }, {
  4086. key: "invalidReason",
  4087. get: function get() {
  4088. return this.invalid ? this.invalid.reason : null;
  4089. }
  4090. /**
  4091. * Returns an explanation of why this Duration became invalid, or null if the Duration is valid
  4092. * @type {string}
  4093. */
  4094. }, {
  4095. key: "invalidExplanation",
  4096. get: function get() {
  4097. return this.invalid ? this.invalid.explanation : null;
  4098. }
  4099. }]);
  4100. return Duration;
  4101. }(Symbol.for("nodejs.util.inspect.custom"));
  4102. var INVALID$1 = "Invalid Interval";
  4103. // checks if the start is equal to or before the end
  4104. function validateStartEnd(start, end) {
  4105. if (!start || !start.isValid) {
  4106. return Interval.invalid("missing or invalid start");
  4107. } else if (!end || !end.isValid) {
  4108. return Interval.invalid("missing or invalid end");
  4109. } else if (end < start) {
  4110. return Interval.invalid("end before start", "The end of an interval must be after its start, but you had start=" + start.toISO() + " and end=" + end.toISO());
  4111. } else {
  4112. return null;
  4113. }
  4114. }
  4115. /**
  4116. * An Interval object represents a half-open interval of time, where each endpoint is a {@link DateTime}. Conceptually, it's a container for those two endpoints, accompanied by methods for creating, parsing, interrogating, comparing, transforming, and formatting them.
  4117. *
  4118. * Here is a brief overview of the most commonly used methods and getters in Interval:
  4119. *
  4120. * * **Creation** To create an Interval, use {@link Interval.fromDateTimes}, {@link Interval.after}, {@link Interval.before}, or {@link Interval.fromISO}.
  4121. * * **Accessors** Use {@link Interval#start} and {@link Interval#end} to get the start and end.
  4122. * * **Interrogation** To analyze the Interval, use {@link Interval#count}, {@link Interval#length}, {@link Interval#hasSame}, {@link Interval#contains}, {@link Interval#isAfter}, or {@link Interval#isBefore}.
  4123. * * **Transformation** To create other Intervals out of this one, use {@link Interval#set}, {@link Interval#splitAt}, {@link Interval#splitBy}, {@link Interval#divideEqually}, {@link Interval.merge}, {@link Interval.xor}, {@link Interval#union}, {@link Interval#intersection}, or {@link Interval#difference}.
  4124. * * **Comparison** To compare this Interval to another one, use {@link Interval#equals}, {@link Interval#overlaps}, {@link Interval#abutsStart}, {@link Interval#abutsEnd}, {@link Interval#engulfs}
  4125. * * **Output** To convert the Interval into other representations, see {@link Interval#toString}, {@link Interval#toLocaleString}, {@link Interval#toISO}, {@link Interval#toISODate}, {@link Interval#toISOTime}, {@link Interval#toFormat}, and {@link Interval#toDuration}.
  4126. */
  4127. var Interval = /*#__PURE__*/function (_Symbol$for) {
  4128. /**
  4129. * @private
  4130. */
  4131. function Interval(config) {
  4132. /**
  4133. * @access private
  4134. */
  4135. this.s = config.start;
  4136. /**
  4137. * @access private
  4138. */
  4139. this.e = config.end;
  4140. /**
  4141. * @access private
  4142. */
  4143. this.invalid = config.invalid || null;
  4144. /**
  4145. * @access private
  4146. */
  4147. this.isLuxonInterval = true;
  4148. }
  4149. /**
  4150. * Create an invalid Interval.
  4151. * @param {string} reason - simple string of why this Interval is invalid. Should not contain parameters or anything else data-dependent
  4152. * @param {string} [explanation=null] - longer explanation, may include parameters and other useful debugging information
  4153. * @return {Interval}
  4154. */
  4155. Interval.invalid = function invalid(reason, explanation) {
  4156. if (explanation === void 0) {
  4157. explanation = null;
  4158. }
  4159. if (!reason) {
  4160. throw new InvalidArgumentError("need to specify a reason the Interval is invalid");
  4161. }
  4162. var invalid = reason instanceof Invalid ? reason : new Invalid(reason, explanation);
  4163. if (Settings.throwOnInvalid) {
  4164. throw new InvalidIntervalError(invalid);
  4165. } else {
  4166. return new Interval({
  4167. invalid: invalid
  4168. });
  4169. }
  4170. }
  4171. /**
  4172. * Create an Interval from a start DateTime and an end DateTime. Inclusive of the start but not the end.
  4173. * @param {DateTime|Date|Object} start
  4174. * @param {DateTime|Date|Object} end
  4175. * @return {Interval}
  4176. */;
  4177. Interval.fromDateTimes = function fromDateTimes(start, end) {
  4178. var builtStart = friendlyDateTime(start),
  4179. builtEnd = friendlyDateTime(end);
  4180. var validateError = validateStartEnd(builtStart, builtEnd);
  4181. if (validateError == null) {
  4182. return new Interval({
  4183. start: builtStart,
  4184. end: builtEnd
  4185. });
  4186. } else {
  4187. return validateError;
  4188. }
  4189. }
  4190. /**
  4191. * Create an Interval from a start DateTime and a Duration to extend to.
  4192. * @param {DateTime|Date|Object} start
  4193. * @param {Duration|Object|number} duration - the length of the Interval.
  4194. * @return {Interval}
  4195. */;
  4196. Interval.after = function after(start, duration) {
  4197. var dur = Duration.fromDurationLike(duration),
  4198. dt = friendlyDateTime(start);
  4199. return Interval.fromDateTimes(dt, dt.plus(dur));
  4200. }
  4201. /**
  4202. * Create an Interval from an end DateTime and a Duration to extend backwards to.
  4203. * @param {DateTime|Date|Object} end
  4204. * @param {Duration|Object|number} duration - the length of the Interval.
  4205. * @return {Interval}
  4206. */;
  4207. Interval.before = function before(end, duration) {
  4208. var dur = Duration.fromDurationLike(duration),
  4209. dt = friendlyDateTime(end);
  4210. return Interval.fromDateTimes(dt.minus(dur), dt);
  4211. }
  4212. /**
  4213. * Create an Interval from an ISO 8601 string.
  4214. * Accepts `<start>/<end>`, `<start>/<duration>`, and `<duration>/<end>` formats.
  4215. * @param {string} text - the ISO string to parse
  4216. * @param {Object} [opts] - options to pass {@link DateTime#fromISO} and optionally {@link Duration#fromISO}
  4217. * @see https://en.wikipedia.org/wiki/ISO_8601#Time_intervals
  4218. * @return {Interval}
  4219. */;
  4220. Interval.fromISO = function fromISO(text, opts) {
  4221. var _split = (text || "").split("/", 2),
  4222. s = _split[0],
  4223. e = _split[1];
  4224. if (s && e) {
  4225. var start, startIsValid;
  4226. try {
  4227. start = DateTime.fromISO(s, opts);
  4228. startIsValid = start.isValid;
  4229. } catch (e) {
  4230. startIsValid = false;
  4231. }
  4232. var end, endIsValid;
  4233. try {
  4234. end = DateTime.fromISO(e, opts);
  4235. endIsValid = end.isValid;
  4236. } catch (e) {
  4237. endIsValid = false;
  4238. }
  4239. if (startIsValid && endIsValid) {
  4240. return Interval.fromDateTimes(start, end);
  4241. }
  4242. if (startIsValid) {
  4243. var dur = Duration.fromISO(e, opts);
  4244. if (dur.isValid) {
  4245. return Interval.after(start, dur);
  4246. }
  4247. } else if (endIsValid) {
  4248. var _dur = Duration.fromISO(s, opts);
  4249. if (_dur.isValid) {
  4250. return Interval.before(end, _dur);
  4251. }
  4252. }
  4253. }
  4254. return Interval.invalid("unparsable", "the input \"" + text + "\" can't be parsed as ISO 8601");
  4255. }
  4256. /**
  4257. * Check if an object is an Interval. Works across context boundaries
  4258. * @param {object} o
  4259. * @return {boolean}
  4260. */;
  4261. Interval.isInterval = function isInterval(o) {
  4262. return o && o.isLuxonInterval || false;
  4263. }
  4264. /**
  4265. * Returns the start of the Interval
  4266. * @type {DateTime}
  4267. */;
  4268. var _proto = Interval.prototype;
  4269. /**
  4270. * Returns the length of the Interval in the specified unit.
  4271. * @param {string} unit - the unit (such as 'hours' or 'days') to return the length in.
  4272. * @return {number}
  4273. */
  4274. _proto.length = function length(unit) {
  4275. if (unit === void 0) {
  4276. unit = "milliseconds";
  4277. }
  4278. return this.isValid ? this.toDuration.apply(this, [unit]).get(unit) : NaN;
  4279. }
  4280. /**
  4281. * Returns the count of minutes, hours, days, months, or years included in the Interval, even in part.
  4282. * Unlike {@link Interval#length} this counts sections of the calendar, not periods of time, e.g. specifying 'day'
  4283. * asks 'what dates are included in this interval?', not 'how many days long is this interval?'
  4284. * @param {string} [unit='milliseconds'] - the unit of time to count.
  4285. * @param {Object} opts - options
  4286. * @param {boolean} [opts.useLocaleWeeks=false] - If true, use weeks based on the locale, i.e. use the locale-dependent start of the week; this operation will always use the locale of the start DateTime
  4287. * @return {number}
  4288. */;
  4289. _proto.count = function count(unit, opts) {
  4290. if (unit === void 0) {
  4291. unit = "milliseconds";
  4292. }
  4293. if (!this.isValid) return NaN;
  4294. var start = this.start.startOf(unit, opts);
  4295. var end;
  4296. if (opts != null && opts.useLocaleWeeks) {
  4297. end = this.end.reconfigure({
  4298. locale: start.locale
  4299. });
  4300. } else {
  4301. end = this.end;
  4302. }
  4303. end = end.startOf(unit, opts);
  4304. return Math.floor(end.diff(start, unit).get(unit)) + (end.valueOf() !== this.end.valueOf());
  4305. }
  4306. /**
  4307. * Returns whether this Interval's start and end are both in the same unit of time
  4308. * @param {string} unit - the unit of time to check sameness on
  4309. * @return {boolean}
  4310. */;
  4311. _proto.hasSame = function hasSame(unit) {
  4312. return this.isValid ? this.isEmpty() || this.e.minus(1).hasSame(this.s, unit) : false;
  4313. }
  4314. /**
  4315. * Return whether this Interval has the same start and end DateTimes.
  4316. * @return {boolean}
  4317. */;
  4318. _proto.isEmpty = function isEmpty() {
  4319. return this.s.valueOf() === this.e.valueOf();
  4320. }
  4321. /**
  4322. * Return whether this Interval's start is after the specified DateTime.
  4323. * @param {DateTime} dateTime
  4324. * @return {boolean}
  4325. */;
  4326. _proto.isAfter = function isAfter(dateTime) {
  4327. if (!this.isValid) return false;
  4328. return this.s > dateTime;
  4329. }
  4330. /**
  4331. * Return whether this Interval's end is before the specified DateTime.
  4332. * @param {DateTime} dateTime
  4333. * @return {boolean}
  4334. */;
  4335. _proto.isBefore = function isBefore(dateTime) {
  4336. if (!this.isValid) return false;
  4337. return this.e <= dateTime;
  4338. }
  4339. /**
  4340. * Return whether this Interval contains the specified DateTime.
  4341. * @param {DateTime} dateTime
  4342. * @return {boolean}
  4343. */;
  4344. _proto.contains = function contains(dateTime) {
  4345. if (!this.isValid) return false;
  4346. return this.s <= dateTime && this.e > dateTime;
  4347. }
  4348. /**
  4349. * "Sets" the start and/or end dates. Returns a newly-constructed Interval.
  4350. * @param {Object} values - the values to set
  4351. * @param {DateTime} values.start - the starting DateTime
  4352. * @param {DateTime} values.end - the ending DateTime
  4353. * @return {Interval}
  4354. */;
  4355. _proto.set = function set(_temp) {
  4356. var _ref = _temp === void 0 ? {} : _temp,
  4357. start = _ref.start,
  4358. end = _ref.end;
  4359. if (!this.isValid) return this;
  4360. return Interval.fromDateTimes(start || this.s, end || this.e);
  4361. }
  4362. /**
  4363. * Split this Interval at each of the specified DateTimes
  4364. * @param {...DateTime} dateTimes - the unit of time to count.
  4365. * @return {Array}
  4366. */;
  4367. _proto.splitAt = function splitAt() {
  4368. var _this = this;
  4369. if (!this.isValid) return [];
  4370. for (var _len = arguments.length, dateTimes = new Array(_len), _key = 0; _key < _len; _key++) {
  4371. dateTimes[_key] = arguments[_key];
  4372. }
  4373. var sorted = dateTimes.map(friendlyDateTime).filter(function (d) {
  4374. return _this.contains(d);
  4375. }).sort(function (a, b) {
  4376. return a.toMillis() - b.toMillis();
  4377. }),
  4378. results = [];
  4379. var s = this.s,
  4380. i = 0;
  4381. while (s < this.e) {
  4382. var added = sorted[i] || this.e,
  4383. next = +added > +this.e ? this.e : added;
  4384. results.push(Interval.fromDateTimes(s, next));
  4385. s = next;
  4386. i += 1;
  4387. }
  4388. return results;
  4389. }
  4390. /**
  4391. * Split this Interval into smaller Intervals, each of the specified length.
  4392. * Left over time is grouped into a smaller interval
  4393. * @param {Duration|Object|number} duration - The length of each resulting interval.
  4394. * @return {Array}
  4395. */;
  4396. _proto.splitBy = function splitBy(duration) {
  4397. var dur = Duration.fromDurationLike(duration);
  4398. if (!this.isValid || !dur.isValid || dur.as("milliseconds") === 0) {
  4399. return [];
  4400. }
  4401. var s = this.s,
  4402. idx = 1,
  4403. next;
  4404. var results = [];
  4405. while (s < this.e) {
  4406. var added = this.start.plus(dur.mapUnits(function (x) {
  4407. return x * idx;
  4408. }));
  4409. next = +added > +this.e ? this.e : added;
  4410. results.push(Interval.fromDateTimes(s, next));
  4411. s = next;
  4412. idx += 1;
  4413. }
  4414. return results;
  4415. }
  4416. /**
  4417. * Split this Interval into the specified number of smaller intervals.
  4418. * @param {number} numberOfParts - The number of Intervals to divide the Interval into.
  4419. * @return {Array}
  4420. */;
  4421. _proto.divideEqually = function divideEqually(numberOfParts) {
  4422. if (!this.isValid) return [];
  4423. return this.splitBy(this.length() / numberOfParts).slice(0, numberOfParts);
  4424. }
  4425. /**
  4426. * Return whether this Interval overlaps with the specified Interval
  4427. * @param {Interval} other
  4428. * @return {boolean}
  4429. */;
  4430. _proto.overlaps = function overlaps(other) {
  4431. return this.e > other.s && this.s < other.e;
  4432. }
  4433. /**
  4434. * Return whether this Interval's end is adjacent to the specified Interval's start.
  4435. * @param {Interval} other
  4436. * @return {boolean}
  4437. */;
  4438. _proto.abutsStart = function abutsStart(other) {
  4439. if (!this.isValid) return false;
  4440. return +this.e === +other.s;
  4441. }
  4442. /**
  4443. * Return whether this Interval's start is adjacent to the specified Interval's end.
  4444. * @param {Interval} other
  4445. * @return {boolean}
  4446. */;
  4447. _proto.abutsEnd = function abutsEnd(other) {
  4448. if (!this.isValid) return false;
  4449. return +other.e === +this.s;
  4450. }
  4451. /**
  4452. * Returns true if this Interval fully contains the specified Interval, specifically if the intersect (of this Interval and the other Interval) is equal to the other Interval; false otherwise.
  4453. * @param {Interval} other
  4454. * @return {boolean}
  4455. */;
  4456. _proto.engulfs = function engulfs(other) {
  4457. if (!this.isValid) return false;
  4458. return this.s <= other.s && this.e >= other.e;
  4459. }
  4460. /**
  4461. * Return whether this Interval has the same start and end as the specified Interval.
  4462. * @param {Interval} other
  4463. * @return {boolean}
  4464. */;
  4465. _proto.equals = function equals(other) {
  4466. if (!this.isValid || !other.isValid) {
  4467. return false;
  4468. }
  4469. return this.s.equals(other.s) && this.e.equals(other.e);
  4470. }
  4471. /**
  4472. * Return an Interval representing the intersection of this Interval and the specified Interval.
  4473. * Specifically, the resulting Interval has the maximum start time and the minimum end time of the two Intervals.
  4474. * Returns null if the intersection is empty, meaning, the intervals don't intersect.
  4475. * @param {Interval} other
  4476. * @return {Interval}
  4477. */;
  4478. _proto.intersection = function intersection(other) {
  4479. if (!this.isValid) return this;
  4480. var s = this.s > other.s ? this.s : other.s,
  4481. e = this.e < other.e ? this.e : other.e;
  4482. if (s >= e) {
  4483. return null;
  4484. } else {
  4485. return Interval.fromDateTimes(s, e);
  4486. }
  4487. }
  4488. /**
  4489. * Return an Interval representing the union of this Interval and the specified Interval.
  4490. * Specifically, the resulting Interval has the minimum start time and the maximum end time of the two Intervals.
  4491. * @param {Interval} other
  4492. * @return {Interval}
  4493. */;
  4494. _proto.union = function union(other) {
  4495. if (!this.isValid) return this;
  4496. var s = this.s < other.s ? this.s : other.s,
  4497. e = this.e > other.e ? this.e : other.e;
  4498. return Interval.fromDateTimes(s, e);
  4499. }
  4500. /**
  4501. * Merge an array of Intervals into a equivalent minimal set of Intervals.
  4502. * Combines overlapping and adjacent Intervals.
  4503. * @param {Array} intervals
  4504. * @return {Array}
  4505. */;
  4506. Interval.merge = function merge(intervals) {
  4507. var _intervals$sort$reduc = intervals.sort(function (a, b) {
  4508. return a.s - b.s;
  4509. }).reduce(function (_ref2, item) {
  4510. var sofar = _ref2[0],
  4511. current = _ref2[1];
  4512. if (!current) {
  4513. return [sofar, item];
  4514. } else if (current.overlaps(item) || current.abutsStart(item)) {
  4515. return [sofar, current.union(item)];
  4516. } else {
  4517. return [sofar.concat([current]), item];
  4518. }
  4519. }, [[], null]),
  4520. found = _intervals$sort$reduc[0],
  4521. final = _intervals$sort$reduc[1];
  4522. if (final) {
  4523. found.push(final);
  4524. }
  4525. return found;
  4526. }
  4527. /**
  4528. * Return an array of Intervals representing the spans of time that only appear in one of the specified Intervals.
  4529. * @param {Array} intervals
  4530. * @return {Array}
  4531. */;
  4532. Interval.xor = function xor(intervals) {
  4533. var _Array$prototype;
  4534. var start = null,
  4535. currentCount = 0;
  4536. var results = [],
  4537. ends = intervals.map(function (i) {
  4538. return [{
  4539. time: i.s,
  4540. type: "s"
  4541. }, {
  4542. time: i.e,
  4543. type: "e"
  4544. }];
  4545. }),
  4546. flattened = (_Array$prototype = Array.prototype).concat.apply(_Array$prototype, ends),
  4547. arr = flattened.sort(function (a, b) {
  4548. return a.time - b.time;
  4549. });
  4550. for (var _iterator = _createForOfIteratorHelperLoose(arr), _step; !(_step = _iterator()).done;) {
  4551. var i = _step.value;
  4552. currentCount += i.type === "s" ? 1 : -1;
  4553. if (currentCount === 1) {
  4554. start = i.time;
  4555. } else {
  4556. if (start && +start !== +i.time) {
  4557. results.push(Interval.fromDateTimes(start, i.time));
  4558. }
  4559. start = null;
  4560. }
  4561. }
  4562. return Interval.merge(results);
  4563. }
  4564. /**
  4565. * Return an Interval representing the span of time in this Interval that doesn't overlap with any of the specified Intervals.
  4566. * @param {...Interval} intervals
  4567. * @return {Array}
  4568. */;
  4569. _proto.difference = function difference() {
  4570. var _this2 = this;
  4571. for (var _len2 = arguments.length, intervals = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  4572. intervals[_key2] = arguments[_key2];
  4573. }
  4574. return Interval.xor([this].concat(intervals)).map(function (i) {
  4575. return _this2.intersection(i);
  4576. }).filter(function (i) {
  4577. return i && !i.isEmpty();
  4578. });
  4579. }
  4580. /**
  4581. * Returns a string representation of this Interval appropriate for debugging.
  4582. * @return {string}
  4583. */;
  4584. _proto.toString = function toString() {
  4585. if (!this.isValid) return INVALID$1;
  4586. return "[" + this.s.toISO() + " \u2013 " + this.e.toISO() + ")";
  4587. }
  4588. /**
  4589. * Returns a string representation of this Interval appropriate for the REPL.
  4590. * @return {string}
  4591. */;
  4592. _proto[_Symbol$for] = function () {
  4593. if (this.isValid) {
  4594. return "Interval { start: " + this.s.toISO() + ", end: " + this.e.toISO() + " }";
  4595. } else {
  4596. return "Interval { Invalid, reason: " + this.invalidReason + " }";
  4597. }
  4598. }
  4599. /**
  4600. * Returns a localized string representing this Interval. Accepts the same options as the
  4601. * Intl.DateTimeFormat constructor and any presets defined by Luxon, such as
  4602. * {@link DateTime.DATE_FULL} or {@link DateTime.TIME_SIMPLE}. The exact behavior of this method
  4603. * is browser-specific, but in general it will return an appropriate representation of the
  4604. * Interval in the assigned locale. Defaults to the system's locale if no locale has been
  4605. * specified.
  4606. * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
  4607. * @param {Object} [formatOpts=DateTime.DATE_SHORT] - Either a DateTime preset or
  4608. * Intl.DateTimeFormat constructor options.
  4609. * @param {Object} opts - Options to override the configuration of the start DateTime.
  4610. * @example Interval.fromISO('2022-11-07T09:00Z/2022-11-08T09:00Z').toLocaleString(); //=> 11/7/2022 – 11/8/2022
  4611. * @example Interval.fromISO('2022-11-07T09:00Z/2022-11-08T09:00Z').toLocaleString(DateTime.DATE_FULL); //=> November 7 – 8, 2022
  4612. * @example Interval.fromISO('2022-11-07T09:00Z/2022-11-08T09:00Z').toLocaleString(DateTime.DATE_FULL, { locale: 'fr-FR' }); //=> 7–8 novembre 2022
  4613. * @example Interval.fromISO('2022-11-07T17:00Z/2022-11-07T19:00Z').toLocaleString(DateTime.TIME_SIMPLE); //=> 6:00 – 8:00 PM
  4614. * @example Interval.fromISO('2022-11-07T17:00Z/2022-11-07T19:00Z').toLocaleString({ weekday: 'short', month: 'short', day: '2-digit', hour: '2-digit', minute: '2-digit' }); //=> Mon, Nov 07, 6:00 – 8:00 p
  4615. * @return {string}
  4616. */;
  4617. _proto.toLocaleString = function toLocaleString(formatOpts, opts) {
  4618. if (formatOpts === void 0) {
  4619. formatOpts = DATE_SHORT;
  4620. }
  4621. if (opts === void 0) {
  4622. opts = {};
  4623. }
  4624. return this.isValid ? Formatter.create(this.s.loc.clone(opts), formatOpts).formatInterval(this) : INVALID$1;
  4625. }
  4626. /**
  4627. * Returns an ISO 8601-compliant string representation of this Interval.
  4628. * @see https://en.wikipedia.org/wiki/ISO_8601#Time_intervals
  4629. * @param {Object} opts - The same options as {@link DateTime#toISO}
  4630. * @return {string}
  4631. */;
  4632. _proto.toISO = function toISO(opts) {
  4633. if (!this.isValid) return INVALID$1;
  4634. return this.s.toISO(opts) + "/" + this.e.toISO(opts);
  4635. }
  4636. /**
  4637. * Returns an ISO 8601-compliant string representation of date of this Interval.
  4638. * The time components are ignored.
  4639. * @see https://en.wikipedia.org/wiki/ISO_8601#Time_intervals
  4640. * @return {string}
  4641. */;
  4642. _proto.toISODate = function toISODate() {
  4643. if (!this.isValid) return INVALID$1;
  4644. return this.s.toISODate() + "/" + this.e.toISODate();
  4645. }
  4646. /**
  4647. * Returns an ISO 8601-compliant string representation of time of this Interval.
  4648. * The date components are ignored.
  4649. * @see https://en.wikipedia.org/wiki/ISO_8601#Time_intervals
  4650. * @param {Object} opts - The same options as {@link DateTime#toISO}
  4651. * @return {string}
  4652. */;
  4653. _proto.toISOTime = function toISOTime(opts) {
  4654. if (!this.isValid) return INVALID$1;
  4655. return this.s.toISOTime(opts) + "/" + this.e.toISOTime(opts);
  4656. }
  4657. /**
  4658. * Returns a string representation of this Interval formatted according to the specified format
  4659. * string. **You may not want this.** See {@link Interval#toLocaleString} for a more flexible
  4660. * formatting tool.
  4661. * @param {string} dateFormat - The format string. This string formats the start and end time.
  4662. * See {@link DateTime#toFormat} for details.
  4663. * @param {Object} opts - Options.
  4664. * @param {string} [opts.separator = ' – '] - A separator to place between the start and end
  4665. * representations.
  4666. * @return {string}
  4667. */;
  4668. _proto.toFormat = function toFormat(dateFormat, _temp2) {
  4669. var _ref3 = _temp2 === void 0 ? {} : _temp2,
  4670. _ref3$separator = _ref3.separator,
  4671. separator = _ref3$separator === void 0 ? " – " : _ref3$separator;
  4672. if (!this.isValid) return INVALID$1;
  4673. return "" + this.s.toFormat(dateFormat) + separator + this.e.toFormat(dateFormat);
  4674. }
  4675. /**
  4676. * Return a Duration representing the time spanned by this interval.
  4677. * @param {string|string[]} [unit=['milliseconds']] - the unit or units (such as 'hours' or 'days') to include in the duration.
  4678. * @param {Object} opts - options that affect the creation of the Duration
  4679. * @param {string} [opts.conversionAccuracy='casual'] - the conversion system to use
  4680. * @example Interval.fromDateTimes(dt1, dt2).toDuration().toObject() //=> { milliseconds: 88489257 }
  4681. * @example Interval.fromDateTimes(dt1, dt2).toDuration('days').toObject() //=> { days: 1.0241812152777778 }
  4682. * @example Interval.fromDateTimes(dt1, dt2).toDuration(['hours', 'minutes']).toObject() //=> { hours: 24, minutes: 34.82095 }
  4683. * @example Interval.fromDateTimes(dt1, dt2).toDuration(['hours', 'minutes', 'seconds']).toObject() //=> { hours: 24, minutes: 34, seconds: 49.257 }
  4684. * @example Interval.fromDateTimes(dt1, dt2).toDuration('seconds').toObject() //=> { seconds: 88489.257 }
  4685. * @return {Duration}
  4686. */;
  4687. _proto.toDuration = function toDuration(unit, opts) {
  4688. if (!this.isValid) {
  4689. return Duration.invalid(this.invalidReason);
  4690. }
  4691. return this.e.diff(this.s, unit, opts);
  4692. }
  4693. /**
  4694. * Run mapFn on the interval start and end, returning a new Interval from the resulting DateTimes
  4695. * @param {function} mapFn
  4696. * @return {Interval}
  4697. * @example Interval.fromDateTimes(dt1, dt2).mapEndpoints(endpoint => endpoint.toUTC())
  4698. * @example Interval.fromDateTimes(dt1, dt2).mapEndpoints(endpoint => endpoint.plus({ hours: 2 }))
  4699. */;
  4700. _proto.mapEndpoints = function mapEndpoints(mapFn) {
  4701. return Interval.fromDateTimes(mapFn(this.s), mapFn(this.e));
  4702. };
  4703. _createClass(Interval, [{
  4704. key: "start",
  4705. get: function get() {
  4706. return this.isValid ? this.s : null;
  4707. }
  4708. /**
  4709. * Returns the end of the Interval
  4710. * @type {DateTime}
  4711. */
  4712. }, {
  4713. key: "end",
  4714. get: function get() {
  4715. return this.isValid ? this.e : null;
  4716. }
  4717. /**
  4718. * Returns whether this Interval's end is at least its start, meaning that the Interval isn't 'backwards'.
  4719. * @type {boolean}
  4720. */
  4721. }, {
  4722. key: "isValid",
  4723. get: function get() {
  4724. return this.invalidReason === null;
  4725. }
  4726. /**
  4727. * Returns an error code if this Interval is invalid, or null if the Interval is valid
  4728. * @type {string}
  4729. */
  4730. }, {
  4731. key: "invalidReason",
  4732. get: function get() {
  4733. return this.invalid ? this.invalid.reason : null;
  4734. }
  4735. /**
  4736. * Returns an explanation of why this Interval became invalid, or null if the Interval is valid
  4737. * @type {string}
  4738. */
  4739. }, {
  4740. key: "invalidExplanation",
  4741. get: function get() {
  4742. return this.invalid ? this.invalid.explanation : null;
  4743. }
  4744. }]);
  4745. return Interval;
  4746. }(Symbol.for("nodejs.util.inspect.custom"));
  4747. /**
  4748. * The Info class contains static methods for retrieving general time and date related data. For example, it has methods for finding out if a time zone has a DST, for listing the months in any supported locale, and for discovering which of Luxon features are available in the current environment.
  4749. */
  4750. var Info = /*#__PURE__*/function () {
  4751. function Info() {}
  4752. /**
  4753. * Return whether the specified zone contains a DST.
  4754. * @param {string|Zone} [zone='local'] - Zone to check. Defaults to the environment's local zone.
  4755. * @return {boolean}
  4756. */
  4757. Info.hasDST = function hasDST(zone) {
  4758. if (zone === void 0) {
  4759. zone = Settings.defaultZone;
  4760. }
  4761. var proto = DateTime.now().setZone(zone).set({
  4762. month: 12
  4763. });
  4764. return !zone.isUniversal && proto.offset !== proto.set({
  4765. month: 6
  4766. }).offset;
  4767. }
  4768. /**
  4769. * Return whether the specified zone is a valid IANA specifier.
  4770. * @param {string} zone - Zone to check
  4771. * @return {boolean}
  4772. */;
  4773. Info.isValidIANAZone = function isValidIANAZone(zone) {
  4774. return IANAZone.isValidZone(zone);
  4775. }
  4776. /**
  4777. * Converts the input into a {@link Zone} instance.
  4778. *
  4779. * * If `input` is already a Zone instance, it is returned unchanged.
  4780. * * If `input` is a string containing a valid time zone name, a Zone instance
  4781. * with that name is returned.
  4782. * * If `input` is a string that doesn't refer to a known time zone, a Zone
  4783. * instance with {@link Zone#isValid} == false is returned.
  4784. * * If `input is a number, a Zone instance with the specified fixed offset
  4785. * in minutes is returned.
  4786. * * If `input` is `null` or `undefined`, the default zone is returned.
  4787. * @param {string|Zone|number} [input] - the value to be converted
  4788. * @return {Zone}
  4789. */;
  4790. Info.normalizeZone = function normalizeZone$1(input) {
  4791. return normalizeZone(input, Settings.defaultZone);
  4792. }
  4793. /**
  4794. * Get the weekday on which the week starts according to the given locale.
  4795. * @param {Object} opts - options
  4796. * @param {string} [opts.locale] - the locale code
  4797. * @param {string} [opts.locObj=null] - an existing locale object to use
  4798. * @returns {number} the start of the week, 1 for Monday through 7 for Sunday
  4799. */;
  4800. Info.getStartOfWeek = function getStartOfWeek(_temp) {
  4801. var _ref = _temp === void 0 ? {} : _temp,
  4802. _ref$locale = _ref.locale,
  4803. locale = _ref$locale === void 0 ? null : _ref$locale,
  4804. _ref$locObj = _ref.locObj,
  4805. locObj = _ref$locObj === void 0 ? null : _ref$locObj;
  4806. return (locObj || Locale.create(locale)).getStartOfWeek();
  4807. }
  4808. /**
  4809. * Get the minimum number of days necessary in a week before it is considered part of the next year according
  4810. * to the given locale.
  4811. * @param {Object} opts - options
  4812. * @param {string} [opts.locale] - the locale code
  4813. * @param {string} [opts.locObj=null] - an existing locale object to use
  4814. * @returns {number}
  4815. */;
  4816. Info.getMinimumDaysInFirstWeek = function getMinimumDaysInFirstWeek(_temp2) {
  4817. var _ref2 = _temp2 === void 0 ? {} : _temp2,
  4818. _ref2$locale = _ref2.locale,
  4819. locale = _ref2$locale === void 0 ? null : _ref2$locale,
  4820. _ref2$locObj = _ref2.locObj,
  4821. locObj = _ref2$locObj === void 0 ? null : _ref2$locObj;
  4822. return (locObj || Locale.create(locale)).getMinDaysInFirstWeek();
  4823. }
  4824. /**
  4825. * Get the weekdays, which are considered the weekend according to the given locale
  4826. * @param {Object} opts - options
  4827. * @param {string} [opts.locale] - the locale code
  4828. * @param {string} [opts.locObj=null] - an existing locale object to use
  4829. * @returns {number[]} an array of weekdays, 1 for Monday through 7 for Sunday
  4830. */;
  4831. Info.getWeekendWeekdays = function getWeekendWeekdays(_temp3) {
  4832. var _ref3 = _temp3 === void 0 ? {} : _temp3,
  4833. _ref3$locale = _ref3.locale,
  4834. locale = _ref3$locale === void 0 ? null : _ref3$locale,
  4835. _ref3$locObj = _ref3.locObj,
  4836. locObj = _ref3$locObj === void 0 ? null : _ref3$locObj;
  4837. // copy the array, because we cache it internally
  4838. return (locObj || Locale.create(locale)).getWeekendDays().slice();
  4839. }
  4840. /**
  4841. * Return an array of standalone month names.
  4842. * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
  4843. * @param {string} [length='long'] - the length of the month representation, such as "numeric", "2-digit", "narrow", "short", "long"
  4844. * @param {Object} opts - options
  4845. * @param {string} [opts.locale] - the locale code
  4846. * @param {string} [opts.numberingSystem=null] - the numbering system
  4847. * @param {string} [opts.locObj=null] - an existing locale object to use
  4848. * @param {string} [opts.outputCalendar='gregory'] - the calendar
  4849. * @example Info.months()[0] //=> 'January'
  4850. * @example Info.months('short')[0] //=> 'Jan'
  4851. * @example Info.months('numeric')[0] //=> '1'
  4852. * @example Info.months('short', { locale: 'fr-CA' } )[0] //=> 'janv.'
  4853. * @example Info.months('numeric', { locale: 'ar' })[0] //=> '١'
  4854. * @example Info.months('long', { outputCalendar: 'islamic' })[0] //=> 'Rabiʻ I'
  4855. * @return {Array}
  4856. */;
  4857. Info.months = function months(length, _temp4) {
  4858. if (length === void 0) {
  4859. length = "long";
  4860. }
  4861. var _ref4 = _temp4 === void 0 ? {} : _temp4,
  4862. _ref4$locale = _ref4.locale,
  4863. locale = _ref4$locale === void 0 ? null : _ref4$locale,
  4864. _ref4$numberingSystem = _ref4.numberingSystem,
  4865. numberingSystem = _ref4$numberingSystem === void 0 ? null : _ref4$numberingSystem,
  4866. _ref4$locObj = _ref4.locObj,
  4867. locObj = _ref4$locObj === void 0 ? null : _ref4$locObj,
  4868. _ref4$outputCalendar = _ref4.outputCalendar,
  4869. outputCalendar = _ref4$outputCalendar === void 0 ? "gregory" : _ref4$outputCalendar;
  4870. return (locObj || Locale.create(locale, numberingSystem, outputCalendar)).months(length);
  4871. }
  4872. /**
  4873. * Return an array of format month names.
  4874. * Format months differ from standalone months in that they're meant to appear next to the day of the month. In some languages, that
  4875. * changes the string.
  4876. * See {@link Info#months}
  4877. * @param {string} [length='long'] - the length of the month representation, such as "numeric", "2-digit", "narrow", "short", "long"
  4878. * @param {Object} opts - options
  4879. * @param {string} [opts.locale] - the locale code
  4880. * @param {string} [opts.numberingSystem=null] - the numbering system
  4881. * @param {string} [opts.locObj=null] - an existing locale object to use
  4882. * @param {string} [opts.outputCalendar='gregory'] - the calendar
  4883. * @return {Array}
  4884. */;
  4885. Info.monthsFormat = function monthsFormat(length, _temp5) {
  4886. if (length === void 0) {
  4887. length = "long";
  4888. }
  4889. var _ref5 = _temp5 === void 0 ? {} : _temp5,
  4890. _ref5$locale = _ref5.locale,
  4891. locale = _ref5$locale === void 0 ? null : _ref5$locale,
  4892. _ref5$numberingSystem = _ref5.numberingSystem,
  4893. numberingSystem = _ref5$numberingSystem === void 0 ? null : _ref5$numberingSystem,
  4894. _ref5$locObj = _ref5.locObj,
  4895. locObj = _ref5$locObj === void 0 ? null : _ref5$locObj,
  4896. _ref5$outputCalendar = _ref5.outputCalendar,
  4897. outputCalendar = _ref5$outputCalendar === void 0 ? "gregory" : _ref5$outputCalendar;
  4898. return (locObj || Locale.create(locale, numberingSystem, outputCalendar)).months(length, true);
  4899. }
  4900. /**
  4901. * Return an array of standalone week names.
  4902. * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
  4903. * @param {string} [length='long'] - the length of the weekday representation, such as "narrow", "short", "long".
  4904. * @param {Object} opts - options
  4905. * @param {string} [opts.locale] - the locale code
  4906. * @param {string} [opts.numberingSystem=null] - the numbering system
  4907. * @param {string} [opts.locObj=null] - an existing locale object to use
  4908. * @example Info.weekdays()[0] //=> 'Monday'
  4909. * @example Info.weekdays('short')[0] //=> 'Mon'
  4910. * @example Info.weekdays('short', { locale: 'fr-CA' })[0] //=> 'lun.'
  4911. * @example Info.weekdays('short', { locale: 'ar' })[0] //=> 'الاثنين'
  4912. * @return {Array}
  4913. */;
  4914. Info.weekdays = function weekdays(length, _temp6) {
  4915. if (length === void 0) {
  4916. length = "long";
  4917. }
  4918. var _ref6 = _temp6 === void 0 ? {} : _temp6,
  4919. _ref6$locale = _ref6.locale,
  4920. locale = _ref6$locale === void 0 ? null : _ref6$locale,
  4921. _ref6$numberingSystem = _ref6.numberingSystem,
  4922. numberingSystem = _ref6$numberingSystem === void 0 ? null : _ref6$numberingSystem,
  4923. _ref6$locObj = _ref6.locObj,
  4924. locObj = _ref6$locObj === void 0 ? null : _ref6$locObj;
  4925. return (locObj || Locale.create(locale, numberingSystem, null)).weekdays(length);
  4926. }
  4927. /**
  4928. * Return an array of format week names.
  4929. * Format weekdays differ from standalone weekdays in that they're meant to appear next to more date information. In some languages, that
  4930. * changes the string.
  4931. * See {@link Info#weekdays}
  4932. * @param {string} [length='long'] - the length of the month representation, such as "narrow", "short", "long".
  4933. * @param {Object} opts - options
  4934. * @param {string} [opts.locale=null] - the locale code
  4935. * @param {string} [opts.numberingSystem=null] - the numbering system
  4936. * @param {string} [opts.locObj=null] - an existing locale object to use
  4937. * @return {Array}
  4938. */;
  4939. Info.weekdaysFormat = function weekdaysFormat(length, _temp7) {
  4940. if (length === void 0) {
  4941. length = "long";
  4942. }
  4943. var _ref7 = _temp7 === void 0 ? {} : _temp7,
  4944. _ref7$locale = _ref7.locale,
  4945. locale = _ref7$locale === void 0 ? null : _ref7$locale,
  4946. _ref7$numberingSystem = _ref7.numberingSystem,
  4947. numberingSystem = _ref7$numberingSystem === void 0 ? null : _ref7$numberingSystem,
  4948. _ref7$locObj = _ref7.locObj,
  4949. locObj = _ref7$locObj === void 0 ? null : _ref7$locObj;
  4950. return (locObj || Locale.create(locale, numberingSystem, null)).weekdays(length, true);
  4951. }
  4952. /**
  4953. * Return an array of meridiems.
  4954. * @param {Object} opts - options
  4955. * @param {string} [opts.locale] - the locale code
  4956. * @example Info.meridiems() //=> [ 'AM', 'PM' ]
  4957. * @example Info.meridiems({ locale: 'my' }) //=> [ 'နံနက်', 'ညနေ' ]
  4958. * @return {Array}
  4959. */;
  4960. Info.meridiems = function meridiems(_temp8) {
  4961. var _ref8 = _temp8 === void 0 ? {} : _temp8,
  4962. _ref8$locale = _ref8.locale,
  4963. locale = _ref8$locale === void 0 ? null : _ref8$locale;
  4964. return Locale.create(locale).meridiems();
  4965. }
  4966. /**
  4967. * Return an array of eras, such as ['BC', 'AD']. The locale can be specified, but the calendar system is always Gregorian.
  4968. * @param {string} [length='short'] - the length of the era representation, such as "short" or "long".
  4969. * @param {Object} opts - options
  4970. * @param {string} [opts.locale] - the locale code
  4971. * @example Info.eras() //=> [ 'BC', 'AD' ]
  4972. * @example Info.eras('long') //=> [ 'Before Christ', 'Anno Domini' ]
  4973. * @example Info.eras('long', { locale: 'fr' }) //=> [ 'avant Jésus-Christ', 'après Jésus-Christ' ]
  4974. * @return {Array}
  4975. */;
  4976. Info.eras = function eras(length, _temp9) {
  4977. if (length === void 0) {
  4978. length = "short";
  4979. }
  4980. var _ref9 = _temp9 === void 0 ? {} : _temp9,
  4981. _ref9$locale = _ref9.locale,
  4982. locale = _ref9$locale === void 0 ? null : _ref9$locale;
  4983. return Locale.create(locale, null, "gregory").eras(length);
  4984. }
  4985. /**
  4986. * Return the set of available features in this environment.
  4987. * Some features of Luxon are not available in all environments. For example, on older browsers, relative time formatting support is not available. Use this function to figure out if that's the case.
  4988. * Keys:
  4989. * * `relative`: whether this environment supports relative time formatting
  4990. * * `localeWeek`: whether this environment supports different weekdays for the start of the week based on the locale
  4991. * @example Info.features() //=> { relative: false, localeWeek: true }
  4992. * @return {Object}
  4993. */;
  4994. Info.features = function features() {
  4995. return {
  4996. relative: hasRelative(),
  4997. localeWeek: hasLocaleWeekInfo()
  4998. };
  4999. };
  5000. return Info;
  5001. }();
  5002. function dayDiff(earlier, later) {
  5003. var utcDayStart = function utcDayStart(dt) {
  5004. return dt.toUTC(0, {
  5005. keepLocalTime: true
  5006. }).startOf("day").valueOf();
  5007. },
  5008. ms = utcDayStart(later) - utcDayStart(earlier);
  5009. return Math.floor(Duration.fromMillis(ms).as("days"));
  5010. }
  5011. function highOrderDiffs(cursor, later, units) {
  5012. var differs = [["years", function (a, b) {
  5013. return b.year - a.year;
  5014. }], ["quarters", function (a, b) {
  5015. return b.quarter - a.quarter + (b.year - a.year) * 4;
  5016. }], ["months", function (a, b) {
  5017. return b.month - a.month + (b.year - a.year) * 12;
  5018. }], ["weeks", function (a, b) {
  5019. var days = dayDiff(a, b);
  5020. return (days - days % 7) / 7;
  5021. }], ["days", dayDiff]];
  5022. var results = {};
  5023. var earlier = cursor;
  5024. var lowestOrder, highWater;
  5025. /* This loop tries to diff using larger units first.
  5026. If we overshoot, we backtrack and try the next smaller unit.
  5027. "cursor" starts out at the earlier timestamp and moves closer and closer to "later"
  5028. as we use smaller and smaller units.
  5029. highWater keeps track of where we would be if we added one more of the smallest unit,
  5030. this is used later to potentially convert any difference smaller than the smallest higher order unit
  5031. into a fraction of that smallest higher order unit
  5032. */
  5033. for (var _i = 0, _differs = differs; _i < _differs.length; _i++) {
  5034. var _differs$_i = _differs[_i],
  5035. unit = _differs$_i[0],
  5036. differ = _differs$_i[1];
  5037. if (units.indexOf(unit) >= 0) {
  5038. lowestOrder = unit;
  5039. results[unit] = differ(cursor, later);
  5040. highWater = earlier.plus(results);
  5041. if (highWater > later) {
  5042. // we overshot the end point, backtrack cursor by 1
  5043. results[unit]--;
  5044. cursor = earlier.plus(results);
  5045. // if we are still overshooting now, we need to backtrack again
  5046. // this happens in certain situations when diffing times in different zones,
  5047. // because this calculation ignores time zones
  5048. if (cursor > later) {
  5049. // keep the "overshot by 1" around as highWater
  5050. highWater = cursor;
  5051. // backtrack cursor by 1
  5052. results[unit]--;
  5053. cursor = earlier.plus(results);
  5054. }
  5055. } else {
  5056. cursor = highWater;
  5057. }
  5058. }
  5059. }
  5060. return [cursor, results, highWater, lowestOrder];
  5061. }
  5062. function _diff (earlier, later, units, opts) {
  5063. var _highOrderDiffs = highOrderDiffs(earlier, later, units),
  5064. cursor = _highOrderDiffs[0],
  5065. results = _highOrderDiffs[1],
  5066. highWater = _highOrderDiffs[2],
  5067. lowestOrder = _highOrderDiffs[3];
  5068. var remainingMillis = later - cursor;
  5069. var lowerOrderUnits = units.filter(function (u) {
  5070. return ["hours", "minutes", "seconds", "milliseconds"].indexOf(u) >= 0;
  5071. });
  5072. if (lowerOrderUnits.length === 0) {
  5073. if (highWater < later) {
  5074. var _cursor$plus;
  5075. highWater = cursor.plus((_cursor$plus = {}, _cursor$plus[lowestOrder] = 1, _cursor$plus));
  5076. }
  5077. if (highWater !== cursor) {
  5078. results[lowestOrder] = (results[lowestOrder] || 0) + remainingMillis / (highWater - cursor);
  5079. }
  5080. }
  5081. var duration = Duration.fromObject(results, opts);
  5082. if (lowerOrderUnits.length > 0) {
  5083. var _Duration$fromMillis;
  5084. return (_Duration$fromMillis = Duration.fromMillis(remainingMillis, opts)).shiftTo.apply(_Duration$fromMillis, lowerOrderUnits).plus(duration);
  5085. } else {
  5086. return duration;
  5087. }
  5088. }
  5089. var MISSING_FTP = "missing Intl.DateTimeFormat.formatToParts support";
  5090. function intUnit(regex, post) {
  5091. if (post === void 0) {
  5092. post = function post(i) {
  5093. return i;
  5094. };
  5095. }
  5096. return {
  5097. regex: regex,
  5098. deser: function deser(_ref) {
  5099. var s = _ref[0];
  5100. return post(parseDigits(s));
  5101. }
  5102. };
  5103. }
  5104. var NBSP = String.fromCharCode(160);
  5105. var spaceOrNBSP = "[ " + NBSP + "]";
  5106. var spaceOrNBSPRegExp = new RegExp(spaceOrNBSP, "g");
  5107. function fixListRegex(s) {
  5108. // make dots optional and also make them literal
  5109. // make space and non breakable space characters interchangeable
  5110. return s.replace(/\./g, "\\.?").replace(spaceOrNBSPRegExp, spaceOrNBSP);
  5111. }
  5112. function stripInsensitivities(s) {
  5113. return s.replace(/\./g, "") // ignore dots that were made optional
  5114. .replace(spaceOrNBSPRegExp, " ") // interchange space and nbsp
  5115. .toLowerCase();
  5116. }
  5117. function oneOf(strings, startIndex) {
  5118. if (strings === null) {
  5119. return null;
  5120. } else {
  5121. return {
  5122. regex: RegExp(strings.map(fixListRegex).join("|")),
  5123. deser: function deser(_ref2) {
  5124. var s = _ref2[0];
  5125. return strings.findIndex(function (i) {
  5126. return stripInsensitivities(s) === stripInsensitivities(i);
  5127. }) + startIndex;
  5128. }
  5129. };
  5130. }
  5131. }
  5132. function offset(regex, groups) {
  5133. return {
  5134. regex: regex,
  5135. deser: function deser(_ref3) {
  5136. var h = _ref3[1],
  5137. m = _ref3[2];
  5138. return signedOffset(h, m);
  5139. },
  5140. groups: groups
  5141. };
  5142. }
  5143. function simple(regex) {
  5144. return {
  5145. regex: regex,
  5146. deser: function deser(_ref4) {
  5147. var s = _ref4[0];
  5148. return s;
  5149. }
  5150. };
  5151. }
  5152. function escapeToken(value) {
  5153. return value.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&");
  5154. }
  5155. /**
  5156. * @param token
  5157. * @param {Locale} loc
  5158. */
  5159. function unitForToken(token, loc) {
  5160. var one = digitRegex(loc),
  5161. two = digitRegex(loc, "{2}"),
  5162. three = digitRegex(loc, "{3}"),
  5163. four = digitRegex(loc, "{4}"),
  5164. six = digitRegex(loc, "{6}"),
  5165. oneOrTwo = digitRegex(loc, "{1,2}"),
  5166. oneToThree = digitRegex(loc, "{1,3}"),
  5167. oneToSix = digitRegex(loc, "{1,6}"),
  5168. oneToNine = digitRegex(loc, "{1,9}"),
  5169. twoToFour = digitRegex(loc, "{2,4}"),
  5170. fourToSix = digitRegex(loc, "{4,6}"),
  5171. literal = function literal(t) {
  5172. return {
  5173. regex: RegExp(escapeToken(t.val)),
  5174. deser: function deser(_ref5) {
  5175. var s = _ref5[0];
  5176. return s;
  5177. },
  5178. literal: true
  5179. };
  5180. },
  5181. unitate = function unitate(t) {
  5182. if (token.literal) {
  5183. return literal(t);
  5184. }
  5185. switch (t.val) {
  5186. // era
  5187. case "G":
  5188. return oneOf(loc.eras("short"), 0);
  5189. case "GG":
  5190. return oneOf(loc.eras("long"), 0);
  5191. // years
  5192. case "y":
  5193. return intUnit(oneToSix);
  5194. case "yy":
  5195. return intUnit(twoToFour, untruncateYear);
  5196. case "yyyy":
  5197. return intUnit(four);
  5198. case "yyyyy":
  5199. return intUnit(fourToSix);
  5200. case "yyyyyy":
  5201. return intUnit(six);
  5202. // months
  5203. case "M":
  5204. return intUnit(oneOrTwo);
  5205. case "MM":
  5206. return intUnit(two);
  5207. case "MMM":
  5208. return oneOf(loc.months("short", true), 1);
  5209. case "MMMM":
  5210. return oneOf(loc.months("long", true), 1);
  5211. case "L":
  5212. return intUnit(oneOrTwo);
  5213. case "LL":
  5214. return intUnit(two);
  5215. case "LLL":
  5216. return oneOf(loc.months("short", false), 1);
  5217. case "LLLL":
  5218. return oneOf(loc.months("long", false), 1);
  5219. // dates
  5220. case "d":
  5221. return intUnit(oneOrTwo);
  5222. case "dd":
  5223. return intUnit(two);
  5224. // ordinals
  5225. case "o":
  5226. return intUnit(oneToThree);
  5227. case "ooo":
  5228. return intUnit(three);
  5229. // time
  5230. case "HH":
  5231. return intUnit(two);
  5232. case "H":
  5233. return intUnit(oneOrTwo);
  5234. case "hh":
  5235. return intUnit(two);
  5236. case "h":
  5237. return intUnit(oneOrTwo);
  5238. case "mm":
  5239. return intUnit(two);
  5240. case "m":
  5241. return intUnit(oneOrTwo);
  5242. case "q":
  5243. return intUnit(oneOrTwo);
  5244. case "qq":
  5245. return intUnit(two);
  5246. case "s":
  5247. return intUnit(oneOrTwo);
  5248. case "ss":
  5249. return intUnit(two);
  5250. case "S":
  5251. return intUnit(oneToThree);
  5252. case "SSS":
  5253. return intUnit(three);
  5254. case "u":
  5255. return simple(oneToNine);
  5256. case "uu":
  5257. return simple(oneOrTwo);
  5258. case "uuu":
  5259. return intUnit(one);
  5260. // meridiem
  5261. case "a":
  5262. return oneOf(loc.meridiems(), 0);
  5263. // weekYear (k)
  5264. case "kkkk":
  5265. return intUnit(four);
  5266. case "kk":
  5267. return intUnit(twoToFour, untruncateYear);
  5268. // weekNumber (W)
  5269. case "W":
  5270. return intUnit(oneOrTwo);
  5271. case "WW":
  5272. return intUnit(two);
  5273. // weekdays
  5274. case "E":
  5275. case "c":
  5276. return intUnit(one);
  5277. case "EEE":
  5278. return oneOf(loc.weekdays("short", false), 1);
  5279. case "EEEE":
  5280. return oneOf(loc.weekdays("long", false), 1);
  5281. case "ccc":
  5282. return oneOf(loc.weekdays("short", true), 1);
  5283. case "cccc":
  5284. return oneOf(loc.weekdays("long", true), 1);
  5285. // offset/zone
  5286. case "Z":
  5287. case "ZZ":
  5288. return offset(new RegExp("([+-]" + oneOrTwo.source + ")(?::(" + two.source + "))?"), 2);
  5289. case "ZZZ":
  5290. return offset(new RegExp("([+-]" + oneOrTwo.source + ")(" + two.source + ")?"), 2);
  5291. // we don't support ZZZZ (PST) or ZZZZZ (Pacific Standard Time) in parsing
  5292. // because we don't have any way to figure out what they are
  5293. case "z":
  5294. return simple(/[a-z_+-/]{1,256}?/i);
  5295. // this special-case "token" represents a place where a macro-token expanded into a white-space literal
  5296. // in this case we accept any non-newline white-space
  5297. case " ":
  5298. return simple(/[^\S\n\r]/);
  5299. default:
  5300. return literal(t);
  5301. }
  5302. };
  5303. var unit = unitate(token) || {
  5304. invalidReason: MISSING_FTP
  5305. };
  5306. unit.token = token;
  5307. return unit;
  5308. }
  5309. var partTypeStyleToTokenVal = {
  5310. year: {
  5311. "2-digit": "yy",
  5312. numeric: "yyyyy"
  5313. },
  5314. month: {
  5315. numeric: "M",
  5316. "2-digit": "MM",
  5317. short: "MMM",
  5318. long: "MMMM"
  5319. },
  5320. day: {
  5321. numeric: "d",
  5322. "2-digit": "dd"
  5323. },
  5324. weekday: {
  5325. short: "EEE",
  5326. long: "EEEE"
  5327. },
  5328. dayperiod: "a",
  5329. dayPeriod: "a",
  5330. hour12: {
  5331. numeric: "h",
  5332. "2-digit": "hh"
  5333. },
  5334. hour24: {
  5335. numeric: "H",
  5336. "2-digit": "HH"
  5337. },
  5338. minute: {
  5339. numeric: "m",
  5340. "2-digit": "mm"
  5341. },
  5342. second: {
  5343. numeric: "s",
  5344. "2-digit": "ss"
  5345. },
  5346. timeZoneName: {
  5347. long: "ZZZZZ",
  5348. short: "ZZZ"
  5349. }
  5350. };
  5351. function tokenForPart(part, formatOpts, resolvedOpts) {
  5352. var type = part.type,
  5353. value = part.value;
  5354. if (type === "literal") {
  5355. var isSpace = /^\s+$/.test(value);
  5356. return {
  5357. literal: !isSpace,
  5358. val: isSpace ? " " : value
  5359. };
  5360. }
  5361. var style = formatOpts[type];
  5362. // The user might have explicitly specified hour12 or hourCycle
  5363. // if so, respect their decision
  5364. // if not, refer back to the resolvedOpts, which are based on the locale
  5365. var actualType = type;
  5366. if (type === "hour") {
  5367. if (formatOpts.hour12 != null) {
  5368. actualType = formatOpts.hour12 ? "hour12" : "hour24";
  5369. } else if (formatOpts.hourCycle != null) {
  5370. if (formatOpts.hourCycle === "h11" || formatOpts.hourCycle === "h12") {
  5371. actualType = "hour12";
  5372. } else {
  5373. actualType = "hour24";
  5374. }
  5375. } else {
  5376. // tokens only differentiate between 24 hours or not,
  5377. // so we do not need to check hourCycle here, which is less supported anyways
  5378. actualType = resolvedOpts.hour12 ? "hour12" : "hour24";
  5379. }
  5380. }
  5381. var val = partTypeStyleToTokenVal[actualType];
  5382. if (typeof val === "object") {
  5383. val = val[style];
  5384. }
  5385. if (val) {
  5386. return {
  5387. literal: false,
  5388. val: val
  5389. };
  5390. }
  5391. return undefined;
  5392. }
  5393. function buildRegex(units) {
  5394. var re = units.map(function (u) {
  5395. return u.regex;
  5396. }).reduce(function (f, r) {
  5397. return f + "(" + r.source + ")";
  5398. }, "");
  5399. return ["^" + re + "$", units];
  5400. }
  5401. function match(input, regex, handlers) {
  5402. var matches = input.match(regex);
  5403. if (matches) {
  5404. var all = {};
  5405. var matchIndex = 1;
  5406. for (var i in handlers) {
  5407. if (hasOwnProperty(handlers, i)) {
  5408. var h = handlers[i],
  5409. groups = h.groups ? h.groups + 1 : 1;
  5410. if (!h.literal && h.token) {
  5411. all[h.token.val[0]] = h.deser(matches.slice(matchIndex, matchIndex + groups));
  5412. }
  5413. matchIndex += groups;
  5414. }
  5415. }
  5416. return [matches, all];
  5417. } else {
  5418. return [matches, {}];
  5419. }
  5420. }
  5421. function dateTimeFromMatches(matches) {
  5422. var toField = function toField(token) {
  5423. switch (token) {
  5424. case "S":
  5425. return "millisecond";
  5426. case "s":
  5427. return "second";
  5428. case "m":
  5429. return "minute";
  5430. case "h":
  5431. case "H":
  5432. return "hour";
  5433. case "d":
  5434. return "day";
  5435. case "o":
  5436. return "ordinal";
  5437. case "L":
  5438. case "M":
  5439. return "month";
  5440. case "y":
  5441. return "year";
  5442. case "E":
  5443. case "c":
  5444. return "weekday";
  5445. case "W":
  5446. return "weekNumber";
  5447. case "k":
  5448. return "weekYear";
  5449. case "q":
  5450. return "quarter";
  5451. default:
  5452. return null;
  5453. }
  5454. };
  5455. var zone = null;
  5456. var specificOffset;
  5457. if (!isUndefined(matches.z)) {
  5458. zone = IANAZone.create(matches.z);
  5459. }
  5460. if (!isUndefined(matches.Z)) {
  5461. if (!zone) {
  5462. zone = new FixedOffsetZone(matches.Z);
  5463. }
  5464. specificOffset = matches.Z;
  5465. }
  5466. if (!isUndefined(matches.q)) {
  5467. matches.M = (matches.q - 1) * 3 + 1;
  5468. }
  5469. if (!isUndefined(matches.h)) {
  5470. if (matches.h < 12 && matches.a === 1) {
  5471. matches.h += 12;
  5472. } else if (matches.h === 12 && matches.a === 0) {
  5473. matches.h = 0;
  5474. }
  5475. }
  5476. if (matches.G === 0 && matches.y) {
  5477. matches.y = -matches.y;
  5478. }
  5479. if (!isUndefined(matches.u)) {
  5480. matches.S = parseMillis(matches.u);
  5481. }
  5482. var vals = Object.keys(matches).reduce(function (r, k) {
  5483. var f = toField(k);
  5484. if (f) {
  5485. r[f] = matches[k];
  5486. }
  5487. return r;
  5488. }, {});
  5489. return [vals, zone, specificOffset];
  5490. }
  5491. var dummyDateTimeCache = null;
  5492. function getDummyDateTime() {
  5493. if (!dummyDateTimeCache) {
  5494. dummyDateTimeCache = DateTime.fromMillis(1555555555555);
  5495. }
  5496. return dummyDateTimeCache;
  5497. }
  5498. function maybeExpandMacroToken(token, locale) {
  5499. if (token.literal) {
  5500. return token;
  5501. }
  5502. var formatOpts = Formatter.macroTokenToFormatOpts(token.val);
  5503. var tokens = formatOptsToTokens(formatOpts, locale);
  5504. if (tokens == null || tokens.includes(undefined)) {
  5505. return token;
  5506. }
  5507. return tokens;
  5508. }
  5509. function expandMacroTokens(tokens, locale) {
  5510. var _Array$prototype;
  5511. return (_Array$prototype = Array.prototype).concat.apply(_Array$prototype, tokens.map(function (t) {
  5512. return maybeExpandMacroToken(t, locale);
  5513. }));
  5514. }
  5515. /**
  5516. * @private
  5517. */
  5518. var TokenParser = /*#__PURE__*/function () {
  5519. function TokenParser(locale, format) {
  5520. this.locale = locale;
  5521. this.format = format;
  5522. this.tokens = expandMacroTokens(Formatter.parseFormat(format), locale);
  5523. this.units = this.tokens.map(function (t) {
  5524. return unitForToken(t, locale);
  5525. });
  5526. this.disqualifyingUnit = this.units.find(function (t) {
  5527. return t.invalidReason;
  5528. });
  5529. if (!this.disqualifyingUnit) {
  5530. var _buildRegex = buildRegex(this.units),
  5531. regexString = _buildRegex[0],
  5532. handlers = _buildRegex[1];
  5533. this.regex = RegExp(regexString, "i");
  5534. this.handlers = handlers;
  5535. }
  5536. }
  5537. var _proto = TokenParser.prototype;
  5538. _proto.explainFromTokens = function explainFromTokens(input) {
  5539. if (!this.isValid) {
  5540. return {
  5541. input: input,
  5542. tokens: this.tokens,
  5543. invalidReason: this.invalidReason
  5544. };
  5545. } else {
  5546. var _match = match(input, this.regex, this.handlers),
  5547. rawMatches = _match[0],
  5548. matches = _match[1],
  5549. _ref6 = matches ? dateTimeFromMatches(matches) : [null, null, undefined],
  5550. result = _ref6[0],
  5551. zone = _ref6[1],
  5552. specificOffset = _ref6[2];
  5553. if (hasOwnProperty(matches, "a") && hasOwnProperty(matches, "H")) {
  5554. throw new ConflictingSpecificationError("Can't include meridiem when specifying 24-hour format");
  5555. }
  5556. return {
  5557. input: input,
  5558. tokens: this.tokens,
  5559. regex: this.regex,
  5560. rawMatches: rawMatches,
  5561. matches: matches,
  5562. result: result,
  5563. zone: zone,
  5564. specificOffset: specificOffset
  5565. };
  5566. }
  5567. };
  5568. _createClass(TokenParser, [{
  5569. key: "isValid",
  5570. get: function get() {
  5571. return !this.disqualifyingUnit;
  5572. }
  5573. }, {
  5574. key: "invalidReason",
  5575. get: function get() {
  5576. return this.disqualifyingUnit ? this.disqualifyingUnit.invalidReason : null;
  5577. }
  5578. }]);
  5579. return TokenParser;
  5580. }();
  5581. function explainFromTokens(locale, input, format) {
  5582. var parser = new TokenParser(locale, format);
  5583. return parser.explainFromTokens(input);
  5584. }
  5585. function parseFromTokens(locale, input, format) {
  5586. var _explainFromTokens = explainFromTokens(locale, input, format),
  5587. result = _explainFromTokens.result,
  5588. zone = _explainFromTokens.zone,
  5589. specificOffset = _explainFromTokens.specificOffset,
  5590. invalidReason = _explainFromTokens.invalidReason;
  5591. return [result, zone, specificOffset, invalidReason];
  5592. }
  5593. function formatOptsToTokens(formatOpts, locale) {
  5594. if (!formatOpts) {
  5595. return null;
  5596. }
  5597. var formatter = Formatter.create(locale, formatOpts);
  5598. var df = formatter.dtFormatter(getDummyDateTime());
  5599. var parts = df.formatToParts();
  5600. var resolvedOpts = df.resolvedOptions();
  5601. return parts.map(function (p) {
  5602. return tokenForPart(p, formatOpts, resolvedOpts);
  5603. });
  5604. }
  5605. var INVALID = "Invalid DateTime";
  5606. var MAX_DATE = 8.64e15;
  5607. function unsupportedZone(zone) {
  5608. return new Invalid("unsupported zone", "the zone \"" + zone.name + "\" is not supported");
  5609. }
  5610. // we cache week data on the DT object and this intermediates the cache
  5611. /**
  5612. * @param {DateTime} dt
  5613. */
  5614. function possiblyCachedWeekData(dt) {
  5615. if (dt.weekData === null) {
  5616. dt.weekData = gregorianToWeek(dt.c);
  5617. }
  5618. return dt.weekData;
  5619. }
  5620. /**
  5621. * @param {DateTime} dt
  5622. */
  5623. function possiblyCachedLocalWeekData(dt) {
  5624. if (dt.localWeekData === null) {
  5625. dt.localWeekData = gregorianToWeek(dt.c, dt.loc.getMinDaysInFirstWeek(), dt.loc.getStartOfWeek());
  5626. }
  5627. return dt.localWeekData;
  5628. }
  5629. // clone really means, "make a new object with these modifications". all "setters" really use this
  5630. // to create a new object while only changing some of the properties
  5631. function clone(inst, alts) {
  5632. var current = {
  5633. ts: inst.ts,
  5634. zone: inst.zone,
  5635. c: inst.c,
  5636. o: inst.o,
  5637. loc: inst.loc,
  5638. invalid: inst.invalid
  5639. };
  5640. return new DateTime(_extends({}, current, alts, {
  5641. old: current
  5642. }));
  5643. }
  5644. // find the right offset a given local time. The o input is our guess, which determines which
  5645. // offset we'll pick in ambiguous cases (e.g. there are two 3 AMs b/c Fallback DST)
  5646. function fixOffset(localTS, o, tz) {
  5647. // Our UTC time is just a guess because our offset is just a guess
  5648. var utcGuess = localTS - o * 60 * 1000;
  5649. // Test whether the zone matches the offset for this ts
  5650. var o2 = tz.offset(utcGuess);
  5651. // If so, offset didn't change and we're done
  5652. if (o === o2) {
  5653. return [utcGuess, o];
  5654. }
  5655. // If not, change the ts by the difference in the offset
  5656. utcGuess -= (o2 - o) * 60 * 1000;
  5657. // If that gives us the local time we want, we're done
  5658. var o3 = tz.offset(utcGuess);
  5659. if (o2 === o3) {
  5660. return [utcGuess, o2];
  5661. }
  5662. // If it's different, we're in a hole time. The offset has changed, but the we don't adjust the time
  5663. return [localTS - Math.min(o2, o3) * 60 * 1000, Math.max(o2, o3)];
  5664. }
  5665. // convert an epoch timestamp into a calendar object with the given offset
  5666. function tsToObj(ts, offset) {
  5667. ts += offset * 60 * 1000;
  5668. var d = new Date(ts);
  5669. return {
  5670. year: d.getUTCFullYear(),
  5671. month: d.getUTCMonth() + 1,
  5672. day: d.getUTCDate(),
  5673. hour: d.getUTCHours(),
  5674. minute: d.getUTCMinutes(),
  5675. second: d.getUTCSeconds(),
  5676. millisecond: d.getUTCMilliseconds()
  5677. };
  5678. }
  5679. // convert a calendar object to a epoch timestamp
  5680. function objToTS(obj, offset, zone) {
  5681. return fixOffset(objToLocalTS(obj), offset, zone);
  5682. }
  5683. // create a new DT instance by adding a duration, adjusting for DSTs
  5684. function adjustTime(inst, dur) {
  5685. var oPre = inst.o,
  5686. year = inst.c.year + Math.trunc(dur.years),
  5687. month = inst.c.month + Math.trunc(dur.months) + Math.trunc(dur.quarters) * 3,
  5688. c = _extends({}, inst.c, {
  5689. year: year,
  5690. month: month,
  5691. day: Math.min(inst.c.day, daysInMonth(year, month)) + Math.trunc(dur.days) + Math.trunc(dur.weeks) * 7
  5692. }),
  5693. millisToAdd = Duration.fromObject({
  5694. years: dur.years - Math.trunc(dur.years),
  5695. quarters: dur.quarters - Math.trunc(dur.quarters),
  5696. months: dur.months - Math.trunc(dur.months),
  5697. weeks: dur.weeks - Math.trunc(dur.weeks),
  5698. days: dur.days - Math.trunc(dur.days),
  5699. hours: dur.hours,
  5700. minutes: dur.minutes,
  5701. seconds: dur.seconds,
  5702. milliseconds: dur.milliseconds
  5703. }).as("milliseconds"),
  5704. localTS = objToLocalTS(c);
  5705. var _fixOffset = fixOffset(localTS, oPre, inst.zone),
  5706. ts = _fixOffset[0],
  5707. o = _fixOffset[1];
  5708. if (millisToAdd !== 0) {
  5709. ts += millisToAdd;
  5710. // that could have changed the offset by going over a DST, but we want to keep the ts the same
  5711. o = inst.zone.offset(ts);
  5712. }
  5713. return {
  5714. ts: ts,
  5715. o: o
  5716. };
  5717. }
  5718. // helper useful in turning the results of parsing into real dates
  5719. // by handling the zone options
  5720. function parseDataToDateTime(parsed, parsedZone, opts, format, text, specificOffset) {
  5721. var setZone = opts.setZone,
  5722. zone = opts.zone;
  5723. if (parsed && Object.keys(parsed).length !== 0 || parsedZone) {
  5724. var interpretationZone = parsedZone || zone,
  5725. inst = DateTime.fromObject(parsed, _extends({}, opts, {
  5726. zone: interpretationZone,
  5727. specificOffset: specificOffset
  5728. }));
  5729. return setZone ? inst : inst.setZone(zone);
  5730. } else {
  5731. return DateTime.invalid(new Invalid("unparsable", "the input \"" + text + "\" can't be parsed as " + format));
  5732. }
  5733. }
  5734. // if you want to output a technical format (e.g. RFC 2822), this helper
  5735. // helps handle the details
  5736. function toTechFormat(dt, format, allowZ) {
  5737. if (allowZ === void 0) {
  5738. allowZ = true;
  5739. }
  5740. return dt.isValid ? Formatter.create(Locale.create("en-US"), {
  5741. allowZ: allowZ,
  5742. forceSimple: true
  5743. }).formatDateTimeFromString(dt, format) : null;
  5744. }
  5745. function _toISODate(o, extended) {
  5746. var longFormat = o.c.year > 9999 || o.c.year < 0;
  5747. var c = "";
  5748. if (longFormat && o.c.year >= 0) c += "+";
  5749. c += padStart(o.c.year, longFormat ? 6 : 4);
  5750. if (extended) {
  5751. c += "-";
  5752. c += padStart(o.c.month);
  5753. c += "-";
  5754. c += padStart(o.c.day);
  5755. } else {
  5756. c += padStart(o.c.month);
  5757. c += padStart(o.c.day);
  5758. }
  5759. return c;
  5760. }
  5761. function _toISOTime(o, extended, suppressSeconds, suppressMilliseconds, includeOffset, extendedZone) {
  5762. var c = padStart(o.c.hour);
  5763. if (extended) {
  5764. c += ":";
  5765. c += padStart(o.c.minute);
  5766. if (o.c.millisecond !== 0 || o.c.second !== 0 || !suppressSeconds) {
  5767. c += ":";
  5768. }
  5769. } else {
  5770. c += padStart(o.c.minute);
  5771. }
  5772. if (o.c.millisecond !== 0 || o.c.second !== 0 || !suppressSeconds) {
  5773. c += padStart(o.c.second);
  5774. if (o.c.millisecond !== 0 || !suppressMilliseconds) {
  5775. c += ".";
  5776. c += padStart(o.c.millisecond, 3);
  5777. }
  5778. }
  5779. if (includeOffset) {
  5780. if (o.isOffsetFixed && o.offset === 0 && !extendedZone) {
  5781. c += "Z";
  5782. } else if (o.o < 0) {
  5783. c += "-";
  5784. c += padStart(Math.trunc(-o.o / 60));
  5785. c += ":";
  5786. c += padStart(Math.trunc(-o.o % 60));
  5787. } else {
  5788. c += "+";
  5789. c += padStart(Math.trunc(o.o / 60));
  5790. c += ":";
  5791. c += padStart(Math.trunc(o.o % 60));
  5792. }
  5793. }
  5794. if (extendedZone) {
  5795. c += "[" + o.zone.ianaName + "]";
  5796. }
  5797. return c;
  5798. }
  5799. // defaults for unspecified units in the supported calendars
  5800. var defaultUnitValues = {
  5801. month: 1,
  5802. day: 1,
  5803. hour: 0,
  5804. minute: 0,
  5805. second: 0,
  5806. millisecond: 0
  5807. },
  5808. defaultWeekUnitValues = {
  5809. weekNumber: 1,
  5810. weekday: 1,
  5811. hour: 0,
  5812. minute: 0,
  5813. second: 0,
  5814. millisecond: 0
  5815. },
  5816. defaultOrdinalUnitValues = {
  5817. ordinal: 1,
  5818. hour: 0,
  5819. minute: 0,
  5820. second: 0,
  5821. millisecond: 0
  5822. };
  5823. // Units in the supported calendars, sorted by bigness
  5824. var orderedUnits = ["year", "month", "day", "hour", "minute", "second", "millisecond"],
  5825. orderedWeekUnits = ["weekYear", "weekNumber", "weekday", "hour", "minute", "second", "millisecond"],
  5826. orderedOrdinalUnits = ["year", "ordinal", "hour", "minute", "second", "millisecond"];
  5827. // standardize case and plurality in units
  5828. function normalizeUnit(unit) {
  5829. var normalized = {
  5830. year: "year",
  5831. years: "year",
  5832. month: "month",
  5833. months: "month",
  5834. day: "day",
  5835. days: "day",
  5836. hour: "hour",
  5837. hours: "hour",
  5838. minute: "minute",
  5839. minutes: "minute",
  5840. quarter: "quarter",
  5841. quarters: "quarter",
  5842. second: "second",
  5843. seconds: "second",
  5844. millisecond: "millisecond",
  5845. milliseconds: "millisecond",
  5846. weekday: "weekday",
  5847. weekdays: "weekday",
  5848. weeknumber: "weekNumber",
  5849. weeksnumber: "weekNumber",
  5850. weeknumbers: "weekNumber",
  5851. weekyear: "weekYear",
  5852. weekyears: "weekYear",
  5853. ordinal: "ordinal"
  5854. }[unit.toLowerCase()];
  5855. if (!normalized) throw new InvalidUnitError(unit);
  5856. return normalized;
  5857. }
  5858. function normalizeUnitWithLocalWeeks(unit) {
  5859. switch (unit.toLowerCase()) {
  5860. case "localweekday":
  5861. case "localweekdays":
  5862. return "localWeekday";
  5863. case "localweeknumber":
  5864. case "localweeknumbers":
  5865. return "localWeekNumber";
  5866. case "localweekyear":
  5867. case "localweekyears":
  5868. return "localWeekYear";
  5869. default:
  5870. return normalizeUnit(unit);
  5871. }
  5872. }
  5873. // cache offsets for zones based on the current timestamp when this function is
  5874. // first called. When we are handling a datetime from components like (year,
  5875. // month, day, hour) in a time zone, we need a guess about what the timezone
  5876. // offset is so that we can convert into a UTC timestamp. One way is to find the
  5877. // offset of now in the zone. The actual date may have a different offset (for
  5878. // example, if we handle a date in June while we're in December in a zone that
  5879. // observes DST), but we can check and adjust that.
  5880. //
  5881. // When handling many dates, calculating the offset for now every time is
  5882. // expensive. It's just a guess, so we can cache the offset to use even if we
  5883. // are right on a time change boundary (we'll just correct in the other
  5884. // direction). Using a timestamp from first read is a slight optimization for
  5885. // handling dates close to the current date, since those dates will usually be
  5886. // in the same offset (we could set the timestamp statically, instead). We use a
  5887. // single timestamp for all zones to make things a bit more predictable.
  5888. //
  5889. // This is safe for quickDT (used by local() and utc()) because we don't fill in
  5890. // higher-order units from tsNow (as we do in fromObject, this requires that
  5891. // offset is calculated from tsNow).
  5892. function guessOffsetForZone(zone) {
  5893. if (!zoneOffsetGuessCache[zone]) {
  5894. if (zoneOffsetTs === undefined) {
  5895. zoneOffsetTs = Settings.now();
  5896. }
  5897. zoneOffsetGuessCache[zone] = zone.offset(zoneOffsetTs);
  5898. }
  5899. return zoneOffsetGuessCache[zone];
  5900. }
  5901. // this is a dumbed down version of fromObject() that runs about 60% faster
  5902. // but doesn't do any validation, makes a bunch of assumptions about what units
  5903. // are present, and so on.
  5904. function quickDT(obj, opts) {
  5905. var zone = normalizeZone(opts.zone, Settings.defaultZone);
  5906. if (!zone.isValid) {
  5907. return DateTime.invalid(unsupportedZone(zone));
  5908. }
  5909. var loc = Locale.fromObject(opts);
  5910. var ts, o;
  5911. // assume we have the higher-order units
  5912. if (!isUndefined(obj.year)) {
  5913. for (var _i = 0, _orderedUnits = orderedUnits; _i < _orderedUnits.length; _i++) {
  5914. var u = _orderedUnits[_i];
  5915. if (isUndefined(obj[u])) {
  5916. obj[u] = defaultUnitValues[u];
  5917. }
  5918. }
  5919. var invalid = hasInvalidGregorianData(obj) || hasInvalidTimeData(obj);
  5920. if (invalid) {
  5921. return DateTime.invalid(invalid);
  5922. }
  5923. var offsetProvis = guessOffsetForZone(zone);
  5924. var _objToTS = objToTS(obj, offsetProvis, zone);
  5925. ts = _objToTS[0];
  5926. o = _objToTS[1];
  5927. } else {
  5928. ts = Settings.now();
  5929. }
  5930. return new DateTime({
  5931. ts: ts,
  5932. zone: zone,
  5933. loc: loc,
  5934. o: o
  5935. });
  5936. }
  5937. function diffRelative(start, end, opts) {
  5938. var round = isUndefined(opts.round) ? true : opts.round,
  5939. format = function format(c, unit) {
  5940. c = roundTo(c, round || opts.calendary ? 0 : 2, true);
  5941. var formatter = end.loc.clone(opts).relFormatter(opts);
  5942. return formatter.format(c, unit);
  5943. },
  5944. differ = function differ(unit) {
  5945. if (opts.calendary) {
  5946. if (!end.hasSame(start, unit)) {
  5947. return end.startOf(unit).diff(start.startOf(unit), unit).get(unit);
  5948. } else return 0;
  5949. } else {
  5950. return end.diff(start, unit).get(unit);
  5951. }
  5952. };
  5953. if (opts.unit) {
  5954. return format(differ(opts.unit), opts.unit);
  5955. }
  5956. for (var _iterator = _createForOfIteratorHelperLoose(opts.units), _step; !(_step = _iterator()).done;) {
  5957. var unit = _step.value;
  5958. var count = differ(unit);
  5959. if (Math.abs(count) >= 1) {
  5960. return format(count, unit);
  5961. }
  5962. }
  5963. return format(start > end ? -0 : 0, opts.units[opts.units.length - 1]);
  5964. }
  5965. function lastOpts(argList) {
  5966. var opts = {},
  5967. args;
  5968. if (argList.length > 0 && typeof argList[argList.length - 1] === "object") {
  5969. opts = argList[argList.length - 1];
  5970. args = Array.from(argList).slice(0, argList.length - 1);
  5971. } else {
  5972. args = Array.from(argList);
  5973. }
  5974. return [opts, args];
  5975. }
  5976. /**
  5977. * Timestamp to use for cached zone offset guesses (exposed for test)
  5978. */
  5979. var zoneOffsetTs;
  5980. /**
  5981. * Cache for zone offset guesses (exposed for test).
  5982. *
  5983. * This optimizes quickDT via guessOffsetForZone to avoid repeated calls of
  5984. * zone.offset().
  5985. */
  5986. var zoneOffsetGuessCache = {};
  5987. /**
  5988. * A DateTime is an immutable data structure representing a specific date and time and accompanying methods. It contains class and instance methods for creating, parsing, interrogating, transforming, and formatting them.
  5989. *
  5990. * A DateTime comprises of:
  5991. * * A timestamp. Each DateTime instance refers to a specific millisecond of the Unix epoch.
  5992. * * A time zone. Each instance is considered in the context of a specific zone (by default the local system's zone).
  5993. * * Configuration properties that effect how output strings are formatted, such as `locale`, `numberingSystem`, and `outputCalendar`.
  5994. *
  5995. * Here is a brief overview of the most commonly used functionality it provides:
  5996. *
  5997. * * **Creation**: To create a DateTime from its components, use one of its factory class methods: {@link DateTime.local}, {@link DateTime.utc}, and (most flexibly) {@link DateTime.fromObject}. To create one from a standard string format, use {@link DateTime.fromISO}, {@link DateTime.fromHTTP}, and {@link DateTime.fromRFC2822}. To create one from a custom string format, use {@link DateTime.fromFormat}. To create one from a native JS date, use {@link DateTime.fromJSDate}.
  5998. * * **Gregorian calendar and time**: To examine the Gregorian properties of a DateTime individually (i.e as opposed to collectively through {@link DateTime#toObject}), use the {@link DateTime#year}, {@link DateTime#month},
  5999. * {@link DateTime#day}, {@link DateTime#hour}, {@link DateTime#minute}, {@link DateTime#second}, {@link DateTime#millisecond} accessors.
  6000. * * **Week calendar**: For ISO week calendar attributes, see the {@link DateTime#weekYear}, {@link DateTime#weekNumber}, and {@link DateTime#weekday} accessors.
  6001. * * **Configuration** See the {@link DateTime#locale} and {@link DateTime#numberingSystem} accessors.
  6002. * * **Transformation**: To transform the DateTime into other DateTimes, use {@link DateTime#set}, {@link DateTime#reconfigure}, {@link DateTime#setZone}, {@link DateTime#setLocale}, {@link DateTime.plus}, {@link DateTime#minus}, {@link DateTime#endOf}, {@link DateTime#startOf}, {@link DateTime#toUTC}, and {@link DateTime#toLocal}.
  6003. * * **Output**: To convert the DateTime to other representations, use the {@link DateTime#toRelative}, {@link DateTime#toRelativeCalendar}, {@link DateTime#toJSON}, {@link DateTime#toISO}, {@link DateTime#toHTTP}, {@link DateTime#toObject}, {@link DateTime#toRFC2822}, {@link DateTime#toString}, {@link DateTime#toLocaleString}, {@link DateTime#toFormat}, {@link DateTime#toMillis} and {@link DateTime#toJSDate}.
  6004. *
  6005. * There's plenty others documented below. In addition, for more information on subtler topics like internationalization, time zones, alternative calendars, validity, and so on, see the external documentation.
  6006. */
  6007. var DateTime = /*#__PURE__*/function (_Symbol$for) {
  6008. /**
  6009. * @access private
  6010. */
  6011. function DateTime(config) {
  6012. var zone = config.zone || Settings.defaultZone;
  6013. var invalid = config.invalid || (Number.isNaN(config.ts) ? new Invalid("invalid input") : null) || (!zone.isValid ? unsupportedZone(zone) : null);
  6014. /**
  6015. * @access private
  6016. */
  6017. this.ts = isUndefined(config.ts) ? Settings.now() : config.ts;
  6018. var c = null,
  6019. o = null;
  6020. if (!invalid) {
  6021. var unchanged = config.old && config.old.ts === this.ts && config.old.zone.equals(zone);
  6022. if (unchanged) {
  6023. var _ref = [config.old.c, config.old.o];
  6024. c = _ref[0];
  6025. o = _ref[1];
  6026. } else {
  6027. // If an offset has been passed and we have not been called from
  6028. // clone(), we can trust it and avoid the offset calculation.
  6029. var ot = isNumber(config.o) && !config.old ? config.o : zone.offset(this.ts);
  6030. c = tsToObj(this.ts, ot);
  6031. invalid = Number.isNaN(c.year) ? new Invalid("invalid input") : null;
  6032. c = invalid ? null : c;
  6033. o = invalid ? null : ot;
  6034. }
  6035. }
  6036. /**
  6037. * @access private
  6038. */
  6039. this._zone = zone;
  6040. /**
  6041. * @access private
  6042. */
  6043. this.loc = config.loc || Locale.create();
  6044. /**
  6045. * @access private
  6046. */
  6047. this.invalid = invalid;
  6048. /**
  6049. * @access private
  6050. */
  6051. this.weekData = null;
  6052. /**
  6053. * @access private
  6054. */
  6055. this.localWeekData = null;
  6056. /**
  6057. * @access private
  6058. */
  6059. this.c = c;
  6060. /**
  6061. * @access private
  6062. */
  6063. this.o = o;
  6064. /**
  6065. * @access private
  6066. */
  6067. this.isLuxonDateTime = true;
  6068. }
  6069. // CONSTRUCT
  6070. /**
  6071. * Create a DateTime for the current instant, in the system's time zone.
  6072. *
  6073. * Use Settings to override these default values if needed.
  6074. * @example DateTime.now().toISO() //~> now in the ISO format
  6075. * @return {DateTime}
  6076. */
  6077. DateTime.now = function now() {
  6078. return new DateTime({});
  6079. }
  6080. /**
  6081. * Create a local DateTime
  6082. * @param {number} [year] - The calendar year. If omitted (as in, call `local()` with no arguments), the current time will be used
  6083. * @param {number} [month=1] - The month, 1-indexed
  6084. * @param {number} [day=1] - The day of the month, 1-indexed
  6085. * @param {number} [hour=0] - The hour of the day, in 24-hour time
  6086. * @param {number} [minute=0] - The minute of the hour, meaning a number between 0 and 59
  6087. * @param {number} [second=0] - The second of the minute, meaning a number between 0 and 59
  6088. * @param {number} [millisecond=0] - The millisecond of the second, meaning a number between 0 and 999
  6089. * @example DateTime.local() //~> now
  6090. * @example DateTime.local({ zone: "America/New_York" }) //~> now, in US east coast time
  6091. * @example DateTime.local(2017) //~> 2017-01-01T00:00:00
  6092. * @example DateTime.local(2017, 3) //~> 2017-03-01T00:00:00
  6093. * @example DateTime.local(2017, 3, 12, { locale: "fr" }) //~> 2017-03-12T00:00:00, with a French locale
  6094. * @example DateTime.local(2017, 3, 12, 5) //~> 2017-03-12T05:00:00
  6095. * @example DateTime.local(2017, 3, 12, 5, { zone: "utc" }) //~> 2017-03-12T05:00:00, in UTC
  6096. * @example DateTime.local(2017, 3, 12, 5, 45) //~> 2017-03-12T05:45:00
  6097. * @example DateTime.local(2017, 3, 12, 5, 45, 10) //~> 2017-03-12T05:45:10
  6098. * @example DateTime.local(2017, 3, 12, 5, 45, 10, 765) //~> 2017-03-12T05:45:10.765
  6099. * @return {DateTime}
  6100. */;
  6101. DateTime.local = function local() {
  6102. var _lastOpts = lastOpts(arguments),
  6103. opts = _lastOpts[0],
  6104. args = _lastOpts[1],
  6105. year = args[0],
  6106. month = args[1],
  6107. day = args[2],
  6108. hour = args[3],
  6109. minute = args[4],
  6110. second = args[5],
  6111. millisecond = args[6];
  6112. return quickDT({
  6113. year: year,
  6114. month: month,
  6115. day: day,
  6116. hour: hour,
  6117. minute: minute,
  6118. second: second,
  6119. millisecond: millisecond
  6120. }, opts);
  6121. }
  6122. /**
  6123. * Create a DateTime in UTC
  6124. * @param {number} [year] - The calendar year. If omitted (as in, call `utc()` with no arguments), the current time will be used
  6125. * @param {number} [month=1] - The month, 1-indexed
  6126. * @param {number} [day=1] - The day of the month
  6127. * @param {number} [hour=0] - The hour of the day, in 24-hour time
  6128. * @param {number} [minute=0] - The minute of the hour, meaning a number between 0 and 59
  6129. * @param {number} [second=0] - The second of the minute, meaning a number between 0 and 59
  6130. * @param {number} [millisecond=0] - The millisecond of the second, meaning a number between 0 and 999
  6131. * @param {Object} options - configuration options for the DateTime
  6132. * @param {string} [options.locale] - a locale to set on the resulting DateTime instance
  6133. * @param {string} [options.outputCalendar] - the output calendar to set on the resulting DateTime instance
  6134. * @param {string} [options.numberingSystem] - the numbering system to set on the resulting DateTime instance
  6135. * @param {string} [options.weekSettings] - the week settings to set on the resulting DateTime instance
  6136. * @example DateTime.utc() //~> now
  6137. * @example DateTime.utc(2017) //~> 2017-01-01T00:00:00Z
  6138. * @example DateTime.utc(2017, 3) //~> 2017-03-01T00:00:00Z
  6139. * @example DateTime.utc(2017, 3, 12) //~> 2017-03-12T00:00:00Z
  6140. * @example DateTime.utc(2017, 3, 12, 5) //~> 2017-03-12T05:00:00Z
  6141. * @example DateTime.utc(2017, 3, 12, 5, 45) //~> 2017-03-12T05:45:00Z
  6142. * @example DateTime.utc(2017, 3, 12, 5, 45, { locale: "fr" }) //~> 2017-03-12T05:45:00Z with a French locale
  6143. * @example DateTime.utc(2017, 3, 12, 5, 45, 10) //~> 2017-03-12T05:45:10Z
  6144. * @example DateTime.utc(2017, 3, 12, 5, 45, 10, 765, { locale: "fr" }) //~> 2017-03-12T05:45:10.765Z with a French locale
  6145. * @return {DateTime}
  6146. */;
  6147. DateTime.utc = function utc() {
  6148. var _lastOpts2 = lastOpts(arguments),
  6149. opts = _lastOpts2[0],
  6150. args = _lastOpts2[1],
  6151. year = args[0],
  6152. month = args[1],
  6153. day = args[2],
  6154. hour = args[3],
  6155. minute = args[4],
  6156. second = args[5],
  6157. millisecond = args[6];
  6158. opts.zone = FixedOffsetZone.utcInstance;
  6159. return quickDT({
  6160. year: year,
  6161. month: month,
  6162. day: day,
  6163. hour: hour,
  6164. minute: minute,
  6165. second: second,
  6166. millisecond: millisecond
  6167. }, opts);
  6168. }
  6169. /**
  6170. * Create a DateTime from a JavaScript Date object. Uses the default zone.
  6171. * @param {Date} date - a JavaScript Date object
  6172. * @param {Object} options - configuration options for the DateTime
  6173. * @param {string|Zone} [options.zone='local'] - the zone to place the DateTime into
  6174. * @return {DateTime}
  6175. */;
  6176. DateTime.fromJSDate = function fromJSDate(date, options) {
  6177. if (options === void 0) {
  6178. options = {};
  6179. }
  6180. var ts = isDate(date) ? date.valueOf() : NaN;
  6181. if (Number.isNaN(ts)) {
  6182. return DateTime.invalid("invalid input");
  6183. }
  6184. var zoneToUse = normalizeZone(options.zone, Settings.defaultZone);
  6185. if (!zoneToUse.isValid) {
  6186. return DateTime.invalid(unsupportedZone(zoneToUse));
  6187. }
  6188. return new DateTime({
  6189. ts: ts,
  6190. zone: zoneToUse,
  6191. loc: Locale.fromObject(options)
  6192. });
  6193. }
  6194. /**
  6195. * Create a DateTime from a number of milliseconds since the epoch (meaning since 1 January 1970 00:00:00 UTC). Uses the default zone.
  6196. * @param {number} milliseconds - a number of milliseconds since 1970 UTC
  6197. * @param {Object} options - configuration options for the DateTime
  6198. * @param {string|Zone} [options.zone='local'] - the zone to place the DateTime into
  6199. * @param {string} [options.locale] - a locale to set on the resulting DateTime instance
  6200. * @param {string} options.outputCalendar - the output calendar to set on the resulting DateTime instance
  6201. * @param {string} options.numberingSystem - the numbering system to set on the resulting DateTime instance
  6202. * @param {string} options.weekSettings - the week settings to set on the resulting DateTime instance
  6203. * @return {DateTime}
  6204. */;
  6205. DateTime.fromMillis = function fromMillis(milliseconds, options) {
  6206. if (options === void 0) {
  6207. options = {};
  6208. }
  6209. if (!isNumber(milliseconds)) {
  6210. throw new InvalidArgumentError("fromMillis requires a numerical input, but received a " + typeof milliseconds + " with value " + milliseconds);
  6211. } else if (milliseconds < -MAX_DATE || milliseconds > MAX_DATE) {
  6212. // this isn't perfect because we can still end up out of range because of additional shifting, but it's a start
  6213. return DateTime.invalid("Timestamp out of range");
  6214. } else {
  6215. return new DateTime({
  6216. ts: milliseconds,
  6217. zone: normalizeZone(options.zone, Settings.defaultZone),
  6218. loc: Locale.fromObject(options)
  6219. });
  6220. }
  6221. }
  6222. /**
  6223. * Create a DateTime from a number of seconds since the epoch (meaning since 1 January 1970 00:00:00 UTC). Uses the default zone.
  6224. * @param {number} seconds - a number of seconds since 1970 UTC
  6225. * @param {Object} options - configuration options for the DateTime
  6226. * @param {string|Zone} [options.zone='local'] - the zone to place the DateTime into
  6227. * @param {string} [options.locale] - a locale to set on the resulting DateTime instance
  6228. * @param {string} options.outputCalendar - the output calendar to set on the resulting DateTime instance
  6229. * @param {string} options.numberingSystem - the numbering system to set on the resulting DateTime instance
  6230. * @param {string} options.weekSettings - the week settings to set on the resulting DateTime instance
  6231. * @return {DateTime}
  6232. */;
  6233. DateTime.fromSeconds = function fromSeconds(seconds, options) {
  6234. if (options === void 0) {
  6235. options = {};
  6236. }
  6237. if (!isNumber(seconds)) {
  6238. throw new InvalidArgumentError("fromSeconds requires a numerical input");
  6239. } else {
  6240. return new DateTime({
  6241. ts: seconds * 1000,
  6242. zone: normalizeZone(options.zone, Settings.defaultZone),
  6243. loc: Locale.fromObject(options)
  6244. });
  6245. }
  6246. }
  6247. /**
  6248. * Create a DateTime from a JavaScript object with keys like 'year' and 'hour' with reasonable defaults.
  6249. * @param {Object} obj - the object to create the DateTime from
  6250. * @param {number} obj.year - a year, such as 1987
  6251. * @param {number} obj.month - a month, 1-12
  6252. * @param {number} obj.day - a day of the month, 1-31, depending on the month
  6253. * @param {number} obj.ordinal - day of the year, 1-365 or 366
  6254. * @param {number} obj.weekYear - an ISO week year
  6255. * @param {number} obj.weekNumber - an ISO week number, between 1 and 52 or 53, depending on the year
  6256. * @param {number} obj.weekday - an ISO weekday, 1-7, where 1 is Monday and 7 is Sunday
  6257. * @param {number} obj.localWeekYear - a week year, according to the locale
  6258. * @param {number} obj.localWeekNumber - a week number, between 1 and 52 or 53, depending on the year, according to the locale
  6259. * @param {number} obj.localWeekday - a weekday, 1-7, where 1 is the first and 7 is the last day of the week, according to the locale
  6260. * @param {number} obj.hour - hour of the day, 0-23
  6261. * @param {number} obj.minute - minute of the hour, 0-59
  6262. * @param {number} obj.second - second of the minute, 0-59
  6263. * @param {number} obj.millisecond - millisecond of the second, 0-999
  6264. * @param {Object} opts - options for creating this DateTime
  6265. * @param {string|Zone} [opts.zone='local'] - interpret the numbers in the context of a particular zone. Can take any value taken as the first argument to setZone()
  6266. * @param {string} [opts.locale='system\'s locale'] - a locale to set on the resulting DateTime instance
  6267. * @param {string} opts.outputCalendar - the output calendar to set on the resulting DateTime instance
  6268. * @param {string} opts.numberingSystem - the numbering system to set on the resulting DateTime instance
  6269. * @param {string} opts.weekSettings - the week settings to set on the resulting DateTime instance
  6270. * @example DateTime.fromObject({ year: 1982, month: 5, day: 25}).toISODate() //=> '1982-05-25'
  6271. * @example DateTime.fromObject({ year: 1982 }).toISODate() //=> '1982-01-01'
  6272. * @example DateTime.fromObject({ hour: 10, minute: 26, second: 6 }) //~> today at 10:26:06
  6273. * @example DateTime.fromObject({ hour: 10, minute: 26, second: 6 }, { zone: 'utc' }),
  6274. * @example DateTime.fromObject({ hour: 10, minute: 26, second: 6 }, { zone: 'local' })
  6275. * @example DateTime.fromObject({ hour: 10, minute: 26, second: 6 }, { zone: 'America/New_York' })
  6276. * @example DateTime.fromObject({ weekYear: 2016, weekNumber: 2, weekday: 3 }).toISODate() //=> '2016-01-13'
  6277. * @example DateTime.fromObject({ localWeekYear: 2022, localWeekNumber: 1, localWeekday: 1 }, { locale: "en-US" }).toISODate() //=> '2021-12-26'
  6278. * @return {DateTime}
  6279. */;
  6280. DateTime.fromObject = function fromObject(obj, opts) {
  6281. if (opts === void 0) {
  6282. opts = {};
  6283. }
  6284. obj = obj || {};
  6285. var zoneToUse = normalizeZone(opts.zone, Settings.defaultZone);
  6286. if (!zoneToUse.isValid) {
  6287. return DateTime.invalid(unsupportedZone(zoneToUse));
  6288. }
  6289. var loc = Locale.fromObject(opts);
  6290. var normalized = normalizeObject(obj, normalizeUnitWithLocalWeeks);
  6291. var _usesLocalWeekValues = usesLocalWeekValues(normalized, loc),
  6292. minDaysInFirstWeek = _usesLocalWeekValues.minDaysInFirstWeek,
  6293. startOfWeek = _usesLocalWeekValues.startOfWeek;
  6294. var tsNow = Settings.now(),
  6295. offsetProvis = !isUndefined(opts.specificOffset) ? opts.specificOffset : zoneToUse.offset(tsNow),
  6296. containsOrdinal = !isUndefined(normalized.ordinal),
  6297. containsGregorYear = !isUndefined(normalized.year),
  6298. containsGregorMD = !isUndefined(normalized.month) || !isUndefined(normalized.day),
  6299. containsGregor = containsGregorYear || containsGregorMD,
  6300. definiteWeekDef = normalized.weekYear || normalized.weekNumber;
  6301. // cases:
  6302. // just a weekday -> this week's instance of that weekday, no worries
  6303. // (gregorian data or ordinal) + (weekYear or weekNumber) -> error
  6304. // (gregorian month or day) + ordinal -> error
  6305. // otherwise just use weeks or ordinals or gregorian, depending on what's specified
  6306. if ((containsGregor || containsOrdinal) && definiteWeekDef) {
  6307. throw new ConflictingSpecificationError("Can't mix weekYear/weekNumber units with year/month/day or ordinals");
  6308. }
  6309. if (containsGregorMD && containsOrdinal) {
  6310. throw new ConflictingSpecificationError("Can't mix ordinal dates with month/day");
  6311. }
  6312. var useWeekData = definiteWeekDef || normalized.weekday && !containsGregor;
  6313. // configure ourselves to deal with gregorian dates or week stuff
  6314. var units,
  6315. defaultValues,
  6316. objNow = tsToObj(tsNow, offsetProvis);
  6317. if (useWeekData) {
  6318. units = orderedWeekUnits;
  6319. defaultValues = defaultWeekUnitValues;
  6320. objNow = gregorianToWeek(objNow, minDaysInFirstWeek, startOfWeek);
  6321. } else if (containsOrdinal) {
  6322. units = orderedOrdinalUnits;
  6323. defaultValues = defaultOrdinalUnitValues;
  6324. objNow = gregorianToOrdinal(objNow);
  6325. } else {
  6326. units = orderedUnits;
  6327. defaultValues = defaultUnitValues;
  6328. }
  6329. // set default values for missing stuff
  6330. var foundFirst = false;
  6331. for (var _iterator2 = _createForOfIteratorHelperLoose(units), _step2; !(_step2 = _iterator2()).done;) {
  6332. var u = _step2.value;
  6333. var v = normalized[u];
  6334. if (!isUndefined(v)) {
  6335. foundFirst = true;
  6336. } else if (foundFirst) {
  6337. normalized[u] = defaultValues[u];
  6338. } else {
  6339. normalized[u] = objNow[u];
  6340. }
  6341. }
  6342. // make sure the values we have are in range
  6343. var higherOrderInvalid = useWeekData ? hasInvalidWeekData(normalized, minDaysInFirstWeek, startOfWeek) : containsOrdinal ? hasInvalidOrdinalData(normalized) : hasInvalidGregorianData(normalized),
  6344. invalid = higherOrderInvalid || hasInvalidTimeData(normalized);
  6345. if (invalid) {
  6346. return DateTime.invalid(invalid);
  6347. }
  6348. // compute the actual time
  6349. var gregorian = useWeekData ? weekToGregorian(normalized, minDaysInFirstWeek, startOfWeek) : containsOrdinal ? ordinalToGregorian(normalized) : normalized,
  6350. _objToTS2 = objToTS(gregorian, offsetProvis, zoneToUse),
  6351. tsFinal = _objToTS2[0],
  6352. offsetFinal = _objToTS2[1],
  6353. inst = new DateTime({
  6354. ts: tsFinal,
  6355. zone: zoneToUse,
  6356. o: offsetFinal,
  6357. loc: loc
  6358. });
  6359. // gregorian data + weekday serves only to validate
  6360. if (normalized.weekday && containsGregor && obj.weekday !== inst.weekday) {
  6361. return DateTime.invalid("mismatched weekday", "you can't specify both a weekday of " + normalized.weekday + " and a date of " + inst.toISO());
  6362. }
  6363. if (!inst.isValid) {
  6364. return DateTime.invalid(inst.invalid);
  6365. }
  6366. return inst;
  6367. }
  6368. /**
  6369. * Create a DateTime from an ISO 8601 string
  6370. * @param {string} text - the ISO string
  6371. * @param {Object} opts - options to affect the creation
  6372. * @param {string|Zone} [opts.zone='local'] - use this zone if no offset is specified in the input string itself. Will also convert the time to this zone
  6373. * @param {boolean} [opts.setZone=false] - override the zone with a fixed-offset zone specified in the string itself, if it specifies one
  6374. * @param {string} [opts.locale='system's locale'] - a locale to set on the resulting DateTime instance
  6375. * @param {string} [opts.outputCalendar] - the output calendar to set on the resulting DateTime instance
  6376. * @param {string} [opts.numberingSystem] - the numbering system to set on the resulting DateTime instance
  6377. * @param {string} [opts.weekSettings] - the week settings to set on the resulting DateTime instance
  6378. * @example DateTime.fromISO('2016-05-25T09:08:34.123')
  6379. * @example DateTime.fromISO('2016-05-25T09:08:34.123+06:00')
  6380. * @example DateTime.fromISO('2016-05-25T09:08:34.123+06:00', {setZone: true})
  6381. * @example DateTime.fromISO('2016-05-25T09:08:34.123', {zone: 'utc'})
  6382. * @example DateTime.fromISO('2016-W05-4')
  6383. * @return {DateTime}
  6384. */;
  6385. DateTime.fromISO = function fromISO(text, opts) {
  6386. if (opts === void 0) {
  6387. opts = {};
  6388. }
  6389. var _parseISODate = parseISODate(text),
  6390. vals = _parseISODate[0],
  6391. parsedZone = _parseISODate[1];
  6392. return parseDataToDateTime(vals, parsedZone, opts, "ISO 8601", text);
  6393. }
  6394. /**
  6395. * Create a DateTime from an RFC 2822 string
  6396. * @param {string} text - the RFC 2822 string
  6397. * @param {Object} opts - options to affect the creation
  6398. * @param {string|Zone} [opts.zone='local'] - convert the time to this zone. Since the offset is always specified in the string itself, this has no effect on the interpretation of string, merely the zone the resulting DateTime is expressed in.
  6399. * @param {boolean} [opts.setZone=false] - override the zone with a fixed-offset zone specified in the string itself, if it specifies one
  6400. * @param {string} [opts.locale='system's locale'] - a locale to set on the resulting DateTime instance
  6401. * @param {string} opts.outputCalendar - the output calendar to set on the resulting DateTime instance
  6402. * @param {string} opts.numberingSystem - the numbering system to set on the resulting DateTime instance
  6403. * @param {string} opts.weekSettings - the week settings to set on the resulting DateTime instance
  6404. * @example DateTime.fromRFC2822('25 Nov 2016 13:23:12 GMT')
  6405. * @example DateTime.fromRFC2822('Fri, 25 Nov 2016 13:23:12 +0600')
  6406. * @example DateTime.fromRFC2822('25 Nov 2016 13:23 Z')
  6407. * @return {DateTime}
  6408. */;
  6409. DateTime.fromRFC2822 = function fromRFC2822(text, opts) {
  6410. if (opts === void 0) {
  6411. opts = {};
  6412. }
  6413. var _parseRFC2822Date = parseRFC2822Date(text),
  6414. vals = _parseRFC2822Date[0],
  6415. parsedZone = _parseRFC2822Date[1];
  6416. return parseDataToDateTime(vals, parsedZone, opts, "RFC 2822", text);
  6417. }
  6418. /**
  6419. * Create a DateTime from an HTTP header date
  6420. * @see https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1
  6421. * @param {string} text - the HTTP header date
  6422. * @param {Object} opts - options to affect the creation
  6423. * @param {string|Zone} [opts.zone='local'] - convert the time to this zone. Since HTTP dates are always in UTC, this has no effect on the interpretation of string, merely the zone the resulting DateTime is expressed in.
  6424. * @param {boolean} [opts.setZone=false] - override the zone with the fixed-offset zone specified in the string. For HTTP dates, this is always UTC, so this option is equivalent to setting the `zone` option to 'utc', but this option is included for consistency with similar methods.
  6425. * @param {string} [opts.locale='system's locale'] - a locale to set on the resulting DateTime instance
  6426. * @param {string} opts.outputCalendar - the output calendar to set on the resulting DateTime instance
  6427. * @param {string} opts.numberingSystem - the numbering system to set on the resulting DateTime instance
  6428. * @param {string} opts.weekSettings - the week settings to set on the resulting DateTime instance
  6429. * @example DateTime.fromHTTP('Sun, 06 Nov 1994 08:49:37 GMT')
  6430. * @example DateTime.fromHTTP('Sunday, 06-Nov-94 08:49:37 GMT')
  6431. * @example DateTime.fromHTTP('Sun Nov 6 08:49:37 1994')
  6432. * @return {DateTime}
  6433. */;
  6434. DateTime.fromHTTP = function fromHTTP(text, opts) {
  6435. if (opts === void 0) {
  6436. opts = {};
  6437. }
  6438. var _parseHTTPDate = parseHTTPDate(text),
  6439. vals = _parseHTTPDate[0],
  6440. parsedZone = _parseHTTPDate[1];
  6441. return parseDataToDateTime(vals, parsedZone, opts, "HTTP", opts);
  6442. }
  6443. /**
  6444. * Create a DateTime from an input string and format string.
  6445. * Defaults to en-US if no locale has been specified, regardless of the system's locale. For a table of tokens and their interpretations, see [here](https://moment.github.io/luxon/#/parsing?id=table-of-tokens).
  6446. * @param {string} text - the string to parse
  6447. * @param {string} fmt - the format the string is expected to be in (see the link below for the formats)
  6448. * @param {Object} opts - options to affect the creation
  6449. * @param {string|Zone} [opts.zone='local'] - use this zone if no offset is specified in the input string itself. Will also convert the DateTime to this zone
  6450. * @param {boolean} [opts.setZone=false] - override the zone with a zone specified in the string itself, if it specifies one
  6451. * @param {string} [opts.locale='en-US'] - a locale string to use when parsing. Will also set the DateTime to this locale
  6452. * @param {string} opts.numberingSystem - the numbering system to use when parsing. Will also set the resulting DateTime to this numbering system
  6453. * @param {string} opts.weekSettings - the week settings to set on the resulting DateTime instance
  6454. * @param {string} opts.outputCalendar - the output calendar to set on the resulting DateTime instance
  6455. * @return {DateTime}
  6456. */;
  6457. DateTime.fromFormat = function fromFormat(text, fmt, opts) {
  6458. if (opts === void 0) {
  6459. opts = {};
  6460. }
  6461. if (isUndefined(text) || isUndefined(fmt)) {
  6462. throw new InvalidArgumentError("fromFormat requires an input string and a format");
  6463. }
  6464. var _opts = opts,
  6465. _opts$locale = _opts.locale,
  6466. locale = _opts$locale === void 0 ? null : _opts$locale,
  6467. _opts$numberingSystem = _opts.numberingSystem,
  6468. numberingSystem = _opts$numberingSystem === void 0 ? null : _opts$numberingSystem,
  6469. localeToUse = Locale.fromOpts({
  6470. locale: locale,
  6471. numberingSystem: numberingSystem,
  6472. defaultToEN: true
  6473. }),
  6474. _parseFromTokens = parseFromTokens(localeToUse, text, fmt),
  6475. vals = _parseFromTokens[0],
  6476. parsedZone = _parseFromTokens[1],
  6477. specificOffset = _parseFromTokens[2],
  6478. invalid = _parseFromTokens[3];
  6479. if (invalid) {
  6480. return DateTime.invalid(invalid);
  6481. } else {
  6482. return parseDataToDateTime(vals, parsedZone, opts, "format " + fmt, text, specificOffset);
  6483. }
  6484. }
  6485. /**
  6486. * @deprecated use fromFormat instead
  6487. */;
  6488. DateTime.fromString = function fromString(text, fmt, opts) {
  6489. if (opts === void 0) {
  6490. opts = {};
  6491. }
  6492. return DateTime.fromFormat(text, fmt, opts);
  6493. }
  6494. /**
  6495. * Create a DateTime from a SQL date, time, or datetime
  6496. * Defaults to en-US if no locale has been specified, regardless of the system's locale
  6497. * @param {string} text - the string to parse
  6498. * @param {Object} opts - options to affect the creation
  6499. * @param {string|Zone} [opts.zone='local'] - use this zone if no offset is specified in the input string itself. Will also convert the DateTime to this zone
  6500. * @param {boolean} [opts.setZone=false] - override the zone with a zone specified in the string itself, if it specifies one
  6501. * @param {string} [opts.locale='en-US'] - a locale string to use when parsing. Will also set the DateTime to this locale
  6502. * @param {string} opts.numberingSystem - the numbering system to use when parsing. Will also set the resulting DateTime to this numbering system
  6503. * @param {string} opts.weekSettings - the week settings to set on the resulting DateTime instance
  6504. * @param {string} opts.outputCalendar - the output calendar to set on the resulting DateTime instance
  6505. * @example DateTime.fromSQL('2017-05-15')
  6506. * @example DateTime.fromSQL('2017-05-15 09:12:34')
  6507. * @example DateTime.fromSQL('2017-05-15 09:12:34.342')
  6508. * @example DateTime.fromSQL('2017-05-15 09:12:34.342+06:00')
  6509. * @example DateTime.fromSQL('2017-05-15 09:12:34.342 America/Los_Angeles')
  6510. * @example DateTime.fromSQL('2017-05-15 09:12:34.342 America/Los_Angeles', { setZone: true })
  6511. * @example DateTime.fromSQL('2017-05-15 09:12:34.342', { zone: 'America/Los_Angeles' })
  6512. * @example DateTime.fromSQL('09:12:34.342')
  6513. * @return {DateTime}
  6514. */;
  6515. DateTime.fromSQL = function fromSQL(text, opts) {
  6516. if (opts === void 0) {
  6517. opts = {};
  6518. }
  6519. var _parseSQL = parseSQL(text),
  6520. vals = _parseSQL[0],
  6521. parsedZone = _parseSQL[1];
  6522. return parseDataToDateTime(vals, parsedZone, opts, "SQL", text);
  6523. }
  6524. /**
  6525. * Create an invalid DateTime.
  6526. * @param {string} reason - simple string of why this DateTime is invalid. Should not contain parameters or anything else data-dependent.
  6527. * @param {string} [explanation=null] - longer explanation, may include parameters and other useful debugging information
  6528. * @return {DateTime}
  6529. */;
  6530. DateTime.invalid = function invalid(reason, explanation) {
  6531. if (explanation === void 0) {
  6532. explanation = null;
  6533. }
  6534. if (!reason) {
  6535. throw new InvalidArgumentError("need to specify a reason the DateTime is invalid");
  6536. }
  6537. var invalid = reason instanceof Invalid ? reason : new Invalid(reason, explanation);
  6538. if (Settings.throwOnInvalid) {
  6539. throw new InvalidDateTimeError(invalid);
  6540. } else {
  6541. return new DateTime({
  6542. invalid: invalid
  6543. });
  6544. }
  6545. }
  6546. /**
  6547. * Check if an object is an instance of DateTime. Works across context boundaries
  6548. * @param {object} o
  6549. * @return {boolean}
  6550. */;
  6551. DateTime.isDateTime = function isDateTime(o) {
  6552. return o && o.isLuxonDateTime || false;
  6553. }
  6554. /**
  6555. * Produce the format string for a set of options
  6556. * @param formatOpts
  6557. * @param localeOpts
  6558. * @returns {string}
  6559. */;
  6560. DateTime.parseFormatForOpts = function parseFormatForOpts(formatOpts, localeOpts) {
  6561. if (localeOpts === void 0) {
  6562. localeOpts = {};
  6563. }
  6564. var tokenList = formatOptsToTokens(formatOpts, Locale.fromObject(localeOpts));
  6565. return !tokenList ? null : tokenList.map(function (t) {
  6566. return t ? t.val : null;
  6567. }).join("");
  6568. }
  6569. /**
  6570. * Produce the the fully expanded format token for the locale
  6571. * Does NOT quote characters, so quoted tokens will not round trip correctly
  6572. * @param fmt
  6573. * @param localeOpts
  6574. * @returns {string}
  6575. */;
  6576. DateTime.expandFormat = function expandFormat(fmt, localeOpts) {
  6577. if (localeOpts === void 0) {
  6578. localeOpts = {};
  6579. }
  6580. var expanded = expandMacroTokens(Formatter.parseFormat(fmt), Locale.fromObject(localeOpts));
  6581. return expanded.map(function (t) {
  6582. return t.val;
  6583. }).join("");
  6584. };
  6585. DateTime.resetCache = function resetCache() {
  6586. zoneOffsetTs = undefined;
  6587. zoneOffsetGuessCache = {};
  6588. }
  6589. // INFO
  6590. /**
  6591. * Get the value of unit.
  6592. * @param {string} unit - a unit such as 'minute' or 'day'
  6593. * @example DateTime.local(2017, 7, 4).get('month'); //=> 7
  6594. * @example DateTime.local(2017, 7, 4).get('day'); //=> 4
  6595. * @return {number}
  6596. */;
  6597. var _proto = DateTime.prototype;
  6598. _proto.get = function get(unit) {
  6599. return this[unit];
  6600. }
  6601. /**
  6602. * Returns whether the DateTime is valid. Invalid DateTimes occur when:
  6603. * * The DateTime was created from invalid calendar information, such as the 13th month or February 30
  6604. * * The DateTime was created by an operation on another invalid date
  6605. * @type {boolean}
  6606. */;
  6607. /**
  6608. * Get those DateTimes which have the same local time as this DateTime, but a different offset from UTC
  6609. * in this DateTime's zone. During DST changes local time can be ambiguous, for example
  6610. * `2023-10-29T02:30:00` in `Europe/Berlin` can have offset `+01:00` or `+02:00`.
  6611. * This method will return both possible DateTimes if this DateTime's local time is ambiguous.
  6612. * @returns {DateTime[]}
  6613. */
  6614. _proto.getPossibleOffsets = function getPossibleOffsets() {
  6615. if (!this.isValid || this.isOffsetFixed) {
  6616. return [this];
  6617. }
  6618. var dayMs = 86400000;
  6619. var minuteMs = 60000;
  6620. var localTS = objToLocalTS(this.c);
  6621. var oEarlier = this.zone.offset(localTS - dayMs);
  6622. var oLater = this.zone.offset(localTS + dayMs);
  6623. var o1 = this.zone.offset(localTS - oEarlier * minuteMs);
  6624. var o2 = this.zone.offset(localTS - oLater * minuteMs);
  6625. if (o1 === o2) {
  6626. return [this];
  6627. }
  6628. var ts1 = localTS - o1 * minuteMs;
  6629. var ts2 = localTS - o2 * minuteMs;
  6630. var c1 = tsToObj(ts1, o1);
  6631. var c2 = tsToObj(ts2, o2);
  6632. if (c1.hour === c2.hour && c1.minute === c2.minute && c1.second === c2.second && c1.millisecond === c2.millisecond) {
  6633. return [clone(this, {
  6634. ts: ts1
  6635. }), clone(this, {
  6636. ts: ts2
  6637. })];
  6638. }
  6639. return [this];
  6640. }
  6641. /**
  6642. * Returns true if this DateTime is in a leap year, false otherwise
  6643. * @example DateTime.local(2016).isInLeapYear //=> true
  6644. * @example DateTime.local(2013).isInLeapYear //=> false
  6645. * @type {boolean}
  6646. */;
  6647. /**
  6648. * Returns the resolved Intl options for this DateTime.
  6649. * This is useful in understanding the behavior of formatting methods
  6650. * @param {Object} opts - the same options as toLocaleString
  6651. * @return {Object}
  6652. */
  6653. _proto.resolvedLocaleOptions = function resolvedLocaleOptions(opts) {
  6654. if (opts === void 0) {
  6655. opts = {};
  6656. }
  6657. var _Formatter$create$res = Formatter.create(this.loc.clone(opts), opts).resolvedOptions(this),
  6658. locale = _Formatter$create$res.locale,
  6659. numberingSystem = _Formatter$create$res.numberingSystem,
  6660. calendar = _Formatter$create$res.calendar;
  6661. return {
  6662. locale: locale,
  6663. numberingSystem: numberingSystem,
  6664. outputCalendar: calendar
  6665. };
  6666. }
  6667. // TRANSFORM
  6668. /**
  6669. * "Set" the DateTime's zone to UTC. Returns a newly-constructed DateTime.
  6670. *
  6671. * Equivalent to {@link DateTime#setZone}('utc')
  6672. * @param {number} [offset=0] - optionally, an offset from UTC in minutes
  6673. * @param {Object} [opts={}] - options to pass to `setZone()`
  6674. * @return {DateTime}
  6675. */;
  6676. _proto.toUTC = function toUTC(offset, opts) {
  6677. if (offset === void 0) {
  6678. offset = 0;
  6679. }
  6680. if (opts === void 0) {
  6681. opts = {};
  6682. }
  6683. return this.setZone(FixedOffsetZone.instance(offset), opts);
  6684. }
  6685. /**
  6686. * "Set" the DateTime's zone to the host's local zone. Returns a newly-constructed DateTime.
  6687. *
  6688. * Equivalent to `setZone('local')`
  6689. * @return {DateTime}
  6690. */;
  6691. _proto.toLocal = function toLocal() {
  6692. return this.setZone(Settings.defaultZone);
  6693. }
  6694. /**
  6695. * "Set" the DateTime's zone to specified zone. Returns a newly-constructed DateTime.
  6696. *
  6697. * By default, the setter keeps the underlying time the same (as in, the same timestamp), but the new instance will report different local times and consider DSTs when making computations, as with {@link DateTime#plus}. You may wish to use {@link DateTime#toLocal} and {@link DateTime#toUTC} which provide simple convenience wrappers for commonly used zones.
  6698. * @param {string|Zone} [zone='local'] - a zone identifier. As a string, that can be any IANA zone supported by the host environment, or a fixed-offset name of the form 'UTC+3', or the strings 'local' or 'utc'. You may also supply an instance of a {@link DateTime#Zone} class.
  6699. * @param {Object} opts - options
  6700. * @param {boolean} [opts.keepLocalTime=false] - If true, adjust the underlying time so that the local time stays the same, but in the target zone. You should rarely need this.
  6701. * @return {DateTime}
  6702. */;
  6703. _proto.setZone = function setZone(zone, _temp) {
  6704. var _ref2 = _temp === void 0 ? {} : _temp,
  6705. _ref2$keepLocalTime = _ref2.keepLocalTime,
  6706. keepLocalTime = _ref2$keepLocalTime === void 0 ? false : _ref2$keepLocalTime,
  6707. _ref2$keepCalendarTim = _ref2.keepCalendarTime,
  6708. keepCalendarTime = _ref2$keepCalendarTim === void 0 ? false : _ref2$keepCalendarTim;
  6709. zone = normalizeZone(zone, Settings.defaultZone);
  6710. if (zone.equals(this.zone)) {
  6711. return this;
  6712. } else if (!zone.isValid) {
  6713. return DateTime.invalid(unsupportedZone(zone));
  6714. } else {
  6715. var newTS = this.ts;
  6716. if (keepLocalTime || keepCalendarTime) {
  6717. var offsetGuess = zone.offset(this.ts);
  6718. var asObj = this.toObject();
  6719. var _objToTS3 = objToTS(asObj, offsetGuess, zone);
  6720. newTS = _objToTS3[0];
  6721. }
  6722. return clone(this, {
  6723. ts: newTS,
  6724. zone: zone
  6725. });
  6726. }
  6727. }
  6728. /**
  6729. * "Set" the locale, numberingSystem, or outputCalendar. Returns a newly-constructed DateTime.
  6730. * @param {Object} properties - the properties to set
  6731. * @example DateTime.local(2017, 5, 25).reconfigure({ locale: 'en-GB' })
  6732. * @return {DateTime}
  6733. */;
  6734. _proto.reconfigure = function reconfigure(_temp2) {
  6735. var _ref3 = _temp2 === void 0 ? {} : _temp2,
  6736. locale = _ref3.locale,
  6737. numberingSystem = _ref3.numberingSystem,
  6738. outputCalendar = _ref3.outputCalendar;
  6739. var loc = this.loc.clone({
  6740. locale: locale,
  6741. numberingSystem: numberingSystem,
  6742. outputCalendar: outputCalendar
  6743. });
  6744. return clone(this, {
  6745. loc: loc
  6746. });
  6747. }
  6748. /**
  6749. * "Set" the locale. Returns a newly-constructed DateTime.
  6750. * Just a convenient alias for reconfigure({ locale })
  6751. * @example DateTime.local(2017, 5, 25).setLocale('en-GB')
  6752. * @return {DateTime}
  6753. */;
  6754. _proto.setLocale = function setLocale(locale) {
  6755. return this.reconfigure({
  6756. locale: locale
  6757. });
  6758. }
  6759. /**
  6760. * "Set" the values of specified units. Returns a newly-constructed DateTime.
  6761. * You can only set units with this method; for "setting" metadata, see {@link DateTime#reconfigure} and {@link DateTime#setZone}.
  6762. *
  6763. * This method also supports setting locale-based week units, i.e. `localWeekday`, `localWeekNumber` and `localWeekYear`.
  6764. * They cannot be mixed with ISO-week units like `weekday`.
  6765. * @param {Object} values - a mapping of units to numbers
  6766. * @example dt.set({ year: 2017 })
  6767. * @example dt.set({ hour: 8, minute: 30 })
  6768. * @example dt.set({ weekday: 5 })
  6769. * @example dt.set({ year: 2005, ordinal: 234 })
  6770. * @return {DateTime}
  6771. */;
  6772. _proto.set = function set(values) {
  6773. if (!this.isValid) return this;
  6774. var normalized = normalizeObject(values, normalizeUnitWithLocalWeeks);
  6775. var _usesLocalWeekValues2 = usesLocalWeekValues(normalized, this.loc),
  6776. minDaysInFirstWeek = _usesLocalWeekValues2.minDaysInFirstWeek,
  6777. startOfWeek = _usesLocalWeekValues2.startOfWeek;
  6778. var settingWeekStuff = !isUndefined(normalized.weekYear) || !isUndefined(normalized.weekNumber) || !isUndefined(normalized.weekday),
  6779. containsOrdinal = !isUndefined(normalized.ordinal),
  6780. containsGregorYear = !isUndefined(normalized.year),
  6781. containsGregorMD = !isUndefined(normalized.month) || !isUndefined(normalized.day),
  6782. containsGregor = containsGregorYear || containsGregorMD,
  6783. definiteWeekDef = normalized.weekYear || normalized.weekNumber;
  6784. if ((containsGregor || containsOrdinal) && definiteWeekDef) {
  6785. throw new ConflictingSpecificationError("Can't mix weekYear/weekNumber units with year/month/day or ordinals");
  6786. }
  6787. if (containsGregorMD && containsOrdinal) {
  6788. throw new ConflictingSpecificationError("Can't mix ordinal dates with month/day");
  6789. }
  6790. var mixed;
  6791. if (settingWeekStuff) {
  6792. mixed = weekToGregorian(_extends({}, gregorianToWeek(this.c, minDaysInFirstWeek, startOfWeek), normalized), minDaysInFirstWeek, startOfWeek);
  6793. } else if (!isUndefined(normalized.ordinal)) {
  6794. mixed = ordinalToGregorian(_extends({}, gregorianToOrdinal(this.c), normalized));
  6795. } else {
  6796. mixed = _extends({}, this.toObject(), normalized);
  6797. // if we didn't set the day but we ended up on an overflow date,
  6798. // use the last day of the right month
  6799. if (isUndefined(normalized.day)) {
  6800. mixed.day = Math.min(daysInMonth(mixed.year, mixed.month), mixed.day);
  6801. }
  6802. }
  6803. var _objToTS4 = objToTS(mixed, this.o, this.zone),
  6804. ts = _objToTS4[0],
  6805. o = _objToTS4[1];
  6806. return clone(this, {
  6807. ts: ts,
  6808. o: o
  6809. });
  6810. }
  6811. /**
  6812. * Add a period of time to this DateTime and return the resulting DateTime
  6813. *
  6814. * Adding hours, minutes, seconds, or milliseconds increases the timestamp by the right number of milliseconds. Adding days, months, or years shifts the calendar, accounting for DSTs and leap years along the way. Thus, `dt.plus({ hours: 24 })` may result in a different time than `dt.plus({ days: 1 })` if there's a DST shift in between.
  6815. * @param {Duration|Object|number} duration - The amount to add. Either a Luxon Duration, a number of milliseconds, the object argument to Duration.fromObject()
  6816. * @example DateTime.now().plus(123) //~> in 123 milliseconds
  6817. * @example DateTime.now().plus({ minutes: 15 }) //~> in 15 minutes
  6818. * @example DateTime.now().plus({ days: 1 }) //~> this time tomorrow
  6819. * @example DateTime.now().plus({ days: -1 }) //~> this time yesterday
  6820. * @example DateTime.now().plus({ hours: 3, minutes: 13 }) //~> in 3 hr, 13 min
  6821. * @example DateTime.now().plus(Duration.fromObject({ hours: 3, minutes: 13 })) //~> in 3 hr, 13 min
  6822. * @return {DateTime}
  6823. */;
  6824. _proto.plus = function plus(duration) {
  6825. if (!this.isValid) return this;
  6826. var dur = Duration.fromDurationLike(duration);
  6827. return clone(this, adjustTime(this, dur));
  6828. }
  6829. /**
  6830. * Subtract a period of time to this DateTime and return the resulting DateTime
  6831. * See {@link DateTime#plus}
  6832. * @param {Duration|Object|number} duration - The amount to subtract. Either a Luxon Duration, a number of milliseconds, the object argument to Duration.fromObject()
  6833. @return {DateTime}
  6834. */;
  6835. _proto.minus = function minus(duration) {
  6836. if (!this.isValid) return this;
  6837. var dur = Duration.fromDurationLike(duration).negate();
  6838. return clone(this, adjustTime(this, dur));
  6839. }
  6840. /**
  6841. * "Set" this DateTime to the beginning of a unit of time.
  6842. * @param {string} unit - The unit to go to the beginning of. Can be 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', or 'millisecond'.
  6843. * @param {Object} opts - options
  6844. * @param {boolean} [opts.useLocaleWeeks=false] - If true, use weeks based on the locale, i.e. use the locale-dependent start of the week
  6845. * @example DateTime.local(2014, 3, 3).startOf('month').toISODate(); //=> '2014-03-01'
  6846. * @example DateTime.local(2014, 3, 3).startOf('year').toISODate(); //=> '2014-01-01'
  6847. * @example DateTime.local(2014, 3, 3).startOf('week').toISODate(); //=> '2014-03-03', weeks always start on Mondays
  6848. * @example DateTime.local(2014, 3, 3, 5, 30).startOf('day').toISOTime(); //=> '00:00.000-05:00'
  6849. * @example DateTime.local(2014, 3, 3, 5, 30).startOf('hour').toISOTime(); //=> '05:00:00.000-05:00'
  6850. * @return {DateTime}
  6851. */;
  6852. _proto.startOf = function startOf(unit, _temp3) {
  6853. var _ref4 = _temp3 === void 0 ? {} : _temp3,
  6854. _ref4$useLocaleWeeks = _ref4.useLocaleWeeks,
  6855. useLocaleWeeks = _ref4$useLocaleWeeks === void 0 ? false : _ref4$useLocaleWeeks;
  6856. if (!this.isValid) return this;
  6857. var o = {},
  6858. normalizedUnit = Duration.normalizeUnit(unit);
  6859. switch (normalizedUnit) {
  6860. case "years":
  6861. o.month = 1;
  6862. // falls through
  6863. case "quarters":
  6864. case "months":
  6865. o.day = 1;
  6866. // falls through
  6867. case "weeks":
  6868. case "days":
  6869. o.hour = 0;
  6870. // falls through
  6871. case "hours":
  6872. o.minute = 0;
  6873. // falls through
  6874. case "minutes":
  6875. o.second = 0;
  6876. // falls through
  6877. case "seconds":
  6878. o.millisecond = 0;
  6879. break;
  6880. // no default, invalid units throw in normalizeUnit()
  6881. }
  6882. if (normalizedUnit === "weeks") {
  6883. if (useLocaleWeeks) {
  6884. var startOfWeek = this.loc.getStartOfWeek();
  6885. var weekday = this.weekday;
  6886. if (weekday < startOfWeek) {
  6887. o.weekNumber = this.weekNumber - 1;
  6888. }
  6889. o.weekday = startOfWeek;
  6890. } else {
  6891. o.weekday = 1;
  6892. }
  6893. }
  6894. if (normalizedUnit === "quarters") {
  6895. var q = Math.ceil(this.month / 3);
  6896. o.month = (q - 1) * 3 + 1;
  6897. }
  6898. return this.set(o);
  6899. }
  6900. /**
  6901. * "Set" this DateTime to the end (meaning the last millisecond) of a unit of time
  6902. * @param {string} unit - The unit to go to the end of. Can be 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', or 'millisecond'.
  6903. * @param {Object} opts - options
  6904. * @param {boolean} [opts.useLocaleWeeks=false] - If true, use weeks based on the locale, i.e. use the locale-dependent start of the week
  6905. * @example DateTime.local(2014, 3, 3).endOf('month').toISO(); //=> '2014-03-31T23:59:59.999-05:00'
  6906. * @example DateTime.local(2014, 3, 3).endOf('year').toISO(); //=> '2014-12-31T23:59:59.999-05:00'
  6907. * @example DateTime.local(2014, 3, 3).endOf('week').toISO(); // => '2014-03-09T23:59:59.999-05:00', weeks start on Mondays
  6908. * @example DateTime.local(2014, 3, 3, 5, 30).endOf('day').toISO(); //=> '2014-03-03T23:59:59.999-05:00'
  6909. * @example DateTime.local(2014, 3, 3, 5, 30).endOf('hour').toISO(); //=> '2014-03-03T05:59:59.999-05:00'
  6910. * @return {DateTime}
  6911. */;
  6912. _proto.endOf = function endOf(unit, opts) {
  6913. var _this$plus;
  6914. return this.isValid ? this.plus((_this$plus = {}, _this$plus[unit] = 1, _this$plus)).startOf(unit, opts).minus(1) : this;
  6915. }
  6916. // OUTPUT
  6917. /**
  6918. * Returns a string representation of this DateTime formatted according to the specified format string.
  6919. * **You may not want this.** See {@link DateTime#toLocaleString} for a more flexible formatting tool. For a table of tokens and their interpretations, see [here](https://moment.github.io/luxon/#/formatting?id=table-of-tokens).
  6920. * Defaults to en-US if no locale has been specified, regardless of the system's locale.
  6921. * @param {string} fmt - the format string
  6922. * @param {Object} opts - opts to override the configuration options on this DateTime
  6923. * @example DateTime.now().toFormat('yyyy LLL dd') //=> '2017 Apr 22'
  6924. * @example DateTime.now().setLocale('fr').toFormat('yyyy LLL dd') //=> '2017 avr. 22'
  6925. * @example DateTime.now().toFormat('yyyy LLL dd', { locale: "fr" }) //=> '2017 avr. 22'
  6926. * @example DateTime.now().toFormat("HH 'hours and' mm 'minutes'") //=> '20 hours and 55 minutes'
  6927. * @return {string}
  6928. */;
  6929. _proto.toFormat = function toFormat(fmt, opts) {
  6930. if (opts === void 0) {
  6931. opts = {};
  6932. }
  6933. return this.isValid ? Formatter.create(this.loc.redefaultToEN(opts)).formatDateTimeFromString(this, fmt) : INVALID;
  6934. }
  6935. /**
  6936. * Returns a localized string representing this date. Accepts the same options as the Intl.DateTimeFormat constructor and any presets defined by Luxon, such as `DateTime.DATE_FULL` or `DateTime.TIME_SIMPLE`.
  6937. * The exact behavior of this method is browser-specific, but in general it will return an appropriate representation
  6938. * of the DateTime in the assigned locale.
  6939. * Defaults to the system's locale if no locale has been specified
  6940. * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
  6941. * @param formatOpts {Object} - Intl.DateTimeFormat constructor options and configuration options
  6942. * @param {Object} opts - opts to override the configuration options on this DateTime
  6943. * @example DateTime.now().toLocaleString(); //=> 4/20/2017
  6944. * @example DateTime.now().setLocale('en-gb').toLocaleString(); //=> '20/04/2017'
  6945. * @example DateTime.now().toLocaleString(DateTime.DATE_FULL); //=> 'April 20, 2017'
  6946. * @example DateTime.now().toLocaleString(DateTime.DATE_FULL, { locale: 'fr' }); //=> '28 août 2022'
  6947. * @example DateTime.now().toLocaleString(DateTime.TIME_SIMPLE); //=> '11:32 AM'
  6948. * @example DateTime.now().toLocaleString(DateTime.DATETIME_SHORT); //=> '4/20/2017, 11:32 AM'
  6949. * @example DateTime.now().toLocaleString({ weekday: 'long', month: 'long', day: '2-digit' }); //=> 'Thursday, April 20'
  6950. * @example DateTime.now().toLocaleString({ weekday: 'short', month: 'short', day: '2-digit', hour: '2-digit', minute: '2-digit' }); //=> 'Thu, Apr 20, 11:27 AM'
  6951. * @example DateTime.now().toLocaleString({ hour: '2-digit', minute: '2-digit', hourCycle: 'h23' }); //=> '11:32'
  6952. * @return {string}
  6953. */;
  6954. _proto.toLocaleString = function toLocaleString(formatOpts, opts) {
  6955. if (formatOpts === void 0) {
  6956. formatOpts = DATE_SHORT;
  6957. }
  6958. if (opts === void 0) {
  6959. opts = {};
  6960. }
  6961. return this.isValid ? Formatter.create(this.loc.clone(opts), formatOpts).formatDateTime(this) : INVALID;
  6962. }
  6963. /**
  6964. * Returns an array of format "parts", meaning individual tokens along with metadata. This is allows callers to post-process individual sections of the formatted output.
  6965. * Defaults to the system's locale if no locale has been specified
  6966. * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts
  6967. * @param opts {Object} - Intl.DateTimeFormat constructor options, same as `toLocaleString`.
  6968. * @example DateTime.now().toLocaleParts(); //=> [
  6969. * //=> { type: 'day', value: '25' },
  6970. * //=> { type: 'literal', value: '/' },
  6971. * //=> { type: 'month', value: '05' },
  6972. * //=> { type: 'literal', value: '/' },
  6973. * //=> { type: 'year', value: '1982' }
  6974. * //=> ]
  6975. */;
  6976. _proto.toLocaleParts = function toLocaleParts(opts) {
  6977. if (opts === void 0) {
  6978. opts = {};
  6979. }
  6980. return this.isValid ? Formatter.create(this.loc.clone(opts), opts).formatDateTimeParts(this) : [];
  6981. }
  6982. /**
  6983. * Returns an ISO 8601-compliant string representation of this DateTime
  6984. * @param {Object} opts - options
  6985. * @param {boolean} [opts.suppressMilliseconds=false] - exclude milliseconds from the format if they're 0
  6986. * @param {boolean} [opts.suppressSeconds=false] - exclude seconds from the format if they're 0
  6987. * @param {boolean} [opts.includeOffset=true] - include the offset, such as 'Z' or '-04:00'
  6988. * @param {boolean} [opts.extendedZone=false] - add the time zone format extension
  6989. * @param {string} [opts.format='extended'] - choose between the basic and extended format
  6990. * @example DateTime.utc(1983, 5, 25).toISO() //=> '1982-05-25T00:00:00.000Z'
  6991. * @example DateTime.now().toISO() //=> '2017-04-22T20:47:05.335-04:00'
  6992. * @example DateTime.now().toISO({ includeOffset: false }) //=> '2017-04-22T20:47:05.335'
  6993. * @example DateTime.now().toISO({ format: 'basic' }) //=> '20170422T204705.335-0400'
  6994. * @return {string}
  6995. */;
  6996. _proto.toISO = function toISO(_temp4) {
  6997. var _ref5 = _temp4 === void 0 ? {} : _temp4,
  6998. _ref5$format = _ref5.format,
  6999. format = _ref5$format === void 0 ? "extended" : _ref5$format,
  7000. _ref5$suppressSeconds = _ref5.suppressSeconds,
  7001. suppressSeconds = _ref5$suppressSeconds === void 0 ? false : _ref5$suppressSeconds,
  7002. _ref5$suppressMillise = _ref5.suppressMilliseconds,
  7003. suppressMilliseconds = _ref5$suppressMillise === void 0 ? false : _ref5$suppressMillise,
  7004. _ref5$includeOffset = _ref5.includeOffset,
  7005. includeOffset = _ref5$includeOffset === void 0 ? true : _ref5$includeOffset,
  7006. _ref5$extendedZone = _ref5.extendedZone,
  7007. extendedZone = _ref5$extendedZone === void 0 ? false : _ref5$extendedZone;
  7008. if (!this.isValid) {
  7009. return null;
  7010. }
  7011. var ext = format === "extended";
  7012. var c = _toISODate(this, ext);
  7013. c += "T";
  7014. c += _toISOTime(this, ext, suppressSeconds, suppressMilliseconds, includeOffset, extendedZone);
  7015. return c;
  7016. }
  7017. /**
  7018. * Returns an ISO 8601-compliant string representation of this DateTime's date component
  7019. * @param {Object} opts - options
  7020. * @param {string} [opts.format='extended'] - choose between the basic and extended format
  7021. * @example DateTime.utc(1982, 5, 25).toISODate() //=> '1982-05-25'
  7022. * @example DateTime.utc(1982, 5, 25).toISODate({ format: 'basic' }) //=> '19820525'
  7023. * @return {string}
  7024. */;
  7025. _proto.toISODate = function toISODate(_temp5) {
  7026. var _ref6 = _temp5 === void 0 ? {} : _temp5,
  7027. _ref6$format = _ref6.format,
  7028. format = _ref6$format === void 0 ? "extended" : _ref6$format;
  7029. if (!this.isValid) {
  7030. return null;
  7031. }
  7032. return _toISODate(this, format === "extended");
  7033. }
  7034. /**
  7035. * Returns an ISO 8601-compliant string representation of this DateTime's week date
  7036. * @example DateTime.utc(1982, 5, 25).toISOWeekDate() //=> '1982-W21-2'
  7037. * @return {string}
  7038. */;
  7039. _proto.toISOWeekDate = function toISOWeekDate() {
  7040. return toTechFormat(this, "kkkk-'W'WW-c");
  7041. }
  7042. /**
  7043. * Returns an ISO 8601-compliant string representation of this DateTime's time component
  7044. * @param {Object} opts - options
  7045. * @param {boolean} [opts.suppressMilliseconds=false] - exclude milliseconds from the format if they're 0
  7046. * @param {boolean} [opts.suppressSeconds=false] - exclude seconds from the format if they're 0
  7047. * @param {boolean} [opts.includeOffset=true] - include the offset, such as 'Z' or '-04:00'
  7048. * @param {boolean} [opts.extendedZone=true] - add the time zone format extension
  7049. * @param {boolean} [opts.includePrefix=false] - include the `T` prefix
  7050. * @param {string} [opts.format='extended'] - choose between the basic and extended format
  7051. * @example DateTime.utc().set({ hour: 7, minute: 34 }).toISOTime() //=> '07:34:19.361Z'
  7052. * @example DateTime.utc().set({ hour: 7, minute: 34, seconds: 0, milliseconds: 0 }).toISOTime({ suppressSeconds: true }) //=> '07:34Z'
  7053. * @example DateTime.utc().set({ hour: 7, minute: 34 }).toISOTime({ format: 'basic' }) //=> '073419.361Z'
  7054. * @example DateTime.utc().set({ hour: 7, minute: 34 }).toISOTime({ includePrefix: true }) //=> 'T07:34:19.361Z'
  7055. * @return {string}
  7056. */;
  7057. _proto.toISOTime = function toISOTime(_temp6) {
  7058. var _ref7 = _temp6 === void 0 ? {} : _temp6,
  7059. _ref7$suppressMillise = _ref7.suppressMilliseconds,
  7060. suppressMilliseconds = _ref7$suppressMillise === void 0 ? false : _ref7$suppressMillise,
  7061. _ref7$suppressSeconds = _ref7.suppressSeconds,
  7062. suppressSeconds = _ref7$suppressSeconds === void 0 ? false : _ref7$suppressSeconds,
  7063. _ref7$includeOffset = _ref7.includeOffset,
  7064. includeOffset = _ref7$includeOffset === void 0 ? true : _ref7$includeOffset,
  7065. _ref7$includePrefix = _ref7.includePrefix,
  7066. includePrefix = _ref7$includePrefix === void 0 ? false : _ref7$includePrefix,
  7067. _ref7$extendedZone = _ref7.extendedZone,
  7068. extendedZone = _ref7$extendedZone === void 0 ? false : _ref7$extendedZone,
  7069. _ref7$format = _ref7.format,
  7070. format = _ref7$format === void 0 ? "extended" : _ref7$format;
  7071. if (!this.isValid) {
  7072. return null;
  7073. }
  7074. var c = includePrefix ? "T" : "";
  7075. return c + _toISOTime(this, format === "extended", suppressSeconds, suppressMilliseconds, includeOffset, extendedZone);
  7076. }
  7077. /**
  7078. * Returns an RFC 2822-compatible string representation of this DateTime
  7079. * @example DateTime.utc(2014, 7, 13).toRFC2822() //=> 'Sun, 13 Jul 2014 00:00:00 +0000'
  7080. * @example DateTime.local(2014, 7, 13).toRFC2822() //=> 'Sun, 13 Jul 2014 00:00:00 -0400'
  7081. * @return {string}
  7082. */;
  7083. _proto.toRFC2822 = function toRFC2822() {
  7084. return toTechFormat(this, "EEE, dd LLL yyyy HH:mm:ss ZZZ", false);
  7085. }
  7086. /**
  7087. * Returns a string representation of this DateTime appropriate for use in HTTP headers. The output is always expressed in GMT.
  7088. * Specifically, the string conforms to RFC 1123.
  7089. * @see https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1
  7090. * @example DateTime.utc(2014, 7, 13).toHTTP() //=> 'Sun, 13 Jul 2014 00:00:00 GMT'
  7091. * @example DateTime.utc(2014, 7, 13, 19).toHTTP() //=> 'Sun, 13 Jul 2014 19:00:00 GMT'
  7092. * @return {string}
  7093. */;
  7094. _proto.toHTTP = function toHTTP() {
  7095. return toTechFormat(this.toUTC(), "EEE, dd LLL yyyy HH:mm:ss 'GMT'");
  7096. }
  7097. /**
  7098. * Returns a string representation of this DateTime appropriate for use in SQL Date
  7099. * @example DateTime.utc(2014, 7, 13).toSQLDate() //=> '2014-07-13'
  7100. * @return {string}
  7101. */;
  7102. _proto.toSQLDate = function toSQLDate() {
  7103. if (!this.isValid) {
  7104. return null;
  7105. }
  7106. return _toISODate(this, true);
  7107. }
  7108. /**
  7109. * Returns a string representation of this DateTime appropriate for use in SQL Time
  7110. * @param {Object} opts - options
  7111. * @param {boolean} [opts.includeZone=false] - include the zone, such as 'America/New_York'. Overrides includeOffset.
  7112. * @param {boolean} [opts.includeOffset=true] - include the offset, such as 'Z' or '-04:00'
  7113. * @param {boolean} [opts.includeOffsetSpace=true] - include the space between the time and the offset, such as '05:15:16.345 -04:00'
  7114. * @example DateTime.utc().toSQL() //=> '05:15:16.345'
  7115. * @example DateTime.now().toSQL() //=> '05:15:16.345 -04:00'
  7116. * @example DateTime.now().toSQL({ includeOffset: false }) //=> '05:15:16.345'
  7117. * @example DateTime.now().toSQL({ includeZone: false }) //=> '05:15:16.345 America/New_York'
  7118. * @return {string}
  7119. */;
  7120. _proto.toSQLTime = function toSQLTime(_temp7) {
  7121. var _ref8 = _temp7 === void 0 ? {} : _temp7,
  7122. _ref8$includeOffset = _ref8.includeOffset,
  7123. includeOffset = _ref8$includeOffset === void 0 ? true : _ref8$includeOffset,
  7124. _ref8$includeZone = _ref8.includeZone,
  7125. includeZone = _ref8$includeZone === void 0 ? false : _ref8$includeZone,
  7126. _ref8$includeOffsetSp = _ref8.includeOffsetSpace,
  7127. includeOffsetSpace = _ref8$includeOffsetSp === void 0 ? true : _ref8$includeOffsetSp;
  7128. var fmt = "HH:mm:ss.SSS";
  7129. if (includeZone || includeOffset) {
  7130. if (includeOffsetSpace) {
  7131. fmt += " ";
  7132. }
  7133. if (includeZone) {
  7134. fmt += "z";
  7135. } else if (includeOffset) {
  7136. fmt += "ZZ";
  7137. }
  7138. }
  7139. return toTechFormat(this, fmt, true);
  7140. }
  7141. /**
  7142. * Returns a string representation of this DateTime appropriate for use in SQL DateTime
  7143. * @param {Object} opts - options
  7144. * @param {boolean} [opts.includeZone=false] - include the zone, such as 'America/New_York'. Overrides includeOffset.
  7145. * @param {boolean} [opts.includeOffset=true] - include the offset, such as 'Z' or '-04:00'
  7146. * @param {boolean} [opts.includeOffsetSpace=true] - include the space between the time and the offset, such as '05:15:16.345 -04:00'
  7147. * @example DateTime.utc(2014, 7, 13).toSQL() //=> '2014-07-13 00:00:00.000 Z'
  7148. * @example DateTime.local(2014, 7, 13).toSQL() //=> '2014-07-13 00:00:00.000 -04:00'
  7149. * @example DateTime.local(2014, 7, 13).toSQL({ includeOffset: false }) //=> '2014-07-13 00:00:00.000'
  7150. * @example DateTime.local(2014, 7, 13).toSQL({ includeZone: true }) //=> '2014-07-13 00:00:00.000 America/New_York'
  7151. * @return {string}
  7152. */;
  7153. _proto.toSQL = function toSQL(opts) {
  7154. if (opts === void 0) {
  7155. opts = {};
  7156. }
  7157. if (!this.isValid) {
  7158. return null;
  7159. }
  7160. return this.toSQLDate() + " " + this.toSQLTime(opts);
  7161. }
  7162. /**
  7163. * Returns a string representation of this DateTime appropriate for debugging
  7164. * @return {string}
  7165. */;
  7166. _proto.toString = function toString() {
  7167. return this.isValid ? this.toISO() : INVALID;
  7168. }
  7169. /**
  7170. * Returns a string representation of this DateTime appropriate for the REPL.
  7171. * @return {string}
  7172. */;
  7173. _proto[_Symbol$for] = function () {
  7174. if (this.isValid) {
  7175. return "DateTime { ts: " + this.toISO() + ", zone: " + this.zone.name + ", locale: " + this.locale + " }";
  7176. } else {
  7177. return "DateTime { Invalid, reason: " + this.invalidReason + " }";
  7178. }
  7179. }
  7180. /**
  7181. * Returns the epoch milliseconds of this DateTime. Alias of {@link DateTime#toMillis}
  7182. * @return {number}
  7183. */;
  7184. _proto.valueOf = function valueOf() {
  7185. return this.toMillis();
  7186. }
  7187. /**
  7188. * Returns the epoch milliseconds of this DateTime.
  7189. * @return {number}
  7190. */;
  7191. _proto.toMillis = function toMillis() {
  7192. return this.isValid ? this.ts : NaN;
  7193. }
  7194. /**
  7195. * Returns the epoch seconds of this DateTime.
  7196. * @return {number}
  7197. */;
  7198. _proto.toSeconds = function toSeconds() {
  7199. return this.isValid ? this.ts / 1000 : NaN;
  7200. }
  7201. /**
  7202. * Returns the epoch seconds (as a whole number) of this DateTime.
  7203. * @return {number}
  7204. */;
  7205. _proto.toUnixInteger = function toUnixInteger() {
  7206. return this.isValid ? Math.floor(this.ts / 1000) : NaN;
  7207. }
  7208. /**
  7209. * Returns an ISO 8601 representation of this DateTime appropriate for use in JSON.
  7210. * @return {string}
  7211. */;
  7212. _proto.toJSON = function toJSON() {
  7213. return this.toISO();
  7214. }
  7215. /**
  7216. * Returns a BSON serializable equivalent to this DateTime.
  7217. * @return {Date}
  7218. */;
  7219. _proto.toBSON = function toBSON() {
  7220. return this.toJSDate();
  7221. }
  7222. /**
  7223. * Returns a JavaScript object with this DateTime's year, month, day, and so on.
  7224. * @param opts - options for generating the object
  7225. * @param {boolean} [opts.includeConfig=false] - include configuration attributes in the output
  7226. * @example DateTime.now().toObject() //=> { year: 2017, month: 4, day: 22, hour: 20, minute: 49, second: 42, millisecond: 268 }
  7227. * @return {Object}
  7228. */;
  7229. _proto.toObject = function toObject(opts) {
  7230. if (opts === void 0) {
  7231. opts = {};
  7232. }
  7233. if (!this.isValid) return {};
  7234. var base = _extends({}, this.c);
  7235. if (opts.includeConfig) {
  7236. base.outputCalendar = this.outputCalendar;
  7237. base.numberingSystem = this.loc.numberingSystem;
  7238. base.locale = this.loc.locale;
  7239. }
  7240. return base;
  7241. }
  7242. /**
  7243. * Returns a JavaScript Date equivalent to this DateTime.
  7244. * @return {Date}
  7245. */;
  7246. _proto.toJSDate = function toJSDate() {
  7247. return new Date(this.isValid ? this.ts : NaN);
  7248. }
  7249. // COMPARE
  7250. /**
  7251. * Return the difference between two DateTimes as a Duration.
  7252. * @param {DateTime} otherDateTime - the DateTime to compare this one to
  7253. * @param {string|string[]} [unit=['milliseconds']] - the unit or array of units (such as 'hours' or 'days') to include in the duration.
  7254. * @param {Object} opts - options that affect the creation of the Duration
  7255. * @param {string} [opts.conversionAccuracy='casual'] - the conversion system to use
  7256. * @example
  7257. * var i1 = DateTime.fromISO('1982-05-25T09:45'),
  7258. * i2 = DateTime.fromISO('1983-10-14T10:30');
  7259. * i2.diff(i1).toObject() //=> { milliseconds: 43807500000 }
  7260. * i2.diff(i1, 'hours').toObject() //=> { hours: 12168.75 }
  7261. * i2.diff(i1, ['months', 'days']).toObject() //=> { months: 16, days: 19.03125 }
  7262. * i2.diff(i1, ['months', 'days', 'hours']).toObject() //=> { months: 16, days: 19, hours: 0.75 }
  7263. * @return {Duration}
  7264. */;
  7265. _proto.diff = function diff(otherDateTime, unit, opts) {
  7266. if (unit === void 0) {
  7267. unit = "milliseconds";
  7268. }
  7269. if (opts === void 0) {
  7270. opts = {};
  7271. }
  7272. if (!this.isValid || !otherDateTime.isValid) {
  7273. return Duration.invalid("created by diffing an invalid DateTime");
  7274. }
  7275. var durOpts = _extends({
  7276. locale: this.locale,
  7277. numberingSystem: this.numberingSystem
  7278. }, opts);
  7279. var units = maybeArray(unit).map(Duration.normalizeUnit),
  7280. otherIsLater = otherDateTime.valueOf() > this.valueOf(),
  7281. earlier = otherIsLater ? this : otherDateTime,
  7282. later = otherIsLater ? otherDateTime : this,
  7283. diffed = _diff(earlier, later, units, durOpts);
  7284. return otherIsLater ? diffed.negate() : diffed;
  7285. }
  7286. /**
  7287. * Return the difference between this DateTime and right now.
  7288. * See {@link DateTime#diff}
  7289. * @param {string|string[]} [unit=['milliseconds']] - the unit or units units (such as 'hours' or 'days') to include in the duration
  7290. * @param {Object} opts - options that affect the creation of the Duration
  7291. * @param {string} [opts.conversionAccuracy='casual'] - the conversion system to use
  7292. * @return {Duration}
  7293. */;
  7294. _proto.diffNow = function diffNow(unit, opts) {
  7295. if (unit === void 0) {
  7296. unit = "milliseconds";
  7297. }
  7298. if (opts === void 0) {
  7299. opts = {};
  7300. }
  7301. return this.diff(DateTime.now(), unit, opts);
  7302. }
  7303. /**
  7304. * Return an Interval spanning between this DateTime and another DateTime
  7305. * @param {DateTime} otherDateTime - the other end point of the Interval
  7306. * @return {Interval}
  7307. */;
  7308. _proto.until = function until(otherDateTime) {
  7309. return this.isValid ? Interval.fromDateTimes(this, otherDateTime) : this;
  7310. }
  7311. /**
  7312. * Return whether this DateTime is in the same unit of time as another DateTime.
  7313. * Higher-order units must also be identical for this function to return `true`.
  7314. * Note that time zones are **ignored** in this comparison, which compares the **local** calendar time. Use {@link DateTime#setZone} to convert one of the dates if needed.
  7315. * @param {DateTime} otherDateTime - the other DateTime
  7316. * @param {string} unit - the unit of time to check sameness on
  7317. * @param {Object} opts - options
  7318. * @param {boolean} [opts.useLocaleWeeks=false] - If true, use weeks based on the locale, i.e. use the locale-dependent start of the week; only the locale of this DateTime is used
  7319. * @example DateTime.now().hasSame(otherDT, 'day'); //~> true if otherDT is in the same current calendar day
  7320. * @return {boolean}
  7321. */;
  7322. _proto.hasSame = function hasSame(otherDateTime, unit, opts) {
  7323. if (!this.isValid) return false;
  7324. var inputMs = otherDateTime.valueOf();
  7325. var adjustedToZone = this.setZone(otherDateTime.zone, {
  7326. keepLocalTime: true
  7327. });
  7328. return adjustedToZone.startOf(unit, opts) <= inputMs && inputMs <= adjustedToZone.endOf(unit, opts);
  7329. }
  7330. /**
  7331. * Equality check
  7332. * Two DateTimes are equal if and only if they represent the same millisecond, have the same zone and location, and are both valid.
  7333. * To compare just the millisecond values, use `+dt1 === +dt2`.
  7334. * @param {DateTime} other - the other DateTime
  7335. * @return {boolean}
  7336. */;
  7337. _proto.equals = function equals(other) {
  7338. return this.isValid && other.isValid && this.valueOf() === other.valueOf() && this.zone.equals(other.zone) && this.loc.equals(other.loc);
  7339. }
  7340. /**
  7341. * Returns a string representation of a this time relative to now, such as "in two days". Can only internationalize if your
  7342. * platform supports Intl.RelativeTimeFormat. Rounds down by default.
  7343. * @param {Object} options - options that affect the output
  7344. * @param {DateTime} [options.base=DateTime.now()] - the DateTime to use as the basis to which this time is compared. Defaults to now.
  7345. * @param {string} [options.style="long"] - the style of units, must be "long", "short", or "narrow"
  7346. * @param {string|string[]} options.unit - use a specific unit or array of units; if omitted, or an array, the method will pick the best unit. Use an array or one of "years", "quarters", "months", "weeks", "days", "hours", "minutes", or "seconds"
  7347. * @param {boolean} [options.round=true] - whether to round the numbers in the output.
  7348. * @param {number} [options.padding=0] - padding in milliseconds. This allows you to round up the result if it fits inside the threshold. Don't use in combination with {round: false} because the decimal output will include the padding.
  7349. * @param {string} options.locale - override the locale of this DateTime
  7350. * @param {string} options.numberingSystem - override the numberingSystem of this DateTime. The Intl system may choose not to honor this
  7351. * @example DateTime.now().plus({ days: 1 }).toRelative() //=> "in 1 day"
  7352. * @example DateTime.now().setLocale("es").toRelative({ days: 1 }) //=> "dentro de 1 día"
  7353. * @example DateTime.now().plus({ days: 1 }).toRelative({ locale: "fr" }) //=> "dans 23 heures"
  7354. * @example DateTime.now().minus({ days: 2 }).toRelative() //=> "2 days ago"
  7355. * @example DateTime.now().minus({ days: 2 }).toRelative({ unit: "hours" }) //=> "48 hours ago"
  7356. * @example DateTime.now().minus({ hours: 36 }).toRelative({ round: false }) //=> "1.5 days ago"
  7357. */;
  7358. _proto.toRelative = function toRelative(options) {
  7359. if (options === void 0) {
  7360. options = {};
  7361. }
  7362. if (!this.isValid) return null;
  7363. var base = options.base || DateTime.fromObject({}, {
  7364. zone: this.zone
  7365. }),
  7366. padding = options.padding ? this < base ? -options.padding : options.padding : 0;
  7367. var units = ["years", "months", "days", "hours", "minutes", "seconds"];
  7368. var unit = options.unit;
  7369. if (Array.isArray(options.unit)) {
  7370. units = options.unit;
  7371. unit = undefined;
  7372. }
  7373. return diffRelative(base, this.plus(padding), _extends({}, options, {
  7374. numeric: "always",
  7375. units: units,
  7376. unit: unit
  7377. }));
  7378. }
  7379. /**
  7380. * Returns a string representation of this date relative to today, such as "yesterday" or "next month".
  7381. * Only internationalizes on platforms that supports Intl.RelativeTimeFormat.
  7382. * @param {Object} options - options that affect the output
  7383. * @param {DateTime} [options.base=DateTime.now()] - the DateTime to use as the basis to which this time is compared. Defaults to now.
  7384. * @param {string} options.locale - override the locale of this DateTime
  7385. * @param {string} options.unit - use a specific unit; if omitted, the method will pick the unit. Use one of "years", "quarters", "months", "weeks", or "days"
  7386. * @param {string} options.numberingSystem - override the numberingSystem of this DateTime. The Intl system may choose not to honor this
  7387. * @example DateTime.now().plus({ days: 1 }).toRelativeCalendar() //=> "tomorrow"
  7388. * @example DateTime.now().setLocale("es").plus({ days: 1 }).toRelative() //=> ""mañana"
  7389. * @example DateTime.now().plus({ days: 1 }).toRelativeCalendar({ locale: "fr" }) //=> "demain"
  7390. * @example DateTime.now().minus({ days: 2 }).toRelativeCalendar() //=> "2 days ago"
  7391. */;
  7392. _proto.toRelativeCalendar = function toRelativeCalendar(options) {
  7393. if (options === void 0) {
  7394. options = {};
  7395. }
  7396. if (!this.isValid) return null;
  7397. return diffRelative(options.base || DateTime.fromObject({}, {
  7398. zone: this.zone
  7399. }), this, _extends({}, options, {
  7400. numeric: "auto",
  7401. units: ["years", "months", "days"],
  7402. calendary: true
  7403. }));
  7404. }
  7405. /**
  7406. * Return the min of several date times
  7407. * @param {...DateTime} dateTimes - the DateTimes from which to choose the minimum
  7408. * @return {DateTime} the min DateTime, or undefined if called with no argument
  7409. */;
  7410. DateTime.min = function min() {
  7411. for (var _len = arguments.length, dateTimes = new Array(_len), _key = 0; _key < _len; _key++) {
  7412. dateTimes[_key] = arguments[_key];
  7413. }
  7414. if (!dateTimes.every(DateTime.isDateTime)) {
  7415. throw new InvalidArgumentError("min requires all arguments be DateTimes");
  7416. }
  7417. return bestBy(dateTimes, function (i) {
  7418. return i.valueOf();
  7419. }, Math.min);
  7420. }
  7421. /**
  7422. * Return the max of several date times
  7423. * @param {...DateTime} dateTimes - the DateTimes from which to choose the maximum
  7424. * @return {DateTime} the max DateTime, or undefined if called with no argument
  7425. */;
  7426. DateTime.max = function max() {
  7427. for (var _len2 = arguments.length, dateTimes = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  7428. dateTimes[_key2] = arguments[_key2];
  7429. }
  7430. if (!dateTimes.every(DateTime.isDateTime)) {
  7431. throw new InvalidArgumentError("max requires all arguments be DateTimes");
  7432. }
  7433. return bestBy(dateTimes, function (i) {
  7434. return i.valueOf();
  7435. }, Math.max);
  7436. }
  7437. // MISC
  7438. /**
  7439. * Explain how a string would be parsed by fromFormat()
  7440. * @param {string} text - the string to parse
  7441. * @param {string} fmt - the format the string is expected to be in (see description)
  7442. * @param {Object} options - options taken by fromFormat()
  7443. * @return {Object}
  7444. */;
  7445. DateTime.fromFormatExplain = function fromFormatExplain(text, fmt, options) {
  7446. if (options === void 0) {
  7447. options = {};
  7448. }
  7449. var _options = options,
  7450. _options$locale = _options.locale,
  7451. locale = _options$locale === void 0 ? null : _options$locale,
  7452. _options$numberingSys = _options.numberingSystem,
  7453. numberingSystem = _options$numberingSys === void 0 ? null : _options$numberingSys,
  7454. localeToUse = Locale.fromOpts({
  7455. locale: locale,
  7456. numberingSystem: numberingSystem,
  7457. defaultToEN: true
  7458. });
  7459. return explainFromTokens(localeToUse, text, fmt);
  7460. }
  7461. /**
  7462. * @deprecated use fromFormatExplain instead
  7463. */;
  7464. DateTime.fromStringExplain = function fromStringExplain(text, fmt, options) {
  7465. if (options === void 0) {
  7466. options = {};
  7467. }
  7468. return DateTime.fromFormatExplain(text, fmt, options);
  7469. }
  7470. /**
  7471. * Build a parser for `fmt` using the given locale. This parser can be passed
  7472. * to {@link DateTime.fromFormatParser} to a parse a date in this format. This
  7473. * can be used to optimize cases where many dates need to be parsed in a
  7474. * specific format.
  7475. *
  7476. * @param {String} fmt - the format the string is expected to be in (see
  7477. * description)
  7478. * @param {Object} options - options used to set locale and numberingSystem
  7479. * for parser
  7480. * @returns {TokenParser} - opaque object to be used
  7481. */;
  7482. DateTime.buildFormatParser = function buildFormatParser(fmt, options) {
  7483. if (options === void 0) {
  7484. options = {};
  7485. }
  7486. var _options2 = options,
  7487. _options2$locale = _options2.locale,
  7488. locale = _options2$locale === void 0 ? null : _options2$locale,
  7489. _options2$numberingSy = _options2.numberingSystem,
  7490. numberingSystem = _options2$numberingSy === void 0 ? null : _options2$numberingSy,
  7491. localeToUse = Locale.fromOpts({
  7492. locale: locale,
  7493. numberingSystem: numberingSystem,
  7494. defaultToEN: true
  7495. });
  7496. return new TokenParser(localeToUse, fmt);
  7497. }
  7498. /**
  7499. * Create a DateTime from an input string and format parser.
  7500. *
  7501. * The format parser must have been created with the same locale as this call.
  7502. *
  7503. * @param {String} text - the string to parse
  7504. * @param {TokenParser} formatParser - parser from {@link DateTime.buildFormatParser}
  7505. * @param {Object} opts - options taken by fromFormat()
  7506. * @returns {DateTime}
  7507. */;
  7508. DateTime.fromFormatParser = function fromFormatParser(text, formatParser, opts) {
  7509. if (opts === void 0) {
  7510. opts = {};
  7511. }
  7512. if (isUndefined(text) || isUndefined(formatParser)) {
  7513. throw new InvalidArgumentError("fromFormatParser requires an input string and a format parser");
  7514. }
  7515. var _opts2 = opts,
  7516. _opts2$locale = _opts2.locale,
  7517. locale = _opts2$locale === void 0 ? null : _opts2$locale,
  7518. _opts2$numberingSyste = _opts2.numberingSystem,
  7519. numberingSystem = _opts2$numberingSyste === void 0 ? null : _opts2$numberingSyste,
  7520. localeToUse = Locale.fromOpts({
  7521. locale: locale,
  7522. numberingSystem: numberingSystem,
  7523. defaultToEN: true
  7524. });
  7525. if (!localeToUse.equals(formatParser.locale)) {
  7526. throw new InvalidArgumentError("fromFormatParser called with a locale of " + localeToUse + ", " + ("but the format parser was created for " + formatParser.locale));
  7527. }
  7528. var _formatParser$explain = formatParser.explainFromTokens(text),
  7529. result = _formatParser$explain.result,
  7530. zone = _formatParser$explain.zone,
  7531. specificOffset = _formatParser$explain.specificOffset,
  7532. invalidReason = _formatParser$explain.invalidReason;
  7533. if (invalidReason) {
  7534. return DateTime.invalid(invalidReason);
  7535. } else {
  7536. return parseDataToDateTime(result, zone, opts, "format " + formatParser.format, text, specificOffset);
  7537. }
  7538. }
  7539. // FORMAT PRESETS
  7540. /**
  7541. * {@link DateTime#toLocaleString} format like 10/14/1983
  7542. * @type {Object}
  7543. */;
  7544. _createClass(DateTime, [{
  7545. key: "isValid",
  7546. get: function get() {
  7547. return this.invalid === null;
  7548. }
  7549. /**
  7550. * Returns an error code if this DateTime is invalid, or null if the DateTime is valid
  7551. * @type {string}
  7552. */
  7553. }, {
  7554. key: "invalidReason",
  7555. get: function get() {
  7556. return this.invalid ? this.invalid.reason : null;
  7557. }
  7558. /**
  7559. * Returns an explanation of why this DateTime became invalid, or null if the DateTime is valid
  7560. * @type {string}
  7561. */
  7562. }, {
  7563. key: "invalidExplanation",
  7564. get: function get() {
  7565. return this.invalid ? this.invalid.explanation : null;
  7566. }
  7567. /**
  7568. * Get the locale of a DateTime, such 'en-GB'. The locale is used when formatting the DateTime
  7569. *
  7570. * @type {string}
  7571. */
  7572. }, {
  7573. key: "locale",
  7574. get: function get() {
  7575. return this.isValid ? this.loc.locale : null;
  7576. }
  7577. /**
  7578. * Get the numbering system of a DateTime, such 'beng'. The numbering system is used when formatting the DateTime
  7579. *
  7580. * @type {string}
  7581. */
  7582. }, {
  7583. key: "numberingSystem",
  7584. get: function get() {
  7585. return this.isValid ? this.loc.numberingSystem : null;
  7586. }
  7587. /**
  7588. * Get the output calendar of a DateTime, such 'islamic'. The output calendar is used when formatting the DateTime
  7589. *
  7590. * @type {string}
  7591. */
  7592. }, {
  7593. key: "outputCalendar",
  7594. get: function get() {
  7595. return this.isValid ? this.loc.outputCalendar : null;
  7596. }
  7597. /**
  7598. * Get the time zone associated with this DateTime.
  7599. * @type {Zone}
  7600. */
  7601. }, {
  7602. key: "zone",
  7603. get: function get() {
  7604. return this._zone;
  7605. }
  7606. /**
  7607. * Get the name of the time zone.
  7608. * @type {string}
  7609. */
  7610. }, {
  7611. key: "zoneName",
  7612. get: function get() {
  7613. return this.isValid ? this.zone.name : null;
  7614. }
  7615. /**
  7616. * Get the year
  7617. * @example DateTime.local(2017, 5, 25).year //=> 2017
  7618. * @type {number}
  7619. */
  7620. }, {
  7621. key: "year",
  7622. get: function get() {
  7623. return this.isValid ? this.c.year : NaN;
  7624. }
  7625. /**
  7626. * Get the quarter
  7627. * @example DateTime.local(2017, 5, 25).quarter //=> 2
  7628. * @type {number}
  7629. */
  7630. }, {
  7631. key: "quarter",
  7632. get: function get() {
  7633. return this.isValid ? Math.ceil(this.c.month / 3) : NaN;
  7634. }
  7635. /**
  7636. * Get the month (1-12).
  7637. * @example DateTime.local(2017, 5, 25).month //=> 5
  7638. * @type {number}
  7639. */
  7640. }, {
  7641. key: "month",
  7642. get: function get() {
  7643. return this.isValid ? this.c.month : NaN;
  7644. }
  7645. /**
  7646. * Get the day of the month (1-30ish).
  7647. * @example DateTime.local(2017, 5, 25).day //=> 25
  7648. * @type {number}
  7649. */
  7650. }, {
  7651. key: "day",
  7652. get: function get() {
  7653. return this.isValid ? this.c.day : NaN;
  7654. }
  7655. /**
  7656. * Get the hour of the day (0-23).
  7657. * @example DateTime.local(2017, 5, 25, 9).hour //=> 9
  7658. * @type {number}
  7659. */
  7660. }, {
  7661. key: "hour",
  7662. get: function get() {
  7663. return this.isValid ? this.c.hour : NaN;
  7664. }
  7665. /**
  7666. * Get the minute of the hour (0-59).
  7667. * @example DateTime.local(2017, 5, 25, 9, 30).minute //=> 30
  7668. * @type {number}
  7669. */
  7670. }, {
  7671. key: "minute",
  7672. get: function get() {
  7673. return this.isValid ? this.c.minute : NaN;
  7674. }
  7675. /**
  7676. * Get the second of the minute (0-59).
  7677. * @example DateTime.local(2017, 5, 25, 9, 30, 52).second //=> 52
  7678. * @type {number}
  7679. */
  7680. }, {
  7681. key: "second",
  7682. get: function get() {
  7683. return this.isValid ? this.c.second : NaN;
  7684. }
  7685. /**
  7686. * Get the millisecond of the second (0-999).
  7687. * @example DateTime.local(2017, 5, 25, 9, 30, 52, 654).millisecond //=> 654
  7688. * @type {number}
  7689. */
  7690. }, {
  7691. key: "millisecond",
  7692. get: function get() {
  7693. return this.isValid ? this.c.millisecond : NaN;
  7694. }
  7695. /**
  7696. * Get the week year
  7697. * @see https://en.wikipedia.org/wiki/ISO_week_date
  7698. * @example DateTime.local(2014, 12, 31).weekYear //=> 2015
  7699. * @type {number}
  7700. */
  7701. }, {
  7702. key: "weekYear",
  7703. get: function get() {
  7704. return this.isValid ? possiblyCachedWeekData(this).weekYear : NaN;
  7705. }
  7706. /**
  7707. * Get the week number of the week year (1-52ish).
  7708. * @see https://en.wikipedia.org/wiki/ISO_week_date
  7709. * @example DateTime.local(2017, 5, 25).weekNumber //=> 21
  7710. * @type {number}
  7711. */
  7712. }, {
  7713. key: "weekNumber",
  7714. get: function get() {
  7715. return this.isValid ? possiblyCachedWeekData(this).weekNumber : NaN;
  7716. }
  7717. /**
  7718. * Get the day of the week.
  7719. * 1 is Monday and 7 is Sunday
  7720. * @see https://en.wikipedia.org/wiki/ISO_week_date
  7721. * @example DateTime.local(2014, 11, 31).weekday //=> 4
  7722. * @type {number}
  7723. */
  7724. }, {
  7725. key: "weekday",
  7726. get: function get() {
  7727. return this.isValid ? possiblyCachedWeekData(this).weekday : NaN;
  7728. }
  7729. /**
  7730. * Returns true if this date is on a weekend according to the locale, false otherwise
  7731. * @returns {boolean}
  7732. */
  7733. }, {
  7734. key: "isWeekend",
  7735. get: function get() {
  7736. return this.isValid && this.loc.getWeekendDays().includes(this.weekday);
  7737. }
  7738. /**
  7739. * Get the day of the week according to the locale.
  7740. * 1 is the first day of the week and 7 is the last day of the week.
  7741. * If the locale assigns Sunday as the first day of the week, then a date which is a Sunday will return 1,
  7742. * @returns {number}
  7743. */
  7744. }, {
  7745. key: "localWeekday",
  7746. get: function get() {
  7747. return this.isValid ? possiblyCachedLocalWeekData(this).weekday : NaN;
  7748. }
  7749. /**
  7750. * Get the week number of the week year according to the locale. Different locales assign week numbers differently,
  7751. * because the week can start on different days of the week (see localWeekday) and because a different number of days
  7752. * is required for a week to count as the first week of a year.
  7753. * @returns {number}
  7754. */
  7755. }, {
  7756. key: "localWeekNumber",
  7757. get: function get() {
  7758. return this.isValid ? possiblyCachedLocalWeekData(this).weekNumber : NaN;
  7759. }
  7760. /**
  7761. * Get the week year according to the locale. Different locales assign week numbers (and therefor week years)
  7762. * differently, see localWeekNumber.
  7763. * @returns {number}
  7764. */
  7765. }, {
  7766. key: "localWeekYear",
  7767. get: function get() {
  7768. return this.isValid ? possiblyCachedLocalWeekData(this).weekYear : NaN;
  7769. }
  7770. /**
  7771. * Get the ordinal (meaning the day of the year)
  7772. * @example DateTime.local(2017, 5, 25).ordinal //=> 145
  7773. * @type {number|DateTime}
  7774. */
  7775. }, {
  7776. key: "ordinal",
  7777. get: function get() {
  7778. return this.isValid ? gregorianToOrdinal(this.c).ordinal : NaN;
  7779. }
  7780. /**
  7781. * Get the human readable short month name, such as 'Oct'.
  7782. * Defaults to the system's locale if no locale has been specified
  7783. * @example DateTime.local(2017, 10, 30).monthShort //=> Oct
  7784. * @type {string}
  7785. */
  7786. }, {
  7787. key: "monthShort",
  7788. get: function get() {
  7789. return this.isValid ? Info.months("short", {
  7790. locObj: this.loc
  7791. })[this.month - 1] : null;
  7792. }
  7793. /**
  7794. * Get the human readable long month name, such as 'October'.
  7795. * Defaults to the system's locale if no locale has been specified
  7796. * @example DateTime.local(2017, 10, 30).monthLong //=> October
  7797. * @type {string}
  7798. */
  7799. }, {
  7800. key: "monthLong",
  7801. get: function get() {
  7802. return this.isValid ? Info.months("long", {
  7803. locObj: this.loc
  7804. })[this.month - 1] : null;
  7805. }
  7806. /**
  7807. * Get the human readable short weekday, such as 'Mon'.
  7808. * Defaults to the system's locale if no locale has been specified
  7809. * @example DateTime.local(2017, 10, 30).weekdayShort //=> Mon
  7810. * @type {string}
  7811. */
  7812. }, {
  7813. key: "weekdayShort",
  7814. get: function get() {
  7815. return this.isValid ? Info.weekdays("short", {
  7816. locObj: this.loc
  7817. })[this.weekday - 1] : null;
  7818. }
  7819. /**
  7820. * Get the human readable long weekday, such as 'Monday'.
  7821. * Defaults to the system's locale if no locale has been specified
  7822. * @example DateTime.local(2017, 10, 30).weekdayLong //=> Monday
  7823. * @type {string}
  7824. */
  7825. }, {
  7826. key: "weekdayLong",
  7827. get: function get() {
  7828. return this.isValid ? Info.weekdays("long", {
  7829. locObj: this.loc
  7830. })[this.weekday - 1] : null;
  7831. }
  7832. /**
  7833. * Get the UTC offset of this DateTime in minutes
  7834. * @example DateTime.now().offset //=> -240
  7835. * @example DateTime.utc().offset //=> 0
  7836. * @type {number}
  7837. */
  7838. }, {
  7839. key: "offset",
  7840. get: function get() {
  7841. return this.isValid ? +this.o : NaN;
  7842. }
  7843. /**
  7844. * Get the short human name for the zone's current offset, for example "EST" or "EDT".
  7845. * Defaults to the system's locale if no locale has been specified
  7846. * @type {string}
  7847. */
  7848. }, {
  7849. key: "offsetNameShort",
  7850. get: function get() {
  7851. if (this.isValid) {
  7852. return this.zone.offsetName(this.ts, {
  7853. format: "short",
  7854. locale: this.locale
  7855. });
  7856. } else {
  7857. return null;
  7858. }
  7859. }
  7860. /**
  7861. * Get the long human name for the zone's current offset, for example "Eastern Standard Time" or "Eastern Daylight Time".
  7862. * Defaults to the system's locale if no locale has been specified
  7863. * @type {string}
  7864. */
  7865. }, {
  7866. key: "offsetNameLong",
  7867. get: function get() {
  7868. if (this.isValid) {
  7869. return this.zone.offsetName(this.ts, {
  7870. format: "long",
  7871. locale: this.locale
  7872. });
  7873. } else {
  7874. return null;
  7875. }
  7876. }
  7877. /**
  7878. * Get whether this zone's offset ever changes, as in a DST.
  7879. * @type {boolean}
  7880. */
  7881. }, {
  7882. key: "isOffsetFixed",
  7883. get: function get() {
  7884. return this.isValid ? this.zone.isUniversal : null;
  7885. }
  7886. /**
  7887. * Get whether the DateTime is in a DST.
  7888. * @type {boolean}
  7889. */
  7890. }, {
  7891. key: "isInDST",
  7892. get: function get() {
  7893. if (this.isOffsetFixed) {
  7894. return false;
  7895. } else {
  7896. return this.offset > this.set({
  7897. month: 1,
  7898. day: 1
  7899. }).offset || this.offset > this.set({
  7900. month: 5
  7901. }).offset;
  7902. }
  7903. }
  7904. }, {
  7905. key: "isInLeapYear",
  7906. get: function get() {
  7907. return isLeapYear(this.year);
  7908. }
  7909. /**
  7910. * Returns the number of days in this DateTime's month
  7911. * @example DateTime.local(2016, 2).daysInMonth //=> 29
  7912. * @example DateTime.local(2016, 3).daysInMonth //=> 31
  7913. * @type {number}
  7914. */
  7915. }, {
  7916. key: "daysInMonth",
  7917. get: function get() {
  7918. return daysInMonth(this.year, this.month);
  7919. }
  7920. /**
  7921. * Returns the number of days in this DateTime's year
  7922. * @example DateTime.local(2016).daysInYear //=> 366
  7923. * @example DateTime.local(2013).daysInYear //=> 365
  7924. * @type {number}
  7925. */
  7926. }, {
  7927. key: "daysInYear",
  7928. get: function get() {
  7929. return this.isValid ? daysInYear(this.year) : NaN;
  7930. }
  7931. /**
  7932. * Returns the number of weeks in this DateTime's year
  7933. * @see https://en.wikipedia.org/wiki/ISO_week_date
  7934. * @example DateTime.local(2004).weeksInWeekYear //=> 53
  7935. * @example DateTime.local(2013).weeksInWeekYear //=> 52
  7936. * @type {number}
  7937. */
  7938. }, {
  7939. key: "weeksInWeekYear",
  7940. get: function get() {
  7941. return this.isValid ? weeksInWeekYear(this.weekYear) : NaN;
  7942. }
  7943. /**
  7944. * Returns the number of weeks in this DateTime's local week year
  7945. * @example DateTime.local(2020, 6, {locale: 'en-US'}).weeksInLocalWeekYear //=> 52
  7946. * @example DateTime.local(2020, 6, {locale: 'de-DE'}).weeksInLocalWeekYear //=> 53
  7947. * @type {number}
  7948. */
  7949. }, {
  7950. key: "weeksInLocalWeekYear",
  7951. get: function get() {
  7952. return this.isValid ? weeksInWeekYear(this.localWeekYear, this.loc.getMinDaysInFirstWeek(), this.loc.getStartOfWeek()) : NaN;
  7953. }
  7954. }], [{
  7955. key: "DATE_SHORT",
  7956. get: function get() {
  7957. return DATE_SHORT;
  7958. }
  7959. /**
  7960. * {@link DateTime#toLocaleString} format like 'Oct 14, 1983'
  7961. * @type {Object}
  7962. */
  7963. }, {
  7964. key: "DATE_MED",
  7965. get: function get() {
  7966. return DATE_MED;
  7967. }
  7968. /**
  7969. * {@link DateTime#toLocaleString} format like 'Fri, Oct 14, 1983'
  7970. * @type {Object}
  7971. */
  7972. }, {
  7973. key: "DATE_MED_WITH_WEEKDAY",
  7974. get: function get() {
  7975. return DATE_MED_WITH_WEEKDAY;
  7976. }
  7977. /**
  7978. * {@link DateTime#toLocaleString} format like 'October 14, 1983'
  7979. * @type {Object}
  7980. */
  7981. }, {
  7982. key: "DATE_FULL",
  7983. get: function get() {
  7984. return DATE_FULL;
  7985. }
  7986. /**
  7987. * {@link DateTime#toLocaleString} format like 'Tuesday, October 14, 1983'
  7988. * @type {Object}
  7989. */
  7990. }, {
  7991. key: "DATE_HUGE",
  7992. get: function get() {
  7993. return DATE_HUGE;
  7994. }
  7995. /**
  7996. * {@link DateTime#toLocaleString} format like '09:30 AM'. Only 12-hour if the locale is.
  7997. * @type {Object}
  7998. */
  7999. }, {
  8000. key: "TIME_SIMPLE",
  8001. get: function get() {
  8002. return TIME_SIMPLE;
  8003. }
  8004. /**
  8005. * {@link DateTime#toLocaleString} format like '09:30:23 AM'. Only 12-hour if the locale is.
  8006. * @type {Object}
  8007. */
  8008. }, {
  8009. key: "TIME_WITH_SECONDS",
  8010. get: function get() {
  8011. return TIME_WITH_SECONDS;
  8012. }
  8013. /**
  8014. * {@link DateTime#toLocaleString} format like '09:30:23 AM EDT'. Only 12-hour if the locale is.
  8015. * @type {Object}
  8016. */
  8017. }, {
  8018. key: "TIME_WITH_SHORT_OFFSET",
  8019. get: function get() {
  8020. return TIME_WITH_SHORT_OFFSET;
  8021. }
  8022. /**
  8023. * {@link DateTime#toLocaleString} format like '09:30:23 AM Eastern Daylight Time'. Only 12-hour if the locale is.
  8024. * @type {Object}
  8025. */
  8026. }, {
  8027. key: "TIME_WITH_LONG_OFFSET",
  8028. get: function get() {
  8029. return TIME_WITH_LONG_OFFSET;
  8030. }
  8031. /**
  8032. * {@link DateTime#toLocaleString} format like '09:30', always 24-hour.
  8033. * @type {Object}
  8034. */
  8035. }, {
  8036. key: "TIME_24_SIMPLE",
  8037. get: function get() {
  8038. return TIME_24_SIMPLE;
  8039. }
  8040. /**
  8041. * {@link DateTime#toLocaleString} format like '09:30:23', always 24-hour.
  8042. * @type {Object}
  8043. */
  8044. }, {
  8045. key: "TIME_24_WITH_SECONDS",
  8046. get: function get() {
  8047. return TIME_24_WITH_SECONDS;
  8048. }
  8049. /**
  8050. * {@link DateTime#toLocaleString} format like '09:30:23 EDT', always 24-hour.
  8051. * @type {Object}
  8052. */
  8053. }, {
  8054. key: "TIME_24_WITH_SHORT_OFFSET",
  8055. get: function get() {
  8056. return TIME_24_WITH_SHORT_OFFSET;
  8057. }
  8058. /**
  8059. * {@link DateTime#toLocaleString} format like '09:30:23 Eastern Daylight Time', always 24-hour.
  8060. * @type {Object}
  8061. */
  8062. }, {
  8063. key: "TIME_24_WITH_LONG_OFFSET",
  8064. get: function get() {
  8065. return TIME_24_WITH_LONG_OFFSET;
  8066. }
  8067. /**
  8068. * {@link DateTime#toLocaleString} format like '10/14/1983, 9:30 AM'. Only 12-hour if the locale is.
  8069. * @type {Object}
  8070. */
  8071. }, {
  8072. key: "DATETIME_SHORT",
  8073. get: function get() {
  8074. return DATETIME_SHORT;
  8075. }
  8076. /**
  8077. * {@link DateTime#toLocaleString} format like '10/14/1983, 9:30:33 AM'. Only 12-hour if the locale is.
  8078. * @type {Object}
  8079. */
  8080. }, {
  8081. key: "DATETIME_SHORT_WITH_SECONDS",
  8082. get: function get() {
  8083. return DATETIME_SHORT_WITH_SECONDS;
  8084. }
  8085. /**
  8086. * {@link DateTime#toLocaleString} format like 'Oct 14, 1983, 9:30 AM'. Only 12-hour if the locale is.
  8087. * @type {Object}
  8088. */
  8089. }, {
  8090. key: "DATETIME_MED",
  8091. get: function get() {
  8092. return DATETIME_MED;
  8093. }
  8094. /**
  8095. * {@link DateTime#toLocaleString} format like 'Oct 14, 1983, 9:30:33 AM'. Only 12-hour if the locale is.
  8096. * @type {Object}
  8097. */
  8098. }, {
  8099. key: "DATETIME_MED_WITH_SECONDS",
  8100. get: function get() {
  8101. return DATETIME_MED_WITH_SECONDS;
  8102. }
  8103. /**
  8104. * {@link DateTime#toLocaleString} format like 'Fri, 14 Oct 1983, 9:30 AM'. Only 12-hour if the locale is.
  8105. * @type {Object}
  8106. */
  8107. }, {
  8108. key: "DATETIME_MED_WITH_WEEKDAY",
  8109. get: function get() {
  8110. return DATETIME_MED_WITH_WEEKDAY;
  8111. }
  8112. /**
  8113. * {@link DateTime#toLocaleString} format like 'October 14, 1983, 9:30 AM EDT'. Only 12-hour if the locale is.
  8114. * @type {Object}
  8115. */
  8116. }, {
  8117. key: "DATETIME_FULL",
  8118. get: function get() {
  8119. return DATETIME_FULL;
  8120. }
  8121. /**
  8122. * {@link DateTime#toLocaleString} format like 'October 14, 1983, 9:30:33 AM EDT'. Only 12-hour if the locale is.
  8123. * @type {Object}
  8124. */
  8125. }, {
  8126. key: "DATETIME_FULL_WITH_SECONDS",
  8127. get: function get() {
  8128. return DATETIME_FULL_WITH_SECONDS;
  8129. }
  8130. /**
  8131. * {@link DateTime#toLocaleString} format like 'Friday, October 14, 1983, 9:30 AM Eastern Daylight Time'. Only 12-hour if the locale is.
  8132. * @type {Object}
  8133. */
  8134. }, {
  8135. key: "DATETIME_HUGE",
  8136. get: function get() {
  8137. return DATETIME_HUGE;
  8138. }
  8139. /**
  8140. * {@link DateTime#toLocaleString} format like 'Friday, October 14, 1983, 9:30:33 AM Eastern Daylight Time'. Only 12-hour if the locale is.
  8141. * @type {Object}
  8142. */
  8143. }, {
  8144. key: "DATETIME_HUGE_WITH_SECONDS",
  8145. get: function get() {
  8146. return DATETIME_HUGE_WITH_SECONDS;
  8147. }
  8148. }]);
  8149. return DateTime;
  8150. }(Symbol.for("nodejs.util.inspect.custom"));
  8151. function friendlyDateTime(dateTimeish) {
  8152. if (DateTime.isDateTime(dateTimeish)) {
  8153. return dateTimeish;
  8154. } else if (dateTimeish && dateTimeish.valueOf && isNumber(dateTimeish.valueOf())) {
  8155. return DateTime.fromJSDate(dateTimeish);
  8156. } else if (dateTimeish && typeof dateTimeish === "object") {
  8157. return DateTime.fromObject(dateTimeish);
  8158. } else {
  8159. throw new InvalidArgumentError("Unknown datetime argument: " + dateTimeish + ", of type " + typeof dateTimeish);
  8160. }
  8161. }
  8162. var VERSION = "3.5.0";
  8163. exports.DateTime = DateTime;
  8164. exports.Duration = Duration;
  8165. exports.FixedOffsetZone = FixedOffsetZone;
  8166. exports.IANAZone = IANAZone;
  8167. exports.Info = Info;
  8168. exports.Interval = Interval;
  8169. exports.InvalidZone = InvalidZone;
  8170. exports.Settings = Settings;
  8171. exports.SystemZone = SystemZone;
  8172. exports.VERSION = VERSION;
  8173. exports.Zone = Zone;
  8174. //# sourceMappingURL=luxon.js.map