moment.js 172 KB

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