cron-parser.js 293 KB

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