Няма описание

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