moment.js 150KB

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