moment.js 148 KB

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