moment.js 170 KB

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