moment.js 170KB

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