moment.js 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400
  1. //! moment.js
  2. //! version : 2.5.1
  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.5.1",
  12. global = this,
  13. round = Math.round,
  14. i,
  15. YEAR = 0,
  16. MONTH = 1,
  17. DATE = 2,
  18. HOUR = 3,
  19. MINUTE = 4,
  20. SECOND = 5,
  21. MILLISECOND = 6,
  22. // internal storage for language config files
  23. languages = {},
  24. // moment internal properties
  25. momentProperties = {
  26. _isAMomentObject: null,
  27. _i : null,
  28. _f : null,
  29. _l : null,
  30. _strict : null,
  31. _isUTC : null,
  32. _offset : null, // optional. Combine with _isUTC
  33. _pf : null,
  34. _lang : null // optional
  35. },
  36. // check for nodeJS
  37. hasModule = (typeof module !== 'undefined' && module.exports && typeof require !== 'undefined'),
  38. // ASP.NET json date format regex
  39. aspNetJsonRegex = /^\/?Date\((\-?\d+)/i,
  40. aspNetTimeSpanJsonRegex = /(\-)?(?:(\d*)\.)?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?)?/,
  41. // from http://docs.closure-library.googlecode.com/git/closure_goog_date_date.js.source.html
  42. // somewhat more in line with 4.4.3.2 2004 spec, but allows decimal anywhere
  43. isoDurationRegex = /^(-)?P(?:(?:([0-9,.]*)Y)?(?:([0-9,.]*)M)?(?:([0-9,.]*)D)?(?:T(?:([0-9,.]*)H)?(?:([0-9,.]*)M)?(?:([0-9,.]*)S)?)?|([0-9,.]*)W)$/,
  44. // format tokens
  45. formattingTokens = /(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|YYYYYY|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|mm?|ss?|S{1,4}|X|zz?|ZZ?|.)/g,
  46. localFormattingTokens = /(\[[^\[]*\])|(\\)?(LT|LL?L?L?|l{1,4})/g,
  47. // parsing token regexes
  48. parseTokenOneOrTwoDigits = /\d\d?/, // 0 - 99
  49. parseTokenOneToThreeDigits = /\d{1,3}/, // 0 - 999
  50. parseTokenOneToFourDigits = /\d{1,4}/, // 0 - 9999
  51. parseTokenOneToSixDigits = /[+\-]?\d{1,6}/, // -999,999 - 999,999
  52. parseTokenDigits = /\d+/, // nonzero number of digits
  53. 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.
  54. parseTokenTimezone = /Z|[\+\-]\d\d:?\d\d/gi, // +00:00 -00:00 +0000 -0000 or Z
  55. parseTokenT = /T/i, // T (ISO separator)
  56. parseTokenTimestampMs = /[\+\-]?\d+(\.\d{1,3})?/, // 123456789 123456789.123
  57. //strict parsing regexes
  58. parseTokenOneDigit = /\d/, // 0 - 9
  59. parseTokenTwoDigits = /\d\d/, // 00 - 99
  60. parseTokenThreeDigits = /\d{3}/, // 000 - 999
  61. parseTokenFourDigits = /\d{4}/, // 0000 - 9999
  62. parseTokenSixDigits = /[+-]?\d{6}/, // -999,999 - 999,999
  63. parseTokenSignedNumber = /[+-]?\d+/, // -inf - inf
  64. // iso 8601 regex
  65. // 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)
  66. 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)?)?$/,
  67. isoFormat = 'YYYY-MM-DDTHH:mm:ssZ',
  68. isoDates = [
  69. ['YYYYYY-MM-DD', /[+-]\d{6}-\d{2}-\d{2}/],
  70. ['YYYY-MM-DD', /\d{4}-\d{2}-\d{2}/],
  71. ['GGGG-[W]WW-E', /\d{4}-W\d{2}-\d/],
  72. ['GGGG-[W]WW', /\d{4}-W\d{2}/],
  73. ['YYYY-DDD', /\d{4}-\d{3}/]
  74. ],
  75. // iso time formats and regexes
  76. isoTimes = [
  77. ['HH:mm:ss.SSSS', /(T| )\d\d:\d\d:\d\d\.\d{1,3}/],
  78. ['HH:mm:ss', /(T| )\d\d:\d\d:\d\d/],
  79. ['HH:mm', /(T| )\d\d:\d\d/],
  80. ['HH', /(T| )\d\d/]
  81. ],
  82. // timezone chunker "+10:00" > ["10", "00"] or "-1530" > ["-15", "30"]
  83. parseTimezoneChunker = /([\+\-]|\d\d)/gi,
  84. // getter and setter names
  85. proxyGettersAndSetters = 'Date|Hours|Minutes|Seconds|Milliseconds'.split('|'),
  86. unitMillisecondFactors = {
  87. 'Milliseconds' : 1,
  88. 'Seconds' : 1e3,
  89. 'Minutes' : 6e4,
  90. 'Hours' : 36e5,
  91. 'Days' : 864e5,
  92. 'Months' : 2592e6,
  93. 'Years' : 31536e6
  94. },
  95. unitAliases = {
  96. ms : 'millisecond',
  97. s : 'second',
  98. m : 'minute',
  99. h : 'hour',
  100. d : 'day',
  101. D : 'date',
  102. w : 'week',
  103. W : 'isoWeek',
  104. M : 'month',
  105. y : 'year',
  106. DDD : 'dayOfYear',
  107. e : 'weekday',
  108. E : 'isoWeekday',
  109. gg: 'weekYear',
  110. GG: 'isoWeekYear'
  111. },
  112. camelFunctions = {
  113. dayofyear : 'dayOfYear',
  114. isoweekday : 'isoWeekday',
  115. isoweek : 'isoWeek',
  116. weekyear : 'weekYear',
  117. isoweekyear : 'isoWeekYear'
  118. },
  119. // format function strings
  120. formatFunctions = {},
  121. // tokens to ordinalize and pad
  122. ordinalizeTokens = 'DDD w W M D d'.split(' '),
  123. paddedTokens = 'M D H h m s w W'.split(' '),
  124. formatTokenFunctions = {
  125. M : function () {
  126. return this.month() + 1;
  127. },
  128. MMM : function (format) {
  129. return this.lang().monthsShort(this, format);
  130. },
  131. MMMM : function (format) {
  132. return this.lang().months(this, format);
  133. },
  134. D : function () {
  135. return this.date();
  136. },
  137. DDD : function () {
  138. return this.dayOfYear();
  139. },
  140. d : function () {
  141. return this.day();
  142. },
  143. dd : function (format) {
  144. return this.lang().weekdaysMin(this, format);
  145. },
  146. ddd : function (format) {
  147. return this.lang().weekdaysShort(this, format);
  148. },
  149. dddd : function (format) {
  150. return this.lang().weekdays(this, format);
  151. },
  152. w : function () {
  153. return this.week();
  154. },
  155. W : function () {
  156. return this.isoWeek();
  157. },
  158. YY : function () {
  159. return leftZeroFill(this.year() % 100, 2);
  160. },
  161. YYYY : function () {
  162. return leftZeroFill(this.year(), 4);
  163. },
  164. YYYYY : function () {
  165. return leftZeroFill(this.year(), 5);
  166. },
  167. YYYYYY : function () {
  168. var y = this.year(), sign = y >= 0 ? '+' : '-';
  169. return sign + leftZeroFill(Math.abs(y), 6);
  170. },
  171. gg : function () {
  172. return leftZeroFill(this.weekYear() % 100, 2);
  173. },
  174. gggg : function () {
  175. return leftZeroFill(this.weekYear(), 4);
  176. },
  177. ggggg : function () {
  178. return leftZeroFill(this.weekYear(), 5);
  179. },
  180. GG : function () {
  181. return leftZeroFill(this.isoWeekYear() % 100, 2);
  182. },
  183. GGGG : function () {
  184. return leftZeroFill(this.isoWeekYear(), 4);
  185. },
  186. GGGGG : function () {
  187. return leftZeroFill(this.isoWeekYear(), 5);
  188. },
  189. e : function () {
  190. return this.weekday();
  191. },
  192. E : function () {
  193. return this.isoWeekday();
  194. },
  195. a : function () {
  196. return this.lang().meridiem(this.hours(), this.minutes(), true);
  197. },
  198. A : function () {
  199. return this.lang().meridiem(this.hours(), this.minutes(), false);
  200. },
  201. H : function () {
  202. return this.hours();
  203. },
  204. h : function () {
  205. return this.hours() % 12 || 12;
  206. },
  207. m : function () {
  208. return this.minutes();
  209. },
  210. s : function () {
  211. return this.seconds();
  212. },
  213. S : function () {
  214. return toInt(this.milliseconds() / 100);
  215. },
  216. SS : function () {
  217. return leftZeroFill(toInt(this.milliseconds() / 10), 2);
  218. },
  219. SSS : function () {
  220. return leftZeroFill(this.milliseconds(), 3);
  221. },
  222. SSSS : function () {
  223. return leftZeroFill(this.milliseconds(), 3);
  224. },
  225. Z : function () {
  226. var a = -this.zone(),
  227. b = "+";
  228. if (a < 0) {
  229. a = -a;
  230. b = "-";
  231. }
  232. return b + leftZeroFill(toInt(a / 60), 2) + ":" + leftZeroFill(toInt(a) % 60, 2);
  233. },
  234. ZZ : function () {
  235. var a = -this.zone(),
  236. b = "+";
  237. if (a < 0) {
  238. a = -a;
  239. b = "-";
  240. }
  241. return b + leftZeroFill(toInt(a / 60), 2) + leftZeroFill(toInt(a) % 60, 2);
  242. },
  243. z : function () {
  244. return this.zoneAbbr();
  245. },
  246. zz : function () {
  247. return this.zoneName();
  248. },
  249. X : function () {
  250. return this.unix();
  251. },
  252. Q : function () {
  253. return this.quarter();
  254. }
  255. },
  256. lists = ['months', 'monthsShort', 'weekdays', 'weekdaysShort', 'weekdaysMin'];
  257. function defaultParsingFlags() {
  258. // We need to deep clone this object, and es5 standard is not very
  259. // helpful.
  260. return {
  261. empty : false,
  262. unusedTokens : [],
  263. unusedInput : [],
  264. overflow : -2,
  265. charsLeftOver : 0,
  266. nullInput : false,
  267. invalidMonth : null,
  268. invalidFormat : false,
  269. userInvalidated : false,
  270. iso: false
  271. };
  272. }
  273. function padToken(func, count) {
  274. return function (a) {
  275. return leftZeroFill(func.call(this, a), count);
  276. };
  277. }
  278. function ordinalizeToken(func, period) {
  279. return function (a) {
  280. return this.lang().ordinal(func.call(this, a), period);
  281. };
  282. }
  283. while (ordinalizeTokens.length) {
  284. i = ordinalizeTokens.pop();
  285. formatTokenFunctions[i + 'o'] = ordinalizeToken(formatTokenFunctions[i], i);
  286. }
  287. while (paddedTokens.length) {
  288. i = paddedTokens.pop();
  289. formatTokenFunctions[i + i] = padToken(formatTokenFunctions[i], 2);
  290. }
  291. formatTokenFunctions.DDDD = padToken(formatTokenFunctions.DDD, 3);
  292. /************************************
  293. Constructors
  294. ************************************/
  295. function Language() {
  296. }
  297. // Moment prototype object
  298. function Moment(config) {
  299. checkOverflow(config);
  300. extend(this, config);
  301. }
  302. // Duration Constructor
  303. function Duration(duration) {
  304. var normalizedInput = normalizeObjectUnits(duration),
  305. years = normalizedInput.year || 0,
  306. months = normalizedInput.month || 0,
  307. weeks = normalizedInput.week || 0,
  308. days = normalizedInput.day || 0,
  309. hours = normalizedInput.hour || 0,
  310. minutes = normalizedInput.minute || 0,
  311. seconds = normalizedInput.second || 0,
  312. milliseconds = normalizedInput.millisecond || 0;
  313. // representation for dateAddRemove
  314. this._milliseconds = +milliseconds +
  315. seconds * 1e3 + // 1000
  316. minutes * 6e4 + // 1000 * 60
  317. hours * 36e5; // 1000 * 60 * 60
  318. // Because of dateAddRemove treats 24 hours as different from a
  319. // day when working around DST, we need to store them separately
  320. this._days = +days +
  321. weeks * 7;
  322. // It is impossible translate months into days without knowing
  323. // which months you are are talking about, so we have to store
  324. // it separately.
  325. this._months = +months +
  326. years * 12;
  327. this._data = {};
  328. this._bubble();
  329. }
  330. /************************************
  331. Helpers
  332. ************************************/
  333. function extend(a, b) {
  334. for (var i in b) {
  335. if (b.hasOwnProperty(i)) {
  336. a[i] = b[i];
  337. }
  338. }
  339. if (b.hasOwnProperty("toString")) {
  340. a.toString = b.toString;
  341. }
  342. if (b.hasOwnProperty("valueOf")) {
  343. a.valueOf = b.valueOf;
  344. }
  345. return a;
  346. }
  347. function cloneMoment(m) {
  348. var result = {}, i;
  349. for (i in m) {
  350. if (m.hasOwnProperty(i) && momentProperties.hasOwnProperty(i)) {
  351. result[i] = m[i];
  352. }
  353. }
  354. return result;
  355. }
  356. function absRound(number) {
  357. if (number < 0) {
  358. return Math.ceil(number);
  359. } else {
  360. return Math.floor(number);
  361. }
  362. }
  363. // left zero fill a number
  364. // see http://jsperf.com/left-zero-filling for performance comparison
  365. function leftZeroFill(number, targetLength, forceSign) {
  366. var output = '' + Math.abs(number),
  367. sign = number >= 0;
  368. while (output.length < targetLength) {
  369. output = '0' + output;
  370. }
  371. return (sign ? (forceSign ? '+' : '') : '-') + output;
  372. }
  373. // helper function for _.addTime and _.subtractTime
  374. function addOrSubtractDurationFromMoment(mom, duration, isAdding, ignoreUpdateOffset) {
  375. var milliseconds = duration._milliseconds,
  376. days = duration._days,
  377. months = duration._months,
  378. minutes,
  379. hours;
  380. if (milliseconds) {
  381. mom._d.setTime(+mom._d + milliseconds * isAdding);
  382. }
  383. // store the minutes and hours so we can restore them
  384. if (days || months) {
  385. minutes = mom.minute();
  386. hours = mom.hour();
  387. }
  388. if (days) {
  389. mom.date(mom.date() + days * isAdding);
  390. }
  391. if (months) {
  392. mom.month(mom.month() + months * isAdding);
  393. }
  394. if (milliseconds && !ignoreUpdateOffset) {
  395. moment.updateOffset(mom);
  396. }
  397. // restore the minutes and hours after possibly changing dst
  398. if (days || months) {
  399. mom.minute(minutes);
  400. mom.hour(hours);
  401. }
  402. }
  403. // check if is an array
  404. function isArray(input) {
  405. return Object.prototype.toString.call(input) === '[object Array]';
  406. }
  407. function isDate(input) {
  408. return Object.prototype.toString.call(input) === '[object Date]' ||
  409. input instanceof Date;
  410. }
  411. // compare two arrays, return the number of differences
  412. function compareArrays(array1, array2, dontConvert) {
  413. var len = Math.min(array1.length, array2.length),
  414. lengthDiff = Math.abs(array1.length - array2.length),
  415. diffs = 0,
  416. i;
  417. for (i = 0; i < len; i++) {
  418. if ((dontConvert && array1[i] !== array2[i]) ||
  419. (!dontConvert && toInt(array1[i]) !== toInt(array2[i]))) {
  420. diffs++;
  421. }
  422. }
  423. return diffs + lengthDiff;
  424. }
  425. function normalizeUnits(units) {
  426. if (units) {
  427. var lowered = units.toLowerCase().replace(/(.)s$/, '$1');
  428. units = unitAliases[units] || camelFunctions[lowered] || lowered;
  429. }
  430. return units;
  431. }
  432. function normalizeObjectUnits(inputObject) {
  433. var normalizedInput = {},
  434. normalizedProp,
  435. prop;
  436. for (prop in inputObject) {
  437. if (inputObject.hasOwnProperty(prop)) {
  438. normalizedProp = normalizeUnits(prop);
  439. if (normalizedProp) {
  440. normalizedInput[normalizedProp] = inputObject[prop];
  441. }
  442. }
  443. }
  444. return normalizedInput;
  445. }
  446. function makeList(field) {
  447. var count, setter;
  448. if (field.indexOf('week') === 0) {
  449. count = 7;
  450. setter = 'day';
  451. }
  452. else if (field.indexOf('month') === 0) {
  453. count = 12;
  454. setter = 'month';
  455. }
  456. else {
  457. return;
  458. }
  459. moment[field] = function (format, index) {
  460. var i, getter,
  461. method = moment.fn._lang[field],
  462. results = [];
  463. if (typeof format === 'number') {
  464. index = format;
  465. format = undefined;
  466. }
  467. getter = function (i) {
  468. var m = moment().utc().set(setter, i);
  469. return method.call(moment.fn._lang, m, format || '');
  470. };
  471. if (index != null) {
  472. return getter(index);
  473. }
  474. else {
  475. for (i = 0; i < count; i++) {
  476. results.push(getter(i));
  477. }
  478. return results;
  479. }
  480. };
  481. }
  482. function toInt(argumentForCoercion) {
  483. var coercedNumber = +argumentForCoercion,
  484. value = 0;
  485. if (coercedNumber !== 0 && isFinite(coercedNumber)) {
  486. if (coercedNumber >= 0) {
  487. value = Math.floor(coercedNumber);
  488. } else {
  489. value = Math.ceil(coercedNumber);
  490. }
  491. }
  492. return value;
  493. }
  494. function daysInMonth(year, month) {
  495. return new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
  496. }
  497. function daysInYear(year) {
  498. return isLeapYear(year) ? 366 : 365;
  499. }
  500. function isLeapYear(year) {
  501. return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
  502. }
  503. function checkOverflow(m) {
  504. var overflow;
  505. if (m._a && m._pf.overflow === -2) {
  506. overflow =
  507. m._a[MONTH] < 0 || m._a[MONTH] > 11 ? MONTH :
  508. m._a[DATE] < 1 || m._a[DATE] > daysInMonth(m._a[YEAR], m._a[MONTH]) ? DATE :
  509. m._a[HOUR] < 0 || m._a[HOUR] > 23 ? HOUR :
  510. m._a[MINUTE] < 0 || m._a[MINUTE] > 59 ? MINUTE :
  511. m._a[SECOND] < 0 || m._a[SECOND] > 59 ? SECOND :
  512. m._a[MILLISECOND] < 0 || m._a[MILLISECOND] > 999 ? MILLISECOND :
  513. -1;
  514. if (m._pf._overflowDayOfYear && (overflow < YEAR || overflow > DATE)) {
  515. overflow = DATE;
  516. }
  517. m._pf.overflow = overflow;
  518. }
  519. }
  520. function isValid(m) {
  521. if (m._isValid == null) {
  522. m._isValid = !isNaN(m._d.getTime()) &&
  523. m._pf.overflow < 0 &&
  524. !m._pf.empty &&
  525. !m._pf.invalidMonth &&
  526. !m._pf.nullInput &&
  527. !m._pf.invalidFormat &&
  528. !m._pf.userInvalidated;
  529. if (m._strict) {
  530. m._isValid = m._isValid &&
  531. m._pf.charsLeftOver === 0 &&
  532. m._pf.unusedTokens.length === 0;
  533. }
  534. }
  535. return m._isValid;
  536. }
  537. function normalizeLanguage(key) {
  538. return key ? key.toLowerCase().replace('_', '-') : key;
  539. }
  540. // Return a moment from input, that is local/utc/zone equivalent to model.
  541. function makeAs(input, model) {
  542. return model._isUTC ? moment(input).zone(model._offset || 0) :
  543. moment(input).local();
  544. }
  545. /************************************
  546. Languages
  547. ************************************/
  548. extend(Language.prototype, {
  549. set : function (config) {
  550. var prop, i;
  551. for (i in config) {
  552. prop = config[i];
  553. if (typeof prop === 'function') {
  554. this[i] = prop;
  555. } else {
  556. this['_' + i] = prop;
  557. }
  558. }
  559. },
  560. _months : "January_February_March_April_May_June_July_August_September_October_November_December".split("_"),
  561. months : function (m) {
  562. return this._months[m.month()];
  563. },
  564. _monthsShort : "Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec".split("_"),
  565. monthsShort : function (m) {
  566. return this._monthsShort[m.month()];
  567. },
  568. monthsParse : function (monthName) {
  569. var i, mom, regex;
  570. if (!this._monthsParse) {
  571. this._monthsParse = [];
  572. }
  573. for (i = 0; i < 12; i++) {
  574. // make the regex if we don't have it already
  575. if (!this._monthsParse[i]) {
  576. mom = moment.utc([2000, i]);
  577. regex = '^' + this.months(mom, '') + '|^' + this.monthsShort(mom, '');
  578. this._monthsParse[i] = new RegExp(regex.replace('.', ''), 'i');
  579. }
  580. // test the regex
  581. if (this._monthsParse[i].test(monthName)) {
  582. return i;
  583. }
  584. }
  585. },
  586. _weekdays : "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),
  587. weekdays : function (m) {
  588. return this._weekdays[m.day()];
  589. },
  590. _weekdaysShort : "Sun_Mon_Tue_Wed_Thu_Fri_Sat".split("_"),
  591. weekdaysShort : function (m) {
  592. return this._weekdaysShort[m.day()];
  593. },
  594. _weekdaysMin : "Su_Mo_Tu_We_Th_Fr_Sa".split("_"),
  595. weekdaysMin : function (m) {
  596. return this._weekdaysMin[m.day()];
  597. },
  598. weekdaysParse : function (weekdayName) {
  599. var i, mom, regex;
  600. if (!this._weekdaysParse) {
  601. this._weekdaysParse = [];
  602. }
  603. for (i = 0; i < 7; i++) {
  604. // make the regex if we don't have it already
  605. if (!this._weekdaysParse[i]) {
  606. mom = moment([2000, 1]).day(i);
  607. regex = '^' + this.weekdays(mom, '') + '|^' + this.weekdaysShort(mom, '') + '|^' + this.weekdaysMin(mom, '');
  608. this._weekdaysParse[i] = new RegExp(regex.replace('.', ''), 'i');
  609. }
  610. // test the regex
  611. if (this._weekdaysParse[i].test(weekdayName)) {
  612. return i;
  613. }
  614. }
  615. },
  616. _longDateFormat : {
  617. LT : "h:mm A",
  618. L : "MM/DD/YYYY",
  619. LL : "MMMM D YYYY",
  620. LLL : "MMMM D YYYY LT",
  621. LLLL : "dddd, MMMM D YYYY LT"
  622. },
  623. longDateFormat : function (key) {
  624. var output = this._longDateFormat[key];
  625. if (!output && this._longDateFormat[key.toUpperCase()]) {
  626. output = this._longDateFormat[key.toUpperCase()].replace(/MMMM|MM|DD|dddd/g, function (val) {
  627. return val.slice(1);
  628. });
  629. this._longDateFormat[key] = output;
  630. }
  631. return output;
  632. },
  633. isPM : function (input) {
  634. // IE8 Quirks Mode & IE7 Standards Mode do not allow accessing strings like arrays
  635. // Using charAt should be more compatible.
  636. return ((input + '').toLowerCase().charAt(0) === 'p');
  637. },
  638. _meridiemParse : /[ap]\.?m?\.?/i,
  639. meridiem : function (hours, minutes, isLower) {
  640. if (hours > 11) {
  641. return isLower ? 'pm' : 'PM';
  642. } else {
  643. return isLower ? 'am' : 'AM';
  644. }
  645. },
  646. _calendar : {
  647. sameDay : '[Today at] LT',
  648. nextDay : '[Tomorrow at] LT',
  649. nextWeek : 'dddd [at] LT',
  650. lastDay : '[Yesterday at] LT',
  651. lastWeek : '[Last] dddd [at] LT',
  652. sameElse : 'L'
  653. },
  654. calendar : function (key, mom) {
  655. var output = this._calendar[key];
  656. return typeof output === 'function' ? output.apply(mom) : output;
  657. },
  658. _relativeTime : {
  659. future : "in %s",
  660. past : "%s ago",
  661. s : "a few seconds",
  662. m : "a minute",
  663. mm : "%d minutes",
  664. h : "an hour",
  665. hh : "%d hours",
  666. d : "a day",
  667. dd : "%d days",
  668. M : "a month",
  669. MM : "%d months",
  670. y : "a year",
  671. yy : "%d years"
  672. },
  673. relativeTime : function (number, withoutSuffix, string, isFuture) {
  674. var output = this._relativeTime[string];
  675. return (typeof output === 'function') ?
  676. output(number, withoutSuffix, string, isFuture) :
  677. output.replace(/%d/i, number);
  678. },
  679. pastFuture : function (diff, output) {
  680. var format = this._relativeTime[diff > 0 ? 'future' : 'past'];
  681. return typeof format === 'function' ? format(output) : format.replace(/%s/i, output);
  682. },
  683. ordinal : function (number) {
  684. return this._ordinal.replace("%d", number);
  685. },
  686. _ordinal : "%d",
  687. preparse : function (string) {
  688. return string;
  689. },
  690. postformat : function (string) {
  691. return string;
  692. },
  693. week : function (mom) {
  694. return weekOfYear(mom, this._week.dow, this._week.doy).week;
  695. },
  696. _week : {
  697. dow : 0, // Sunday is the first day of the week.
  698. doy : 6 // The week that contains Jan 1st is the first week of the year.
  699. },
  700. _invalidDate: 'Invalid date',
  701. invalidDate: function () {
  702. return this._invalidDate;
  703. }
  704. });
  705. // Loads a language definition into the `languages` cache. The function
  706. // takes a key and optionally values. If not in the browser and no values
  707. // are provided, it will load the language file module. As a convenience,
  708. // this function also returns the language values.
  709. function loadLang(key, values) {
  710. values.abbr = key;
  711. if (!languages[key]) {
  712. languages[key] = new Language();
  713. }
  714. languages[key].set(values);
  715. return languages[key];
  716. }
  717. // Remove a language from the `languages` cache. Mostly useful in tests.
  718. function unloadLang(key) {
  719. delete languages[key];
  720. }
  721. // Determines which language definition to use and returns it.
  722. //
  723. // With no parameters, it will return the global language. If you
  724. // pass in a language key, such as 'en', it will return the
  725. // definition for 'en', so long as 'en' has already been loaded using
  726. // moment.lang.
  727. function getLangDefinition(key) {
  728. var i = 0, j, lang, next, split,
  729. get = function (k) {
  730. if (!languages[k] && hasModule) {
  731. try {
  732. require('./lang/' + k);
  733. } catch (e) { }
  734. }
  735. return languages[k];
  736. };
  737. if (!key) {
  738. return moment.fn._lang;
  739. }
  740. if (!isArray(key)) {
  741. //short-circuit everything else
  742. lang = get(key);
  743. if (lang) {
  744. return lang;
  745. }
  746. key = [key];
  747. }
  748. //pick the language from the array
  749. //try ['en-au', 'en-gb'] as 'en-au', 'en-gb', 'en', as in move through the list trying each
  750. //substring from most specific to least, but move to the next array item if it's a more specific variant than the current root
  751. while (i < key.length) {
  752. split = normalizeLanguage(key[i]).split('-');
  753. j = split.length;
  754. next = normalizeLanguage(key[i + 1]);
  755. next = next ? next.split('-') : null;
  756. while (j > 0) {
  757. lang = get(split.slice(0, j).join('-'));
  758. if (lang) {
  759. return lang;
  760. }
  761. if (next && next.length >= j && compareArrays(split, next, true) >= j - 1) {
  762. //the next array item is better than a shallower substring of this one
  763. break;
  764. }
  765. j--;
  766. }
  767. i++;
  768. }
  769. return moment.fn._lang;
  770. }
  771. /************************************
  772. Formatting
  773. ************************************/
  774. function removeFormattingTokens(input) {
  775. if (input.match(/\[[\s\S]/)) {
  776. return input.replace(/^\[|\]$/g, "");
  777. }
  778. return input.replace(/\\/g, "");
  779. }
  780. function makeFormatFunction(format) {
  781. var array = format.match(formattingTokens), i, length;
  782. for (i = 0, length = array.length; i < length; i++) {
  783. if (formatTokenFunctions[array[i]]) {
  784. array[i] = formatTokenFunctions[array[i]];
  785. } else {
  786. array[i] = removeFormattingTokens(array[i]);
  787. }
  788. }
  789. return function (mom) {
  790. var output = "";
  791. for (i = 0; i < length; i++) {
  792. output += array[i] instanceof Function ? array[i].call(mom, format) : array[i];
  793. }
  794. return output;
  795. };
  796. }
  797. // format date using native date object
  798. function formatMoment(m, format) {
  799. if (!m.isValid()) {
  800. return m.lang().invalidDate();
  801. }
  802. format = expandFormat(format, m.lang());
  803. if (!formatFunctions[format]) {
  804. formatFunctions[format] = makeFormatFunction(format);
  805. }
  806. return formatFunctions[format](m);
  807. }
  808. function expandFormat(format, lang) {
  809. var i = 5;
  810. function replaceLongDateFormatTokens(input) {
  811. return lang.longDateFormat(input) || input;
  812. }
  813. localFormattingTokens.lastIndex = 0;
  814. while (i >= 0 && localFormattingTokens.test(format)) {
  815. format = format.replace(localFormattingTokens, replaceLongDateFormatTokens);
  816. localFormattingTokens.lastIndex = 0;
  817. i -= 1;
  818. }
  819. return format;
  820. }
  821. /************************************
  822. Parsing
  823. ************************************/
  824. // get the regex to find the next token
  825. function getParseRegexForToken(token, config) {
  826. var a, strict = config._strict;
  827. switch (token) {
  828. case 'DDDD':
  829. return parseTokenThreeDigits;
  830. case 'YYYY':
  831. case 'GGGG':
  832. case 'gggg':
  833. return strict ? parseTokenFourDigits : parseTokenOneToFourDigits;
  834. case 'Y':
  835. case 'G':
  836. case 'g':
  837. return parseTokenSignedNumber;
  838. case 'YYYYYY':
  839. case 'YYYYY':
  840. case 'GGGGG':
  841. case 'ggggg':
  842. return strict ? parseTokenSixDigits : parseTokenOneToSixDigits;
  843. case 'S':
  844. if (strict) { return parseTokenOneDigit; }
  845. /* falls through */
  846. case 'SS':
  847. if (strict) { return parseTokenTwoDigits; }
  848. /* falls through */
  849. case 'SSS':
  850. if (strict) { return parseTokenThreeDigits; }
  851. /* falls through */
  852. case 'DDD':
  853. return parseTokenOneToThreeDigits;
  854. case 'MMM':
  855. case 'MMMM':
  856. case 'dd':
  857. case 'ddd':
  858. case 'dddd':
  859. return parseTokenWord;
  860. case 'a':
  861. case 'A':
  862. return getLangDefinition(config._l)._meridiemParse;
  863. case 'X':
  864. return parseTokenTimestampMs;
  865. case 'Z':
  866. case 'ZZ':
  867. return parseTokenTimezone;
  868. case 'T':
  869. return parseTokenT;
  870. case 'SSSS':
  871. return parseTokenDigits;
  872. case 'MM':
  873. case 'DD':
  874. case 'YY':
  875. case 'GG':
  876. case 'gg':
  877. case 'HH':
  878. case 'hh':
  879. case 'mm':
  880. case 'ss':
  881. case 'ww':
  882. case 'WW':
  883. return strict ? parseTokenTwoDigits : parseTokenOneOrTwoDigits;
  884. case 'M':
  885. case 'D':
  886. case 'd':
  887. case 'H':
  888. case 'h':
  889. case 'm':
  890. case 's':
  891. case 'w':
  892. case 'W':
  893. case 'e':
  894. case 'E':
  895. return parseTokenOneOrTwoDigits;
  896. default :
  897. a = new RegExp(regexpEscape(unescapeFormat(token.replace('\\', '')), "i"));
  898. return a;
  899. }
  900. }
  901. function timezoneMinutesFromString(string) {
  902. string = string || "";
  903. var possibleTzMatches = (string.match(parseTokenTimezone) || []),
  904. tzChunk = possibleTzMatches[possibleTzMatches.length - 1] || [],
  905. parts = (tzChunk + '').match(parseTimezoneChunker) || ['-', 0, 0],
  906. minutes = +(parts[1] * 60) + toInt(parts[2]);
  907. return parts[0] === '+' ? -minutes : minutes;
  908. }
  909. // function to convert string input to date
  910. function addTimeToArrayFromToken(token, input, config) {
  911. var a, datePartArray = config._a;
  912. switch (token) {
  913. // MONTH
  914. case 'M' : // fall through to MM
  915. case 'MM' :
  916. if (input != null) {
  917. datePartArray[MONTH] = toInt(input) - 1;
  918. }
  919. break;
  920. case 'MMM' : // fall through to MMMM
  921. case 'MMMM' :
  922. a = getLangDefinition(config._l).monthsParse(input);
  923. // if we didn't find a month name, mark the date as invalid.
  924. if (a != null) {
  925. datePartArray[MONTH] = a;
  926. } else {
  927. config._pf.invalidMonth = input;
  928. }
  929. break;
  930. // DAY OF MONTH
  931. case 'D' : // fall through to DD
  932. case 'DD' :
  933. if (input != null) {
  934. datePartArray[DATE] = toInt(input);
  935. }
  936. break;
  937. // DAY OF YEAR
  938. case 'DDD' : // fall through to DDDD
  939. case 'DDDD' :
  940. if (input != null) {
  941. config._dayOfYear = toInt(input);
  942. }
  943. break;
  944. // YEAR
  945. case 'YY' :
  946. datePartArray[YEAR] = toInt(input) + (toInt(input) > 68 ? 1900 : 2000);
  947. break;
  948. case 'YYYY' :
  949. case 'YYYYY' :
  950. case 'YYYYYY' :
  951. datePartArray[YEAR] = toInt(input);
  952. break;
  953. // AM / PM
  954. case 'a' : // fall through to A
  955. case 'A' :
  956. config._isPm = getLangDefinition(config._l).isPM(input);
  957. break;
  958. // 24 HOUR
  959. case 'H' : // fall through to hh
  960. case 'HH' : // fall through to hh
  961. case 'h' : // fall through to hh
  962. case 'hh' :
  963. datePartArray[HOUR] = toInt(input);
  964. break;
  965. // MINUTE
  966. case 'm' : // fall through to mm
  967. case 'mm' :
  968. datePartArray[MINUTE] = toInt(input);
  969. break;
  970. // SECOND
  971. case 's' : // fall through to ss
  972. case 'ss' :
  973. datePartArray[SECOND] = toInt(input);
  974. break;
  975. // MILLISECOND
  976. case 'S' :
  977. case 'SS' :
  978. case 'SSS' :
  979. case 'SSSS' :
  980. datePartArray[MILLISECOND] = toInt(('0.' + input) * 1000);
  981. break;
  982. // UNIX TIMESTAMP WITH MS
  983. case 'X':
  984. config._d = new Date(parseFloat(input) * 1000);
  985. break;
  986. // TIMEZONE
  987. case 'Z' : // fall through to ZZ
  988. case 'ZZ' :
  989. config._useUTC = true;
  990. config._tzm = timezoneMinutesFromString(input);
  991. break;
  992. case 'w':
  993. case 'ww':
  994. case 'W':
  995. case 'WW':
  996. case 'd':
  997. case 'dd':
  998. case 'ddd':
  999. case 'dddd':
  1000. case 'e':
  1001. case 'E':
  1002. token = token.substr(0, 1);
  1003. /* falls through */
  1004. case 'gg':
  1005. case 'gggg':
  1006. case 'GG':
  1007. case 'GGGG':
  1008. case 'GGGGG':
  1009. token = token.substr(0, 2);
  1010. if (input) {
  1011. config._w = config._w || {};
  1012. config._w[token] = input;
  1013. }
  1014. break;
  1015. }
  1016. }
  1017. // convert an array to a date.
  1018. // the array should mirror the parameters below
  1019. // note: all values past the year are optional and will default to the lowest possible value.
  1020. // [year, month, day , hour, minute, second, millisecond]
  1021. function dateFromConfig(config) {
  1022. var i, date, input = [], currentDate,
  1023. yearToUse, fixYear, w, temp, lang, weekday, week;
  1024. if (config._d) {
  1025. return;
  1026. }
  1027. currentDate = currentDateArray(config);
  1028. //compute day of the year from weeks and weekdays
  1029. if (config._w && config._a[DATE] == null && config._a[MONTH] == null) {
  1030. fixYear = function (val) {
  1031. var int_val = parseInt(val, 10);
  1032. return val ?
  1033. (val.length < 3 ? (int_val > 68 ? 1900 + int_val : 2000 + int_val) : int_val) :
  1034. (config._a[YEAR] == null ? moment().weekYear() : config._a[YEAR]);
  1035. };
  1036. w = config._w;
  1037. if (w.GG != null || w.W != null || w.E != null) {
  1038. temp = dayOfYearFromWeeks(fixYear(w.GG), w.W || 1, w.E, 4, 1);
  1039. }
  1040. else {
  1041. lang = getLangDefinition(config._l);
  1042. weekday = w.d != null ? parseWeekday(w.d, lang) :
  1043. (w.e != null ? parseInt(w.e, 10) + lang._week.dow : 0);
  1044. week = parseInt(w.w, 10) || 1;
  1045. //if we're parsing 'd', then the low day numbers may be next week
  1046. if (w.d != null && weekday < lang._week.dow) {
  1047. week++;
  1048. }
  1049. temp = dayOfYearFromWeeks(fixYear(w.gg), week, weekday, lang._week.doy, lang._week.dow);
  1050. }
  1051. config._a[YEAR] = temp.year;
  1052. config._dayOfYear = temp.dayOfYear;
  1053. }
  1054. //if the day of the year is set, figure out what it is
  1055. if (config._dayOfYear) {
  1056. yearToUse = config._a[YEAR] == null ? currentDate[YEAR] : config._a[YEAR];
  1057. if (config._dayOfYear > daysInYear(yearToUse)) {
  1058. config._pf._overflowDayOfYear = true;
  1059. }
  1060. date = makeUTCDate(yearToUse, 0, config._dayOfYear);
  1061. config._a[MONTH] = date.getUTCMonth();
  1062. config._a[DATE] = date.getUTCDate();
  1063. }
  1064. // Default to current date.
  1065. // * if no year, month, day of month are given, default to today
  1066. // * if day of month is given, default month and year
  1067. // * if month is given, default only year
  1068. // * if year is given, don't default anything
  1069. for (i = 0; i < 3 && config._a[i] == null; ++i) {
  1070. config._a[i] = input[i] = currentDate[i];
  1071. }
  1072. // Zero out whatever was not defaulted, including time
  1073. for (; i < 7; i++) {
  1074. config._a[i] = input[i] = (config._a[i] == null) ? (i === 2 ? 1 : 0) : config._a[i];
  1075. }
  1076. // add the offsets to the time to be parsed so that we can have a clean array for checking isValid
  1077. input[HOUR] += toInt((config._tzm || 0) / 60);
  1078. input[MINUTE] += toInt((config._tzm || 0) % 60);
  1079. config._d = (config._useUTC ? makeUTCDate : makeDate).apply(null, input);
  1080. }
  1081. function dateFromObject(config) {
  1082. var normalizedInput;
  1083. if (config._d) {
  1084. return;
  1085. }
  1086. normalizedInput = normalizeObjectUnits(config._i);
  1087. config._a = [
  1088. normalizedInput.year,
  1089. normalizedInput.month,
  1090. normalizedInput.day,
  1091. normalizedInput.hour,
  1092. normalizedInput.minute,
  1093. normalizedInput.second,
  1094. normalizedInput.millisecond
  1095. ];
  1096. dateFromConfig(config);
  1097. }
  1098. function currentDateArray(config) {
  1099. var now = new Date();
  1100. if (config._useUTC) {
  1101. return [
  1102. now.getUTCFullYear(),
  1103. now.getUTCMonth(),
  1104. now.getUTCDate()
  1105. ];
  1106. } else {
  1107. return [now.getFullYear(), now.getMonth(), now.getDate()];
  1108. }
  1109. }
  1110. // date from string and format string
  1111. function makeDateFromStringAndFormat(config) {
  1112. config._a = [];
  1113. config._pf.empty = true;
  1114. // This array is used to make a Date, either with `new Date` or `Date.UTC`
  1115. var lang = getLangDefinition(config._l),
  1116. string = '' + config._i,
  1117. i, parsedInput, tokens, token, skipped,
  1118. stringLength = string.length,
  1119. totalParsedInputLength = 0;
  1120. tokens = expandFormat(config._f, lang).match(formattingTokens) || [];
  1121. for (i = 0; i < tokens.length; i++) {
  1122. token = tokens[i];
  1123. parsedInput = (string.match(getParseRegexForToken(token, config)) || [])[0];
  1124. if (parsedInput) {
  1125. skipped = string.substr(0, string.indexOf(parsedInput));
  1126. if (skipped.length > 0) {
  1127. config._pf.unusedInput.push(skipped);
  1128. }
  1129. string = string.slice(string.indexOf(parsedInput) + parsedInput.length);
  1130. totalParsedInputLength += parsedInput.length;
  1131. }
  1132. // don't parse if it's not a known token
  1133. if (formatTokenFunctions[token]) {
  1134. if (parsedInput) {
  1135. config._pf.empty = false;
  1136. }
  1137. else {
  1138. config._pf.unusedTokens.push(token);
  1139. }
  1140. addTimeToArrayFromToken(token, parsedInput, config);
  1141. }
  1142. else if (config._strict && !parsedInput) {
  1143. config._pf.unusedTokens.push(token);
  1144. }
  1145. }
  1146. // add remaining unparsed input length to the string
  1147. config._pf.charsLeftOver = stringLength - totalParsedInputLength;
  1148. if (string.length > 0) {
  1149. config._pf.unusedInput.push(string);
  1150. }
  1151. // handle am pm
  1152. if (config._isPm && config._a[HOUR] < 12) {
  1153. config._a[HOUR] += 12;
  1154. }
  1155. // if is 12 am, change hours to 0
  1156. if (config._isPm === false && config._a[HOUR] === 12) {
  1157. config._a[HOUR] = 0;
  1158. }
  1159. dateFromConfig(config);
  1160. checkOverflow(config);
  1161. }
  1162. function unescapeFormat(s) {
  1163. return s.replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, function (matched, p1, p2, p3, p4) {
  1164. return p1 || p2 || p3 || p4;
  1165. });
  1166. }
  1167. // Code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
  1168. function regexpEscape(s) {
  1169. return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
  1170. }
  1171. // date from string and array of format strings
  1172. function makeDateFromStringAndArray(config) {
  1173. var tempConfig,
  1174. bestMoment,
  1175. scoreToBeat,
  1176. i,
  1177. currentScore;
  1178. if (config._f.length === 0) {
  1179. config._pf.invalidFormat = true;
  1180. config._d = new Date(NaN);
  1181. return;
  1182. }
  1183. for (i = 0; i < config._f.length; i++) {
  1184. currentScore = 0;
  1185. tempConfig = extend({}, config);
  1186. tempConfig._pf = defaultParsingFlags();
  1187. tempConfig._f = config._f[i];
  1188. makeDateFromStringAndFormat(tempConfig);
  1189. if (!isValid(tempConfig)) {
  1190. continue;
  1191. }
  1192. // if there is any input that was not parsed add a penalty for that format
  1193. currentScore += tempConfig._pf.charsLeftOver;
  1194. //or tokens
  1195. currentScore += tempConfig._pf.unusedTokens.length * 10;
  1196. tempConfig._pf.score = currentScore;
  1197. if (scoreToBeat == null || currentScore < scoreToBeat) {
  1198. scoreToBeat = currentScore;
  1199. bestMoment = tempConfig;
  1200. }
  1201. }
  1202. extend(config, bestMoment || tempConfig);
  1203. }
  1204. // date from iso format
  1205. function makeDateFromString(config) {
  1206. var i, l,
  1207. string = config._i,
  1208. match = isoRegex.exec(string);
  1209. if (match) {
  1210. config._pf.iso = true;
  1211. for (i = 0, l = isoDates.length; i < l; i++) {
  1212. if (isoDates[i][1].exec(string)) {
  1213. // match[5] should be "T" or undefined
  1214. config._f = isoDates[i][0] + (match[6] || " ");
  1215. break;
  1216. }
  1217. }
  1218. for (i = 0, l = isoTimes.length; i < l; i++) {
  1219. if (isoTimes[i][1].exec(string)) {
  1220. config._f += isoTimes[i][0];
  1221. break;
  1222. }
  1223. }
  1224. if (string.match(parseTokenTimezone)) {
  1225. config._f += "Z";
  1226. }
  1227. makeDateFromStringAndFormat(config);
  1228. }
  1229. else {
  1230. config._d = new Date(string);
  1231. }
  1232. }
  1233. function makeDateFromInput(config) {
  1234. var input = config._i,
  1235. matched = aspNetJsonRegex.exec(input);
  1236. if (input === undefined) {
  1237. config._d = new Date();
  1238. } else if (matched) {
  1239. config._d = new Date(+matched[1]);
  1240. } else if (typeof input === 'string') {
  1241. makeDateFromString(config);
  1242. } else if (isArray(input)) {
  1243. config._a = input.slice(0);
  1244. dateFromConfig(config);
  1245. } else if (isDate(input)) {
  1246. config._d = new Date(+input);
  1247. } else if (typeof(input) === 'object') {
  1248. dateFromObject(config);
  1249. } else {
  1250. config._d = new Date(input);
  1251. }
  1252. }
  1253. function makeDate(y, m, d, h, M, s, ms) {
  1254. //can't just apply() to create a date:
  1255. //http://stackoverflow.com/questions/181348/instantiating-a-javascript-object-by-calling-prototype-constructor-apply
  1256. var date = new Date(y, m, d, h, M, s, ms);
  1257. //the date constructor doesn't accept years < 1970
  1258. if (y < 1970) {
  1259. date.setFullYear(y);
  1260. }
  1261. return date;
  1262. }
  1263. function makeUTCDate(y) {
  1264. var date = new Date(Date.UTC.apply(null, arguments));
  1265. if (y < 1970) {
  1266. date.setUTCFullYear(y);
  1267. }
  1268. return date;
  1269. }
  1270. function parseWeekday(input, language) {
  1271. if (typeof input === 'string') {
  1272. if (!isNaN(input)) {
  1273. input = parseInt(input, 10);
  1274. }
  1275. else {
  1276. input = language.weekdaysParse(input);
  1277. if (typeof input !== 'number') {
  1278. return null;
  1279. }
  1280. }
  1281. }
  1282. return input;
  1283. }
  1284. /************************************
  1285. Relative Time
  1286. ************************************/
  1287. // helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize
  1288. function substituteTimeAgo(string, number, withoutSuffix, isFuture, lang) {
  1289. return lang.relativeTime(number || 1, !!withoutSuffix, string, isFuture);
  1290. }
  1291. function relativeTime(milliseconds, withoutSuffix, lang) {
  1292. var seconds = round(Math.abs(milliseconds) / 1000),
  1293. minutes = round(seconds / 60),
  1294. hours = round(minutes / 60),
  1295. days = round(hours / 24),
  1296. years = round(days / 365),
  1297. args = seconds < 45 && ['s', seconds] ||
  1298. minutes === 1 && ['m'] ||
  1299. minutes < 45 && ['mm', minutes] ||
  1300. hours === 1 && ['h'] ||
  1301. hours < 22 && ['hh', hours] ||
  1302. days === 1 && ['d'] ||
  1303. days <= 25 && ['dd', days] ||
  1304. days <= 45 && ['M'] ||
  1305. days < 345 && ['MM', round(days / 30)] ||
  1306. years === 1 && ['y'] || ['yy', years];
  1307. args[2] = withoutSuffix;
  1308. args[3] = milliseconds > 0;
  1309. args[4] = lang;
  1310. return substituteTimeAgo.apply({}, args);
  1311. }
  1312. /************************************
  1313. Week of Year
  1314. ************************************/
  1315. // firstDayOfWeek 0 = sun, 6 = sat
  1316. // the day of the week that starts the week
  1317. // (usually sunday or monday)
  1318. // firstDayOfWeekOfYear 0 = sun, 6 = sat
  1319. // the first week is the week that contains the first
  1320. // of this day of the week
  1321. // (eg. ISO weeks use thursday (4))
  1322. function weekOfYear(mom, firstDayOfWeek, firstDayOfWeekOfYear) {
  1323. var end = firstDayOfWeekOfYear - firstDayOfWeek,
  1324. daysToDayOfWeek = firstDayOfWeekOfYear - mom.day(),
  1325. adjustedMoment;
  1326. if (daysToDayOfWeek > end) {
  1327. daysToDayOfWeek -= 7;
  1328. }
  1329. if (daysToDayOfWeek < end - 7) {
  1330. daysToDayOfWeek += 7;
  1331. }
  1332. adjustedMoment = moment(mom).add('d', daysToDayOfWeek);
  1333. return {
  1334. week: Math.ceil(adjustedMoment.dayOfYear() / 7),
  1335. year: adjustedMoment.year()
  1336. };
  1337. }
  1338. //http://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday
  1339. function dayOfYearFromWeeks(year, week, weekday, firstDayOfWeekOfYear, firstDayOfWeek) {
  1340. var d = makeUTCDate(year, 0, 1).getUTCDay(), daysToAdd, dayOfYear;
  1341. weekday = weekday != null ? weekday : firstDayOfWeek;
  1342. daysToAdd = firstDayOfWeek - d + (d > firstDayOfWeekOfYear ? 7 : 0) - (d < firstDayOfWeek ? 7 : 0);
  1343. dayOfYear = 7 * (week - 1) + (weekday - firstDayOfWeek) + daysToAdd + 1;
  1344. return {
  1345. year: dayOfYear > 0 ? year : year - 1,
  1346. dayOfYear: dayOfYear > 0 ? dayOfYear : daysInYear(year - 1) + dayOfYear
  1347. };
  1348. }
  1349. /************************************
  1350. Top Level Functions
  1351. ************************************/
  1352. function makeMoment(config) {
  1353. var input = config._i,
  1354. format = config._f;
  1355. if (input === null) {
  1356. return moment.invalid({nullInput: true});
  1357. }
  1358. if (typeof input === 'string') {
  1359. config._i = input = getLangDefinition().preparse(input);
  1360. }
  1361. if (moment.isMoment(input)) {
  1362. config = cloneMoment(input);
  1363. config._d = new Date(+input._d);
  1364. } else if (format) {
  1365. if (isArray(format)) {
  1366. makeDateFromStringAndArray(config);
  1367. } else {
  1368. makeDateFromStringAndFormat(config);
  1369. }
  1370. } else {
  1371. makeDateFromInput(config);
  1372. }
  1373. return new Moment(config);
  1374. }
  1375. moment = function (input, format, lang, strict) {
  1376. var c;
  1377. if (typeof(lang) === "boolean") {
  1378. strict = lang;
  1379. lang = undefined;
  1380. }
  1381. // object construction must be done this way.
  1382. // https://github.com/moment/moment/issues/1423
  1383. c = {};
  1384. c._isAMomentObject = true;
  1385. c._i = input;
  1386. c._f = format;
  1387. c._l = lang;
  1388. c._strict = strict;
  1389. c._isUTC = false;
  1390. c._pf = defaultParsingFlags();
  1391. return makeMoment(c);
  1392. };
  1393. // creating with utc
  1394. moment.utc = function (input, format, lang, strict) {
  1395. var c;
  1396. if (typeof(lang) === "boolean") {
  1397. strict = lang;
  1398. lang = undefined;
  1399. }
  1400. // object construction must be done this way.
  1401. // https://github.com/moment/moment/issues/1423
  1402. c = {};
  1403. c._isAMomentObject = true;
  1404. c._useUTC = true;
  1405. c._isUTC = true;
  1406. c._l = lang;
  1407. c._i = input;
  1408. c._f = format;
  1409. c._strict = strict;
  1410. c._pf = defaultParsingFlags();
  1411. return makeMoment(c).utc();
  1412. };
  1413. // creating with unix timestamp (in seconds)
  1414. moment.unix = function (input) {
  1415. return moment(input * 1000);
  1416. };
  1417. // duration
  1418. moment.duration = function (input, key) {
  1419. var duration = input,
  1420. // matching against regexp is expensive, do it on demand
  1421. match = null,
  1422. sign,
  1423. ret,
  1424. parseIso;
  1425. if (moment.isDuration(input)) {
  1426. duration = {
  1427. ms: input._milliseconds,
  1428. d: input._days,
  1429. M: input._months
  1430. };
  1431. } else if (typeof input === 'number') {
  1432. duration = {};
  1433. if (key) {
  1434. duration[key] = input;
  1435. } else {
  1436. duration.milliseconds = input;
  1437. }
  1438. } else if (!!(match = aspNetTimeSpanJsonRegex.exec(input))) {
  1439. sign = (match[1] === "-") ? -1 : 1;
  1440. duration = {
  1441. y: 0,
  1442. d: toInt(match[DATE]) * sign,
  1443. h: toInt(match[HOUR]) * sign,
  1444. m: toInt(match[MINUTE]) * sign,
  1445. s: toInt(match[SECOND]) * sign,
  1446. ms: toInt(match[MILLISECOND]) * sign
  1447. };
  1448. } else if (!!(match = isoDurationRegex.exec(input))) {
  1449. sign = (match[1] === "-") ? -1 : 1;
  1450. parseIso = function (inp) {
  1451. // We'd normally use ~~inp for this, but unfortunately it also
  1452. // converts floats to ints.
  1453. // inp may be undefined, so careful calling replace on it.
  1454. var res = inp && parseFloat(inp.replace(',', '.'));
  1455. // apply sign while we're at it
  1456. return (isNaN(res) ? 0 : res) * sign;
  1457. };
  1458. duration = {
  1459. y: parseIso(match[2]),
  1460. M: parseIso(match[3]),
  1461. d: parseIso(match[4]),
  1462. h: parseIso(match[5]),
  1463. m: parseIso(match[6]),
  1464. s: parseIso(match[7]),
  1465. w: parseIso(match[8])
  1466. };
  1467. }
  1468. ret = new Duration(duration);
  1469. if (moment.isDuration(input) && input.hasOwnProperty('_lang')) {
  1470. ret._lang = input._lang;
  1471. }
  1472. return ret;
  1473. };
  1474. // version number
  1475. moment.version = VERSION;
  1476. // default format
  1477. moment.defaultFormat = isoFormat;
  1478. // This function will be called whenever a moment is mutated.
  1479. // It is intended to keep the offset in sync with the timezone.
  1480. moment.updateOffset = function () {};
  1481. // This function will load languages and then set the global language. If
  1482. // no arguments are passed in, it will simply return the current global
  1483. // language key.
  1484. moment.lang = function (key, values) {
  1485. var r;
  1486. if (!key) {
  1487. return moment.fn._lang._abbr;
  1488. }
  1489. if (values) {
  1490. loadLang(normalizeLanguage(key), values);
  1491. } else if (values === null) {
  1492. unloadLang(key);
  1493. key = 'en';
  1494. } else if (!languages[key]) {
  1495. getLangDefinition(key);
  1496. }
  1497. r = moment.duration.fn._lang = moment.fn._lang = getLangDefinition(key);
  1498. return r._abbr;
  1499. };
  1500. // returns language data
  1501. moment.langData = function (key) {
  1502. if (key && key._lang && key._lang._abbr) {
  1503. key = key._lang._abbr;
  1504. }
  1505. return getLangDefinition(key);
  1506. };
  1507. // compare moment object
  1508. moment.isMoment = function (obj) {
  1509. return obj instanceof Moment ||
  1510. (obj != null && obj.hasOwnProperty('_isAMomentObject'));
  1511. };
  1512. // for typechecking Duration objects
  1513. moment.isDuration = function (obj) {
  1514. return obj instanceof Duration;
  1515. };
  1516. for (i = lists.length - 1; i >= 0; --i) {
  1517. makeList(lists[i]);
  1518. }
  1519. moment.normalizeUnits = function (units) {
  1520. return normalizeUnits(units);
  1521. };
  1522. moment.invalid = function (flags) {
  1523. var m = moment.utc(NaN);
  1524. if (flags != null) {
  1525. extend(m._pf, flags);
  1526. }
  1527. else {
  1528. m._pf.userInvalidated = true;
  1529. }
  1530. return m;
  1531. };
  1532. moment.parseZone = function (input) {
  1533. return moment(input).parseZone();
  1534. };
  1535. /************************************
  1536. Moment Prototype
  1537. ************************************/
  1538. extend(moment.fn = Moment.prototype, {
  1539. clone : function () {
  1540. return moment(this);
  1541. },
  1542. valueOf : function () {
  1543. return +this._d + ((this._offset || 0) * 60000);
  1544. },
  1545. unix : function () {
  1546. return Math.floor(+this / 1000);
  1547. },
  1548. toString : function () {
  1549. return this.clone().lang('en').format("ddd MMM DD YYYY HH:mm:ss [GMT]ZZ");
  1550. },
  1551. toDate : function () {
  1552. return this._offset ? new Date(+this) : this._d;
  1553. },
  1554. toISOString : function () {
  1555. var m = moment(this).utc();
  1556. if (0 < m.year() && m.year() <= 9999) {
  1557. return formatMoment(m, 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
  1558. } else {
  1559. return formatMoment(m, 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
  1560. }
  1561. },
  1562. toArray : function () {
  1563. var m = this;
  1564. return [
  1565. m.year(),
  1566. m.month(),
  1567. m.date(),
  1568. m.hours(),
  1569. m.minutes(),
  1570. m.seconds(),
  1571. m.milliseconds()
  1572. ];
  1573. },
  1574. isValid : function () {
  1575. return isValid(this);
  1576. },
  1577. isDSTShifted : function () {
  1578. if (this._a) {
  1579. return this.isValid() && compareArrays(this._a, (this._isUTC ? moment.utc(this._a) : moment(this._a)).toArray()) > 0;
  1580. }
  1581. return false;
  1582. },
  1583. parsingFlags : function () {
  1584. return extend({}, this._pf);
  1585. },
  1586. invalidAt: function () {
  1587. return this._pf.overflow;
  1588. },
  1589. utc : function () {
  1590. return this.zone(0);
  1591. },
  1592. local : function () {
  1593. this.zone(0);
  1594. this._isUTC = false;
  1595. return this;
  1596. },
  1597. format : function (inputString) {
  1598. var output = formatMoment(this, inputString || moment.defaultFormat);
  1599. return this.lang().postformat(output);
  1600. },
  1601. add : function (input, val) {
  1602. var dur;
  1603. // switch args to support add('s', 1) and add(1, 's')
  1604. if (typeof input === 'string') {
  1605. dur = moment.duration(+val, input);
  1606. } else {
  1607. dur = moment.duration(input, val);
  1608. }
  1609. addOrSubtractDurationFromMoment(this, dur, 1);
  1610. return this;
  1611. },
  1612. subtract : function (input, val) {
  1613. var dur;
  1614. // switch args to support subtract('s', 1) and subtract(1, 's')
  1615. if (typeof input === 'string') {
  1616. dur = moment.duration(+val, input);
  1617. } else {
  1618. dur = moment.duration(input, val);
  1619. }
  1620. addOrSubtractDurationFromMoment(this, dur, -1);
  1621. return this;
  1622. },
  1623. diff : function (input, units, asFloat) {
  1624. var that = makeAs(input, this),
  1625. zoneDiff = (this.zone() - that.zone()) * 6e4,
  1626. diff, output;
  1627. units = normalizeUnits(units);
  1628. if (units === 'year' || units === 'month') {
  1629. // average number of days in the months in the given dates
  1630. diff = (this.daysInMonth() + that.daysInMonth()) * 432e5; // 24 * 60 * 60 * 1000 / 2
  1631. // difference in months
  1632. output = ((this.year() - that.year()) * 12) + (this.month() - that.month());
  1633. // adjust by taking difference in days, average number of days
  1634. // and dst in the given months.
  1635. output += ((this - moment(this).startOf('month')) -
  1636. (that - moment(that).startOf('month'))) / diff;
  1637. // same as above but with zones, to negate all dst
  1638. output -= ((this.zone() - moment(this).startOf('month').zone()) -
  1639. (that.zone() - moment(that).startOf('month').zone())) * 6e4 / diff;
  1640. if (units === 'year') {
  1641. output = output / 12;
  1642. }
  1643. } else {
  1644. diff = (this - that);
  1645. output = units === 'second' ? diff / 1e3 : // 1000
  1646. units === 'minute' ? diff / 6e4 : // 1000 * 60
  1647. units === 'hour' ? diff / 36e5 : // 1000 * 60 * 60
  1648. units === 'day' ? (diff - zoneDiff) / 864e5 : // 1000 * 60 * 60 * 24, negate dst
  1649. units === 'week' ? (diff - zoneDiff) / 6048e5 : // 1000 * 60 * 60 * 24 * 7, negate dst
  1650. diff;
  1651. }
  1652. return asFloat ? output : absRound(output);
  1653. },
  1654. from : function (time, withoutSuffix) {
  1655. return moment.duration(this.diff(time)).lang(this.lang()._abbr).humanize(!withoutSuffix);
  1656. },
  1657. fromNow : function (withoutSuffix) {
  1658. return this.from(moment(), withoutSuffix);
  1659. },
  1660. calendar : function () {
  1661. // We want to compare the start of today, vs this.
  1662. // Getting start-of-today depends on whether we're zone'd or not.
  1663. var sod = makeAs(moment(), this).startOf('day'),
  1664. diff = this.diff(sod, 'days', true),
  1665. format = diff < -6 ? 'sameElse' :
  1666. diff < -1 ? 'lastWeek' :
  1667. diff < 0 ? 'lastDay' :
  1668. diff < 1 ? 'sameDay' :
  1669. diff < 2 ? 'nextDay' :
  1670. diff < 7 ? 'nextWeek' : 'sameElse';
  1671. return this.format(this.lang().calendar(format, this));
  1672. },
  1673. isLeapYear : function () {
  1674. return isLeapYear(this.year());
  1675. },
  1676. isDST : function () {
  1677. return (this.zone() < this.clone().month(0).zone() ||
  1678. this.zone() < this.clone().month(5).zone());
  1679. },
  1680. day : function (input) {
  1681. var day = this._isUTC ? this._d.getUTCDay() : this._d.getDay();
  1682. if (input != null) {
  1683. input = parseWeekday(input, this.lang());
  1684. return this.add({ d : input - day });
  1685. } else {
  1686. return day;
  1687. }
  1688. },
  1689. month : function (input) {
  1690. var utc = this._isUTC ? 'UTC' : '',
  1691. dayOfMonth;
  1692. if (input != null) {
  1693. if (typeof input === 'string') {
  1694. input = this.lang().monthsParse(input);
  1695. if (typeof input !== 'number') {
  1696. return this;
  1697. }
  1698. }
  1699. dayOfMonth = this.date();
  1700. this.date(1);
  1701. this._d['set' + utc + 'Month'](input);
  1702. this.date(Math.min(dayOfMonth, this.daysInMonth()));
  1703. moment.updateOffset(this);
  1704. return this;
  1705. } else {
  1706. return this._d['get' + utc + 'Month']();
  1707. }
  1708. },
  1709. startOf: function (units) {
  1710. units = normalizeUnits(units);
  1711. // the following switch intentionally omits break keywords
  1712. // to utilize falling through the cases.
  1713. switch (units) {
  1714. case 'year':
  1715. this.month(0);
  1716. /* falls through */
  1717. case 'month':
  1718. this.date(1);
  1719. /* falls through */
  1720. case 'week':
  1721. case 'isoWeek':
  1722. case 'day':
  1723. this.hours(0);
  1724. /* falls through */
  1725. case 'hour':
  1726. this.minutes(0);
  1727. /* falls through */
  1728. case 'minute':
  1729. this.seconds(0);
  1730. /* falls through */
  1731. case 'second':
  1732. this.milliseconds(0);
  1733. /* falls through */
  1734. }
  1735. // weeks are a special case
  1736. if (units === 'week') {
  1737. this.weekday(0);
  1738. } else if (units === 'isoWeek') {
  1739. this.isoWeekday(1);
  1740. }
  1741. return this;
  1742. },
  1743. endOf: function (units) {
  1744. units = normalizeUnits(units);
  1745. return this.startOf(units).add((units === 'isoWeek' ? 'week' : units), 1).subtract('ms', 1);
  1746. },
  1747. isAfter: function (input, units) {
  1748. units = typeof units !== 'undefined' ? units : 'millisecond';
  1749. return +this.clone().startOf(units) > +moment(input).startOf(units);
  1750. },
  1751. isBefore: function (input, units) {
  1752. units = typeof units !== 'undefined' ? units : 'millisecond';
  1753. return +this.clone().startOf(units) < +moment(input).startOf(units);
  1754. },
  1755. isSame: function (input, units) {
  1756. units = units || 'ms';
  1757. return +this.clone().startOf(units) === +makeAs(input, this).startOf(units);
  1758. },
  1759. min: function (other) {
  1760. other = moment.apply(null, arguments);
  1761. return other < this ? this : other;
  1762. },
  1763. max: function (other) {
  1764. other = moment.apply(null, arguments);
  1765. return other > this ? this : other;
  1766. },
  1767. zone : function (input) {
  1768. var offset = this._offset || 0;
  1769. if (input != null) {
  1770. if (typeof input === "string") {
  1771. input = timezoneMinutesFromString(input);
  1772. }
  1773. if (Math.abs(input) < 16) {
  1774. input = input * 60;
  1775. }
  1776. this._offset = input;
  1777. this._isUTC = true;
  1778. if (offset !== input) {
  1779. addOrSubtractDurationFromMoment(this, moment.duration(offset - input, 'm'), 1, true);
  1780. }
  1781. } else {
  1782. return this._isUTC ? offset : this._d.getTimezoneOffset();
  1783. }
  1784. return this;
  1785. },
  1786. zoneAbbr : function () {
  1787. return this._isUTC ? "UTC" : "";
  1788. },
  1789. zoneName : function () {
  1790. return this._isUTC ? "Coordinated Universal Time" : "";
  1791. },
  1792. parseZone : function () {
  1793. if (this._tzm) {
  1794. this.zone(this._tzm);
  1795. } else if (typeof this._i === 'string') {
  1796. this.zone(this._i);
  1797. }
  1798. return this;
  1799. },
  1800. hasAlignedHourOffset : function (input) {
  1801. if (!input) {
  1802. input = 0;
  1803. }
  1804. else {
  1805. input = moment(input).zone();
  1806. }
  1807. return (this.zone() - input) % 60 === 0;
  1808. },
  1809. daysInMonth : function () {
  1810. return daysInMonth(this.year(), this.month());
  1811. },
  1812. dayOfYear : function (input) {
  1813. var dayOfYear = round((moment(this).startOf('day') - moment(this).startOf('year')) / 864e5) + 1;
  1814. return input == null ? dayOfYear : this.add("d", (input - dayOfYear));
  1815. },
  1816. quarter : function () {
  1817. return Math.ceil((this.month() + 1.0) / 3.0);
  1818. },
  1819. weekYear : function (input) {
  1820. var year = weekOfYear(this, this.lang()._week.dow, this.lang()._week.doy).year;
  1821. return input == null ? year : this.add("y", (input - year));
  1822. },
  1823. isoWeekYear : function (input) {
  1824. var year = weekOfYear(this, 1, 4).year;
  1825. return input == null ? year : this.add("y", (input - year));
  1826. },
  1827. week : function (input) {
  1828. var week = this.lang().week(this);
  1829. return input == null ? week : this.add("d", (input - week) * 7);
  1830. },
  1831. isoWeek : function (input) {
  1832. var week = weekOfYear(this, 1, 4).week;
  1833. return input == null ? week : this.add("d", (input - week) * 7);
  1834. },
  1835. weekday : function (input) {
  1836. var weekday = (this.day() + 7 - this.lang()._week.dow) % 7;
  1837. return input == null ? weekday : this.add("d", input - weekday);
  1838. },
  1839. isoWeekday : function (input) {
  1840. // behaves the same as moment#day except
  1841. // as a getter, returns 7 instead of 0 (1-7 range instead of 0-6)
  1842. // as a setter, sunday should belong to the previous week.
  1843. return input == null ? this.day() || 7 : this.day(this.day() % 7 ? input : input - 7);
  1844. },
  1845. get : function (units) {
  1846. units = normalizeUnits(units);
  1847. return this[units]();
  1848. },
  1849. set : function (units, value) {
  1850. units = normalizeUnits(units);
  1851. if (typeof this[units] === 'function') {
  1852. this[units](value);
  1853. }
  1854. return this;
  1855. },
  1856. // If passed a language key, it will set the language for this
  1857. // instance. Otherwise, it will return the language configuration
  1858. // variables for this instance.
  1859. lang : function (key) {
  1860. if (key === undefined) {
  1861. return this._lang;
  1862. } else {
  1863. this._lang = getLangDefinition(key);
  1864. return this;
  1865. }
  1866. }
  1867. });
  1868. // helper for adding shortcuts
  1869. function makeGetterAndSetter(name, key) {
  1870. moment.fn[name] = moment.fn[name + 's'] = function (input) {
  1871. var utc = this._isUTC ? 'UTC' : '';
  1872. if (input != null) {
  1873. this._d['set' + utc + key](input);
  1874. moment.updateOffset(this);
  1875. return this;
  1876. } else {
  1877. return this._d['get' + utc + key]();
  1878. }
  1879. };
  1880. }
  1881. // loop through and add shortcuts (Month, Date, Hours, Minutes, Seconds, Milliseconds)
  1882. for (i = 0; i < proxyGettersAndSetters.length; i ++) {
  1883. makeGetterAndSetter(proxyGettersAndSetters[i].toLowerCase().replace(/s$/, ''), proxyGettersAndSetters[i]);
  1884. }
  1885. // add shortcut for year (uses different syntax than the getter/setter 'year' == 'FullYear')
  1886. makeGetterAndSetter('year', 'FullYear');
  1887. // add plural methods
  1888. moment.fn.days = moment.fn.day;
  1889. moment.fn.months = moment.fn.month;
  1890. moment.fn.weeks = moment.fn.week;
  1891. moment.fn.isoWeeks = moment.fn.isoWeek;
  1892. // add aliased format methods
  1893. moment.fn.toJSON = moment.fn.toISOString;
  1894. /************************************
  1895. Duration Prototype
  1896. ************************************/
  1897. extend(moment.duration.fn = Duration.prototype, {
  1898. _bubble : function () {
  1899. var milliseconds = this._milliseconds,
  1900. days = this._days,
  1901. months = this._months,
  1902. data = this._data,
  1903. seconds, minutes, hours, years;
  1904. // The following code bubbles up values, see the tests for
  1905. // examples of what that means.
  1906. data.milliseconds = milliseconds % 1000;
  1907. seconds = absRound(milliseconds / 1000);
  1908. data.seconds = seconds % 60;
  1909. minutes = absRound(seconds / 60);
  1910. data.minutes = minutes % 60;
  1911. hours = absRound(minutes / 60);
  1912. data.hours = hours % 24;
  1913. days += absRound(hours / 24);
  1914. data.days = days % 30;
  1915. months += absRound(days / 30);
  1916. data.months = months % 12;
  1917. years = absRound(months / 12);
  1918. data.years = years;
  1919. },
  1920. weeks : function () {
  1921. return absRound(this.days() / 7);
  1922. },
  1923. valueOf : function () {
  1924. return this._milliseconds +
  1925. this._days * 864e5 +
  1926. (this._months % 12) * 2592e6 +
  1927. toInt(this._months / 12) * 31536e6;
  1928. },
  1929. humanize : function (withSuffix) {
  1930. var difference = +this,
  1931. output = relativeTime(difference, !withSuffix, this.lang());
  1932. if (withSuffix) {
  1933. output = this.lang().pastFuture(difference, output);
  1934. }
  1935. return this.lang().postformat(output);
  1936. },
  1937. add : function (input, val) {
  1938. // supports only 2.0-style add(1, 's') or add(moment)
  1939. var dur = moment.duration(input, val);
  1940. this._milliseconds += dur._milliseconds;
  1941. this._days += dur._days;
  1942. this._months += dur._months;
  1943. this._bubble();
  1944. return this;
  1945. },
  1946. subtract : function (input, val) {
  1947. var dur = moment.duration(input, val);
  1948. this._milliseconds -= dur._milliseconds;
  1949. this._days -= dur._days;
  1950. this._months -= dur._months;
  1951. this._bubble();
  1952. return this;
  1953. },
  1954. get : function (units) {
  1955. units = normalizeUnits(units);
  1956. return this[units.toLowerCase() + 's']();
  1957. },
  1958. as : function (units) {
  1959. units = normalizeUnits(units);
  1960. return this['as' + units.charAt(0).toUpperCase() + units.slice(1) + 's']();
  1961. },
  1962. lang : moment.fn.lang,
  1963. toIsoString : function () {
  1964. // inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js
  1965. var years = Math.abs(this.years()),
  1966. months = Math.abs(this.months()),
  1967. days = Math.abs(this.days()),
  1968. hours = Math.abs(this.hours()),
  1969. minutes = Math.abs(this.minutes()),
  1970. seconds = Math.abs(this.seconds() + this.milliseconds() / 1000);
  1971. if (!this.asSeconds()) {
  1972. // this is the same as C#'s (Noda) and python (isodate)...
  1973. // but not other JS (goog.date)
  1974. return 'P0D';
  1975. }
  1976. return (this.asSeconds() < 0 ? '-' : '') +
  1977. 'P' +
  1978. (years ? years + 'Y' : '') +
  1979. (months ? months + 'M' : '') +
  1980. (days ? days + 'D' : '') +
  1981. ((hours || minutes || seconds) ? 'T' : '') +
  1982. (hours ? hours + 'H' : '') +
  1983. (minutes ? minutes + 'M' : '') +
  1984. (seconds ? seconds + 'S' : '');
  1985. }
  1986. });
  1987. function makeDurationGetter(name) {
  1988. moment.duration.fn[name] = function () {
  1989. return this._data[name];
  1990. };
  1991. }
  1992. function makeDurationAsGetter(name, factor) {
  1993. moment.duration.fn['as' + name] = function () {
  1994. return +this / factor;
  1995. };
  1996. }
  1997. for (i in unitMillisecondFactors) {
  1998. if (unitMillisecondFactors.hasOwnProperty(i)) {
  1999. makeDurationAsGetter(i, unitMillisecondFactors[i]);
  2000. makeDurationGetter(i.toLowerCase());
  2001. }
  2002. }
  2003. makeDurationAsGetter('Weeks', 6048e5);
  2004. moment.duration.fn.asMonths = function () {
  2005. return (+this - this.years() * 31536e6) / 2592e6 + this.years() * 12;
  2006. };
  2007. /************************************
  2008. Default Lang
  2009. ************************************/
  2010. // Set default language, other languages will inherit from English.
  2011. moment.lang('en', {
  2012. ordinal : function (number) {
  2013. var b = number % 10,
  2014. output = (toInt(number % 100 / 10) === 1) ? 'th' :
  2015. (b === 1) ? 'st' :
  2016. (b === 2) ? 'nd' :
  2017. (b === 3) ? 'rd' : 'th';
  2018. return number + output;
  2019. }
  2020. });
  2021. /* EMBED_LANGUAGES */
  2022. /************************************
  2023. Exposing Moment
  2024. ************************************/
  2025. function makeGlobal(deprecate) {
  2026. var warned = false, local_moment = moment;
  2027. /*global ender:false */
  2028. if (typeof ender !== 'undefined') {
  2029. return;
  2030. }
  2031. // here, `this` means `window` in the browser, or `global` on the server
  2032. // add `moment` as a global object via a string identifier,
  2033. // for Closure Compiler "advanced" mode
  2034. if (deprecate) {
  2035. global.moment = function () {
  2036. if (!warned && console && console.warn) {
  2037. warned = true;
  2038. console.warn(
  2039. "Accessing Moment through the global scope is " +
  2040. "deprecated, and will be removed in an upcoming " +
  2041. "release.");
  2042. }
  2043. return local_moment.apply(null, arguments);
  2044. };
  2045. extend(global.moment, local_moment);
  2046. } else {
  2047. global['moment'] = moment;
  2048. }
  2049. }
  2050. // CommonJS module is defined
  2051. if (hasModule) {
  2052. module.exports = moment;
  2053. makeGlobal(true);
  2054. } else if (typeof define === "function" && define.amd) {
  2055. define("moment", function (require, exports, module) {
  2056. if (module.config && module.config() && module.config().noGlobal !== true) {
  2057. // If user provided noGlobal, he is aware of global
  2058. makeGlobal(module.config().noGlobal === undefined);
  2059. }
  2060. return moment;
  2061. });
  2062. } else {
  2063. makeGlobal();
  2064. }
  2065. }).call(this);