luxon.js 251 KB

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