moment.js 137 KB

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