Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

moment.js 150KB

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