moment.js 126 KB

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