moment.js 121 KB

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