moment.js 142 KB

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