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

luxon.js 303KB

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