moment.js 136 KB

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