moment.js 150 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663
  1. //! moment.js
  2. //! version : 2.29.0
  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 and will be removed in an upcoming major release. Please refer to ' +
  2227. 'http://momentjs.com/guides/#/warnings/js-date/ for more info.',
  2228. function (config) {
  2229. config._d = new Date(config._i + (config._useUTC ? ' UTC' : ''));
  2230. }
  2231. );
  2232. // Pick the first defined of two or three arguments.
  2233. function defaults(a, b, c) {
  2234. if (a != null) {
  2235. return a;
  2236. }
  2237. if (b != null) {
  2238. return b;
  2239. }
  2240. return c;
  2241. }
  2242. function currentDateArray(config) {
  2243. // hooks is actually the exported moment object
  2244. var nowValue = new Date(hooks.now());
  2245. if (config._useUTC) {
  2246. return [
  2247. nowValue.getUTCFullYear(),
  2248. nowValue.getUTCMonth(),
  2249. nowValue.getUTCDate(),
  2250. ];
  2251. }
  2252. return [nowValue.getFullYear(), nowValue.getMonth(), nowValue.getDate()];
  2253. }
  2254. // convert an array to a date.
  2255. // the array should mirror the parameters below
  2256. // note: all values past the year are optional and will default to the lowest possible value.
  2257. // [year, month, day , hour, minute, second, millisecond]
  2258. function configFromArray(config) {
  2259. var i,
  2260. date,
  2261. input = [],
  2262. currentDate,
  2263. expectedWeekday,
  2264. yearToUse;
  2265. if (config._d) {
  2266. return;
  2267. }
  2268. currentDate = currentDateArray(config);
  2269. //compute day of the year from weeks and weekdays
  2270. if (config._w && config._a[DATE] == null && config._a[MONTH] == null) {
  2271. dayOfYearFromWeekInfo(config);
  2272. }
  2273. //if the day of the year is set, figure out what it is
  2274. if (config._dayOfYear != null) {
  2275. yearToUse = defaults(config._a[YEAR], currentDate[YEAR]);
  2276. if (
  2277. config._dayOfYear > daysInYear(yearToUse) ||
  2278. config._dayOfYear === 0
  2279. ) {
  2280. getParsingFlags(config)._overflowDayOfYear = true;
  2281. }
  2282. date = createUTCDate(yearToUse, 0, config._dayOfYear);
  2283. config._a[MONTH] = date.getUTCMonth();
  2284. config._a[DATE] = date.getUTCDate();
  2285. }
  2286. // Default to current date.
  2287. // * if no year, month, day of month are given, default to today
  2288. // * if day of month is given, default month and year
  2289. // * if month is given, default only year
  2290. // * if year is given, don't default anything
  2291. for (i = 0; i < 3 && config._a[i] == null; ++i) {
  2292. config._a[i] = input[i] = currentDate[i];
  2293. }
  2294. // Zero out whatever was not defaulted, including time
  2295. for (; i < 7; i++) {
  2296. config._a[i] = input[i] =
  2297. config._a[i] == null ? (i === 2 ? 1 : 0) : config._a[i];
  2298. }
  2299. // Check for 24:00:00.000
  2300. if (
  2301. config._a[HOUR] === 24 &&
  2302. config._a[MINUTE] === 0 &&
  2303. config._a[SECOND] === 0 &&
  2304. config._a[MILLISECOND] === 0
  2305. ) {
  2306. config._nextDay = true;
  2307. config._a[HOUR] = 0;
  2308. }
  2309. config._d = (config._useUTC ? createUTCDate : createDate).apply(
  2310. null,
  2311. input
  2312. );
  2313. expectedWeekday = config._useUTC
  2314. ? config._d.getUTCDay()
  2315. : config._d.getDay();
  2316. // Apply timezone offset from input. The actual utcOffset can be changed
  2317. // with parseZone.
  2318. if (config._tzm != null) {
  2319. config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm);
  2320. }
  2321. if (config._nextDay) {
  2322. config._a[HOUR] = 24;
  2323. }
  2324. // check for mismatching day of week
  2325. if (
  2326. config._w &&
  2327. typeof config._w.d !== 'undefined' &&
  2328. config._w.d !== expectedWeekday
  2329. ) {
  2330. getParsingFlags(config).weekdayMismatch = true;
  2331. }
  2332. }
  2333. function dayOfYearFromWeekInfo(config) {
  2334. var w, weekYear, week, weekday, dow, doy, temp, weekdayOverflow, curWeek;
  2335. w = config._w;
  2336. if (w.GG != null || w.W != null || w.E != null) {
  2337. dow = 1;
  2338. doy = 4;
  2339. // TODO: We need to take the current isoWeekYear, but that depends on
  2340. // how we interpret now (local, utc, fixed offset). So create
  2341. // a now version of current config (take local/utc/offset flags, and
  2342. // create now).
  2343. weekYear = defaults(
  2344. w.GG,
  2345. config._a[YEAR],
  2346. weekOfYear(createLocal(), 1, 4).year
  2347. );
  2348. week = defaults(w.W, 1);
  2349. weekday = defaults(w.E, 1);
  2350. if (weekday < 1 || weekday > 7) {
  2351. weekdayOverflow = true;
  2352. }
  2353. } else {
  2354. dow = config._locale._week.dow;
  2355. doy = config._locale._week.doy;
  2356. curWeek = weekOfYear(createLocal(), dow, doy);
  2357. weekYear = defaults(w.gg, config._a[YEAR], curWeek.year);
  2358. // Default to current week.
  2359. week = defaults(w.w, curWeek.week);
  2360. if (w.d != null) {
  2361. // weekday -- low day numbers are considered next week
  2362. weekday = w.d;
  2363. if (weekday < 0 || weekday > 6) {
  2364. weekdayOverflow = true;
  2365. }
  2366. } else if (w.e != null) {
  2367. // local weekday -- counting starts from beginning of week
  2368. weekday = w.e + dow;
  2369. if (w.e < 0 || w.e > 6) {
  2370. weekdayOverflow = true;
  2371. }
  2372. } else {
  2373. // default to beginning of week
  2374. weekday = dow;
  2375. }
  2376. }
  2377. if (week < 1 || week > weeksInYear(weekYear, dow, doy)) {
  2378. getParsingFlags(config)._overflowWeeks = true;
  2379. } else if (weekdayOverflow != null) {
  2380. getParsingFlags(config)._overflowWeekday = true;
  2381. } else {
  2382. temp = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy);
  2383. config._a[YEAR] = temp.year;
  2384. config._dayOfYear = temp.dayOfYear;
  2385. }
  2386. }
  2387. // constant that refers to the ISO standard
  2388. hooks.ISO_8601 = function () {};
  2389. // constant that refers to the RFC 2822 form
  2390. hooks.RFC_2822 = function () {};
  2391. // date from string and format string
  2392. function configFromStringAndFormat(config) {
  2393. // TODO: Move this to another part of the creation flow to prevent circular deps
  2394. if (config._f === hooks.ISO_8601) {
  2395. configFromISO(config);
  2396. return;
  2397. }
  2398. if (config._f === hooks.RFC_2822) {
  2399. configFromRFC2822(config);
  2400. return;
  2401. }
  2402. config._a = [];
  2403. getParsingFlags(config).empty = true;
  2404. // This array is used to make a Date, either with `new Date` or `Date.UTC`
  2405. var string = '' + config._i,
  2406. i,
  2407. parsedInput,
  2408. tokens,
  2409. token,
  2410. skipped,
  2411. stringLength = string.length,
  2412. totalParsedInputLength = 0,
  2413. era;
  2414. tokens =
  2415. expandFormat(config._f, config._locale).match(formattingTokens) || [];
  2416. for (i = 0; i < tokens.length; i++) {
  2417. token = tokens[i];
  2418. parsedInput = (string.match(getParseRegexForToken(token, config)) ||
  2419. [])[0];
  2420. if (parsedInput) {
  2421. skipped = string.substr(0, string.indexOf(parsedInput));
  2422. if (skipped.length > 0) {
  2423. getParsingFlags(config).unusedInput.push(skipped);
  2424. }
  2425. string = string.slice(
  2426. string.indexOf(parsedInput) + parsedInput.length
  2427. );
  2428. totalParsedInputLength += parsedInput.length;
  2429. }
  2430. // don't parse if it's not a known token
  2431. if (formatTokenFunctions[token]) {
  2432. if (parsedInput) {
  2433. getParsingFlags(config).empty = false;
  2434. } else {
  2435. getParsingFlags(config).unusedTokens.push(token);
  2436. }
  2437. addTimeToArrayFromToken(token, parsedInput, config);
  2438. } else if (config._strict && !parsedInput) {
  2439. getParsingFlags(config).unusedTokens.push(token);
  2440. }
  2441. }
  2442. // add remaining unparsed input length to the string
  2443. getParsingFlags(config).charsLeftOver =
  2444. stringLength - totalParsedInputLength;
  2445. if (string.length > 0) {
  2446. getParsingFlags(config).unusedInput.push(string);
  2447. }
  2448. // clear _12h flag if hour is <= 12
  2449. if (
  2450. config._a[HOUR] <= 12 &&
  2451. getParsingFlags(config).bigHour === true &&
  2452. config._a[HOUR] > 0
  2453. ) {
  2454. getParsingFlags(config).bigHour = undefined;
  2455. }
  2456. getParsingFlags(config).parsedDateParts = config._a.slice(0);
  2457. getParsingFlags(config).meridiem = config._meridiem;
  2458. // handle meridiem
  2459. config._a[HOUR] = meridiemFixWrap(
  2460. config._locale,
  2461. config._a[HOUR],
  2462. config._meridiem
  2463. );
  2464. // handle era
  2465. era = getParsingFlags(config).era;
  2466. if (era !== null) {
  2467. config._a[YEAR] = config._locale.erasConvertYear(era, config._a[YEAR]);
  2468. }
  2469. configFromArray(config);
  2470. checkOverflow(config);
  2471. }
  2472. function meridiemFixWrap(locale, hour, meridiem) {
  2473. var isPm;
  2474. if (meridiem == null) {
  2475. // nothing to do
  2476. return hour;
  2477. }
  2478. if (locale.meridiemHour != null) {
  2479. return locale.meridiemHour(hour, meridiem);
  2480. } else if (locale.isPM != null) {
  2481. // Fallback
  2482. isPm = locale.isPM(meridiem);
  2483. if (isPm && hour < 12) {
  2484. hour += 12;
  2485. }
  2486. if (!isPm && hour === 12) {
  2487. hour = 0;
  2488. }
  2489. return hour;
  2490. } else {
  2491. // this is not supposed to happen
  2492. return hour;
  2493. }
  2494. }
  2495. // date from string and array of format strings
  2496. function configFromStringAndArray(config) {
  2497. var tempConfig,
  2498. bestMoment,
  2499. scoreToBeat,
  2500. i,
  2501. currentScore,
  2502. validFormatFound,
  2503. bestFormatIsValid = false;
  2504. if (config._f.length === 0) {
  2505. getParsingFlags(config).invalidFormat = true;
  2506. config._d = new Date(NaN);
  2507. return;
  2508. }
  2509. for (i = 0; i < config._f.length; i++) {
  2510. currentScore = 0;
  2511. validFormatFound = false;
  2512. tempConfig = copyConfig({}, config);
  2513. if (config._useUTC != null) {
  2514. tempConfig._useUTC = config._useUTC;
  2515. }
  2516. tempConfig._f = config._f[i];
  2517. configFromStringAndFormat(tempConfig);
  2518. if (isValid(tempConfig)) {
  2519. validFormatFound = true;
  2520. }
  2521. // if there is any input that was not parsed add a penalty for that format
  2522. currentScore += getParsingFlags(tempConfig).charsLeftOver;
  2523. //or tokens
  2524. currentScore += getParsingFlags(tempConfig).unusedTokens.length * 10;
  2525. getParsingFlags(tempConfig).score = currentScore;
  2526. if (!bestFormatIsValid) {
  2527. if (
  2528. scoreToBeat == null ||
  2529. currentScore < scoreToBeat ||
  2530. validFormatFound
  2531. ) {
  2532. scoreToBeat = currentScore;
  2533. bestMoment = tempConfig;
  2534. if (validFormatFound) {
  2535. bestFormatIsValid = true;
  2536. }
  2537. }
  2538. } else {
  2539. if (currentScore < scoreToBeat) {
  2540. scoreToBeat = currentScore;
  2541. bestMoment = tempConfig;
  2542. }
  2543. }
  2544. }
  2545. extend(config, bestMoment || tempConfig);
  2546. }
  2547. function configFromObject(config) {
  2548. if (config._d) {
  2549. return;
  2550. }
  2551. var i = normalizeObjectUnits(config._i),
  2552. dayOrDate = i.day === undefined ? i.date : i.day;
  2553. config._a = map(
  2554. [i.year, i.month, dayOrDate, i.hour, i.minute, i.second, i.millisecond],
  2555. function (obj) {
  2556. return obj && parseInt(obj, 10);
  2557. }
  2558. );
  2559. configFromArray(config);
  2560. }
  2561. function createFromConfig(config) {
  2562. var res = new Moment(checkOverflow(prepareConfig(config)));
  2563. if (res._nextDay) {
  2564. // Adding is smart enough around DST
  2565. res.add(1, 'd');
  2566. res._nextDay = undefined;
  2567. }
  2568. return res;
  2569. }
  2570. function prepareConfig(config) {
  2571. var input = config._i,
  2572. format = config._f;
  2573. config._locale = config._locale || getLocale(config._l);
  2574. if (input === null || (format === undefined && input === '')) {
  2575. return createInvalid({ nullInput: true });
  2576. }
  2577. if (typeof input === 'string') {
  2578. config._i = input = config._locale.preparse(input);
  2579. }
  2580. if (isMoment(input)) {
  2581. return new Moment(checkOverflow(input));
  2582. } else if (isDate(input)) {
  2583. config._d = input;
  2584. } else if (isArray(format)) {
  2585. configFromStringAndArray(config);
  2586. } else if (format) {
  2587. configFromStringAndFormat(config);
  2588. } else {
  2589. configFromInput(config);
  2590. }
  2591. if (!isValid(config)) {
  2592. config._d = null;
  2593. }
  2594. return config;
  2595. }
  2596. function configFromInput(config) {
  2597. var input = config._i;
  2598. if (isUndefined(input)) {
  2599. config._d = new Date(hooks.now());
  2600. } else if (isDate(input)) {
  2601. config._d = new Date(input.valueOf());
  2602. } else if (typeof input === 'string') {
  2603. configFromString(config);
  2604. } else if (isArray(input)) {
  2605. config._a = map(input.slice(0), function (obj) {
  2606. return parseInt(obj, 10);
  2607. });
  2608. configFromArray(config);
  2609. } else if (isObject(input)) {
  2610. configFromObject(config);
  2611. } else if (isNumber(input)) {
  2612. // from milliseconds
  2613. config._d = new Date(input);
  2614. } else {
  2615. hooks.createFromInputFallback(config);
  2616. }
  2617. }
  2618. function createLocalOrUTC(input, format, locale, strict, isUTC) {
  2619. var c = {};
  2620. if (format === true || format === false) {
  2621. strict = format;
  2622. format = undefined;
  2623. }
  2624. if (locale === true || locale === false) {
  2625. strict = locale;
  2626. locale = undefined;
  2627. }
  2628. if (
  2629. (isObject(input) && isObjectEmpty(input)) ||
  2630. (isArray(input) && input.length === 0)
  2631. ) {
  2632. input = undefined;
  2633. }
  2634. // object construction must be done this way.
  2635. // https://github.com/moment/moment/issues/1423
  2636. c._isAMomentObject = true;
  2637. c._useUTC = c._isUTC = isUTC;
  2638. c._l = locale;
  2639. c._i = input;
  2640. c._f = format;
  2641. c._strict = strict;
  2642. return createFromConfig(c);
  2643. }
  2644. function createLocal(input, format, locale, strict) {
  2645. return createLocalOrUTC(input, format, locale, strict, false);
  2646. }
  2647. var prototypeMin = deprecate(
  2648. 'moment().min is deprecated, use moment.max instead. http://momentjs.com/guides/#/warnings/min-max/',
  2649. function () {
  2650. var other = createLocal.apply(null, arguments);
  2651. if (this.isValid() && other.isValid()) {
  2652. return other < this ? this : other;
  2653. } else {
  2654. return createInvalid();
  2655. }
  2656. }
  2657. ),
  2658. prototypeMax = deprecate(
  2659. 'moment().max is deprecated, use moment.min instead. http://momentjs.com/guides/#/warnings/min-max/',
  2660. function () {
  2661. var other = createLocal.apply(null, arguments);
  2662. if (this.isValid() && other.isValid()) {
  2663. return other > this ? this : other;
  2664. } else {
  2665. return createInvalid();
  2666. }
  2667. }
  2668. );
  2669. // Pick a moment m from moments so that m[fn](other) is true for all
  2670. // other. This relies on the function fn to be transitive.
  2671. //
  2672. // moments should either be an array of moment objects or an array, whose
  2673. // first element is an array of moment objects.
  2674. function pickBy(fn, moments) {
  2675. var res, i;
  2676. if (moments.length === 1 && isArray(moments[0])) {
  2677. moments = moments[0];
  2678. }
  2679. if (!moments.length) {
  2680. return createLocal();
  2681. }
  2682. res = moments[0];
  2683. for (i = 1; i < moments.length; ++i) {
  2684. if (!moments[i].isValid() || moments[i][fn](res)) {
  2685. res = moments[i];
  2686. }
  2687. }
  2688. return res;
  2689. }
  2690. // TODO: Use [].sort instead?
  2691. function min() {
  2692. var args = [].slice.call(arguments, 0);
  2693. return pickBy('isBefore', args);
  2694. }
  2695. function max() {
  2696. var args = [].slice.call(arguments, 0);
  2697. return pickBy('isAfter', args);
  2698. }
  2699. var now = function () {
  2700. return Date.now ? Date.now() : +new Date();
  2701. };
  2702. var ordering = [
  2703. 'year',
  2704. 'quarter',
  2705. 'month',
  2706. 'week',
  2707. 'day',
  2708. 'hour',
  2709. 'minute',
  2710. 'second',
  2711. 'millisecond',
  2712. ];
  2713. function isDurationValid(m) {
  2714. var key,
  2715. unitHasDecimal = false,
  2716. i;
  2717. for (key in m) {
  2718. if (
  2719. hasOwnProp(m, key) &&
  2720. !(
  2721. indexOf.call(ordering, key) !== -1 &&
  2722. (m[key] == null || !isNaN(m[key]))
  2723. )
  2724. ) {
  2725. return false;
  2726. }
  2727. }
  2728. for (i = 0; i < ordering.length; ++i) {
  2729. if (m[ordering[i]]) {
  2730. if (unitHasDecimal) {
  2731. return false; // only allow non-integers for smallest unit
  2732. }
  2733. if (parseFloat(m[ordering[i]]) !== toInt(m[ordering[i]])) {
  2734. unitHasDecimal = true;
  2735. }
  2736. }
  2737. }
  2738. return true;
  2739. }
  2740. function isValid$1() {
  2741. return this._isValid;
  2742. }
  2743. function createInvalid$1() {
  2744. return createDuration(NaN);
  2745. }
  2746. function Duration(duration) {
  2747. var normalizedInput = normalizeObjectUnits(duration),
  2748. years = normalizedInput.year || 0,
  2749. quarters = normalizedInput.quarter || 0,
  2750. months = normalizedInput.month || 0,
  2751. weeks = normalizedInput.week || normalizedInput.isoWeek || 0,
  2752. days = normalizedInput.day || 0,
  2753. hours = normalizedInput.hour || 0,
  2754. minutes = normalizedInput.minute || 0,
  2755. seconds = normalizedInput.second || 0,
  2756. milliseconds = normalizedInput.millisecond || 0;
  2757. this._isValid = isDurationValid(normalizedInput);
  2758. // representation for dateAddRemove
  2759. this._milliseconds =
  2760. +milliseconds +
  2761. seconds * 1e3 + // 1000
  2762. minutes * 6e4 + // 1000 * 60
  2763. hours * 1000 * 60 * 60; //using 1000 * 60 * 60 instead of 36e5 to avoid floating point rounding errors https://github.com/moment/moment/issues/2978
  2764. // Because of dateAddRemove treats 24 hours as different from a
  2765. // day when working around DST, we need to store them separately
  2766. this._days = +days + weeks * 7;
  2767. // It is impossible to translate months into days without knowing
  2768. // which months you are are talking about, so we have to store
  2769. // it separately.
  2770. this._months = +months + quarters * 3 + years * 12;
  2771. this._data = {};
  2772. this._locale = getLocale();
  2773. this._bubble();
  2774. }
  2775. function isDuration(obj) {
  2776. return obj instanceof Duration;
  2777. }
  2778. function absRound(number) {
  2779. if (number < 0) {
  2780. return Math.round(-1 * number) * -1;
  2781. } else {
  2782. return Math.round(number);
  2783. }
  2784. }
  2785. // compare two arrays, return the number of differences
  2786. function compareArrays(array1, array2, dontConvert) {
  2787. var len = Math.min(array1.length, array2.length),
  2788. lengthDiff = Math.abs(array1.length - array2.length),
  2789. diffs = 0,
  2790. i;
  2791. for (i = 0; i < len; i++) {
  2792. if (
  2793. (dontConvert && array1[i] !== array2[i]) ||
  2794. (!dontConvert && toInt(array1[i]) !== toInt(array2[i]))
  2795. ) {
  2796. diffs++;
  2797. }
  2798. }
  2799. return diffs + lengthDiff;
  2800. }
  2801. // FORMATTING
  2802. function offset(token, separator) {
  2803. addFormatToken(token, 0, 0, function () {
  2804. var offset = this.utcOffset(),
  2805. sign = '+';
  2806. if (offset < 0) {
  2807. offset = -offset;
  2808. sign = '-';
  2809. }
  2810. return (
  2811. sign +
  2812. zeroFill(~~(offset / 60), 2) +
  2813. separator +
  2814. zeroFill(~~offset % 60, 2)
  2815. );
  2816. });
  2817. }
  2818. offset('Z', ':');
  2819. offset('ZZ', '');
  2820. // PARSING
  2821. addRegexToken('Z', matchShortOffset);
  2822. addRegexToken('ZZ', matchShortOffset);
  2823. addParseToken(['Z', 'ZZ'], function (input, array, config) {
  2824. config._useUTC = true;
  2825. config._tzm = offsetFromString(matchShortOffset, input);
  2826. });
  2827. // HELPERS
  2828. // timezone chunker
  2829. // '+10:00' > ['10', '00']
  2830. // '-1530' > ['-15', '30']
  2831. var chunkOffset = /([\+\-]|\d\d)/gi;
  2832. function offsetFromString(matcher, string) {
  2833. var matches = (string || '').match(matcher),
  2834. chunk,
  2835. parts,
  2836. minutes;
  2837. if (matches === null) {
  2838. return null;
  2839. }
  2840. chunk = matches[matches.length - 1] || [];
  2841. parts = (chunk + '').match(chunkOffset) || ['-', 0, 0];
  2842. minutes = +(parts[1] * 60) + toInt(parts[2]);
  2843. return minutes === 0 ? 0 : parts[0] === '+' ? minutes : -minutes;
  2844. }
  2845. // Return a moment from input, that is local/utc/zone equivalent to model.
  2846. function cloneWithOffset(input, model) {
  2847. var res, diff;
  2848. if (model._isUTC) {
  2849. res = model.clone();
  2850. diff =
  2851. (isMoment(input) || isDate(input)
  2852. ? input.valueOf()
  2853. : createLocal(input).valueOf()) - res.valueOf();
  2854. // Use low-level api, because this fn is low-level api.
  2855. res._d.setTime(res._d.valueOf() + diff);
  2856. hooks.updateOffset(res, false);
  2857. return res;
  2858. } else {
  2859. return createLocal(input).local();
  2860. }
  2861. }
  2862. function getDateOffset(m) {
  2863. // On Firefox.24 Date#getTimezoneOffset returns a floating point.
  2864. // https://github.com/moment/moment/pull/1871
  2865. return -Math.round(m._d.getTimezoneOffset());
  2866. }
  2867. // HOOKS
  2868. // This function will be called whenever a moment is mutated.
  2869. // It is intended to keep the offset in sync with the timezone.
  2870. hooks.updateOffset = function () {};
  2871. // MOMENTS
  2872. // keepLocalTime = true means only change the timezone, without
  2873. // affecting the local hour. So 5:31:26 +0300 --[utcOffset(2, true)]-->
  2874. // 5:31:26 +0200 It is possible that 5:31:26 doesn't exist with offset
  2875. // +0200, so we adjust the time as needed, to be valid.
  2876. //
  2877. // Keeping the time actually adds/subtracts (one hour)
  2878. // from the actual represented time. That is why we call updateOffset
  2879. // a second time. In case it wants us to change the offset again
  2880. // _changeInProgress == true case, then we have to adjust, because
  2881. // there is no such time in the given timezone.
  2882. function getSetOffset(input, keepLocalTime, keepMinutes) {
  2883. var offset = this._offset || 0,
  2884. localAdjust;
  2885. if (!this.isValid()) {
  2886. return input != null ? this : NaN;
  2887. }
  2888. if (input != null) {
  2889. if (typeof input === 'string') {
  2890. input = offsetFromString(matchShortOffset, input);
  2891. if (input === null) {
  2892. return this;
  2893. }
  2894. } else if (Math.abs(input) < 16 && !keepMinutes) {
  2895. input = input * 60;
  2896. }
  2897. if (!this._isUTC && keepLocalTime) {
  2898. localAdjust = getDateOffset(this);
  2899. }
  2900. this._offset = input;
  2901. this._isUTC = true;
  2902. if (localAdjust != null) {
  2903. this.add(localAdjust, 'm');
  2904. }
  2905. if (offset !== input) {
  2906. if (!keepLocalTime || this._changeInProgress) {
  2907. addSubtract(
  2908. this,
  2909. createDuration(input - offset, 'm'),
  2910. 1,
  2911. false
  2912. );
  2913. } else if (!this._changeInProgress) {
  2914. this._changeInProgress = true;
  2915. hooks.updateOffset(this, true);
  2916. this._changeInProgress = null;
  2917. }
  2918. }
  2919. return this;
  2920. } else {
  2921. return this._isUTC ? offset : getDateOffset(this);
  2922. }
  2923. }
  2924. function getSetZone(input, keepLocalTime) {
  2925. if (input != null) {
  2926. if (typeof input !== 'string') {
  2927. input = -input;
  2928. }
  2929. this.utcOffset(input, keepLocalTime);
  2930. return this;
  2931. } else {
  2932. return -this.utcOffset();
  2933. }
  2934. }
  2935. function setOffsetToUTC(keepLocalTime) {
  2936. return this.utcOffset(0, keepLocalTime);
  2937. }
  2938. function setOffsetToLocal(keepLocalTime) {
  2939. if (this._isUTC) {
  2940. this.utcOffset(0, keepLocalTime);
  2941. this._isUTC = false;
  2942. if (keepLocalTime) {
  2943. this.subtract(getDateOffset(this), 'm');
  2944. }
  2945. }
  2946. return this;
  2947. }
  2948. function setOffsetToParsedOffset() {
  2949. if (this._tzm != null) {
  2950. this.utcOffset(this._tzm, false, true);
  2951. } else if (typeof this._i === 'string') {
  2952. var tZone = offsetFromString(matchOffset, this._i);
  2953. if (tZone != null) {
  2954. this.utcOffset(tZone);
  2955. } else {
  2956. this.utcOffset(0, true);
  2957. }
  2958. }
  2959. return this;
  2960. }
  2961. function hasAlignedHourOffset(input) {
  2962. if (!this.isValid()) {
  2963. return false;
  2964. }
  2965. input = input ? createLocal(input).utcOffset() : 0;
  2966. return (this.utcOffset() - input) % 60 === 0;
  2967. }
  2968. function isDaylightSavingTime() {
  2969. return (
  2970. this.utcOffset() > this.clone().month(0).utcOffset() ||
  2971. this.utcOffset() > this.clone().month(5).utcOffset()
  2972. );
  2973. }
  2974. function isDaylightSavingTimeShifted() {
  2975. if (!isUndefined(this._isDSTShifted)) {
  2976. return this._isDSTShifted;
  2977. }
  2978. var c = {},
  2979. other;
  2980. copyConfig(c, this);
  2981. c = prepareConfig(c);
  2982. if (c._a) {
  2983. other = c._isUTC ? createUTC(c._a) : createLocal(c._a);
  2984. this._isDSTShifted =
  2985. this.isValid() && compareArrays(c._a, other.toArray()) > 0;
  2986. } else {
  2987. this._isDSTShifted = false;
  2988. }
  2989. return this._isDSTShifted;
  2990. }
  2991. function isLocal() {
  2992. return this.isValid() ? !this._isUTC : false;
  2993. }
  2994. function isUtcOffset() {
  2995. return this.isValid() ? this._isUTC : false;
  2996. }
  2997. function isUtc() {
  2998. return this.isValid() ? this._isUTC && this._offset === 0 : false;
  2999. }
  3000. // ASP.NET json date format regex
  3001. var aspNetRegex = /^(-|\+)?(?:(\d*)[. ])?(\d+):(\d+)(?::(\d+)(\.\d*)?)?$/,
  3002. // from http://docs.closure-library.googlecode.com/git/closure_goog_date_date.js.source.html
  3003. // somewhat more in line with 4.4.3.2 2004 spec, but allows decimal anywhere
  3004. // and further modified to allow for strings containing both week and day
  3005. isoRegex = /^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/;
  3006. function createDuration(input, key) {
  3007. var duration = input,
  3008. // matching against regexp is expensive, do it on demand
  3009. match = null,
  3010. sign,
  3011. ret,
  3012. diffRes;
  3013. if (isDuration(input)) {
  3014. duration = {
  3015. ms: input._milliseconds,
  3016. d: input._days,
  3017. M: input._months,
  3018. };
  3019. } else if (isNumber(input) || !isNaN(+input)) {
  3020. duration = {};
  3021. if (key) {
  3022. duration[key] = +input;
  3023. } else {
  3024. duration.milliseconds = +input;
  3025. }
  3026. } else if ((match = aspNetRegex.exec(input))) {
  3027. sign = match[1] === '-' ? -1 : 1;
  3028. duration = {
  3029. y: 0,
  3030. d: toInt(match[DATE]) * sign,
  3031. h: toInt(match[HOUR]) * sign,
  3032. m: toInt(match[MINUTE]) * sign,
  3033. s: toInt(match[SECOND]) * sign,
  3034. ms: toInt(absRound(match[MILLISECOND] * 1000)) * sign, // the millisecond decimal point is included in the match
  3035. };
  3036. } else if ((match = isoRegex.exec(input))) {
  3037. sign = match[1] === '-' ? -1 : 1;
  3038. duration = {
  3039. y: parseIso(match[2], sign),
  3040. M: parseIso(match[3], sign),
  3041. w: parseIso(match[4], sign),
  3042. d: parseIso(match[5], sign),
  3043. h: parseIso(match[6], sign),
  3044. m: parseIso(match[7], sign),
  3045. s: parseIso(match[8], sign),
  3046. };
  3047. } else if (duration == null) {
  3048. // checks for null or undefined
  3049. duration = {};
  3050. } else if (
  3051. typeof duration === 'object' &&
  3052. ('from' in duration || 'to' in duration)
  3053. ) {
  3054. diffRes = momentsDifference(
  3055. createLocal(duration.from),
  3056. createLocal(duration.to)
  3057. );
  3058. duration = {};
  3059. duration.ms = diffRes.milliseconds;
  3060. duration.M = diffRes.months;
  3061. }
  3062. ret = new Duration(duration);
  3063. if (isDuration(input) && hasOwnProp(input, '_locale')) {
  3064. ret._locale = input._locale;
  3065. }
  3066. if (isDuration(input) && hasOwnProp(input, '_isValid')) {
  3067. ret._isValid = input._isValid;
  3068. }
  3069. return ret;
  3070. }
  3071. createDuration.fn = Duration.prototype;
  3072. createDuration.invalid = createInvalid$1;
  3073. function parseIso(inp, sign) {
  3074. // We'd normally use ~~inp for this, but unfortunately it also
  3075. // converts floats to ints.
  3076. // inp may be undefined, so careful calling replace on it.
  3077. var res = inp && parseFloat(inp.replace(',', '.'));
  3078. // apply sign while we're at it
  3079. return (isNaN(res) ? 0 : res) * sign;
  3080. }
  3081. function positiveMomentsDifference(base, other) {
  3082. var res = {};
  3083. res.months =
  3084. other.month() - base.month() + (other.year() - base.year()) * 12;
  3085. if (base.clone().add(res.months, 'M').isAfter(other)) {
  3086. --res.months;
  3087. }
  3088. res.milliseconds = +other - +base.clone().add(res.months, 'M');
  3089. return res;
  3090. }
  3091. function momentsDifference(base, other) {
  3092. var res;
  3093. if (!(base.isValid() && other.isValid())) {
  3094. return { milliseconds: 0, months: 0 };
  3095. }
  3096. other = cloneWithOffset(other, base);
  3097. if (base.isBefore(other)) {
  3098. res = positiveMomentsDifference(base, other);
  3099. } else {
  3100. res = positiveMomentsDifference(other, base);
  3101. res.milliseconds = -res.milliseconds;
  3102. res.months = -res.months;
  3103. }
  3104. return res;
  3105. }
  3106. // TODO: remove 'name' arg after deprecation is removed
  3107. function createAdder(direction, name) {
  3108. return function (val, period) {
  3109. var dur, tmp;
  3110. //invert the arguments, but complain about it
  3111. if (period !== null && !isNaN(+period)) {
  3112. deprecateSimple(
  3113. name,
  3114. 'moment().' +
  3115. name +
  3116. '(period, number) is deprecated. Please use moment().' +
  3117. name +
  3118. '(number, period). ' +
  3119. 'See http://momentjs.com/guides/#/warnings/add-inverted-param/ for more info.'
  3120. );
  3121. tmp = val;
  3122. val = period;
  3123. period = tmp;
  3124. }
  3125. dur = createDuration(val, period);
  3126. addSubtract(this, dur, direction);
  3127. return this;
  3128. };
  3129. }
  3130. function addSubtract(mom, duration, isAdding, updateOffset) {
  3131. var milliseconds = duration._milliseconds,
  3132. days = absRound(duration._days),
  3133. months = absRound(duration._months);
  3134. if (!mom.isValid()) {
  3135. // No op
  3136. return;
  3137. }
  3138. updateOffset = updateOffset == null ? true : updateOffset;
  3139. if (months) {
  3140. setMonth(mom, get(mom, 'Month') + months * isAdding);
  3141. }
  3142. if (days) {
  3143. set$1(mom, 'Date', get(mom, 'Date') + days * isAdding);
  3144. }
  3145. if (milliseconds) {
  3146. mom._d.setTime(mom._d.valueOf() + milliseconds * isAdding);
  3147. }
  3148. if (updateOffset) {
  3149. hooks.updateOffset(mom, days || months);
  3150. }
  3151. }
  3152. var add = createAdder(1, 'add'),
  3153. subtract = createAdder(-1, 'subtract');
  3154. function isString(input) {
  3155. return typeof input === 'string' || input instanceof String;
  3156. }
  3157. // type MomentInput = Moment | Date | string | number | (number | string)[] | MomentInputObject | void; // null | undefined
  3158. function isMomentInput(input) {
  3159. return (
  3160. isMoment(input) ||
  3161. isDate(input) ||
  3162. isString(input) ||
  3163. isNumber(input) ||
  3164. isNumberOrStringArray(input) ||
  3165. isMomentInputObject(input) ||
  3166. input === null ||
  3167. input === undefined
  3168. );
  3169. }
  3170. function isMomentInputObject(input) {
  3171. var objectTest = isObject(input) && !isObjectEmpty(input),
  3172. propertyTest = false,
  3173. properties = [
  3174. 'years',
  3175. 'year',
  3176. 'y',
  3177. 'months',
  3178. 'month',
  3179. 'M',
  3180. 'days',
  3181. 'day',
  3182. 'd',
  3183. 'dates',
  3184. 'date',
  3185. 'D',
  3186. 'hours',
  3187. 'hour',
  3188. 'h',
  3189. 'minutes',
  3190. 'minute',
  3191. 'm',
  3192. 'seconds',
  3193. 'second',
  3194. 's',
  3195. 'milliseconds',
  3196. 'millisecond',
  3197. 'ms',
  3198. ],
  3199. i,
  3200. property;
  3201. for (i = 0; i < properties.length; i += 1) {
  3202. property = properties[i];
  3203. propertyTest = propertyTest || hasOwnProp(input, property);
  3204. }
  3205. return objectTest && propertyTest;
  3206. }
  3207. function isNumberOrStringArray(input) {
  3208. var arrayTest = isArray(input),
  3209. dataTypeTest = false;
  3210. if (arrayTest) {
  3211. dataTypeTest =
  3212. input.filter(function (item) {
  3213. return !isNumber(item) && isString(input);
  3214. }).length === 0;
  3215. }
  3216. return arrayTest && dataTypeTest;
  3217. }
  3218. function isCalendarSpec(input) {
  3219. var objectTest = isObject(input) && !isObjectEmpty(input),
  3220. propertyTest = false,
  3221. properties = [
  3222. 'sameDay',
  3223. 'nextDay',
  3224. 'lastDay',
  3225. 'nextWeek',
  3226. 'lastWeek',
  3227. 'sameElse',
  3228. ],
  3229. i,
  3230. property;
  3231. for (i = 0; i < properties.length; i += 1) {
  3232. property = properties[i];
  3233. propertyTest = propertyTest || hasOwnProp(input, property);
  3234. }
  3235. return objectTest && propertyTest;
  3236. }
  3237. function getCalendarFormat(myMoment, now) {
  3238. var diff = myMoment.diff(now, 'days', true);
  3239. return diff < -6
  3240. ? 'sameElse'
  3241. : diff < -1
  3242. ? 'lastWeek'
  3243. : diff < 0
  3244. ? 'lastDay'
  3245. : diff < 1
  3246. ? 'sameDay'
  3247. : diff < 2
  3248. ? 'nextDay'
  3249. : diff < 7
  3250. ? 'nextWeek'
  3251. : 'sameElse';
  3252. }
  3253. function calendar$1(time, formats) {
  3254. // Support for single parameter, formats only overload to the calendar function
  3255. if (arguments.length === 1) {
  3256. if (!arguments[0]) {
  3257. time = undefined;
  3258. formats = undefined;
  3259. } else if (isMomentInput(arguments[0])) {
  3260. time = arguments[0];
  3261. formats = undefined;
  3262. } else if (isCalendarSpec(arguments[0])) {
  3263. formats = arguments[0];
  3264. time = undefined;
  3265. }
  3266. }
  3267. // We want to compare the start of today, vs this.
  3268. // Getting start-of-today depends on whether we're local/utc/offset or not.
  3269. var now = time || createLocal(),
  3270. sod = cloneWithOffset(now, this).startOf('day'),
  3271. format = hooks.calendarFormat(this, sod) || 'sameElse',
  3272. output =
  3273. formats &&
  3274. (isFunction(formats[format])
  3275. ? formats[format].call(this, now)
  3276. : formats[format]);
  3277. return this.format(
  3278. output || this.localeData().calendar(format, this, createLocal(now))
  3279. );
  3280. }
  3281. function clone() {
  3282. return new Moment(this);
  3283. }
  3284. function isAfter(input, units) {
  3285. var localInput = isMoment(input) ? input : createLocal(input);
  3286. if (!(this.isValid() && localInput.isValid())) {
  3287. return false;
  3288. }
  3289. units = normalizeUnits(units) || 'millisecond';
  3290. if (units === 'millisecond') {
  3291. return this.valueOf() > localInput.valueOf();
  3292. } else {
  3293. return localInput.valueOf() < this.clone().startOf(units).valueOf();
  3294. }
  3295. }
  3296. function isBefore(input, units) {
  3297. var localInput = isMoment(input) ? input : createLocal(input);
  3298. if (!(this.isValid() && localInput.isValid())) {
  3299. return false;
  3300. }
  3301. units = normalizeUnits(units) || 'millisecond';
  3302. if (units === 'millisecond') {
  3303. return this.valueOf() < localInput.valueOf();
  3304. } else {
  3305. return this.clone().endOf(units).valueOf() < localInput.valueOf();
  3306. }
  3307. }
  3308. function isBetween(from, to, units, inclusivity) {
  3309. var localFrom = isMoment(from) ? from : createLocal(from),
  3310. localTo = isMoment(to) ? to : createLocal(to);
  3311. if (!(this.isValid() && localFrom.isValid() && localTo.isValid())) {
  3312. return false;
  3313. }
  3314. inclusivity = inclusivity || '()';
  3315. return (
  3316. (inclusivity[0] === '('
  3317. ? this.isAfter(localFrom, units)
  3318. : !this.isBefore(localFrom, units)) &&
  3319. (inclusivity[1] === ')'
  3320. ? this.isBefore(localTo, units)
  3321. : !this.isAfter(localTo, units))
  3322. );
  3323. }
  3324. function isSame(input, units) {
  3325. var localInput = isMoment(input) ? input : createLocal(input),
  3326. inputMs;
  3327. if (!(this.isValid() && localInput.isValid())) {
  3328. return false;
  3329. }
  3330. units = normalizeUnits(units) || 'millisecond';
  3331. if (units === 'millisecond') {
  3332. return this.valueOf() === localInput.valueOf();
  3333. } else {
  3334. inputMs = localInput.valueOf();
  3335. return (
  3336. this.clone().startOf(units).valueOf() <= inputMs &&
  3337. inputMs <= this.clone().endOf(units).valueOf()
  3338. );
  3339. }
  3340. }
  3341. function isSameOrAfter(input, units) {
  3342. return this.isSame(input, units) || this.isAfter(input, units);
  3343. }
  3344. function isSameOrBefore(input, units) {
  3345. return this.isSame(input, units) || this.isBefore(input, units);
  3346. }
  3347. function diff(input, units, asFloat) {
  3348. var that, zoneDelta, output;
  3349. if (!this.isValid()) {
  3350. return NaN;
  3351. }
  3352. that = cloneWithOffset(input, this);
  3353. if (!that.isValid()) {
  3354. return NaN;
  3355. }
  3356. zoneDelta = (that.utcOffset() - this.utcOffset()) * 6e4;
  3357. units = normalizeUnits(units);
  3358. switch (units) {
  3359. case 'year':
  3360. output = monthDiff(this, that) / 12;
  3361. break;
  3362. case 'month':
  3363. output = monthDiff(this, that);
  3364. break;
  3365. case 'quarter':
  3366. output = monthDiff(this, that) / 3;
  3367. break;
  3368. case 'second':
  3369. output = (this - that) / 1e3;
  3370. break; // 1000
  3371. case 'minute':
  3372. output = (this - that) / 6e4;
  3373. break; // 1000 * 60
  3374. case 'hour':
  3375. output = (this - that) / 36e5;
  3376. break; // 1000 * 60 * 60
  3377. case 'day':
  3378. output = (this - that - zoneDelta) / 864e5;
  3379. break; // 1000 * 60 * 60 * 24, negate dst
  3380. case 'week':
  3381. output = (this - that - zoneDelta) / 6048e5;
  3382. break; // 1000 * 60 * 60 * 24 * 7, negate dst
  3383. default:
  3384. output = this - that;
  3385. }
  3386. return asFloat ? output : absFloor(output);
  3387. }
  3388. function monthDiff(a, b) {
  3389. if (a.date() < b.date()) {
  3390. // end-of-month calculations work correct when the start month has more
  3391. // days than the end month.
  3392. return -monthDiff(b, a);
  3393. }
  3394. // difference in months
  3395. var wholeMonthDiff = (b.year() - a.year()) * 12 + (b.month() - a.month()),
  3396. // b is in (anchor - 1 month, anchor + 1 month)
  3397. anchor = a.clone().add(wholeMonthDiff, 'months'),
  3398. anchor2,
  3399. adjust;
  3400. if (b - anchor < 0) {
  3401. anchor2 = a.clone().add(wholeMonthDiff - 1, 'months');
  3402. // linear across the month
  3403. adjust = (b - anchor) / (anchor - anchor2);
  3404. } else {
  3405. anchor2 = a.clone().add(wholeMonthDiff + 1, 'months');
  3406. // linear across the month
  3407. adjust = (b - anchor) / (anchor2 - anchor);
  3408. }
  3409. //check for negative zero, return zero if negative zero
  3410. return -(wholeMonthDiff + adjust) || 0;
  3411. }
  3412. hooks.defaultFormat = 'YYYY-MM-DDTHH:mm:ssZ';
  3413. hooks.defaultFormatUtc = 'YYYY-MM-DDTHH:mm:ss[Z]';
  3414. function toString() {
  3415. return this.clone().locale('en').format('ddd MMM DD YYYY HH:mm:ss [GMT]ZZ');
  3416. }
  3417. function toISOString(keepOffset) {
  3418. if (!this.isValid()) {
  3419. return null;
  3420. }
  3421. var utc = keepOffset !== true,
  3422. m = utc ? this.clone().utc() : this;
  3423. if (m.year() < 0 || m.year() > 9999) {
  3424. return formatMoment(
  3425. m,
  3426. utc
  3427. ? 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]'
  3428. : 'YYYYYY-MM-DD[T]HH:mm:ss.SSSZ'
  3429. );
  3430. }
  3431. if (isFunction(Date.prototype.toISOString)) {
  3432. // native implementation is ~50x faster, use it when we can
  3433. if (utc) {
  3434. return this.toDate().toISOString();
  3435. } else {
  3436. return new Date(this.valueOf() + this.utcOffset() * 60 * 1000)
  3437. .toISOString()
  3438. .replace('Z', formatMoment(m, 'Z'));
  3439. }
  3440. }
  3441. return formatMoment(
  3442. m,
  3443. utc ? 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]' : 'YYYY-MM-DD[T]HH:mm:ss.SSSZ'
  3444. );
  3445. }
  3446. /**
  3447. * Return a human readable representation of a moment that can
  3448. * also be evaluated to get a new moment which is the same
  3449. *
  3450. * @link https://nodejs.org/dist/latest/docs/api/util.html#util_custom_inspect_function_on_objects
  3451. */
  3452. function inspect() {
  3453. if (!this.isValid()) {
  3454. return 'moment.invalid(/* ' + this._i + ' */)';
  3455. }
  3456. var func = 'moment',
  3457. zone = '',
  3458. prefix,
  3459. year,
  3460. datetime,
  3461. suffix;
  3462. if (!this.isLocal()) {
  3463. func = this.utcOffset() === 0 ? 'moment.utc' : 'moment.parseZone';
  3464. zone = 'Z';
  3465. }
  3466. prefix = '[' + func + '("]';
  3467. year = 0 <= this.year() && this.year() <= 9999 ? 'YYYY' : 'YYYYYY';
  3468. datetime = '-MM-DD[T]HH:mm:ss.SSS';
  3469. suffix = zone + '[")]';
  3470. return this.format(prefix + year + datetime + suffix);
  3471. }
  3472. function format(inputString) {
  3473. if (!inputString) {
  3474. inputString = this.isUtc()
  3475. ? hooks.defaultFormatUtc
  3476. : hooks.defaultFormat;
  3477. }
  3478. var output = formatMoment(this, inputString);
  3479. return this.localeData().postformat(output);
  3480. }
  3481. function from(time, withoutSuffix) {
  3482. if (
  3483. this.isValid() &&
  3484. ((isMoment(time) && time.isValid()) || createLocal(time).isValid())
  3485. ) {
  3486. return createDuration({ to: this, from: time })
  3487. .locale(this.locale())
  3488. .humanize(!withoutSuffix);
  3489. } else {
  3490. return this.localeData().invalidDate();
  3491. }
  3492. }
  3493. function fromNow(withoutSuffix) {
  3494. return this.from(createLocal(), withoutSuffix);
  3495. }
  3496. function to(time, withoutSuffix) {
  3497. if (
  3498. this.isValid() &&
  3499. ((isMoment(time) && time.isValid()) || createLocal(time).isValid())
  3500. ) {
  3501. return createDuration({ from: this, to: time })
  3502. .locale(this.locale())
  3503. .humanize(!withoutSuffix);
  3504. } else {
  3505. return this.localeData().invalidDate();
  3506. }
  3507. }
  3508. function toNow(withoutSuffix) {
  3509. return this.to(createLocal(), withoutSuffix);
  3510. }
  3511. // If passed a locale key, it will set the locale for this
  3512. // instance. Otherwise, it will return the locale configuration
  3513. // variables for this instance.
  3514. function locale(key) {
  3515. var newLocaleData;
  3516. if (key === undefined) {
  3517. return this._locale._abbr;
  3518. } else {
  3519. newLocaleData = getLocale(key);
  3520. if (newLocaleData != null) {
  3521. this._locale = newLocaleData;
  3522. }
  3523. return this;
  3524. }
  3525. }
  3526. var lang = deprecate(
  3527. 'moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.',
  3528. function (key) {
  3529. if (key === undefined) {
  3530. return this.localeData();
  3531. } else {
  3532. return this.locale(key);
  3533. }
  3534. }
  3535. );
  3536. function localeData() {
  3537. return this._locale;
  3538. }
  3539. var MS_PER_SECOND = 1000,
  3540. MS_PER_MINUTE = 60 * MS_PER_SECOND,
  3541. MS_PER_HOUR = 60 * MS_PER_MINUTE,
  3542. MS_PER_400_YEARS = (365 * 400 + 97) * 24 * MS_PER_HOUR;
  3543. // actual modulo - handles negative numbers (for dates before 1970):
  3544. function mod$1(dividend, divisor) {
  3545. return ((dividend % divisor) + divisor) % divisor;
  3546. }
  3547. function localStartOfDate(y, m, d) {
  3548. // the date constructor remaps years 0-99 to 1900-1999
  3549. if (y < 100 && y >= 0) {
  3550. // preserve leap years using a full 400 year cycle, then reset
  3551. return new Date(y + 400, m, d) - MS_PER_400_YEARS;
  3552. } else {
  3553. return new Date(y, m, d).valueOf();
  3554. }
  3555. }
  3556. function utcStartOfDate(y, m, d) {
  3557. // Date.UTC remaps years 0-99 to 1900-1999
  3558. if (y < 100 && y >= 0) {
  3559. // preserve leap years using a full 400 year cycle, then reset
  3560. return Date.UTC(y + 400, m, d) - MS_PER_400_YEARS;
  3561. } else {
  3562. return Date.UTC(y, m, d);
  3563. }
  3564. }
  3565. function startOf(units) {
  3566. var time, startOfDate;
  3567. units = normalizeUnits(units);
  3568. if (units === undefined || units === 'millisecond' || !this.isValid()) {
  3569. return this;
  3570. }
  3571. startOfDate = this._isUTC ? utcStartOfDate : localStartOfDate;
  3572. switch (units) {
  3573. case 'year':
  3574. time = startOfDate(this.year(), 0, 1);
  3575. break;
  3576. case 'quarter':
  3577. time = startOfDate(
  3578. this.year(),
  3579. this.month() - (this.month() % 3),
  3580. 1
  3581. );
  3582. break;
  3583. case 'month':
  3584. time = startOfDate(this.year(), this.month(), 1);
  3585. break;
  3586. case 'week':
  3587. time = startOfDate(
  3588. this.year(),
  3589. this.month(),
  3590. this.date() - this.weekday()
  3591. );
  3592. break;
  3593. case 'isoWeek':
  3594. time = startOfDate(
  3595. this.year(),
  3596. this.month(),
  3597. this.date() - (this.isoWeekday() - 1)
  3598. );
  3599. break;
  3600. case 'day':
  3601. case 'date':
  3602. time = startOfDate(this.year(), this.month(), this.date());
  3603. break;
  3604. case 'hour':
  3605. time = this._d.valueOf();
  3606. time -= mod$1(
  3607. time + (this._isUTC ? 0 : this.utcOffset() * MS_PER_MINUTE),
  3608. MS_PER_HOUR
  3609. );
  3610. break;
  3611. case 'minute':
  3612. time = this._d.valueOf();
  3613. time -= mod$1(time, MS_PER_MINUTE);
  3614. break;
  3615. case 'second':
  3616. time = this._d.valueOf();
  3617. time -= mod$1(time, MS_PER_SECOND);
  3618. break;
  3619. }
  3620. this._d.setTime(time);
  3621. hooks.updateOffset(this, true);
  3622. return this;
  3623. }
  3624. function endOf(units) {
  3625. var time, startOfDate;
  3626. units = normalizeUnits(units);
  3627. if (units === undefined || units === 'millisecond' || !this.isValid()) {
  3628. return this;
  3629. }
  3630. startOfDate = this._isUTC ? utcStartOfDate : localStartOfDate;
  3631. switch (units) {
  3632. case 'year':
  3633. time = startOfDate(this.year() + 1, 0, 1) - 1;
  3634. break;
  3635. case 'quarter':
  3636. time =
  3637. startOfDate(
  3638. this.year(),
  3639. this.month() - (this.month() % 3) + 3,
  3640. 1
  3641. ) - 1;
  3642. break;
  3643. case 'month':
  3644. time = startOfDate(this.year(), this.month() + 1, 1) - 1;
  3645. break;
  3646. case 'week':
  3647. time =
  3648. startOfDate(
  3649. this.year(),
  3650. this.month(),
  3651. this.date() - this.weekday() + 7
  3652. ) - 1;
  3653. break;
  3654. case 'isoWeek':
  3655. time =
  3656. startOfDate(
  3657. this.year(),
  3658. this.month(),
  3659. this.date() - (this.isoWeekday() - 1) + 7
  3660. ) - 1;
  3661. break;
  3662. case 'day':
  3663. case 'date':
  3664. time = startOfDate(this.year(), this.month(), this.date() + 1) - 1;
  3665. break;
  3666. case 'hour':
  3667. time = this._d.valueOf();
  3668. time +=
  3669. MS_PER_HOUR -
  3670. mod$1(
  3671. time + (this._isUTC ? 0 : this.utcOffset() * MS_PER_MINUTE),
  3672. MS_PER_HOUR
  3673. ) -
  3674. 1;
  3675. break;
  3676. case 'minute':
  3677. time = this._d.valueOf();
  3678. time += MS_PER_MINUTE - mod$1(time, MS_PER_MINUTE) - 1;
  3679. break;
  3680. case 'second':
  3681. time = this._d.valueOf();
  3682. time += MS_PER_SECOND - mod$1(time, MS_PER_SECOND) - 1;
  3683. break;
  3684. }
  3685. this._d.setTime(time);
  3686. hooks.updateOffset(this, true);
  3687. return this;
  3688. }
  3689. function valueOf() {
  3690. return this._d.valueOf() - (this._offset || 0) * 60000;
  3691. }
  3692. function unix() {
  3693. return Math.floor(this.valueOf() / 1000);
  3694. }
  3695. function toDate() {
  3696. return new Date(this.valueOf());
  3697. }
  3698. function toArray() {
  3699. var m = this;
  3700. return [
  3701. m.year(),
  3702. m.month(),
  3703. m.date(),
  3704. m.hour(),
  3705. m.minute(),
  3706. m.second(),
  3707. m.millisecond(),
  3708. ];
  3709. }
  3710. function toObject() {
  3711. var m = this;
  3712. return {
  3713. years: m.year(),
  3714. months: m.month(),
  3715. date: m.date(),
  3716. hours: m.hours(),
  3717. minutes: m.minutes(),
  3718. seconds: m.seconds(),
  3719. milliseconds: m.milliseconds(),
  3720. };
  3721. }
  3722. function toJSON() {
  3723. // new Date(NaN).toJSON() === null
  3724. return this.isValid() ? this.toISOString() : null;
  3725. }
  3726. function isValid$2() {
  3727. return isValid(this);
  3728. }
  3729. function parsingFlags() {
  3730. return extend({}, getParsingFlags(this));
  3731. }
  3732. function invalidAt() {
  3733. return getParsingFlags(this).overflow;
  3734. }
  3735. function creationData() {
  3736. return {
  3737. input: this._i,
  3738. format: this._f,
  3739. locale: this._locale,
  3740. isUTC: this._isUTC,
  3741. strict: this._strict,
  3742. };
  3743. }
  3744. addFormatToken('N', 0, 0, 'eraAbbr');
  3745. addFormatToken('NN', 0, 0, 'eraAbbr');
  3746. addFormatToken('NNN', 0, 0, 'eraAbbr');
  3747. addFormatToken('NNNN', 0, 0, 'eraName');
  3748. addFormatToken('NNNNN', 0, 0, 'eraNarrow');
  3749. addFormatToken('y', ['y', 1], 'yo', 'eraYear');
  3750. addFormatToken('y', ['yy', 2], 0, 'eraYear');
  3751. addFormatToken('y', ['yyy', 3], 0, 'eraYear');
  3752. addFormatToken('y', ['yyyy', 4], 0, 'eraYear');
  3753. addRegexToken('N', matchEraAbbr);
  3754. addRegexToken('NN', matchEraAbbr);
  3755. addRegexToken('NNN', matchEraAbbr);
  3756. addRegexToken('NNNN', matchEraName);
  3757. addRegexToken('NNNNN', matchEraNarrow);
  3758. addParseToken(['N', 'NN', 'NNN', 'NNNN', 'NNNNN'], function (
  3759. input,
  3760. array,
  3761. config,
  3762. token
  3763. ) {
  3764. var era = config._locale.erasParse(input, token, config._strict);
  3765. if (era) {
  3766. getParsingFlags(config).era = era;
  3767. } else {
  3768. getParsingFlags(config).invalidEra = input;
  3769. }
  3770. });
  3771. addRegexToken('y', matchUnsigned);
  3772. addRegexToken('yy', matchUnsigned);
  3773. addRegexToken('yyy', matchUnsigned);
  3774. addRegexToken('yyyy', matchUnsigned);
  3775. addRegexToken('yo', matchEraYearOrdinal);
  3776. addParseToken(['y', 'yy', 'yyy', 'yyyy'], YEAR);
  3777. addParseToken(['yo'], function (input, array, config, token) {
  3778. var match;
  3779. if (config._locale._eraYearOrdinalRegex) {
  3780. match = input.match(config._locale._eraYearOrdinalRegex);
  3781. }
  3782. if (config._locale.eraYearOrdinalParse) {
  3783. array[YEAR] = config._locale.eraYearOrdinalParse(input, match);
  3784. } else {
  3785. array[YEAR] = parseInt(input, 10);
  3786. }
  3787. });
  3788. function localeEras(m, format) {
  3789. var i,
  3790. l,
  3791. date,
  3792. eras = this._eras || getLocale('en')._eras;
  3793. for (i = 0, l = eras.length; i < l; ++i) {
  3794. switch (typeof eras[i].since) {
  3795. case 'string':
  3796. // truncate time
  3797. date = hooks(eras[i].since).startOf('day');
  3798. eras[i].since = date.valueOf();
  3799. break;
  3800. }
  3801. switch (typeof eras[i].until) {
  3802. case 'undefined':
  3803. eras[i].until = +Infinity;
  3804. break;
  3805. case 'string':
  3806. // truncate time
  3807. date = hooks(eras[i].until).startOf('day').valueOf();
  3808. eras[i].until = date.valueOf();
  3809. break;
  3810. }
  3811. }
  3812. return eras;
  3813. }
  3814. function localeErasParse(eraName, format, strict) {
  3815. var i,
  3816. l,
  3817. eras = this.eras(),
  3818. name,
  3819. abbr,
  3820. narrow;
  3821. eraName = eraName.toUpperCase();
  3822. for (i = 0, l = eras.length; i < l; ++i) {
  3823. name = eras[i].name.toUpperCase();
  3824. abbr = eras[i].abbr.toUpperCase();
  3825. narrow = eras[i].narrow.toUpperCase();
  3826. if (strict) {
  3827. switch (format) {
  3828. case 'N':
  3829. case 'NN':
  3830. case 'NNN':
  3831. if (abbr === eraName) {
  3832. return eras[i];
  3833. }
  3834. break;
  3835. case 'NNNN':
  3836. if (name === eraName) {
  3837. return eras[i];
  3838. }
  3839. break;
  3840. case 'NNNNN':
  3841. if (narrow === eraName) {
  3842. return eras[i];
  3843. }
  3844. break;
  3845. }
  3846. } else if ([name, abbr, narrow].indexOf(eraName) >= 0) {
  3847. return eras[i];
  3848. }
  3849. }
  3850. }
  3851. function localeErasConvertYear(era, year) {
  3852. var dir = era.since <= era.until ? +1 : -1;
  3853. if (year === undefined) {
  3854. return hooks(era.since).year();
  3855. } else {
  3856. return hooks(era.since).year() + (year - era.offset) * dir;
  3857. }
  3858. }
  3859. function getEraName() {
  3860. var i,
  3861. l,
  3862. val,
  3863. eras = this.localeData().eras();
  3864. for (i = 0, l = eras.length; i < l; ++i) {
  3865. // truncate time
  3866. val = this.clone().startOf('day').valueOf();
  3867. if (eras[i].since <= val && val <= eras[i].until) {
  3868. return eras[i].name;
  3869. }
  3870. if (eras[i].until <= val && val <= eras[i].since) {
  3871. return eras[i].name;
  3872. }
  3873. }
  3874. return '';
  3875. }
  3876. function getEraNarrow() {
  3877. var i,
  3878. l,
  3879. val,
  3880. eras = this.localeData().eras();
  3881. for (i = 0, l = eras.length; i < l; ++i) {
  3882. // truncate time
  3883. val = this.clone().startOf('day').valueOf();
  3884. if (eras[i].since <= val && val <= eras[i].until) {
  3885. return eras[i].narrow;
  3886. }
  3887. if (eras[i].until <= val && val <= eras[i].since) {
  3888. return eras[i].narrow;
  3889. }
  3890. }
  3891. return '';
  3892. }
  3893. function getEraAbbr() {
  3894. var i,
  3895. l,
  3896. val,
  3897. eras = this.localeData().eras();
  3898. for (i = 0, l = eras.length; i < l; ++i) {
  3899. // truncate time
  3900. val = this.clone().startOf('day').valueOf();
  3901. if (eras[i].since <= val && val <= eras[i].until) {
  3902. return eras[i].abbr;
  3903. }
  3904. if (eras[i].until <= val && val <= eras[i].since) {
  3905. return eras[i].abbr;
  3906. }
  3907. }
  3908. return '';
  3909. }
  3910. function getEraYear() {
  3911. var i,
  3912. l,
  3913. dir,
  3914. val,
  3915. eras = this.localeData().eras();
  3916. for (i = 0, l = eras.length; i < l; ++i) {
  3917. dir = eras[i].since <= eras[i].until ? +1 : -1;
  3918. // truncate time
  3919. val = this.clone().startOf('day').valueOf();
  3920. if (
  3921. (eras[i].since <= val && val <= eras[i].until) ||
  3922. (eras[i].until <= val && val <= eras[i].since)
  3923. ) {
  3924. return (
  3925. (this.year() - hooks(eras[i].since).year()) * dir +
  3926. eras[i].offset
  3927. );
  3928. }
  3929. }
  3930. return this.year();
  3931. }
  3932. function erasNameRegex(isStrict) {
  3933. if (!hasOwnProp(this, '_erasNameRegex')) {
  3934. computeErasParse.call(this);
  3935. }
  3936. return isStrict ? this._erasNameRegex : this._erasRegex;
  3937. }
  3938. function erasAbbrRegex(isStrict) {
  3939. if (!hasOwnProp(this, '_erasAbbrRegex')) {
  3940. computeErasParse.call(this);
  3941. }
  3942. return isStrict ? this._erasAbbrRegex : this._erasRegex;
  3943. }
  3944. function erasNarrowRegex(isStrict) {
  3945. if (!hasOwnProp(this, '_erasNarrowRegex')) {
  3946. computeErasParse.call(this);
  3947. }
  3948. return isStrict ? this._erasNarrowRegex : this._erasRegex;
  3949. }
  3950. function matchEraAbbr(isStrict, locale) {
  3951. return locale.erasAbbrRegex(isStrict);
  3952. }
  3953. function matchEraName(isStrict, locale) {
  3954. return locale.erasNameRegex(isStrict);
  3955. }
  3956. function matchEraNarrow(isStrict, locale) {
  3957. return locale.erasNarrowRegex(isStrict);
  3958. }
  3959. function matchEraYearOrdinal(isStrict, locale) {
  3960. return locale._eraYearOrdinalRegex || matchUnsigned;
  3961. }
  3962. function computeErasParse() {
  3963. var abbrPieces = [],
  3964. namePieces = [],
  3965. narrowPieces = [],
  3966. mixedPieces = [],
  3967. i,
  3968. l,
  3969. eras = this.eras();
  3970. for (i = 0, l = eras.length; i < l; ++i) {
  3971. namePieces.push(regexEscape(eras[i].name));
  3972. abbrPieces.push(regexEscape(eras[i].abbr));
  3973. narrowPieces.push(regexEscape(eras[i].narrow));
  3974. mixedPieces.push(regexEscape(eras[i].name));
  3975. mixedPieces.push(regexEscape(eras[i].abbr));
  3976. mixedPieces.push(regexEscape(eras[i].narrow));
  3977. }
  3978. this._erasRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i');
  3979. this._erasNameRegex = new RegExp('^(' + namePieces.join('|') + ')', 'i');
  3980. this._erasAbbrRegex = new RegExp('^(' + abbrPieces.join('|') + ')', 'i');
  3981. this._erasNarrowRegex = new RegExp(
  3982. '^(' + narrowPieces.join('|') + ')',
  3983. 'i'
  3984. );
  3985. }
  3986. // FORMATTING
  3987. addFormatToken(0, ['gg', 2], 0, function () {
  3988. return this.weekYear() % 100;
  3989. });
  3990. addFormatToken(0, ['GG', 2], 0, function () {
  3991. return this.isoWeekYear() % 100;
  3992. });
  3993. function addWeekYearFormatToken(token, getter) {
  3994. addFormatToken(0, [token, token.length], 0, getter);
  3995. }
  3996. addWeekYearFormatToken('gggg', 'weekYear');
  3997. addWeekYearFormatToken('ggggg', 'weekYear');
  3998. addWeekYearFormatToken('GGGG', 'isoWeekYear');
  3999. addWeekYearFormatToken('GGGGG', 'isoWeekYear');
  4000. // ALIASES
  4001. addUnitAlias('weekYear', 'gg');
  4002. addUnitAlias('isoWeekYear', 'GG');
  4003. // PRIORITY
  4004. addUnitPriority('weekYear', 1);
  4005. addUnitPriority('isoWeekYear', 1);
  4006. // PARSING
  4007. addRegexToken('G', matchSigned);
  4008. addRegexToken('g', matchSigned);
  4009. addRegexToken('GG', match1to2, match2);
  4010. addRegexToken('gg', match1to2, match2);
  4011. addRegexToken('GGGG', match1to4, match4);
  4012. addRegexToken('gggg', match1to4, match4);
  4013. addRegexToken('GGGGG', match1to6, match6);
  4014. addRegexToken('ggggg', match1to6, match6);
  4015. addWeekParseToken(['gggg', 'ggggg', 'GGGG', 'GGGGG'], function (
  4016. input,
  4017. week,
  4018. config,
  4019. token
  4020. ) {
  4021. week[token.substr(0, 2)] = toInt(input);
  4022. });
  4023. addWeekParseToken(['gg', 'GG'], function (input, week, config, token) {
  4024. week[token] = hooks.parseTwoDigitYear(input);
  4025. });
  4026. // MOMENTS
  4027. function getSetWeekYear(input) {
  4028. return getSetWeekYearHelper.call(
  4029. this,
  4030. input,
  4031. this.week(),
  4032. this.weekday(),
  4033. this.localeData()._week.dow,
  4034. this.localeData()._week.doy
  4035. );
  4036. }
  4037. function getSetISOWeekYear(input) {
  4038. return getSetWeekYearHelper.call(
  4039. this,
  4040. input,
  4041. this.isoWeek(),
  4042. this.isoWeekday(),
  4043. 1,
  4044. 4
  4045. );
  4046. }
  4047. function getISOWeeksInYear() {
  4048. return weeksInYear(this.year(), 1, 4);
  4049. }
  4050. function getISOWeeksInISOWeekYear() {
  4051. return weeksInYear(this.isoWeekYear(), 1, 4);
  4052. }
  4053. function getWeeksInYear() {
  4054. var weekInfo = this.localeData()._week;
  4055. return weeksInYear(this.year(), weekInfo.dow, weekInfo.doy);
  4056. }
  4057. function getWeeksInWeekYear() {
  4058. var weekInfo = this.localeData()._week;
  4059. return weeksInYear(this.weekYear(), weekInfo.dow, weekInfo.doy);
  4060. }
  4061. function getSetWeekYearHelper(input, week, weekday, dow, doy) {
  4062. var weeksTarget;
  4063. if (input == null) {
  4064. return weekOfYear(this, dow, doy).year;
  4065. } else {
  4066. weeksTarget = weeksInYear(input, dow, doy);
  4067. if (week > weeksTarget) {
  4068. week = weeksTarget;
  4069. }
  4070. return setWeekAll.call(this, input, week, weekday, dow, doy);
  4071. }
  4072. }
  4073. function setWeekAll(weekYear, week, weekday, dow, doy) {
  4074. var dayOfYearData = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy),
  4075. date = createUTCDate(dayOfYearData.year, 0, dayOfYearData.dayOfYear);
  4076. this.year(date.getUTCFullYear());
  4077. this.month(date.getUTCMonth());
  4078. this.date(date.getUTCDate());
  4079. return this;
  4080. }
  4081. // FORMATTING
  4082. addFormatToken('Q', 0, 'Qo', 'quarter');
  4083. // ALIASES
  4084. addUnitAlias('quarter', 'Q');
  4085. // PRIORITY
  4086. addUnitPriority('quarter', 7);
  4087. // PARSING
  4088. addRegexToken('Q', match1);
  4089. addParseToken('Q', function (input, array) {
  4090. array[MONTH] = (toInt(input) - 1) * 3;
  4091. });
  4092. // MOMENTS
  4093. function getSetQuarter(input) {
  4094. return input == null
  4095. ? Math.ceil((this.month() + 1) / 3)
  4096. : this.month((input - 1) * 3 + (this.month() % 3));
  4097. }
  4098. // FORMATTING
  4099. addFormatToken('D', ['DD', 2], 'Do', 'date');
  4100. // ALIASES
  4101. addUnitAlias('date', 'D');
  4102. // PRIORITY
  4103. addUnitPriority('date', 9);
  4104. // PARSING
  4105. addRegexToken('D', match1to2);
  4106. addRegexToken('DD', match1to2, match2);
  4107. addRegexToken('Do', function (isStrict, locale) {
  4108. // TODO: Remove "ordinalParse" fallback in next major release.
  4109. return isStrict
  4110. ? locale._dayOfMonthOrdinalParse || locale._ordinalParse
  4111. : locale._dayOfMonthOrdinalParseLenient;
  4112. });
  4113. addParseToken(['D', 'DD'], DATE);
  4114. addParseToken('Do', function (input, array) {
  4115. array[DATE] = toInt(input.match(match1to2)[0]);
  4116. });
  4117. // MOMENTS
  4118. var getSetDayOfMonth = makeGetSet('Date', true);
  4119. // FORMATTING
  4120. addFormatToken('DDD', ['DDDD', 3], 'DDDo', 'dayOfYear');
  4121. // ALIASES
  4122. addUnitAlias('dayOfYear', 'DDD');
  4123. // PRIORITY
  4124. addUnitPriority('dayOfYear', 4);
  4125. // PARSING
  4126. addRegexToken('DDD', match1to3);
  4127. addRegexToken('DDDD', match3);
  4128. addParseToken(['DDD', 'DDDD'], function (input, array, config) {
  4129. config._dayOfYear = toInt(input);
  4130. });
  4131. // HELPERS
  4132. // MOMENTS
  4133. function getSetDayOfYear(input) {
  4134. var dayOfYear =
  4135. Math.round(
  4136. (this.clone().startOf('day') - this.clone().startOf('year')) / 864e5
  4137. ) + 1;
  4138. return input == null ? dayOfYear : this.add(input - dayOfYear, 'd');
  4139. }
  4140. // FORMATTING
  4141. addFormatToken('m', ['mm', 2], 0, 'minute');
  4142. // ALIASES
  4143. addUnitAlias('minute', 'm');
  4144. // PRIORITY
  4145. addUnitPriority('minute', 14);
  4146. // PARSING
  4147. addRegexToken('m', match1to2);
  4148. addRegexToken('mm', match1to2, match2);
  4149. addParseToken(['m', 'mm'], MINUTE);
  4150. // MOMENTS
  4151. var getSetMinute = makeGetSet('Minutes', false);
  4152. // FORMATTING
  4153. addFormatToken('s', ['ss', 2], 0, 'second');
  4154. // ALIASES
  4155. addUnitAlias('second', 's');
  4156. // PRIORITY
  4157. addUnitPriority('second', 15);
  4158. // PARSING
  4159. addRegexToken('s', match1to2);
  4160. addRegexToken('ss', match1to2, match2);
  4161. addParseToken(['s', 'ss'], SECOND);
  4162. // MOMENTS
  4163. var getSetSecond = makeGetSet('Seconds', false);
  4164. // FORMATTING
  4165. addFormatToken('S', 0, 0, function () {
  4166. return ~~(this.millisecond() / 100);
  4167. });
  4168. addFormatToken(0, ['SS', 2], 0, function () {
  4169. return ~~(this.millisecond() / 10);
  4170. });
  4171. addFormatToken(0, ['SSS', 3], 0, 'millisecond');
  4172. addFormatToken(0, ['SSSS', 4], 0, function () {
  4173. return this.millisecond() * 10;
  4174. });
  4175. addFormatToken(0, ['SSSSS', 5], 0, function () {
  4176. return this.millisecond() * 100;
  4177. });
  4178. addFormatToken(0, ['SSSSSS', 6], 0, function () {
  4179. return this.millisecond() * 1000;
  4180. });
  4181. addFormatToken(0, ['SSSSSSS', 7], 0, function () {
  4182. return this.millisecond() * 10000;
  4183. });
  4184. addFormatToken(0, ['SSSSSSSS', 8], 0, function () {
  4185. return this.millisecond() * 100000;
  4186. });
  4187. addFormatToken(0, ['SSSSSSSSS', 9], 0, function () {
  4188. return this.millisecond() * 1000000;
  4189. });
  4190. // ALIASES
  4191. addUnitAlias('millisecond', 'ms');
  4192. // PRIORITY
  4193. addUnitPriority('millisecond', 16);
  4194. // PARSING
  4195. addRegexToken('S', match1to3, match1);
  4196. addRegexToken('SS', match1to3, match2);
  4197. addRegexToken('SSS', match1to3, match3);
  4198. var token, getSetMillisecond;
  4199. for (token = 'SSSS'; token.length <= 9; token += 'S') {
  4200. addRegexToken(token, matchUnsigned);
  4201. }
  4202. function parseMs(input, array) {
  4203. array[MILLISECOND] = toInt(('0.' + input) * 1000);
  4204. }
  4205. for (token = 'S'; token.length <= 9; token += 'S') {
  4206. addParseToken(token, parseMs);
  4207. }
  4208. getSetMillisecond = makeGetSet('Milliseconds', false);
  4209. // FORMATTING
  4210. addFormatToken('z', 0, 0, 'zoneAbbr');
  4211. addFormatToken('zz', 0, 0, 'zoneName');
  4212. // MOMENTS
  4213. function getZoneAbbr() {
  4214. return this._isUTC ? 'UTC' : '';
  4215. }
  4216. function getZoneName() {
  4217. return this._isUTC ? 'Coordinated Universal Time' : '';
  4218. }
  4219. var proto = Moment.prototype;
  4220. proto.add = add;
  4221. proto.calendar = calendar$1;
  4222. proto.clone = clone;
  4223. proto.diff = diff;
  4224. proto.endOf = endOf;
  4225. proto.format = format;
  4226. proto.from = from;
  4227. proto.fromNow = fromNow;
  4228. proto.to = to;
  4229. proto.toNow = toNow;
  4230. proto.get = stringGet;
  4231. proto.invalidAt = invalidAt;
  4232. proto.isAfter = isAfter;
  4233. proto.isBefore = isBefore;
  4234. proto.isBetween = isBetween;
  4235. proto.isSame = isSame;
  4236. proto.isSameOrAfter = isSameOrAfter;
  4237. proto.isSameOrBefore = isSameOrBefore;
  4238. proto.isValid = isValid$2;
  4239. proto.lang = lang;
  4240. proto.locale = locale;
  4241. proto.localeData = localeData;
  4242. proto.max = prototypeMax;
  4243. proto.min = prototypeMin;
  4244. proto.parsingFlags = parsingFlags;
  4245. proto.set = stringSet;
  4246. proto.startOf = startOf;
  4247. proto.subtract = subtract;
  4248. proto.toArray = toArray;
  4249. proto.toObject = toObject;
  4250. proto.toDate = toDate;
  4251. proto.toISOString = toISOString;
  4252. proto.inspect = inspect;
  4253. if (typeof Symbol !== 'undefined' && Symbol.for != null) {
  4254. proto[Symbol.for('nodejs.util.inspect.custom')] = function () {
  4255. return 'Moment<' + this.format() + '>';
  4256. };
  4257. }
  4258. proto.toJSON = toJSON;
  4259. proto.toString = toString;
  4260. proto.unix = unix;
  4261. proto.valueOf = valueOf;
  4262. proto.creationData = creationData;
  4263. proto.eraName = getEraName;
  4264. proto.eraNarrow = getEraNarrow;
  4265. proto.eraAbbr = getEraAbbr;
  4266. proto.eraYear = getEraYear;
  4267. proto.year = getSetYear;
  4268. proto.isLeapYear = getIsLeapYear;
  4269. proto.weekYear = getSetWeekYear;
  4270. proto.isoWeekYear = getSetISOWeekYear;
  4271. proto.quarter = proto.quarters = getSetQuarter;
  4272. proto.month = getSetMonth;
  4273. proto.daysInMonth = getDaysInMonth;
  4274. proto.week = proto.weeks = getSetWeek;
  4275. proto.isoWeek = proto.isoWeeks = getSetISOWeek;
  4276. proto.weeksInYear = getWeeksInYear;
  4277. proto.weeksInWeekYear = getWeeksInWeekYear;
  4278. proto.isoWeeksInYear = getISOWeeksInYear;
  4279. proto.isoWeeksInISOWeekYear = getISOWeeksInISOWeekYear;
  4280. proto.date = getSetDayOfMonth;
  4281. proto.day = proto.days = getSetDayOfWeek;
  4282. proto.weekday = getSetLocaleDayOfWeek;
  4283. proto.isoWeekday = getSetISODayOfWeek;
  4284. proto.dayOfYear = getSetDayOfYear;
  4285. proto.hour = proto.hours = getSetHour;
  4286. proto.minute = proto.minutes = getSetMinute;
  4287. proto.second = proto.seconds = getSetSecond;
  4288. proto.millisecond = proto.milliseconds = getSetMillisecond;
  4289. proto.utcOffset = getSetOffset;
  4290. proto.utc = setOffsetToUTC;
  4291. proto.local = setOffsetToLocal;
  4292. proto.parseZone = setOffsetToParsedOffset;
  4293. proto.hasAlignedHourOffset = hasAlignedHourOffset;
  4294. proto.isDST = isDaylightSavingTime;
  4295. proto.isLocal = isLocal;
  4296. proto.isUtcOffset = isUtcOffset;
  4297. proto.isUtc = isUtc;
  4298. proto.isUTC = isUtc;
  4299. proto.zoneAbbr = getZoneAbbr;
  4300. proto.zoneName = getZoneName;
  4301. proto.dates = deprecate(
  4302. 'dates accessor is deprecated. Use date instead.',
  4303. getSetDayOfMonth
  4304. );
  4305. proto.months = deprecate(
  4306. 'months accessor is deprecated. Use month instead',
  4307. getSetMonth
  4308. );
  4309. proto.years = deprecate(
  4310. 'years accessor is deprecated. Use year instead',
  4311. getSetYear
  4312. );
  4313. proto.zone = deprecate(
  4314. 'moment().zone is deprecated, use moment().utcOffset instead. http://momentjs.com/guides/#/warnings/zone/',
  4315. getSetZone
  4316. );
  4317. proto.isDSTShifted = deprecate(
  4318. 'isDSTShifted is deprecated. See http://momentjs.com/guides/#/warnings/dst-shifted/ for more information',
  4319. isDaylightSavingTimeShifted
  4320. );
  4321. function createUnix(input) {
  4322. return createLocal(input * 1000);
  4323. }
  4324. function createInZone() {
  4325. return createLocal.apply(null, arguments).parseZone();
  4326. }
  4327. function preParsePostFormat(string) {
  4328. return string;
  4329. }
  4330. var proto$1 = Locale.prototype;
  4331. proto$1.calendar = calendar;
  4332. proto$1.longDateFormat = longDateFormat;
  4333. proto$1.invalidDate = invalidDate;
  4334. proto$1.ordinal = ordinal;
  4335. proto$1.preparse = preParsePostFormat;
  4336. proto$1.postformat = preParsePostFormat;
  4337. proto$1.relativeTime = relativeTime;
  4338. proto$1.pastFuture = pastFuture;
  4339. proto$1.set = set;
  4340. proto$1.eras = localeEras;
  4341. proto$1.erasParse = localeErasParse;
  4342. proto$1.erasConvertYear = localeErasConvertYear;
  4343. proto$1.erasAbbrRegex = erasAbbrRegex;
  4344. proto$1.erasNameRegex = erasNameRegex;
  4345. proto$1.erasNarrowRegex = erasNarrowRegex;
  4346. proto$1.months = localeMonths;
  4347. proto$1.monthsShort = localeMonthsShort;
  4348. proto$1.monthsParse = localeMonthsParse;
  4349. proto$1.monthsRegex = monthsRegex;
  4350. proto$1.monthsShortRegex = monthsShortRegex;
  4351. proto$1.week = localeWeek;
  4352. proto$1.firstDayOfYear = localeFirstDayOfYear;
  4353. proto$1.firstDayOfWeek = localeFirstDayOfWeek;
  4354. proto$1.weekdays = localeWeekdays;
  4355. proto$1.weekdaysMin = localeWeekdaysMin;
  4356. proto$1.weekdaysShort = localeWeekdaysShort;
  4357. proto$1.weekdaysParse = localeWeekdaysParse;
  4358. proto$1.weekdaysRegex = weekdaysRegex;
  4359. proto$1.weekdaysShortRegex = weekdaysShortRegex;
  4360. proto$1.weekdaysMinRegex = weekdaysMinRegex;
  4361. proto$1.isPM = localeIsPM;
  4362. proto$1.meridiem = localeMeridiem;
  4363. function get$1(format, index, field, setter) {
  4364. var locale = getLocale(),
  4365. utc = createUTC().set(setter, index);
  4366. return locale[field](utc, format);
  4367. }
  4368. function listMonthsImpl(format, index, field) {
  4369. if (isNumber(format)) {
  4370. index = format;
  4371. format = undefined;
  4372. }
  4373. format = format || '';
  4374. if (index != null) {
  4375. return get$1(format, index, field, 'month');
  4376. }
  4377. var i,
  4378. out = [];
  4379. for (i = 0; i < 12; i++) {
  4380. out[i] = get$1(format, i, field, 'month');
  4381. }
  4382. return out;
  4383. }
  4384. // ()
  4385. // (5)
  4386. // (fmt, 5)
  4387. // (fmt)
  4388. // (true)
  4389. // (true, 5)
  4390. // (true, fmt, 5)
  4391. // (true, fmt)
  4392. function listWeekdaysImpl(localeSorted, format, index, field) {
  4393. if (typeof localeSorted === 'boolean') {
  4394. if (isNumber(format)) {
  4395. index = format;
  4396. format = undefined;
  4397. }
  4398. format = format || '';
  4399. } else {
  4400. format = localeSorted;
  4401. index = format;
  4402. localeSorted = false;
  4403. if (isNumber(format)) {
  4404. index = format;
  4405. format = undefined;
  4406. }
  4407. format = format || '';
  4408. }
  4409. var locale = getLocale(),
  4410. shift = localeSorted ? locale._week.dow : 0,
  4411. i,
  4412. out = [];
  4413. if (index != null) {
  4414. return get$1(format, (index + shift) % 7, field, 'day');
  4415. }
  4416. for (i = 0; i < 7; i++) {
  4417. out[i] = get$1(format, (i + shift) % 7, field, 'day');
  4418. }
  4419. return out;
  4420. }
  4421. function listMonths(format, index) {
  4422. return listMonthsImpl(format, index, 'months');
  4423. }
  4424. function listMonthsShort(format, index) {
  4425. return listMonthsImpl(format, index, 'monthsShort');
  4426. }
  4427. function listWeekdays(localeSorted, format, index) {
  4428. return listWeekdaysImpl(localeSorted, format, index, 'weekdays');
  4429. }
  4430. function listWeekdaysShort(localeSorted, format, index) {
  4431. return listWeekdaysImpl(localeSorted, format, index, 'weekdaysShort');
  4432. }
  4433. function listWeekdaysMin(localeSorted, format, index) {
  4434. return listWeekdaysImpl(localeSorted, format, index, 'weekdaysMin');
  4435. }
  4436. getSetGlobalLocale('en', {
  4437. eras: [
  4438. {
  4439. since: '0001-01-01',
  4440. until: +Infinity,
  4441. offset: 1,
  4442. name: 'Anno Domini',
  4443. narrow: 'AD',
  4444. abbr: 'AD',
  4445. },
  4446. {
  4447. since: '0000-12-31',
  4448. until: -Infinity,
  4449. offset: 1,
  4450. name: 'Before Christ',
  4451. narrow: 'BC',
  4452. abbr: 'BC',
  4453. },
  4454. ],
  4455. dayOfMonthOrdinalParse: /\d{1,2}(th|st|nd|rd)/,
  4456. ordinal: function (number) {
  4457. var b = number % 10,
  4458. output =
  4459. toInt((number % 100) / 10) === 1
  4460. ? 'th'
  4461. : b === 1
  4462. ? 'st'
  4463. : b === 2
  4464. ? 'nd'
  4465. : b === 3
  4466. ? 'rd'
  4467. : 'th';
  4468. return number + output;
  4469. },
  4470. });
  4471. // Side effect imports
  4472. hooks.lang = deprecate(
  4473. 'moment.lang is deprecated. Use moment.locale instead.',
  4474. getSetGlobalLocale
  4475. );
  4476. hooks.langData = deprecate(
  4477. 'moment.langData is deprecated. Use moment.localeData instead.',
  4478. getLocale
  4479. );
  4480. var mathAbs = Math.abs;
  4481. function abs() {
  4482. var data = this._data;
  4483. this._milliseconds = mathAbs(this._milliseconds);
  4484. this._days = mathAbs(this._days);
  4485. this._months = mathAbs(this._months);
  4486. data.milliseconds = mathAbs(data.milliseconds);
  4487. data.seconds = mathAbs(data.seconds);
  4488. data.minutes = mathAbs(data.minutes);
  4489. data.hours = mathAbs(data.hours);
  4490. data.months = mathAbs(data.months);
  4491. data.years = mathAbs(data.years);
  4492. return this;
  4493. }
  4494. function addSubtract$1(duration, input, value, direction) {
  4495. var other = createDuration(input, value);
  4496. duration._milliseconds += direction * other._milliseconds;
  4497. duration._days += direction * other._days;
  4498. duration._months += direction * other._months;
  4499. return duration._bubble();
  4500. }
  4501. // supports only 2.0-style add(1, 's') or add(duration)
  4502. function add$1(input, value) {
  4503. return addSubtract$1(this, input, value, 1);
  4504. }
  4505. // supports only 2.0-style subtract(1, 's') or subtract(duration)
  4506. function subtract$1(input, value) {
  4507. return addSubtract$1(this, input, value, -1);
  4508. }
  4509. function absCeil(number) {
  4510. if (number < 0) {
  4511. return Math.floor(number);
  4512. } else {
  4513. return Math.ceil(number);
  4514. }
  4515. }
  4516. function bubble() {
  4517. var milliseconds = this._milliseconds,
  4518. days = this._days,
  4519. months = this._months,
  4520. data = this._data,
  4521. seconds,
  4522. minutes,
  4523. hours,
  4524. years,
  4525. monthsFromDays;
  4526. // if we have a mix of positive and negative values, bubble down first
  4527. // check: https://github.com/moment/moment/issues/2166
  4528. if (
  4529. !(
  4530. (milliseconds >= 0 && days >= 0 && months >= 0) ||
  4531. (milliseconds <= 0 && days <= 0 && months <= 0)
  4532. )
  4533. ) {
  4534. milliseconds += absCeil(monthsToDays(months) + days) * 864e5;
  4535. days = 0;
  4536. months = 0;
  4537. }
  4538. // The following code bubbles up values, see the tests for
  4539. // examples of what that means.
  4540. data.milliseconds = milliseconds % 1000;
  4541. seconds = absFloor(milliseconds / 1000);
  4542. data.seconds = seconds % 60;
  4543. minutes = absFloor(seconds / 60);
  4544. data.minutes = minutes % 60;
  4545. hours = absFloor(minutes / 60);
  4546. data.hours = hours % 24;
  4547. days += absFloor(hours / 24);
  4548. // convert days to months
  4549. monthsFromDays = absFloor(daysToMonths(days));
  4550. months += monthsFromDays;
  4551. days -= absCeil(monthsToDays(monthsFromDays));
  4552. // 12 months -> 1 year
  4553. years = absFloor(months / 12);
  4554. months %= 12;
  4555. data.days = days;
  4556. data.months = months;
  4557. data.years = years;
  4558. return this;
  4559. }
  4560. function daysToMonths(days) {
  4561. // 400 years have 146097 days (taking into account leap year rules)
  4562. // 400 years have 12 months === 4800
  4563. return (days * 4800) / 146097;
  4564. }
  4565. function monthsToDays(months) {
  4566. // the reverse of daysToMonths
  4567. return (months * 146097) / 4800;
  4568. }
  4569. function as(units) {
  4570. if (!this.isValid()) {
  4571. return NaN;
  4572. }
  4573. var days,
  4574. months,
  4575. milliseconds = this._milliseconds;
  4576. units = normalizeUnits(units);
  4577. if (units === 'month' || units === 'quarter' || units === 'year') {
  4578. days = this._days + milliseconds / 864e5;
  4579. months = this._months + daysToMonths(days);
  4580. switch (units) {
  4581. case 'month':
  4582. return months;
  4583. case 'quarter':
  4584. return months / 3;
  4585. case 'year':
  4586. return months / 12;
  4587. }
  4588. } else {
  4589. // handle milliseconds separately because of floating point math errors (issue #1867)
  4590. days = this._days + Math.round(monthsToDays(this._months));
  4591. switch (units) {
  4592. case 'week':
  4593. return days / 7 + milliseconds / 6048e5;
  4594. case 'day':
  4595. return days + milliseconds / 864e5;
  4596. case 'hour':
  4597. return days * 24 + milliseconds / 36e5;
  4598. case 'minute':
  4599. return days * 1440 + milliseconds / 6e4;
  4600. case 'second':
  4601. return days * 86400 + milliseconds / 1000;
  4602. // Math.floor prevents floating point math errors here
  4603. case 'millisecond':
  4604. return Math.floor(days * 864e5) + milliseconds;
  4605. default:
  4606. throw new Error('Unknown unit ' + units);
  4607. }
  4608. }
  4609. }
  4610. // TODO: Use this.as('ms')?
  4611. function valueOf$1() {
  4612. if (!this.isValid()) {
  4613. return NaN;
  4614. }
  4615. return (
  4616. this._milliseconds +
  4617. this._days * 864e5 +
  4618. (this._months % 12) * 2592e6 +
  4619. toInt(this._months / 12) * 31536e6
  4620. );
  4621. }
  4622. function makeAs(alias) {
  4623. return function () {
  4624. return this.as(alias);
  4625. };
  4626. }
  4627. var asMilliseconds = makeAs('ms'),
  4628. asSeconds = makeAs('s'),
  4629. asMinutes = makeAs('m'),
  4630. asHours = makeAs('h'),
  4631. asDays = makeAs('d'),
  4632. asWeeks = makeAs('w'),
  4633. asMonths = makeAs('M'),
  4634. asQuarters = makeAs('Q'),
  4635. asYears = makeAs('y');
  4636. function clone$1() {
  4637. return createDuration(this);
  4638. }
  4639. function get$2(units) {
  4640. units = normalizeUnits(units);
  4641. return this.isValid() ? this[units + 's']() : NaN;
  4642. }
  4643. function makeGetter(name) {
  4644. return function () {
  4645. return this.isValid() ? this._data[name] : NaN;
  4646. };
  4647. }
  4648. var milliseconds = makeGetter('milliseconds'),
  4649. seconds = makeGetter('seconds'),
  4650. minutes = makeGetter('minutes'),
  4651. hours = makeGetter('hours'),
  4652. days = makeGetter('days'),
  4653. months = makeGetter('months'),
  4654. years = makeGetter('years');
  4655. function weeks() {
  4656. return absFloor(this.days() / 7);
  4657. }
  4658. var round = Math.round,
  4659. thresholds = {
  4660. ss: 44, // a few seconds to seconds
  4661. s: 45, // seconds to minute
  4662. m: 45, // minutes to hour
  4663. h: 22, // hours to day
  4664. d: 26, // days to month/week
  4665. w: null, // weeks to month
  4666. M: 11, // months to year
  4667. };
  4668. // helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize
  4669. function substituteTimeAgo(string, number, withoutSuffix, isFuture, locale) {
  4670. return locale.relativeTime(number || 1, !!withoutSuffix, string, isFuture);
  4671. }
  4672. function relativeTime$1(posNegDuration, withoutSuffix, thresholds, locale) {
  4673. var duration = createDuration(posNegDuration).abs(),
  4674. seconds = round(duration.as('s')),
  4675. minutes = round(duration.as('m')),
  4676. hours = round(duration.as('h')),
  4677. days = round(duration.as('d')),
  4678. months = round(duration.as('M')),
  4679. weeks = round(duration.as('w')),
  4680. years = round(duration.as('y')),
  4681. a =
  4682. (seconds <= thresholds.ss && ['s', seconds]) ||
  4683. (seconds < thresholds.s && ['ss', seconds]) ||
  4684. (minutes <= 1 && ['m']) ||
  4685. (minutes < thresholds.m && ['mm', minutes]) ||
  4686. (hours <= 1 && ['h']) ||
  4687. (hours < thresholds.h && ['hh', hours]) ||
  4688. (days <= 1 && ['d']) ||
  4689. (days < thresholds.d && ['dd', days]);
  4690. if (thresholds.w != null) {
  4691. a =
  4692. a ||
  4693. (weeks <= 1 && ['w']) ||
  4694. (weeks < thresholds.w && ['ww', weeks]);
  4695. }
  4696. a = a ||
  4697. (months <= 1 && ['M']) ||
  4698. (months < thresholds.M && ['MM', months]) ||
  4699. (years <= 1 && ['y']) || ['yy', years];
  4700. a[2] = withoutSuffix;
  4701. a[3] = +posNegDuration > 0;
  4702. a[4] = locale;
  4703. return substituteTimeAgo.apply(null, a);
  4704. }
  4705. // This function allows you to set the rounding function for relative time strings
  4706. function getSetRelativeTimeRounding(roundingFunction) {
  4707. if (roundingFunction === undefined) {
  4708. return round;
  4709. }
  4710. if (typeof roundingFunction === 'function') {
  4711. round = roundingFunction;
  4712. return true;
  4713. }
  4714. return false;
  4715. }
  4716. // This function allows you to set a threshold for relative time strings
  4717. function getSetRelativeTimeThreshold(threshold, limit) {
  4718. if (thresholds[threshold] === undefined) {
  4719. return false;
  4720. }
  4721. if (limit === undefined) {
  4722. return thresholds[threshold];
  4723. }
  4724. thresholds[threshold] = limit;
  4725. if (threshold === 's') {
  4726. thresholds.ss = limit - 1;
  4727. }
  4728. return true;
  4729. }
  4730. function humanize(argWithSuffix, argThresholds) {
  4731. if (!this.isValid()) {
  4732. return this.localeData().invalidDate();
  4733. }
  4734. var withSuffix = false,
  4735. th = thresholds,
  4736. locale,
  4737. output;
  4738. if (typeof argWithSuffix === 'object') {
  4739. argThresholds = argWithSuffix;
  4740. argWithSuffix = false;
  4741. }
  4742. if (typeof argWithSuffix === 'boolean') {
  4743. withSuffix = argWithSuffix;
  4744. }
  4745. if (typeof argThresholds === 'object') {
  4746. th = Object.assign({}, thresholds, argThresholds);
  4747. if (argThresholds.s != null && argThresholds.ss == null) {
  4748. th.ss = argThresholds.s - 1;
  4749. }
  4750. }
  4751. locale = this.localeData();
  4752. output = relativeTime$1(this, !withSuffix, th, locale);
  4753. if (withSuffix) {
  4754. output = locale.pastFuture(+this, output);
  4755. }
  4756. return locale.postformat(output);
  4757. }
  4758. var abs$1 = Math.abs;
  4759. function sign(x) {
  4760. return (x > 0) - (x < 0) || +x;
  4761. }
  4762. function toISOString$1() {
  4763. // for ISO strings we do not use the normal bubbling rules:
  4764. // * milliseconds bubble up until they become hours
  4765. // * days do not bubble at all
  4766. // * months bubble up until they become years
  4767. // This is because there is no context-free conversion between hours and days
  4768. // (think of clock changes)
  4769. // and also not between days and months (28-31 days per month)
  4770. if (!this.isValid()) {
  4771. return this.localeData().invalidDate();
  4772. }
  4773. var seconds = abs$1(this._milliseconds) / 1000,
  4774. days = abs$1(this._days),
  4775. months = abs$1(this._months),
  4776. minutes,
  4777. hours,
  4778. years,
  4779. s,
  4780. total = this.asSeconds(),
  4781. totalSign,
  4782. ymSign,
  4783. daysSign,
  4784. hmsSign;
  4785. if (!total) {
  4786. // this is the same as C#'s (Noda) and python (isodate)...
  4787. // but not other JS (goog.date)
  4788. return 'P0D';
  4789. }
  4790. // 3600 seconds -> 60 minutes -> 1 hour
  4791. minutes = absFloor(seconds / 60);
  4792. hours = absFloor(minutes / 60);
  4793. seconds %= 60;
  4794. minutes %= 60;
  4795. // 12 months -> 1 year
  4796. years = absFloor(months / 12);
  4797. months %= 12;
  4798. // inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js
  4799. s = seconds ? seconds.toFixed(3).replace(/\.?0+$/, '') : '';
  4800. totalSign = total < 0 ? '-' : '';
  4801. ymSign = sign(this._months) !== sign(total) ? '-' : '';
  4802. daysSign = sign(this._days) !== sign(total) ? '-' : '';
  4803. hmsSign = sign(this._milliseconds) !== sign(total) ? '-' : '';
  4804. return (
  4805. totalSign +
  4806. 'P' +
  4807. (years ? ymSign + years + 'Y' : '') +
  4808. (months ? ymSign + months + 'M' : '') +
  4809. (days ? daysSign + days + 'D' : '') +
  4810. (hours || minutes || seconds ? 'T' : '') +
  4811. (hours ? hmsSign + hours + 'H' : '') +
  4812. (minutes ? hmsSign + minutes + 'M' : '') +
  4813. (seconds ? hmsSign + s + 'S' : '')
  4814. );
  4815. }
  4816. var proto$2 = Duration.prototype;
  4817. proto$2.isValid = isValid$1;
  4818. proto$2.abs = abs;
  4819. proto$2.add = add$1;
  4820. proto$2.subtract = subtract$1;
  4821. proto$2.as = as;
  4822. proto$2.asMilliseconds = asMilliseconds;
  4823. proto$2.asSeconds = asSeconds;
  4824. proto$2.asMinutes = asMinutes;
  4825. proto$2.asHours = asHours;
  4826. proto$2.asDays = asDays;
  4827. proto$2.asWeeks = asWeeks;
  4828. proto$2.asMonths = asMonths;
  4829. proto$2.asQuarters = asQuarters;
  4830. proto$2.asYears = asYears;
  4831. proto$2.valueOf = valueOf$1;
  4832. proto$2._bubble = bubble;
  4833. proto$2.clone = clone$1;
  4834. proto$2.get = get$2;
  4835. proto$2.milliseconds = milliseconds;
  4836. proto$2.seconds = seconds;
  4837. proto$2.minutes = minutes;
  4838. proto$2.hours = hours;
  4839. proto$2.days = days;
  4840. proto$2.weeks = weeks;
  4841. proto$2.months = months;
  4842. proto$2.years = years;
  4843. proto$2.humanize = humanize;
  4844. proto$2.toISOString = toISOString$1;
  4845. proto$2.toString = toISOString$1;
  4846. proto$2.toJSON = toISOString$1;
  4847. proto$2.locale = locale;
  4848. proto$2.localeData = localeData;
  4849. proto$2.toIsoString = deprecate(
  4850. 'toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)',
  4851. toISOString$1
  4852. );
  4853. proto$2.lang = lang;
  4854. // FORMATTING
  4855. addFormatToken('X', 0, 0, 'unix');
  4856. addFormatToken('x', 0, 0, 'valueOf');
  4857. // PARSING
  4858. addRegexToken('x', matchSigned);
  4859. addRegexToken('X', matchTimestamp);
  4860. addParseToken('X', function (input, array, config) {
  4861. config._d = new Date(parseFloat(input) * 1000);
  4862. });
  4863. addParseToken('x', function (input, array, config) {
  4864. config._d = new Date(toInt(input));
  4865. });
  4866. //! moment.js
  4867. hooks.version = '2.29.0';
  4868. setHookCallback(createLocal);
  4869. hooks.fn = proto;
  4870. hooks.min = min;
  4871. hooks.max = max;
  4872. hooks.now = now;
  4873. hooks.utc = createUTC;
  4874. hooks.unix = createUnix;
  4875. hooks.months = listMonths;
  4876. hooks.isDate = isDate;
  4877. hooks.locale = getSetGlobalLocale;
  4878. hooks.invalid = createInvalid;
  4879. hooks.duration = createDuration;
  4880. hooks.isMoment = isMoment;
  4881. hooks.weekdays = listWeekdays;
  4882. hooks.parseZone = createInZone;
  4883. hooks.localeData = getLocale;
  4884. hooks.isDuration = isDuration;
  4885. hooks.monthsShort = listMonthsShort;
  4886. hooks.weekdaysMin = listWeekdaysMin;
  4887. hooks.defineLocale = defineLocale;
  4888. hooks.updateLocale = updateLocale;
  4889. hooks.locales = listLocales;
  4890. hooks.weekdaysShort = listWeekdaysShort;
  4891. hooks.normalizeUnits = normalizeUnits;
  4892. hooks.relativeTimeRounding = getSetRelativeTimeRounding;
  4893. hooks.relativeTimeThreshold = getSetRelativeTimeThreshold;
  4894. hooks.calendarFormat = getCalendarFormat;
  4895. hooks.prototype = proto;
  4896. // currently HTML5 input type only supports 24-hour formats
  4897. hooks.HTML5_FMT = {
  4898. DATETIME_LOCAL: 'YYYY-MM-DDTHH:mm', // <input type="datetime-local" />
  4899. DATETIME_LOCAL_SECONDS: 'YYYY-MM-DDTHH:mm:ss', // <input type="datetime-local" step="1" />
  4900. DATETIME_LOCAL_MS: 'YYYY-MM-DDTHH:mm:ss.SSS', // <input type="datetime-local" step="0.001" />
  4901. DATE: 'YYYY-MM-DD', // <input type="date" />
  4902. TIME: 'HH:mm', // <input type="time" />
  4903. TIME_SECONDS: 'HH:mm:ss', // <input type="time" step="1" />
  4904. TIME_MS: 'HH:mm:ss.SSS', // <input type="time" step="0.001" />
  4905. WEEK: 'GGGG-[W]WW', // <input type="week" />
  4906. MONTH: 'YYYY-MM', // <input type="month" />
  4907. };
  4908. export default hooks;