moment.js 107 KB

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