moment.js 140 KB

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