moment.js 153 KB

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