Node-Red configuration
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

moment.js 151KB

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