luxon.js 249 KB

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