moment.js 94 KB

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