vue-moment.js 153 KB

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