moment.js 116 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606
  1. //! moment.js
  2. //! version : 2.11.2
  3. //! authors : Tim Wood, Iskren Chernev, Moment.js contributors
  4. //! license : MIT
  5. //! momentjs.com
  6. ;(function (global, factory) {
  7. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  8. typeof define === 'function' && define.amd ? define(factory) :
  9. global.moment = factory()
  10. }(this, function () { 'use strict';
  11. var hookCallback;
  12. function utils_hooks__hooks () {
  13. return hookCallback.apply(null, arguments);
  14. }
  15. // This is done to register the method called with moment()
  16. // without creating circular dependencies.
  17. function setHookCallback (callback) {
  18. hookCallback = callback;
  19. }
  20. function isArray(input) {
  21. return Object.prototype.toString.call(input) === '[object Array]';
  22. }
  23. function isDate(input) {
  24. return input instanceof Date || Object.prototype.toString.call(input) === '[object Date]';
  25. }
  26. function map(arr, fn) {
  27. var res = [], i;
  28. for (i = 0; i < arr.length; ++i) {
  29. res.push(fn(arr[i], i));
  30. }
  31. return res;
  32. }
  33. function hasOwnProp(a, b) {
  34. return Object.prototype.hasOwnProperty.call(a, b);
  35. }
  36. function extend(a, b) {
  37. for (var i in b) {
  38. if (hasOwnProp(b, i)) {
  39. a[i] = b[i];
  40. }
  41. }
  42. if (hasOwnProp(b, 'toString')) {
  43. a.toString = b.toString;
  44. }
  45. if (hasOwnProp(b, 'valueOf')) {
  46. a.valueOf = b.valueOf;
  47. }
  48. return a;
  49. }
  50. function create_utc__createUTC (input, format, locale, strict) {
  51. return createLocalOrUTC(input, format, locale, strict, true).utc();
  52. }
  53. function defaultParsingFlags() {
  54. // We need to deep clone this object.
  55. return {
  56. empty : false,
  57. unusedTokens : [],
  58. unusedInput : [],
  59. overflow : -2,
  60. charsLeftOver : 0,
  61. nullInput : false,
  62. invalidMonth : null,
  63. invalidFormat : false,
  64. userInvalidated : false,
  65. iso : false
  66. };
  67. }
  68. function getParsingFlags(m) {
  69. if (m._pf == null) {
  70. m._pf = defaultParsingFlags();
  71. }
  72. return m._pf;
  73. }
  74. function valid__isValid(m) {
  75. if (m._isValid == null) {
  76. var flags = getParsingFlags(m);
  77. m._isValid = !isNaN(m._d.getTime()) &&
  78. flags.overflow < 0 &&
  79. !flags.empty &&
  80. !flags.invalidMonth &&
  81. !flags.invalidWeekday &&
  82. !flags.nullInput &&
  83. !flags.invalidFormat &&
  84. !flags.userInvalidated;
  85. if (m._strict) {
  86. m._isValid = m._isValid &&
  87. flags.charsLeftOver === 0 &&
  88. flags.unusedTokens.length === 0 &&
  89. flags.bigHour === undefined;
  90. }
  91. }
  92. return m._isValid;
  93. }
  94. function valid__createInvalid (flags) {
  95. var m = create_utc__createUTC(NaN);
  96. if (flags != null) {
  97. extend(getParsingFlags(m), flags);
  98. }
  99. else {
  100. getParsingFlags(m).userInvalidated = true;
  101. }
  102. return m;
  103. }
  104. function isUndefined(input) {
  105. return input === void 0;
  106. }
  107. // Plugins that add properties should also add the key here (null value),
  108. // so we can properly clone ourselves.
  109. var momentProperties = utils_hooks__hooks.momentProperties = [];
  110. function copyConfig(to, from) {
  111. var i, prop, val;
  112. if (!isUndefined(from._isAMomentObject)) {
  113. to._isAMomentObject = from._isAMomentObject;
  114. }
  115. if (!isUndefined(from._i)) {
  116. to._i = from._i;
  117. }
  118. if (!isUndefined(from._f)) {
  119. to._f = from._f;
  120. }
  121. if (!isUndefined(from._l)) {
  122. to._l = from._l;
  123. }
  124. if (!isUndefined(from._strict)) {
  125. to._strict = from._strict;
  126. }
  127. if (!isUndefined(from._tzm)) {
  128. to._tzm = from._tzm;
  129. }
  130. if (!isUndefined(from._isUTC)) {
  131. to._isUTC = from._isUTC;
  132. }
  133. if (!isUndefined(from._offset)) {
  134. to._offset = from._offset;
  135. }
  136. if (!isUndefined(from._pf)) {
  137. to._pf = getParsingFlags(from);
  138. }
  139. if (!isUndefined(from._locale)) {
  140. to._locale = from._locale;
  141. }
  142. if (momentProperties.length > 0) {
  143. for (i in momentProperties) {
  144. prop = momentProperties[i];
  145. val = from[prop];
  146. if (!isUndefined(val)) {
  147. to[prop] = val;
  148. }
  149. }
  150. }
  151. return to;
  152. }
  153. var updateInProgress = false;
  154. // Moment prototype object
  155. function Moment(config) {
  156. copyConfig(this, config);
  157. this._d = new Date(config._d != null ? config._d.getTime() : NaN);
  158. // Prevent infinite loop in case updateOffset creates new moment
  159. // objects.
  160. if (updateInProgress === false) {
  161. updateInProgress = true;
  162. utils_hooks__hooks.updateOffset(this);
  163. updateInProgress = false;
  164. }
  165. }
  166. function isMoment (obj) {
  167. return obj instanceof Moment || (obj != null && obj._isAMomentObject != null);
  168. }
  169. function absFloor (number) {
  170. if (number < 0) {
  171. return Math.ceil(number);
  172. } else {
  173. return Math.floor(number);
  174. }
  175. }
  176. function toInt(argumentForCoercion) {
  177. var coercedNumber = +argumentForCoercion,
  178. value = 0;
  179. if (coercedNumber !== 0 && isFinite(coercedNumber)) {
  180. value = absFloor(coercedNumber);
  181. }
  182. return value;
  183. }
  184. // compare two arrays, return the number of differences
  185. function compareArrays(array1, array2, dontConvert) {
  186. var len = Math.min(array1.length, array2.length),
  187. lengthDiff = Math.abs(array1.length - array2.length),
  188. diffs = 0,
  189. i;
  190. for (i = 0; i < len; i++) {
  191. if ((dontConvert && array1[i] !== array2[i]) ||
  192. (!dontConvert && toInt(array1[i]) !== toInt(array2[i]))) {
  193. diffs++;
  194. }
  195. }
  196. return diffs + lengthDiff;
  197. }
  198. function Locale() {
  199. }
  200. // internal storage for locale config files
  201. var locales = {};
  202. var globalLocale;
  203. function normalizeLocale(key) {
  204. return key ? key.toLowerCase().replace('_', '-') : key;
  205. }
  206. // pick the locale from the array
  207. // try ['en-au', 'en-gb'] as 'en-au', 'en-gb', 'en', as in move through the list trying each
  208. // substring from most specific to least, but move to the next array item if it's a more specific variant than the current root
  209. function chooseLocale(names) {
  210. var i = 0, j, next, locale, split;
  211. while (i < names.length) {
  212. split = normalizeLocale(names[i]).split('-');
  213. j = split.length;
  214. next = normalizeLocale(names[i + 1]);
  215. next = next ? next.split('-') : null;
  216. while (j > 0) {
  217. locale = loadLocale(split.slice(0, j).join('-'));
  218. if (locale) {
  219. return locale;
  220. }
  221. if (next && next.length >= j && compareArrays(split, next, true) >= j - 1) {
  222. //the next array item is better than a shallower substring of this one
  223. break;
  224. }
  225. j--;
  226. }
  227. i++;
  228. }
  229. return null;
  230. }
  231. function loadLocale(name) {
  232. var oldLocale = null;
  233. // TODO: Find a better way to register and load all the locales in Node
  234. if (!locales[name] && (typeof module !== 'undefined') &&
  235. module && module.exports) {
  236. try {
  237. oldLocale = globalLocale._abbr;
  238. require('./locale/' + name);
  239. // because defineLocale currently also sets the global locale, we
  240. // want to undo that for lazy loaded locales
  241. locale_locales__getSetGlobalLocale(oldLocale);
  242. } catch (e) { }
  243. }
  244. return locales[name];
  245. }
  246. // This function will load locale and then set the global locale. If
  247. // no arguments are passed in, it will simply return the current global
  248. // locale key.
  249. function locale_locales__getSetGlobalLocale (key, values) {
  250. var data;
  251. if (key) {
  252. if (isUndefined(values)) {
  253. data = locale_locales__getLocale(key);
  254. }
  255. else {
  256. data = defineLocale(key, values);
  257. }
  258. if (data) {
  259. // moment.duration._locale = moment._locale = data;
  260. globalLocale = data;
  261. }
  262. }
  263. return globalLocale._abbr;
  264. }
  265. function defineLocale (name, values) {
  266. if (values !== null) {
  267. values.abbr = name;
  268. locales[name] = locales[name] || new Locale();
  269. locales[name].set(values);
  270. // backwards compat for now: also set the locale
  271. locale_locales__getSetGlobalLocale(name);
  272. return locales[name];
  273. } else {
  274. // useful for testing
  275. delete locales[name];
  276. return null;
  277. }
  278. }
  279. // returns locale data
  280. function locale_locales__getLocale (key) {
  281. var locale;
  282. if (key && key._locale && key._locale._abbr) {
  283. key = key._locale._abbr;
  284. }
  285. if (!key) {
  286. return globalLocale;
  287. }
  288. if (!isArray(key)) {
  289. //short-circuit everything else
  290. locale = loadLocale(key);
  291. if (locale) {
  292. return locale;
  293. }
  294. key = [key];
  295. }
  296. return chooseLocale(key);
  297. }
  298. var aliases = {};
  299. function addUnitAlias (unit, shorthand) {
  300. var lowerCase = unit.toLowerCase();
  301. aliases[lowerCase] = aliases[lowerCase + 's'] = aliases[shorthand] = unit;
  302. }
  303. function normalizeUnits(units) {
  304. return typeof units === 'string' ? aliases[units] || aliases[units.toLowerCase()] : undefined;
  305. }
  306. function normalizeObjectUnits(inputObject) {
  307. var normalizedInput = {},
  308. normalizedProp,
  309. prop;
  310. for (prop in inputObject) {
  311. if (hasOwnProp(inputObject, prop)) {
  312. normalizedProp = normalizeUnits(prop);
  313. if (normalizedProp) {
  314. normalizedInput[normalizedProp] = inputObject[prop];
  315. }
  316. }
  317. }
  318. return normalizedInput;
  319. }
  320. function isFunction(input) {
  321. return input instanceof Function || Object.prototype.toString.call(input) === '[object Function]';
  322. }
  323. function makeGetSet (unit, keepTime) {
  324. return function (value) {
  325. if (value != null) {
  326. get_set__set(this, unit, value);
  327. utils_hooks__hooks.updateOffset(this, keepTime);
  328. return this;
  329. } else {
  330. return get_set__get(this, unit);
  331. }
  332. };
  333. }
  334. function get_set__get (mom, unit) {
  335. return mom.isValid() ?
  336. mom._d['get' + (mom._isUTC ? 'UTC' : '') + unit]() : NaN;
  337. }
  338. function get_set__set (mom, unit, value) {
  339. if (mom.isValid()) {
  340. mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value);
  341. }
  342. }
  343. // MOMENTS
  344. function getSet (units, value) {
  345. var unit;
  346. if (typeof units === 'object') {
  347. for (unit in units) {
  348. this.set(unit, units[unit]);
  349. }
  350. } else {
  351. units = normalizeUnits(units);
  352. if (isFunction(this[units])) {
  353. return this[units](value);
  354. }
  355. }
  356. return this;
  357. }
  358. function zeroFill(number, targetLength, forceSign) {
  359. var absNumber = '' + Math.abs(number),
  360. zerosToFill = targetLength - absNumber.length,
  361. sign = number >= 0;
  362. return (sign ? (forceSign ? '+' : '') : '-') +
  363. Math.pow(10, Math.max(0, zerosToFill)).toString().substr(1) + absNumber;
  364. }
  365. 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?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g;
  366. var localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g;
  367. var formatFunctions = {};
  368. var formatTokenFunctions = {};
  369. // token: 'M'
  370. // padded: ['MM', 2]
  371. // ordinal: 'Mo'
  372. // callback: function () { this.month() + 1 }
  373. function addFormatToken (token, padded, ordinal, callback) {
  374. var func = callback;
  375. if (typeof callback === 'string') {
  376. func = function () {
  377. return this[callback]();
  378. };
  379. }
  380. if (token) {
  381. formatTokenFunctions[token] = func;
  382. }
  383. if (padded) {
  384. formatTokenFunctions[padded[0]] = function () {
  385. return zeroFill(func.apply(this, arguments), padded[1], padded[2]);
  386. };
  387. }
  388. if (ordinal) {
  389. formatTokenFunctions[ordinal] = function () {
  390. return this.localeData().ordinal(func.apply(this, arguments), token);
  391. };
  392. }
  393. }
  394. function removeFormattingTokens(input) {
  395. if (input.match(/\[[\s\S]/)) {
  396. return input.replace(/^\[|\]$/g, '');
  397. }
  398. return input.replace(/\\/g, '');
  399. }
  400. function makeFormatFunction(format) {
  401. var array = format.match(formattingTokens), i, length;
  402. for (i = 0, length = array.length; i < length; i++) {
  403. if (formatTokenFunctions[array[i]]) {
  404. array[i] = formatTokenFunctions[array[i]];
  405. } else {
  406. array[i] = removeFormattingTokens(array[i]);
  407. }
  408. }
  409. return function (mom) {
  410. var output = '';
  411. for (i = 0; i < length; i++) {
  412. output += array[i] instanceof Function ? array[i].call(mom, format) : array[i];
  413. }
  414. return output;
  415. };
  416. }
  417. // format date using native date object
  418. function formatMoment(m, format) {
  419. if (!m.isValid()) {
  420. return m.localeData().invalidDate();
  421. }
  422. format = expandFormat(format, m.localeData());
  423. formatFunctions[format] = formatFunctions[format] || makeFormatFunction(format);
  424. return formatFunctions[format](m);
  425. }
  426. function expandFormat(format, locale) {
  427. var i = 5;
  428. function replaceLongDateFormatTokens(input) {
  429. return locale.longDateFormat(input) || input;
  430. }
  431. localFormattingTokens.lastIndex = 0;
  432. while (i >= 0 && localFormattingTokens.test(format)) {
  433. format = format.replace(localFormattingTokens, replaceLongDateFormatTokens);
  434. localFormattingTokens.lastIndex = 0;
  435. i -= 1;
  436. }
  437. return format;
  438. }
  439. var match1 = /\d/; // 0 - 9
  440. var match2 = /\d\d/; // 00 - 99
  441. var match3 = /\d{3}/; // 000 - 999
  442. var match4 = /\d{4}/; // 0000 - 9999
  443. var match6 = /[+-]?\d{6}/; // -999999 - 999999
  444. var match1to2 = /\d\d?/; // 0 - 99
  445. var match3to4 = /\d\d\d\d?/; // 999 - 9999
  446. var match5to6 = /\d\d\d\d\d\d?/; // 99999 - 999999
  447. var match1to3 = /\d{1,3}/; // 0 - 999
  448. var match1to4 = /\d{1,4}/; // 0 - 9999
  449. var match1to6 = /[+-]?\d{1,6}/; // -999999 - 999999
  450. var matchUnsigned = /\d+/; // 0 - inf
  451. var matchSigned = /[+-]?\d+/; // -inf - inf
  452. var matchOffset = /Z|[+-]\d\d:?\d\d/gi; // +00:00 -00:00 +0000 -0000 or Z
  453. var matchShortOffset = /Z|[+-]\d\d(?::?\d\d)?/gi; // +00 -00 +00:00 -00:00 +0000 -0000 or Z
  454. var matchTimestamp = /[+-]?\d+(\.\d{1,3})?/; // 123456789 123456789.123
  455. // any word (or two) characters or numbers including two/three word month in arabic.
  456. // includes scottish gaelic two word and hyphenated months
  457. var matchWord = /[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i;
  458. var regexes = {};
  459. function addRegexToken (token, regex, strictRegex) {
  460. regexes[token] = isFunction(regex) ? regex : function (isStrict, localeData) {
  461. return (isStrict && strictRegex) ? strictRegex : regex;
  462. };
  463. }
  464. function getParseRegexForToken (token, config) {
  465. if (!hasOwnProp(regexes, token)) {
  466. return new RegExp(unescapeFormat(token));
  467. }
  468. return regexes[token](config._strict, config._locale);
  469. }
  470. // Code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
  471. function unescapeFormat(s) {
  472. return regexEscape(s.replace('\\', '').replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, function (matched, p1, p2, p3, p4) {
  473. return p1 || p2 || p3 || p4;
  474. }));
  475. }
  476. function regexEscape(s) {
  477. return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
  478. }
  479. var tokens = {};
  480. function addParseToken (token, callback) {
  481. var i, func = callback;
  482. if (typeof token === 'string') {
  483. token = [token];
  484. }
  485. if (typeof callback === 'number') {
  486. func = function (input, array) {
  487. array[callback] = toInt(input);
  488. };
  489. }
  490. for (i = 0; i < token.length; i++) {
  491. tokens[token[i]] = func;
  492. }
  493. }
  494. function addWeekParseToken (token, callback) {
  495. addParseToken(token, function (input, array, config, token) {
  496. config._w = config._w || {};
  497. callback(input, config._w, config, token);
  498. });
  499. }
  500. function addTimeToArrayFromToken(token, input, config) {
  501. if (input != null && hasOwnProp(tokens, token)) {
  502. tokens[token](input, config._a, config, token);
  503. }
  504. }
  505. var YEAR = 0;
  506. var MONTH = 1;
  507. var DATE = 2;
  508. var HOUR = 3;
  509. var MINUTE = 4;
  510. var SECOND = 5;
  511. var MILLISECOND = 6;
  512. var WEEK = 7;
  513. var WEEKDAY = 8;
  514. function daysInMonth(year, month) {
  515. return new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
  516. }
  517. // FORMATTING
  518. addFormatToken('M', ['MM', 2], 'Mo', function () {
  519. return this.month() + 1;
  520. });
  521. addFormatToken('MMM', 0, 0, function (format) {
  522. return this.localeData().monthsShort(this, format);
  523. });
  524. addFormatToken('MMMM', 0, 0, function (format) {
  525. return this.localeData().months(this, format);
  526. });
  527. // ALIASES
  528. addUnitAlias('month', 'M');
  529. // PARSING
  530. addRegexToken('M', match1to2);
  531. addRegexToken('MM', match1to2, match2);
  532. addRegexToken('MMM', function (isStrict, locale) {
  533. return locale.monthsShortRegex(isStrict);
  534. });
  535. addRegexToken('MMMM', function (isStrict, locale) {
  536. return locale.monthsRegex(isStrict);
  537. });
  538. addParseToken(['M', 'MM'], function (input, array) {
  539. array[MONTH] = toInt(input) - 1;
  540. });
  541. addParseToken(['MMM', 'MMMM'], function (input, array, config, token) {
  542. var month = config._locale.monthsParse(input, token, config._strict);
  543. // if we didn't find a month name, mark the date as invalid.
  544. if (month != null) {
  545. array[MONTH] = month;
  546. } else {
  547. getParsingFlags(config).invalidMonth = input;
  548. }
  549. });
  550. // LOCALES
  551. var MONTHS_IN_FORMAT = /D[oD]?(\[[^\[\]]*\]|\s+)+MMMM?/;
  552. var defaultLocaleMonths = 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_');
  553. function localeMonths (m, format) {
  554. return isArray(this._months) ? this._months[m.month()] :
  555. this._months[MONTHS_IN_FORMAT.test(format) ? 'format' : 'standalone'][m.month()];
  556. }
  557. var defaultLocaleMonthsShort = 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_');
  558. function localeMonthsShort (m, format) {
  559. return isArray(this._monthsShort) ? this._monthsShort[m.month()] :
  560. this._monthsShort[MONTHS_IN_FORMAT.test(format) ? 'format' : 'standalone'][m.month()];
  561. }
  562. function localeMonthsParse (monthName, format, strict) {
  563. var i, mom, regex;
  564. if (!this._monthsParse) {
  565. this._monthsParse = [];
  566. this._longMonthsParse = [];
  567. this._shortMonthsParse = [];
  568. }
  569. for (i = 0; i < 12; i++) {
  570. // make the regex if we don't have it already
  571. mom = create_utc__createUTC([2000, i]);
  572. if (strict && !this._longMonthsParse[i]) {
  573. this._longMonthsParse[i] = new RegExp('^' + this.months(mom, '').replace('.', '') + '$', 'i');
  574. this._shortMonthsParse[i] = new RegExp('^' + this.monthsShort(mom, '').replace('.', '') + '$', 'i');
  575. }
  576. if (!strict && !this._monthsParse[i]) {
  577. regex = '^' + this.months(mom, '') + '|^' + this.monthsShort(mom, '');
  578. this._monthsParse[i] = new RegExp(regex.replace('.', ''), 'i');
  579. }
  580. // test the regex
  581. if (strict && format === 'MMMM' && this._longMonthsParse[i].test(monthName)) {
  582. return i;
  583. } else if (strict && format === 'MMM' && this._shortMonthsParse[i].test(monthName)) {
  584. return i;
  585. } else if (!strict && this._monthsParse[i].test(monthName)) {
  586. return i;
  587. }
  588. }
  589. }
  590. // MOMENTS
  591. function setMonth (mom, value) {
  592. var dayOfMonth;
  593. if (!mom.isValid()) {
  594. // No op
  595. return mom;
  596. }
  597. // TODO: Move this out of here!
  598. if (typeof value === 'string') {
  599. value = mom.localeData().monthsParse(value);
  600. // TODO: Another silent failure?
  601. if (typeof value !== 'number') {
  602. return mom;
  603. }
  604. }
  605. dayOfMonth = Math.min(mom.date(), daysInMonth(mom.year(), value));
  606. mom._d['set' + (mom._isUTC ? 'UTC' : '') + 'Month'](value, dayOfMonth);
  607. return mom;
  608. }
  609. function getSetMonth (value) {
  610. if (value != null) {
  611. setMonth(this, value);
  612. utils_hooks__hooks.updateOffset(this, true);
  613. return this;
  614. } else {
  615. return get_set__get(this, 'Month');
  616. }
  617. }
  618. function getDaysInMonth () {
  619. return daysInMonth(this.year(), this.month());
  620. }
  621. var defaultMonthsShortRegex = matchWord;
  622. function monthsShortRegex (isStrict) {
  623. if (this._monthsParseExact) {
  624. if (!hasOwnProp(this, '_monthsRegex')) {
  625. computeMonthsParse.call(this);
  626. }
  627. if (isStrict) {
  628. return this._monthsShortStrictRegex;
  629. } else {
  630. return this._monthsShortRegex;
  631. }
  632. } else {
  633. return this._monthsShortStrictRegex && isStrict ?
  634. this._monthsShortStrictRegex : this._monthsShortRegex;
  635. }
  636. }
  637. var defaultMonthsRegex = matchWord;
  638. function monthsRegex (isStrict) {
  639. if (this._monthsParseExact) {
  640. if (!hasOwnProp(this, '_monthsRegex')) {
  641. computeMonthsParse.call(this);
  642. }
  643. if (isStrict) {
  644. return this._monthsStrictRegex;
  645. } else {
  646. return this._monthsRegex;
  647. }
  648. } else {
  649. return this._monthsStrictRegex && isStrict ?
  650. this._monthsStrictRegex : this._monthsRegex;
  651. }
  652. }
  653. function computeMonthsParse () {
  654. function cmpLenRev(a, b) {
  655. return b.length - a.length;
  656. }
  657. var shortPieces = [], longPieces = [], mixedPieces = [],
  658. i, mom;
  659. for (i = 0; i < 12; i++) {
  660. // make the regex if we don't have it already
  661. mom = create_utc__createUTC([2000, i]);
  662. shortPieces.push(this.monthsShort(mom, ''));
  663. longPieces.push(this.months(mom, ''));
  664. mixedPieces.push(this.months(mom, ''));
  665. mixedPieces.push(this.monthsShort(mom, ''));
  666. }
  667. // Sorting makes sure if one month (or abbr) is a prefix of another it
  668. // will match the longer piece.
  669. shortPieces.sort(cmpLenRev);
  670. longPieces.sort(cmpLenRev);
  671. mixedPieces.sort(cmpLenRev);
  672. for (i = 0; i < 12; i++) {
  673. shortPieces[i] = regexEscape(shortPieces[i]);
  674. longPieces[i] = regexEscape(longPieces[i]);
  675. mixedPieces[i] = regexEscape(mixedPieces[i]);
  676. }
  677. this._monthsRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i');
  678. this._monthsShortRegex = this._monthsRegex;
  679. this._monthsStrictRegex = new RegExp('^(' + longPieces.join('|') + ')$', 'i');
  680. this._monthsShortStrictRegex = new RegExp('^(' + shortPieces.join('|') + ')$', 'i');
  681. }
  682. function checkOverflow (m) {
  683. var overflow;
  684. var a = m._a;
  685. if (a && getParsingFlags(m).overflow === -2) {
  686. overflow =
  687. a[MONTH] < 0 || a[MONTH] > 11 ? MONTH :
  688. a[DATE] < 1 || a[DATE] > daysInMonth(a[YEAR], a[MONTH]) ? DATE :
  689. a[HOUR] < 0 || a[HOUR] > 24 || (a[HOUR] === 24 && (a[MINUTE] !== 0 || a[SECOND] !== 0 || a[MILLISECOND] !== 0)) ? HOUR :
  690. a[MINUTE] < 0 || a[MINUTE] > 59 ? MINUTE :
  691. a[SECOND] < 0 || a[SECOND] > 59 ? SECOND :
  692. a[MILLISECOND] < 0 || a[MILLISECOND] > 999 ? MILLISECOND :
  693. -1;
  694. if (getParsingFlags(m)._overflowDayOfYear && (overflow < YEAR || overflow > DATE)) {
  695. overflow = DATE;
  696. }
  697. if (getParsingFlags(m)._overflowWeeks && overflow === -1) {
  698. overflow = WEEK;
  699. }
  700. if (getParsingFlags(m)._overflowWeekday && overflow === -1) {
  701. overflow = WEEKDAY;
  702. }
  703. getParsingFlags(m).overflow = overflow;
  704. }
  705. return m;
  706. }
  707. function warn(msg) {
  708. if (utils_hooks__hooks.suppressDeprecationWarnings === false &&
  709. (typeof console !== 'undefined') && console.warn) {
  710. console.warn('Deprecation warning: ' + msg);
  711. }
  712. }
  713. function deprecate(msg, fn) {
  714. var firstTime = true;
  715. return extend(function () {
  716. if (firstTime) {
  717. warn(msg + '\nArguments: ' + Array.prototype.slice.call(arguments).join(', ') + '\n' + (new Error()).stack);
  718. firstTime = false;
  719. }
  720. return fn.apply(this, arguments);
  721. }, fn);
  722. }
  723. var deprecations = {};
  724. function deprecateSimple(name, msg) {
  725. if (!deprecations[name]) {
  726. warn(msg);
  727. deprecations[name] = true;
  728. }
  729. }
  730. utils_hooks__hooks.suppressDeprecationWarnings = false;
  731. // iso 8601 regex
  732. // 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)
  733. 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)?)?/;
  734. 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)?)?/;
  735. var tzRegex = /Z|[+-]\d\d(?::?\d\d)?/;
  736. var isoDates = [
  737. ['YYYYYY-MM-DD', /[+-]\d{6}-\d\d-\d\d/],
  738. ['YYYY-MM-DD', /\d{4}-\d\d-\d\d/],
  739. ['GGGG-[W]WW-E', /\d{4}-W\d\d-\d/],
  740. ['GGGG-[W]WW', /\d{4}-W\d\d/, false],
  741. ['YYYY-DDD', /\d{4}-\d{3}/],
  742. ['YYYY-MM', /\d{4}-\d\d/, false],
  743. ['YYYYYYMMDD', /[+-]\d{10}/],
  744. ['YYYYMMDD', /\d{8}/],
  745. // YYYYMM is NOT allowed by the standard
  746. ['GGGG[W]WWE', /\d{4}W\d{3}/],
  747. ['GGGG[W]WW', /\d{4}W\d{2}/, false],
  748. ['YYYYDDD', /\d{7}/]
  749. ];
  750. // iso time formats and regexes
  751. var isoTimes = [
  752. ['HH:mm:ss.SSSS', /\d\d:\d\d:\d\d\.\d+/],
  753. ['HH:mm:ss,SSSS', /\d\d:\d\d:\d\d,\d+/],
  754. ['HH:mm:ss', /\d\d:\d\d:\d\d/],
  755. ['HH:mm', /\d\d:\d\d/],
  756. ['HHmmss.SSSS', /\d\d\d\d\d\d\.\d+/],
  757. ['HHmmss,SSSS', /\d\d\d\d\d\d,\d+/],
  758. ['HHmmss', /\d\d\d\d\d\d/],
  759. ['HHmm', /\d\d\d\d/],
  760. ['HH', /\d\d/]
  761. ];
  762. var aspNetJsonRegex = /^\/?Date\((\-?\d+)/i;
  763. // date from iso format
  764. function configFromISO(config) {
  765. var i, l,
  766. string = config._i,
  767. match = extendedIsoRegex.exec(string) || basicIsoRegex.exec(string),
  768. allowTime, dateFormat, timeFormat, tzFormat;
  769. if (match) {
  770. getParsingFlags(config).iso = true;
  771. for (i = 0, l = isoDates.length; i < l; i++) {
  772. if (isoDates[i][1].exec(match[1])) {
  773. dateFormat = isoDates[i][0];
  774. allowTime = isoDates[i][2] !== false;
  775. break;
  776. }
  777. }
  778. if (dateFormat == null) {
  779. config._isValid = false;
  780. return;
  781. }
  782. if (match[3]) {
  783. for (i = 0, l = isoTimes.length; i < l; i++) {
  784. if (isoTimes[i][1].exec(match[3])) {
  785. // match[2] should be 'T' or space
  786. timeFormat = (match[2] || ' ') + isoTimes[i][0];
  787. break;
  788. }
  789. }
  790. if (timeFormat == null) {
  791. config._isValid = false;
  792. return;
  793. }
  794. }
  795. if (!allowTime && timeFormat != null) {
  796. config._isValid = false;
  797. return;
  798. }
  799. if (match[4]) {
  800. if (tzRegex.exec(match[4])) {
  801. tzFormat = 'Z';
  802. } else {
  803. config._isValid = false;
  804. return;
  805. }
  806. }
  807. config._f = dateFormat + (timeFormat || '') + (tzFormat || '');
  808. configFromStringAndFormat(config);
  809. } else {
  810. config._isValid = false;
  811. }
  812. }
  813. // date from iso format or fallback
  814. function configFromString(config) {
  815. var matched = aspNetJsonRegex.exec(config._i);
  816. if (matched !== null) {
  817. config._d = new Date(+matched[1]);
  818. return;
  819. }
  820. configFromISO(config);
  821. if (config._isValid === false) {
  822. delete config._isValid;
  823. utils_hooks__hooks.createFromInputFallback(config);
  824. }
  825. }
  826. utils_hooks__hooks.createFromInputFallback = deprecate(
  827. 'moment construction falls back to js Date. This is ' +
  828. 'discouraged and will be removed in upcoming major ' +
  829. 'release. Please refer to ' +
  830. 'https://github.com/moment/moment/issues/1407 for more info.',
  831. function (config) {
  832. config._d = new Date(config._i + (config._useUTC ? ' UTC' : ''));
  833. }
  834. );
  835. function createDate (y, m, d, h, M, s, ms) {
  836. //can't just apply() to create a date:
  837. //http://stackoverflow.com/questions/181348/instantiating-a-javascript-object-by-calling-prototype-constructor-apply
  838. var date = new Date(y, m, d, h, M, s, ms);
  839. //the date constructor remaps years 0-99 to 1900-1999
  840. if (y < 100 && y >= 0 && isFinite(date.getFullYear())) {
  841. date.setFullYear(y);
  842. }
  843. return date;
  844. }
  845. function createUTCDate (y) {
  846. var date = new Date(Date.UTC.apply(null, arguments));
  847. //the Date.UTC function remaps years 0-99 to 1900-1999
  848. if (y < 100 && y >= 0 && isFinite(date.getUTCFullYear())) {
  849. date.setUTCFullYear(y);
  850. }
  851. return date;
  852. }
  853. // FORMATTING
  854. addFormatToken('Y', 0, 0, function () {
  855. var y = this.year();
  856. return y <= 9999 ? '' + y : '+' + y;
  857. });
  858. addFormatToken(0, ['YY', 2], 0, function () {
  859. return this.year() % 100;
  860. });
  861. addFormatToken(0, ['YYYY', 4], 0, 'year');
  862. addFormatToken(0, ['YYYYY', 5], 0, 'year');
  863. addFormatToken(0, ['YYYYYY', 6, true], 0, 'year');
  864. // ALIASES
  865. addUnitAlias('year', 'y');
  866. // PARSING
  867. addRegexToken('Y', matchSigned);
  868. addRegexToken('YY', match1to2, match2);
  869. addRegexToken('YYYY', match1to4, match4);
  870. addRegexToken('YYYYY', match1to6, match6);
  871. addRegexToken('YYYYYY', match1to6, match6);
  872. addParseToken(['YYYYY', 'YYYYYY'], YEAR);
  873. addParseToken('YYYY', function (input, array) {
  874. array[YEAR] = input.length === 2 ? utils_hooks__hooks.parseTwoDigitYear(input) : toInt(input);
  875. });
  876. addParseToken('YY', function (input, array) {
  877. array[YEAR] = utils_hooks__hooks.parseTwoDigitYear(input);
  878. });
  879. addParseToken('Y', function (input, array) {
  880. array[YEAR] = parseInt(input, 10);
  881. });
  882. // HELPERS
  883. function daysInYear(year) {
  884. return isLeapYear(year) ? 366 : 365;
  885. }
  886. function isLeapYear(year) {
  887. return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
  888. }
  889. // HOOKS
  890. utils_hooks__hooks.parseTwoDigitYear = function (input) {
  891. return toInt(input) + (toInt(input) > 68 ? 1900 : 2000);
  892. };
  893. // MOMENTS
  894. var getSetYear = makeGetSet('FullYear', false);
  895. function getIsLeapYear () {
  896. return isLeapYear(this.year());
  897. }
  898. // start-of-first-week - start-of-year
  899. function firstWeekOffset(year, dow, doy) {
  900. var // first-week day -- which january is always in the first week (4 for iso, 1 for other)
  901. fwd = 7 + dow - doy,
  902. // first-week day local weekday -- which local weekday is fwd
  903. fwdlw = (7 + createUTCDate(year, 0, fwd).getUTCDay() - dow) % 7;
  904. return -fwdlw + fwd - 1;
  905. }
  906. //http://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday
  907. function dayOfYearFromWeeks(year, week, weekday, dow, doy) {
  908. var localWeekday = (7 + weekday - dow) % 7,
  909. weekOffset = firstWeekOffset(year, dow, doy),
  910. dayOfYear = 1 + 7 * (week - 1) + localWeekday + weekOffset,
  911. resYear, resDayOfYear;
  912. if (dayOfYear <= 0) {
  913. resYear = year - 1;
  914. resDayOfYear = daysInYear(resYear) + dayOfYear;
  915. } else if (dayOfYear > daysInYear(year)) {
  916. resYear = year + 1;
  917. resDayOfYear = dayOfYear - daysInYear(year);
  918. } else {
  919. resYear = year;
  920. resDayOfYear = dayOfYear;
  921. }
  922. return {
  923. year: resYear,
  924. dayOfYear: resDayOfYear
  925. };
  926. }
  927. function weekOfYear(mom, dow, doy) {
  928. var weekOffset = firstWeekOffset(mom.year(), dow, doy),
  929. week = Math.floor((mom.dayOfYear() - weekOffset - 1) / 7) + 1,
  930. resWeek, resYear;
  931. if (week < 1) {
  932. resYear = mom.year() - 1;
  933. resWeek = week + weeksInYear(resYear, dow, doy);
  934. } else if (week > weeksInYear(mom.year(), dow, doy)) {
  935. resWeek = week - weeksInYear(mom.year(), dow, doy);
  936. resYear = mom.year() + 1;
  937. } else {
  938. resYear = mom.year();
  939. resWeek = week;
  940. }
  941. return {
  942. week: resWeek,
  943. year: resYear
  944. };
  945. }
  946. function weeksInYear(year, dow, doy) {
  947. var weekOffset = firstWeekOffset(year, dow, doy),
  948. weekOffsetNext = firstWeekOffset(year + 1, dow, doy);
  949. return (daysInYear(year) - weekOffset + weekOffsetNext) / 7;
  950. }
  951. // Pick the first defined of two or three arguments.
  952. function defaults(a, b, c) {
  953. if (a != null) {
  954. return a;
  955. }
  956. if (b != null) {
  957. return b;
  958. }
  959. return c;
  960. }
  961. function currentDateArray(config) {
  962. // hooks is actually the exported moment object
  963. var nowValue = new Date(utils_hooks__hooks.now());
  964. if (config._useUTC) {
  965. return [nowValue.getUTCFullYear(), nowValue.getUTCMonth(), nowValue.getUTCDate()];
  966. }
  967. return [nowValue.getFullYear(), nowValue.getMonth(), nowValue.getDate()];
  968. }
  969. // convert an array to a date.
  970. // the array should mirror the parameters below
  971. // note: all values past the year are optional and will default to the lowest possible value.
  972. // [year, month, day , hour, minute, second, millisecond]
  973. function configFromArray (config) {
  974. var i, date, input = [], currentDate, yearToUse;
  975. if (config._d) {
  976. return;
  977. }
  978. currentDate = currentDateArray(config);
  979. //compute day of the year from weeks and weekdays
  980. if (config._w && config._a[DATE] == null && config._a[MONTH] == null) {
  981. dayOfYearFromWeekInfo(config);
  982. }
  983. //if the day of the year is set, figure out what it is
  984. if (config._dayOfYear) {
  985. yearToUse = defaults(config._a[YEAR], currentDate[YEAR]);
  986. if (config._dayOfYear > daysInYear(yearToUse)) {
  987. getParsingFlags(config)._overflowDayOfYear = true;
  988. }
  989. date = createUTCDate(yearToUse, 0, config._dayOfYear);
  990. config._a[MONTH] = date.getUTCMonth();
  991. config._a[DATE] = date.getUTCDate();
  992. }
  993. // Default to current date.
  994. // * if no year, month, day of month are given, default to today
  995. // * if day of month is given, default month and year
  996. // * if month is given, default only year
  997. // * if year is given, don't default anything
  998. for (i = 0; i < 3 && config._a[i] == null; ++i) {
  999. config._a[i] = input[i] = currentDate[i];
  1000. }
  1001. // Zero out whatever was not defaulted, including time
  1002. for (; i < 7; i++) {
  1003. config._a[i] = input[i] = (config._a[i] == null) ? (i === 2 ? 1 : 0) : config._a[i];
  1004. }
  1005. // Check for 24:00:00.000
  1006. if (config._a[HOUR] === 24 &&
  1007. config._a[MINUTE] === 0 &&
  1008. config._a[SECOND] === 0 &&
  1009. config._a[MILLISECOND] === 0) {
  1010. config._nextDay = true;
  1011. config._a[HOUR] = 0;
  1012. }
  1013. config._d = (config._useUTC ? createUTCDate : createDate).apply(null, input);
  1014. // Apply timezone offset from input. The actual utcOffset can be changed
  1015. // with parseZone.
  1016. if (config._tzm != null) {
  1017. config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm);
  1018. }
  1019. if (config._nextDay) {
  1020. config._a[HOUR] = 24;
  1021. }
  1022. }
  1023. function dayOfYearFromWeekInfo(config) {
  1024. var w, weekYear, week, weekday, dow, doy, temp, weekdayOverflow;
  1025. w = config._w;
  1026. if (w.GG != null || w.W != null || w.E != null) {
  1027. dow = 1;
  1028. doy = 4;
  1029. // TODO: We need to take the current isoWeekYear, but that depends on
  1030. // how we interpret now (local, utc, fixed offset). So create
  1031. // a now version of current config (take local/utc/offset flags, and
  1032. // create now).
  1033. weekYear = defaults(w.GG, config._a[YEAR], weekOfYear(local__createLocal(), 1, 4).year);
  1034. week = defaults(w.W, 1);
  1035. weekday = defaults(w.E, 1);
  1036. if (weekday < 1 || weekday > 7) {
  1037. weekdayOverflow = true;
  1038. }
  1039. } else {
  1040. dow = config._locale._week.dow;
  1041. doy = config._locale._week.doy;
  1042. weekYear = defaults(w.gg, config._a[YEAR], weekOfYear(local__createLocal(), dow, doy).year);
  1043. week = defaults(w.w, 1);
  1044. if (w.d != null) {
  1045. // weekday -- low day numbers are considered next week
  1046. weekday = w.d;
  1047. if (weekday < 0 || weekday > 6) {
  1048. weekdayOverflow = true;
  1049. }
  1050. } else if (w.e != null) {
  1051. // local weekday -- counting starts from begining of week
  1052. weekday = w.e + dow;
  1053. if (w.e < 0 || w.e > 6) {
  1054. weekdayOverflow = true;
  1055. }
  1056. } else {
  1057. // default to begining of week
  1058. weekday = dow;
  1059. }
  1060. }
  1061. if (week < 1 || week > weeksInYear(weekYear, dow, doy)) {
  1062. getParsingFlags(config)._overflowWeeks = true;
  1063. } else if (weekdayOverflow != null) {
  1064. getParsingFlags(config)._overflowWeekday = true;
  1065. } else {
  1066. temp = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy);
  1067. config._a[YEAR] = temp.year;
  1068. config._dayOfYear = temp.dayOfYear;
  1069. }
  1070. }
  1071. // constant that refers to the ISO standard
  1072. utils_hooks__hooks.ISO_8601 = function () {};
  1073. // date from string and format string
  1074. function configFromStringAndFormat(config) {
  1075. // TODO: Move this to another part of the creation flow to prevent circular deps
  1076. if (config._f === utils_hooks__hooks.ISO_8601) {
  1077. configFromISO(config);
  1078. return;
  1079. }
  1080. config._a = [];
  1081. getParsingFlags(config).empty = true;
  1082. // This array is used to make a Date, either with `new Date` or `Date.UTC`
  1083. var string = '' + config._i,
  1084. i, parsedInput, tokens, token, skipped,
  1085. stringLength = string.length,
  1086. totalParsedInputLength = 0;
  1087. tokens = expandFormat(config._f, config._locale).match(formattingTokens) || [];
  1088. for (i = 0; i < tokens.length; i++) {
  1089. token = tokens[i];
  1090. parsedInput = (string.match(getParseRegexForToken(token, config)) || [])[0];
  1091. // console.log('token', token, 'parsedInput', parsedInput,
  1092. // 'regex', getParseRegexForToken(token, config));
  1093. if (parsedInput) {
  1094. skipped = string.substr(0, string.indexOf(parsedInput));
  1095. if (skipped.length > 0) {
  1096. getParsingFlags(config).unusedInput.push(skipped);
  1097. }
  1098. string = string.slice(string.indexOf(parsedInput) + parsedInput.length);
  1099. totalParsedInputLength += parsedInput.length;
  1100. }
  1101. // don't parse if it's not a known token
  1102. if (formatTokenFunctions[token]) {
  1103. if (parsedInput) {
  1104. getParsingFlags(config).empty = false;
  1105. }
  1106. else {
  1107. getParsingFlags(config).unusedTokens.push(token);
  1108. }
  1109. addTimeToArrayFromToken(token, parsedInput, config);
  1110. }
  1111. else if (config._strict && !parsedInput) {
  1112. getParsingFlags(config).unusedTokens.push(token);
  1113. }
  1114. }
  1115. // add remaining unparsed input length to the string
  1116. getParsingFlags(config).charsLeftOver = stringLength - totalParsedInputLength;
  1117. if (string.length > 0) {
  1118. getParsingFlags(config).unusedInput.push(string);
  1119. }
  1120. // clear _12h flag if hour is <= 12
  1121. if (getParsingFlags(config).bigHour === true &&
  1122. config._a[HOUR] <= 12 &&
  1123. config._a[HOUR] > 0) {
  1124. getParsingFlags(config).bigHour = undefined;
  1125. }
  1126. // handle meridiem
  1127. config._a[HOUR] = meridiemFixWrap(config._locale, config._a[HOUR], config._meridiem);
  1128. configFromArray(config);
  1129. checkOverflow(config);
  1130. }
  1131. function meridiemFixWrap (locale, hour, meridiem) {
  1132. var isPm;
  1133. if (meridiem == null) {
  1134. // nothing to do
  1135. return hour;
  1136. }
  1137. if (locale.meridiemHour != null) {
  1138. return locale.meridiemHour(hour, meridiem);
  1139. } else if (locale.isPM != null) {
  1140. // Fallback
  1141. isPm = locale.isPM(meridiem);
  1142. if (isPm && hour < 12) {
  1143. hour += 12;
  1144. }
  1145. if (!isPm && hour === 12) {
  1146. hour = 0;
  1147. }
  1148. return hour;
  1149. } else {
  1150. // this is not supposed to happen
  1151. return hour;
  1152. }
  1153. }
  1154. // date from string and array of format strings
  1155. function configFromStringAndArray(config) {
  1156. var tempConfig,
  1157. bestMoment,
  1158. scoreToBeat,
  1159. i,
  1160. currentScore;
  1161. if (config._f.length === 0) {
  1162. getParsingFlags(config).invalidFormat = true;
  1163. config._d = new Date(NaN);
  1164. return;
  1165. }
  1166. for (i = 0; i < config._f.length; i++) {
  1167. currentScore = 0;
  1168. tempConfig = copyConfig({}, config);
  1169. if (config._useUTC != null) {
  1170. tempConfig._useUTC = config._useUTC;
  1171. }
  1172. tempConfig._f = config._f[i];
  1173. configFromStringAndFormat(tempConfig);
  1174. if (!valid__isValid(tempConfig)) {
  1175. continue;
  1176. }
  1177. // if there is any input that was not parsed add a penalty for that format
  1178. currentScore += getParsingFlags(tempConfig).charsLeftOver;
  1179. //or tokens
  1180. currentScore += getParsingFlags(tempConfig).unusedTokens.length * 10;
  1181. getParsingFlags(tempConfig).score = currentScore;
  1182. if (scoreToBeat == null || currentScore < scoreToBeat) {
  1183. scoreToBeat = currentScore;
  1184. bestMoment = tempConfig;
  1185. }
  1186. }
  1187. extend(config, bestMoment || tempConfig);
  1188. }
  1189. function configFromObject(config) {
  1190. if (config._d) {
  1191. return;
  1192. }
  1193. var i = normalizeObjectUnits(config._i);
  1194. config._a = map([i.year, i.month, i.day || i.date, i.hour, i.minute, i.second, i.millisecond], function (obj) {
  1195. return obj && parseInt(obj, 10);
  1196. });
  1197. configFromArray(config);
  1198. }
  1199. function createFromConfig (config) {
  1200. var res = new Moment(checkOverflow(prepareConfig(config)));
  1201. if (res._nextDay) {
  1202. // Adding is smart enough around DST
  1203. res.add(1, 'd');
  1204. res._nextDay = undefined;
  1205. }
  1206. return res;
  1207. }
  1208. function prepareConfig (config) {
  1209. var input = config._i,
  1210. format = config._f;
  1211. config._locale = config._locale || locale_locales__getLocale(config._l);
  1212. if (input === null || (format === undefined && input === '')) {
  1213. return valid__createInvalid({nullInput: true});
  1214. }
  1215. if (typeof input === 'string') {
  1216. config._i = input = config._locale.preparse(input);
  1217. }
  1218. if (isMoment(input)) {
  1219. return new Moment(checkOverflow(input));
  1220. } else if (isArray(format)) {
  1221. configFromStringAndArray(config);
  1222. } else if (format) {
  1223. configFromStringAndFormat(config);
  1224. } else if (isDate(input)) {
  1225. config._d = input;
  1226. } else {
  1227. configFromInput(config);
  1228. }
  1229. if (!valid__isValid(config)) {
  1230. config._d = null;
  1231. }
  1232. return config;
  1233. }
  1234. function configFromInput(config) {
  1235. var input = config._i;
  1236. if (input === undefined) {
  1237. config._d = new Date(utils_hooks__hooks.now());
  1238. } else if (isDate(input)) {
  1239. config._d = new Date(+input);
  1240. } else if (typeof input === 'string') {
  1241. configFromString(config);
  1242. } else if (isArray(input)) {
  1243. config._a = map(input.slice(0), function (obj) {
  1244. return parseInt(obj, 10);
  1245. });
  1246. configFromArray(config);
  1247. } else if (typeof(input) === 'object') {
  1248. configFromObject(config);
  1249. } else if (typeof(input) === 'number') {
  1250. // from milliseconds
  1251. config._d = new Date(input);
  1252. } else {
  1253. utils_hooks__hooks.createFromInputFallback(config);
  1254. }
  1255. }
  1256. function createLocalOrUTC (input, format, locale, strict, isUTC) {
  1257. var c = {};
  1258. if (typeof(locale) === 'boolean') {
  1259. strict = locale;
  1260. locale = undefined;
  1261. }
  1262. // object construction must be done this way.
  1263. // https://github.com/moment/moment/issues/1423
  1264. c._isAMomentObject = true;
  1265. c._useUTC = c._isUTC = isUTC;
  1266. c._l = locale;
  1267. c._i = input;
  1268. c._f = format;
  1269. c._strict = strict;
  1270. return createFromConfig(c);
  1271. }
  1272. function local__createLocal (input, format, locale, strict) {
  1273. return createLocalOrUTC(input, format, locale, strict, false);
  1274. }
  1275. var prototypeMin = deprecate(
  1276. 'moment().min is deprecated, use moment.min instead. https://github.com/moment/moment/issues/1548',
  1277. function () {
  1278. var other = local__createLocal.apply(null, arguments);
  1279. if (this.isValid() && other.isValid()) {
  1280. return other < this ? this : other;
  1281. } else {
  1282. return valid__createInvalid();
  1283. }
  1284. }
  1285. );
  1286. var prototypeMax = deprecate(
  1287. 'moment().max is deprecated, use moment.max instead. https://github.com/moment/moment/issues/1548',
  1288. function () {
  1289. var other = local__createLocal.apply(null, arguments);
  1290. if (this.isValid() && other.isValid()) {
  1291. return other > this ? this : other;
  1292. } else {
  1293. return valid__createInvalid();
  1294. }
  1295. }
  1296. );
  1297. // Pick a moment m from moments so that m[fn](other) is true for all
  1298. // other. This relies on the function fn to be transitive.
  1299. //
  1300. // moments should either be an array of moment objects or an array, whose
  1301. // first element is an array of moment objects.
  1302. function pickBy(fn, moments) {
  1303. var res, i;
  1304. if (moments.length === 1 && isArray(moments[0])) {
  1305. moments = moments[0];
  1306. }
  1307. if (!moments.length) {
  1308. return local__createLocal();
  1309. }
  1310. res = moments[0];
  1311. for (i = 1; i < moments.length; ++i) {
  1312. if (!moments[i].isValid() || moments[i][fn](res)) {
  1313. res = moments[i];
  1314. }
  1315. }
  1316. return res;
  1317. }
  1318. // TODO: Use [].sort instead?
  1319. function min () {
  1320. var args = [].slice.call(arguments, 0);
  1321. return pickBy('isBefore', args);
  1322. }
  1323. function max () {
  1324. var args = [].slice.call(arguments, 0);
  1325. return pickBy('isAfter', args);
  1326. }
  1327. var now = function () {
  1328. return Date.now ? Date.now() : +(new Date());
  1329. };
  1330. function Duration (duration) {
  1331. var normalizedInput = normalizeObjectUnits(duration),
  1332. years = normalizedInput.year || 0,
  1333. quarters = normalizedInput.quarter || 0,
  1334. months = normalizedInput.month || 0,
  1335. weeks = normalizedInput.week || 0,
  1336. days = normalizedInput.day || 0,
  1337. hours = normalizedInput.hour || 0,
  1338. minutes = normalizedInput.minute || 0,
  1339. seconds = normalizedInput.second || 0,
  1340. milliseconds = normalizedInput.millisecond || 0;
  1341. // representation for dateAddRemove
  1342. this._milliseconds = +milliseconds +
  1343. seconds * 1e3 + // 1000
  1344. minutes * 6e4 + // 1000 * 60
  1345. hours * 36e5; // 1000 * 60 * 60
  1346. // Because of dateAddRemove treats 24 hours as different from a
  1347. // day when working around DST, we need to store them separately
  1348. this._days = +days +
  1349. weeks * 7;
  1350. // It is impossible translate months into days without knowing
  1351. // which months you are are talking about, so we have to store
  1352. // it separately.
  1353. this._months = +months +
  1354. quarters * 3 +
  1355. years * 12;
  1356. this._data = {};
  1357. this._locale = locale_locales__getLocale();
  1358. this._bubble();
  1359. }
  1360. function isDuration (obj) {
  1361. return obj instanceof Duration;
  1362. }
  1363. // FORMATTING
  1364. function offset (token, separator) {
  1365. addFormatToken(token, 0, 0, function () {
  1366. var offset = this.utcOffset();
  1367. var sign = '+';
  1368. if (offset < 0) {
  1369. offset = -offset;
  1370. sign = '-';
  1371. }
  1372. return sign + zeroFill(~~(offset / 60), 2) + separator + zeroFill(~~(offset) % 60, 2);
  1373. });
  1374. }
  1375. offset('Z', ':');
  1376. offset('ZZ', '');
  1377. // PARSING
  1378. addRegexToken('Z', matchShortOffset);
  1379. addRegexToken('ZZ', matchShortOffset);
  1380. addParseToken(['Z', 'ZZ'], function (input, array, config) {
  1381. config._useUTC = true;
  1382. config._tzm = offsetFromString(matchShortOffset, input);
  1383. });
  1384. // HELPERS
  1385. // timezone chunker
  1386. // '+10:00' > ['10', '00']
  1387. // '-1530' > ['-15', '30']
  1388. var chunkOffset = /([\+\-]|\d\d)/gi;
  1389. function offsetFromString(matcher, string) {
  1390. var matches = ((string || '').match(matcher) || []);
  1391. var chunk = matches[matches.length - 1] || [];
  1392. var parts = (chunk + '').match(chunkOffset) || ['-', 0, 0];
  1393. var minutes = +(parts[1] * 60) + toInt(parts[2]);
  1394. return parts[0] === '+' ? minutes : -minutes;
  1395. }
  1396. // Return a moment from input, that is local/utc/zone equivalent to model.
  1397. function cloneWithOffset(input, model) {
  1398. var res, diff;
  1399. if (model._isUTC) {
  1400. res = model.clone();
  1401. diff = (isMoment(input) || isDate(input) ? +input : +local__createLocal(input)) - (+res);
  1402. // Use low-level api, because this fn is low-level api.
  1403. res._d.setTime(+res._d + diff);
  1404. utils_hooks__hooks.updateOffset(res, false);
  1405. return res;
  1406. } else {
  1407. return local__createLocal(input).local();
  1408. }
  1409. }
  1410. function getDateOffset (m) {
  1411. // On Firefox.24 Date#getTimezoneOffset returns a floating point.
  1412. // https://github.com/moment/moment/pull/1871
  1413. return -Math.round(m._d.getTimezoneOffset() / 15) * 15;
  1414. }
  1415. // HOOKS
  1416. // This function will be called whenever a moment is mutated.
  1417. // It is intended to keep the offset in sync with the timezone.
  1418. utils_hooks__hooks.updateOffset = function () {};
  1419. // MOMENTS
  1420. // keepLocalTime = true means only change the timezone, without
  1421. // affecting the local hour. So 5:31:26 +0300 --[utcOffset(2, true)]-->
  1422. // 5:31:26 +0200 It is possible that 5:31:26 doesn't exist with offset
  1423. // +0200, so we adjust the time as needed, to be valid.
  1424. //
  1425. // Keeping the time actually adds/subtracts (one hour)
  1426. // from the actual represented time. That is why we call updateOffset
  1427. // a second time. In case it wants us to change the offset again
  1428. // _changeInProgress == true case, then we have to adjust, because
  1429. // there is no such time in the given timezone.
  1430. function getSetOffset (input, keepLocalTime) {
  1431. var offset = this._offset || 0,
  1432. localAdjust;
  1433. if (!this.isValid()) {
  1434. return input != null ? this : NaN;
  1435. }
  1436. if (input != null) {
  1437. if (typeof input === 'string') {
  1438. input = offsetFromString(matchShortOffset, input);
  1439. } else if (Math.abs(input) < 16) {
  1440. input = input * 60;
  1441. }
  1442. if (!this._isUTC && keepLocalTime) {
  1443. localAdjust = getDateOffset(this);
  1444. }
  1445. this._offset = input;
  1446. this._isUTC = true;
  1447. if (localAdjust != null) {
  1448. this.add(localAdjust, 'm');
  1449. }
  1450. if (offset !== input) {
  1451. if (!keepLocalTime || this._changeInProgress) {
  1452. add_subtract__addSubtract(this, create__createDuration(input - offset, 'm'), 1, false);
  1453. } else if (!this._changeInProgress) {
  1454. this._changeInProgress = true;
  1455. utils_hooks__hooks.updateOffset(this, true);
  1456. this._changeInProgress = null;
  1457. }
  1458. }
  1459. return this;
  1460. } else {
  1461. return this._isUTC ? offset : getDateOffset(this);
  1462. }
  1463. }
  1464. function getSetZone (input, keepLocalTime) {
  1465. if (input != null) {
  1466. if (typeof input !== 'string') {
  1467. input = -input;
  1468. }
  1469. this.utcOffset(input, keepLocalTime);
  1470. return this;
  1471. } else {
  1472. return -this.utcOffset();
  1473. }
  1474. }
  1475. function setOffsetToUTC (keepLocalTime) {
  1476. return this.utcOffset(0, keepLocalTime);
  1477. }
  1478. function setOffsetToLocal (keepLocalTime) {
  1479. if (this._isUTC) {
  1480. this.utcOffset(0, keepLocalTime);
  1481. this._isUTC = false;
  1482. if (keepLocalTime) {
  1483. this.subtract(getDateOffset(this), 'm');
  1484. }
  1485. }
  1486. return this;
  1487. }
  1488. function setOffsetToParsedOffset () {
  1489. if (this._tzm) {
  1490. this.utcOffset(this._tzm);
  1491. } else if (typeof this._i === 'string') {
  1492. this.utcOffset(offsetFromString(matchOffset, this._i));
  1493. }
  1494. return this;
  1495. }
  1496. function hasAlignedHourOffset (input) {
  1497. if (!this.isValid()) {
  1498. return false;
  1499. }
  1500. input = input ? local__createLocal(input).utcOffset() : 0;
  1501. return (this.utcOffset() - input) % 60 === 0;
  1502. }
  1503. function isDaylightSavingTime () {
  1504. return (
  1505. this.utcOffset() > this.clone().month(0).utcOffset() ||
  1506. this.utcOffset() > this.clone().month(5).utcOffset()
  1507. );
  1508. }
  1509. function isDaylightSavingTimeShifted () {
  1510. if (!isUndefined(this._isDSTShifted)) {
  1511. return this._isDSTShifted;
  1512. }
  1513. var c = {};
  1514. copyConfig(c, this);
  1515. c = prepareConfig(c);
  1516. if (c._a) {
  1517. var other = c._isUTC ? create_utc__createUTC(c._a) : local__createLocal(c._a);
  1518. this._isDSTShifted = this.isValid() &&
  1519. compareArrays(c._a, other.toArray()) > 0;
  1520. } else {
  1521. this._isDSTShifted = false;
  1522. }
  1523. return this._isDSTShifted;
  1524. }
  1525. function isLocal () {
  1526. return this.isValid() ? !this._isUTC : false;
  1527. }
  1528. function isUtcOffset () {
  1529. return this.isValid() ? this._isUTC : false;
  1530. }
  1531. function isUtc () {
  1532. return this.isValid() ? this._isUTC && this._offset === 0 : false;
  1533. }
  1534. // ASP.NET json date format regex
  1535. var aspNetRegex = /^(\-)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?\d*)?$/;
  1536. // from http://docs.closure-library.googlecode.com/git/closure_goog_date_date.js.source.html
  1537. // somewhat more in line with 4.4.3.2 2004 spec, but allows decimal anywhere
  1538. var isoRegex = /^(-)?P(?:(?:([0-9,.]*)Y)?(?:([0-9,.]*)M)?(?:([0-9,.]*)D)?(?:T(?:([0-9,.]*)H)?(?:([0-9,.]*)M)?(?:([0-9,.]*)S)?)?|([0-9,.]*)W)$/;
  1539. function create__createDuration (input, key) {
  1540. var duration = input,
  1541. // matching against regexp is expensive, do it on demand
  1542. match = null,
  1543. sign,
  1544. ret,
  1545. diffRes;
  1546. if (isDuration(input)) {
  1547. duration = {
  1548. ms : input._milliseconds,
  1549. d : input._days,
  1550. M : input._months
  1551. };
  1552. } else if (typeof input === 'number') {
  1553. duration = {};
  1554. if (key) {
  1555. duration[key] = input;
  1556. } else {
  1557. duration.milliseconds = input;
  1558. }
  1559. } else if (!!(match = aspNetRegex.exec(input))) {
  1560. sign = (match[1] === '-') ? -1 : 1;
  1561. duration = {
  1562. y : 0,
  1563. d : toInt(match[DATE]) * sign,
  1564. h : toInt(match[HOUR]) * sign,
  1565. m : toInt(match[MINUTE]) * sign,
  1566. s : toInt(match[SECOND]) * sign,
  1567. ms : toInt(match[MILLISECOND]) * sign
  1568. };
  1569. } else if (!!(match = isoRegex.exec(input))) {
  1570. sign = (match[1] === '-') ? -1 : 1;
  1571. duration = {
  1572. y : parseIso(match[2], sign),
  1573. M : parseIso(match[3], sign),
  1574. d : parseIso(match[4], sign),
  1575. h : parseIso(match[5], sign),
  1576. m : parseIso(match[6], sign),
  1577. s : parseIso(match[7], sign),
  1578. w : parseIso(match[8], sign)
  1579. };
  1580. } else if (duration == null) {// checks for null or undefined
  1581. duration = {};
  1582. } else if (typeof duration === 'object' && ('from' in duration || 'to' in duration)) {
  1583. diffRes = momentsDifference(local__createLocal(duration.from), local__createLocal(duration.to));
  1584. duration = {};
  1585. duration.ms = diffRes.milliseconds;
  1586. duration.M = diffRes.months;
  1587. }
  1588. ret = new Duration(duration);
  1589. if (isDuration(input) && hasOwnProp(input, '_locale')) {
  1590. ret._locale = input._locale;
  1591. }
  1592. return ret;
  1593. }
  1594. create__createDuration.fn = Duration.prototype;
  1595. function parseIso (inp, sign) {
  1596. // We'd normally use ~~inp for this, but unfortunately it also
  1597. // converts floats to ints.
  1598. // inp may be undefined, so careful calling replace on it.
  1599. var res = inp && parseFloat(inp.replace(',', '.'));
  1600. // apply sign while we're at it
  1601. return (isNaN(res) ? 0 : res) * sign;
  1602. }
  1603. function positiveMomentsDifference(base, other) {
  1604. var res = {milliseconds: 0, months: 0};
  1605. res.months = other.month() - base.month() +
  1606. (other.year() - base.year()) * 12;
  1607. if (base.clone().add(res.months, 'M').isAfter(other)) {
  1608. --res.months;
  1609. }
  1610. res.milliseconds = +other - +(base.clone().add(res.months, 'M'));
  1611. return res;
  1612. }
  1613. function momentsDifference(base, other) {
  1614. var res;
  1615. if (!(base.isValid() && other.isValid())) {
  1616. return {milliseconds: 0, months: 0};
  1617. }
  1618. other = cloneWithOffset(other, base);
  1619. if (base.isBefore(other)) {
  1620. res = positiveMomentsDifference(base, other);
  1621. } else {
  1622. res = positiveMomentsDifference(other, base);
  1623. res.milliseconds = -res.milliseconds;
  1624. res.months = -res.months;
  1625. }
  1626. return res;
  1627. }
  1628. // TODO: remove 'name' arg after deprecation is removed
  1629. function createAdder(direction, name) {
  1630. return function (val, period) {
  1631. var dur, tmp;
  1632. //invert the arguments, but complain about it
  1633. if (period !== null && !isNaN(+period)) {
  1634. deprecateSimple(name, 'moment().' + name + '(period, number) is deprecated. Please use moment().' + name + '(number, period).');
  1635. tmp = val; val = period; period = tmp;
  1636. }
  1637. val = typeof val === 'string' ? +val : val;
  1638. dur = create__createDuration(val, period);
  1639. add_subtract__addSubtract(this, dur, direction);
  1640. return this;
  1641. };
  1642. }
  1643. function add_subtract__addSubtract (mom, duration, isAdding, updateOffset) {
  1644. var milliseconds = duration._milliseconds,
  1645. days = duration._days,
  1646. months = duration._months;
  1647. if (!mom.isValid()) {
  1648. // No op
  1649. return;
  1650. }
  1651. updateOffset = updateOffset == null ? true : updateOffset;
  1652. if (milliseconds) {
  1653. mom._d.setTime(+mom._d + milliseconds * isAdding);
  1654. }
  1655. if (days) {
  1656. get_set__set(mom, 'Date', get_set__get(mom, 'Date') + days * isAdding);
  1657. }
  1658. if (months) {
  1659. setMonth(mom, get_set__get(mom, 'Month') + months * isAdding);
  1660. }
  1661. if (updateOffset) {
  1662. utils_hooks__hooks.updateOffset(mom, days || months);
  1663. }
  1664. }
  1665. var add_subtract__add = createAdder(1, 'add');
  1666. var add_subtract__subtract = createAdder(-1, 'subtract');
  1667. function moment_calendar__calendar (time, formats) {
  1668. // We want to compare the start of today, vs this.
  1669. // Getting start-of-today depends on whether we're local/utc/offset or not.
  1670. var now = time || local__createLocal(),
  1671. sod = cloneWithOffset(now, this).startOf('day'),
  1672. diff = this.diff(sod, 'days', true),
  1673. format = diff < -6 ? 'sameElse' :
  1674. diff < -1 ? 'lastWeek' :
  1675. diff < 0 ? 'lastDay' :
  1676. diff < 1 ? 'sameDay' :
  1677. diff < 2 ? 'nextDay' :
  1678. diff < 7 ? 'nextWeek' : 'sameElse';
  1679. var output = formats && (isFunction(formats[format]) ? formats[format]() : formats[format]);
  1680. return this.format(output || this.localeData().calendar(format, this, local__createLocal(now)));
  1681. }
  1682. function clone () {
  1683. return new Moment(this);
  1684. }
  1685. function isAfter (input, units) {
  1686. var localInput = isMoment(input) ? input : local__createLocal(input);
  1687. if (!(this.isValid() && localInput.isValid())) {
  1688. return false;
  1689. }
  1690. units = normalizeUnits(!isUndefined(units) ? units : 'millisecond');
  1691. if (units === 'millisecond') {
  1692. return +this > +localInput;
  1693. } else {
  1694. return +localInput < +this.clone().startOf(units);
  1695. }
  1696. }
  1697. function isBefore (input, units) {
  1698. var localInput = isMoment(input) ? input : local__createLocal(input);
  1699. if (!(this.isValid() && localInput.isValid())) {
  1700. return false;
  1701. }
  1702. units = normalizeUnits(!isUndefined(units) ? units : 'millisecond');
  1703. if (units === 'millisecond') {
  1704. return +this < +localInput;
  1705. } else {
  1706. return +this.clone().endOf(units) < +localInput;
  1707. }
  1708. }
  1709. function isBetween (from, to, units) {
  1710. return this.isAfter(from, units) && this.isBefore(to, units);
  1711. }
  1712. function isSame (input, units) {
  1713. var localInput = isMoment(input) ? input : local__createLocal(input),
  1714. inputMs;
  1715. if (!(this.isValid() && localInput.isValid())) {
  1716. return false;
  1717. }
  1718. units = normalizeUnits(units || 'millisecond');
  1719. if (units === 'millisecond') {
  1720. return +this === +localInput;
  1721. } else {
  1722. inputMs = +localInput;
  1723. return +(this.clone().startOf(units)) <= inputMs && inputMs <= +(this.clone().endOf(units));
  1724. }
  1725. }
  1726. function isSameOrAfter (input, units) {
  1727. return this.isSame(input, units) || this.isAfter(input,units);
  1728. }
  1729. function isSameOrBefore (input, units) {
  1730. return this.isSame(input, units) || this.isBefore(input,units);
  1731. }
  1732. function diff (input, units, asFloat) {
  1733. var that,
  1734. zoneDelta,
  1735. delta, output;
  1736. if (!this.isValid()) {
  1737. return NaN;
  1738. }
  1739. that = cloneWithOffset(input, this);
  1740. if (!that.isValid()) {
  1741. return NaN;
  1742. }
  1743. zoneDelta = (that.utcOffset() - this.utcOffset()) * 6e4;
  1744. units = normalizeUnits(units);
  1745. if (units === 'year' || units === 'month' || units === 'quarter') {
  1746. output = monthDiff(this, that);
  1747. if (units === 'quarter') {
  1748. output = output / 3;
  1749. } else if (units === 'year') {
  1750. output = output / 12;
  1751. }
  1752. } else {
  1753. delta = this - that;
  1754. output = units === 'second' ? delta / 1e3 : // 1000
  1755. units === 'minute' ? delta / 6e4 : // 1000 * 60
  1756. units === 'hour' ? delta / 36e5 : // 1000 * 60 * 60
  1757. units === 'day' ? (delta - zoneDelta) / 864e5 : // 1000 * 60 * 60 * 24, negate dst
  1758. units === 'week' ? (delta - zoneDelta) / 6048e5 : // 1000 * 60 * 60 * 24 * 7, negate dst
  1759. delta;
  1760. }
  1761. return asFloat ? output : absFloor(output);
  1762. }
  1763. function monthDiff (a, b) {
  1764. // difference in months
  1765. var wholeMonthDiff = ((b.year() - a.year()) * 12) + (b.month() - a.month()),
  1766. // b is in (anchor - 1 month, anchor + 1 month)
  1767. anchor = a.clone().add(wholeMonthDiff, 'months'),
  1768. anchor2, adjust;
  1769. if (b - anchor < 0) {
  1770. anchor2 = a.clone().add(wholeMonthDiff - 1, 'months');
  1771. // linear across the month
  1772. adjust = (b - anchor) / (anchor - anchor2);
  1773. } else {
  1774. anchor2 = a.clone().add(wholeMonthDiff + 1, 'months');
  1775. // linear across the month
  1776. adjust = (b - anchor) / (anchor2 - anchor);
  1777. }
  1778. return -(wholeMonthDiff + adjust);
  1779. }
  1780. utils_hooks__hooks.defaultFormat = 'YYYY-MM-DDTHH:mm:ssZ';
  1781. function toString () {
  1782. return this.clone().locale('en').format('ddd MMM DD YYYY HH:mm:ss [GMT]ZZ');
  1783. }
  1784. function moment_format__toISOString () {
  1785. var m = this.clone().utc();
  1786. if (0 < m.year() && m.year() <= 9999) {
  1787. if (isFunction(Date.prototype.toISOString)) {
  1788. // native implementation is ~50x faster, use it when we can
  1789. return this.toDate().toISOString();
  1790. } else {
  1791. return formatMoment(m, 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
  1792. }
  1793. } else {
  1794. return formatMoment(m, 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
  1795. }
  1796. }
  1797. function format (inputString) {
  1798. var output = formatMoment(this, inputString || utils_hooks__hooks.defaultFormat);
  1799. return this.localeData().postformat(output);
  1800. }
  1801. function from (time, withoutSuffix) {
  1802. if (this.isValid() &&
  1803. ((isMoment(time) && time.isValid()) ||
  1804. local__createLocal(time).isValid())) {
  1805. return create__createDuration({to: this, from: time}).locale(this.locale()).humanize(!withoutSuffix);
  1806. } else {
  1807. return this.localeData().invalidDate();
  1808. }
  1809. }
  1810. function fromNow (withoutSuffix) {
  1811. return this.from(local__createLocal(), withoutSuffix);
  1812. }
  1813. function to (time, withoutSuffix) {
  1814. if (this.isValid() &&
  1815. ((isMoment(time) && time.isValid()) ||
  1816. local__createLocal(time).isValid())) {
  1817. return create__createDuration({from: this, to: time}).locale(this.locale()).humanize(!withoutSuffix);
  1818. } else {
  1819. return this.localeData().invalidDate();
  1820. }
  1821. }
  1822. function toNow (withoutSuffix) {
  1823. return this.to(local__createLocal(), withoutSuffix);
  1824. }
  1825. // If passed a locale key, it will set the locale for this
  1826. // instance. Otherwise, it will return the locale configuration
  1827. // variables for this instance.
  1828. function locale (key) {
  1829. var newLocaleData;
  1830. if (key === undefined) {
  1831. return this._locale._abbr;
  1832. } else {
  1833. newLocaleData = locale_locales__getLocale(key);
  1834. if (newLocaleData != null) {
  1835. this._locale = newLocaleData;
  1836. }
  1837. return this;
  1838. }
  1839. }
  1840. var lang = deprecate(
  1841. 'moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.',
  1842. function (key) {
  1843. if (key === undefined) {
  1844. return this.localeData();
  1845. } else {
  1846. return this.locale(key);
  1847. }
  1848. }
  1849. );
  1850. function localeData () {
  1851. return this._locale;
  1852. }
  1853. function startOf (units) {
  1854. units = normalizeUnits(units);
  1855. // the following switch intentionally omits break keywords
  1856. // to utilize falling through the cases.
  1857. switch (units) {
  1858. case 'year':
  1859. this.month(0);
  1860. /* falls through */
  1861. case 'quarter':
  1862. case 'month':
  1863. this.date(1);
  1864. /* falls through */
  1865. case 'week':
  1866. case 'isoWeek':
  1867. case 'day':
  1868. this.hours(0);
  1869. /* falls through */
  1870. case 'hour':
  1871. this.minutes(0);
  1872. /* falls through */
  1873. case 'minute':
  1874. this.seconds(0);
  1875. /* falls through */
  1876. case 'second':
  1877. this.milliseconds(0);
  1878. }
  1879. // weeks are a special case
  1880. if (units === 'week') {
  1881. this.weekday(0);
  1882. }
  1883. if (units === 'isoWeek') {
  1884. this.isoWeekday(1);
  1885. }
  1886. // quarters are also special
  1887. if (units === 'quarter') {
  1888. this.month(Math.floor(this.month() / 3) * 3);
  1889. }
  1890. return this;
  1891. }
  1892. function endOf (units) {
  1893. units = normalizeUnits(units);
  1894. if (units === undefined || units === 'millisecond') {
  1895. return this;
  1896. }
  1897. return this.startOf(units).add(1, (units === 'isoWeek' ? 'week' : units)).subtract(1, 'ms');
  1898. }
  1899. function to_type__valueOf () {
  1900. return +this._d - ((this._offset || 0) * 60000);
  1901. }
  1902. function unix () {
  1903. return Math.floor(+this / 1000);
  1904. }
  1905. function toDate () {
  1906. return this._offset ? new Date(+this) : this._d;
  1907. }
  1908. function toArray () {
  1909. var m = this;
  1910. return [m.year(), m.month(), m.date(), m.hour(), m.minute(), m.second(), m.millisecond()];
  1911. }
  1912. function toObject () {
  1913. var m = this;
  1914. return {
  1915. years: m.year(),
  1916. months: m.month(),
  1917. date: m.date(),
  1918. hours: m.hours(),
  1919. minutes: m.minutes(),
  1920. seconds: m.seconds(),
  1921. milliseconds: m.milliseconds()
  1922. };
  1923. }
  1924. function toJSON () {
  1925. // JSON.stringify(new Date(NaN)) === 'null'
  1926. return this.isValid() ? this.toISOString() : 'null';
  1927. }
  1928. function moment_valid__isValid () {
  1929. return valid__isValid(this);
  1930. }
  1931. function parsingFlags () {
  1932. return extend({}, getParsingFlags(this));
  1933. }
  1934. function invalidAt () {
  1935. return getParsingFlags(this).overflow;
  1936. }
  1937. function creationData() {
  1938. return {
  1939. input: this._i,
  1940. format: this._f,
  1941. locale: this._locale,
  1942. isUTC: this._isUTC,
  1943. strict: this._strict
  1944. };
  1945. }
  1946. // FORMATTING
  1947. addFormatToken(0, ['gg', 2], 0, function () {
  1948. return this.weekYear() % 100;
  1949. });
  1950. addFormatToken(0, ['GG', 2], 0, function () {
  1951. return this.isoWeekYear() % 100;
  1952. });
  1953. function addWeekYearFormatToken (token, getter) {
  1954. addFormatToken(0, [token, token.length], 0, getter);
  1955. }
  1956. addWeekYearFormatToken('gggg', 'weekYear');
  1957. addWeekYearFormatToken('ggggg', 'weekYear');
  1958. addWeekYearFormatToken('GGGG', 'isoWeekYear');
  1959. addWeekYearFormatToken('GGGGG', 'isoWeekYear');
  1960. // ALIASES
  1961. addUnitAlias('weekYear', 'gg');
  1962. addUnitAlias('isoWeekYear', 'GG');
  1963. // PARSING
  1964. addRegexToken('G', matchSigned);
  1965. addRegexToken('g', matchSigned);
  1966. addRegexToken('GG', match1to2, match2);
  1967. addRegexToken('gg', match1to2, match2);
  1968. addRegexToken('GGGG', match1to4, match4);
  1969. addRegexToken('gggg', match1to4, match4);
  1970. addRegexToken('GGGGG', match1to6, match6);
  1971. addRegexToken('ggggg', match1to6, match6);
  1972. addWeekParseToken(['gggg', 'ggggg', 'GGGG', 'GGGGG'], function (input, week, config, token) {
  1973. week[token.substr(0, 2)] = toInt(input);
  1974. });
  1975. addWeekParseToken(['gg', 'GG'], function (input, week, config, token) {
  1976. week[token] = utils_hooks__hooks.parseTwoDigitYear(input);
  1977. });
  1978. // MOMENTS
  1979. function getSetWeekYear (input) {
  1980. return getSetWeekYearHelper.call(this,
  1981. input,
  1982. this.week(),
  1983. this.weekday(),
  1984. this.localeData()._week.dow,
  1985. this.localeData()._week.doy);
  1986. }
  1987. function getSetISOWeekYear (input) {
  1988. return getSetWeekYearHelper.call(this,
  1989. input, this.isoWeek(), this.isoWeekday(), 1, 4);
  1990. }
  1991. function getISOWeeksInYear () {
  1992. return weeksInYear(this.year(), 1, 4);
  1993. }
  1994. function getWeeksInYear () {
  1995. var weekInfo = this.localeData()._week;
  1996. return weeksInYear(this.year(), weekInfo.dow, weekInfo.doy);
  1997. }
  1998. function getSetWeekYearHelper(input, week, weekday, dow, doy) {
  1999. var weeksTarget;
  2000. if (input == null) {
  2001. return weekOfYear(this, dow, doy).year;
  2002. } else {
  2003. weeksTarget = weeksInYear(input, dow, doy);
  2004. if (week > weeksTarget) {
  2005. week = weeksTarget;
  2006. }
  2007. return setWeekAll.call(this, input, week, weekday, dow, doy);
  2008. }
  2009. }
  2010. function setWeekAll(weekYear, week, weekday, dow, doy) {
  2011. var dayOfYearData = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy),
  2012. date = createUTCDate(dayOfYearData.year, 0, dayOfYearData.dayOfYear);
  2013. // console.log("got", weekYear, week, weekday, "set", date.toISOString());
  2014. this.year(date.getUTCFullYear());
  2015. this.month(date.getUTCMonth());
  2016. this.date(date.getUTCDate());
  2017. return this;
  2018. }
  2019. // FORMATTING
  2020. addFormatToken('Q', 0, 'Qo', 'quarter');
  2021. // ALIASES
  2022. addUnitAlias('quarter', 'Q');
  2023. // PARSING
  2024. addRegexToken('Q', match1);
  2025. addParseToken('Q', function (input, array) {
  2026. array[MONTH] = (toInt(input) - 1) * 3;
  2027. });
  2028. // MOMENTS
  2029. function getSetQuarter (input) {
  2030. return input == null ? Math.ceil((this.month() + 1) / 3) : this.month((input - 1) * 3 + this.month() % 3);
  2031. }
  2032. // FORMATTING
  2033. addFormatToken('w', ['ww', 2], 'wo', 'week');
  2034. addFormatToken('W', ['WW', 2], 'Wo', 'isoWeek');
  2035. // ALIASES
  2036. addUnitAlias('week', 'w');
  2037. addUnitAlias('isoWeek', 'W');
  2038. // PARSING
  2039. addRegexToken('w', match1to2);
  2040. addRegexToken('ww', match1to2, match2);
  2041. addRegexToken('W', match1to2);
  2042. addRegexToken('WW', match1to2, match2);
  2043. addWeekParseToken(['w', 'ww', 'W', 'WW'], function (input, week, config, token) {
  2044. week[token.substr(0, 1)] = toInt(input);
  2045. });
  2046. // HELPERS
  2047. // LOCALES
  2048. function localeWeek (mom) {
  2049. return weekOfYear(mom, this._week.dow, this._week.doy).week;
  2050. }
  2051. var defaultLocaleWeek = {
  2052. dow : 0, // Sunday is the first day of the week.
  2053. doy : 6 // The week that contains Jan 1st is the first week of the year.
  2054. };
  2055. function localeFirstDayOfWeek () {
  2056. return this._week.dow;
  2057. }
  2058. function localeFirstDayOfYear () {
  2059. return this._week.doy;
  2060. }
  2061. // MOMENTS
  2062. function getSetWeek (input) {
  2063. var week = this.localeData().week(this);
  2064. return input == null ? week : this.add((input - week) * 7, 'd');
  2065. }
  2066. function getSetISOWeek (input) {
  2067. var week = weekOfYear(this, 1, 4).week;
  2068. return input == null ? week : this.add((input - week) * 7, 'd');
  2069. }
  2070. // FORMATTING
  2071. addFormatToken('D', ['DD', 2], 'Do', 'date');
  2072. // ALIASES
  2073. addUnitAlias('date', 'D');
  2074. // PARSING
  2075. addRegexToken('D', match1to2);
  2076. addRegexToken('DD', match1to2, match2);
  2077. addRegexToken('Do', function (isStrict, locale) {
  2078. return isStrict ? locale._ordinalParse : locale._ordinalParseLenient;
  2079. });
  2080. addParseToken(['D', 'DD'], DATE);
  2081. addParseToken('Do', function (input, array) {
  2082. array[DATE] = toInt(input.match(match1to2)[0], 10);
  2083. });
  2084. // MOMENTS
  2085. var getSetDayOfMonth = makeGetSet('Date', true);
  2086. // FORMATTING
  2087. addFormatToken('d', 0, 'do', 'day');
  2088. addFormatToken('dd', 0, 0, function (format) {
  2089. return this.localeData().weekdaysMin(this, format);
  2090. });
  2091. addFormatToken('ddd', 0, 0, function (format) {
  2092. return this.localeData().weekdaysShort(this, format);
  2093. });
  2094. addFormatToken('dddd', 0, 0, function (format) {
  2095. return this.localeData().weekdays(this, format);
  2096. });
  2097. addFormatToken('e', 0, 0, 'weekday');
  2098. addFormatToken('E', 0, 0, 'isoWeekday');
  2099. // ALIASES
  2100. addUnitAlias('day', 'd');
  2101. addUnitAlias('weekday', 'e');
  2102. addUnitAlias('isoWeekday', 'E');
  2103. // PARSING
  2104. addRegexToken('d', match1to2);
  2105. addRegexToken('e', match1to2);
  2106. addRegexToken('E', match1to2);
  2107. addRegexToken('dd', matchWord);
  2108. addRegexToken('ddd', matchWord);
  2109. addRegexToken('dddd', matchWord);
  2110. addWeekParseToken(['dd', 'ddd', 'dddd'], function (input, week, config, token) {
  2111. var weekday = config._locale.weekdaysParse(input, token, config._strict);
  2112. // if we didn't get a weekday name, mark the date as invalid
  2113. if (weekday != null) {
  2114. week.d = weekday;
  2115. } else {
  2116. getParsingFlags(config).invalidWeekday = input;
  2117. }
  2118. });
  2119. addWeekParseToken(['d', 'e', 'E'], function (input, week, config, token) {
  2120. week[token] = toInt(input);
  2121. });
  2122. // HELPERS
  2123. function parseWeekday(input, locale) {
  2124. if (typeof input !== 'string') {
  2125. return input;
  2126. }
  2127. if (!isNaN(input)) {
  2128. return parseInt(input, 10);
  2129. }
  2130. input = locale.weekdaysParse(input);
  2131. if (typeof input === 'number') {
  2132. return input;
  2133. }
  2134. return null;
  2135. }
  2136. // LOCALES
  2137. var defaultLocaleWeekdays = 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_');
  2138. function localeWeekdays (m, format) {
  2139. return isArray(this._weekdays) ? this._weekdays[m.day()] :
  2140. this._weekdays[this._weekdays.isFormat.test(format) ? 'format' : 'standalone'][m.day()];
  2141. }
  2142. var defaultLocaleWeekdaysShort = 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_');
  2143. function localeWeekdaysShort (m) {
  2144. return this._weekdaysShort[m.day()];
  2145. }
  2146. var defaultLocaleWeekdaysMin = 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_');
  2147. function localeWeekdaysMin (m) {
  2148. return this._weekdaysMin[m.day()];
  2149. }
  2150. function localeWeekdaysParse (weekdayName, format, strict) {
  2151. var i, mom, regex;
  2152. if (!this._weekdaysParse) {
  2153. this._weekdaysParse = [];
  2154. this._minWeekdaysParse = [];
  2155. this._shortWeekdaysParse = [];
  2156. this._fullWeekdaysParse = [];
  2157. }
  2158. for (i = 0; i < 7; i++) {
  2159. // make the regex if we don't have it already
  2160. mom = local__createLocal([2000, 1]).day(i);
  2161. if (strict && !this._fullWeekdaysParse[i]) {
  2162. this._fullWeekdaysParse[i] = new RegExp('^' + this.weekdays(mom, '').replace('.', '\.?') + '$', 'i');
  2163. this._shortWeekdaysParse[i] = new RegExp('^' + this.weekdaysShort(mom, '').replace('.', '\.?') + '$', 'i');
  2164. this._minWeekdaysParse[i] = new RegExp('^' + this.weekdaysMin(mom, '').replace('.', '\.?') + '$', 'i');
  2165. }
  2166. if (!this._weekdaysParse[i]) {
  2167. regex = '^' + this.weekdays(mom, '') + '|^' + this.weekdaysShort(mom, '') + '|^' + this.weekdaysMin(mom, '');
  2168. this._weekdaysParse[i] = new RegExp(regex.replace('.', ''), 'i');
  2169. }
  2170. // test the regex
  2171. if (strict && format === 'dddd' && this._fullWeekdaysParse[i].test(weekdayName)) {
  2172. return i;
  2173. } else if (strict && format === 'ddd' && this._shortWeekdaysParse[i].test(weekdayName)) {
  2174. return i;
  2175. } else if (strict && format === 'dd' && this._minWeekdaysParse[i].test(weekdayName)) {
  2176. return i;
  2177. } else if (!strict && this._weekdaysParse[i].test(weekdayName)) {
  2178. return i;
  2179. }
  2180. }
  2181. }
  2182. // MOMENTS
  2183. function getSetDayOfWeek (input) {
  2184. if (!this.isValid()) {
  2185. return input != null ? this : NaN;
  2186. }
  2187. var day = this._isUTC ? this._d.getUTCDay() : this._d.getDay();
  2188. if (input != null) {
  2189. input = parseWeekday(input, this.localeData());
  2190. return this.add(input - day, 'd');
  2191. } else {
  2192. return day;
  2193. }
  2194. }
  2195. function getSetLocaleDayOfWeek (input) {
  2196. if (!this.isValid()) {
  2197. return input != null ? this : NaN;
  2198. }
  2199. var weekday = (this.day() + 7 - this.localeData()._week.dow) % 7;
  2200. return input == null ? weekday : this.add(input - weekday, 'd');
  2201. }
  2202. function getSetISODayOfWeek (input) {
  2203. if (!this.isValid()) {
  2204. return input != null ? this : NaN;
  2205. }
  2206. // behaves the same as moment#day except
  2207. // as a getter, returns 7 instead of 0 (1-7 range instead of 0-6)
  2208. // as a setter, sunday should belong to the previous week.
  2209. return input == null ? this.day() || 7 : this.day(this.day() % 7 ? input : input - 7);
  2210. }
  2211. // FORMATTING
  2212. addFormatToken('DDD', ['DDDD', 3], 'DDDo', 'dayOfYear');
  2213. // ALIASES
  2214. addUnitAlias('dayOfYear', 'DDD');
  2215. // PARSING
  2216. addRegexToken('DDD', match1to3);
  2217. addRegexToken('DDDD', match3);
  2218. addParseToken(['DDD', 'DDDD'], function (input, array, config) {
  2219. config._dayOfYear = toInt(input);
  2220. });
  2221. // HELPERS
  2222. // MOMENTS
  2223. function getSetDayOfYear (input) {
  2224. var dayOfYear = Math.round((this.clone().startOf('day') - this.clone().startOf('year')) / 864e5) + 1;
  2225. return input == null ? dayOfYear : this.add((input - dayOfYear), 'd');
  2226. }
  2227. // FORMATTING
  2228. function hFormat() {
  2229. return this.hours() % 12 || 12;
  2230. }
  2231. addFormatToken('H', ['HH', 2], 0, 'hour');
  2232. addFormatToken('h', ['hh', 2], 0, hFormat);
  2233. addFormatToken('hmm', 0, 0, function () {
  2234. return '' + hFormat.apply(this) + zeroFill(this.minutes(), 2);
  2235. });
  2236. addFormatToken('hmmss', 0, 0, function () {
  2237. return '' + hFormat.apply(this) + zeroFill(this.minutes(), 2) +
  2238. zeroFill(this.seconds(), 2);
  2239. });
  2240. addFormatToken('Hmm', 0, 0, function () {
  2241. return '' + this.hours() + zeroFill(this.minutes(), 2);
  2242. });
  2243. addFormatToken('Hmmss', 0, 0, function () {
  2244. return '' + this.hours() + zeroFill(this.minutes(), 2) +
  2245. zeroFill(this.seconds(), 2);
  2246. });
  2247. function meridiem (token, lowercase) {
  2248. addFormatToken(token, 0, 0, function () {
  2249. return this.localeData().meridiem(this.hours(), this.minutes(), lowercase);
  2250. });
  2251. }
  2252. meridiem('a', true);
  2253. meridiem('A', false);
  2254. // ALIASES
  2255. addUnitAlias('hour', 'h');
  2256. // PARSING
  2257. function matchMeridiem (isStrict, locale) {
  2258. return locale._meridiemParse;
  2259. }
  2260. addRegexToken('a', matchMeridiem);
  2261. addRegexToken('A', matchMeridiem);
  2262. addRegexToken('H', match1to2);
  2263. addRegexToken('h', match1to2);
  2264. addRegexToken('HH', match1to2, match2);
  2265. addRegexToken('hh', match1to2, match2);
  2266. addRegexToken('hmm', match3to4);
  2267. addRegexToken('hmmss', match5to6);
  2268. addRegexToken('Hmm', match3to4);
  2269. addRegexToken('Hmmss', match5to6);
  2270. addParseToken(['H', 'HH'], HOUR);
  2271. addParseToken(['a', 'A'], function (input, array, config) {
  2272. config._isPm = config._locale.isPM(input);
  2273. config._meridiem = input;
  2274. });
  2275. addParseToken(['h', 'hh'], function (input, array, config) {
  2276. array[HOUR] = toInt(input);
  2277. getParsingFlags(config).bigHour = true;
  2278. });
  2279. addParseToken('hmm', function (input, array, config) {
  2280. var pos = input.length - 2;
  2281. array[HOUR] = toInt(input.substr(0, pos));
  2282. array[MINUTE] = toInt(input.substr(pos));
  2283. getParsingFlags(config).bigHour = true;
  2284. });
  2285. addParseToken('hmmss', function (input, array, config) {
  2286. var pos1 = input.length - 4;
  2287. var pos2 = input.length - 2;
  2288. array[HOUR] = toInt(input.substr(0, pos1));
  2289. array[MINUTE] = toInt(input.substr(pos1, 2));
  2290. array[SECOND] = toInt(input.substr(pos2));
  2291. getParsingFlags(config).bigHour = true;
  2292. });
  2293. addParseToken('Hmm', function (input, array, config) {
  2294. var pos = input.length - 2;
  2295. array[HOUR] = toInt(input.substr(0, pos));
  2296. array[MINUTE] = toInt(input.substr(pos));
  2297. });
  2298. addParseToken('Hmmss', function (input, array, config) {
  2299. var pos1 = input.length - 4;
  2300. var pos2 = input.length - 2;
  2301. array[HOUR] = toInt(input.substr(0, pos1));
  2302. array[MINUTE] = toInt(input.substr(pos1, 2));
  2303. array[SECOND] = toInt(input.substr(pos2));
  2304. });
  2305. // LOCALES
  2306. function localeIsPM (input) {
  2307. // IE8 Quirks Mode & IE7 Standards Mode do not allow accessing strings like arrays
  2308. // Using charAt should be more compatible.
  2309. return ((input + '').toLowerCase().charAt(0) === 'p');
  2310. }
  2311. var defaultLocaleMeridiemParse = /[ap]\.?m?\.?/i;
  2312. function localeMeridiem (hours, minutes, isLower) {
  2313. if (hours > 11) {
  2314. return isLower ? 'pm' : 'PM';
  2315. } else {
  2316. return isLower ? 'am' : 'AM';
  2317. }
  2318. }
  2319. // MOMENTS
  2320. // Setting the hour should keep the time, because the user explicitly
  2321. // specified which hour he wants. So trying to maintain the same hour (in
  2322. // a new timezone) makes sense. Adding/subtracting hours does not follow
  2323. // this rule.
  2324. var getSetHour = makeGetSet('Hours', true);
  2325. // FORMATTING
  2326. addFormatToken('m', ['mm', 2], 0, 'minute');
  2327. // ALIASES
  2328. addUnitAlias('minute', 'm');
  2329. // PARSING
  2330. addRegexToken('m', match1to2);
  2331. addRegexToken('mm', match1to2, match2);
  2332. addParseToken(['m', 'mm'], MINUTE);
  2333. // MOMENTS
  2334. var getSetMinute = makeGetSet('Minutes', false);
  2335. // FORMATTING
  2336. addFormatToken('s', ['ss', 2], 0, 'second');
  2337. // ALIASES
  2338. addUnitAlias('second', 's');
  2339. // PARSING
  2340. addRegexToken('s', match1to2);
  2341. addRegexToken('ss', match1to2, match2);
  2342. addParseToken(['s', 'ss'], SECOND);
  2343. // MOMENTS
  2344. var getSetSecond = makeGetSet('Seconds', false);
  2345. // FORMATTING
  2346. addFormatToken('S', 0, 0, function () {
  2347. return ~~(this.millisecond() / 100);
  2348. });
  2349. addFormatToken(0, ['SS', 2], 0, function () {
  2350. return ~~(this.millisecond() / 10);
  2351. });
  2352. addFormatToken(0, ['SSS', 3], 0, 'millisecond');
  2353. addFormatToken(0, ['SSSS', 4], 0, function () {
  2354. return this.millisecond() * 10;
  2355. });
  2356. addFormatToken(0, ['SSSSS', 5], 0, function () {
  2357. return this.millisecond() * 100;
  2358. });
  2359. addFormatToken(0, ['SSSSSS', 6], 0, function () {
  2360. return this.millisecond() * 1000;
  2361. });
  2362. addFormatToken(0, ['SSSSSSS', 7], 0, function () {
  2363. return this.millisecond() * 10000;
  2364. });
  2365. addFormatToken(0, ['SSSSSSSS', 8], 0, function () {
  2366. return this.millisecond() * 100000;
  2367. });
  2368. addFormatToken(0, ['SSSSSSSSS', 9], 0, function () {
  2369. return this.millisecond() * 1000000;
  2370. });
  2371. // ALIASES
  2372. addUnitAlias('millisecond', 'ms');
  2373. // PARSING
  2374. addRegexToken('S', match1to3, match1);
  2375. addRegexToken('SS', match1to3, match2);
  2376. addRegexToken('SSS', match1to3, match3);
  2377. var token;
  2378. for (token = 'SSSS'; token.length <= 9; token += 'S') {
  2379. addRegexToken(token, matchUnsigned);
  2380. }
  2381. function parseMs(input, array) {
  2382. array[MILLISECOND] = toInt(('0.' + input) * 1000);
  2383. }
  2384. for (token = 'S'; token.length <= 9; token += 'S') {
  2385. addParseToken(token, parseMs);
  2386. }
  2387. // MOMENTS
  2388. var getSetMillisecond = makeGetSet('Milliseconds', false);
  2389. // FORMATTING
  2390. addFormatToken('z', 0, 0, 'zoneAbbr');
  2391. addFormatToken('zz', 0, 0, 'zoneName');
  2392. // MOMENTS
  2393. function getZoneAbbr () {
  2394. return this._isUTC ? 'UTC' : '';
  2395. }
  2396. function getZoneName () {
  2397. return this._isUTC ? 'Coordinated Universal Time' : '';
  2398. }
  2399. var momentPrototype__proto = Moment.prototype;
  2400. momentPrototype__proto.add = add_subtract__add;
  2401. momentPrototype__proto.calendar = moment_calendar__calendar;
  2402. momentPrototype__proto.clone = clone;
  2403. momentPrototype__proto.diff = diff;
  2404. momentPrototype__proto.endOf = endOf;
  2405. momentPrototype__proto.format = format;
  2406. momentPrototype__proto.from = from;
  2407. momentPrototype__proto.fromNow = fromNow;
  2408. momentPrototype__proto.to = to;
  2409. momentPrototype__proto.toNow = toNow;
  2410. momentPrototype__proto.get = getSet;
  2411. momentPrototype__proto.invalidAt = invalidAt;
  2412. momentPrototype__proto.isAfter = isAfter;
  2413. momentPrototype__proto.isBefore = isBefore;
  2414. momentPrototype__proto.isBetween = isBetween;
  2415. momentPrototype__proto.isSame = isSame;
  2416. momentPrototype__proto.isSameOrAfter = isSameOrAfter;
  2417. momentPrototype__proto.isSameOrBefore = isSameOrBefore;
  2418. momentPrototype__proto.isValid = moment_valid__isValid;
  2419. momentPrototype__proto.lang = lang;
  2420. momentPrototype__proto.locale = locale;
  2421. momentPrototype__proto.localeData = localeData;
  2422. momentPrototype__proto.max = prototypeMax;
  2423. momentPrototype__proto.min = prototypeMin;
  2424. momentPrototype__proto.parsingFlags = parsingFlags;
  2425. momentPrototype__proto.set = getSet;
  2426. momentPrototype__proto.startOf = startOf;
  2427. momentPrototype__proto.subtract = add_subtract__subtract;
  2428. momentPrototype__proto.toArray = toArray;
  2429. momentPrototype__proto.toObject = toObject;
  2430. momentPrototype__proto.toDate = toDate;
  2431. momentPrototype__proto.toISOString = moment_format__toISOString;
  2432. momentPrototype__proto.toJSON = toJSON;
  2433. momentPrototype__proto.toString = toString;
  2434. momentPrototype__proto.unix = unix;
  2435. momentPrototype__proto.valueOf = to_type__valueOf;
  2436. momentPrototype__proto.creationData = creationData;
  2437. // Year
  2438. momentPrototype__proto.year = getSetYear;
  2439. momentPrototype__proto.isLeapYear = getIsLeapYear;
  2440. // Week Year
  2441. momentPrototype__proto.weekYear = getSetWeekYear;
  2442. momentPrototype__proto.isoWeekYear = getSetISOWeekYear;
  2443. // Quarter
  2444. momentPrototype__proto.quarter = momentPrototype__proto.quarters = getSetQuarter;
  2445. // Month
  2446. momentPrototype__proto.month = getSetMonth;
  2447. momentPrototype__proto.daysInMonth = getDaysInMonth;
  2448. // Week
  2449. momentPrototype__proto.week = momentPrototype__proto.weeks = getSetWeek;
  2450. momentPrototype__proto.isoWeek = momentPrototype__proto.isoWeeks = getSetISOWeek;
  2451. momentPrototype__proto.weeksInYear = getWeeksInYear;
  2452. momentPrototype__proto.isoWeeksInYear = getISOWeeksInYear;
  2453. // Day
  2454. momentPrototype__proto.date = getSetDayOfMonth;
  2455. momentPrototype__proto.day = momentPrototype__proto.days = getSetDayOfWeek;
  2456. momentPrototype__proto.weekday = getSetLocaleDayOfWeek;
  2457. momentPrototype__proto.isoWeekday = getSetISODayOfWeek;
  2458. momentPrototype__proto.dayOfYear = getSetDayOfYear;
  2459. // Hour
  2460. momentPrototype__proto.hour = momentPrototype__proto.hours = getSetHour;
  2461. // Minute
  2462. momentPrototype__proto.minute = momentPrototype__proto.minutes = getSetMinute;
  2463. // Second
  2464. momentPrototype__proto.second = momentPrototype__proto.seconds = getSetSecond;
  2465. // Millisecond
  2466. momentPrototype__proto.millisecond = momentPrototype__proto.milliseconds = getSetMillisecond;
  2467. // Offset
  2468. momentPrototype__proto.utcOffset = getSetOffset;
  2469. momentPrototype__proto.utc = setOffsetToUTC;
  2470. momentPrototype__proto.local = setOffsetToLocal;
  2471. momentPrototype__proto.parseZone = setOffsetToParsedOffset;
  2472. momentPrototype__proto.hasAlignedHourOffset = hasAlignedHourOffset;
  2473. momentPrototype__proto.isDST = isDaylightSavingTime;
  2474. momentPrototype__proto.isDSTShifted = isDaylightSavingTimeShifted;
  2475. momentPrototype__proto.isLocal = isLocal;
  2476. momentPrototype__proto.isUtcOffset = isUtcOffset;
  2477. momentPrototype__proto.isUtc = isUtc;
  2478. momentPrototype__proto.isUTC = isUtc;
  2479. // Timezone
  2480. momentPrototype__proto.zoneAbbr = getZoneAbbr;
  2481. momentPrototype__proto.zoneName = getZoneName;
  2482. // Deprecations
  2483. momentPrototype__proto.dates = deprecate('dates accessor is deprecated. Use date instead.', getSetDayOfMonth);
  2484. momentPrototype__proto.months = deprecate('months accessor is deprecated. Use month instead', getSetMonth);
  2485. momentPrototype__proto.years = deprecate('years accessor is deprecated. Use year instead', getSetYear);
  2486. momentPrototype__proto.zone = deprecate('moment().zone is deprecated, use moment().utcOffset instead. https://github.com/moment/moment/issues/1779', getSetZone);
  2487. var momentPrototype = momentPrototype__proto;
  2488. function moment__createUnix (input) {
  2489. return local__createLocal(input * 1000);
  2490. }
  2491. function moment__createInZone () {
  2492. return local__createLocal.apply(null, arguments).parseZone();
  2493. }
  2494. var defaultCalendar = {
  2495. sameDay : '[Today at] LT',
  2496. nextDay : '[Tomorrow at] LT',
  2497. nextWeek : 'dddd [at] LT',
  2498. lastDay : '[Yesterday at] LT',
  2499. lastWeek : '[Last] dddd [at] LT',
  2500. sameElse : 'L'
  2501. };
  2502. function locale_calendar__calendar (key, mom, now) {
  2503. var output = this._calendar[key];
  2504. return isFunction(output) ? output.call(mom, now) : output;
  2505. }
  2506. var defaultLongDateFormat = {
  2507. LTS : 'h:mm:ss A',
  2508. LT : 'h:mm A',
  2509. L : 'MM/DD/YYYY',
  2510. LL : 'MMMM D, YYYY',
  2511. LLL : 'MMMM D, YYYY h:mm A',
  2512. LLLL : 'dddd, MMMM D, YYYY h:mm A'
  2513. };
  2514. function longDateFormat (key) {
  2515. var format = this._longDateFormat[key],
  2516. formatUpper = this._longDateFormat[key.toUpperCase()];
  2517. if (format || !formatUpper) {
  2518. return format;
  2519. }
  2520. this._longDateFormat[key] = formatUpper.replace(/MMMM|MM|DD|dddd/g, function (val) {
  2521. return val.slice(1);
  2522. });
  2523. return this._longDateFormat[key];
  2524. }
  2525. var defaultInvalidDate = 'Invalid date';
  2526. function invalidDate () {
  2527. return this._invalidDate;
  2528. }
  2529. var defaultOrdinal = '%d';
  2530. var defaultOrdinalParse = /\d{1,2}/;
  2531. function ordinal (number) {
  2532. return this._ordinal.replace('%d', number);
  2533. }
  2534. function preParsePostFormat (string) {
  2535. return string;
  2536. }
  2537. var defaultRelativeTime = {
  2538. future : 'in %s',
  2539. past : '%s ago',
  2540. s : 'a few seconds',
  2541. m : 'a minute',
  2542. mm : '%d minutes',
  2543. h : 'an hour',
  2544. hh : '%d hours',
  2545. d : 'a day',
  2546. dd : '%d days',
  2547. M : 'a month',
  2548. MM : '%d months',
  2549. y : 'a year',
  2550. yy : '%d years'
  2551. };
  2552. function relative__relativeTime (number, withoutSuffix, string, isFuture) {
  2553. var output = this._relativeTime[string];
  2554. return (isFunction(output)) ?
  2555. output(number, withoutSuffix, string, isFuture) :
  2556. output.replace(/%d/i, number);
  2557. }
  2558. function pastFuture (diff, output) {
  2559. var format = this._relativeTime[diff > 0 ? 'future' : 'past'];
  2560. return isFunction(format) ? format(output) : format.replace(/%s/i, output);
  2561. }
  2562. function locale_set__set (config) {
  2563. var prop, i;
  2564. for (i in config) {
  2565. prop = config[i];
  2566. if (isFunction(prop)) {
  2567. this[i] = prop;
  2568. } else {
  2569. this['_' + i] = prop;
  2570. }
  2571. }
  2572. // Lenient ordinal parsing accepts just a number in addition to
  2573. // number + (possibly) stuff coming from _ordinalParseLenient.
  2574. this._ordinalParseLenient = new RegExp(this._ordinalParse.source + '|' + (/\d{1,2}/).source);
  2575. }
  2576. var prototype__proto = Locale.prototype;
  2577. prototype__proto._calendar = defaultCalendar;
  2578. prototype__proto.calendar = locale_calendar__calendar;
  2579. prototype__proto._longDateFormat = defaultLongDateFormat;
  2580. prototype__proto.longDateFormat = longDateFormat;
  2581. prototype__proto._invalidDate = defaultInvalidDate;
  2582. prototype__proto.invalidDate = invalidDate;
  2583. prototype__proto._ordinal = defaultOrdinal;
  2584. prototype__proto.ordinal = ordinal;
  2585. prototype__proto._ordinalParse = defaultOrdinalParse;
  2586. prototype__proto.preparse = preParsePostFormat;
  2587. prototype__proto.postformat = preParsePostFormat;
  2588. prototype__proto._relativeTime = defaultRelativeTime;
  2589. prototype__proto.relativeTime = relative__relativeTime;
  2590. prototype__proto.pastFuture = pastFuture;
  2591. prototype__proto.set = locale_set__set;
  2592. // Month
  2593. prototype__proto.months = localeMonths;
  2594. prototype__proto._months = defaultLocaleMonths;
  2595. prototype__proto.monthsShort = localeMonthsShort;
  2596. prototype__proto._monthsShort = defaultLocaleMonthsShort;
  2597. prototype__proto.monthsParse = localeMonthsParse;
  2598. prototype__proto._monthsRegex = defaultMonthsRegex;
  2599. prototype__proto.monthsRegex = monthsRegex;
  2600. prototype__proto._monthsShortRegex = defaultMonthsShortRegex;
  2601. prototype__proto.monthsShortRegex = monthsShortRegex;
  2602. // Week
  2603. prototype__proto.week = localeWeek;
  2604. prototype__proto._week = defaultLocaleWeek;
  2605. prototype__proto.firstDayOfYear = localeFirstDayOfYear;
  2606. prototype__proto.firstDayOfWeek = localeFirstDayOfWeek;
  2607. // Day of Week
  2608. prototype__proto.weekdays = localeWeekdays;
  2609. prototype__proto._weekdays = defaultLocaleWeekdays;
  2610. prototype__proto.weekdaysMin = localeWeekdaysMin;
  2611. prototype__proto._weekdaysMin = defaultLocaleWeekdaysMin;
  2612. prototype__proto.weekdaysShort = localeWeekdaysShort;
  2613. prototype__proto._weekdaysShort = defaultLocaleWeekdaysShort;
  2614. prototype__proto.weekdaysParse = localeWeekdaysParse;
  2615. // Hours
  2616. prototype__proto.isPM = localeIsPM;
  2617. prototype__proto._meridiemParse = defaultLocaleMeridiemParse;
  2618. prototype__proto.meridiem = localeMeridiem;
  2619. function lists__get (format, index, field, setter) {
  2620. var locale = locale_locales__getLocale();
  2621. var utc = create_utc__createUTC().set(setter, index);
  2622. return locale[field](utc, format);
  2623. }
  2624. function list (format, index, field, count, setter) {
  2625. if (typeof format === 'number') {
  2626. index = format;
  2627. format = undefined;
  2628. }
  2629. format = format || '';
  2630. if (index != null) {
  2631. return lists__get(format, index, field, setter);
  2632. }
  2633. var i;
  2634. var out = [];
  2635. for (i = 0; i < count; i++) {
  2636. out[i] = lists__get(format, i, field, setter);
  2637. }
  2638. return out;
  2639. }
  2640. function lists__listMonths (format, index) {
  2641. return list(format, index, 'months', 12, 'month');
  2642. }
  2643. function lists__listMonthsShort (format, index) {
  2644. return list(format, index, 'monthsShort', 12, 'month');
  2645. }
  2646. function lists__listWeekdays (format, index) {
  2647. return list(format, index, 'weekdays', 7, 'day');
  2648. }
  2649. function lists__listWeekdaysShort (format, index) {
  2650. return list(format, index, 'weekdaysShort', 7, 'day');
  2651. }
  2652. function lists__listWeekdaysMin (format, index) {
  2653. return list(format, index, 'weekdaysMin', 7, 'day');
  2654. }
  2655. locale_locales__getSetGlobalLocale('en', {
  2656. ordinalParse: /\d{1,2}(th|st|nd|rd)/,
  2657. ordinal : function (number) {
  2658. var b = number % 10,
  2659. output = (toInt(number % 100 / 10) === 1) ? 'th' :
  2660. (b === 1) ? 'st' :
  2661. (b === 2) ? 'nd' :
  2662. (b === 3) ? 'rd' : 'th';
  2663. return number + output;
  2664. }
  2665. });
  2666. // Side effect imports
  2667. utils_hooks__hooks.lang = deprecate('moment.lang is deprecated. Use moment.locale instead.', locale_locales__getSetGlobalLocale);
  2668. utils_hooks__hooks.langData = deprecate('moment.langData is deprecated. Use moment.localeData instead.', locale_locales__getLocale);
  2669. var mathAbs = Math.abs;
  2670. function duration_abs__abs () {
  2671. var data = this._data;
  2672. this._milliseconds = mathAbs(this._milliseconds);
  2673. this._days = mathAbs(this._days);
  2674. this._months = mathAbs(this._months);
  2675. data.milliseconds = mathAbs(data.milliseconds);
  2676. data.seconds = mathAbs(data.seconds);
  2677. data.minutes = mathAbs(data.minutes);
  2678. data.hours = mathAbs(data.hours);
  2679. data.months = mathAbs(data.months);
  2680. data.years = mathAbs(data.years);
  2681. return this;
  2682. }
  2683. function duration_add_subtract__addSubtract (duration, input, value, direction) {
  2684. var other = create__createDuration(input, value);
  2685. duration._milliseconds += direction * other._milliseconds;
  2686. duration._days += direction * other._days;
  2687. duration._months += direction * other._months;
  2688. return duration._bubble();
  2689. }
  2690. // supports only 2.0-style add(1, 's') or add(duration)
  2691. function duration_add_subtract__add (input, value) {
  2692. return duration_add_subtract__addSubtract(this, input, value, 1);
  2693. }
  2694. // supports only 2.0-style subtract(1, 's') or subtract(duration)
  2695. function duration_add_subtract__subtract (input, value) {
  2696. return duration_add_subtract__addSubtract(this, input, value, -1);
  2697. }
  2698. function absCeil (number) {
  2699. if (number < 0) {
  2700. return Math.floor(number);
  2701. } else {
  2702. return Math.ceil(number);
  2703. }
  2704. }
  2705. function bubble () {
  2706. var milliseconds = this._milliseconds;
  2707. var days = this._days;
  2708. var months = this._months;
  2709. var data = this._data;
  2710. var seconds, minutes, hours, years, monthsFromDays;
  2711. // if we have a mix of positive and negative values, bubble down first
  2712. // check: https://github.com/moment/moment/issues/2166
  2713. if (!((milliseconds >= 0 && days >= 0 && months >= 0) ||
  2714. (milliseconds <= 0 && days <= 0 && months <= 0))) {
  2715. milliseconds += absCeil(monthsToDays(months) + days) * 864e5;
  2716. days = 0;
  2717. months = 0;
  2718. }
  2719. // The following code bubbles up values, see the tests for
  2720. // examples of what that means.
  2721. data.milliseconds = milliseconds % 1000;
  2722. seconds = absFloor(milliseconds / 1000);
  2723. data.seconds = seconds % 60;
  2724. minutes = absFloor(seconds / 60);
  2725. data.minutes = minutes % 60;
  2726. hours = absFloor(minutes / 60);
  2727. data.hours = hours % 24;
  2728. days += absFloor(hours / 24);
  2729. // convert days to months
  2730. monthsFromDays = absFloor(daysToMonths(days));
  2731. months += monthsFromDays;
  2732. days -= absCeil(monthsToDays(monthsFromDays));
  2733. // 12 months -> 1 year
  2734. years = absFloor(months / 12);
  2735. months %= 12;
  2736. data.days = days;
  2737. data.months = months;
  2738. data.years = years;
  2739. return this;
  2740. }
  2741. function daysToMonths (days) {
  2742. // 400 years have 146097 days (taking into account leap year rules)
  2743. // 400 years have 12 months === 4800
  2744. return days * 4800 / 146097;
  2745. }
  2746. function monthsToDays (months) {
  2747. // the reverse of daysToMonths
  2748. return months * 146097 / 4800;
  2749. }
  2750. function as (units) {
  2751. var days;
  2752. var months;
  2753. var milliseconds = this._milliseconds;
  2754. units = normalizeUnits(units);
  2755. if (units === 'month' || units === 'year') {
  2756. days = this._days + milliseconds / 864e5;
  2757. months = this._months + daysToMonths(days);
  2758. return units === 'month' ? months : months / 12;
  2759. } else {
  2760. // handle milliseconds separately because of floating point math errors (issue #1867)
  2761. days = this._days + Math.round(monthsToDays(this._months));
  2762. switch (units) {
  2763. case 'week' : return days / 7 + milliseconds / 6048e5;
  2764. case 'day' : return days + milliseconds / 864e5;
  2765. case 'hour' : return days * 24 + milliseconds / 36e5;
  2766. case 'minute' : return days * 1440 + milliseconds / 6e4;
  2767. case 'second' : return days * 86400 + milliseconds / 1000;
  2768. // Math.floor prevents floating point math errors here
  2769. case 'millisecond': return Math.floor(days * 864e5) + milliseconds;
  2770. default: throw new Error('Unknown unit ' + units);
  2771. }
  2772. }
  2773. }
  2774. // TODO: Use this.as('ms')?
  2775. function duration_as__valueOf () {
  2776. return (
  2777. this._milliseconds +
  2778. this._days * 864e5 +
  2779. (this._months % 12) * 2592e6 +
  2780. toInt(this._months / 12) * 31536e6
  2781. );
  2782. }
  2783. function makeAs (alias) {
  2784. return function () {
  2785. return this.as(alias);
  2786. };
  2787. }
  2788. var asMilliseconds = makeAs('ms');
  2789. var asSeconds = makeAs('s');
  2790. var asMinutes = makeAs('m');
  2791. var asHours = makeAs('h');
  2792. var asDays = makeAs('d');
  2793. var asWeeks = makeAs('w');
  2794. var asMonths = makeAs('M');
  2795. var asYears = makeAs('y');
  2796. function duration_get__get (units) {
  2797. units = normalizeUnits(units);
  2798. return this[units + 's']();
  2799. }
  2800. function makeGetter(name) {
  2801. return function () {
  2802. return this._data[name];
  2803. };
  2804. }
  2805. var milliseconds = makeGetter('milliseconds');
  2806. var seconds = makeGetter('seconds');
  2807. var minutes = makeGetter('minutes');
  2808. var hours = makeGetter('hours');
  2809. var days = makeGetter('days');
  2810. var months = makeGetter('months');
  2811. var years = makeGetter('years');
  2812. function weeks () {
  2813. return absFloor(this.days() / 7);
  2814. }
  2815. var round = Math.round;
  2816. var thresholds = {
  2817. s: 45, // seconds to minute
  2818. m: 45, // minutes to hour
  2819. h: 22, // hours to day
  2820. d: 26, // days to month
  2821. M: 11 // months to year
  2822. };
  2823. // helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize
  2824. function substituteTimeAgo(string, number, withoutSuffix, isFuture, locale) {
  2825. return locale.relativeTime(number || 1, !!withoutSuffix, string, isFuture);
  2826. }
  2827. function duration_humanize__relativeTime (posNegDuration, withoutSuffix, locale) {
  2828. var duration = create__createDuration(posNegDuration).abs();
  2829. var seconds = round(duration.as('s'));
  2830. var minutes = round(duration.as('m'));
  2831. var hours = round(duration.as('h'));
  2832. var days = round(duration.as('d'));
  2833. var months = round(duration.as('M'));
  2834. var years = round(duration.as('y'));
  2835. var a = seconds < thresholds.s && ['s', seconds] ||
  2836. minutes <= 1 && ['m'] ||
  2837. minutes < thresholds.m && ['mm', minutes] ||
  2838. hours <= 1 && ['h'] ||
  2839. hours < thresholds.h && ['hh', hours] ||
  2840. days <= 1 && ['d'] ||
  2841. days < thresholds.d && ['dd', days] ||
  2842. months <= 1 && ['M'] ||
  2843. months < thresholds.M && ['MM', months] ||
  2844. years <= 1 && ['y'] || ['yy', years];
  2845. a[2] = withoutSuffix;
  2846. a[3] = +posNegDuration > 0;
  2847. a[4] = locale;
  2848. return substituteTimeAgo.apply(null, a);
  2849. }
  2850. // This function allows you to set a threshold for relative time strings
  2851. function duration_humanize__getSetRelativeTimeThreshold (threshold, limit) {
  2852. if (thresholds[threshold] === undefined) {
  2853. return false;
  2854. }
  2855. if (limit === undefined) {
  2856. return thresholds[threshold];
  2857. }
  2858. thresholds[threshold] = limit;
  2859. return true;
  2860. }
  2861. function humanize (withSuffix) {
  2862. var locale = this.localeData();
  2863. var output = duration_humanize__relativeTime(this, !withSuffix, locale);
  2864. if (withSuffix) {
  2865. output = locale.pastFuture(+this, output);
  2866. }
  2867. return locale.postformat(output);
  2868. }
  2869. var iso_string__abs = Math.abs;
  2870. function iso_string__toISOString() {
  2871. // for ISO strings we do not use the normal bubbling rules:
  2872. // * milliseconds bubble up until they become hours
  2873. // * days do not bubble at all
  2874. // * months bubble up until they become years
  2875. // This is because there is no context-free conversion between hours and days
  2876. // (think of clock changes)
  2877. // and also not between days and months (28-31 days per month)
  2878. var seconds = iso_string__abs(this._milliseconds) / 1000;
  2879. var days = iso_string__abs(this._days);
  2880. var months = iso_string__abs(this._months);
  2881. var minutes, hours, years;
  2882. // 3600 seconds -> 60 minutes -> 1 hour
  2883. minutes = absFloor(seconds / 60);
  2884. hours = absFloor(minutes / 60);
  2885. seconds %= 60;
  2886. minutes %= 60;
  2887. // 12 months -> 1 year
  2888. years = absFloor(months / 12);
  2889. months %= 12;
  2890. // inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js
  2891. var Y = years;
  2892. var M = months;
  2893. var D = days;
  2894. var h = hours;
  2895. var m = minutes;
  2896. var s = seconds;
  2897. var total = this.asSeconds();
  2898. if (!total) {
  2899. // this is the same as C#'s (Noda) and python (isodate)...
  2900. // but not other JS (goog.date)
  2901. return 'P0D';
  2902. }
  2903. return (total < 0 ? '-' : '') +
  2904. 'P' +
  2905. (Y ? Y + 'Y' : '') +
  2906. (M ? M + 'M' : '') +
  2907. (D ? D + 'D' : '') +
  2908. ((h || m || s) ? 'T' : '') +
  2909. (h ? h + 'H' : '') +
  2910. (m ? m + 'M' : '') +
  2911. (s ? s + 'S' : '');
  2912. }
  2913. var duration_prototype__proto = Duration.prototype;
  2914. duration_prototype__proto.abs = duration_abs__abs;
  2915. duration_prototype__proto.add = duration_add_subtract__add;
  2916. duration_prototype__proto.subtract = duration_add_subtract__subtract;
  2917. duration_prototype__proto.as = as;
  2918. duration_prototype__proto.asMilliseconds = asMilliseconds;
  2919. duration_prototype__proto.asSeconds = asSeconds;
  2920. duration_prototype__proto.asMinutes = asMinutes;
  2921. duration_prototype__proto.asHours = asHours;
  2922. duration_prototype__proto.asDays = asDays;
  2923. duration_prototype__proto.asWeeks = asWeeks;
  2924. duration_prototype__proto.asMonths = asMonths;
  2925. duration_prototype__proto.asYears = asYears;
  2926. duration_prototype__proto.valueOf = duration_as__valueOf;
  2927. duration_prototype__proto._bubble = bubble;
  2928. duration_prototype__proto.get = duration_get__get;
  2929. duration_prototype__proto.milliseconds = milliseconds;
  2930. duration_prototype__proto.seconds = seconds;
  2931. duration_prototype__proto.minutes = minutes;
  2932. duration_prototype__proto.hours = hours;
  2933. duration_prototype__proto.days = days;
  2934. duration_prototype__proto.weeks = weeks;
  2935. duration_prototype__proto.months = months;
  2936. duration_prototype__proto.years = years;
  2937. duration_prototype__proto.humanize = humanize;
  2938. duration_prototype__proto.toISOString = iso_string__toISOString;
  2939. duration_prototype__proto.toString = iso_string__toISOString;
  2940. duration_prototype__proto.toJSON = iso_string__toISOString;
  2941. duration_prototype__proto.locale = locale;
  2942. duration_prototype__proto.localeData = localeData;
  2943. // Deprecations
  2944. duration_prototype__proto.toIsoString = deprecate('toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)', iso_string__toISOString);
  2945. duration_prototype__proto.lang = lang;
  2946. // Side effect imports
  2947. // FORMATTING
  2948. addFormatToken('X', 0, 0, 'unix');
  2949. addFormatToken('x', 0, 0, 'valueOf');
  2950. // PARSING
  2951. addRegexToken('x', matchSigned);
  2952. addRegexToken('X', matchTimestamp);
  2953. addParseToken('X', function (input, array, config) {
  2954. config._d = new Date(parseFloat(input, 10) * 1000);
  2955. });
  2956. addParseToken('x', function (input, array, config) {
  2957. config._d = new Date(toInt(input));
  2958. });
  2959. // Side effect imports
  2960. utils_hooks__hooks.version = '2.11.2';
  2961. setHookCallback(local__createLocal);
  2962. utils_hooks__hooks.fn = momentPrototype;
  2963. utils_hooks__hooks.min = min;
  2964. utils_hooks__hooks.max = max;
  2965. utils_hooks__hooks.now = now;
  2966. utils_hooks__hooks.utc = create_utc__createUTC;
  2967. utils_hooks__hooks.unix = moment__createUnix;
  2968. utils_hooks__hooks.months = lists__listMonths;
  2969. utils_hooks__hooks.isDate = isDate;
  2970. utils_hooks__hooks.locale = locale_locales__getSetGlobalLocale;
  2971. utils_hooks__hooks.invalid = valid__createInvalid;
  2972. utils_hooks__hooks.duration = create__createDuration;
  2973. utils_hooks__hooks.isMoment = isMoment;
  2974. utils_hooks__hooks.weekdays = lists__listWeekdays;
  2975. utils_hooks__hooks.parseZone = moment__createInZone;
  2976. utils_hooks__hooks.localeData = locale_locales__getLocale;
  2977. utils_hooks__hooks.isDuration = isDuration;
  2978. utils_hooks__hooks.monthsShort = lists__listMonthsShort;
  2979. utils_hooks__hooks.weekdaysMin = lists__listWeekdaysMin;
  2980. utils_hooks__hooks.defineLocale = defineLocale;
  2981. utils_hooks__hooks.weekdaysShort = lists__listWeekdaysShort;
  2982. utils_hooks__hooks.normalizeUnits = normalizeUnits;
  2983. utils_hooks__hooks.relativeTimeThreshold = duration_humanize__getSetRelativeTimeThreshold;
  2984. utils_hooks__hooks.prototype = momentPrototype;
  2985. var _moment = utils_hooks__hooks;
  2986. return _moment;
  2987. }));