moment.js 171 KB

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