moment.js 105 KB

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