New UI layout
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

moment.js 146KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649
  1. //! moment.js
  2. //! version : 2.29.4
  3. //! authors : Tim Wood, Iskren Chernev, Moment.js contributors
  4. //! license : MIT
  5. //! momentjs.com
  6. (function (global, factory) {
  7. typeof exports === "object" && typeof module !== "undefined"
  8. ? (module.exports = factory())
  9. : typeof define === "function" && define.amd
  10. ? define(factory)
  11. : (global.moment = factory());
  12. })(this, function () {
  13. "use strict";
  14. var hookCallback;
  15. function hooks() {
  16. return hookCallback.apply(null, arguments);
  17. }
  18. // This is done to register the method called with moment()
  19. // without creating circular dependencies.
  20. function setHookCallback(callback) {
  21. hookCallback = callback;
  22. }
  23. function isArray(input) {
  24. return (
  25. input instanceof Array ||
  26. Object.prototype.toString.call(input) === "[object Array]"
  27. );
  28. }
  29. function isObject(input) {
  30. // IE8 will treat undefined and null as object if it wasn't for
  31. // input != null
  32. return (
  33. input != null &&
  34. Object.prototype.toString.call(input) === "[object Object]"
  35. );
  36. }
  37. function hasOwnProp(a, b) {
  38. return Object.prototype.hasOwnProperty.call(a, b);
  39. }
  40. function isObjectEmpty(obj) {
  41. if (Object.getOwnPropertyNames) {
  42. return Object.getOwnPropertyNames(obj).length === 0;
  43. } else {
  44. var k;
  45. for (k in obj) {
  46. if (hasOwnProp(obj, k)) {
  47. return false;
  48. }
  49. }
  50. return true;
  51. }
  52. }
  53. function isUndefined(input) {
  54. return input === void 0;
  55. }
  56. function isNumber(input) {
  57. return (
  58. typeof input === "number" ||
  59. Object.prototype.toString.call(input) === "[object Number]"
  60. );
  61. }
  62. function isDate(input) {
  63. return (
  64. input instanceof Date ||
  65. Object.prototype.toString.call(input) === "[object Date]"
  66. );
  67. }
  68. function map(arr, fn) {
  69. var res = [],
  70. i,
  71. arrLen = arr.length;
  72. for (i = 0; i < arrLen; ++i) {
  73. res.push(fn(arr[i], i));
  74. }
  75. return res;
  76. }
  77. function extend(a, b) {
  78. for (var i in b) {
  79. if (hasOwnProp(b, i)) {
  80. a[i] = b[i];
  81. }
  82. }
  83. if (hasOwnProp(b, "toString")) {
  84. a.toString = b.toString;
  85. }
  86. if (hasOwnProp(b, "valueOf")) {
  87. a.valueOf = b.valueOf;
  88. }
  89. return a;
  90. }
  91. function createUTC(input, format, locale, strict) {
  92. return createLocalOrUTC(input, format, locale, strict, true).utc();
  93. }
  94. function defaultParsingFlags() {
  95. // We need to deep clone this object.
  96. return {
  97. empty: false,
  98. unusedTokens: [],
  99. unusedInput: [],
  100. overflow: -2,
  101. charsLeftOver: 0,
  102. nullInput: false,
  103. invalidEra: null,
  104. invalidMonth: null,
  105. invalidFormat: false,
  106. userInvalidated: false,
  107. iso: false,
  108. parsedDateParts: [],
  109. era: null,
  110. meridiem: null,
  111. rfc2822: false,
  112. weekdayMismatch: false,
  113. };
  114. }
  115. function getParsingFlags(m) {
  116. if (m._pf == null) {
  117. m._pf = defaultParsingFlags();
  118. }
  119. return m._pf;
  120. }
  121. var some;
  122. if (Array.prototype.some) {
  123. some = Array.prototype.some;
  124. } else {
  125. some = function (fun) {
  126. var t = Object(this),
  127. len = t.length >>> 0,
  128. i;
  129. for (i = 0; i < len; i++) {
  130. if (i in t && fun.call(this, t[i], i, t)) {
  131. return true;
  132. }
  133. }
  134. return false;
  135. };
  136. }
  137. function isValid(m) {
  138. if (m._isValid == null) {
  139. var flags = getParsingFlags(m),
  140. parsedParts = some.call(flags.parsedDateParts, function (i) {
  141. return i != null;
  142. }),
  143. isNowValid =
  144. !isNaN(m._d.getTime()) &&
  145. flags.overflow < 0 &&
  146. !flags.empty &&
  147. !flags.invalidEra &&
  148. !flags.invalidMonth &&
  149. !flags.invalidWeekday &&
  150. !flags.weekdayMismatch &&
  151. !flags.nullInput &&
  152. !flags.invalidFormat &&
  153. !flags.userInvalidated &&
  154. (!flags.meridiem || (flags.meridiem && parsedParts));
  155. if (m._strict) {
  156. isNowValid =
  157. isNowValid &&
  158. flags.charsLeftOver === 0 &&
  159. flags.unusedTokens.length === 0 &&
  160. flags.bigHour === undefined;
  161. }
  162. if (Object.isFrozen == null || !Object.isFrozen(m)) {
  163. m._isValid = isNowValid;
  164. } else {
  165. return isNowValid;
  166. }
  167. }
  168. return m._isValid;
  169. }
  170. function createInvalid(flags) {
  171. var m = createUTC(NaN);
  172. if (flags != null) {
  173. extend(getParsingFlags(m), flags);
  174. } else {
  175. getParsingFlags(m).userInvalidated = true;
  176. }
  177. return m;
  178. }
  179. // Plugins that add properties should also add the key here (null value),
  180. // so we can properly clone ourselves.
  181. var momentProperties = (hooks.momentProperties = []),
  182. updateInProgress = false;
  183. function copyConfig(to, from) {
  184. var i,
  185. prop,
  186. val,
  187. momentPropertiesLen = momentProperties.length;
  188. if (!isUndefined(from._isAMomentObject)) {
  189. to._isAMomentObject = from._isAMomentObject;
  190. }
  191. if (!isUndefined(from._i)) {
  192. to._i = from._i;
  193. }
  194. if (!isUndefined(from._f)) {
  195. to._f = from._f;
  196. }
  197. if (!isUndefined(from._l)) {
  198. to._l = from._l;
  199. }
  200. if (!isUndefined(from._strict)) {
  201. to._strict = from._strict;
  202. }
  203. if (!isUndefined(from._tzm)) {
  204. to._tzm = from._tzm;
  205. }
  206. if (!isUndefined(from._isUTC)) {
  207. to._isUTC = from._isUTC;
  208. }
  209. if (!isUndefined(from._offset)) {
  210. to._offset = from._offset;
  211. }
  212. if (!isUndefined(from._pf)) {
  213. to._pf = getParsingFlags(from);
  214. }
  215. if (!isUndefined(from._locale)) {
  216. to._locale = from._locale;
  217. }
  218. if (momentPropertiesLen > 0) {
  219. for (i = 0; i < momentPropertiesLen; i++) {
  220. prop = momentProperties[i];
  221. val = from[prop];
  222. if (!isUndefined(val)) {
  223. to[prop] = val;
  224. }
  225. }
  226. }
  227. return to;
  228. }
  229. // Moment prototype object
  230. function Moment(config) {
  231. copyConfig(this, config);
  232. this._d = new Date(config._d != null ? config._d.getTime() : NaN);
  233. if (!this.isValid()) {
  234. this._d = new Date(NaN);
  235. }
  236. // Prevent infinite loop in case updateOffset creates new moment
  237. // objects.
  238. if (updateInProgress === false) {
  239. updateInProgress = true;
  240. hooks.updateOffset(this);
  241. updateInProgress = false;
  242. }
  243. }
  244. function isMoment(obj) {
  245. return (
  246. obj instanceof Moment || (obj != null && obj._isAMomentObject != null)
  247. );
  248. }
  249. function warn(msg) {
  250. if (
  251. hooks.suppressDeprecationWarnings === false &&
  252. typeof console !== "undefined" &&
  253. console.warn
  254. ) {
  255. console.warn("Deprecation warning: " + msg);
  256. }
  257. }
  258. function deprecate(msg, fn) {
  259. var firstTime = true;
  260. return extend(function () {
  261. if (hooks.deprecationHandler != null) {
  262. hooks.deprecationHandler(null, msg);
  263. }
  264. if (firstTime) {
  265. var args = [],
  266. arg,
  267. i,
  268. key,
  269. argLen = arguments.length;
  270. for (i = 0; i < argLen; i++) {
  271. arg = "";
  272. if (typeof arguments[i] === "object") {
  273. arg += "\n[" + i + "] ";
  274. for (key in arguments[0]) {
  275. if (hasOwnProp(arguments[0], key)) {
  276. arg += key + ": " + arguments[0][key] + ", ";
  277. }
  278. }
  279. arg = arg.slice(0, -2); // Remove trailing comma and space
  280. } else {
  281. arg = arguments[i];
  282. }
  283. args.push(arg);
  284. }
  285. warn(
  286. msg +
  287. "\nArguments: " +
  288. Array.prototype.slice.call(args).join("") +
  289. "\n" +
  290. new Error().stack
  291. );
  292. firstTime = false;
  293. }
  294. return fn.apply(this, arguments);
  295. }, fn);
  296. }
  297. var deprecations = {};
  298. function deprecateSimple(name, msg) {
  299. if (hooks.deprecationHandler != null) {
  300. hooks.deprecationHandler(name, msg);
  301. }
  302. if (!deprecations[name]) {
  303. warn(msg);
  304. deprecations[name] = true;
  305. }
  306. }
  307. hooks.suppressDeprecationWarnings = false;
  308. hooks.deprecationHandler = null;
  309. function isFunction(input) {
  310. return (
  311. (typeof Function !== "undefined" && input instanceof Function) ||
  312. Object.prototype.toString.call(input) === "[object Function]"
  313. );
  314. }
  315. function set(config) {
  316. var prop, i;
  317. for (i in config) {
  318. if (hasOwnProp(config, i)) {
  319. prop = config[i];
  320. if (isFunction(prop)) {
  321. this[i] = prop;
  322. } else {
  323. this["_" + i] = prop;
  324. }
  325. }
  326. }
  327. this._config = config;
  328. // Lenient ordinal parsing accepts just a number in addition to
  329. // number + (possibly) stuff coming from _dayOfMonthOrdinalParse.
  330. // TODO: Remove "ordinalParse" fallback in next major release.
  331. this._dayOfMonthOrdinalParseLenient = new RegExp(
  332. (this._dayOfMonthOrdinalParse.source || this._ordinalParse.source) +
  333. "|" +
  334. /\d{1,2}/.source
  335. );
  336. }
  337. function mergeConfigs(parentConfig, childConfig) {
  338. var res = extend({}, parentConfig),
  339. prop;
  340. for (prop in childConfig) {
  341. if (hasOwnProp(childConfig, prop)) {
  342. if (isObject(parentConfig[prop]) && isObject(childConfig[prop])) {
  343. res[prop] = {};
  344. extend(res[prop], parentConfig[prop]);
  345. extend(res[prop], childConfig[prop]);
  346. } else if (childConfig[prop] != null) {
  347. res[prop] = childConfig[prop];
  348. } else {
  349. delete res[prop];
  350. }
  351. }
  352. }
  353. for (prop in parentConfig) {
  354. if (
  355. hasOwnProp(parentConfig, prop) &&
  356. !hasOwnProp(childConfig, prop) &&
  357. isObject(parentConfig[prop])
  358. ) {
  359. // make sure changes to properties don't modify parent config
  360. res[prop] = extend({}, res[prop]);
  361. }
  362. }
  363. return res;
  364. }
  365. function Locale(config) {
  366. if (config != null) {
  367. this.set(config);
  368. }
  369. }
  370. var keys;
  371. if (Object.keys) {
  372. keys = Object.keys;
  373. } else {
  374. keys = function (obj) {
  375. var i,
  376. res = [];
  377. for (i in obj) {
  378. if (hasOwnProp(obj, i)) {
  379. res.push(i);
  380. }
  381. }
  382. return res;
  383. };
  384. }
  385. var defaultCalendar = {
  386. sameDay: "[Today at] LT",
  387. nextDay: "[Tomorrow at] LT",
  388. nextWeek: "dddd [at] LT",
  389. lastDay: "[Yesterday at] LT",
  390. lastWeek: "[Last] dddd [at] LT",
  391. sameElse: "L",
  392. };
  393. function calendar(key, mom, now) {
  394. var output = this._calendar[key] || this._calendar["sameElse"];
  395. return isFunction(output) ? output.call(mom, now) : output;
  396. }
  397. function zeroFill(number, targetLength, forceSign) {
  398. var absNumber = "" + Math.abs(number),
  399. zerosToFill = targetLength - absNumber.length,
  400. sign = number >= 0;
  401. return (
  402. (sign ? (forceSign ? "+" : "") : "-") +
  403. Math.pow(10, Math.max(0, zerosToFill)).toString().substr(1) +
  404. absNumber
  405. );
  406. }
  407. var formattingTokens =
  408. /(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|N{1,5}|YYYYYY|YYYYY|YYYY|YY|y{2,4}|yo?|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g,
  409. localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g,
  410. formatFunctions = {},
  411. formatTokenFunctions = {};
  412. // token: 'M'
  413. // padded: ['MM', 2]
  414. // ordinal: 'Mo'
  415. // callback: function () { this.month() + 1 }
  416. function addFormatToken(token, padded, ordinal, callback) {
  417. var func = callback;
  418. if (typeof callback === "string") {
  419. func = function () {
  420. return this[callback]();
  421. };
  422. }
  423. if (token) {
  424. formatTokenFunctions[token] = func;
  425. }
  426. if (padded) {
  427. formatTokenFunctions[padded[0]] = function () {
  428. return zeroFill(func.apply(this, arguments), padded[1], padded[2]);
  429. };
  430. }
  431. if (ordinal) {
  432. formatTokenFunctions[ordinal] = function () {
  433. return this.localeData().ordinal(func.apply(this, arguments), token);
  434. };
  435. }
  436. }
  437. function removeFormattingTokens(input) {
  438. if (input.match(/\[[\s\S]/)) {
  439. return input.replace(/^\[|\]$/g, "");
  440. }
  441. return input.replace(/\\/g, "");
  442. }
  443. function makeFormatFunction(format) {
  444. var array = format.match(formattingTokens),
  445. i,
  446. length;
  447. for (i = 0, length = array.length; i < length; i++) {
  448. if (formatTokenFunctions[array[i]]) {
  449. array[i] = formatTokenFunctions[array[i]];
  450. } else {
  451. array[i] = removeFormattingTokens(array[i]);
  452. }
  453. }
  454. return function (mom) {
  455. var output = "",
  456. i;
  457. for (i = 0; i < length; i++) {
  458. output += isFunction(array[i]) ? array[i].call(mom, format) : array[i];
  459. }
  460. return output;
  461. };
  462. }
  463. // format date using native date object
  464. function formatMoment(m, format) {
  465. if (!m.isValid()) {
  466. return m.localeData().invalidDate();
  467. }
  468. format = expandFormat(format, m.localeData());
  469. formatFunctions[format] =
  470. formatFunctions[format] || makeFormatFunction(format);
  471. return formatFunctions[format](m);
  472. }
  473. function expandFormat(format, locale) {
  474. var i = 5;
  475. function replaceLongDateFormatTokens(input) {
  476. return locale.longDateFormat(input) || input;
  477. }
  478. localFormattingTokens.lastIndex = 0;
  479. while (i >= 0 && localFormattingTokens.test(format)) {
  480. format = format.replace(
  481. localFormattingTokens,
  482. replaceLongDateFormatTokens
  483. );
  484. localFormattingTokens.lastIndex = 0;
  485. i -= 1;
  486. }
  487. return format;
  488. }
  489. var defaultLongDateFormat = {
  490. LTS: "h:mm:ss A",
  491. LT: "h:mm A",
  492. L: "MM/DD/YYYY",
  493. LL: "MMMM D, YYYY",
  494. LLL: "MMMM D, YYYY h:mm A",
  495. LLLL: "dddd, MMMM D, YYYY h:mm A",
  496. };
  497. function longDateFormat(key) {
  498. var format = this._longDateFormat[key],
  499. formatUpper = this._longDateFormat[key.toUpperCase()];
  500. if (format || !formatUpper) {
  501. return format;
  502. }
  503. this._longDateFormat[key] = formatUpper
  504. .match(formattingTokens)
  505. .map(function (tok) {
  506. if (tok === "MMMM" || tok === "MM" || tok === "DD" || tok === "dddd") {
  507. return tok.slice(1);
  508. }
  509. return tok;
  510. })
  511. .join("");
  512. return this._longDateFormat[key];
  513. }
  514. var defaultInvalidDate = "Invalid date";
  515. function invalidDate() {
  516. return this._invalidDate;
  517. }
  518. var defaultOrdinal = "%d",
  519. defaultDayOfMonthOrdinalParse = /\d{1,2}/;
  520. function ordinal(number) {
  521. return this._ordinal.replace("%d", number);
  522. }
  523. var defaultRelativeTime = {
  524. future: "in %s",
  525. past: "%s ago",
  526. s: "a few seconds",
  527. ss: "%d seconds",
  528. m: "a minute",
  529. mm: "%d minutes",
  530. h: "an hour",
  531. hh: "%d hours",
  532. d: "a day",
  533. dd: "%d days",
  534. w: "a week",
  535. ww: "%d weeks",
  536. M: "a month",
  537. MM: "%d months",
  538. y: "a year",
  539. yy: "%d years",
  540. };
  541. function relativeTime(number, withoutSuffix, string, isFuture) {
  542. var output = this._relativeTime[string];
  543. return isFunction(output)
  544. ? output(number, withoutSuffix, string, isFuture)
  545. : output.replace(/%d/i, number);
  546. }
  547. function pastFuture(diff, output) {
  548. var format = this._relativeTime[diff > 0 ? "future" : "past"];
  549. return isFunction(format) ? format(output) : format.replace(/%s/i, output);
  550. }
  551. var aliases = {};
  552. function addUnitAlias(unit, shorthand) {
  553. var lowerCase = unit.toLowerCase();
  554. aliases[lowerCase] = aliases[lowerCase + "s"] = aliases[shorthand] = unit;
  555. }
  556. function normalizeUnits(units) {
  557. return typeof units === "string"
  558. ? aliases[units] || aliases[units.toLowerCase()]
  559. : undefined;
  560. }
  561. function normalizeObjectUnits(inputObject) {
  562. var normalizedInput = {},
  563. normalizedProp,
  564. prop;
  565. for (prop in inputObject) {
  566. if (hasOwnProp(inputObject, prop)) {
  567. normalizedProp = normalizeUnits(prop);
  568. if (normalizedProp) {
  569. normalizedInput[normalizedProp] = inputObject[prop];
  570. }
  571. }
  572. }
  573. return normalizedInput;
  574. }
  575. var priorities = {};
  576. function addUnitPriority(unit, priority) {
  577. priorities[unit] = priority;
  578. }
  579. function getPrioritizedUnits(unitsObj) {
  580. var units = [],
  581. u;
  582. for (u in unitsObj) {
  583. if (hasOwnProp(unitsObj, u)) {
  584. units.push({unit: u, priority: priorities[u]});
  585. }
  586. }
  587. units.sort(function (a, b) {
  588. return a.priority - b.priority;
  589. });
  590. return units;
  591. }
  592. function isLeapYear(year) {
  593. return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
  594. }
  595. function absFloor(number) {
  596. if (number < 0) {
  597. // -0 -> 0
  598. return Math.ceil(number) || 0;
  599. } else {
  600. return Math.floor(number);
  601. }
  602. }
  603. function toInt(argumentForCoercion) {
  604. var coercedNumber = +argumentForCoercion,
  605. value = 0;
  606. if (coercedNumber !== 0 && isFinite(coercedNumber)) {
  607. value = absFloor(coercedNumber);
  608. }
  609. return value;
  610. }
  611. function makeGetSet(unit, keepTime) {
  612. return function (value) {
  613. if (value != null) {
  614. set$1(this, unit, value);
  615. hooks.updateOffset(this, keepTime);
  616. return this;
  617. } else {
  618. return get(this, unit);
  619. }
  620. };
  621. }
  622. function get(mom, unit) {
  623. return mom.isValid()
  624. ? mom._d["get" + (mom._isUTC ? "UTC" : "") + unit]()
  625. : NaN;
  626. }
  627. function set$1(mom, unit, value) {
  628. if (mom.isValid() && !isNaN(value)) {
  629. if (
  630. unit === "FullYear" &&
  631. isLeapYear(mom.year()) &&
  632. mom.month() === 1 &&
  633. mom.date() === 29
  634. ) {
  635. value = toInt(value);
  636. mom._d["set" + (mom._isUTC ? "UTC" : "") + unit](
  637. value,
  638. mom.month(),
  639. daysInMonth(value, mom.month())
  640. );
  641. } else {
  642. mom._d["set" + (mom._isUTC ? "UTC" : "") + unit](value);
  643. }
  644. }
  645. }
  646. // MOMENTS
  647. function stringGet(units) {
  648. units = normalizeUnits(units);
  649. if (isFunction(this[units])) {
  650. return this[units]();
  651. }
  652. return this;
  653. }
  654. function stringSet(units, value) {
  655. if (typeof units === "object") {
  656. units = normalizeObjectUnits(units);
  657. var prioritized = getPrioritizedUnits(units),
  658. i,
  659. prioritizedLen = prioritized.length;
  660. for (i = 0; i < prioritizedLen; i++) {
  661. this[prioritized[i].unit](units[prioritized[i].unit]);
  662. }
  663. } else {
  664. units = normalizeUnits(units);
  665. if (isFunction(this[units])) {
  666. return this[units](value);
  667. }
  668. }
  669. return this;
  670. }
  671. var match1 = /\d/, // 0 - 9
  672. match2 = /\d\d/, // 00 - 99
  673. match3 = /\d{3}/, // 000 - 999
  674. match4 = /\d{4}/, // 0000 - 9999
  675. match6 = /[+-]?\d{6}/, // -999999 - 999999
  676. match1to2 = /\d\d?/, // 0 - 99
  677. match3to4 = /\d\d\d\d?/, // 999 - 9999
  678. match5to6 = /\d\d\d\d\d\d?/, // 99999 - 999999
  679. match1to3 = /\d{1,3}/, // 0 - 999
  680. match1to4 = /\d{1,4}/, // 0 - 9999
  681. match1to6 = /[+-]?\d{1,6}/, // -999999 - 999999
  682. matchUnsigned = /\d+/, // 0 - inf
  683. matchSigned = /[+-]?\d+/, // -inf - inf
  684. matchOffset = /Z|[+-]\d\d:?\d\d/gi, // +00:00 -00:00 +0000 -0000 or Z
  685. matchShortOffset = /Z|[+-]\d\d(?::?\d\d)?/gi, // +00 -00 +00:00 -00:00 +0000 -0000 or Z
  686. matchTimestamp = /[+-]?\d+(\.\d{1,3})?/, // 123456789 123456789.123
  687. // any word (or two) characters or numbers including two/three word month in arabic.
  688. // includes scottish gaelic two word and hyphenated months
  689. matchWord =
  690. /[0-9]{0,256}['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFF07\uFF10-\uFFEF]{1,256}|[\u0600-\u06FF\/]{1,256}(\s*?[\u0600-\u06FF]{1,256}){1,2}/i,
  691. regexes;
  692. regexes = {};
  693. function addRegexToken(token, regex, strictRegex) {
  694. regexes[token] = isFunction(regex)
  695. ? regex
  696. : function (isStrict, localeData) {
  697. return isStrict && strictRegex ? strictRegex : regex;
  698. };
  699. }
  700. function getParseRegexForToken(token, config) {
  701. if (!hasOwnProp(regexes, token)) {
  702. return new RegExp(unescapeFormat(token));
  703. }
  704. return regexes[token](config._strict, config._locale);
  705. }
  706. // Code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
  707. function unescapeFormat(s) {
  708. return regexEscape(
  709. s
  710. .replace("\\", "")
  711. .replace(
  712. /\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g,
  713. function (matched, p1, p2, p3, p4) {
  714. return p1 || p2 || p3 || p4;
  715. }
  716. )
  717. );
  718. }
  719. function regexEscape(s) {
  720. return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
  721. }
  722. var tokens = {};
  723. function addParseToken(token, callback) {
  724. var i,
  725. func = callback,
  726. tokenLen;
  727. if (typeof token === "string") {
  728. token = [token];
  729. }
  730. if (isNumber(callback)) {
  731. func = function (input, array) {
  732. array[callback] = toInt(input);
  733. };
  734. }
  735. tokenLen = token.length;
  736. for (i = 0; i < tokenLen; i++) {
  737. tokens[token[i]] = func;
  738. }
  739. }
  740. function addWeekParseToken(token, callback) {
  741. addParseToken(token, function (input, array, config, token) {
  742. config._w = config._w || {};
  743. callback(input, config._w, config, token);
  744. });
  745. }
  746. function addTimeToArrayFromToken(token, input, config) {
  747. if (input != null && hasOwnProp(tokens, token)) {
  748. tokens[token](input, config._a, config, token);
  749. }
  750. }
  751. var YEAR = 0,
  752. MONTH = 1,
  753. DATE = 2,
  754. HOUR = 3,
  755. MINUTE = 4,
  756. SECOND = 5,
  757. MILLISECOND = 6,
  758. WEEK = 7,
  759. WEEKDAY = 8;
  760. function mod(n, x) {
  761. return ((n % x) + x) % x;
  762. }
  763. var indexOf;
  764. if (Array.prototype.indexOf) {
  765. indexOf = Array.prototype.indexOf;
  766. } else {
  767. indexOf = function (o) {
  768. // I know
  769. var i;
  770. for (i = 0; i < this.length; ++i) {
  771. if (this[i] === o) {
  772. return i;
  773. }
  774. }
  775. return -1;
  776. };
  777. }
  778. function daysInMonth(year, month) {
  779. if (isNaN(year) || isNaN(month)) {
  780. return NaN;
  781. }
  782. var modMonth = mod(month, 12);
  783. year += (month - modMonth) / 12;
  784. return modMonth === 1
  785. ? isLeapYear(year)
  786. ? 29
  787. : 28
  788. : 31 - ((modMonth % 7) % 2);
  789. }
  790. // FORMATTING
  791. addFormatToken("M", ["MM", 2], "Mo", function () {
  792. return this.month() + 1;
  793. });
  794. addFormatToken("MMM", 0, 0, function (format) {
  795. return this.localeData().monthsShort(this, format);
  796. });
  797. addFormatToken("MMMM", 0, 0, function (format) {
  798. return this.localeData().months(this, format);
  799. });
  800. // ALIASES
  801. addUnitAlias("month", "M");
  802. // PRIORITY
  803. addUnitPriority("month", 8);
  804. // PARSING
  805. addRegexToken("M", match1to2);
  806. addRegexToken("MM", match1to2, match2);
  807. addRegexToken("MMM", function (isStrict, locale) {
  808. return locale.monthsShortRegex(isStrict);
  809. });
  810. addRegexToken("MMMM", function (isStrict, locale) {
  811. return locale.monthsRegex(isStrict);
  812. });
  813. addParseToken(["M", "MM"], function (input, array) {
  814. array[MONTH] = toInt(input) - 1;
  815. });
  816. addParseToken(["MMM", "MMMM"], function (input, array, config, token) {
  817. var month = config._locale.monthsParse(input, token, config._strict);
  818. // if we didn't find a month name, mark the date as invalid.
  819. if (month != null) {
  820. array[MONTH] = month;
  821. } else {
  822. getParsingFlags(config).invalidMonth = input;
  823. }
  824. });
  825. // LOCALES
  826. var defaultLocaleMonths =
  827. "January_February_March_April_May_June_July_August_September_October_November_December".split(
  828. "_"
  829. ),
  830. defaultLocaleMonthsShort =
  831. "Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec".split("_"),
  832. MONTHS_IN_FORMAT = /D[oD]?(\[[^\[\]]*\]|\s)+MMMM?/,
  833. defaultMonthsShortRegex = matchWord,
  834. defaultMonthsRegex = matchWord;
  835. function localeMonths(m, format) {
  836. if (!m) {
  837. return isArray(this._months) ? this._months : this._months["standalone"];
  838. }
  839. return isArray(this._months)
  840. ? this._months[m.month()]
  841. : this._months[
  842. (this._months.isFormat || MONTHS_IN_FORMAT).test(format)
  843. ? "format"
  844. : "standalone"
  845. ][m.month()];
  846. }
  847. function localeMonthsShort(m, format) {
  848. if (!m) {
  849. return isArray(this._monthsShort)
  850. ? this._monthsShort
  851. : this._monthsShort["standalone"];
  852. }
  853. return isArray(this._monthsShort)
  854. ? this._monthsShort[m.month()]
  855. : this._monthsShort[
  856. MONTHS_IN_FORMAT.test(format) ? "format" : "standalone"
  857. ][m.month()];
  858. }
  859. function handleStrictParse(monthName, format, strict) {
  860. var i,
  861. ii,
  862. mom,
  863. llc = monthName.toLocaleLowerCase();
  864. if (!this._monthsParse) {
  865. // this is not used
  866. this._monthsParse = [];
  867. this._longMonthsParse = [];
  868. this._shortMonthsParse = [];
  869. for (i = 0; i < 12; ++i) {
  870. mom = createUTC([2000, i]);
  871. this._shortMonthsParse[i] = this.monthsShort(
  872. mom,
  873. ""
  874. ).toLocaleLowerCase();
  875. this._longMonthsParse[i] = this.months(mom, "").toLocaleLowerCase();
  876. }
  877. }
  878. if (strict) {
  879. if (format === "MMM") {
  880. ii = indexOf.call(this._shortMonthsParse, llc);
  881. return ii !== -1 ? ii : null;
  882. } else {
  883. ii = indexOf.call(this._longMonthsParse, llc);
  884. return ii !== -1 ? ii : null;
  885. }
  886. } else {
  887. if (format === "MMM") {
  888. ii = indexOf.call(this._shortMonthsParse, llc);
  889. if (ii !== -1) {
  890. return ii;
  891. }
  892. ii = indexOf.call(this._longMonthsParse, llc);
  893. return ii !== -1 ? ii : null;
  894. } else {
  895. ii = indexOf.call(this._longMonthsParse, llc);
  896. if (ii !== -1) {
  897. return ii;
  898. }
  899. ii = indexOf.call(this._shortMonthsParse, llc);
  900. return ii !== -1 ? ii : null;
  901. }
  902. }
  903. }
  904. function localeMonthsParse(monthName, format, strict) {
  905. var i, mom, regex;
  906. if (this._monthsParseExact) {
  907. return handleStrictParse.call(this, monthName, format, strict);
  908. }
  909. if (!this._monthsParse) {
  910. this._monthsParse = [];
  911. this._longMonthsParse = [];
  912. this._shortMonthsParse = [];
  913. }
  914. // TODO: add sorting
  915. // Sorting makes sure if one month (or abbr) is a prefix of another
  916. // see sorting in computeMonthsParse
  917. for (i = 0; i < 12; i++) {
  918. // make the regex if we don't have it already
  919. mom = createUTC([2000, i]);
  920. if (strict && !this._longMonthsParse[i]) {
  921. this._longMonthsParse[i] = new RegExp(
  922. "^" + this.months(mom, "").replace(".", "") + "$",
  923. "i"
  924. );
  925. this._shortMonthsParse[i] = new RegExp(
  926. "^" + this.monthsShort(mom, "").replace(".", "") + "$",
  927. "i"
  928. );
  929. }
  930. if (!strict && !this._monthsParse[i]) {
  931. regex = "^" + this.months(mom, "") + "|^" + this.monthsShort(mom, "");
  932. this._monthsParse[i] = new RegExp(regex.replace(".", ""), "i");
  933. }
  934. // test the regex
  935. if (
  936. strict &&
  937. format === "MMMM" &&
  938. this._longMonthsParse[i].test(monthName)
  939. ) {
  940. return i;
  941. } else if (
  942. strict &&
  943. format === "MMM" &&
  944. this._shortMonthsParse[i].test(monthName)
  945. ) {
  946. return i;
  947. } else if (!strict && this._monthsParse[i].test(monthName)) {
  948. return i;
  949. }
  950. }
  951. }
  952. // MOMENTS
  953. function setMonth(mom, value) {
  954. var dayOfMonth;
  955. if (!mom.isValid()) {
  956. // No op
  957. return mom;
  958. }
  959. if (typeof value === "string") {
  960. if (/^\d+$/.test(value)) {
  961. value = toInt(value);
  962. } else {
  963. value = mom.localeData().monthsParse(value);
  964. // TODO: Another silent failure?
  965. if (!isNumber(value)) {
  966. return mom;
  967. }
  968. }
  969. }
  970. dayOfMonth = Math.min(mom.date(), daysInMonth(mom.year(), value));
  971. mom._d["set" + (mom._isUTC ? "UTC" : "") + "Month"](value, dayOfMonth);
  972. return mom;
  973. }
  974. function getSetMonth(value) {
  975. if (value != null) {
  976. setMonth(this, value);
  977. hooks.updateOffset(this, true);
  978. return this;
  979. } else {
  980. return get(this, "Month");
  981. }
  982. }
  983. function getDaysInMonth() {
  984. return daysInMonth(this.year(), this.month());
  985. }
  986. function monthsShortRegex(isStrict) {
  987. if (this._monthsParseExact) {
  988. if (!hasOwnProp(this, "_monthsRegex")) {
  989. computeMonthsParse.call(this);
  990. }
  991. if (isStrict) {
  992. return this._monthsShortStrictRegex;
  993. } else {
  994. return this._monthsShortRegex;
  995. }
  996. } else {
  997. if (!hasOwnProp(this, "_monthsShortRegex")) {
  998. this._monthsShortRegex = defaultMonthsShortRegex;
  999. }
  1000. return this._monthsShortStrictRegex && isStrict
  1001. ? this._monthsShortStrictRegex
  1002. : this._monthsShortRegex;
  1003. }
  1004. }
  1005. function monthsRegex(isStrict) {
  1006. if (this._monthsParseExact) {
  1007. if (!hasOwnProp(this, "_monthsRegex")) {
  1008. computeMonthsParse.call(this);
  1009. }
  1010. if (isStrict) {
  1011. return this._monthsStrictRegex;
  1012. } else {
  1013. return this._monthsRegex;
  1014. }
  1015. } else {
  1016. if (!hasOwnProp(this, "_monthsRegex")) {
  1017. this._monthsRegex = defaultMonthsRegex;
  1018. }
  1019. return this._monthsStrictRegex && isStrict
  1020. ? this._monthsStrictRegex
  1021. : this._monthsRegex;
  1022. }
  1023. }
  1024. function computeMonthsParse() {
  1025. function cmpLenRev(a, b) {
  1026. return b.length - a.length;
  1027. }
  1028. var shortPieces = [],
  1029. longPieces = [],
  1030. mixedPieces = [],
  1031. i,
  1032. mom;
  1033. for (i = 0; i < 12; i++) {
  1034. // make the regex if we don't have it already
  1035. mom = createUTC([2000, i]);
  1036. shortPieces.push(this.monthsShort(mom, ""));
  1037. longPieces.push(this.months(mom, ""));
  1038. mixedPieces.push(this.months(mom, ""));
  1039. mixedPieces.push(this.monthsShort(mom, ""));
  1040. }
  1041. // Sorting makes sure if one month (or abbr) is a prefix of another it
  1042. // will match the longer piece.
  1043. shortPieces.sort(cmpLenRev);
  1044. longPieces.sort(cmpLenRev);
  1045. mixedPieces.sort(cmpLenRev);
  1046. for (i = 0; i < 12; i++) {
  1047. shortPieces[i] = regexEscape(shortPieces[i]);
  1048. longPieces[i] = regexEscape(longPieces[i]);
  1049. }
  1050. for (i = 0; i < 24; i++) {
  1051. mixedPieces[i] = regexEscape(mixedPieces[i]);
  1052. }
  1053. this._monthsRegex = new RegExp("^(" + mixedPieces.join("|") + ")", "i");
  1054. this._monthsShortRegex = this._monthsRegex;
  1055. this._monthsStrictRegex = new RegExp(
  1056. "^(" + longPieces.join("|") + ")",
  1057. "i"
  1058. );
  1059. this._monthsShortStrictRegex = new RegExp(
  1060. "^(" + shortPieces.join("|") + ")",
  1061. "i"
  1062. );
  1063. }
  1064. // FORMATTING
  1065. addFormatToken("Y", 0, 0, function () {
  1066. var y = this.year();
  1067. return y <= 9999 ? zeroFill(y, 4) : "+" + y;
  1068. });
  1069. addFormatToken(0, ["YY", 2], 0, function () {
  1070. return this.year() % 100;
  1071. });
  1072. addFormatToken(0, ["YYYY", 4], 0, "year");
  1073. addFormatToken(0, ["YYYYY", 5], 0, "year");
  1074. addFormatToken(0, ["YYYYYY", 6, true], 0, "year");
  1075. // ALIASES
  1076. addUnitAlias("year", "y");
  1077. // PRIORITIES
  1078. addUnitPriority("year", 1);
  1079. // PARSING
  1080. addRegexToken("Y", matchSigned);
  1081. addRegexToken("YY", match1to2, match2);
  1082. addRegexToken("YYYY", match1to4, match4);
  1083. addRegexToken("YYYYY", match1to6, match6);
  1084. addRegexToken("YYYYYY", match1to6, match6);
  1085. addParseToken(["YYYYY", "YYYYYY"], YEAR);
  1086. addParseToken("YYYY", function (input, array) {
  1087. array[YEAR] =
  1088. input.length === 2 ? hooks.parseTwoDigitYear(input) : toInt(input);
  1089. });
  1090. addParseToken("YY", function (input, array) {
  1091. array[YEAR] = hooks.parseTwoDigitYear(input);
  1092. });
  1093. addParseToken("Y", function (input, array) {
  1094. array[YEAR] = parseInt(input, 10);
  1095. });
  1096. // HELPERS
  1097. function daysInYear(year) {
  1098. return isLeapYear(year) ? 366 : 365;
  1099. }
  1100. // HOOKS
  1101. hooks.parseTwoDigitYear = function (input) {
  1102. return toInt(input) + (toInt(input) > 68 ? 1900 : 2000);
  1103. };
  1104. // MOMENTS
  1105. var getSetYear = makeGetSet("FullYear", true);
  1106. function getIsLeapYear() {
  1107. return isLeapYear(this.year());
  1108. }
  1109. function createDate(y, m, d, h, M, s, ms) {
  1110. // can't just apply() to create a date:
  1111. // https://stackoverflow.com/q/181348
  1112. var date;
  1113. // the date constructor remaps years 0-99 to 1900-1999
  1114. if (y < 100 && y >= 0) {
  1115. // preserve leap years using a full 400 year cycle, then reset
  1116. date = new Date(y + 400, m, d, h, M, s, ms);
  1117. if (isFinite(date.getFullYear())) {
  1118. date.setFullYear(y);
  1119. }
  1120. } else {
  1121. date = new Date(y, m, d, h, M, s, ms);
  1122. }
  1123. return date;
  1124. }
  1125. function createUTCDate(y) {
  1126. var date, args;
  1127. // the Date.UTC function remaps years 0-99 to 1900-1999
  1128. if (y < 100 && y >= 0) {
  1129. args = Array.prototype.slice.call(arguments);
  1130. // preserve leap years using a full 400 year cycle, then reset
  1131. args[0] = y + 400;
  1132. date = new Date(Date.UTC.apply(null, args));
  1133. if (isFinite(date.getUTCFullYear())) {
  1134. date.setUTCFullYear(y);
  1135. }
  1136. } else {
  1137. date = new Date(Date.UTC.apply(null, arguments));
  1138. }
  1139. return date;
  1140. }
  1141. // start-of-first-week - start-of-year
  1142. function firstWeekOffset(year, dow, doy) {
  1143. var // first-week day -- which january is always in the first week (4 for iso, 1 for other)
  1144. fwd = 7 + dow - doy,
  1145. // first-week day local weekday -- which local weekday is fwd
  1146. fwdlw = (7 + createUTCDate(year, 0, fwd).getUTCDay() - dow) % 7;
  1147. return -fwdlw + fwd - 1;
  1148. }
  1149. // https://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday
  1150. function dayOfYearFromWeeks(year, week, weekday, dow, doy) {
  1151. var localWeekday = (7 + weekday - dow) % 7,
  1152. weekOffset = firstWeekOffset(year, dow, doy),
  1153. dayOfYear = 1 + 7 * (week - 1) + localWeekday + weekOffset,
  1154. resYear,
  1155. resDayOfYear;
  1156. if (dayOfYear <= 0) {
  1157. resYear = year - 1;
  1158. resDayOfYear = daysInYear(resYear) + dayOfYear;
  1159. } else if (dayOfYear > daysInYear(year)) {
  1160. resYear = year + 1;
  1161. resDayOfYear = dayOfYear - daysInYear(year);
  1162. } else {
  1163. resYear = year;
  1164. resDayOfYear = dayOfYear;
  1165. }
  1166. return {
  1167. year: resYear,
  1168. dayOfYear: resDayOfYear,
  1169. };
  1170. }
  1171. function weekOfYear(mom, dow, doy) {
  1172. var weekOffset = firstWeekOffset(mom.year(), dow, doy),
  1173. week = Math.floor((mom.dayOfYear() - weekOffset - 1) / 7) + 1,
  1174. resWeek,
  1175. resYear;
  1176. if (week < 1) {
  1177. resYear = mom.year() - 1;
  1178. resWeek = week + weeksInYear(resYear, dow, doy);
  1179. } else if (week > weeksInYear(mom.year(), dow, doy)) {
  1180. resWeek = week - weeksInYear(mom.year(), dow, doy);
  1181. resYear = mom.year() + 1;
  1182. } else {
  1183. resYear = mom.year();
  1184. resWeek = week;
  1185. }
  1186. return {
  1187. week: resWeek,
  1188. year: resYear,
  1189. };
  1190. }
  1191. function weeksInYear(year, dow, doy) {
  1192. var weekOffset = firstWeekOffset(year, dow, doy),
  1193. weekOffsetNext = firstWeekOffset(year + 1, dow, doy);
  1194. return (daysInYear(year) - weekOffset + weekOffsetNext) / 7;
  1195. }
  1196. // FORMATTING
  1197. addFormatToken("w", ["ww", 2], "wo", "week");
  1198. addFormatToken("W", ["WW", 2], "Wo", "isoWeek");
  1199. // ALIASES
  1200. addUnitAlias("week", "w");
  1201. addUnitAlias("isoWeek", "W");
  1202. // PRIORITIES
  1203. addUnitPriority("week", 5);
  1204. addUnitPriority("isoWeek", 5);
  1205. // PARSING
  1206. addRegexToken("w", match1to2);
  1207. addRegexToken("ww", match1to2, match2);
  1208. addRegexToken("W", match1to2);
  1209. addRegexToken("WW", match1to2, match2);
  1210. addWeekParseToken(
  1211. ["w", "ww", "W", "WW"],
  1212. function (input, week, config, token) {
  1213. week[token.substr(0, 1)] = toInt(input);
  1214. }
  1215. );
  1216. // HELPERS
  1217. // LOCALES
  1218. function localeWeek(mom) {
  1219. return weekOfYear(mom, this._week.dow, this._week.doy).week;
  1220. }
  1221. var defaultLocaleWeek = {
  1222. dow: 0, // Sunday is the first day of the week.
  1223. doy: 6, // The week that contains Jan 6th is the first week of the year.
  1224. };
  1225. function localeFirstDayOfWeek() {
  1226. return this._week.dow;
  1227. }
  1228. function localeFirstDayOfYear() {
  1229. return this._week.doy;
  1230. }
  1231. // MOMENTS
  1232. function getSetWeek(input) {
  1233. var week = this.localeData().week(this);
  1234. return input == null ? week : this.add((input - week) * 7, "d");
  1235. }
  1236. function getSetISOWeek(input) {
  1237. var week = weekOfYear(this, 1, 4).week;
  1238. return input == null ? week : this.add((input - week) * 7, "d");
  1239. }
  1240. // FORMATTING
  1241. addFormatToken("d", 0, "do", "day");
  1242. addFormatToken("dd", 0, 0, function (format) {
  1243. return this.localeData().weekdaysMin(this, format);
  1244. });
  1245. addFormatToken("ddd", 0, 0, function (format) {
  1246. return this.localeData().weekdaysShort(this, format);
  1247. });
  1248. addFormatToken("dddd", 0, 0, function (format) {
  1249. return this.localeData().weekdays(this, format);
  1250. });
  1251. addFormatToken("e", 0, 0, "weekday");
  1252. addFormatToken("E", 0, 0, "isoWeekday");
  1253. // ALIASES
  1254. addUnitAlias("day", "d");
  1255. addUnitAlias("weekday", "e");
  1256. addUnitAlias("isoWeekday", "E");
  1257. // PRIORITY
  1258. addUnitPriority("day", 11);
  1259. addUnitPriority("weekday", 11);
  1260. addUnitPriority("isoWeekday", 11);
  1261. // PARSING
  1262. addRegexToken("d", match1to2);
  1263. addRegexToken("e", match1to2);
  1264. addRegexToken("E", match1to2);
  1265. addRegexToken("dd", function (isStrict, locale) {
  1266. return locale.weekdaysMinRegex(isStrict);
  1267. });
  1268. addRegexToken("ddd", function (isStrict, locale) {
  1269. return locale.weekdaysShortRegex(isStrict);
  1270. });
  1271. addRegexToken("dddd", function (isStrict, locale) {
  1272. return locale.weekdaysRegex(isStrict);
  1273. });
  1274. addWeekParseToken(
  1275. ["dd", "ddd", "dddd"],
  1276. function (input, week, config, token) {
  1277. var weekday = config._locale.weekdaysParse(input, token, config._strict);
  1278. // if we didn't get a weekday name, mark the date as invalid
  1279. if (weekday != null) {
  1280. week.d = weekday;
  1281. } else {
  1282. getParsingFlags(config).invalidWeekday = input;
  1283. }
  1284. }
  1285. );
  1286. addWeekParseToken(["d", "e", "E"], function (input, week, config, token) {
  1287. week[token] = toInt(input);
  1288. });
  1289. // HELPERS
  1290. function parseWeekday(input, locale) {
  1291. if (typeof input !== "string") {
  1292. return input;
  1293. }
  1294. if (!isNaN(input)) {
  1295. return parseInt(input, 10);
  1296. }
  1297. input = locale.weekdaysParse(input);
  1298. if (typeof input === "number") {
  1299. return input;
  1300. }
  1301. return null;
  1302. }
  1303. function parseIsoWeekday(input, locale) {
  1304. if (typeof input === "string") {
  1305. return locale.weekdaysParse(input) % 7 || 7;
  1306. }
  1307. return isNaN(input) ? null : input;
  1308. }
  1309. // LOCALES
  1310. function shiftWeekdays(ws, n) {
  1311. return ws.slice(n, 7).concat(ws.slice(0, n));
  1312. }
  1313. var defaultLocaleWeekdays =
  1314. "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),
  1315. defaultLocaleWeekdaysShort = "Sun_Mon_Tue_Wed_Thu_Fri_Sat".split("_"),
  1316. defaultLocaleWeekdaysMin = "Su_Mo_Tu_We_Th_Fr_Sa".split("_"),
  1317. defaultWeekdaysRegex = matchWord,
  1318. defaultWeekdaysShortRegex = matchWord,
  1319. defaultWeekdaysMinRegex = matchWord;
  1320. function localeWeekdays(m, format) {
  1321. var weekdays = isArray(this._weekdays)
  1322. ? this._weekdays
  1323. : this._weekdays[
  1324. m && m !== true && this._weekdays.isFormat.test(format)
  1325. ? "format"
  1326. : "standalone"
  1327. ];
  1328. return m === true
  1329. ? shiftWeekdays(weekdays, this._week.dow)
  1330. : m
  1331. ? weekdays[m.day()]
  1332. : weekdays;
  1333. }
  1334. function localeWeekdaysShort(m) {
  1335. return m === true
  1336. ? shiftWeekdays(this._weekdaysShort, this._week.dow)
  1337. : m
  1338. ? this._weekdaysShort[m.day()]
  1339. : this._weekdaysShort;
  1340. }
  1341. function localeWeekdaysMin(m) {
  1342. return m === true
  1343. ? shiftWeekdays(this._weekdaysMin, this._week.dow)
  1344. : m
  1345. ? this._weekdaysMin[m.day()]
  1346. : this._weekdaysMin;
  1347. }
  1348. function handleStrictParse$1(weekdayName, format, strict) {
  1349. var i,
  1350. ii,
  1351. mom,
  1352. llc = weekdayName.toLocaleLowerCase();
  1353. if (!this._weekdaysParse) {
  1354. this._weekdaysParse = [];
  1355. this._shortWeekdaysParse = [];
  1356. this._minWeekdaysParse = [];
  1357. for (i = 0; i < 7; ++i) {
  1358. mom = createUTC([2000, 1]).day(i);
  1359. this._minWeekdaysParse[i] = this.weekdaysMin(
  1360. mom,
  1361. ""
  1362. ).toLocaleLowerCase();
  1363. this._shortWeekdaysParse[i] = this.weekdaysShort(
  1364. mom,
  1365. ""
  1366. ).toLocaleLowerCase();
  1367. this._weekdaysParse[i] = this.weekdays(mom, "").toLocaleLowerCase();
  1368. }
  1369. }
  1370. if (strict) {
  1371. if (format === "dddd") {
  1372. ii = indexOf.call(this._weekdaysParse, llc);
  1373. return ii !== -1 ? ii : null;
  1374. } else if (format === "ddd") {
  1375. ii = indexOf.call(this._shortWeekdaysParse, llc);
  1376. return ii !== -1 ? ii : null;
  1377. } else {
  1378. ii = indexOf.call(this._minWeekdaysParse, llc);
  1379. return ii !== -1 ? ii : null;
  1380. }
  1381. } else {
  1382. if (format === "dddd") {
  1383. ii = indexOf.call(this._weekdaysParse, llc);
  1384. if (ii !== -1) {
  1385. return ii;
  1386. }
  1387. ii = indexOf.call(this._shortWeekdaysParse, llc);
  1388. if (ii !== -1) {
  1389. return ii;
  1390. }
  1391. ii = indexOf.call(this._minWeekdaysParse, llc);
  1392. return ii !== -1 ? ii : null;
  1393. } else if (format === "ddd") {
  1394. ii = indexOf.call(this._shortWeekdaysParse, llc);
  1395. if (ii !== -1) {
  1396. return ii;
  1397. }
  1398. ii = indexOf.call(this._weekdaysParse, llc);
  1399. if (ii !== -1) {
  1400. return ii;
  1401. }
  1402. ii = indexOf.call(this._minWeekdaysParse, llc);
  1403. return ii !== -1 ? ii : null;
  1404. } else {
  1405. ii = indexOf.call(this._minWeekdaysParse, llc);
  1406. if (ii !== -1) {
  1407. return ii;
  1408. }
  1409. ii = indexOf.call(this._weekdaysParse, llc);
  1410. if (ii !== -1) {
  1411. return ii;
  1412. }
  1413. ii = indexOf.call(this._shortWeekdaysParse, llc);
  1414. return ii !== -1 ? ii : null;
  1415. }
  1416. }
  1417. }
  1418. function localeWeekdaysParse(weekdayName, format, strict) {
  1419. var i, mom, regex;
  1420. if (this._weekdaysParseExact) {
  1421. return handleStrictParse$1.call(this, weekdayName, format, strict);
  1422. }
  1423. if (!this._weekdaysParse) {
  1424. this._weekdaysParse = [];
  1425. this._minWeekdaysParse = [];
  1426. this._shortWeekdaysParse = [];
  1427. this._fullWeekdaysParse = [];
  1428. }
  1429. for (i = 0; i < 7; i++) {
  1430. // make the regex if we don't have it already
  1431. mom = createUTC([2000, 1]).day(i);
  1432. if (strict && !this._fullWeekdaysParse[i]) {
  1433. this._fullWeekdaysParse[i] = new RegExp(
  1434. "^" + this.weekdays(mom, "").replace(".", "\\.?") + "$",
  1435. "i"
  1436. );
  1437. this._shortWeekdaysParse[i] = new RegExp(
  1438. "^" + this.weekdaysShort(mom, "").replace(".", "\\.?") + "$",
  1439. "i"
  1440. );
  1441. this._minWeekdaysParse[i] = new RegExp(
  1442. "^" + this.weekdaysMin(mom, "").replace(".", "\\.?") + "$",
  1443. "i"
  1444. );
  1445. }
  1446. if (!this._weekdaysParse[i]) {
  1447. regex =
  1448. "^" +
  1449. this.weekdays(mom, "") +
  1450. "|^" +
  1451. this.weekdaysShort(mom, "") +
  1452. "|^" +
  1453. this.weekdaysMin(mom, "");
  1454. this._weekdaysParse[i] = new RegExp(regex.replace(".", ""), "i");
  1455. }
  1456. // test the regex
  1457. if (
  1458. strict &&
  1459. format === "dddd" &&
  1460. this._fullWeekdaysParse[i].test(weekdayName)
  1461. ) {
  1462. return i;
  1463. } else if (
  1464. strict &&
  1465. format === "ddd" &&
  1466. this._shortWeekdaysParse[i].test(weekdayName)
  1467. ) {
  1468. return i;
  1469. } else if (
  1470. strict &&
  1471. format === "dd" &&
  1472. this._minWeekdaysParse[i].test(weekdayName)
  1473. ) {
  1474. return i;
  1475. } else if (!strict && this._weekdaysParse[i].test(weekdayName)) {
  1476. return i;
  1477. }
  1478. }
  1479. }
  1480. // MOMENTS
  1481. function getSetDayOfWeek(input) {
  1482. if (!this.isValid()) {
  1483. return input != null ? this : NaN;
  1484. }
  1485. var day = this._isUTC ? this._d.getUTCDay() : this._d.getDay();
  1486. if (input != null) {
  1487. input = parseWeekday(input, this.localeData());
  1488. return this.add(input - day, "d");
  1489. } else {
  1490. return day;
  1491. }
  1492. }
  1493. function getSetLocaleDayOfWeek(input) {
  1494. if (!this.isValid()) {
  1495. return input != null ? this : NaN;
  1496. }
  1497. var weekday = (this.day() + 7 - this.localeData()._week.dow) % 7;
  1498. return input == null ? weekday : this.add(input - weekday, "d");
  1499. }
  1500. function getSetISODayOfWeek(input) {
  1501. if (!this.isValid()) {
  1502. return input != null ? this : NaN;
  1503. }
  1504. // behaves the same as moment#day except
  1505. // as a getter, returns 7 instead of 0 (1-7 range instead of 0-6)
  1506. // as a setter, sunday should belong to the previous week.
  1507. if (input != null) {
  1508. var weekday = parseIsoWeekday(input, this.localeData());
  1509. return this.day(this.day() % 7 ? weekday : weekday - 7);
  1510. } else {
  1511. return this.day() || 7;
  1512. }
  1513. }
  1514. function weekdaysRegex(isStrict) {
  1515. if (this._weekdaysParseExact) {
  1516. if (!hasOwnProp(this, "_weekdaysRegex")) {
  1517. computeWeekdaysParse.call(this);
  1518. }
  1519. if (isStrict) {
  1520. return this._weekdaysStrictRegex;
  1521. } else {
  1522. return this._weekdaysRegex;
  1523. }
  1524. } else {
  1525. if (!hasOwnProp(this, "_weekdaysRegex")) {
  1526. this._weekdaysRegex = defaultWeekdaysRegex;
  1527. }
  1528. return this._weekdaysStrictRegex && isStrict
  1529. ? this._weekdaysStrictRegex
  1530. : this._weekdaysRegex;
  1531. }
  1532. }
  1533. function weekdaysShortRegex(isStrict) {
  1534. if (this._weekdaysParseExact) {
  1535. if (!hasOwnProp(this, "_weekdaysRegex")) {
  1536. computeWeekdaysParse.call(this);
  1537. }
  1538. if (isStrict) {
  1539. return this._weekdaysShortStrictRegex;
  1540. } else {
  1541. return this._weekdaysShortRegex;
  1542. }
  1543. } else {
  1544. if (!hasOwnProp(this, "_weekdaysShortRegex")) {
  1545. this._weekdaysShortRegex = defaultWeekdaysShortRegex;
  1546. }
  1547. return this._weekdaysShortStrictRegex && isStrict
  1548. ? this._weekdaysShortStrictRegex
  1549. : this._weekdaysShortRegex;
  1550. }
  1551. }
  1552. function weekdaysMinRegex(isStrict) {
  1553. if (this._weekdaysParseExact) {
  1554. if (!hasOwnProp(this, "_weekdaysRegex")) {
  1555. computeWeekdaysParse.call(this);
  1556. }
  1557. if (isStrict) {
  1558. return this._weekdaysMinStrictRegex;
  1559. } else {
  1560. return this._weekdaysMinRegex;
  1561. }
  1562. } else {
  1563. if (!hasOwnProp(this, "_weekdaysMinRegex")) {
  1564. this._weekdaysMinRegex = defaultWeekdaysMinRegex;
  1565. }
  1566. return this._weekdaysMinStrictRegex && isStrict
  1567. ? this._weekdaysMinStrictRegex
  1568. : this._weekdaysMinRegex;
  1569. }
  1570. }
  1571. function computeWeekdaysParse() {
  1572. function cmpLenRev(a, b) {
  1573. return b.length - a.length;
  1574. }
  1575. var minPieces = [],
  1576. shortPieces = [],
  1577. longPieces = [],
  1578. mixedPieces = [],
  1579. i,
  1580. mom,
  1581. minp,
  1582. shortp,
  1583. longp;
  1584. for (i = 0; i < 7; i++) {
  1585. // make the regex if we don't have it already
  1586. mom = createUTC([2000, 1]).day(i);
  1587. minp = regexEscape(this.weekdaysMin(mom, ""));
  1588. shortp = regexEscape(this.weekdaysShort(mom, ""));
  1589. longp = regexEscape(this.weekdays(mom, ""));
  1590. minPieces.push(minp);
  1591. shortPieces.push(shortp);
  1592. longPieces.push(longp);
  1593. mixedPieces.push(minp);
  1594. mixedPieces.push(shortp);
  1595. mixedPieces.push(longp);
  1596. }
  1597. // Sorting makes sure if one weekday (or abbr) is a prefix of another it
  1598. // will match the longer piece.
  1599. minPieces.sort(cmpLenRev);
  1600. shortPieces.sort(cmpLenRev);
  1601. longPieces.sort(cmpLenRev);
  1602. mixedPieces.sort(cmpLenRev);
  1603. this._weekdaysRegex = new RegExp("^(" + mixedPieces.join("|") + ")", "i");
  1604. this._weekdaysShortRegex = this._weekdaysRegex;
  1605. this._weekdaysMinRegex = this._weekdaysRegex;
  1606. this._weekdaysStrictRegex = new RegExp(
  1607. "^(" + longPieces.join("|") + ")",
  1608. "i"
  1609. );
  1610. this._weekdaysShortStrictRegex = new RegExp(
  1611. "^(" + shortPieces.join("|") + ")",
  1612. "i"
  1613. );
  1614. this._weekdaysMinStrictRegex = new RegExp(
  1615. "^(" + minPieces.join("|") + ")",
  1616. "i"
  1617. );
  1618. }
  1619. // FORMATTING
  1620. function hFormat() {
  1621. return this.hours() % 12 || 12;
  1622. }
  1623. function kFormat() {
  1624. return this.hours() || 24;
  1625. }
  1626. addFormatToken("H", ["HH", 2], 0, "hour");
  1627. addFormatToken("h", ["hh", 2], 0, hFormat);
  1628. addFormatToken("k", ["kk", 2], 0, kFormat);
  1629. addFormatToken("hmm", 0, 0, function () {
  1630. return "" + hFormat.apply(this) + zeroFill(this.minutes(), 2);
  1631. });
  1632. addFormatToken("hmmss", 0, 0, function () {
  1633. return (
  1634. "" +
  1635. hFormat.apply(this) +
  1636. zeroFill(this.minutes(), 2) +
  1637. zeroFill(this.seconds(), 2)
  1638. );
  1639. });
  1640. addFormatToken("Hmm", 0, 0, function () {
  1641. return "" + this.hours() + zeroFill(this.minutes(), 2);
  1642. });
  1643. addFormatToken("Hmmss", 0, 0, function () {
  1644. return (
  1645. "" +
  1646. this.hours() +
  1647. zeroFill(this.minutes(), 2) +
  1648. zeroFill(this.seconds(), 2)
  1649. );
  1650. });
  1651. function meridiem(token, lowercase) {
  1652. addFormatToken(token, 0, 0, function () {
  1653. return this.localeData().meridiem(
  1654. this.hours(),
  1655. this.minutes(),
  1656. lowercase
  1657. );
  1658. });
  1659. }
  1660. meridiem("a", true);
  1661. meridiem("A", false);
  1662. // ALIASES
  1663. addUnitAlias("hour", "h");
  1664. // PRIORITY
  1665. addUnitPriority("hour", 13);
  1666. // PARSING
  1667. function matchMeridiem(isStrict, locale) {
  1668. return locale._meridiemParse;
  1669. }
  1670. addRegexToken("a", matchMeridiem);
  1671. addRegexToken("A", matchMeridiem);
  1672. addRegexToken("H", match1to2);
  1673. addRegexToken("h", match1to2);
  1674. addRegexToken("k", match1to2);
  1675. addRegexToken("HH", match1to2, match2);
  1676. addRegexToken("hh", match1to2, match2);
  1677. addRegexToken("kk", match1to2, match2);
  1678. addRegexToken("hmm", match3to4);
  1679. addRegexToken("hmmss", match5to6);
  1680. addRegexToken("Hmm", match3to4);
  1681. addRegexToken("Hmmss", match5to6);
  1682. addParseToken(["H", "HH"], HOUR);
  1683. addParseToken(["k", "kk"], function (input, array, config) {
  1684. var kInput = toInt(input);
  1685. array[HOUR] = kInput === 24 ? 0 : kInput;
  1686. });
  1687. addParseToken(["a", "A"], function (input, array, config) {
  1688. config._isPm = config._locale.isPM(input);
  1689. config._meridiem = input;
  1690. });
  1691. addParseToken(["h", "hh"], function (input, array, config) {
  1692. array[HOUR] = toInt(input);
  1693. getParsingFlags(config).bigHour = true;
  1694. });
  1695. addParseToken("hmm", function (input, array, config) {
  1696. var pos = input.length - 2;
  1697. array[HOUR] = toInt(input.substr(0, pos));
  1698. array[MINUTE] = toInt(input.substr(pos));
  1699. getParsingFlags(config).bigHour = true;
  1700. });
  1701. addParseToken("hmmss", function (input, array, config) {
  1702. var pos1 = input.length - 4,
  1703. pos2 = input.length - 2;
  1704. array[HOUR] = toInt(input.substr(0, pos1));
  1705. array[MINUTE] = toInt(input.substr(pos1, 2));
  1706. array[SECOND] = toInt(input.substr(pos2));
  1707. getParsingFlags(config).bigHour = true;
  1708. });
  1709. addParseToken("Hmm", function (input, array, config) {
  1710. var pos = input.length - 2;
  1711. array[HOUR] = toInt(input.substr(0, pos));
  1712. array[MINUTE] = toInt(input.substr(pos));
  1713. });
  1714. addParseToken("Hmmss", function (input, array, config) {
  1715. var pos1 = input.length - 4,
  1716. pos2 = input.length - 2;
  1717. array[HOUR] = toInt(input.substr(0, pos1));
  1718. array[MINUTE] = toInt(input.substr(pos1, 2));
  1719. array[SECOND] = toInt(input.substr(pos2));
  1720. });
  1721. // LOCALES
  1722. function localeIsPM(input) {
  1723. // IE8 Quirks Mode & IE7 Standards Mode do not allow accessing strings like arrays
  1724. // Using charAt should be more compatible.
  1725. return (input + "").toLowerCase().charAt(0) === "p";
  1726. }
  1727. var defaultLocaleMeridiemParse = /[ap]\.?m?\.?/i,
  1728. // Setting the hour should keep the time, because the user explicitly
  1729. // specified which hour they want. So trying to maintain the same hour (in
  1730. // a new timezone) makes sense. Adding/subtracting hours does not follow
  1731. // this rule.
  1732. getSetHour = makeGetSet("Hours", true);
  1733. function localeMeridiem(hours, minutes, isLower) {
  1734. if (hours > 11) {
  1735. return isLower ? "pm" : "PM";
  1736. } else {
  1737. return isLower ? "am" : "AM";
  1738. }
  1739. }
  1740. var baseConfig = {
  1741. calendar: defaultCalendar,
  1742. longDateFormat: defaultLongDateFormat,
  1743. invalidDate: defaultInvalidDate,
  1744. ordinal: defaultOrdinal,
  1745. dayOfMonthOrdinalParse: defaultDayOfMonthOrdinalParse,
  1746. relativeTime: defaultRelativeTime,
  1747. months: defaultLocaleMonths,
  1748. monthsShort: defaultLocaleMonthsShort,
  1749. week: defaultLocaleWeek,
  1750. weekdays: defaultLocaleWeekdays,
  1751. weekdaysMin: defaultLocaleWeekdaysMin,
  1752. weekdaysShort: defaultLocaleWeekdaysShort,
  1753. meridiemParse: defaultLocaleMeridiemParse,
  1754. };
  1755. // internal storage for locale config files
  1756. var locales = {},
  1757. localeFamilies = {},
  1758. globalLocale;
  1759. function commonPrefix(arr1, arr2) {
  1760. var i,
  1761. minl = Math.min(arr1.length, arr2.length);
  1762. for (i = 0; i < minl; i += 1) {
  1763. if (arr1[i] !== arr2[i]) {
  1764. return i;
  1765. }
  1766. }
  1767. return minl;
  1768. }
  1769. function normalizeLocale(key) {
  1770. return key ? key.toLowerCase().replace("_", "-") : key;
  1771. }
  1772. // pick the locale from the array
  1773. // try ['en-au', 'en-gb'] as 'en-au', 'en-gb', 'en', as in move through the list trying each
  1774. // substring from most specific to least, but move to the next array item if it's a more specific variant than the current root
  1775. function chooseLocale(names) {
  1776. var i = 0,
  1777. j,
  1778. next,
  1779. locale,
  1780. split;
  1781. while (i < names.length) {
  1782. split = normalizeLocale(names[i]).split("-");
  1783. j = split.length;
  1784. next = normalizeLocale(names[i + 1]);
  1785. next = next ? next.split("-") : null;
  1786. while (j > 0) {
  1787. locale = loadLocale(split.slice(0, j).join("-"));
  1788. if (locale) {
  1789. return locale;
  1790. }
  1791. if (next && next.length >= j && commonPrefix(split, next) >= j - 1) {
  1792. //the next array item is better than a shallower substring of this one
  1793. break;
  1794. }
  1795. j--;
  1796. }
  1797. i++;
  1798. }
  1799. return globalLocale;
  1800. }
  1801. function isLocaleNameSane(name) {
  1802. // Prevent names that look like filesystem paths, i.e contain '/' or '\'
  1803. return name.match("^[^/\\\\]*$") != null;
  1804. }
  1805. function loadLocale(name) {
  1806. var oldLocale = null,
  1807. aliasedRequire;
  1808. // TODO: Find a better way to register and load all the locales in Node
  1809. if (
  1810. locales[name] === undefined &&
  1811. typeof module !== "undefined" &&
  1812. module &&
  1813. module.exports &&
  1814. isLocaleNameSane(name)
  1815. ) {
  1816. try {
  1817. oldLocale = globalLocale._abbr;
  1818. aliasedRequire = require;
  1819. aliasedRequire("./locale/" + name);
  1820. getSetGlobalLocale(oldLocale);
  1821. } catch (e) {
  1822. // mark as not found to avoid repeating expensive file require call causing high CPU
  1823. // when trying to find en-US, en_US, en-us for every format call
  1824. locales[name] = null; // null means not found
  1825. }
  1826. }
  1827. return locales[name];
  1828. }
  1829. // This function will load locale and then set the global locale. If
  1830. // no arguments are passed in, it will simply return the current global
  1831. // locale key.
  1832. function getSetGlobalLocale(key, values) {
  1833. var data;
  1834. if (key) {
  1835. if (isUndefined(values)) {
  1836. data = getLocale(key);
  1837. } else {
  1838. data = defineLocale(key, values);
  1839. }
  1840. if (data) {
  1841. // moment.duration._locale = moment._locale = data;
  1842. globalLocale = data;
  1843. } else {
  1844. if (typeof console !== "undefined" && console.warn) {
  1845. //warn user if arguments are passed but the locale could not be set
  1846. console.warn(
  1847. "Locale " + key + " not found. Did you forget to load it?"
  1848. );
  1849. }
  1850. }
  1851. }
  1852. return globalLocale._abbr;
  1853. }
  1854. function defineLocale(name, config) {
  1855. if (config !== null) {
  1856. var locale,
  1857. parentConfig = baseConfig;
  1858. config.abbr = name;
  1859. if (locales[name] != null) {
  1860. deprecateSimple(
  1861. "defineLocaleOverride",
  1862. "use moment.updateLocale(localeName, config) to change " +
  1863. "an existing locale. moment.defineLocale(localeName, " +
  1864. "config) should only be used for creating a new locale " +
  1865. "See http://momentjs.com/guides/#/warnings/define-locale/ for more info."
  1866. );
  1867. parentConfig = locales[name]._config;
  1868. } else if (config.parentLocale != null) {
  1869. if (locales[config.parentLocale] != null) {
  1870. parentConfig = locales[config.parentLocale]._config;
  1871. } else {
  1872. locale = loadLocale(config.parentLocale);
  1873. if (locale != null) {
  1874. parentConfig = locale._config;
  1875. } else {
  1876. if (!localeFamilies[config.parentLocale]) {
  1877. localeFamilies[config.parentLocale] = [];
  1878. }
  1879. localeFamilies[config.parentLocale].push({
  1880. name: name,
  1881. config: config,
  1882. });
  1883. return null;
  1884. }
  1885. }
  1886. }
  1887. locales[name] = new Locale(mergeConfigs(parentConfig, config));
  1888. if (localeFamilies[name]) {
  1889. localeFamilies[name].forEach(function (x) {
  1890. defineLocale(x.name, x.config);
  1891. });
  1892. }
  1893. // backwards compat for now: also set the locale
  1894. // make sure we set the locale AFTER all child locales have been
  1895. // created, so we won't end up with the child locale set.
  1896. getSetGlobalLocale(name);
  1897. return locales[name];
  1898. } else {
  1899. // useful for testing
  1900. delete locales[name];
  1901. return null;
  1902. }
  1903. }
  1904. function updateLocale(name, config) {
  1905. if (config != null) {
  1906. var locale,
  1907. tmpLocale,
  1908. parentConfig = baseConfig;
  1909. if (locales[name] != null && locales[name].parentLocale != null) {
  1910. // Update existing child locale in-place to avoid memory-leaks
  1911. locales[name].set(mergeConfigs(locales[name]._config, config));
  1912. } else {
  1913. // MERGE
  1914. tmpLocale = loadLocale(name);
  1915. if (tmpLocale != null) {
  1916. parentConfig = tmpLocale._config;
  1917. }
  1918. config = mergeConfigs(parentConfig, config);
  1919. if (tmpLocale == null) {
  1920. // updateLocale is called for creating a new locale
  1921. // Set abbr so it will have a name (getters return
  1922. // undefined otherwise).
  1923. config.abbr = name;
  1924. }
  1925. locale = new Locale(config);
  1926. locale.parentLocale = locales[name];
  1927. locales[name] = locale;
  1928. }
  1929. // backwards compat for now: also set the locale
  1930. getSetGlobalLocale(name);
  1931. } else {
  1932. // pass null for config to unupdate, useful for tests
  1933. if (locales[name] != null) {
  1934. if (locales[name].parentLocale != null) {
  1935. locales[name] = locales[name].parentLocale;
  1936. if (name === getSetGlobalLocale()) {
  1937. getSetGlobalLocale(name);
  1938. }
  1939. } else if (locales[name] != null) {
  1940. delete locales[name];
  1941. }
  1942. }
  1943. }
  1944. return locales[name];
  1945. }
  1946. // returns locale data
  1947. function getLocale(key) {
  1948. var locale;
  1949. if (key && key._locale && key._locale._abbr) {
  1950. key = key._locale._abbr;
  1951. }
  1952. if (!key) {
  1953. return globalLocale;
  1954. }
  1955. if (!isArray(key)) {
  1956. //short-circuit everything else
  1957. locale = loadLocale(key);
  1958. if (locale) {
  1959. return locale;
  1960. }
  1961. key = [key];
  1962. }
  1963. return chooseLocale(key);
  1964. }
  1965. function listLocales() {
  1966. return keys(locales);
  1967. }
  1968. function checkOverflow(m) {
  1969. var overflow,
  1970. a = m._a;
  1971. if (a && getParsingFlags(m).overflow === -2) {
  1972. overflow =
  1973. a[MONTH] < 0 || a[MONTH] > 11
  1974. ? MONTH
  1975. : a[DATE] < 1 || a[DATE] > daysInMonth(a[YEAR], a[MONTH])
  1976. ? DATE
  1977. : a[HOUR] < 0 ||
  1978. a[HOUR] > 24 ||
  1979. (a[HOUR] === 24 &&
  1980. (a[MINUTE] !== 0 || a[SECOND] !== 0 || a[MILLISECOND] !== 0))
  1981. ? HOUR
  1982. : a[MINUTE] < 0 || a[MINUTE] > 59
  1983. ? MINUTE
  1984. : a[SECOND] < 0 || a[SECOND] > 59
  1985. ? SECOND
  1986. : a[MILLISECOND] < 0 || a[MILLISECOND] > 999
  1987. ? MILLISECOND
  1988. : -1;
  1989. if (
  1990. getParsingFlags(m)._overflowDayOfYear &&
  1991. (overflow < YEAR || overflow > DATE)
  1992. ) {
  1993. overflow = DATE;
  1994. }
  1995. if (getParsingFlags(m)._overflowWeeks && overflow === -1) {
  1996. overflow = WEEK;
  1997. }
  1998. if (getParsingFlags(m)._overflowWeekday && overflow === -1) {
  1999. overflow = WEEKDAY;
  2000. }
  2001. getParsingFlags(m).overflow = overflow;
  2002. }
  2003. return m;
  2004. }
  2005. // iso 8601 regex
  2006. // 0000-00-00 0000-W00 or 0000-W00-0 + T + 00 or 00:00 or 00:00:00 or 00:00:00.000 + +00:00 or +0000 or +00)
  2007. var extendedIsoRegex =
  2008. /^\s*((?:[+-]\d{6}|\d{4})-(?:\d\d-\d\d|W\d\d-\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?::\d\d(?::\d\d(?:[.,]\d+)?)?)?)([+-]\d\d(?::?\d\d)?|\s*Z)?)?$/,
  2009. basicIsoRegex =
  2010. /^\s*((?:[+-]\d{6}|\d{4})(?:\d\d\d\d|W\d\d\d|W\d\d|\d\d\d|\d\d|))(?:(T| )(\d\d(?:\d\d(?:\d\d(?:[.,]\d+)?)?)?)([+-]\d\d(?::?\d\d)?|\s*Z)?)?$/,
  2011. tzRegex = /Z|[+-]\d\d(?::?\d\d)?/,
  2012. isoDates = [
  2013. ["YYYYYY-MM-DD", /[+-]\d{6}-\d\d-\d\d/],
  2014. ["YYYY-MM-DD", /\d{4}-\d\d-\d\d/],
  2015. ["GGGG-[W]WW-E", /\d{4}-W\d\d-\d/],
  2016. ["GGGG-[W]WW", /\d{4}-W\d\d/, false],
  2017. ["YYYY-DDD", /\d{4}-\d{3}/],
  2018. ["YYYY-MM", /\d{4}-\d\d/, false],
  2019. ["YYYYYYMMDD", /[+-]\d{10}/],
  2020. ["YYYYMMDD", /\d{8}/],
  2021. ["GGGG[W]WWE", /\d{4}W\d{3}/],
  2022. ["GGGG[W]WW", /\d{4}W\d{2}/, false],
  2023. ["YYYYDDD", /\d{7}/],
  2024. ["YYYYMM", /\d{6}/, false],
  2025. ["YYYY", /\d{4}/, false],
  2026. ],
  2027. // iso time formats and regexes
  2028. isoTimes = [
  2029. ["HH:mm:ss.SSSS", /\d\d:\d\d:\d\d\.\d+/],
  2030. ["HH:mm:ss,SSSS", /\d\d:\d\d:\d\d,\d+/],
  2031. ["HH:mm:ss", /\d\d:\d\d:\d\d/],
  2032. ["HH:mm", /\d\d:\d\d/],
  2033. ["HHmmss.SSSS", /\d\d\d\d\d\d\.\d+/],
  2034. ["HHmmss,SSSS", /\d\d\d\d\d\d,\d+/],
  2035. ["HHmmss", /\d\d\d\d\d\d/],
  2036. ["HHmm", /\d\d\d\d/],
  2037. ["HH", /\d\d/],
  2038. ],
  2039. aspNetJsonRegex = /^\/?Date\((-?\d+)/i,
  2040. // RFC 2822 regex: For details see https://tools.ietf.org/html/rfc2822#section-3.3
  2041. rfc2822 =
  2042. /^(?:(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{4}))$/,
  2043. obsOffsets = {
  2044. UT: 0,
  2045. GMT: 0,
  2046. EDT: -4 * 60,
  2047. EST: -5 * 60,
  2048. CDT: -5 * 60,
  2049. CST: -6 * 60,
  2050. MDT: -6 * 60,
  2051. MST: -7 * 60,
  2052. PDT: -7 * 60,
  2053. PST: -8 * 60,
  2054. };
  2055. // date from iso format
  2056. function configFromISO(config) {
  2057. var i,
  2058. l,
  2059. string = config._i,
  2060. match = extendedIsoRegex.exec(string) || basicIsoRegex.exec(string),
  2061. allowTime,
  2062. dateFormat,
  2063. timeFormat,
  2064. tzFormat,
  2065. isoDatesLen = isoDates.length,
  2066. isoTimesLen = isoTimes.length;
  2067. if (match) {
  2068. getParsingFlags(config).iso = true;
  2069. for (i = 0, l = isoDatesLen; i < l; i++) {
  2070. if (isoDates[i][1].exec(match[1])) {
  2071. dateFormat = isoDates[i][0];
  2072. allowTime = isoDates[i][2] !== false;
  2073. break;
  2074. }
  2075. }
  2076. if (dateFormat == null) {
  2077. config._isValid = false;
  2078. return;
  2079. }
  2080. if (match[3]) {
  2081. for (i = 0, l = isoTimesLen; i < l; i++) {
  2082. if (isoTimes[i][1].exec(match[3])) {
  2083. // match[2] should be 'T' or space
  2084. timeFormat = (match[2] || " ") + isoTimes[i][0];
  2085. break;
  2086. }
  2087. }
  2088. if (timeFormat == null) {
  2089. config._isValid = false;
  2090. return;
  2091. }
  2092. }
  2093. if (!allowTime && timeFormat != null) {
  2094. config._isValid = false;
  2095. return;
  2096. }
  2097. if (match[4]) {
  2098. if (tzRegex.exec(match[4])) {
  2099. tzFormat = "Z";
  2100. } else {
  2101. config._isValid = false;
  2102. return;
  2103. }
  2104. }
  2105. config._f = dateFormat + (timeFormat || "") + (tzFormat || "");
  2106. configFromStringAndFormat(config);
  2107. } else {
  2108. config._isValid = false;
  2109. }
  2110. }
  2111. function extractFromRFC2822Strings(
  2112. yearStr,
  2113. monthStr,
  2114. dayStr,
  2115. hourStr,
  2116. minuteStr,
  2117. secondStr
  2118. ) {
  2119. var result = [
  2120. untruncateYear(yearStr),
  2121. defaultLocaleMonthsShort.indexOf(monthStr),
  2122. parseInt(dayStr, 10),
  2123. parseInt(hourStr, 10),
  2124. parseInt(minuteStr, 10),
  2125. ];
  2126. if (secondStr) {
  2127. result.push(parseInt(secondStr, 10));
  2128. }
  2129. return result;
  2130. }
  2131. function untruncateYear(yearStr) {
  2132. var year = parseInt(yearStr, 10);
  2133. if (year <= 49) {
  2134. return 2000 + year;
  2135. } else if (year <= 999) {
  2136. return 1900 + year;
  2137. }
  2138. return year;
  2139. }
  2140. function preprocessRFC2822(s) {
  2141. // Remove comments and folding whitespace and replace multiple-spaces with a single space
  2142. return s
  2143. .replace(/\([^()]*\)|[\n\t]/g, " ")
  2144. .replace(/(\s\s+)/g, " ")
  2145. .replace(/^\s\s*/, "")
  2146. .replace(/\s\s*$/, "");
  2147. }
  2148. function checkWeekday(weekdayStr, parsedInput, config) {
  2149. if (weekdayStr) {
  2150. // TODO: Replace the vanilla JS Date object with an independent day-of-week check.
  2151. var weekdayProvided = defaultLocaleWeekdaysShort.indexOf(weekdayStr),
  2152. weekdayActual = new Date(
  2153. parsedInput[0],
  2154. parsedInput[1],
  2155. parsedInput[2]
  2156. ).getDay();
  2157. if (weekdayProvided !== weekdayActual) {
  2158. getParsingFlags(config).weekdayMismatch = true;
  2159. config._isValid = false;
  2160. return false;
  2161. }
  2162. }
  2163. return true;
  2164. }
  2165. function calculateOffset(obsOffset, militaryOffset, numOffset) {
  2166. if (obsOffset) {
  2167. return obsOffsets[obsOffset];
  2168. } else if (militaryOffset) {
  2169. // the only allowed military tz is Z
  2170. return 0;
  2171. } else {
  2172. var hm = parseInt(numOffset, 10),
  2173. m = hm % 100,
  2174. h = (hm - m) / 100;
  2175. return h * 60 + m;
  2176. }
  2177. }
  2178. // date and time from ref 2822 format
  2179. function configFromRFC2822(config) {
  2180. var match = rfc2822.exec(preprocessRFC2822(config._i)),
  2181. parsedArray;
  2182. if (match) {
  2183. parsedArray = extractFromRFC2822Strings(
  2184. match[4],
  2185. match[3],
  2186. match[2],
  2187. match[5],
  2188. match[6],
  2189. match[7]
  2190. );
  2191. if (!checkWeekday(match[1], parsedArray, config)) {
  2192. return;
  2193. }
  2194. config._a = parsedArray;
  2195. config._tzm = calculateOffset(match[8], match[9], match[10]);
  2196. config._d = createUTCDate.apply(null, config._a);
  2197. config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm);
  2198. getParsingFlags(config).rfc2822 = true;
  2199. } else {
  2200. config._isValid = false;
  2201. }
  2202. }
  2203. // date from 1) ASP.NET, 2) ISO, 3) RFC 2822 formats, or 4) optional fallback if parsing isn't strict
  2204. function configFromString(config) {
  2205. var matched = aspNetJsonRegex.exec(config._i);
  2206. if (matched !== null) {
  2207. config._d = new Date(+matched[1]);
  2208. return;
  2209. }
  2210. configFromISO(config);
  2211. if (config._isValid === false) {
  2212. delete config._isValid;
  2213. } else {
  2214. return;
  2215. }
  2216. configFromRFC2822(config);
  2217. if (config._isValid === false) {
  2218. delete config._isValid;
  2219. } else {
  2220. return;
  2221. }
  2222. if (config._strict) {
  2223. config._isValid = false;
  2224. } else {
  2225. // Final attempt, use Input Fallback
  2226. hooks.createFromInputFallback(config);
  2227. }
  2228. }
  2229. hooks.createFromInputFallback = deprecate(
  2230. "value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), " +
  2231. "which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are " +
  2232. "discouraged. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.",
  2233. function (config) {
  2234. config._d = new Date(config._i + (config._useUTC ? " UTC" : ""));
  2235. }
  2236. );
  2237. // Pick the first defined of two or three arguments.
  2238. function defaults(a, b, c) {
  2239. if (a != null) {
  2240. return a;
  2241. }
  2242. if (b != null) {
  2243. return b;
  2244. }
  2245. return c;
  2246. }
  2247. function currentDateArray(config) {
  2248. // hooks is actually the exported moment object
  2249. var nowValue = new Date(hooks.now());
  2250. if (config._useUTC) {
  2251. return [
  2252. nowValue.getUTCFullYear(),
  2253. nowValue.getUTCMonth(),
  2254. nowValue.getUTCDate(),
  2255. ];
  2256. }
  2257. return [nowValue.getFullYear(), nowValue.getMonth(), nowValue.getDate()];
  2258. }
  2259. // convert an array to a date.
  2260. // the array should mirror the parameters below
  2261. // note: all values past the year are optional and will default to the lowest possible value.
  2262. // [year, month, day , hour, minute, second, millisecond]
  2263. function configFromArray(config) {
  2264. var i,
  2265. date,
  2266. input = [],
  2267. currentDate,
  2268. expectedWeekday,
  2269. yearToUse;
  2270. if (config._d) {
  2271. return;
  2272. }
  2273. currentDate = currentDateArray(config);
  2274. //compute day of the year from weeks and weekdays
  2275. if (config._w && config._a[DATE] == null && config._a[MONTH] == null) {
  2276. dayOfYearFromWeekInfo(config);
  2277. }
  2278. //if the day of the year is set, figure out what it is
  2279. if (config._dayOfYear != null) {
  2280. yearToUse = defaults(config._a[YEAR], currentDate[YEAR]);
  2281. if (
  2282. config._dayOfYear > daysInYear(yearToUse) ||
  2283. config._dayOfYear === 0
  2284. ) {
  2285. getParsingFlags(config)._overflowDayOfYear = true;
  2286. }
  2287. date = createUTCDate(yearToUse, 0, config._dayOfYear);
  2288. config._a[MONTH] = date.getUTCMonth();
  2289. config._a[DATE] = date.getUTCDate();
  2290. }
  2291. // Default to current date.
  2292. // * if no year, month, day of month are given, default to today
  2293. // * if day of month is given, default month and year
  2294. // * if month is given, default only year
  2295. // * if year is given, don't default anything
  2296. for (i = 0; i < 3 && config._a[i] == null; ++i) {
  2297. config._a[i] = input[i] = currentDate[i];
  2298. }
  2299. // Zero out whatever was not defaulted, including time
  2300. for (; i < 7; i++) {
  2301. config._a[i] = input[i] =
  2302. config._a[i] == null ? (i === 2 ? 1 : 0) : config._a[i];
  2303. }
  2304. // Check for 24:00:00.000
  2305. if (
  2306. config._a[HOUR] === 24 &&
  2307. config._a[MINUTE] === 0 &&
  2308. config._a[SECOND] === 0 &&
  2309. config._a[MILLISECOND] === 0
  2310. ) {
  2311. config._nextDay = true;
  2312. config._a[HOUR] = 0;
  2313. }
  2314. config._d = (config._useUTC ? createUTCDate : createDate).apply(
  2315. null,
  2316. input
  2317. );
  2318. expectedWeekday = config._useUTC
  2319. ? config._d.getUTCDay()
  2320. : config._d.getDay();
  2321. // Apply timezone offset from input. The actual utcOffset can be changed
  2322. // with parseZone.
  2323. if (config._tzm != null) {
  2324. config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm);
  2325. }
  2326. if (config._nextDay) {
  2327. config._a[HOUR] = 24;
  2328. }
  2329. // check for mismatching day of week
  2330. if (
  2331. config._w &&
  2332. typeof config._w.d !== "undefined" &&
  2333. config._w.d !== expectedWeekday
  2334. ) {
  2335. getParsingFlags(config).weekdayMismatch = true;
  2336. }
  2337. }
  2338. function dayOfYearFromWeekInfo(config) {
  2339. var w, weekYear, week, weekday, dow, doy, temp, weekdayOverflow, curWeek;
  2340. w = config._w;
  2341. if (w.GG != null || w.W != null || w.E != null) {
  2342. dow = 1;
  2343. doy = 4;
  2344. // TODO: We need to take the current isoWeekYear, but that depends on
  2345. // how we interpret now (local, utc, fixed offset). So create
  2346. // a now version of current config (take local/utc/offset flags, and
  2347. // create now).
  2348. weekYear = defaults(
  2349. w.GG,
  2350. config._a[YEAR],
  2351. weekOfYear(createLocal(), 1, 4).year
  2352. );
  2353. week = defaults(w.W, 1);
  2354. weekday = defaults(w.E, 1);
  2355. if (weekday < 1 || weekday > 7) {
  2356. weekdayOverflow = true;
  2357. }
  2358. } else {
  2359. dow = config._locale._week.dow;
  2360. doy = config._locale._week.doy;
  2361. curWeek = weekOfYear(createLocal(), dow, doy);
  2362. weekYear = defaults(w.gg, config._a[YEAR], curWeek.year);
  2363. // Default to current week.
  2364. week = defaults(w.w, curWeek.week);
  2365. if (w.d != null) {
  2366. // weekday -- low day numbers are considered next week
  2367. weekday = w.d;
  2368. if (weekday < 0 || weekday > 6) {
  2369. weekdayOverflow = true;
  2370. }
  2371. } else if (w.e != null) {
  2372. // local weekday -- counting starts from beginning of week
  2373. weekday = w.e + dow;
  2374. if (w.e < 0 || w.e > 6) {
  2375. weekdayOverflow = true;
  2376. }
  2377. } else {
  2378. // default to beginning of week
  2379. weekday = dow;
  2380. }
  2381. }
  2382. if (week < 1 || week > weeksInYear(weekYear, dow, doy)) {
  2383. getParsingFlags(config)._overflowWeeks = true;
  2384. } else if (weekdayOverflow != null) {
  2385. getParsingFlags(config)._overflowWeekday = true;
  2386. } else {
  2387. temp = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy);
  2388. config._a[YEAR] = temp.year;
  2389. config._dayOfYear = temp.dayOfYear;
  2390. }
  2391. }
  2392. // constant that refers to the ISO standard
  2393. hooks.ISO_8601 = function () {};
  2394. // constant that refers to the RFC 2822 form
  2395. hooks.RFC_2822 = function () {};
  2396. // date from string and format string
  2397. function configFromStringAndFormat(config) {
  2398. // TODO: Move this to another part of the creation flow to prevent circular deps
  2399. if (config._f === hooks.ISO_8601) {
  2400. configFromISO(config);
  2401. return;
  2402. }
  2403. if (config._f === hooks.RFC_2822) {
  2404. configFromRFC2822(config);
  2405. return;
  2406. }
  2407. config._a = [];
  2408. getParsingFlags(config).empty = true;
  2409. // This array is used to make a Date, either with `new Date` or `Date.UTC`
  2410. var string = "" + config._i,
  2411. i,
  2412. parsedInput,
  2413. tokens,
  2414. token,
  2415. skipped,
  2416. stringLength = string.length,
  2417. totalParsedInputLength = 0,
  2418. era,
  2419. tokenLen;
  2420. tokens =
  2421. expandFormat(config._f, config._locale).match(formattingTokens) || [];
  2422. tokenLen = tokens.length;
  2423. for (i = 0; i < tokenLen; i++) {
  2424. token = tokens[i];
  2425. parsedInput = (string.match(getParseRegexForToken(token, config)) ||
  2426. [])[0];
  2427. if (parsedInput) {
  2428. skipped = string.substr(0, string.indexOf(parsedInput));
  2429. if (skipped.length > 0) {
  2430. getParsingFlags(config).unusedInput.push(skipped);
  2431. }
  2432. string = string.slice(string.indexOf(parsedInput) + parsedInput.length);
  2433. totalParsedInputLength += parsedInput.length;
  2434. }
  2435. // don't parse if it's not a known token
  2436. if (formatTokenFunctions[token]) {
  2437. if (parsedInput) {
  2438. getParsingFlags(config).empty = false;
  2439. } else {
  2440. getParsingFlags(config).unusedTokens.push(token);
  2441. }
  2442. addTimeToArrayFromToken(token, parsedInput, config);
  2443. } else if (config._strict && !parsedInput) {
  2444. getParsingFlags(config).unusedTokens.push(token);
  2445. }
  2446. }
  2447. // add remaining unparsed input length to the string
  2448. getParsingFlags(config).charsLeftOver =
  2449. stringLength - totalParsedInputLength;
  2450. if (string.length > 0) {
  2451. getParsingFlags(config).unusedInput.push(string);
  2452. }
  2453. // clear _12h flag if hour is <= 12
  2454. if (
  2455. config._a[HOUR] <= 12 &&
  2456. getParsingFlags(config).bigHour === true &&
  2457. config._a[HOUR] > 0
  2458. ) {
  2459. getParsingFlags(config).bigHour = undefined;
  2460. }
  2461. getParsingFlags(config).parsedDateParts = config._a.slice(0);
  2462. getParsingFlags(config).meridiem = config._meridiem;
  2463. // handle meridiem
  2464. config._a[HOUR] = meridiemFixWrap(
  2465. config._locale,
  2466. config._a[HOUR],
  2467. config._meridiem
  2468. );
  2469. // handle era
  2470. era = getParsingFlags(config).era;
  2471. if (era !== null) {
  2472. config._a[YEAR] = config._locale.erasConvertYear(era, config._a[YEAR]);
  2473. }
  2474. configFromArray(config);
  2475. checkOverflow(config);
  2476. }
  2477. function meridiemFixWrap(locale, hour, meridiem) {
  2478. var isPm;
  2479. if (meridiem == null) {
  2480. // nothing to do
  2481. return hour;
  2482. }
  2483. if (locale.meridiemHour != null) {
  2484. return locale.meridiemHour(hour, meridiem);
  2485. } else if (locale.isPM != null) {
  2486. // Fallback
  2487. isPm = locale.isPM(meridiem);
  2488. if (isPm && hour < 12) {
  2489. hour += 12;
  2490. }
  2491. if (!isPm && hour === 12) {
  2492. hour = 0;
  2493. }
  2494. return hour;
  2495. } else {
  2496. // this is not supposed to happen
  2497. return hour;
  2498. }
  2499. }
  2500. // date from string and array of format strings
  2501. function configFromStringAndArray(config) {
  2502. var tempConfig,
  2503. bestMoment,
  2504. scoreToBeat,
  2505. i,
  2506. currentScore,
  2507. validFormatFound,
  2508. bestFormatIsValid = false,
  2509. configfLen = config._f.length;
  2510. if (configfLen === 0) {
  2511. getParsingFlags(config).invalidFormat = true;
  2512. config._d = new Date(NaN);
  2513. return;
  2514. }
  2515. for (i = 0; i < configfLen; i++) {
  2516. currentScore = 0;
  2517. validFormatFound = false;
  2518. tempConfig = copyConfig({}, config);
  2519. if (config._useUTC != null) {
  2520. tempConfig._useUTC = config._useUTC;
  2521. }
  2522. tempConfig._f = config._f[i];
  2523. configFromStringAndFormat(tempConfig);
  2524. if (isValid(tempConfig)) {
  2525. validFormatFound = true;
  2526. }
  2527. // if there is any input that was not parsed add a penalty for that format
  2528. currentScore += getParsingFlags(tempConfig).charsLeftOver;
  2529. //or tokens
  2530. currentScore += getParsingFlags(tempConfig).unusedTokens.length * 10;
  2531. getParsingFlags(tempConfig).score = currentScore;
  2532. if (!bestFormatIsValid) {
  2533. if (
  2534. scoreToBeat == null ||
  2535. currentScore < scoreToBeat ||
  2536. validFormatFound
  2537. ) {
  2538. scoreToBeat = currentScore;
  2539. bestMoment = tempConfig;
  2540. if (validFormatFound) {
  2541. bestFormatIsValid = true;
  2542. }
  2543. }
  2544. } else {
  2545. if (currentScore < scoreToBeat) {
  2546. scoreToBeat = currentScore;
  2547. bestMoment = tempConfig;
  2548. }
  2549. }
  2550. }
  2551. extend(config, bestMoment || tempConfig);
  2552. }
  2553. function configFromObject(config) {
  2554. if (config._d) {
  2555. return;
  2556. }
  2557. var i = normalizeObjectUnits(config._i),
  2558. dayOrDate = i.day === undefined ? i.date : i.day;
  2559. config._a = map(
  2560. [i.year, i.month, dayOrDate, i.hour, i.minute, i.second, i.millisecond],
  2561. function (obj) {
  2562. return obj && parseInt(obj, 10);
  2563. }
  2564. );
  2565. configFromArray(config);
  2566. }
  2567. function createFromConfig(config) {
  2568. var res = new Moment(checkOverflow(prepareConfig(config)));
  2569. if (res._nextDay) {
  2570. // Adding is smart enough around DST
  2571. res.add(1, "d");
  2572. res._nextDay = undefined;
  2573. }
  2574. return res;
  2575. }
  2576. function prepareConfig(config) {
  2577. var input = config._i,
  2578. format = config._f;
  2579. config._locale = config._locale || getLocale(config._l);
  2580. if (input === null || (format === undefined && input === "")) {
  2581. return createInvalid({nullInput: true});
  2582. }
  2583. if (typeof input === "string") {
  2584. config._i = input = config._locale.preparse(input);
  2585. }
  2586. if (isMoment(input)) {
  2587. return new Moment(checkOverflow(input));
  2588. } else if (isDate(input)) {
  2589. config._d = input;
  2590. } else if (isArray(format)) {
  2591. configFromStringAndArray(config);
  2592. } else if (format) {
  2593. configFromStringAndFormat(config);
  2594. } else {
  2595. configFromInput(config);
  2596. }
  2597. if (!isValid(config)) {
  2598. config._d = null;
  2599. }
  2600. return config;
  2601. }
  2602. function configFromInput(config) {
  2603. var input = config._i;
  2604. if (isUndefined(input)) {
  2605. config._d = new Date(hooks.now());
  2606. } else if (isDate(input)) {
  2607. config._d = new Date(input.valueOf());
  2608. } else if (typeof input === "string") {
  2609. configFromString(config);
  2610. } else if (isArray(input)) {
  2611. config._a = map(input.slice(0), function (obj) {
  2612. return parseInt(obj, 10);
  2613. });
  2614. configFromArray(config);
  2615. } else if (isObject(input)) {
  2616. configFromObject(config);
  2617. } else if (isNumber(input)) {
  2618. // from milliseconds
  2619. config._d = new Date(input);
  2620. } else {
  2621. hooks.createFromInputFallback(config);
  2622. }
  2623. }
  2624. function createLocalOrUTC(input, format, locale, strict, isUTC) {
  2625. var c = {};
  2626. if (format === true || format === false) {
  2627. strict = format;
  2628. format = undefined;
  2629. }
  2630. if (locale === true || locale === false) {
  2631. strict = locale;
  2632. locale = undefined;
  2633. }
  2634. if (
  2635. (isObject(input) && isObjectEmpty(input)) ||
  2636. (isArray(input) && input.length === 0)
  2637. ) {
  2638. input = undefined;
  2639. }
  2640. // object construction must be done this way.
  2641. // https://github.com/moment/moment/issues/1423
  2642. c._isAMomentObject = true;
  2643. c._useUTC = c._isUTC = isUTC;
  2644. c._l = locale;
  2645. c._i = input;
  2646. c._f = format;
  2647. c._strict = strict;
  2648. return createFromConfig(c);
  2649. }
  2650. function createLocal(input, format, locale, strict) {
  2651. return createLocalOrUTC(input, format, locale, strict, false);
  2652. }
  2653. var prototypeMin = deprecate(
  2654. "moment().min is deprecated, use moment.max instead. http://momentjs.com/guides/#/warnings/min-max/",
  2655. function () {
  2656. var other = createLocal.apply(null, arguments);
  2657. if (this.isValid() && other.isValid()) {
  2658. return other < this ? this : other;
  2659. } else {
  2660. return createInvalid();
  2661. }
  2662. }
  2663. ),
  2664. prototypeMax = deprecate(
  2665. "moment().max is deprecated, use moment.min instead. http://momentjs.com/guides/#/warnings/min-max/",
  2666. function () {
  2667. var other = createLocal.apply(null, arguments);
  2668. if (this.isValid() && other.isValid()) {
  2669. return other > this ? this : other;
  2670. } else {
  2671. return createInvalid();
  2672. }
  2673. }
  2674. );
  2675. // Pick a moment m from moments so that m[fn](other) is true for all
  2676. // other. This relies on the function fn to be transitive.
  2677. //
  2678. // moments should either be an array of moment objects or an array, whose
  2679. // first element is an array of moment objects.
  2680. function pickBy(fn, moments) {
  2681. var res, i;
  2682. if (moments.length === 1 && isArray(moments[0])) {
  2683. moments = moments[0];
  2684. }
  2685. if (!moments.length) {
  2686. return createLocal();
  2687. }
  2688. res = moments[0];
  2689. for (i = 1; i < moments.length; ++i) {
  2690. if (!moments[i].isValid() || moments[i][fn](res)) {
  2691. res = moments[i];
  2692. }
  2693. }
  2694. return res;
  2695. }
  2696. // TODO: Use [].sort instead?
  2697. function min() {
  2698. var args = [].slice.call(arguments, 0);
  2699. return pickBy("isBefore", args);
  2700. }
  2701. function max() {
  2702. var args = [].slice.call(arguments, 0);
  2703. return pickBy("isAfter", args);
  2704. }
  2705. var now = function () {
  2706. return Date.now ? Date.now() : +new Date();
  2707. };
  2708. var ordering = [
  2709. "year",
  2710. "quarter",
  2711. "month",
  2712. "week",
  2713. "day",
  2714. "hour",
  2715. "minute",
  2716. "second",
  2717. "millisecond",
  2718. ];
  2719. function isDurationValid(m) {
  2720. var key,
  2721. unitHasDecimal = false,
  2722. i,
  2723. orderLen = ordering.length;
  2724. for (key in m) {
  2725. if (
  2726. hasOwnProp(m, key) &&
  2727. !(
  2728. indexOf.call(ordering, key) !== -1 &&
  2729. (m[key] == null || !isNaN(m[key]))
  2730. )
  2731. ) {
  2732. return false;
  2733. }
  2734. }
  2735. for (i = 0; i < orderLen; ++i) {
  2736. if (m[ordering[i]]) {
  2737. if (unitHasDecimal) {
  2738. return false; // only allow non-integers for smallest unit
  2739. }
  2740. if (parseFloat(m[ordering[i]]) !== toInt(m[ordering[i]])) {
  2741. unitHasDecimal = true;
  2742. }
  2743. }
  2744. }
  2745. return true;
  2746. }
  2747. function isValid$1() {
  2748. return this._isValid;
  2749. }
  2750. function createInvalid$1() {
  2751. return createDuration(NaN);
  2752. }
  2753. function Duration(duration) {
  2754. var normalizedInput = normalizeObjectUnits(duration),
  2755. years = normalizedInput.year || 0,
  2756. quarters = normalizedInput.quarter || 0,
  2757. months = normalizedInput.month || 0,
  2758. weeks = normalizedInput.week || normalizedInput.isoWeek || 0,
  2759. days = normalizedInput.day || 0,
  2760. hours = normalizedInput.hour || 0,
  2761. minutes = normalizedInput.minute || 0,
  2762. seconds = normalizedInput.second || 0,
  2763. milliseconds = normalizedInput.millisecond || 0;
  2764. this._isValid = isDurationValid(normalizedInput);
  2765. // representation for dateAddRemove
  2766. this._milliseconds =
  2767. +milliseconds +
  2768. seconds * 1e3 + // 1000
  2769. minutes * 6e4 + // 1000 * 60
  2770. hours * 1000 * 60 * 60; //using 1000 * 60 * 60 instead of 36e5 to avoid floating point rounding errors https://github.com/moment/moment/issues/2978
  2771. // Because of dateAddRemove treats 24 hours as different from a
  2772. // day when working around DST, we need to store them separately
  2773. this._days = +days + weeks * 7;
  2774. // It is impossible to translate months into days without knowing
  2775. // which months you are are talking about, so we have to store
  2776. // it separately.
  2777. this._months = +months + quarters * 3 + years * 12;
  2778. this._data = {};
  2779. this._locale = getLocale();
  2780. this._bubble();
  2781. }
  2782. function isDuration(obj) {
  2783. return obj instanceof Duration;
  2784. }
  2785. function absRound(number) {
  2786. if (number < 0) {
  2787. return Math.round(-1 * number) * -1;
  2788. } else {
  2789. return Math.round(number);
  2790. }
  2791. }
  2792. // compare two arrays, return the number of differences
  2793. function compareArrays(array1, array2, dontConvert) {
  2794. var len = Math.min(array1.length, array2.length),
  2795. lengthDiff = Math.abs(array1.length - array2.length),
  2796. diffs = 0,
  2797. i;
  2798. for (i = 0; i < len; i++) {
  2799. if (
  2800. (dontConvert && array1[i] !== array2[i]) ||
  2801. (!dontConvert && toInt(array1[i]) !== toInt(array2[i]))
  2802. ) {
  2803. diffs++;
  2804. }
  2805. }
  2806. return diffs + lengthDiff;
  2807. }
  2808. // FORMATTING
  2809. function offset(token, separator) {
  2810. addFormatToken(token, 0, 0, function () {
  2811. var offset = this.utcOffset(),
  2812. sign = "+";
  2813. if (offset < 0) {
  2814. offset = -offset;
  2815. sign = "-";
  2816. }
  2817. return (
  2818. sign +
  2819. zeroFill(~~(offset / 60), 2) +
  2820. separator +
  2821. zeroFill(~~offset % 60, 2)
  2822. );
  2823. });
  2824. }
  2825. offset("Z", ":");
  2826. offset("ZZ", "");
  2827. // PARSING
  2828. addRegexToken("Z", matchShortOffset);
  2829. addRegexToken("ZZ", matchShortOffset);
  2830. addParseToken(["Z", "ZZ"], function (input, array, config) {
  2831. config._useUTC = true;
  2832. config._tzm = offsetFromString(matchShortOffset, input);
  2833. });
  2834. // HELPERS
  2835. // timezone chunker
  2836. // '+10:00' > ['10', '00']
  2837. // '-1530' > ['-15', '30']
  2838. var chunkOffset = /([\+\-]|\d\d)/gi;
  2839. function offsetFromString(matcher, string) {
  2840. var matches = (string || "").match(matcher),
  2841. chunk,
  2842. parts,
  2843. minutes;
  2844. if (matches === null) {
  2845. return null;
  2846. }
  2847. chunk = matches[matches.length - 1] || [];
  2848. parts = (chunk + "").match(chunkOffset) || ["-", 0, 0];
  2849. minutes = +(parts[1] * 60) + toInt(parts[2]);
  2850. return minutes === 0 ? 0 : parts[0] === "+" ? minutes : -minutes;
  2851. }
  2852. // Return a moment from input, that is local/utc/zone equivalent to model.
  2853. function cloneWithOffset(input, model) {
  2854. var res, diff;
  2855. if (model._isUTC) {
  2856. res = model.clone();
  2857. diff =
  2858. (isMoment(input) || isDate(input)
  2859. ? input.valueOf()
  2860. : createLocal(input).valueOf()) - res.valueOf();
  2861. // Use low-level api, because this fn is low-level api.
  2862. res._d.setTime(res._d.valueOf() + diff);
  2863. hooks.updateOffset(res, false);
  2864. return res;
  2865. } else {
  2866. return createLocal(input).local();
  2867. }
  2868. }
  2869. function getDateOffset(m) {
  2870. // On Firefox.24 Date#getTimezoneOffset returns a floating point.
  2871. // https://github.com/moment/moment/pull/1871
  2872. return -Math.round(m._d.getTimezoneOffset());
  2873. }
  2874. // HOOKS
  2875. // This function will be called whenever a moment is mutated.
  2876. // It is intended to keep the offset in sync with the timezone.
  2877. hooks.updateOffset = function () {};
  2878. // MOMENTS
  2879. // keepLocalTime = true means only change the timezone, without
  2880. // affecting the local hour. So 5:31:26 +0300 --[utcOffset(2, true)]-->
  2881. // 5:31:26 +0200 It is possible that 5:31:26 doesn't exist with offset
  2882. // +0200, so we adjust the time as needed, to be valid.
  2883. //
  2884. // Keeping the time actually adds/subtracts (one hour)
  2885. // from the actual represented time. That is why we call updateOffset
  2886. // a second time. In case it wants us to change the offset again
  2887. // _changeInProgress == true case, then we have to adjust, because
  2888. // there is no such time in the given timezone.
  2889. function getSetOffset(input, keepLocalTime, keepMinutes) {
  2890. var offset = this._offset || 0,
  2891. localAdjust;
  2892. if (!this.isValid()) {
  2893. return input != null ? this : NaN;
  2894. }
  2895. if (input != null) {
  2896. if (typeof input === "string") {
  2897. input = offsetFromString(matchShortOffset, input);
  2898. if (input === null) {
  2899. return this;
  2900. }
  2901. } else if (Math.abs(input) < 16 && !keepMinutes) {
  2902. input = input * 60;
  2903. }
  2904. if (!this._isUTC && keepLocalTime) {
  2905. localAdjust = getDateOffset(this);
  2906. }
  2907. this._offset = input;
  2908. this._isUTC = true;
  2909. if (localAdjust != null) {
  2910. this.add(localAdjust, "m");
  2911. }
  2912. if (offset !== input) {
  2913. if (!keepLocalTime || this._changeInProgress) {
  2914. addSubtract(this, createDuration(input - offset, "m"), 1, false);
  2915. } else if (!this._changeInProgress) {
  2916. this._changeInProgress = true;
  2917. hooks.updateOffset(this, true);
  2918. this._changeInProgress = null;
  2919. }
  2920. }
  2921. return this;
  2922. } else {
  2923. return this._isUTC ? offset : getDateOffset(this);
  2924. }
  2925. }
  2926. function getSetZone(input, keepLocalTime) {
  2927. if (input != null) {
  2928. if (typeof input !== "string") {
  2929. input = -input;
  2930. }
  2931. this.utcOffset(input, keepLocalTime);
  2932. return this;
  2933. } else {
  2934. return -this.utcOffset();
  2935. }
  2936. }
  2937. function setOffsetToUTC(keepLocalTime) {
  2938. return this.utcOffset(0, keepLocalTime);
  2939. }
  2940. function setOffsetToLocal(keepLocalTime) {
  2941. if (this._isUTC) {
  2942. this.utcOffset(0, keepLocalTime);
  2943. this._isUTC = false;
  2944. if (keepLocalTime) {
  2945. this.subtract(getDateOffset(this), "m");
  2946. }
  2947. }
  2948. return this;
  2949. }
  2950. function setOffsetToParsedOffset() {
  2951. if (this._tzm != null) {
  2952. this.utcOffset(this._tzm, false, true);
  2953. } else if (typeof this._i === "string") {
  2954. var tZone = offsetFromString(matchOffset, this._i);
  2955. if (tZone != null) {
  2956. this.utcOffset(tZone);
  2957. } else {
  2958. this.utcOffset(0, true);
  2959. }
  2960. }
  2961. return this;
  2962. }
  2963. function hasAlignedHourOffset(input) {
  2964. if (!this.isValid()) {
  2965. return false;
  2966. }
  2967. input = input ? createLocal(input).utcOffset() : 0;
  2968. return (this.utcOffset() - input) % 60 === 0;
  2969. }
  2970. function isDaylightSavingTime() {
  2971. return (
  2972. this.utcOffset() > this.clone().month(0).utcOffset() ||
  2973. this.utcOffset() > this.clone().month(5).utcOffset()
  2974. );
  2975. }
  2976. function isDaylightSavingTimeShifted() {
  2977. if (!isUndefined(this._isDSTShifted)) {
  2978. return this._isDSTShifted;
  2979. }
  2980. var c = {},
  2981. other;
  2982. copyConfig(c, this);
  2983. c = prepareConfig(c);
  2984. if (c._a) {
  2985. other = c._isUTC ? createUTC(c._a) : createLocal(c._a);
  2986. this._isDSTShifted =
  2987. this.isValid() && compareArrays(c._a, other.toArray()) > 0;
  2988. } else {
  2989. this._isDSTShifted = false;
  2990. }
  2991. return this._isDSTShifted;
  2992. }
  2993. function isLocal() {
  2994. return this.isValid() ? !this._isUTC : false;
  2995. }
  2996. function isUtcOffset() {
  2997. return this.isValid() ? this._isUTC : false;
  2998. }
  2999. function isUtc() {
  3000. return this.isValid() ? this._isUTC && this._offset === 0 : false;
  3001. }
  3002. // ASP.NET json date format regex
  3003. var aspNetRegex = /^(-|\+)?(?:(\d*)[. ])?(\d+):(\d+)(?::(\d+)(\.\d*)?)?$/,
  3004. // from http://docs.closure-library.googlecode.com/git/closure_goog_date_date.js.source.html
  3005. // somewhat more in line with 4.4.3.2 2004 spec, but allows decimal anywhere
  3006. // and further modified to allow for strings containing both week and day
  3007. isoRegex =
  3008. /^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/;
  3009. function createDuration(input, key) {
  3010. var duration = input,
  3011. // matching against regexp is expensive, do it on demand
  3012. match = null,
  3013. sign,
  3014. ret,
  3015. diffRes;
  3016. if (isDuration(input)) {
  3017. duration = {
  3018. ms: input._milliseconds,
  3019. d: input._days,
  3020. M: input._months,
  3021. };
  3022. } else if (isNumber(input) || !isNaN(+input)) {
  3023. duration = {};
  3024. if (key) {
  3025. duration[key] = +input;
  3026. } else {
  3027. duration.milliseconds = +input;
  3028. }
  3029. } else if ((match = aspNetRegex.exec(input))) {
  3030. sign = match[1] === "-" ? -1 : 1;
  3031. duration = {
  3032. y: 0,
  3033. d: toInt(match[DATE]) * sign,
  3034. h: toInt(match[HOUR]) * sign,
  3035. m: toInt(match[MINUTE]) * sign,
  3036. s: toInt(match[SECOND]) * sign,
  3037. ms: toInt(absRound(match[MILLISECOND] * 1000)) * sign, // the millisecond decimal point is included in the match
  3038. };
  3039. } else if ((match = isoRegex.exec(input))) {
  3040. sign = match[1] === "-" ? -1 : 1;
  3041. duration = {
  3042. y: parseIso(match[2], sign),
  3043. M: parseIso(match[3], sign),
  3044. w: parseIso(match[4], sign),
  3045. d: parseIso(match[5], sign),
  3046. h: parseIso(match[6], sign),
  3047. m: parseIso(match[7], sign),
  3048. s: parseIso(match[8], sign),
  3049. };
  3050. } else if (duration == null) {
  3051. // checks for null or undefined
  3052. duration = {};
  3053. } else if (
  3054. typeof duration === "object" &&
  3055. ("from" in duration || "to" in duration)
  3056. ) {
  3057. diffRes = momentsDifference(
  3058. createLocal(duration.from),
  3059. createLocal(duration.to)
  3060. );
  3061. duration = {};
  3062. duration.ms = diffRes.milliseconds;
  3063. duration.M = diffRes.months;
  3064. }
  3065. ret = new Duration(duration);
  3066. if (isDuration(input) && hasOwnProp(input, "_locale")) {
  3067. ret._locale = input._locale;
  3068. }
  3069. if (isDuration(input) && hasOwnProp(input, "_isValid")) {
  3070. ret._isValid = input._isValid;
  3071. }
  3072. return ret;
  3073. }
  3074. createDuration.fn = Duration.prototype;
  3075. createDuration.invalid = createInvalid$1;
  3076. function parseIso(inp, sign) {
  3077. // We'd normally use ~~inp for this, but unfortunately it also
  3078. // converts floats to ints.
  3079. // inp may be undefined, so careful calling replace on it.
  3080. var res = inp && parseFloat(inp.replace(",", "."));
  3081. // apply sign while we're at it
  3082. return (isNaN(res) ? 0 : res) * sign;
  3083. }
  3084. function positiveMomentsDifference(base, other) {
  3085. var res = {};
  3086. res.months =
  3087. other.month() - base.month() + (other.year() - base.year()) * 12;
  3088. if (base.clone().add(res.months, "M").isAfter(other)) {
  3089. --res.months;
  3090. }
  3091. res.milliseconds = +other - +base.clone().add(res.months, "M");
  3092. return res;
  3093. }
  3094. function momentsDifference(base, other) {
  3095. var res;
  3096. if (!(base.isValid() && other.isValid())) {
  3097. return {milliseconds: 0, months: 0};
  3098. }
  3099. other = cloneWithOffset(other, base);
  3100. if (base.isBefore(other)) {
  3101. res = positiveMomentsDifference(base, other);
  3102. } else {
  3103. res = positiveMomentsDifference(other, base);
  3104. res.milliseconds = -res.milliseconds;
  3105. res.months = -res.months;
  3106. }
  3107. return res;
  3108. }
  3109. // TODO: remove 'name' arg after deprecation is removed
  3110. function createAdder(direction, name) {
  3111. return function (val, period) {
  3112. var dur, tmp;
  3113. //invert the arguments, but complain about it
  3114. if (period !== null && !isNaN(+period)) {
  3115. deprecateSimple(
  3116. name,
  3117. "moment()." +
  3118. name +
  3119. "(period, number) is deprecated. Please use moment()." +
  3120. name +
  3121. "(number, period). " +
  3122. "See http://momentjs.com/guides/#/warnings/add-inverted-param/ for more info."
  3123. );
  3124. tmp = val;
  3125. val = period;
  3126. period = tmp;
  3127. }
  3128. dur = createDuration(val, period);
  3129. addSubtract(this, dur, direction);
  3130. return this;
  3131. };
  3132. }
  3133. function addSubtract(mom, duration, isAdding, updateOffset) {
  3134. var milliseconds = duration._milliseconds,
  3135. days = absRound(duration._days),
  3136. months = absRound(duration._months);
  3137. if (!mom.isValid()) {
  3138. // No op
  3139. return;
  3140. }
  3141. updateOffset = updateOffset == null ? true : updateOffset;
  3142. if (months) {
  3143. setMonth(mom, get(mom, "Month") + months * isAdding);
  3144. }
  3145. if (days) {
  3146. set$1(mom, "Date", get(mom, "Date") + days * isAdding);
  3147. }
  3148. if (milliseconds) {
  3149. mom._d.setTime(mom._d.valueOf() + milliseconds * isAdding);
  3150. }
  3151. if (updateOffset) {
  3152. hooks.updateOffset(mom, days || months);
  3153. }
  3154. }
  3155. var add = createAdder(1, "add"),
  3156. subtract = createAdder(-1, "subtract");
  3157. function isString(input) {
  3158. return typeof input === "string" || input instanceof String;
  3159. }
  3160. // type MomentInput = Moment | Date | string | number | (number | string)[] | MomentInputObject | void; // null | undefined
  3161. function isMomentInput(input) {
  3162. return (
  3163. isMoment(input) ||
  3164. isDate(input) ||
  3165. isString(input) ||
  3166. isNumber(input) ||
  3167. isNumberOrStringArray(input) ||
  3168. isMomentInputObject(input) ||
  3169. input === null ||
  3170. input === undefined
  3171. );
  3172. }
  3173. function isMomentInputObject(input) {
  3174. var objectTest = isObject(input) && !isObjectEmpty(input),
  3175. propertyTest = false,
  3176. properties = [
  3177. "years",
  3178. "year",
  3179. "y",
  3180. "months",
  3181. "month",
  3182. "M",
  3183. "days",
  3184. "day",
  3185. "d",
  3186. "dates",
  3187. "date",
  3188. "D",
  3189. "hours",
  3190. "hour",
  3191. "h",
  3192. "minutes",
  3193. "minute",
  3194. "m",
  3195. "seconds",
  3196. "second",
  3197. "s",
  3198. "milliseconds",
  3199. "millisecond",
  3200. "ms",
  3201. ],
  3202. i,
  3203. property,
  3204. propertyLen = properties.length;
  3205. for (i = 0; i < propertyLen; i += 1) {
  3206. property = properties[i];
  3207. propertyTest = propertyTest || hasOwnProp(input, property);
  3208. }
  3209. return objectTest && propertyTest;
  3210. }
  3211. function isNumberOrStringArray(input) {
  3212. var arrayTest = isArray(input),
  3213. dataTypeTest = false;
  3214. if (arrayTest) {
  3215. dataTypeTest =
  3216. input.filter(function (item) {
  3217. return !isNumber(item) && isString(input);
  3218. }).length === 0;
  3219. }
  3220. return arrayTest && dataTypeTest;
  3221. }
  3222. function isCalendarSpec(input) {
  3223. var objectTest = isObject(input) && !isObjectEmpty(input),
  3224. propertyTest = false,
  3225. properties = [
  3226. "sameDay",
  3227. "nextDay",
  3228. "lastDay",
  3229. "nextWeek",
  3230. "lastWeek",
  3231. "sameElse",
  3232. ],
  3233. i,
  3234. property;
  3235. for (i = 0; i < properties.length; i += 1) {
  3236. property = properties[i];
  3237. propertyTest = propertyTest || hasOwnProp(input, property);
  3238. }
  3239. return objectTest && propertyTest;
  3240. }
  3241. function getCalendarFormat(myMoment, now) {
  3242. var diff = myMoment.diff(now, "days", true);
  3243. return diff < -6
  3244. ? "sameElse"
  3245. : diff < -1
  3246. ? "lastWeek"
  3247. : diff < 0
  3248. ? "lastDay"
  3249. : diff < 1
  3250. ? "sameDay"
  3251. : diff < 2
  3252. ? "nextDay"
  3253. : diff < 7
  3254. ? "nextWeek"
  3255. : "sameElse";
  3256. }
  3257. function calendar$1(time, formats) {
  3258. // Support for single parameter, formats only overload to the calendar function
  3259. if (arguments.length === 1) {
  3260. if (!arguments[0]) {
  3261. time = undefined;
  3262. formats = undefined;
  3263. } else if (isMomentInput(arguments[0])) {
  3264. time = arguments[0];
  3265. formats = undefined;
  3266. } else if (isCalendarSpec(arguments[0])) {
  3267. formats = arguments[0];
  3268. time = undefined;
  3269. }
  3270. }
  3271. // We want to compare the start of today, vs this.
  3272. // Getting start-of-today depends on whether we're local/utc/offset or not.
  3273. var now = time || createLocal(),
  3274. sod = cloneWithOffset(now, this).startOf("day"),
  3275. format = hooks.calendarFormat(this, sod) || "sameElse",
  3276. output =
  3277. formats &&
  3278. (isFunction(formats[format])
  3279. ? formats[format].call(this, now)
  3280. : formats[format]);
  3281. return this.format(
  3282. output || this.localeData().calendar(format, this, createLocal(now))
  3283. );
  3284. }
  3285. function clone() {
  3286. return new Moment(this);
  3287. }
  3288. function isAfter(input, units) {
  3289. var localInput = isMoment(input) ? input : createLocal(input);
  3290. if (!(this.isValid() && localInput.isValid())) {
  3291. return false;
  3292. }
  3293. units = normalizeUnits(units) || "millisecond";
  3294. if (units === "millisecond") {
  3295. return this.valueOf() > localInput.valueOf();
  3296. } else {
  3297. return localInput.valueOf() < this.clone().startOf(units).valueOf();
  3298. }
  3299. }
  3300. function isBefore(input, units) {
  3301. var localInput = isMoment(input) ? input : createLocal(input);
  3302. if (!(this.isValid() && localInput.isValid())) {
  3303. return false;
  3304. }
  3305. units = normalizeUnits(units) || "millisecond";
  3306. if (units === "millisecond") {
  3307. return this.valueOf() < localInput.valueOf();
  3308. } else {
  3309. return this.clone().endOf(units).valueOf() < localInput.valueOf();
  3310. }
  3311. }
  3312. function isBetween(from, to, units, inclusivity) {
  3313. var localFrom = isMoment(from) ? from : createLocal(from),
  3314. localTo = isMoment(to) ? to : createLocal(to);
  3315. if (!(this.isValid() && localFrom.isValid() && localTo.isValid())) {
  3316. return false;
  3317. }
  3318. inclusivity = inclusivity || "()";
  3319. return (
  3320. (inclusivity[0] === "("
  3321. ? this.isAfter(localFrom, units)
  3322. : !this.isBefore(localFrom, units)) &&
  3323. (inclusivity[1] === ")"
  3324. ? this.isBefore(localTo, units)
  3325. : !this.isAfter(localTo, units))
  3326. );
  3327. }
  3328. function isSame(input, units) {
  3329. var localInput = isMoment(input) ? input : createLocal(input),
  3330. inputMs;
  3331. if (!(this.isValid() && localInput.isValid())) {
  3332. return false;
  3333. }
  3334. units = normalizeUnits(units) || "millisecond";
  3335. if (units === "millisecond") {
  3336. return this.valueOf() === localInput.valueOf();
  3337. } else {
  3338. inputMs = localInput.valueOf();
  3339. return (
  3340. this.clone().startOf(units).valueOf() <= inputMs &&
  3341. inputMs <= this.clone().endOf(units).valueOf()
  3342. );
  3343. }
  3344. }
  3345. function isSameOrAfter(input, units) {
  3346. return this.isSame(input, units) || this.isAfter(input, units);
  3347. }
  3348. function isSameOrBefore(input, units) {
  3349. return this.isSame(input, units) || this.isBefore(input, units);
  3350. }
  3351. function diff(input, units, asFloat) {
  3352. var that, zoneDelta, output;
  3353. if (!this.isValid()) {
  3354. return NaN;
  3355. }
  3356. that = cloneWithOffset(input, this);
  3357. if (!that.isValid()) {
  3358. return NaN;
  3359. }
  3360. zoneDelta = (that.utcOffset() - this.utcOffset()) * 6e4;
  3361. units = normalizeUnits(units);
  3362. switch (units) {
  3363. case "year":
  3364. output = monthDiff(this, that) / 12;
  3365. break;
  3366. case "month":
  3367. output = monthDiff(this, that);
  3368. break;
  3369. case "quarter":
  3370. output = monthDiff(this, that) / 3;
  3371. break;
  3372. case "second":
  3373. output = (this - that) / 1e3;
  3374. break; // 1000
  3375. case "minute":
  3376. output = (this - that) / 6e4;
  3377. break; // 1000 * 60
  3378. case "hour":
  3379. output = (this - that) / 36e5;
  3380. break; // 1000 * 60 * 60
  3381. case "day":
  3382. output = (this - that - zoneDelta) / 864e5;
  3383. break; // 1000 * 60 * 60 * 24, negate dst
  3384. case "week":
  3385. output = (this - that - zoneDelta) / 6048e5;
  3386. break; // 1000 * 60 * 60 * 24 * 7, negate dst
  3387. default:
  3388. output = this - that;
  3389. }
  3390. return asFloat ? output : absFloor(output);
  3391. }
  3392. function monthDiff(a, b) {
  3393. if (a.date() < b.date()) {
  3394. // end-of-month calculations work correct when the start month has more
  3395. // days than the end month.
  3396. return -monthDiff(b, a);
  3397. }
  3398. // difference in months
  3399. var wholeMonthDiff = (b.year() - a.year()) * 12 + (b.month() - a.month()),
  3400. // b is in (anchor - 1 month, anchor + 1 month)
  3401. anchor = a.clone().add(wholeMonthDiff, "months"),
  3402. anchor2,
  3403. adjust;
  3404. if (b - anchor < 0) {
  3405. anchor2 = a.clone().add(wholeMonthDiff - 1, "months");
  3406. // linear across the month
  3407. adjust = (b - anchor) / (anchor - anchor2);
  3408. } else {
  3409. anchor2 = a.clone().add(wholeMonthDiff + 1, "months");
  3410. // linear across the month
  3411. adjust = (b - anchor) / (anchor2 - anchor);
  3412. }
  3413. //check for negative zero, return zero if negative zero
  3414. return -(wholeMonthDiff + adjust) || 0;
  3415. }
  3416. hooks.defaultFormat = "YYYY-MM-DDTHH:mm:ssZ";
  3417. hooks.defaultFormatUtc = "YYYY-MM-DDTHH:mm:ss[Z]";
  3418. function toString() {
  3419. return this.clone().locale("en").format("ddd MMM DD YYYY HH:mm:ss [GMT]ZZ");
  3420. }
  3421. function toISOString(keepOffset) {
  3422. if (!this.isValid()) {
  3423. return null;
  3424. }
  3425. var utc = keepOffset !== true,
  3426. m = utc ? this.clone().utc() : this;
  3427. if (m.year() < 0 || m.year() > 9999) {
  3428. return formatMoment(
  3429. m,
  3430. utc ? "YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]" : "YYYYYY-MM-DD[T]HH:mm:ss.SSSZ"
  3431. );
  3432. }
  3433. if (isFunction(Date.prototype.toISOString)) {
  3434. // native implementation is ~50x faster, use it when we can
  3435. if (utc) {
  3436. return this.toDate().toISOString();
  3437. } else {
  3438. return new Date(this.valueOf() + this.utcOffset() * 60 * 1000)
  3439. .toISOString()
  3440. .replace("Z", formatMoment(m, "Z"));
  3441. }
  3442. }
  3443. return formatMoment(
  3444. m,
  3445. utc ? "YYYY-MM-DD[T]HH:mm:ss.SSS[Z]" : "YYYY-MM-DD[T]HH:mm:ss.SSSZ"
  3446. );
  3447. }
  3448. /**
  3449. * Return a human readable representation of a moment that can
  3450. * also be evaluated to get a new moment which is the same
  3451. *
  3452. * @link https://nodejs.org/dist/latest/docs/api/util.html#util_custom_inspect_function_on_objects
  3453. */
  3454. function inspect() {
  3455. if (!this.isValid()) {
  3456. return "moment.invalid(/* " + this._i + " */)";
  3457. }
  3458. var func = "moment",
  3459. zone = "",
  3460. prefix,
  3461. year,
  3462. datetime,
  3463. suffix;
  3464. if (!this.isLocal()) {
  3465. func = this.utcOffset() === 0 ? "moment.utc" : "moment.parseZone";
  3466. zone = "Z";
  3467. }
  3468. prefix = "[" + func + '("]';
  3469. year = 0 <= this.year() && this.year() <= 9999 ? "YYYY" : "YYYYYY";
  3470. datetime = "-MM-DD[T]HH:mm:ss.SSS";
  3471. suffix = zone + '[")]';
  3472. return this.format(prefix + year + datetime + suffix);
  3473. }
  3474. function format(inputString) {
  3475. if (!inputString) {
  3476. inputString = this.isUtc() ? hooks.defaultFormatUtc : hooks.defaultFormat;
  3477. }
  3478. var output = formatMoment(this, inputString);
  3479. return this.localeData().postformat(output);
  3480. }
  3481. function from(time, withoutSuffix) {
  3482. if (
  3483. this.isValid() &&
  3484. ((isMoment(time) && time.isValid()) || createLocal(time).isValid())
  3485. ) {
  3486. return createDuration({to: this, from: time})
  3487. .locale(this.locale())
  3488. .humanize(!withoutSuffix);
  3489. } else {
  3490. return this.localeData().invalidDate();
  3491. }
  3492. }
  3493. function fromNow(withoutSuffix) {
  3494. return this.from(createLocal(), withoutSuffix);
  3495. }
  3496. function to(time, withoutSuffix) {
  3497. if (
  3498. this.isValid() &&
  3499. ((isMoment(time) && time.isValid()) || createLocal(time).isValid())
  3500. ) {
  3501. return createDuration({from: this, to: time})
  3502. .locale(this.locale())
  3503. .humanize(!withoutSuffix);
  3504. } else {
  3505. return this.localeData().invalidDate();
  3506. }
  3507. }
  3508. function toNow(withoutSuffix) {
  3509. return this.to(createLocal(), withoutSuffix);
  3510. }
  3511. // If passed a locale key, it will set the locale for this
  3512. // instance. Otherwise, it will return the locale configuration
  3513. // variables for this instance.
  3514. function locale(key) {
  3515. var newLocaleData;
  3516. if (key === undefined) {
  3517. return this._locale._abbr;
  3518. } else {
  3519. newLocaleData = getLocale(key);
  3520. if (newLocaleData != null) {
  3521. this._locale = newLocaleData;
  3522. }
  3523. return this;
  3524. }
  3525. }
  3526. var lang = deprecate(
  3527. "moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.",
  3528. function (key) {
  3529. if (key === undefined) {
  3530. return this.localeData();
  3531. } else {
  3532. return this.locale(key);
  3533. }
  3534. }
  3535. );
  3536. function localeData() {
  3537. return this._locale;
  3538. }
  3539. var MS_PER_SECOND = 1000,
  3540. MS_PER_MINUTE = 60 * MS_PER_SECOND,
  3541. MS_PER_HOUR = 60 * MS_PER_MINUTE,
  3542. MS_PER_400_YEARS = (365 * 400 + 97) * 24 * MS_PER_HOUR;
  3543. // actual modulo - handles negative numbers (for dates before 1970):
  3544. function mod$1(dividend, divisor) {
  3545. return ((dividend % divisor) + divisor) % divisor;
  3546. }
  3547. function localStartOfDate(y, m, d) {
  3548. // the date constructor remaps years 0-99 to 1900-1999
  3549. if (y < 100 && y >= 0) {
  3550. // preserve leap years using a full 400 year cycle, then reset
  3551. return new Date(y + 400, m, d) - MS_PER_400_YEARS;
  3552. } else {
  3553. return new Date(y, m, d).valueOf();
  3554. }
  3555. }
  3556. function utcStartOfDate(y, m, d) {
  3557. // Date.UTC remaps years 0-99 to 1900-1999
  3558. if (y < 100 && y >= 0) {
  3559. // preserve leap years using a full 400 year cycle, then reset
  3560. return Date.UTC(y + 400, m, d) - MS_PER_400_YEARS;
  3561. } else {
  3562. return Date.UTC(y, m, d);
  3563. }
  3564. }
  3565. function startOf(units) {
  3566. var time, startOfDate;
  3567. units = normalizeUnits(units);
  3568. if (units === undefined || units === "millisecond" || !this.isValid()) {
  3569. return this;
  3570. }
  3571. startOfDate = this._isUTC ? utcStartOfDate : localStartOfDate;
  3572. switch (units) {
  3573. case "year":
  3574. time = startOfDate(this.year(), 0, 1);
  3575. break;
  3576. case "quarter":
  3577. time = startOfDate(this.year(), this.month() - (this.month() % 3), 1);
  3578. break;
  3579. case "month":
  3580. time = startOfDate(this.year(), this.month(), 1);
  3581. break;
  3582. case "week":
  3583. time = startOfDate(
  3584. this.year(),
  3585. this.month(),
  3586. this.date() - this.weekday()
  3587. );
  3588. break;
  3589. case "isoWeek":
  3590. time = startOfDate(
  3591. this.year(),
  3592. this.month(),
  3593. this.date() - (this.isoWeekday() - 1)
  3594. );
  3595. break;
  3596. case "day":
  3597. case "date":
  3598. time = startOfDate(this.year(), this.month(), this.date());
  3599. break;
  3600. case "hour":
  3601. time = this._d.valueOf();
  3602. time -= mod$1(
  3603. time + (this._isUTC ? 0 : this.utcOffset() * MS_PER_MINUTE),
  3604. MS_PER_HOUR
  3605. );
  3606. break;
  3607. case "minute":
  3608. time = this._d.valueOf();
  3609. time -= mod$1(time, MS_PER_MINUTE);
  3610. break;
  3611. case "second":
  3612. time = this._d.valueOf();
  3613. time -= mod$1(time, MS_PER_SECOND);
  3614. break;
  3615. }
  3616. this._d.setTime(time);
  3617. hooks.updateOffset(this, true);
  3618. return this;
  3619. }
  3620. function endOf(units) {
  3621. var time, startOfDate;
  3622. units = normalizeUnits(units);
  3623. if (units === undefined || units === "millisecond" || !this.isValid()) {
  3624. return this;
  3625. }
  3626. startOfDate = this._isUTC ? utcStartOfDate : localStartOfDate;
  3627. switch (units) {
  3628. case "year":
  3629. time = startOfDate(this.year() + 1, 0, 1) - 1;
  3630. break;
  3631. case "quarter":
  3632. time =
  3633. startOfDate(this.year(), this.month() - (this.month() % 3) + 3, 1) -
  3634. 1;
  3635. break;
  3636. case "month":
  3637. time = startOfDate(this.year(), this.month() + 1, 1) - 1;
  3638. break;
  3639. case "week":
  3640. time =
  3641. startOfDate(
  3642. this.year(),
  3643. this.month(),
  3644. this.date() - this.weekday() + 7
  3645. ) - 1;
  3646. break;
  3647. case "isoWeek":
  3648. time =
  3649. startOfDate(
  3650. this.year(),
  3651. this.month(),
  3652. this.date() - (this.isoWeekday() - 1) + 7
  3653. ) - 1;
  3654. break;
  3655. case "day":
  3656. case "date":
  3657. time = startOfDate(this.year(), this.month(), this.date() + 1) - 1;
  3658. break;
  3659. case "hour":
  3660. time = this._d.valueOf();
  3661. time +=
  3662. MS_PER_HOUR -
  3663. mod$1(
  3664. time + (this._isUTC ? 0 : this.utcOffset() * MS_PER_MINUTE),
  3665. MS_PER_HOUR
  3666. ) -
  3667. 1;
  3668. break;
  3669. case "minute":
  3670. time = this._d.valueOf();
  3671. time += MS_PER_MINUTE - mod$1(time, MS_PER_MINUTE) - 1;
  3672. break;
  3673. case "second":
  3674. time = this._d.valueOf();
  3675. time += MS_PER_SECOND - mod$1(time, MS_PER_SECOND) - 1;
  3676. break;
  3677. }
  3678. this._d.setTime(time);
  3679. hooks.updateOffset(this, true);
  3680. return this;
  3681. }
  3682. function valueOf() {
  3683. return this._d.valueOf() - (this._offset || 0) * 60000;
  3684. }
  3685. function unix() {
  3686. return Math.floor(this.valueOf() / 1000);
  3687. }
  3688. function toDate() {
  3689. return new Date(this.valueOf());
  3690. }
  3691. function toArray() {
  3692. var m = this;
  3693. return [
  3694. m.year(),
  3695. m.month(),
  3696. m.date(),
  3697. m.hour(),
  3698. m.minute(),
  3699. m.second(),
  3700. m.millisecond(),
  3701. ];
  3702. }
  3703. function toObject() {
  3704. var m = this;
  3705. return {
  3706. years: m.year(),
  3707. months: m.month(),
  3708. date: m.date(),
  3709. hours: m.hours(),
  3710. minutes: m.minutes(),
  3711. seconds: m.seconds(),
  3712. milliseconds: m.milliseconds(),
  3713. };
  3714. }
  3715. function toJSON() {
  3716. // new Date(NaN).toJSON() === null
  3717. return this.isValid() ? this.toISOString() : null;
  3718. }
  3719. function isValid$2() {
  3720. return isValid(this);
  3721. }
  3722. function parsingFlags() {
  3723. return extend({}, getParsingFlags(this));
  3724. }
  3725. function invalidAt() {
  3726. return getParsingFlags(this).overflow;
  3727. }
  3728. function creationData() {
  3729. return {
  3730. input: this._i,
  3731. format: this._f,
  3732. locale: this._locale,
  3733. isUTC: this._isUTC,
  3734. strict: this._strict,
  3735. };
  3736. }
  3737. addFormatToken("N", 0, 0, "eraAbbr");
  3738. addFormatToken("NN", 0, 0, "eraAbbr");
  3739. addFormatToken("NNN", 0, 0, "eraAbbr");
  3740. addFormatToken("NNNN", 0, 0, "eraName");
  3741. addFormatToken("NNNNN", 0, 0, "eraNarrow");
  3742. addFormatToken("y", ["y", 1], "yo", "eraYear");
  3743. addFormatToken("y", ["yy", 2], 0, "eraYear");
  3744. addFormatToken("y", ["yyy", 3], 0, "eraYear");
  3745. addFormatToken("y", ["yyyy", 4], 0, "eraYear");
  3746. addRegexToken("N", matchEraAbbr);
  3747. addRegexToken("NN", matchEraAbbr);
  3748. addRegexToken("NNN", matchEraAbbr);
  3749. addRegexToken("NNNN", matchEraName);
  3750. addRegexToken("NNNNN", matchEraNarrow);
  3751. addParseToken(
  3752. ["N", "NN", "NNN", "NNNN", "NNNNN"],
  3753. function (input, array, config, token) {
  3754. var era = config._locale.erasParse(input, token, config._strict);
  3755. if (era) {
  3756. getParsingFlags(config).era = era;
  3757. } else {
  3758. getParsingFlags(config).invalidEra = input;
  3759. }
  3760. }
  3761. );
  3762. addRegexToken("y", matchUnsigned);
  3763. addRegexToken("yy", matchUnsigned);
  3764. addRegexToken("yyy", matchUnsigned);
  3765. addRegexToken("yyyy", matchUnsigned);
  3766. addRegexToken("yo", matchEraYearOrdinal);
  3767. addParseToken(["y", "yy", "yyy", "yyyy"], YEAR);
  3768. addParseToken(["yo"], function (input, array, config, token) {
  3769. var match;
  3770. if (config._locale._eraYearOrdinalRegex) {
  3771. match = input.match(config._locale._eraYearOrdinalRegex);
  3772. }
  3773. if (config._locale.eraYearOrdinalParse) {
  3774. array[YEAR] = config._locale.eraYearOrdinalParse(input, match);
  3775. } else {
  3776. array[YEAR] = parseInt(input, 10);
  3777. }
  3778. });
  3779. function localeEras(m, format) {
  3780. var i,
  3781. l,
  3782. date,
  3783. eras = this._eras || getLocale("en")._eras;
  3784. for (i = 0, l = eras.length; i < l; ++i) {
  3785. switch (typeof eras[i].since) {
  3786. case "string":
  3787. // truncate time
  3788. date = hooks(eras[i].since).startOf("day");
  3789. eras[i].since = date.valueOf();
  3790. break;
  3791. }
  3792. switch (typeof eras[i].until) {
  3793. case "undefined":
  3794. eras[i].until = +Infinity;
  3795. break;
  3796. case "string":
  3797. // truncate time
  3798. date = hooks(eras[i].until).startOf("day").valueOf();
  3799. eras[i].until = date.valueOf();
  3800. break;
  3801. }
  3802. }
  3803. return eras;
  3804. }
  3805. function localeErasParse(eraName, format, strict) {
  3806. var i,
  3807. l,
  3808. eras = this.eras(),
  3809. name,
  3810. abbr,
  3811. narrow;
  3812. eraName = eraName.toUpperCase();
  3813. for (i = 0, l = eras.length; i < l; ++i) {
  3814. name = eras[i].name.toUpperCase();
  3815. abbr = eras[i].abbr.toUpperCase();
  3816. narrow = eras[i].narrow.toUpperCase();
  3817. if (strict) {
  3818. switch (format) {
  3819. case "N":
  3820. case "NN":
  3821. case "NNN":
  3822. if (abbr === eraName) {
  3823. return eras[i];
  3824. }
  3825. break;
  3826. case "NNNN":
  3827. if (name === eraName) {
  3828. return eras[i];
  3829. }
  3830. break;
  3831. case "NNNNN":
  3832. if (narrow === eraName) {
  3833. return eras[i];
  3834. }
  3835. break;
  3836. }
  3837. } else if ([name, abbr, narrow].indexOf(eraName) >= 0) {
  3838. return eras[i];
  3839. }
  3840. }
  3841. }
  3842. function localeErasConvertYear(era, year) {
  3843. var dir = era.since <= era.until ? +1 : -1;
  3844. if (year === undefined) {
  3845. return hooks(era.since).year();
  3846. } else {
  3847. return hooks(era.since).year() + (year - era.offset) * dir;
  3848. }
  3849. }
  3850. function getEraName() {
  3851. var i,
  3852. l,
  3853. val,
  3854. eras = this.localeData().eras();
  3855. for (i = 0, l = eras.length; i < l; ++i) {
  3856. // truncate time
  3857. val = this.clone().startOf("day").valueOf();
  3858. if (eras[i].since <= val && val <= eras[i].until) {
  3859. return eras[i].name;
  3860. }
  3861. if (eras[i].until <= val && val <= eras[i].since) {
  3862. return eras[i].name;
  3863. }
  3864. }
  3865. return "";
  3866. }
  3867. function getEraNarrow() {
  3868. var i,
  3869. l,
  3870. val,
  3871. eras = this.localeData().eras();
  3872. for (i = 0, l = eras.length; i < l; ++i) {
  3873. // truncate time
  3874. val = this.clone().startOf("day").valueOf();
  3875. if (eras[i].since <= val && val <= eras[i].until) {
  3876. return eras[i].narrow;
  3877. }
  3878. if (eras[i].until <= val && val <= eras[i].since) {
  3879. return eras[i].narrow;
  3880. }
  3881. }
  3882. return "";
  3883. }
  3884. function getEraAbbr() {
  3885. var i,
  3886. l,
  3887. val,
  3888. eras = this.localeData().eras();
  3889. for (i = 0, l = eras.length; i < l; ++i) {
  3890. // truncate time
  3891. val = this.clone().startOf("day").valueOf();
  3892. if (eras[i].since <= val && val <= eras[i].until) {
  3893. return eras[i].abbr;
  3894. }
  3895. if (eras[i].until <= val && val <= eras[i].since) {
  3896. return eras[i].abbr;
  3897. }
  3898. }
  3899. return "";
  3900. }
  3901. function getEraYear() {
  3902. var i,
  3903. l,
  3904. dir,
  3905. val,
  3906. eras = this.localeData().eras();
  3907. for (i = 0, l = eras.length; i < l; ++i) {
  3908. dir = eras[i].since <= eras[i].until ? +1 : -1;
  3909. // truncate time
  3910. val = this.clone().startOf("day").valueOf();
  3911. if (
  3912. (eras[i].since <= val && val <= eras[i].until) ||
  3913. (eras[i].until <= val && val <= eras[i].since)
  3914. ) {
  3915. return (
  3916. (this.year() - hooks(eras[i].since).year()) * dir + eras[i].offset
  3917. );
  3918. }
  3919. }
  3920. return this.year();
  3921. }
  3922. function erasNameRegex(isStrict) {
  3923. if (!hasOwnProp(this, "_erasNameRegex")) {
  3924. computeErasParse.call(this);
  3925. }
  3926. return isStrict ? this._erasNameRegex : this._erasRegex;
  3927. }
  3928. function erasAbbrRegex(isStrict) {
  3929. if (!hasOwnProp(this, "_erasAbbrRegex")) {
  3930. computeErasParse.call(this);
  3931. }
  3932. return isStrict ? this._erasAbbrRegex : this._erasRegex;
  3933. }
  3934. function erasNarrowRegex(isStrict) {
  3935. if (!hasOwnProp(this, "_erasNarrowRegex")) {
  3936. computeErasParse.call(this);
  3937. }
  3938. return isStrict ? this._erasNarrowRegex : this._erasRegex;
  3939. }
  3940. function matchEraAbbr(isStrict, locale) {
  3941. return locale.erasAbbrRegex(isStrict);
  3942. }
  3943. function matchEraName(isStrict, locale) {
  3944. return locale.erasNameRegex(isStrict);
  3945. }
  3946. function matchEraNarrow(isStrict, locale) {
  3947. return locale.erasNarrowRegex(isStrict);
  3948. }
  3949. function matchEraYearOrdinal(isStrict, locale) {
  3950. return locale._eraYearOrdinalRegex || matchUnsigned;
  3951. }
  3952. function computeErasParse() {
  3953. var abbrPieces = [],
  3954. namePieces = [],
  3955. narrowPieces = [],
  3956. mixedPieces = [],
  3957. i,
  3958. l,
  3959. eras = this.eras();
  3960. for (i = 0, l = eras.length; i < l; ++i) {
  3961. namePieces.push(regexEscape(eras[i].name));
  3962. abbrPieces.push(regexEscape(eras[i].abbr));
  3963. narrowPieces.push(regexEscape(eras[i].narrow));
  3964. mixedPieces.push(regexEscape(eras[i].name));
  3965. mixedPieces.push(regexEscape(eras[i].abbr));
  3966. mixedPieces.push(regexEscape(eras[i].narrow));
  3967. }
  3968. this._erasRegex = new RegExp("^(" + mixedPieces.join("|") + ")", "i");
  3969. this._erasNameRegex = new RegExp("^(" + namePieces.join("|") + ")", "i");
  3970. this._erasAbbrRegex = new RegExp("^(" + abbrPieces.join("|") + ")", "i");
  3971. this._erasNarrowRegex = new RegExp(
  3972. "^(" + narrowPieces.join("|") + ")",
  3973. "i"
  3974. );
  3975. }
  3976. // FORMATTING
  3977. addFormatToken(0, ["gg", 2], 0, function () {
  3978. return this.weekYear() % 100;
  3979. });
  3980. addFormatToken(0, ["GG", 2], 0, function () {
  3981. return this.isoWeekYear() % 100;
  3982. });
  3983. function addWeekYearFormatToken(token, getter) {
  3984. addFormatToken(0, [token, token.length], 0, getter);
  3985. }
  3986. addWeekYearFormatToken("gggg", "weekYear");
  3987. addWeekYearFormatToken("ggggg", "weekYear");
  3988. addWeekYearFormatToken("GGGG", "isoWeekYear");
  3989. addWeekYearFormatToken("GGGGG", "isoWeekYear");
  3990. // ALIASES
  3991. addUnitAlias("weekYear", "gg");
  3992. addUnitAlias("isoWeekYear", "GG");
  3993. // PRIORITY
  3994. addUnitPriority("weekYear", 1);
  3995. addUnitPriority("isoWeekYear", 1);
  3996. // PARSING
  3997. addRegexToken("G", matchSigned);
  3998. addRegexToken("g", matchSigned);
  3999. addRegexToken("GG", match1to2, match2);
  4000. addRegexToken("gg", match1to2, match2);
  4001. addRegexToken("GGGG", match1to4, match4);
  4002. addRegexToken("gggg", match1to4, match4);
  4003. addRegexToken("GGGGG", match1to6, match6);
  4004. addRegexToken("ggggg", match1to6, match6);
  4005. addWeekParseToken(
  4006. ["gggg", "ggggg", "GGGG", "GGGGG"],
  4007. function (input, week, config, token) {
  4008. week[token.substr(0, 2)] = toInt(input);
  4009. }
  4010. );
  4011. addWeekParseToken(["gg", "GG"], function (input, week, config, token) {
  4012. week[token] = hooks.parseTwoDigitYear(input);
  4013. });
  4014. // MOMENTS
  4015. function getSetWeekYear(input) {
  4016. return getSetWeekYearHelper.call(
  4017. this,
  4018. input,
  4019. this.week(),
  4020. this.weekday(),
  4021. this.localeData()._week.dow,
  4022. this.localeData()._week.doy
  4023. );
  4024. }
  4025. function getSetISOWeekYear(input) {
  4026. return getSetWeekYearHelper.call(
  4027. this,
  4028. input,
  4029. this.isoWeek(),
  4030. this.isoWeekday(),
  4031. 1,
  4032. 4
  4033. );
  4034. }
  4035. function getISOWeeksInYear() {
  4036. return weeksInYear(this.year(), 1, 4);
  4037. }
  4038. function getISOWeeksInISOWeekYear() {
  4039. return weeksInYear(this.isoWeekYear(), 1, 4);
  4040. }
  4041. function getWeeksInYear() {
  4042. var weekInfo = this.localeData()._week;
  4043. return weeksInYear(this.year(), weekInfo.dow, weekInfo.doy);
  4044. }
  4045. function getWeeksInWeekYear() {
  4046. var weekInfo = this.localeData()._week;
  4047. return weeksInYear(this.weekYear(), weekInfo.dow, weekInfo.doy);
  4048. }
  4049. function getSetWeekYearHelper(input, week, weekday, dow, doy) {
  4050. var weeksTarget;
  4051. if (input == null) {
  4052. return weekOfYear(this, dow, doy).year;
  4053. } else {
  4054. weeksTarget = weeksInYear(input, dow, doy);
  4055. if (week > weeksTarget) {
  4056. week = weeksTarget;
  4057. }
  4058. return setWeekAll.call(this, input, week, weekday, dow, doy);
  4059. }
  4060. }
  4061. function setWeekAll(weekYear, week, weekday, dow, doy) {
  4062. var dayOfYearData = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy),
  4063. date = createUTCDate(dayOfYearData.year, 0, dayOfYearData.dayOfYear);
  4064. this.year(date.getUTCFullYear());
  4065. this.month(date.getUTCMonth());
  4066. this.date(date.getUTCDate());
  4067. return this;
  4068. }
  4069. // FORMATTING
  4070. addFormatToken("Q", 0, "Qo", "quarter");
  4071. // ALIASES
  4072. addUnitAlias("quarter", "Q");
  4073. // PRIORITY
  4074. addUnitPriority("quarter", 7);
  4075. // PARSING
  4076. addRegexToken("Q", match1);
  4077. addParseToken("Q", function (input, array) {
  4078. array[MONTH] = (toInt(input) - 1) * 3;
  4079. });
  4080. // MOMENTS
  4081. function getSetQuarter(input) {
  4082. return input == null
  4083. ? Math.ceil((this.month() + 1) / 3)
  4084. : this.month((input - 1) * 3 + (this.month() % 3));
  4085. }
  4086. // FORMATTING
  4087. addFormatToken("D", ["DD", 2], "Do", "date");
  4088. // ALIASES
  4089. addUnitAlias("date", "D");
  4090. // PRIORITY
  4091. addUnitPriority("date", 9);
  4092. // PARSING
  4093. addRegexToken("D", match1to2);
  4094. addRegexToken("DD", match1to2, match2);
  4095. addRegexToken("Do", function (isStrict, locale) {
  4096. // TODO: Remove "ordinalParse" fallback in next major release.
  4097. return isStrict
  4098. ? locale._dayOfMonthOrdinalParse || locale._ordinalParse
  4099. : locale._dayOfMonthOrdinalParseLenient;
  4100. });
  4101. addParseToken(["D", "DD"], DATE);
  4102. addParseToken("Do", function (input, array) {
  4103. array[DATE] = toInt(input.match(match1to2)[0]);
  4104. });
  4105. // MOMENTS
  4106. var getSetDayOfMonth = makeGetSet("Date", true);
  4107. // FORMATTING
  4108. addFormatToken("DDD", ["DDDD", 3], "DDDo", "dayOfYear");
  4109. // ALIASES
  4110. addUnitAlias("dayOfYear", "DDD");
  4111. // PRIORITY
  4112. addUnitPriority("dayOfYear", 4);
  4113. // PARSING
  4114. addRegexToken("DDD", match1to3);
  4115. addRegexToken("DDDD", match3);
  4116. addParseToken(["DDD", "DDDD"], function (input, array, config) {
  4117. config._dayOfYear = toInt(input);
  4118. });
  4119. // HELPERS
  4120. // MOMENTS
  4121. function getSetDayOfYear(input) {
  4122. var dayOfYear =
  4123. Math.round(
  4124. (this.clone().startOf("day") - this.clone().startOf("year")) / 864e5
  4125. ) + 1;
  4126. return input == null ? dayOfYear : this.add(input - dayOfYear, "d");
  4127. }
  4128. // FORMATTING
  4129. addFormatToken("m", ["mm", 2], 0, "minute");
  4130. // ALIASES
  4131. addUnitAlias("minute", "m");
  4132. // PRIORITY
  4133. addUnitPriority("minute", 14);
  4134. // PARSING
  4135. addRegexToken("m", match1to2);
  4136. addRegexToken("mm", match1to2, match2);
  4137. addParseToken(["m", "mm"], MINUTE);
  4138. // MOMENTS
  4139. var getSetMinute = makeGetSet("Minutes", false);
  4140. // FORMATTING
  4141. addFormatToken("s", ["ss", 2], 0, "second");
  4142. // ALIASES
  4143. addUnitAlias("second", "s");
  4144. // PRIORITY
  4145. addUnitPriority("second", 15);
  4146. // PARSING
  4147. addRegexToken("s", match1to2);
  4148. addRegexToken("ss", match1to2, match2);
  4149. addParseToken(["s", "ss"], SECOND);
  4150. // MOMENTS
  4151. var getSetSecond = makeGetSet("Seconds", false);
  4152. // FORMATTING
  4153. addFormatToken("S", 0, 0, function () {
  4154. return ~~(this.millisecond() / 100);
  4155. });
  4156. addFormatToken(0, ["SS", 2], 0, function () {
  4157. return ~~(this.millisecond() / 10);
  4158. });
  4159. addFormatToken(0, ["SSS", 3], 0, "millisecond");
  4160. addFormatToken(0, ["SSSS", 4], 0, function () {
  4161. return this.millisecond() * 10;
  4162. });
  4163. addFormatToken(0, ["SSSSS", 5], 0, function () {
  4164. return this.millisecond() * 100;
  4165. });
  4166. addFormatToken(0, ["SSSSSS", 6], 0, function () {
  4167. return this.millisecond() * 1000;
  4168. });
  4169. addFormatToken(0, ["SSSSSSS", 7], 0, function () {
  4170. return this.millisecond() * 10000;
  4171. });
  4172. addFormatToken(0, ["SSSSSSSS", 8], 0, function () {
  4173. return this.millisecond() * 100000;
  4174. });
  4175. addFormatToken(0, ["SSSSSSSSS", 9], 0, function () {
  4176. return this.millisecond() * 1000000;
  4177. });
  4178. // ALIASES
  4179. addUnitAlias("millisecond", "ms");
  4180. // PRIORITY
  4181. addUnitPriority("millisecond", 16);
  4182. // PARSING
  4183. addRegexToken("S", match1to3, match1);
  4184. addRegexToken("SS", match1to3, match2);
  4185. addRegexToken("SSS", match1to3, match3);
  4186. var token, getSetMillisecond;
  4187. for (token = "SSSS"; token.length <= 9; token += "S") {
  4188. addRegexToken(token, matchUnsigned);
  4189. }
  4190. function parseMs(input, array) {
  4191. array[MILLISECOND] = toInt(("0." + input) * 1000);
  4192. }
  4193. for (token = "S"; token.length <= 9; token += "S") {
  4194. addParseToken(token, parseMs);
  4195. }
  4196. getSetMillisecond = makeGetSet("Milliseconds", false);
  4197. // FORMATTING
  4198. addFormatToken("z", 0, 0, "zoneAbbr");
  4199. addFormatToken("zz", 0, 0, "zoneName");
  4200. // MOMENTS
  4201. function getZoneAbbr() {
  4202. return this._isUTC ? "UTC" : "";
  4203. }
  4204. function getZoneName() {
  4205. return this._isUTC ? "Coordinated Universal Time" : "";
  4206. }
  4207. var proto = Moment.prototype;
  4208. proto.add = add;
  4209. proto.calendar = calendar$1;
  4210. proto.clone = clone;
  4211. proto.diff = diff;
  4212. proto.endOf = endOf;
  4213. proto.format = format;
  4214. proto.from = from;
  4215. proto.fromNow = fromNow;
  4216. proto.to = to;
  4217. proto.toNow = toNow;
  4218. proto.get = stringGet;
  4219. proto.invalidAt = invalidAt;
  4220. proto.isAfter = isAfter;
  4221. proto.isBefore = isBefore;
  4222. proto.isBetween = isBetween;
  4223. proto.isSame = isSame;
  4224. proto.isSameOrAfter = isSameOrAfter;
  4225. proto.isSameOrBefore = isSameOrBefore;
  4226. proto.isValid = isValid$2;
  4227. proto.lang = lang;
  4228. proto.locale = locale;
  4229. proto.localeData = localeData;
  4230. proto.max = prototypeMax;
  4231. proto.min = prototypeMin;
  4232. proto.parsingFlags = parsingFlags;
  4233. proto.set = stringSet;
  4234. proto.startOf = startOf;
  4235. proto.subtract = subtract;
  4236. proto.toArray = toArray;
  4237. proto.toObject = toObject;
  4238. proto.toDate = toDate;
  4239. proto.toISOString = toISOString;
  4240. proto.inspect = inspect;
  4241. if (typeof Symbol !== "undefined" && Symbol.for != null) {
  4242. proto[Symbol.for("nodejs.util.inspect.custom")] = function () {
  4243. return "Moment<" + this.format() + ">";
  4244. };
  4245. }
  4246. proto.toJSON = toJSON;
  4247. proto.toString = toString;
  4248. proto.unix = unix;
  4249. proto.valueOf = valueOf;
  4250. proto.creationData = creationData;
  4251. proto.eraName = getEraName;
  4252. proto.eraNarrow = getEraNarrow;
  4253. proto.eraAbbr = getEraAbbr;
  4254. proto.eraYear = getEraYear;
  4255. proto.year = getSetYear;
  4256. proto.isLeapYear = getIsLeapYear;
  4257. proto.weekYear = getSetWeekYear;
  4258. proto.isoWeekYear = getSetISOWeekYear;
  4259. proto.quarter = proto.quarters = getSetQuarter;
  4260. proto.month = getSetMonth;
  4261. proto.daysInMonth = getDaysInMonth;
  4262. proto.week = proto.weeks = getSetWeek;
  4263. proto.isoWeek = proto.isoWeeks = getSetISOWeek;
  4264. proto.weeksInYear = getWeeksInYear;
  4265. proto.weeksInWeekYear = getWeeksInWeekYear;
  4266. proto.isoWeeksInYear = getISOWeeksInYear;
  4267. proto.isoWeeksInISOWeekYear = getISOWeeksInISOWeekYear;
  4268. proto.date = getSetDayOfMonth;
  4269. proto.day = proto.days = getSetDayOfWeek;
  4270. proto.weekday = getSetLocaleDayOfWeek;
  4271. proto.isoWeekday = getSetISODayOfWeek;
  4272. proto.dayOfYear = getSetDayOfYear;
  4273. proto.hour = proto.hours = getSetHour;
  4274. proto.minute = proto.minutes = getSetMinute;
  4275. proto.second = proto.seconds = getSetSecond;
  4276. proto.millisecond = proto.milliseconds = getSetMillisecond;
  4277. proto.utcOffset = getSetOffset;
  4278. proto.utc = setOffsetToUTC;
  4279. proto.local = setOffsetToLocal;
  4280. proto.parseZone = setOffsetToParsedOffset;
  4281. proto.hasAlignedHourOffset = hasAlignedHourOffset;
  4282. proto.isDST = isDaylightSavingTime;
  4283. proto.isLocal = isLocal;
  4284. proto.isUtcOffset = isUtcOffset;
  4285. proto.isUtc = isUtc;
  4286. proto.isUTC = isUtc;
  4287. proto.zoneAbbr = getZoneAbbr;
  4288. proto.zoneName = getZoneName;
  4289. proto.dates = deprecate(
  4290. "dates accessor is deprecated. Use date instead.",
  4291. getSetDayOfMonth
  4292. );
  4293. proto.months = deprecate(
  4294. "months accessor is deprecated. Use month instead",
  4295. getSetMonth
  4296. );
  4297. proto.years = deprecate(
  4298. "years accessor is deprecated. Use year instead",
  4299. getSetYear
  4300. );
  4301. proto.zone = deprecate(
  4302. "moment().zone is deprecated, use moment().utcOffset instead. http://momentjs.com/guides/#/warnings/zone/",
  4303. getSetZone
  4304. );
  4305. proto.isDSTShifted = deprecate(
  4306. "isDSTShifted is deprecated. See http://momentjs.com/guides/#/warnings/dst-shifted/ for more information",
  4307. isDaylightSavingTimeShifted
  4308. );
  4309. function createUnix(input) {
  4310. return createLocal(input * 1000);
  4311. }
  4312. function createInZone() {
  4313. return createLocal.apply(null, arguments).parseZone();
  4314. }
  4315. function preParsePostFormat(string) {
  4316. return string;
  4317. }
  4318. var proto$1 = Locale.prototype;
  4319. proto$1.calendar = calendar;
  4320. proto$1.longDateFormat = longDateFormat;
  4321. proto$1.invalidDate = invalidDate;
  4322. proto$1.ordinal = ordinal;
  4323. proto$1.preparse = preParsePostFormat;
  4324. proto$1.postformat = preParsePostFormat;
  4325. proto$1.relativeTime = relativeTime;
  4326. proto$1.pastFuture = pastFuture;
  4327. proto$1.set = set;
  4328. proto$1.eras = localeEras;
  4329. proto$1.erasParse = localeErasParse;
  4330. proto$1.erasConvertYear = localeErasConvertYear;
  4331. proto$1.erasAbbrRegex = erasAbbrRegex;
  4332. proto$1.erasNameRegex = erasNameRegex;
  4333. proto$1.erasNarrowRegex = erasNarrowRegex;
  4334. proto$1.months = localeMonths;
  4335. proto$1.monthsShort = localeMonthsShort;
  4336. proto$1.monthsParse = localeMonthsParse;
  4337. proto$1.monthsRegex = monthsRegex;
  4338. proto$1.monthsShortRegex = monthsShortRegex;
  4339. proto$1.week = localeWeek;
  4340. proto$1.firstDayOfYear = localeFirstDayOfYear;
  4341. proto$1.firstDayOfWeek = localeFirstDayOfWeek;
  4342. proto$1.weekdays = localeWeekdays;
  4343. proto$1.weekdaysMin = localeWeekdaysMin;
  4344. proto$1.weekdaysShort = localeWeekdaysShort;
  4345. proto$1.weekdaysParse = localeWeekdaysParse;
  4346. proto$1.weekdaysRegex = weekdaysRegex;
  4347. proto$1.weekdaysShortRegex = weekdaysShortRegex;
  4348. proto$1.weekdaysMinRegex = weekdaysMinRegex;
  4349. proto$1.isPM = localeIsPM;
  4350. proto$1.meridiem = localeMeridiem;
  4351. function get$1(format, index, field, setter) {
  4352. var locale = getLocale(),
  4353. utc = createUTC().set(setter, index);
  4354. return locale[field](utc, format);
  4355. }
  4356. function listMonthsImpl(format, index, field) {
  4357. if (isNumber(format)) {
  4358. index = format;
  4359. format = undefined;
  4360. }
  4361. format = format || "";
  4362. if (index != null) {
  4363. return get$1(format, index, field, "month");
  4364. }
  4365. var i,
  4366. out = [];
  4367. for (i = 0; i < 12; i++) {
  4368. out[i] = get$1(format, i, field, "month");
  4369. }
  4370. return out;
  4371. }
  4372. // ()
  4373. // (5)
  4374. // (fmt, 5)
  4375. // (fmt)
  4376. // (true)
  4377. // (true, 5)
  4378. // (true, fmt, 5)
  4379. // (true, fmt)
  4380. function listWeekdaysImpl(localeSorted, format, index, field) {
  4381. if (typeof localeSorted === "boolean") {
  4382. if (isNumber(format)) {
  4383. index = format;
  4384. format = undefined;
  4385. }
  4386. format = format || "";
  4387. } else {
  4388. format = localeSorted;
  4389. index = format;
  4390. localeSorted = false;
  4391. if (isNumber(format)) {
  4392. index = format;
  4393. format = undefined;
  4394. }
  4395. format = format || "";
  4396. }
  4397. var locale = getLocale(),
  4398. shift = localeSorted ? locale._week.dow : 0,
  4399. i,
  4400. out = [];
  4401. if (index != null) {
  4402. return get$1(format, (index + shift) % 7, field, "day");
  4403. }
  4404. for (i = 0; i < 7; i++) {
  4405. out[i] = get$1(format, (i + shift) % 7, field, "day");
  4406. }
  4407. return out;
  4408. }
  4409. function listMonths(format, index) {
  4410. return listMonthsImpl(format, index, "months");
  4411. }
  4412. function listMonthsShort(format, index) {
  4413. return listMonthsImpl(format, index, "monthsShort");
  4414. }
  4415. function listWeekdays(localeSorted, format, index) {
  4416. return listWeekdaysImpl(localeSorted, format, index, "weekdays");
  4417. }
  4418. function listWeekdaysShort(localeSorted, format, index) {
  4419. return listWeekdaysImpl(localeSorted, format, index, "weekdaysShort");
  4420. }
  4421. function listWeekdaysMin(localeSorted, format, index) {
  4422. return listWeekdaysImpl(localeSorted, format, index, "weekdaysMin");
  4423. }
  4424. getSetGlobalLocale("en", {
  4425. eras: [
  4426. {
  4427. since: "0001-01-01",
  4428. until: +Infinity,
  4429. offset: 1,
  4430. name: "Anno Domini",
  4431. narrow: "AD",
  4432. abbr: "AD",
  4433. },
  4434. {
  4435. since: "0000-12-31",
  4436. until: -Infinity,
  4437. offset: 1,
  4438. name: "Before Christ",
  4439. narrow: "BC",
  4440. abbr: "BC",
  4441. },
  4442. ],
  4443. dayOfMonthOrdinalParse: /\d{1,2}(th|st|nd|rd)/,
  4444. ordinal: function (number) {
  4445. var b = number % 10,
  4446. output =
  4447. toInt((number % 100) / 10) === 1
  4448. ? "th"
  4449. : b === 1
  4450. ? "st"
  4451. : b === 2
  4452. ? "nd"
  4453. : b === 3
  4454. ? "rd"
  4455. : "th";
  4456. return number + output;
  4457. },
  4458. });
  4459. // Side effect imports
  4460. hooks.lang = deprecate(
  4461. "moment.lang is deprecated. Use moment.locale instead.",
  4462. getSetGlobalLocale
  4463. );
  4464. hooks.langData = deprecate(
  4465. "moment.langData is deprecated. Use moment.localeData instead.",
  4466. getLocale
  4467. );
  4468. var mathAbs = Math.abs;
  4469. function abs() {
  4470. var data = this._data;
  4471. this._milliseconds = mathAbs(this._milliseconds);
  4472. this._days = mathAbs(this._days);
  4473. this._months = mathAbs(this._months);
  4474. data.milliseconds = mathAbs(data.milliseconds);
  4475. data.seconds = mathAbs(data.seconds);
  4476. data.minutes = mathAbs(data.minutes);
  4477. data.hours = mathAbs(data.hours);
  4478. data.months = mathAbs(data.months);
  4479. data.years = mathAbs(data.years);
  4480. return this;
  4481. }
  4482. function addSubtract$1(duration, input, value, direction) {
  4483. var other = createDuration(input, value);
  4484. duration._milliseconds += direction * other._milliseconds;
  4485. duration._days += direction * other._days;
  4486. duration._months += direction * other._months;
  4487. return duration._bubble();
  4488. }
  4489. // supports only 2.0-style add(1, 's') or add(duration)
  4490. function add$1(input, value) {
  4491. return addSubtract$1(this, input, value, 1);
  4492. }
  4493. // supports only 2.0-style subtract(1, 's') or subtract(duration)
  4494. function subtract$1(input, value) {
  4495. return addSubtract$1(this, input, value, -1);
  4496. }
  4497. function absCeil(number) {
  4498. if (number < 0) {
  4499. return Math.floor(number);
  4500. } else {
  4501. return Math.ceil(number);
  4502. }
  4503. }
  4504. function bubble() {
  4505. var milliseconds = this._milliseconds,
  4506. days = this._days,
  4507. months = this._months,
  4508. data = this._data,
  4509. seconds,
  4510. minutes,
  4511. hours,
  4512. years,
  4513. monthsFromDays;
  4514. // if we have a mix of positive and negative values, bubble down first
  4515. // check: https://github.com/moment/moment/issues/2166
  4516. if (
  4517. !(
  4518. (milliseconds >= 0 && days >= 0 && months >= 0) ||
  4519. (milliseconds <= 0 && days <= 0 && months <= 0)
  4520. )
  4521. ) {
  4522. milliseconds += absCeil(monthsToDays(months) + days) * 864e5;
  4523. days = 0;
  4524. months = 0;
  4525. }
  4526. // The following code bubbles up values, see the tests for
  4527. // examples of what that means.
  4528. data.milliseconds = milliseconds % 1000;
  4529. seconds = absFloor(milliseconds / 1000);
  4530. data.seconds = seconds % 60;
  4531. minutes = absFloor(seconds / 60);
  4532. data.minutes = minutes % 60;
  4533. hours = absFloor(minutes / 60);
  4534. data.hours = hours % 24;
  4535. days += absFloor(hours / 24);
  4536. // convert days to months
  4537. monthsFromDays = absFloor(daysToMonths(days));
  4538. months += monthsFromDays;
  4539. days -= absCeil(monthsToDays(monthsFromDays));
  4540. // 12 months -> 1 year
  4541. years = absFloor(months / 12);
  4542. months %= 12;
  4543. data.days = days;
  4544. data.months = months;
  4545. data.years = years;
  4546. return this;
  4547. }
  4548. function daysToMonths(days) {
  4549. // 400 years have 146097 days (taking into account leap year rules)
  4550. // 400 years have 12 months === 4800
  4551. return (days * 4800) / 146097;
  4552. }
  4553. function monthsToDays(months) {
  4554. // the reverse of daysToMonths
  4555. return (months * 146097) / 4800;
  4556. }
  4557. function as(units) {
  4558. if (!this.isValid()) {
  4559. return NaN;
  4560. }
  4561. var days,
  4562. months,
  4563. milliseconds = this._milliseconds;
  4564. units = normalizeUnits(units);
  4565. if (units === "month" || units === "quarter" || units === "year") {
  4566. days = this._days + milliseconds / 864e5;
  4567. months = this._months + daysToMonths(days);
  4568. switch (units) {
  4569. case "month":
  4570. return months;
  4571. case "quarter":
  4572. return months / 3;
  4573. case "year":
  4574. return months / 12;
  4575. }
  4576. } else {
  4577. // handle milliseconds separately because of floating point math errors (issue #1867)
  4578. days = this._days + Math.round(monthsToDays(this._months));
  4579. switch (units) {
  4580. case "week":
  4581. return days / 7 + milliseconds / 6048e5;
  4582. case "day":
  4583. return days + milliseconds / 864e5;
  4584. case "hour":
  4585. return days * 24 + milliseconds / 36e5;
  4586. case "minute":
  4587. return days * 1440 + milliseconds / 6e4;
  4588. case "second":
  4589. return days * 86400 + milliseconds / 1000;
  4590. // Math.floor prevents floating point math errors here
  4591. case "millisecond":
  4592. return Math.floor(days * 864e5) + milliseconds;
  4593. default:
  4594. throw new Error("Unknown unit " + units);
  4595. }
  4596. }
  4597. }
  4598. // TODO: Use this.as('ms')?
  4599. function valueOf$1() {
  4600. if (!this.isValid()) {
  4601. return NaN;
  4602. }
  4603. return (
  4604. this._milliseconds +
  4605. this._days * 864e5 +
  4606. (this._months % 12) * 2592e6 +
  4607. toInt(this._months / 12) * 31536e6
  4608. );
  4609. }
  4610. function makeAs(alias) {
  4611. return function () {
  4612. return this.as(alias);
  4613. };
  4614. }
  4615. var asMilliseconds = makeAs("ms"),
  4616. asSeconds = makeAs("s"),
  4617. asMinutes = makeAs("m"),
  4618. asHours = makeAs("h"),
  4619. asDays = makeAs("d"),
  4620. asWeeks = makeAs("w"),
  4621. asMonths = makeAs("M"),
  4622. asQuarters = makeAs("Q"),
  4623. asYears = makeAs("y");
  4624. function clone$1() {
  4625. return createDuration(this);
  4626. }
  4627. function get$2(units) {
  4628. units = normalizeUnits(units);
  4629. return this.isValid() ? this[units + "s"]() : NaN;
  4630. }
  4631. function makeGetter(name) {
  4632. return function () {
  4633. return this.isValid() ? this._data[name] : NaN;
  4634. };
  4635. }
  4636. var milliseconds = makeGetter("milliseconds"),
  4637. seconds = makeGetter("seconds"),
  4638. minutes = makeGetter("minutes"),
  4639. hours = makeGetter("hours"),
  4640. days = makeGetter("days"),
  4641. months = makeGetter("months"),
  4642. years = makeGetter("years");
  4643. function weeks() {
  4644. return absFloor(this.days() / 7);
  4645. }
  4646. var round = Math.round,
  4647. thresholds = {
  4648. ss: 44, // a few seconds to seconds
  4649. s: 45, // seconds to minute
  4650. m: 45, // minutes to hour
  4651. h: 22, // hours to day
  4652. d: 26, // days to month/week
  4653. w: null, // weeks to month
  4654. M: 11, // months to year
  4655. };
  4656. // helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize
  4657. function substituteTimeAgo(string, number, withoutSuffix, isFuture, locale) {
  4658. return locale.relativeTime(number || 1, !!withoutSuffix, string, isFuture);
  4659. }
  4660. function relativeTime$1(posNegDuration, withoutSuffix, thresholds, locale) {
  4661. var duration = createDuration(posNegDuration).abs(),
  4662. seconds = round(duration.as("s")),
  4663. minutes = round(duration.as("m")),
  4664. hours = round(duration.as("h")),
  4665. days = round(duration.as("d")),
  4666. months = round(duration.as("M")),
  4667. weeks = round(duration.as("w")),
  4668. years = round(duration.as("y")),
  4669. a =
  4670. (seconds <= thresholds.ss && ["s", seconds]) ||
  4671. (seconds < thresholds.s && ["ss", seconds]) ||
  4672. (minutes <= 1 && ["m"]) ||
  4673. (minutes < thresholds.m && ["mm", minutes]) ||
  4674. (hours <= 1 && ["h"]) ||
  4675. (hours < thresholds.h && ["hh", hours]) ||
  4676. (days <= 1 && ["d"]) ||
  4677. (days < thresholds.d && ["dd", days]);
  4678. if (thresholds.w != null) {
  4679. a = a || (weeks <= 1 && ["w"]) || (weeks < thresholds.w && ["ww", weeks]);
  4680. }
  4681. a = a ||
  4682. (months <= 1 && ["M"]) ||
  4683. (months < thresholds.M && ["MM", months]) ||
  4684. (years <= 1 && ["y"]) || ["yy", years];
  4685. a[2] = withoutSuffix;
  4686. a[3] = +posNegDuration > 0;
  4687. a[4] = locale;
  4688. return substituteTimeAgo.apply(null, a);
  4689. }
  4690. // This function allows you to set the rounding function for relative time strings
  4691. function getSetRelativeTimeRounding(roundingFunction) {
  4692. if (roundingFunction === undefined) {
  4693. return round;
  4694. }
  4695. if (typeof roundingFunction === "function") {
  4696. round = roundingFunction;
  4697. return true;
  4698. }
  4699. return false;
  4700. }
  4701. // This function allows you to set a threshold for relative time strings
  4702. function getSetRelativeTimeThreshold(threshold, limit) {
  4703. if (thresholds[threshold] === undefined) {
  4704. return false;
  4705. }
  4706. if (limit === undefined) {
  4707. return thresholds[threshold];
  4708. }
  4709. thresholds[threshold] = limit;
  4710. if (threshold === "s") {
  4711. thresholds.ss = limit - 1;
  4712. }
  4713. return true;
  4714. }
  4715. function humanize(argWithSuffix, argThresholds) {
  4716. if (!this.isValid()) {
  4717. return this.localeData().invalidDate();
  4718. }
  4719. var withSuffix = false,
  4720. th = thresholds,
  4721. locale,
  4722. output;
  4723. if (typeof argWithSuffix === "object") {
  4724. argThresholds = argWithSuffix;
  4725. argWithSuffix = false;
  4726. }
  4727. if (typeof argWithSuffix === "boolean") {
  4728. withSuffix = argWithSuffix;
  4729. }
  4730. if (typeof argThresholds === "object") {
  4731. th = Object.assign({}, thresholds, argThresholds);
  4732. if (argThresholds.s != null && argThresholds.ss == null) {
  4733. th.ss = argThresholds.s - 1;
  4734. }
  4735. }
  4736. locale = this.localeData();
  4737. output = relativeTime$1(this, !withSuffix, th, locale);
  4738. if (withSuffix) {
  4739. output = locale.pastFuture(+this, output);
  4740. }
  4741. return locale.postformat(output);
  4742. }
  4743. var abs$1 = Math.abs;
  4744. function sign(x) {
  4745. return (x > 0) - (x < 0) || +x;
  4746. }
  4747. function toISOString$1() {
  4748. // for ISO strings we do not use the normal bubbling rules:
  4749. // * milliseconds bubble up until they become hours
  4750. // * days do not bubble at all
  4751. // * months bubble up until they become years
  4752. // This is because there is no context-free conversion between hours and days
  4753. // (think of clock changes)
  4754. // and also not between days and months (28-31 days per month)
  4755. if (!this.isValid()) {
  4756. return this.localeData().invalidDate();
  4757. }
  4758. var seconds = abs$1(this._milliseconds) / 1000,
  4759. days = abs$1(this._days),
  4760. months = abs$1(this._months),
  4761. minutes,
  4762. hours,
  4763. years,
  4764. s,
  4765. total = this.asSeconds(),
  4766. totalSign,
  4767. ymSign,
  4768. daysSign,
  4769. hmsSign;
  4770. if (!total) {
  4771. // this is the same as C#'s (Noda) and python (isodate)...
  4772. // but not other JS (goog.date)
  4773. return "P0D";
  4774. }
  4775. // 3600 seconds -> 60 minutes -> 1 hour
  4776. minutes = absFloor(seconds / 60);
  4777. hours = absFloor(minutes / 60);
  4778. seconds %= 60;
  4779. minutes %= 60;
  4780. // 12 months -> 1 year
  4781. years = absFloor(months / 12);
  4782. months %= 12;
  4783. // inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js
  4784. s = seconds ? seconds.toFixed(3).replace(/\.?0+$/, "") : "";
  4785. totalSign = total < 0 ? "-" : "";
  4786. ymSign = sign(this._months) !== sign(total) ? "-" : "";
  4787. daysSign = sign(this._days) !== sign(total) ? "-" : "";
  4788. hmsSign = sign(this._milliseconds) !== sign(total) ? "-" : "";
  4789. return (
  4790. totalSign +
  4791. "P" +
  4792. (years ? ymSign + years + "Y" : "") +
  4793. (months ? ymSign + months + "M" : "") +
  4794. (days ? daysSign + days + "D" : "") +
  4795. (hours || minutes || seconds ? "T" : "") +
  4796. (hours ? hmsSign + hours + "H" : "") +
  4797. (minutes ? hmsSign + minutes + "M" : "") +
  4798. (seconds ? hmsSign + s + "S" : "")
  4799. );
  4800. }
  4801. var proto$2 = Duration.prototype;
  4802. proto$2.isValid = isValid$1;
  4803. proto$2.abs = abs;
  4804. proto$2.add = add$1;
  4805. proto$2.subtract = subtract$1;
  4806. proto$2.as = as;
  4807. proto$2.asMilliseconds = asMilliseconds;
  4808. proto$2.asSeconds = asSeconds;
  4809. proto$2.asMinutes = asMinutes;
  4810. proto$2.asHours = asHours;
  4811. proto$2.asDays = asDays;
  4812. proto$2.asWeeks = asWeeks;
  4813. proto$2.asMonths = asMonths;
  4814. proto$2.asQuarters = asQuarters;
  4815. proto$2.asYears = asYears;
  4816. proto$2.valueOf = valueOf$1;
  4817. proto$2._bubble = bubble;
  4818. proto$2.clone = clone$1;
  4819. proto$2.get = get$2;
  4820. proto$2.milliseconds = milliseconds;
  4821. proto$2.seconds = seconds;
  4822. proto$2.minutes = minutes;
  4823. proto$2.hours = hours;
  4824. proto$2.days = days;
  4825. proto$2.weeks = weeks;
  4826. proto$2.months = months;
  4827. proto$2.years = years;
  4828. proto$2.humanize = humanize;
  4829. proto$2.toISOString = toISOString$1;
  4830. proto$2.toString = toISOString$1;
  4831. proto$2.toJSON = toISOString$1;
  4832. proto$2.locale = locale;
  4833. proto$2.localeData = localeData;
  4834. proto$2.toIsoString = deprecate(
  4835. "toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)",
  4836. toISOString$1
  4837. );
  4838. proto$2.lang = lang;
  4839. // FORMATTING
  4840. addFormatToken("X", 0, 0, "unix");
  4841. addFormatToken("x", 0, 0, "valueOf");
  4842. // PARSING
  4843. addRegexToken("x", matchSigned);
  4844. addRegexToken("X", matchTimestamp);
  4845. addParseToken("X", function (input, array, config) {
  4846. config._d = new Date(parseFloat(input) * 1000);
  4847. });
  4848. addParseToken("x", function (input, array, config) {
  4849. config._d = new Date(toInt(input));
  4850. });
  4851. //! moment.js
  4852. hooks.version = "2.29.4";
  4853. setHookCallback(createLocal);
  4854. hooks.fn = proto;
  4855. hooks.min = min;
  4856. hooks.max = max;
  4857. hooks.now = now;
  4858. hooks.utc = createUTC;
  4859. hooks.unix = createUnix;
  4860. hooks.months = listMonths;
  4861. hooks.isDate = isDate;
  4862. hooks.locale = getSetGlobalLocale;
  4863. hooks.invalid = createInvalid;
  4864. hooks.duration = createDuration;
  4865. hooks.isMoment = isMoment;
  4866. hooks.weekdays = listWeekdays;
  4867. hooks.parseZone = createInZone;
  4868. hooks.localeData = getLocale;
  4869. hooks.isDuration = isDuration;
  4870. hooks.monthsShort = listMonthsShort;
  4871. hooks.weekdaysMin = listWeekdaysMin;
  4872. hooks.defineLocale = defineLocale;
  4873. hooks.updateLocale = updateLocale;
  4874. hooks.locales = listLocales;
  4875. hooks.weekdaysShort = listWeekdaysShort;
  4876. hooks.normalizeUnits = normalizeUnits;
  4877. hooks.relativeTimeRounding = getSetRelativeTimeRounding;
  4878. hooks.relativeTimeThreshold = getSetRelativeTimeThreshold;
  4879. hooks.calendarFormat = getCalendarFormat;
  4880. hooks.prototype = proto;
  4881. // currently HTML5 input type only supports 24-hour formats
  4882. hooks.HTML5_FMT = {
  4883. DATETIME_LOCAL: "YYYY-MM-DDTHH:mm", // <input type="datetime-local" />
  4884. DATETIME_LOCAL_SECONDS: "YYYY-MM-DDTHH:mm:ss", // <input type="datetime-local" step="1" />
  4885. DATETIME_LOCAL_MS: "YYYY-MM-DDTHH:mm:ss.SSS", // <input type="datetime-local" step="0.001" />
  4886. DATE: "YYYY-MM-DD", // <input type="date" />
  4887. TIME: "HH:mm", // <input type="time" />
  4888. TIME_SECONDS: "HH:mm:ss", // <input type="time" step="1" />
  4889. TIME_MS: "HH:mm:ss.SSS", // <input type="time" step="0.001" />
  4890. WEEK: "GGGG-[W]WW", // <input type="week" />
  4891. MONTH: "YYYY-MM", // <input type="month" />
  4892. };
  4893. return hooks;
  4894. });