modernizer.js 136 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552
  1. /*!
  2. * Modernizr v2.7.2
  3. * www.modernizr.com
  4. *
  5. * Copyright (c) Faruk Ates, Paul Irish, Alex Sexton
  6. * Available under the BSD and MIT licenses: www.modernizr.com/license/
  7. */
  8. ;window.Modernizr=function(a,b,c){function u(a){j.cssText=a}function v(a,b){return u(prefixes.join(a+";")+(b||""))}function w(a,b){return typeof a===b}function x(a,b){return!!~(""+a).indexOf(b)}function y(a,b,d){for(var e in a){var f=b[a[e]];if(f!==c)return d===!1?a[e]:w(f,"function")?f.bind(d||b):f}return!1}var d="2.8.3",e={},f=!0,g=b.documentElement,h="modernizr",i=b.createElement(h),j=i.style,k,l={}.toString,m={},n={},o={},p=[],q=p.slice,r,s={}.hasOwnProperty,t;!w(s,"undefined")&&!w(s.call,"undefined")?t=function(a,b){return s.call(a,b)}:t=function(a,b){return b in a&&w(a.constructor.prototype[b],"undefined")},Function.prototype.bind||(Function.prototype.bind=function(b){var c=this;if(typeof c!="function")throw new TypeError;var d=q.call(arguments,1),e=function(){if(this instanceof e){var a=function(){};a.prototype=c.prototype;var f=new a,g=c.apply(f,d.concat(q.call(arguments)));return Object(g)===g?g:f}return c.apply(b,d.concat(q.call(arguments)))};return e});for(var z in m)t(m,z)&&(r=z.toLowerCase(),e[r]=m[z](),p.push((e[r]?"":"no-")+r));return e.addTest=function(a,b){if(typeof a=="object")for(var d in a)t(a,d)&&e.addTest(d,a[d]);else{a=a.toLowerCase();if(e[a]!==c)return e;b=typeof b=="function"?b():b,typeof f!="undefined"&&f&&(g.className+=" "+(b?"":"no-")+a),e[a]=b}return e},u(""),i=k=null,function(a,b){function l(a,b){var c=a.createElement("p"),d=a.getElementsByTagName("head")[0]||a.documentElement;return c.innerHTML="x<style>"+b+"</style>",d.insertBefore(c.lastChild,d.firstChild)}function m(){var a=s.elements;return typeof a=="string"?a.split(" "):a}function n(a){var b=j[a[h]];return b||(b={},i++,a[h]=i,j[i]=b),b}function o(a,c,d){c||(c=b);if(k)return c.createElement(a);d||(d=n(c));var g;return d.cache[a]?g=d.cache[a].cloneNode():f.test(a)?g=(d.cache[a]=d.createElem(a)).cloneNode():g=d.createElem(a),g.canHaveChildren&&!e.test(a)&&!g.tagUrn?d.frag.appendChild(g):g}function p(a,c){a||(a=b);if(k)return a.createDocumentFragment();c=c||n(a);var d=c.frag.cloneNode(),e=0,f=m(),g=f.length;for(;e<g;e++)d.createElement(f[e]);return d}function q(a,b){b.cache||(b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag()),a.createElement=function(c){return s.shivMethods?o(c,a,b):b.createElem(c)},a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+m().join().replace(/[\w\-]+/g,function(a){return b.createElem(a),b.frag.createElement(a),'c("'+a+'")'})+");return n}")(s,b.frag)}function r(a){a||(a=b);var c=n(a);return s.shivCSS&&!g&&!c.hasCSS&&(c.hasCSS=!!l(a,"article,aside,dialog,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}mark{background:#FF0;color:#000}template{display:none}")),k||q(a,c),a}var c="3.7.0",d=a.html5||{},e=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,f=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,g,h="_html5shiv",i=0,j={},k;(function(){try{var a=b.createElement("a");a.innerHTML="<xyz></xyz>",g="hidden"in a,k=a.childNodes.length==1||function(){b.createElement("a");var a=b.createDocumentFragment();return typeof a.cloneNode=="undefined"||typeof a.createDocumentFragment=="undefined"||typeof a.createElement=="undefined"}()}catch(c){g=!0,k=!0}})();var s={elements:d.elements||"abbr article aside audio bdi canvas data datalist details dialog figcaption figure footer header hgroup main mark meter nav output progress section summary template time video",version:c,shivCSS:d.shivCSS!==!1,supportsUnknownElements:k,shivMethods:d.shivMethods!==!1,type:"default",shivDocument:r,createElement:o,createDocumentFragment:p};a.html5=s,r(b)}(this,b),e._version=d,g.className=g.className.replace(/(^|\s)no-js(\s|$)/,"$1$2")+(f?" js "+p.join(" "):""),e}(this,this.document),function(a,b,c){function d(a){return"[object Function]"==o.call(a)}function e(a){return"string"==typeof a}function f(){}function g(a){return!a||"loaded"==a||"complete"==a||"uninitialized"==a}function h(){var a=p.shift();q=1,a?a.t?m(function(){("c"==a.t?B.injectCss:B.injectJs)(a.s,0,a.a,a.x,a.e,1)},0):(a(),h()):q=0}function i(a,c,d,e,f,i,j){function k(b){if(!o&&g(l.readyState)&&(u.r=o=1,!q&&h(),l.onload=l.onreadystatechange=null,b)){"img"!=a&&m(function(){t.removeChild(l)},50);for(var d in y[c])y[c].hasOwnProperty(d)&&y[c][d].onload()}}var j=j||B.errorTimeout,l=b.createElement(a),o=0,r=0,u={t:d,s:c,e:f,a:i,x:j};1===y[c]&&(r=1,y[c]=[]),"object"==a?l.data=c:(l.src=c,l.type=a),l.width=l.height="0",l.onerror=l.onload=l.onreadystatechange=function(){k.call(this,r)},p.splice(e,0,u),"img"!=a&&(r||2===y[c]?(t.insertBefore(l,s?null:n),m(k,j)):y[c].push(l))}function j(a,b,c,d,f){return q=0,b=b||"j",e(a)?i("c"==b?v:u,a,b,this.i++,c,d,f):(p.splice(this.i++,0,a),1==p.length&&h()),this}function k(){var a=B;return a.loader={load:j,i:0},a}var l=b.documentElement,m=a.setTimeout,n=b.getElementsByTagName("script")[0],o={}.toString,p=[],q=0,r="MozAppearance"in l.style,s=r&&!!b.createRange().compareNode,t=s?l:n.parentNode,l=a.opera&&"[object Opera]"==o.call(a.opera),l=!!b.attachEvent&&!l,u=r?"object":l?"script":"img",v=l?"script":u,w=Array.isArray||function(a){return"[object Array]"==o.call(a)},x=[],y={},z={timeout:function(a,b){return b.length&&(a.timeout=b[0]),a}},A,B;B=function(a){function b(a){var a=a.split("!"),b=x.length,c=a.pop(),d=a.length,c={url:c,origUrl:c,prefixes:a},e,f,g;for(f=0;f<d;f++)g=a[f].split("="),(e=z[g.shift()])&&(c=e(c,g));for(f=0;f<b;f++)c=x[f](c);return c}function g(a,e,f,g,h){var i=b(a),j=i.autoCallback;i.url.split(".").pop().split("?").shift(),i.bypass||(e&&(e=d(e)?e:e[a]||e[g]||e[a.split("/").pop().split("?")[0]]),i.instead?i.instead(a,e,f,g,h):(y[i.url]?i.noexec=!0:y[i.url]=1,f.load(i.url,i.forceCSS||!i.forceJS&&"css"==i.url.split(".").pop().split("?").shift()?"c":c,i.noexec,i.attrs,i.timeout),(d(e)||d(j))&&f.load(function(){k(),e&&e(i.origUrl,h,g),j&&j(i.origUrl,h,g),y[i.url]=2})))}function h(a,b){function c(a,c){if(a){if(e(a))c||(j=function(){var a=[].slice.call(arguments);k.apply(this,a),l()}),g(a,j,b,0,h);else if(Object(a)===a)for(n in m=function(){var b=0,c;for(c in a)a.hasOwnProperty(c)&&b++;return b}(),a)a.hasOwnProperty(n)&&(!c&&!--m&&(d(j)?j=function(){var a=[].slice.call(arguments);k.apply(this,a),l()}:j[n]=function(a){return function(){var b=[].slice.call(arguments);a&&a.apply(this,b),l()}}(k[n])),g(a[n],j,b,n,h))}else!c&&l()}var h=!!a.test,i=a.load||a.both,j=a.callback||f,k=j,l=a.complete||f,m,n;c(h?a.yep:a.nope,!!i),i&&c(i)}var i,j,l=this.yepnope.loader;if(e(a))g(a,0,l,0);else if(w(a))for(i=0;i<a.length;i++)j=a[i],e(j)?g(j,0,l,0):w(j)?B(j):Object(j)===j&&h(j,l);else Object(a)===a&&h(a,l)},B.addPrefix=function(a,b){z[a]=b},B.addFilter=function(a){x.push(a)},B.errorTimeout=1e4,null==b.readyState&&b.addEventListener&&(b.readyState="loading",b.addEventListener("DOMContentLoaded",A=function(){b.removeEventListener("DOMContentLoaded",A,0),b.readyState="complete"},0)),a.yepnope=k(),a.yepnope.executeStack=h,a.yepnope.injectJs=function(a,c,d,e,i,j){var k=b.createElement("script"),l,o,e=e||B.errorTimeout;k.src=a;for(o in d)k.setAttribute(o,d[o]);c=j?h:c||f,k.onreadystatechange=k.onload=function(){!l&&g(k.readyState)&&(l=1,c(),k.onload=k.onreadystatechange=null)},m(function(){l||(l=1,c(1))},e),i?k.onload():n.parentNode.insertBefore(k,n)},a.yepnope.injectCss=function(a,c,d,e,g,i){var e=b.createElement("link"),j,c=i?h:c||f;e.href=a,e.rel="stylesheet",e.type="text/css";for(j in d)e.setAttribute(j,d[j]);g||(n.parentNode.insertBefore(e,n),m(c,0))}}(this,document),Modernizr.load=function(){yepnope.apply(window,[].slice.call(arguments,0))};
  9. //! moment.js
  10. //! version : 2.20.1
  11. //! authors : Tim Wood, Iskren Chernev, Moment.js contributors
  12. //! license : MIT
  13. //! momentjs.com
  14. ;(function (global, factory) {
  15. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  16. typeof define === 'function' && define.amd ? define(factory) :
  17. global.moment = factory()
  18. }(this, (function () { 'use strict';
  19. var hookCallback;
  20. function hooks () {
  21. return hookCallback.apply(null, arguments);
  22. }
  23. // This is done to register the method called with moment()
  24. // without creating circular dependencies.
  25. function setHookCallback (callback) {
  26. hookCallback = callback;
  27. }
  28. function isArray(input) {
  29. return input instanceof Array || Object.prototype.toString.call(input) === '[object Array]';
  30. }
  31. function isObject(input) {
  32. // IE8 will treat undefined and null as object if it wasn't for
  33. // input != null
  34. return input != null && Object.prototype.toString.call(input) === '[object Object]';
  35. }
  36. function isObjectEmpty(obj) {
  37. if (Object.getOwnPropertyNames) {
  38. return (Object.getOwnPropertyNames(obj).length === 0);
  39. } else {
  40. var k;
  41. for (k in obj) {
  42. if (obj.hasOwnProperty(k)) {
  43. return false;
  44. }
  45. }
  46. return true;
  47. }
  48. }
  49. function isUndefined(input) {
  50. return input === void 0;
  51. }
  52. function isNumber(input) {
  53. return typeof input === 'number' || Object.prototype.toString.call(input) === '[object Number]';
  54. }
  55. function isDate(input) {
  56. return input instanceof Date || Object.prototype.toString.call(input) === '[object Date]';
  57. }
  58. function map(arr, fn) {
  59. var res = [], i;
  60. for (i = 0; i < arr.length; ++i) {
  61. res.push(fn(arr[i], i));
  62. }
  63. return res;
  64. }
  65. function hasOwnProp(a, b) {
  66. return Object.prototype.hasOwnProperty.call(a, b);
  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. invalidMonth : null,
  95. invalidFormat : false,
  96. userInvalidated : false,
  97. iso : false,
  98. parsedDateParts : [],
  99. meridiem : null,
  100. rfc2822 : false,
  101. weekdayMismatch : false
  102. };
  103. }
  104. function getParsingFlags(m) {
  105. if (m._pf == null) {
  106. m._pf = defaultParsingFlags();
  107. }
  108. return m._pf;
  109. }
  110. var some;
  111. if (Array.prototype.some) {
  112. some = Array.prototype.some;
  113. } else {
  114. some = function (fun) {
  115. var t = Object(this);
  116. var len = t.length >>> 0;
  117. for (var i = 0; i < len; i++) {
  118. if (i in t && fun.call(this, t[i], i, t)) {
  119. return true;
  120. }
  121. }
  122. return false;
  123. };
  124. }
  125. function isValid(m) {
  126. if (m._isValid == null) {
  127. var flags = getParsingFlags(m);
  128. var parsedParts = some.call(flags.parsedDateParts, function (i) {
  129. return i != null;
  130. });
  131. var isNowValid = !isNaN(m._d.getTime()) &&
  132. flags.overflow < 0 &&
  133. !flags.empty &&
  134. !flags.invalidMonth &&
  135. !flags.invalidWeekday &&
  136. !flags.weekdayMismatch &&
  137. !flags.nullInput &&
  138. !flags.invalidFormat &&
  139. !flags.userInvalidated &&
  140. (!flags.meridiem || (flags.meridiem && parsedParts));
  141. if (m._strict) {
  142. isNowValid = isNowValid &&
  143. flags.charsLeftOver === 0 &&
  144. flags.unusedTokens.length === 0 &&
  145. flags.bigHour === undefined;
  146. }
  147. if (Object.isFrozen == null || !Object.isFrozen(m)) {
  148. m._isValid = isNowValid;
  149. }
  150. else {
  151. return isNowValid;
  152. }
  153. }
  154. return m._isValid;
  155. }
  156. function createInvalid (flags) {
  157. var m = createUTC(NaN);
  158. if (flags != null) {
  159. extend(getParsingFlags(m), flags);
  160. }
  161. else {
  162. getParsingFlags(m).userInvalidated = true;
  163. }
  164. return m;
  165. }
  166. // Plugins that add properties should also add the key here (null value),
  167. // so we can properly clone ourselves.
  168. var momentProperties = hooks.momentProperties = [];
  169. function copyConfig(to, from) {
  170. var i, prop, val;
  171. if (!isUndefined(from._isAMomentObject)) {
  172. to._isAMomentObject = from._isAMomentObject;
  173. }
  174. if (!isUndefined(from._i)) {
  175. to._i = from._i;
  176. }
  177. if (!isUndefined(from._f)) {
  178. to._f = from._f;
  179. }
  180. if (!isUndefined(from._l)) {
  181. to._l = from._l;
  182. }
  183. if (!isUndefined(from._strict)) {
  184. to._strict = from._strict;
  185. }
  186. if (!isUndefined(from._tzm)) {
  187. to._tzm = from._tzm;
  188. }
  189. if (!isUndefined(from._isUTC)) {
  190. to._isUTC = from._isUTC;
  191. }
  192. if (!isUndefined(from._offset)) {
  193. to._offset = from._offset;
  194. }
  195. if (!isUndefined(from._pf)) {
  196. to._pf = getParsingFlags(from);
  197. }
  198. if (!isUndefined(from._locale)) {
  199. to._locale = from._locale;
  200. }
  201. if (momentProperties.length > 0) {
  202. for (i = 0; i < momentProperties.length; i++) {
  203. prop = momentProperties[i];
  204. val = from[prop];
  205. if (!isUndefined(val)) {
  206. to[prop] = val;
  207. }
  208. }
  209. }
  210. return to;
  211. }
  212. var updateInProgress = false;
  213. // Moment prototype object
  214. function Moment(config) {
  215. copyConfig(this, config);
  216. this._d = new Date(config._d != null ? config._d.getTime() : NaN);
  217. if (!this.isValid()) {
  218. this._d = new Date(NaN);
  219. }
  220. // Prevent infinite loop in case updateOffset creates new moment
  221. // objects.
  222. if (updateInProgress === false) {
  223. updateInProgress = true;
  224. hooks.updateOffset(this);
  225. updateInProgress = false;
  226. }
  227. }
  228. function isMoment (obj) {
  229. return obj instanceof Moment || (obj != null && obj._isAMomentObject != null);
  230. }
  231. function absFloor (number) {
  232. if (number < 0) {
  233. // -0 -> 0
  234. return Math.ceil(number) || 0;
  235. } else {
  236. return Math.floor(number);
  237. }
  238. }
  239. function toInt(argumentForCoercion) {
  240. var coercedNumber = +argumentForCoercion,
  241. value = 0;
  242. if (coercedNumber !== 0 && isFinite(coercedNumber)) {
  243. value = absFloor(coercedNumber);
  244. }
  245. return value;
  246. }
  247. // compare two arrays, return the number of differences
  248. function compareArrays(array1, array2, dontConvert) {
  249. var len = Math.min(array1.length, array2.length),
  250. lengthDiff = Math.abs(array1.length - array2.length),
  251. diffs = 0,
  252. i;
  253. for (i = 0; i < len; i++) {
  254. if ((dontConvert && array1[i] !== array2[i]) ||
  255. (!dontConvert && toInt(array1[i]) !== toInt(array2[i]))) {
  256. diffs++;
  257. }
  258. }
  259. return diffs + lengthDiff;
  260. }
  261. function warn(msg) {
  262. if (hooks.suppressDeprecationWarnings === false &&
  263. (typeof console !== 'undefined') && console.warn) {
  264. console.warn('Deprecation warning: ' + msg);
  265. }
  266. }
  267. function deprecate(msg, fn) {
  268. var firstTime = true;
  269. return extend(function () {
  270. if (hooks.deprecationHandler != null) {
  271. hooks.deprecationHandler(null, msg);
  272. }
  273. if (firstTime) {
  274. var args = [];
  275. var arg;
  276. for (var i = 0; i < arguments.length; i++) {
  277. arg = '';
  278. if (typeof arguments[i] === 'object') {
  279. arg += '\n[' + i + '] ';
  280. for (var key in arguments[0]) {
  281. arg += key + ': ' + arguments[0][key] + ', ';
  282. }
  283. arg = arg.slice(0, -2); // Remove trailing comma and space
  284. } else {
  285. arg = arguments[i];
  286. }
  287. args.push(arg);
  288. }
  289. warn(msg + '\nArguments: ' + Array.prototype.slice.call(args).join('') + '\n' + (new Error()).stack);
  290. firstTime = false;
  291. }
  292. return fn.apply(this, arguments);
  293. }, fn);
  294. }
  295. var deprecations = {};
  296. function deprecateSimple(name, msg) {
  297. if (hooks.deprecationHandler != null) {
  298. hooks.deprecationHandler(name, msg);
  299. }
  300. if (!deprecations[name]) {
  301. warn(msg);
  302. deprecations[name] = true;
  303. }
  304. }
  305. hooks.suppressDeprecationWarnings = false;
  306. hooks.deprecationHandler = null;
  307. function isFunction(input) {
  308. return input instanceof Function || Object.prototype.toString.call(input) === '[object Function]';
  309. }
  310. function set (config) {
  311. var prop, i;
  312. for (i in config) {
  313. prop = config[i];
  314. if (isFunction(prop)) {
  315. this[i] = prop;
  316. } else {
  317. this['_' + i] = prop;
  318. }
  319. }
  320. this._config = config;
  321. // Lenient ordinal parsing accepts just a number in addition to
  322. // number + (possibly) stuff coming from _dayOfMonthOrdinalParse.
  323. // TODO: Remove "ordinalParse" fallback in next major release.
  324. this._dayOfMonthOrdinalParseLenient = new RegExp(
  325. (this._dayOfMonthOrdinalParse.source || this._ordinalParse.source) +
  326. '|' + (/\d{1,2}/).source);
  327. }
  328. function mergeConfigs(parentConfig, childConfig) {
  329. var res = extend({}, parentConfig), prop;
  330. for (prop in childConfig) {
  331. if (hasOwnProp(childConfig, prop)) {
  332. if (isObject(parentConfig[prop]) && isObject(childConfig[prop])) {
  333. res[prop] = {};
  334. extend(res[prop], parentConfig[prop]);
  335. extend(res[prop], childConfig[prop]);
  336. } else if (childConfig[prop] != null) {
  337. res[prop] = childConfig[prop];
  338. } else {
  339. delete res[prop];
  340. }
  341. }
  342. }
  343. for (prop in parentConfig) {
  344. if (hasOwnProp(parentConfig, prop) &&
  345. !hasOwnProp(childConfig, prop) &&
  346. isObject(parentConfig[prop])) {
  347. // make sure changes to properties don't modify parent config
  348. res[prop] = extend({}, res[prop]);
  349. }
  350. }
  351. return res;
  352. }
  353. function Locale(config) {
  354. if (config != null) {
  355. this.set(config);
  356. }
  357. }
  358. var keys;
  359. if (Object.keys) {
  360. keys = Object.keys;
  361. } else {
  362. keys = function (obj) {
  363. var i, 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. var defaultLongDateFormat = {
  385. LTS : 'h:mm:ss A',
  386. LT : 'h:mm A',
  387. L : 'MM/DD/YYYY',
  388. LL : 'MMMM D, YYYY',
  389. LLL : 'MMMM D, YYYY h:mm A',
  390. LLLL : 'dddd, MMMM D, YYYY h:mm A'
  391. };
  392. function longDateFormat (key) {
  393. var format = this._longDateFormat[key],
  394. formatUpper = this._longDateFormat[key.toUpperCase()];
  395. if (format || !formatUpper) {
  396. return format;
  397. }
  398. this._longDateFormat[key] = formatUpper.replace(/MMMM|MM|DD|dddd/g, function (val) {
  399. return val.slice(1);
  400. });
  401. return this._longDateFormat[key];
  402. }
  403. var defaultInvalidDate = 'Invalid date';
  404. function invalidDate () {
  405. return this._invalidDate;
  406. }
  407. var defaultOrdinal = '%d';
  408. var defaultDayOfMonthOrdinalParse = /\d{1,2}/;
  409. function ordinal (number) {
  410. return this._ordinal.replace('%d', number);
  411. }
  412. var defaultRelativeTime = {
  413. future : 'in %s',
  414. past : '%s ago',
  415. s : 'a few seconds',
  416. ss : '%d seconds',
  417. m : 'a minute',
  418. mm : '%d minutes',
  419. h : 'an hour',
  420. hh : '%d hours',
  421. d : 'a day',
  422. dd : '%d days',
  423. M : 'a month',
  424. MM : '%d months',
  425. y : 'a year',
  426. yy : '%d years'
  427. };
  428. function relativeTime (number, withoutSuffix, string, isFuture) {
  429. var output = this._relativeTime[string];
  430. return (isFunction(output)) ?
  431. output(number, withoutSuffix, string, isFuture) :
  432. output.replace(/%d/i, number);
  433. }
  434. function pastFuture (diff, output) {
  435. var format = this._relativeTime[diff > 0 ? 'future' : 'past'];
  436. return isFunction(format) ? format(output) : format.replace(/%s/i, output);
  437. }
  438. var aliases = {};
  439. function addUnitAlias (unit, shorthand) {
  440. var lowerCase = unit.toLowerCase();
  441. aliases[lowerCase] = aliases[lowerCase + 's'] = aliases[shorthand] = unit;
  442. }
  443. function normalizeUnits(units) {
  444. return typeof units === 'string' ? aliases[units] || aliases[units.toLowerCase()] : undefined;
  445. }
  446. function normalizeObjectUnits(inputObject) {
  447. var normalizedInput = {},
  448. normalizedProp,
  449. prop;
  450. for (prop in inputObject) {
  451. if (hasOwnProp(inputObject, prop)) {
  452. normalizedProp = normalizeUnits(prop);
  453. if (normalizedProp) {
  454. normalizedInput[normalizedProp] = inputObject[prop];
  455. }
  456. }
  457. }
  458. return normalizedInput;
  459. }
  460. var priorities = {};
  461. function addUnitPriority(unit, priority) {
  462. priorities[unit] = priority;
  463. }
  464. function getPrioritizedUnits(unitsObj) {
  465. var units = [];
  466. for (var u in unitsObj) {
  467. units.push({unit: u, priority: priorities[u]});
  468. }
  469. units.sort(function (a, b) {
  470. return a.priority - b.priority;
  471. });
  472. return units;
  473. }
  474. function zeroFill(number, targetLength, forceSign) {
  475. var absNumber = '' + Math.abs(number),
  476. zerosToFill = targetLength - absNumber.length,
  477. sign = number >= 0;
  478. return (sign ? (forceSign ? '+' : '') : '-') +
  479. Math.pow(10, Math.max(0, zerosToFill)).toString().substr(1) + absNumber;
  480. }
  481. var formattingTokens = /(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|YYYYYY|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g;
  482. var localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g;
  483. var formatFunctions = {};
  484. var formatTokenFunctions = {};
  485. // token: 'M'
  486. // padded: ['MM', 2]
  487. // ordinal: 'Mo'
  488. // callback: function () { this.month() + 1 }
  489. function addFormatToken (token, padded, ordinal, callback) {
  490. var func = callback;
  491. if (typeof callback === 'string') {
  492. func = function () {
  493. return this[callback]();
  494. };
  495. }
  496. if (token) {
  497. formatTokenFunctions[token] = func;
  498. }
  499. if (padded) {
  500. formatTokenFunctions[padded[0]] = function () {
  501. return zeroFill(func.apply(this, arguments), padded[1], padded[2]);
  502. };
  503. }
  504. if (ordinal) {
  505. formatTokenFunctions[ordinal] = function () {
  506. return this.localeData().ordinal(func.apply(this, arguments), token);
  507. };
  508. }
  509. }
  510. function removeFormattingTokens(input) {
  511. if (input.match(/\[[\s\S]/)) {
  512. return input.replace(/^\[|\]$/g, '');
  513. }
  514. return input.replace(/\\/g, '');
  515. }
  516. function makeFormatFunction(format) {
  517. var array = format.match(formattingTokens), i, length;
  518. for (i = 0, length = array.length; i < length; i++) {
  519. if (formatTokenFunctions[array[i]]) {
  520. array[i] = formatTokenFunctions[array[i]];
  521. } else {
  522. array[i] = removeFormattingTokens(array[i]);
  523. }
  524. }
  525. return function (mom) {
  526. var output = '', i;
  527. for (i = 0; i < length; i++) {
  528. output += isFunction(array[i]) ? array[i].call(mom, format) : array[i];
  529. }
  530. return output;
  531. };
  532. }
  533. // format date using native date object
  534. function formatMoment(m, format) {
  535. if (!m.isValid()) {
  536. return m.localeData().invalidDate();
  537. }
  538. format = expandFormat(format, m.localeData());
  539. formatFunctions[format] = formatFunctions[format] || makeFormatFunction(format);
  540. return formatFunctions[format](m);
  541. }
  542. function expandFormat(format, locale) {
  543. var i = 5;
  544. function replaceLongDateFormatTokens(input) {
  545. return locale.longDateFormat(input) || input;
  546. }
  547. localFormattingTokens.lastIndex = 0;
  548. while (i >= 0 && localFormattingTokens.test(format)) {
  549. format = format.replace(localFormattingTokens, replaceLongDateFormatTokens);
  550. localFormattingTokens.lastIndex = 0;
  551. i -= 1;
  552. }
  553. return format;
  554. }
  555. var match1 = /\d/; // 0 - 9
  556. var match2 = /\d\d/; // 00 - 99
  557. var match3 = /\d{3}/; // 000 - 999
  558. var match4 = /\d{4}/; // 0000 - 9999
  559. var match6 = /[+-]?\d{6}/; // -999999 - 999999
  560. var match1to2 = /\d\d?/; // 0 - 99
  561. var match3to4 = /\d\d\d\d?/; // 999 - 9999
  562. var match5to6 = /\d\d\d\d\d\d?/; // 99999 - 999999
  563. var match1to3 = /\d{1,3}/; // 0 - 999
  564. var match1to4 = /\d{1,4}/; // 0 - 9999
  565. var match1to6 = /[+-]?\d{1,6}/; // -999999 - 999999
  566. var matchUnsigned = /\d+/; // 0 - inf
  567. var matchSigned = /[+-]?\d+/; // -inf - inf
  568. var matchOffset = /Z|[+-]\d\d:?\d\d/gi; // +00:00 -00:00 +0000 -0000 or Z
  569. var matchShortOffset = /Z|[+-]\d\d(?::?\d\d)?/gi; // +00 -00 +00:00 -00:00 +0000 -0000 or Z
  570. var matchTimestamp = /[+-]?\d+(\.\d{1,3})?/; // 123456789 123456789.123
  571. // any word (or two) characters or numbers including two/three word month in arabic.
  572. // includes scottish gaelic two word and hyphenated months
  573. var 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;
  574. var regexes = {};
  575. function addRegexToken (token, regex, strictRegex) {
  576. regexes[token] = isFunction(regex) ? regex : function (isStrict, localeData) {
  577. return (isStrict && strictRegex) ? strictRegex : regex;
  578. };
  579. }
  580. function getParseRegexForToken (token, config) {
  581. if (!hasOwnProp(regexes, token)) {
  582. return new RegExp(unescapeFormat(token));
  583. }
  584. return regexes[token](config._strict, config._locale);
  585. }
  586. // Code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
  587. function unescapeFormat(s) {
  588. return regexEscape(s.replace('\\', '').replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, function (matched, p1, p2, p3, p4) {
  589. return p1 || p2 || p3 || p4;
  590. }));
  591. }
  592. function regexEscape(s) {
  593. return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
  594. }
  595. var tokens = {};
  596. function addParseToken (token, callback) {
  597. var i, func = callback;
  598. if (typeof token === 'string') {
  599. token = [token];
  600. }
  601. if (isNumber(callback)) {
  602. func = function (input, array) {
  603. array[callback] = toInt(input);
  604. };
  605. }
  606. for (i = 0; i < token.length; i++) {
  607. tokens[token[i]] = func;
  608. }
  609. }
  610. function addWeekParseToken (token, callback) {
  611. addParseToken(token, function (input, array, config, token) {
  612. config._w = config._w || {};
  613. callback(input, config._w, config, token);
  614. });
  615. }
  616. function addTimeToArrayFromToken(token, input, config) {
  617. if (input != null && hasOwnProp(tokens, token)) {
  618. tokens[token](input, config._a, config, token);
  619. }
  620. }
  621. var YEAR = 0;
  622. var MONTH = 1;
  623. var DATE = 2;
  624. var HOUR = 3;
  625. var MINUTE = 4;
  626. var SECOND = 5;
  627. var MILLISECOND = 6;
  628. var WEEK = 7;
  629. var WEEKDAY = 8;
  630. // FORMATTING
  631. addFormatToken('Y', 0, 0, function () {
  632. var y = this.year();
  633. return y <= 9999 ? '' + y : '+' + y;
  634. });
  635. addFormatToken(0, ['YY', 2], 0, function () {
  636. return this.year() % 100;
  637. });
  638. addFormatToken(0, ['YYYY', 4], 0, 'year');
  639. addFormatToken(0, ['YYYYY', 5], 0, 'year');
  640. addFormatToken(0, ['YYYYYY', 6, true], 0, 'year');
  641. // ALIASES
  642. addUnitAlias('year', 'y');
  643. // PRIORITIES
  644. addUnitPriority('year', 1);
  645. // PARSING
  646. addRegexToken('Y', matchSigned);
  647. addRegexToken('YY', match1to2, match2);
  648. addRegexToken('YYYY', match1to4, match4);
  649. addRegexToken('YYYYY', match1to6, match6);
  650. addRegexToken('YYYYYY', match1to6, match6);
  651. addParseToken(['YYYYY', 'YYYYYY'], YEAR);
  652. addParseToken('YYYY', function (input, array) {
  653. array[YEAR] = input.length === 2 ? hooks.parseTwoDigitYear(input) : toInt(input);
  654. });
  655. addParseToken('YY', function (input, array) {
  656. array[YEAR] = hooks.parseTwoDigitYear(input);
  657. });
  658. addParseToken('Y', function (input, array) {
  659. array[YEAR] = parseInt(input, 10);
  660. });
  661. // HELPERS
  662. function daysInYear(year) {
  663. return isLeapYear(year) ? 366 : 365;
  664. }
  665. function isLeapYear(year) {
  666. return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
  667. }
  668. // HOOKS
  669. hooks.parseTwoDigitYear = function (input) {
  670. return toInt(input) + (toInt(input) > 68 ? 1900 : 2000);
  671. };
  672. // MOMENTS
  673. var getSetYear = makeGetSet('FullYear', true);
  674. function getIsLeapYear () {
  675. return isLeapYear(this.year());
  676. }
  677. function makeGetSet (unit, keepTime) {
  678. return function (value) {
  679. if (value != null) {
  680. set$1(this, unit, value);
  681. hooks.updateOffset(this, keepTime);
  682. return this;
  683. } else {
  684. return get(this, unit);
  685. }
  686. };
  687. }
  688. function get (mom, unit) {
  689. return mom.isValid() ?
  690. mom._d['get' + (mom._isUTC ? 'UTC' : '') + unit]() : NaN;
  691. }
  692. function set$1 (mom, unit, value) {
  693. if (mom.isValid() && !isNaN(value)) {
  694. if (unit === 'FullYear' && isLeapYear(mom.year()) && mom.month() === 1 && mom.date() === 29) {
  695. mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value, mom.month(), daysInMonth(value, mom.month()));
  696. }
  697. else {
  698. mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value);
  699. }
  700. }
  701. }
  702. // MOMENTS
  703. function stringGet (units) {
  704. units = normalizeUnits(units);
  705. if (isFunction(this[units])) {
  706. return this[units]();
  707. }
  708. return this;
  709. }
  710. function stringSet (units, value) {
  711. if (typeof units === 'object') {
  712. units = normalizeObjectUnits(units);
  713. var prioritized = getPrioritizedUnits(units);
  714. for (var i = 0; i < prioritized.length; i++) {
  715. this[prioritized[i].unit](units[prioritized[i].unit]);
  716. }
  717. } else {
  718. units = normalizeUnits(units);
  719. if (isFunction(this[units])) {
  720. return this[units](value);
  721. }
  722. }
  723. return this;
  724. }
  725. function mod(n, x) {
  726. return ((n % x) + x) % x;
  727. }
  728. var indexOf;
  729. if (Array.prototype.indexOf) {
  730. indexOf = Array.prototype.indexOf;
  731. } else {
  732. indexOf = function (o) {
  733. // I know
  734. var i;
  735. for (i = 0; i < this.length; ++i) {
  736. if (this[i] === o) {
  737. return i;
  738. }
  739. }
  740. return -1;
  741. };
  742. }
  743. function daysInMonth(year, month) {
  744. if (isNaN(year) || isNaN(month)) {
  745. return NaN;
  746. }
  747. var modMonth = mod(month, 12);
  748. year += (month - modMonth) / 12;
  749. return modMonth === 1 ? (isLeapYear(year) ? 29 : 28) : (31 - modMonth % 7 % 2);
  750. }
  751. // FORMATTING
  752. addFormatToken('M', ['MM', 2], 'Mo', function () {
  753. return this.month() + 1;
  754. });
  755. addFormatToken('MMM', 0, 0, function (format) {
  756. return this.localeData().monthsShort(this, format);
  757. });
  758. addFormatToken('MMMM', 0, 0, function (format) {
  759. return this.localeData().months(this, format);
  760. });
  761. // ALIASES
  762. addUnitAlias('month', 'M');
  763. // PRIORITY
  764. addUnitPriority('month', 8);
  765. // PARSING
  766. addRegexToken('M', match1to2);
  767. addRegexToken('MM', match1to2, match2);
  768. addRegexToken('MMM', function (isStrict, locale) {
  769. return locale.monthsShortRegex(isStrict);
  770. });
  771. addRegexToken('MMMM', function (isStrict, locale) {
  772. return locale.monthsRegex(isStrict);
  773. });
  774. addParseToken(['M', 'MM'], function (input, array) {
  775. array[MONTH] = toInt(input) - 1;
  776. });
  777. addParseToken(['MMM', 'MMMM'], function (input, array, config, token) {
  778. var month = config._locale.monthsParse(input, token, config._strict);
  779. // if we didn't find a month name, mark the date as invalid.
  780. if (month != null) {
  781. array[MONTH] = month;
  782. } else {
  783. getParsingFlags(config).invalidMonth = input;
  784. }
  785. });
  786. // LOCALES
  787. var MONTHS_IN_FORMAT = /D[oD]?(\[[^\[\]]*\]|\s)+MMMM?/;
  788. var defaultLocaleMonths = 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_');
  789. function localeMonths (m, format) {
  790. if (!m) {
  791. return isArray(this._months) ? this._months :
  792. this._months['standalone'];
  793. }
  794. return isArray(this._months) ? this._months[m.month()] :
  795. this._months[(this._months.isFormat || MONTHS_IN_FORMAT).test(format) ? 'format' : 'standalone'][m.month()];
  796. }
  797. var defaultLocaleMonthsShort = 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_');
  798. function localeMonthsShort (m, format) {
  799. if (!m) {
  800. return isArray(this._monthsShort) ? this._monthsShort :
  801. this._monthsShort['standalone'];
  802. }
  803. return isArray(this._monthsShort) ? this._monthsShort[m.month()] :
  804. this._monthsShort[MONTHS_IN_FORMAT.test(format) ? 'format' : 'standalone'][m.month()];
  805. }
  806. function handleStrictParse(monthName, format, strict) {
  807. var i, ii, mom, llc = monthName.toLocaleLowerCase();
  808. if (!this._monthsParse) {
  809. // this is not used
  810. this._monthsParse = [];
  811. this._longMonthsParse = [];
  812. this._shortMonthsParse = [];
  813. for (i = 0; i < 12; ++i) {
  814. mom = createUTC([2000, i]);
  815. this._shortMonthsParse[i] = this.monthsShort(mom, '').toLocaleLowerCase();
  816. this._longMonthsParse[i] = this.months(mom, '').toLocaleLowerCase();
  817. }
  818. }
  819. if (strict) {
  820. if (format === 'MMM') {
  821. ii = indexOf.call(this._shortMonthsParse, llc);
  822. return ii !== -1 ? ii : null;
  823. } else {
  824. ii = indexOf.call(this._longMonthsParse, llc);
  825. return ii !== -1 ? ii : null;
  826. }
  827. } else {
  828. if (format === 'MMM') {
  829. ii = indexOf.call(this._shortMonthsParse, llc);
  830. if (ii !== -1) {
  831. return ii;
  832. }
  833. ii = indexOf.call(this._longMonthsParse, llc);
  834. return ii !== -1 ? ii : null;
  835. } else {
  836. ii = indexOf.call(this._longMonthsParse, llc);
  837. if (ii !== -1) {
  838. return ii;
  839. }
  840. ii = indexOf.call(this._shortMonthsParse, llc);
  841. return ii !== -1 ? ii : null;
  842. }
  843. }
  844. }
  845. function localeMonthsParse (monthName, format, strict) {
  846. var i, mom, regex;
  847. if (this._monthsParseExact) {
  848. return handleStrictParse.call(this, monthName, format, strict);
  849. }
  850. if (!this._monthsParse) {
  851. this._monthsParse = [];
  852. this._longMonthsParse = [];
  853. this._shortMonthsParse = [];
  854. }
  855. // TODO: add sorting
  856. // Sorting makes sure if one month (or abbr) is a prefix of another
  857. // see sorting in computeMonthsParse
  858. for (i = 0; i < 12; i++) {
  859. // make the regex if we don't have it already
  860. mom = createUTC([2000, i]);
  861. if (strict && !this._longMonthsParse[i]) {
  862. this._longMonthsParse[i] = new RegExp('^' + this.months(mom, '').replace('.', '') + '$', 'i');
  863. this._shortMonthsParse[i] = new RegExp('^' + this.monthsShort(mom, '').replace('.', '') + '$', 'i');
  864. }
  865. if (!strict && !this._monthsParse[i]) {
  866. regex = '^' + this.months(mom, '') + '|^' + this.monthsShort(mom, '');
  867. this._monthsParse[i] = new RegExp(regex.replace('.', ''), 'i');
  868. }
  869. // test the regex
  870. if (strict && format === 'MMMM' && this._longMonthsParse[i].test(monthName)) {
  871. return i;
  872. } else if (strict && format === 'MMM' && this._shortMonthsParse[i].test(monthName)) {
  873. return i;
  874. } else if (!strict && this._monthsParse[i].test(monthName)) {
  875. return i;
  876. }
  877. }
  878. }
  879. // MOMENTS
  880. function setMonth (mom, value) {
  881. var dayOfMonth;
  882. if (!mom.isValid()) {
  883. // No op
  884. return mom;
  885. }
  886. if (typeof value === 'string') {
  887. if (/^\d+$/.test(value)) {
  888. value = toInt(value);
  889. } else {
  890. value = mom.localeData().monthsParse(value);
  891. // TODO: Another silent failure?
  892. if (!isNumber(value)) {
  893. return mom;
  894. }
  895. }
  896. }
  897. dayOfMonth = Math.min(mom.date(), daysInMonth(mom.year(), value));
  898. mom._d['set' + (mom._isUTC ? 'UTC' : '') + 'Month'](value, dayOfMonth);
  899. return mom;
  900. }
  901. function getSetMonth (value) {
  902. if (value != null) {
  903. setMonth(this, value);
  904. hooks.updateOffset(this, true);
  905. return this;
  906. } else {
  907. return get(this, 'Month');
  908. }
  909. }
  910. function getDaysInMonth () {
  911. return daysInMonth(this.year(), this.month());
  912. }
  913. var defaultMonthsShortRegex = matchWord;
  914. function monthsShortRegex (isStrict) {
  915. if (this._monthsParseExact) {
  916. if (!hasOwnProp(this, '_monthsRegex')) {
  917. computeMonthsParse.call(this);
  918. }
  919. if (isStrict) {
  920. return this._monthsShortStrictRegex;
  921. } else {
  922. return this._monthsShortRegex;
  923. }
  924. } else {
  925. if (!hasOwnProp(this, '_monthsShortRegex')) {
  926. this._monthsShortRegex = defaultMonthsShortRegex;
  927. }
  928. return this._monthsShortStrictRegex && isStrict ?
  929. this._monthsShortStrictRegex : this._monthsShortRegex;
  930. }
  931. }
  932. var defaultMonthsRegex = matchWord;
  933. function monthsRegex (isStrict) {
  934. if (this._monthsParseExact) {
  935. if (!hasOwnProp(this, '_monthsRegex')) {
  936. computeMonthsParse.call(this);
  937. }
  938. if (isStrict) {
  939. return this._monthsStrictRegex;
  940. } else {
  941. return this._monthsRegex;
  942. }
  943. } else {
  944. if (!hasOwnProp(this, '_monthsRegex')) {
  945. this._monthsRegex = defaultMonthsRegex;
  946. }
  947. return this._monthsStrictRegex && isStrict ?
  948. this._monthsStrictRegex : this._monthsRegex;
  949. }
  950. }
  951. function computeMonthsParse () {
  952. function cmpLenRev(a, b) {
  953. return b.length - a.length;
  954. }
  955. var shortPieces = [], longPieces = [], mixedPieces = [],
  956. i, mom;
  957. for (i = 0; i < 12; i++) {
  958. // make the regex if we don't have it already
  959. mom = createUTC([2000, i]);
  960. shortPieces.push(this.monthsShort(mom, ''));
  961. longPieces.push(this.months(mom, ''));
  962. mixedPieces.push(this.months(mom, ''));
  963. mixedPieces.push(this.monthsShort(mom, ''));
  964. }
  965. // Sorting makes sure if one month (or abbr) is a prefix of another it
  966. // will match the longer piece.
  967. shortPieces.sort(cmpLenRev);
  968. longPieces.sort(cmpLenRev);
  969. mixedPieces.sort(cmpLenRev);
  970. for (i = 0; i < 12; i++) {
  971. shortPieces[i] = regexEscape(shortPieces[i]);
  972. longPieces[i] = regexEscape(longPieces[i]);
  973. }
  974. for (i = 0; i < 24; i++) {
  975. mixedPieces[i] = regexEscape(mixedPieces[i]);
  976. }
  977. this._monthsRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i');
  978. this._monthsShortRegex = this._monthsRegex;
  979. this._monthsStrictRegex = new RegExp('^(' + longPieces.join('|') + ')', 'i');
  980. this._monthsShortStrictRegex = new RegExp('^(' + shortPieces.join('|') + ')', 'i');
  981. }
  982. function createDate (y, m, d, h, M, s, ms) {
  983. // can't just apply() to create a date:
  984. // https://stackoverflow.com/q/181348
  985. var date = new Date(y, m, d, h, M, s, ms);
  986. // the date constructor remaps years 0-99 to 1900-1999
  987. if (y < 100 && y >= 0 && isFinite(date.getFullYear())) {
  988. date.setFullYear(y);
  989. }
  990. return date;
  991. }
  992. function createUTCDate (y) {
  993. var date = new Date(Date.UTC.apply(null, arguments));
  994. // the Date.UTC function remaps years 0-99 to 1900-1999
  995. if (y < 100 && y >= 0 && isFinite(date.getUTCFullYear())) {
  996. date.setUTCFullYear(y);
  997. }
  998. return date;
  999. }
  1000. // start-of-first-week - start-of-year
  1001. function firstWeekOffset(year, dow, doy) {
  1002. var // first-week day -- which january is always in the first week (4 for iso, 1 for other)
  1003. fwd = 7 + dow - doy,
  1004. // first-week day local weekday -- which local weekday is fwd
  1005. fwdlw = (7 + createUTCDate(year, 0, fwd).getUTCDay() - dow) % 7;
  1006. return -fwdlw + fwd - 1;
  1007. }
  1008. // https://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday
  1009. function dayOfYearFromWeeks(year, week, weekday, dow, doy) {
  1010. var localWeekday = (7 + weekday - dow) % 7,
  1011. weekOffset = firstWeekOffset(year, dow, doy),
  1012. dayOfYear = 1 + 7 * (week - 1) + localWeekday + weekOffset,
  1013. resYear, resDayOfYear;
  1014. if (dayOfYear <= 0) {
  1015. resYear = year - 1;
  1016. resDayOfYear = daysInYear(resYear) + dayOfYear;
  1017. } else if (dayOfYear > daysInYear(year)) {
  1018. resYear = year + 1;
  1019. resDayOfYear = dayOfYear - daysInYear(year);
  1020. } else {
  1021. resYear = year;
  1022. resDayOfYear = dayOfYear;
  1023. }
  1024. return {
  1025. year: resYear,
  1026. dayOfYear: resDayOfYear
  1027. };
  1028. }
  1029. function weekOfYear(mom, dow, doy) {
  1030. var weekOffset = firstWeekOffset(mom.year(), dow, doy),
  1031. week = Math.floor((mom.dayOfYear() - weekOffset - 1) / 7) + 1,
  1032. resWeek, resYear;
  1033. if (week < 1) {
  1034. resYear = mom.year() - 1;
  1035. resWeek = week + weeksInYear(resYear, dow, doy);
  1036. } else if (week > weeksInYear(mom.year(), dow, doy)) {
  1037. resWeek = week - weeksInYear(mom.year(), dow, doy);
  1038. resYear = mom.year() + 1;
  1039. } else {
  1040. resYear = mom.year();
  1041. resWeek = week;
  1042. }
  1043. return {
  1044. week: resWeek,
  1045. year: resYear
  1046. };
  1047. }
  1048. function weeksInYear(year, dow, doy) {
  1049. var weekOffset = firstWeekOffset(year, dow, doy),
  1050. weekOffsetNext = firstWeekOffset(year + 1, dow, doy);
  1051. return (daysInYear(year) - weekOffset + weekOffsetNext) / 7;
  1052. }
  1053. // FORMATTING
  1054. addFormatToken('w', ['ww', 2], 'wo', 'week');
  1055. addFormatToken('W', ['WW', 2], 'Wo', 'isoWeek');
  1056. // ALIASES
  1057. addUnitAlias('week', 'w');
  1058. addUnitAlias('isoWeek', 'W');
  1059. // PRIORITIES
  1060. addUnitPriority('week', 5);
  1061. addUnitPriority('isoWeek', 5);
  1062. // PARSING
  1063. addRegexToken('w', match1to2);
  1064. addRegexToken('ww', match1to2, match2);
  1065. addRegexToken('W', match1to2);
  1066. addRegexToken('WW', match1to2, match2);
  1067. addWeekParseToken(['w', 'ww', 'W', 'WW'], function (input, week, config, token) {
  1068. week[token.substr(0, 1)] = toInt(input);
  1069. });
  1070. // HELPERS
  1071. // LOCALES
  1072. function localeWeek (mom) {
  1073. return weekOfYear(mom, this._week.dow, this._week.doy).week;
  1074. }
  1075. var defaultLocaleWeek = {
  1076. dow : 0, // Sunday is the first day of the week.
  1077. doy : 6 // The week that contains Jan 1st is the first week of the year.
  1078. };
  1079. function localeFirstDayOfWeek () {
  1080. return this._week.dow;
  1081. }
  1082. function localeFirstDayOfYear () {
  1083. return this._week.doy;
  1084. }
  1085. // MOMENTS
  1086. function getSetWeek (input) {
  1087. var week = this.localeData().week(this);
  1088. return input == null ? week : this.add((input - week) * 7, 'd');
  1089. }
  1090. function getSetISOWeek (input) {
  1091. var week = weekOfYear(this, 1, 4).week;
  1092. return input == null ? week : this.add((input - week) * 7, 'd');
  1093. }
  1094. // FORMATTING
  1095. addFormatToken('d', 0, 'do', 'day');
  1096. addFormatToken('dd', 0, 0, function (format) {
  1097. return this.localeData().weekdaysMin(this, format);
  1098. });
  1099. addFormatToken('ddd', 0, 0, function (format) {
  1100. return this.localeData().weekdaysShort(this, format);
  1101. });
  1102. addFormatToken('dddd', 0, 0, function (format) {
  1103. return this.localeData().weekdays(this, format);
  1104. });
  1105. addFormatToken('e', 0, 0, 'weekday');
  1106. addFormatToken('E', 0, 0, 'isoWeekday');
  1107. // ALIASES
  1108. addUnitAlias('day', 'd');
  1109. addUnitAlias('weekday', 'e');
  1110. addUnitAlias('isoWeekday', 'E');
  1111. // PRIORITY
  1112. addUnitPriority('day', 11);
  1113. addUnitPriority('weekday', 11);
  1114. addUnitPriority('isoWeekday', 11);
  1115. // PARSING
  1116. addRegexToken('d', match1to2);
  1117. addRegexToken('e', match1to2);
  1118. addRegexToken('E', match1to2);
  1119. addRegexToken('dd', function (isStrict, locale) {
  1120. return locale.weekdaysMinRegex(isStrict);
  1121. });
  1122. addRegexToken('ddd', function (isStrict, locale) {
  1123. return locale.weekdaysShortRegex(isStrict);
  1124. });
  1125. addRegexToken('dddd', function (isStrict, locale) {
  1126. return locale.weekdaysRegex(isStrict);
  1127. });
  1128. addWeekParseToken(['dd', 'ddd', 'dddd'], function (input, week, config, token) {
  1129. var weekday = config._locale.weekdaysParse(input, token, config._strict);
  1130. // if we didn't get a weekday name, mark the date as invalid
  1131. if (weekday != null) {
  1132. week.d = weekday;
  1133. } else {
  1134. getParsingFlags(config).invalidWeekday = input;
  1135. }
  1136. });
  1137. addWeekParseToken(['d', 'e', 'E'], function (input, week, config, token) {
  1138. week[token] = toInt(input);
  1139. });
  1140. // HELPERS
  1141. function parseWeekday(input, locale) {
  1142. if (typeof input !== 'string') {
  1143. return input;
  1144. }
  1145. if (!isNaN(input)) {
  1146. return parseInt(input, 10);
  1147. }
  1148. input = locale.weekdaysParse(input);
  1149. if (typeof input === 'number') {
  1150. return input;
  1151. }
  1152. return null;
  1153. }
  1154. function parseIsoWeekday(input, locale) {
  1155. if (typeof input === 'string') {
  1156. return locale.weekdaysParse(input) % 7 || 7;
  1157. }
  1158. return isNaN(input) ? null : input;
  1159. }
  1160. // LOCALES
  1161. var defaultLocaleWeekdays = 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_');
  1162. function localeWeekdays (m, format) {
  1163. if (!m) {
  1164. return isArray(this._weekdays) ? this._weekdays :
  1165. this._weekdays['standalone'];
  1166. }
  1167. return isArray(this._weekdays) ? this._weekdays[m.day()] :
  1168. this._weekdays[this._weekdays.isFormat.test(format) ? 'format' : 'standalone'][m.day()];
  1169. }
  1170. var defaultLocaleWeekdaysShort = 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_');
  1171. function localeWeekdaysShort (m) {
  1172. return (m) ? this._weekdaysShort[m.day()] : this._weekdaysShort;
  1173. }
  1174. var defaultLocaleWeekdaysMin = 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_');
  1175. function localeWeekdaysMin (m) {
  1176. return (m) ? this._weekdaysMin[m.day()] : this._weekdaysMin;
  1177. }
  1178. function handleStrictParse$1(weekdayName, format, strict) {
  1179. var i, ii, mom, llc = weekdayName.toLocaleLowerCase();
  1180. if (!this._weekdaysParse) {
  1181. this._weekdaysParse = [];
  1182. this._shortWeekdaysParse = [];
  1183. this._minWeekdaysParse = [];
  1184. for (i = 0; i < 7; ++i) {
  1185. mom = createUTC([2000, 1]).day(i);
  1186. this._minWeekdaysParse[i] = this.weekdaysMin(mom, '').toLocaleLowerCase();
  1187. this._shortWeekdaysParse[i] = this.weekdaysShort(mom, '').toLocaleLowerCase();
  1188. this._weekdaysParse[i] = this.weekdays(mom, '').toLocaleLowerCase();
  1189. }
  1190. }
  1191. if (strict) {
  1192. if (format === 'dddd') {
  1193. ii = indexOf.call(this._weekdaysParse, llc);
  1194. return ii !== -1 ? ii : null;
  1195. } else if (format === 'ddd') {
  1196. ii = indexOf.call(this._shortWeekdaysParse, llc);
  1197. return ii !== -1 ? ii : null;
  1198. } else {
  1199. ii = indexOf.call(this._minWeekdaysParse, llc);
  1200. return ii !== -1 ? ii : null;
  1201. }
  1202. } else {
  1203. if (format === 'dddd') {
  1204. ii = indexOf.call(this._weekdaysParse, llc);
  1205. if (ii !== -1) {
  1206. return ii;
  1207. }
  1208. ii = indexOf.call(this._shortWeekdaysParse, llc);
  1209. if (ii !== -1) {
  1210. return ii;
  1211. }
  1212. ii = indexOf.call(this._minWeekdaysParse, llc);
  1213. return ii !== -1 ? ii : null;
  1214. } else if (format === 'ddd') {
  1215. ii = indexOf.call(this._shortWeekdaysParse, llc);
  1216. if (ii !== -1) {
  1217. return ii;
  1218. }
  1219. ii = indexOf.call(this._weekdaysParse, llc);
  1220. if (ii !== -1) {
  1221. return ii;
  1222. }
  1223. ii = indexOf.call(this._minWeekdaysParse, llc);
  1224. return ii !== -1 ? ii : null;
  1225. } else {
  1226. ii = indexOf.call(this._minWeekdaysParse, llc);
  1227. if (ii !== -1) {
  1228. return ii;
  1229. }
  1230. ii = indexOf.call(this._weekdaysParse, llc);
  1231. if (ii !== -1) {
  1232. return ii;
  1233. }
  1234. ii = indexOf.call(this._shortWeekdaysParse, llc);
  1235. return ii !== -1 ? ii : null;
  1236. }
  1237. }
  1238. }
  1239. function localeWeekdaysParse (weekdayName, format, strict) {
  1240. var i, mom, regex;
  1241. if (this._weekdaysParseExact) {
  1242. return handleStrictParse$1.call(this, weekdayName, format, strict);
  1243. }
  1244. if (!this._weekdaysParse) {
  1245. this._weekdaysParse = [];
  1246. this._minWeekdaysParse = [];
  1247. this._shortWeekdaysParse = [];
  1248. this._fullWeekdaysParse = [];
  1249. }
  1250. for (i = 0; i < 7; i++) {
  1251. // make the regex if we don't have it already
  1252. mom = createUTC([2000, 1]).day(i);
  1253. if (strict && !this._fullWeekdaysParse[i]) {
  1254. this._fullWeekdaysParse[i] = new RegExp('^' + this.weekdays(mom, '').replace('.', '\.?') + '$', 'i');
  1255. this._shortWeekdaysParse[i] = new RegExp('^' + this.weekdaysShort(mom, '').replace('.', '\.?') + '$', 'i');
  1256. this._minWeekdaysParse[i] = new RegExp('^' + this.weekdaysMin(mom, '').replace('.', '\.?') + '$', 'i');
  1257. }
  1258. if (!this._weekdaysParse[i]) {
  1259. regex = '^' + this.weekdays(mom, '') + '|^' + this.weekdaysShort(mom, '') + '|^' + this.weekdaysMin(mom, '');
  1260. this._weekdaysParse[i] = new RegExp(regex.replace('.', ''), 'i');
  1261. }
  1262. // test the regex
  1263. if (strict && format === 'dddd' && this._fullWeekdaysParse[i].test(weekdayName)) {
  1264. return i;
  1265. } else if (strict && format === 'ddd' && this._shortWeekdaysParse[i].test(weekdayName)) {
  1266. return i;
  1267. } else if (strict && format === 'dd' && this._minWeekdaysParse[i].test(weekdayName)) {
  1268. return i;
  1269. } else if (!strict && this._weekdaysParse[i].test(weekdayName)) {
  1270. return i;
  1271. }
  1272. }
  1273. }
  1274. // MOMENTS
  1275. function getSetDayOfWeek (input) {
  1276. if (!this.isValid()) {
  1277. return input != null ? this : NaN;
  1278. }
  1279. var day = this._isUTC ? this._d.getUTCDay() : this._d.getDay();
  1280. if (input != null) {
  1281. input = parseWeekday(input, this.localeData());
  1282. return this.add(input - day, 'd');
  1283. } else {
  1284. return day;
  1285. }
  1286. }
  1287. function getSetLocaleDayOfWeek (input) {
  1288. if (!this.isValid()) {
  1289. return input != null ? this : NaN;
  1290. }
  1291. var weekday = (this.day() + 7 - this.localeData()._week.dow) % 7;
  1292. return input == null ? weekday : this.add(input - weekday, 'd');
  1293. }
  1294. function getSetISODayOfWeek (input) {
  1295. if (!this.isValid()) {
  1296. return input != null ? this : NaN;
  1297. }
  1298. // behaves the same as moment#day except
  1299. // as a getter, returns 7 instead of 0 (1-7 range instead of 0-6)
  1300. // as a setter, sunday should belong to the previous week.
  1301. if (input != null) {
  1302. var weekday = parseIsoWeekday(input, this.localeData());
  1303. return this.day(this.day() % 7 ? weekday : weekday - 7);
  1304. } else {
  1305. return this.day() || 7;
  1306. }
  1307. }
  1308. var defaultWeekdaysRegex = matchWord;
  1309. function weekdaysRegex (isStrict) {
  1310. if (this._weekdaysParseExact) {
  1311. if (!hasOwnProp(this, '_weekdaysRegex')) {
  1312. computeWeekdaysParse.call(this);
  1313. }
  1314. if (isStrict) {
  1315. return this._weekdaysStrictRegex;
  1316. } else {
  1317. return this._weekdaysRegex;
  1318. }
  1319. } else {
  1320. if (!hasOwnProp(this, '_weekdaysRegex')) {
  1321. this._weekdaysRegex = defaultWeekdaysRegex;
  1322. }
  1323. return this._weekdaysStrictRegex && isStrict ?
  1324. this._weekdaysStrictRegex : this._weekdaysRegex;
  1325. }
  1326. }
  1327. var defaultWeekdaysShortRegex = matchWord;
  1328. function weekdaysShortRegex (isStrict) {
  1329. if (this._weekdaysParseExact) {
  1330. if (!hasOwnProp(this, '_weekdaysRegex')) {
  1331. computeWeekdaysParse.call(this);
  1332. }
  1333. if (isStrict) {
  1334. return this._weekdaysShortStrictRegex;
  1335. } else {
  1336. return this._weekdaysShortRegex;
  1337. }
  1338. } else {
  1339. if (!hasOwnProp(this, '_weekdaysShortRegex')) {
  1340. this._weekdaysShortRegex = defaultWeekdaysShortRegex;
  1341. }
  1342. return this._weekdaysShortStrictRegex && isStrict ?
  1343. this._weekdaysShortStrictRegex : this._weekdaysShortRegex;
  1344. }
  1345. }
  1346. var defaultWeekdaysMinRegex = matchWord;
  1347. function weekdaysMinRegex (isStrict) {
  1348. if (this._weekdaysParseExact) {
  1349. if (!hasOwnProp(this, '_weekdaysRegex')) {
  1350. computeWeekdaysParse.call(this);
  1351. }
  1352. if (isStrict) {
  1353. return this._weekdaysMinStrictRegex;
  1354. } else {
  1355. return this._weekdaysMinRegex;
  1356. }
  1357. } else {
  1358. if (!hasOwnProp(this, '_weekdaysMinRegex')) {
  1359. this._weekdaysMinRegex = defaultWeekdaysMinRegex;
  1360. }
  1361. return this._weekdaysMinStrictRegex && isStrict ?
  1362. this._weekdaysMinStrictRegex : this._weekdaysMinRegex;
  1363. }
  1364. }
  1365. function computeWeekdaysParse () {
  1366. function cmpLenRev(a, b) {
  1367. return b.length - a.length;
  1368. }
  1369. var minPieces = [], shortPieces = [], longPieces = [], mixedPieces = [],
  1370. i, mom, minp, shortp, longp;
  1371. for (i = 0; i < 7; i++) {
  1372. // make the regex if we don't have it already
  1373. mom = createUTC([2000, 1]).day(i);
  1374. minp = this.weekdaysMin(mom, '');
  1375. shortp = this.weekdaysShort(mom, '');
  1376. longp = this.weekdays(mom, '');
  1377. minPieces.push(minp);
  1378. shortPieces.push(shortp);
  1379. longPieces.push(longp);
  1380. mixedPieces.push(minp);
  1381. mixedPieces.push(shortp);
  1382. mixedPieces.push(longp);
  1383. }
  1384. // Sorting makes sure if one weekday (or abbr) is a prefix of another it
  1385. // will match the longer piece.
  1386. minPieces.sort(cmpLenRev);
  1387. shortPieces.sort(cmpLenRev);
  1388. longPieces.sort(cmpLenRev);
  1389. mixedPieces.sort(cmpLenRev);
  1390. for (i = 0; i < 7; i++) {
  1391. shortPieces[i] = regexEscape(shortPieces[i]);
  1392. longPieces[i] = regexEscape(longPieces[i]);
  1393. mixedPieces[i] = regexEscape(mixedPieces[i]);
  1394. }
  1395. this._weekdaysRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i');
  1396. this._weekdaysShortRegex = this._weekdaysRegex;
  1397. this._weekdaysMinRegex = this._weekdaysRegex;
  1398. this._weekdaysStrictRegex = new RegExp('^(' + longPieces.join('|') + ')', 'i');
  1399. this._weekdaysShortStrictRegex = new RegExp('^(' + shortPieces.join('|') + ')', 'i');
  1400. this._weekdaysMinStrictRegex = new RegExp('^(' + minPieces.join('|') + ')', 'i');
  1401. }
  1402. // FORMATTING
  1403. function hFormat() {
  1404. return this.hours() % 12 || 12;
  1405. }
  1406. function kFormat() {
  1407. return this.hours() || 24;
  1408. }
  1409. addFormatToken('H', ['HH', 2], 0, 'hour');
  1410. addFormatToken('h', ['hh', 2], 0, hFormat);
  1411. addFormatToken('k', ['kk', 2], 0, kFormat);
  1412. addFormatToken('hmm', 0, 0, function () {
  1413. return '' + hFormat.apply(this) + zeroFill(this.minutes(), 2);
  1414. });
  1415. addFormatToken('hmmss', 0, 0, function () {
  1416. return '' + hFormat.apply(this) + zeroFill(this.minutes(), 2) +
  1417. zeroFill(this.seconds(), 2);
  1418. });
  1419. addFormatToken('Hmm', 0, 0, function () {
  1420. return '' + this.hours() + zeroFill(this.minutes(), 2);
  1421. });
  1422. addFormatToken('Hmmss', 0, 0, function () {
  1423. return '' + this.hours() + zeroFill(this.minutes(), 2) +
  1424. zeroFill(this.seconds(), 2);
  1425. });
  1426. function meridiem (token, lowercase) {
  1427. addFormatToken(token, 0, 0, function () {
  1428. return this.localeData().meridiem(this.hours(), this.minutes(), lowercase);
  1429. });
  1430. }
  1431. meridiem('a', true);
  1432. meridiem('A', false);
  1433. // ALIASES
  1434. addUnitAlias('hour', 'h');
  1435. // PRIORITY
  1436. addUnitPriority('hour', 13);
  1437. // PARSING
  1438. function matchMeridiem (isStrict, locale) {
  1439. return locale._meridiemParse;
  1440. }
  1441. addRegexToken('a', matchMeridiem);
  1442. addRegexToken('A', matchMeridiem);
  1443. addRegexToken('H', match1to2);
  1444. addRegexToken('h', match1to2);
  1445. addRegexToken('k', match1to2);
  1446. addRegexToken('HH', match1to2, match2);
  1447. addRegexToken('hh', match1to2, match2);
  1448. addRegexToken('kk', match1to2, match2);
  1449. addRegexToken('hmm', match3to4);
  1450. addRegexToken('hmmss', match5to6);
  1451. addRegexToken('Hmm', match3to4);
  1452. addRegexToken('Hmmss', match5to6);
  1453. addParseToken(['H', 'HH'], HOUR);
  1454. addParseToken(['k', 'kk'], function (input, array, config) {
  1455. var kInput = toInt(input);
  1456. array[HOUR] = kInput === 24 ? 0 : kInput;
  1457. });
  1458. addParseToken(['a', 'A'], function (input, array, config) {
  1459. config._isPm = config._locale.isPM(input);
  1460. config._meridiem = input;
  1461. });
  1462. addParseToken(['h', 'hh'], function (input, array, config) {
  1463. array[HOUR] = toInt(input);
  1464. getParsingFlags(config).bigHour = true;
  1465. });
  1466. addParseToken('hmm', function (input, array, config) {
  1467. var pos = input.length - 2;
  1468. array[HOUR] = toInt(input.substr(0, pos));
  1469. array[MINUTE] = toInt(input.substr(pos));
  1470. getParsingFlags(config).bigHour = true;
  1471. });
  1472. addParseToken('hmmss', function (input, array, config) {
  1473. var pos1 = input.length - 4;
  1474. var pos2 = input.length - 2;
  1475. array[HOUR] = toInt(input.substr(0, pos1));
  1476. array[MINUTE] = toInt(input.substr(pos1, 2));
  1477. array[SECOND] = toInt(input.substr(pos2));
  1478. getParsingFlags(config).bigHour = true;
  1479. });
  1480. addParseToken('Hmm', function (input, array, config) {
  1481. var pos = input.length - 2;
  1482. array[HOUR] = toInt(input.substr(0, pos));
  1483. array[MINUTE] = toInt(input.substr(pos));
  1484. });
  1485. addParseToken('Hmmss', function (input, array, config) {
  1486. var pos1 = input.length - 4;
  1487. var pos2 = input.length - 2;
  1488. array[HOUR] = toInt(input.substr(0, pos1));
  1489. array[MINUTE] = toInt(input.substr(pos1, 2));
  1490. array[SECOND] = toInt(input.substr(pos2));
  1491. });
  1492. // LOCALES
  1493. function localeIsPM (input) {
  1494. // IE8 Quirks Mode & IE7 Standards Mode do not allow accessing strings like arrays
  1495. // Using charAt should be more compatible.
  1496. return ((input + '').toLowerCase().charAt(0) === 'p');
  1497. }
  1498. var defaultLocaleMeridiemParse = /[ap]\.?m?\.?/i;
  1499. function localeMeridiem (hours, minutes, isLower) {
  1500. if (hours > 11) {
  1501. return isLower ? 'pm' : 'PM';
  1502. } else {
  1503. return isLower ? 'am' : 'AM';
  1504. }
  1505. }
  1506. // MOMENTS
  1507. // Setting the hour should keep the time, because the user explicitly
  1508. // specified which hour he wants. So trying to maintain the same hour (in
  1509. // a new timezone) makes sense. Adding/subtracting hours does not follow
  1510. // this rule.
  1511. var getSetHour = makeGetSet('Hours', true);
  1512. // months
  1513. // week
  1514. // weekdays
  1515. // meridiem
  1516. var baseConfig = {
  1517. calendar: defaultCalendar,
  1518. longDateFormat: defaultLongDateFormat,
  1519. invalidDate: defaultInvalidDate,
  1520. ordinal: defaultOrdinal,
  1521. dayOfMonthOrdinalParse: defaultDayOfMonthOrdinalParse,
  1522. relativeTime: defaultRelativeTime,
  1523. months: defaultLocaleMonths,
  1524. monthsShort: defaultLocaleMonthsShort,
  1525. week: defaultLocaleWeek,
  1526. weekdays: defaultLocaleWeekdays,
  1527. weekdaysMin: defaultLocaleWeekdaysMin,
  1528. weekdaysShort: defaultLocaleWeekdaysShort,
  1529. meridiemParse: defaultLocaleMeridiemParse
  1530. };
  1531. // internal storage for locale config files
  1532. var locales = {};
  1533. var localeFamilies = {};
  1534. var globalLocale;
  1535. function normalizeLocale(key) {
  1536. return key ? key.toLowerCase().replace('_', '-') : key;
  1537. }
  1538. // pick the locale from the array
  1539. // try ['en-au', 'en-gb'] as 'en-au', 'en-gb', 'en', as in move through the list trying each
  1540. // substring from most specific to least, but move to the next array item if it's a more specific variant than the current root
  1541. function chooseLocale(names) {
  1542. var i = 0, j, next, locale, split;
  1543. while (i < names.length) {
  1544. split = normalizeLocale(names[i]).split('-');
  1545. j = split.length;
  1546. next = normalizeLocale(names[i + 1]);
  1547. next = next ? next.split('-') : null;
  1548. while (j > 0) {
  1549. locale = loadLocale(split.slice(0, j).join('-'));
  1550. if (locale) {
  1551. return locale;
  1552. }
  1553. if (next && next.length >= j && compareArrays(split, next, true) >= j - 1) {
  1554. //the next array item is better than a shallower substring of this one
  1555. break;
  1556. }
  1557. j--;
  1558. }
  1559. i++;
  1560. }
  1561. return null;
  1562. }
  1563. function loadLocale(name) {
  1564. var oldLocale = null;
  1565. // TODO: Find a better way to register and load all the locales in Node
  1566. if (!locales[name] && (typeof module !== 'undefined') &&
  1567. module && module.exports) {
  1568. try {
  1569. oldLocale = globalLocale._abbr;
  1570. var aliasedRequire = require;
  1571. aliasedRequire('./locale/' + name);
  1572. getSetGlobalLocale(oldLocale);
  1573. } catch (e) {}
  1574. }
  1575. return locales[name];
  1576. }
  1577. // This function will load locale and then set the global locale. If
  1578. // no arguments are passed in, it will simply return the current global
  1579. // locale key.
  1580. function getSetGlobalLocale (key, values) {
  1581. var data;
  1582. if (key) {
  1583. if (isUndefined(values)) {
  1584. data = getLocale(key);
  1585. }
  1586. else {
  1587. data = defineLocale(key, values);
  1588. }
  1589. if (data) {
  1590. // moment.duration._locale = moment._locale = data;
  1591. globalLocale = data;
  1592. }
  1593. }
  1594. return globalLocale._abbr;
  1595. }
  1596. function defineLocale (name, config) {
  1597. if (config !== null) {
  1598. var parentConfig = baseConfig;
  1599. config.abbr = name;
  1600. if (locales[name] != null) {
  1601. deprecateSimple('defineLocaleOverride',
  1602. 'use moment.updateLocale(localeName, config) to change ' +
  1603. 'an existing locale. moment.defineLocale(localeName, ' +
  1604. 'config) should only be used for creating a new locale ' +
  1605. 'See http://momentjs.com/guides/#/warnings/define-locale/ for more info.');
  1606. parentConfig = locales[name]._config;
  1607. } else if (config.parentLocale != null) {
  1608. if (locales[config.parentLocale] != null) {
  1609. parentConfig = locales[config.parentLocale]._config;
  1610. } else {
  1611. if (!localeFamilies[config.parentLocale]) {
  1612. localeFamilies[config.parentLocale] = [];
  1613. }
  1614. localeFamilies[config.parentLocale].push({
  1615. name: name,
  1616. config: config
  1617. });
  1618. return null;
  1619. }
  1620. }
  1621. locales[name] = new Locale(mergeConfigs(parentConfig, config));
  1622. if (localeFamilies[name]) {
  1623. localeFamilies[name].forEach(function (x) {
  1624. defineLocale(x.name, x.config);
  1625. });
  1626. }
  1627. // backwards compat for now: also set the locale
  1628. // make sure we set the locale AFTER all child locales have been
  1629. // created, so we won't end up with the child locale set.
  1630. getSetGlobalLocale(name);
  1631. return locales[name];
  1632. } else {
  1633. // useful for testing
  1634. delete locales[name];
  1635. return null;
  1636. }
  1637. }
  1638. function updateLocale(name, config) {
  1639. if (config != null) {
  1640. var locale, tmpLocale, parentConfig = baseConfig;
  1641. // MERGE
  1642. tmpLocale = loadLocale(name);
  1643. if (tmpLocale != null) {
  1644. parentConfig = tmpLocale._config;
  1645. }
  1646. config = mergeConfigs(parentConfig, config);
  1647. locale = new Locale(config);
  1648. locale.parentLocale = locales[name];
  1649. locales[name] = locale;
  1650. // backwards compat for now: also set the locale
  1651. getSetGlobalLocale(name);
  1652. } else {
  1653. // pass null for config to unupdate, useful for tests
  1654. if (locales[name] != null) {
  1655. if (locales[name].parentLocale != null) {
  1656. locales[name] = locales[name].parentLocale;
  1657. } else if (locales[name] != null) {
  1658. delete locales[name];
  1659. }
  1660. }
  1661. }
  1662. return locales[name];
  1663. }
  1664. // returns locale data
  1665. function getLocale (key) {
  1666. var locale;
  1667. if (key && key._locale && key._locale._abbr) {
  1668. key = key._locale._abbr;
  1669. }
  1670. if (!key) {
  1671. return globalLocale;
  1672. }
  1673. if (!isArray(key)) {
  1674. //short-circuit everything else
  1675. locale = loadLocale(key);
  1676. if (locale) {
  1677. return locale;
  1678. }
  1679. key = [key];
  1680. }
  1681. return chooseLocale(key);
  1682. }
  1683. function listLocales() {
  1684. return keys(locales);
  1685. }
  1686. function checkOverflow (m) {
  1687. var overflow;
  1688. var a = m._a;
  1689. if (a && getParsingFlags(m).overflow === -2) {
  1690. overflow =
  1691. a[MONTH] < 0 || a[MONTH] > 11 ? MONTH :
  1692. a[DATE] < 1 || a[DATE] > daysInMonth(a[YEAR], a[MONTH]) ? DATE :
  1693. a[HOUR] < 0 || a[HOUR] > 24 || (a[HOUR] === 24 && (a[MINUTE] !== 0 || a[SECOND] !== 0 || a[MILLISECOND] !== 0)) ? HOUR :
  1694. a[MINUTE] < 0 || a[MINUTE] > 59 ? MINUTE :
  1695. a[SECOND] < 0 || a[SECOND] > 59 ? SECOND :
  1696. a[MILLISECOND] < 0 || a[MILLISECOND] > 999 ? MILLISECOND :
  1697. -1;
  1698. if (getParsingFlags(m)._overflowDayOfYear && (overflow < YEAR || overflow > DATE)) {
  1699. overflow = DATE;
  1700. }
  1701. if (getParsingFlags(m)._overflowWeeks && overflow === -1) {
  1702. overflow = WEEK;
  1703. }
  1704. if (getParsingFlags(m)._overflowWeekday && overflow === -1) {
  1705. overflow = WEEKDAY;
  1706. }
  1707. getParsingFlags(m).overflow = overflow;
  1708. }
  1709. return m;
  1710. }
  1711. // Pick the first defined of two or three arguments.
  1712. function defaults(a, b, c) {
  1713. if (a != null) {
  1714. return a;
  1715. }
  1716. if (b != null) {
  1717. return b;
  1718. }
  1719. return c;
  1720. }
  1721. function currentDateArray(config) {
  1722. // hooks is actually the exported moment object
  1723. var nowValue = new Date(hooks.now());
  1724. if (config._useUTC) {
  1725. return [nowValue.getUTCFullYear(), nowValue.getUTCMonth(), nowValue.getUTCDate()];
  1726. }
  1727. return [nowValue.getFullYear(), nowValue.getMonth(), nowValue.getDate()];
  1728. }
  1729. // convert an array to a date.
  1730. // the array should mirror the parameters below
  1731. // note: all values past the year are optional and will default to the lowest possible value.
  1732. // [year, month, day , hour, minute, second, millisecond]
  1733. function configFromArray (config) {
  1734. var i, date, input = [], currentDate, expectedWeekday, yearToUse;
  1735. if (config._d) {
  1736. return;
  1737. }
  1738. currentDate = currentDateArray(config);
  1739. //compute day of the year from weeks and weekdays
  1740. if (config._w && config._a[DATE] == null && config._a[MONTH] == null) {
  1741. dayOfYearFromWeekInfo(config);
  1742. }
  1743. //if the day of the year is set, figure out what it is
  1744. if (config._dayOfYear != null) {
  1745. yearToUse = defaults(config._a[YEAR], currentDate[YEAR]);
  1746. if (config._dayOfYear > daysInYear(yearToUse) || config._dayOfYear === 0) {
  1747. getParsingFlags(config)._overflowDayOfYear = true;
  1748. }
  1749. date = createUTCDate(yearToUse, 0, config._dayOfYear);
  1750. config._a[MONTH] = date.getUTCMonth();
  1751. config._a[DATE] = date.getUTCDate();
  1752. }
  1753. // Default to current date.
  1754. // * if no year, month, day of month are given, default to today
  1755. // * if day of month is given, default month and year
  1756. // * if month is given, default only year
  1757. // * if year is given, don't default anything
  1758. for (i = 0; i < 3 && config._a[i] == null; ++i) {
  1759. config._a[i] = input[i] = currentDate[i];
  1760. }
  1761. // Zero out whatever was not defaulted, including time
  1762. for (; i < 7; i++) {
  1763. config._a[i] = input[i] = (config._a[i] == null) ? (i === 2 ? 1 : 0) : config._a[i];
  1764. }
  1765. // Check for 24:00:00.000
  1766. if (config._a[HOUR] === 24 &&
  1767. config._a[MINUTE] === 0 &&
  1768. config._a[SECOND] === 0 &&
  1769. config._a[MILLISECOND] === 0) {
  1770. config._nextDay = true;
  1771. config._a[HOUR] = 0;
  1772. }
  1773. config._d = (config._useUTC ? createUTCDate : createDate).apply(null, input);
  1774. expectedWeekday = config._useUTC ? config._d.getUTCDay() : config._d.getDay();
  1775. // Apply timezone offset from input. The actual utcOffset can be changed
  1776. // with parseZone.
  1777. if (config._tzm != null) {
  1778. config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm);
  1779. }
  1780. if (config._nextDay) {
  1781. config._a[HOUR] = 24;
  1782. }
  1783. // check for mismatching day of week
  1784. if (config._w && typeof config._w.d !== 'undefined' && config._w.d !== expectedWeekday) {
  1785. getParsingFlags(config).weekdayMismatch = true;
  1786. }
  1787. }
  1788. function dayOfYearFromWeekInfo(config) {
  1789. var w, weekYear, week, weekday, dow, doy, temp, weekdayOverflow;
  1790. w = config._w;
  1791. if (w.GG != null || w.W != null || w.E != null) {
  1792. dow = 1;
  1793. doy = 4;
  1794. // TODO: We need to take the current isoWeekYear, but that depends on
  1795. // how we interpret now (local, utc, fixed offset). So create
  1796. // a now version of current config (take local/utc/offset flags, and
  1797. // create now).
  1798. weekYear = defaults(w.GG, config._a[YEAR], weekOfYear(createLocal(), 1, 4).year);
  1799. week = defaults(w.W, 1);
  1800. weekday = defaults(w.E, 1);
  1801. if (weekday < 1 || weekday > 7) {
  1802. weekdayOverflow = true;
  1803. }
  1804. } else {
  1805. dow = config._locale._week.dow;
  1806. doy = config._locale._week.doy;
  1807. var curWeek = weekOfYear(createLocal(), dow, doy);
  1808. weekYear = defaults(w.gg, config._a[YEAR], curWeek.year);
  1809. // Default to current week.
  1810. week = defaults(w.w, curWeek.week);
  1811. if (w.d != null) {
  1812. // weekday -- low day numbers are considered next week
  1813. weekday = w.d;
  1814. if (weekday < 0 || weekday > 6) {
  1815. weekdayOverflow = true;
  1816. }
  1817. } else if (w.e != null) {
  1818. // local weekday -- counting starts from begining of week
  1819. weekday = w.e + dow;
  1820. if (w.e < 0 || w.e > 6) {
  1821. weekdayOverflow = true;
  1822. }
  1823. } else {
  1824. // default to begining of week
  1825. weekday = dow;
  1826. }
  1827. }
  1828. if (week < 1 || week > weeksInYear(weekYear, dow, doy)) {
  1829. getParsingFlags(config)._overflowWeeks = true;
  1830. } else if (weekdayOverflow != null) {
  1831. getParsingFlags(config)._overflowWeekday = true;
  1832. } else {
  1833. temp = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy);
  1834. config._a[YEAR] = temp.year;
  1835. config._dayOfYear = temp.dayOfYear;
  1836. }
  1837. }
  1838. // iso 8601 regex
  1839. // 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)
  1840. 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)?)?$/;
  1841. var 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)?)?$/;
  1842. var tzRegex = /Z|[+-]\d\d(?::?\d\d)?/;
  1843. var isoDates = [
  1844. ['YYYYYY-MM-DD', /[+-]\d{6}-\d\d-\d\d/],
  1845. ['YYYY-MM-DD', /\d{4}-\d\d-\d\d/],
  1846. ['GGGG-[W]WW-E', /\d{4}-W\d\d-\d/],
  1847. ['GGGG-[W]WW', /\d{4}-W\d\d/, false],
  1848. ['YYYY-DDD', /\d{4}-\d{3}/],
  1849. ['YYYY-MM', /\d{4}-\d\d/, false],
  1850. ['YYYYYYMMDD', /[+-]\d{10}/],
  1851. ['YYYYMMDD', /\d{8}/],
  1852. // YYYYMM is NOT allowed by the standard
  1853. ['GGGG[W]WWE', /\d{4}W\d{3}/],
  1854. ['GGGG[W]WW', /\d{4}W\d{2}/, false],
  1855. ['YYYYDDD', /\d{7}/]
  1856. ];
  1857. // iso time formats and regexes
  1858. var isoTimes = [
  1859. ['HH:mm:ss.SSSS', /\d\d:\d\d:\d\d\.\d+/],
  1860. ['HH:mm:ss,SSSS', /\d\d:\d\d:\d\d,\d+/],
  1861. ['HH:mm:ss', /\d\d:\d\d:\d\d/],
  1862. ['HH:mm', /\d\d:\d\d/],
  1863. ['HHmmss.SSSS', /\d\d\d\d\d\d\.\d+/],
  1864. ['HHmmss,SSSS', /\d\d\d\d\d\d,\d+/],
  1865. ['HHmmss', /\d\d\d\d\d\d/],
  1866. ['HHmm', /\d\d\d\d/],
  1867. ['HH', /\d\d/]
  1868. ];
  1869. var aspNetJsonRegex = /^\/?Date\((\-?\d+)/i;
  1870. // date from iso format
  1871. function configFromISO(config) {
  1872. var i, l,
  1873. string = config._i,
  1874. match = extendedIsoRegex.exec(string) || basicIsoRegex.exec(string),
  1875. allowTime, dateFormat, timeFormat, tzFormat;
  1876. if (match) {
  1877. getParsingFlags(config).iso = true;
  1878. for (i = 0, l = isoDates.length; i < l; i++) {
  1879. if (isoDates[i][1].exec(match[1])) {
  1880. dateFormat = isoDates[i][0];
  1881. allowTime = isoDates[i][2] !== false;
  1882. break;
  1883. }
  1884. }
  1885. if (dateFormat == null) {
  1886. config._isValid = false;
  1887. return;
  1888. }
  1889. if (match[3]) {
  1890. for (i = 0, l = isoTimes.length; i < l; i++) {
  1891. if (isoTimes[i][1].exec(match[3])) {
  1892. // match[2] should be 'T' or space
  1893. timeFormat = (match[2] || ' ') + isoTimes[i][0];
  1894. break;
  1895. }
  1896. }
  1897. if (timeFormat == null) {
  1898. config._isValid = false;
  1899. return;
  1900. }
  1901. }
  1902. if (!allowTime && timeFormat != null) {
  1903. config._isValid = false;
  1904. return;
  1905. }
  1906. if (match[4]) {
  1907. if (tzRegex.exec(match[4])) {
  1908. tzFormat = 'Z';
  1909. } else {
  1910. config._isValid = false;
  1911. return;
  1912. }
  1913. }
  1914. config._f = dateFormat + (timeFormat || '') + (tzFormat || '');
  1915. configFromStringAndFormat(config);
  1916. } else {
  1917. config._isValid = false;
  1918. }
  1919. }
  1920. // RFC 2822 regex: For details see https://tools.ietf.org/html/rfc2822#section-3.3
  1921. var 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}))$/;
  1922. function extractFromRFC2822Strings(yearStr, monthStr, dayStr, hourStr, minuteStr, secondStr) {
  1923. var result = [
  1924. untruncateYear(yearStr),
  1925. defaultLocaleMonthsShort.indexOf(monthStr),
  1926. parseInt(dayStr, 10),
  1927. parseInt(hourStr, 10),
  1928. parseInt(minuteStr, 10)
  1929. ];
  1930. if (secondStr) {
  1931. result.push(parseInt(secondStr, 10));
  1932. }
  1933. return result;
  1934. }
  1935. function untruncateYear(yearStr) {
  1936. var year = parseInt(yearStr, 10);
  1937. if (year <= 49) {
  1938. return 2000 + year;
  1939. } else if (year <= 999) {
  1940. return 1900 + year;
  1941. }
  1942. return year;
  1943. }
  1944. function preprocessRFC2822(s) {
  1945. // Remove comments and folding whitespace and replace multiple-spaces with a single space
  1946. return s.replace(/\([^)]*\)|[\n\t]/g, ' ').replace(/(\s\s+)/g, ' ').trim();
  1947. }
  1948. function checkWeekday(weekdayStr, parsedInput, config) {
  1949. if (weekdayStr) {
  1950. // TODO: Replace the vanilla JS Date object with an indepentent day-of-week check.
  1951. var weekdayProvided = defaultLocaleWeekdaysShort.indexOf(weekdayStr),
  1952. weekdayActual = new Date(parsedInput[0], parsedInput[1], parsedInput[2]).getDay();
  1953. if (weekdayProvided !== weekdayActual) {
  1954. getParsingFlags(config).weekdayMismatch = true;
  1955. config._isValid = false;
  1956. return false;
  1957. }
  1958. }
  1959. return true;
  1960. }
  1961. var obsOffsets = {
  1962. UT: 0,
  1963. GMT: 0,
  1964. EDT: -4 * 60,
  1965. EST: -5 * 60,
  1966. CDT: -5 * 60,
  1967. CST: -6 * 60,
  1968. MDT: -6 * 60,
  1969. MST: -7 * 60,
  1970. PDT: -7 * 60,
  1971. PST: -8 * 60
  1972. };
  1973. function calculateOffset(obsOffset, militaryOffset, numOffset) {
  1974. if (obsOffset) {
  1975. return obsOffsets[obsOffset];
  1976. } else if (militaryOffset) {
  1977. // the only allowed military tz is Z
  1978. return 0;
  1979. } else {
  1980. var hm = parseInt(numOffset, 10);
  1981. var m = hm % 100, h = (hm - m) / 100;
  1982. return h * 60 + m;
  1983. }
  1984. }
  1985. // date and time from ref 2822 format
  1986. function configFromRFC2822(config) {
  1987. var match = rfc2822.exec(preprocessRFC2822(config._i));
  1988. if (match) {
  1989. var parsedArray = extractFromRFC2822Strings(match[4], match[3], match[2], match[5], match[6], match[7]);
  1990. if (!checkWeekday(match[1], parsedArray, config)) {
  1991. return;
  1992. }
  1993. config._a = parsedArray;
  1994. config._tzm = calculateOffset(match[8], match[9], match[10]);
  1995. config._d = createUTCDate.apply(null, config._a);
  1996. config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm);
  1997. getParsingFlags(config).rfc2822 = true;
  1998. } else {
  1999. config._isValid = false;
  2000. }
  2001. }
  2002. // date from iso format or fallback
  2003. function configFromString(config) {
  2004. var matched = aspNetJsonRegex.exec(config._i);
  2005. if (matched !== null) {
  2006. config._d = new Date(+matched[1]);
  2007. return;
  2008. }
  2009. configFromISO(config);
  2010. if (config._isValid === false) {
  2011. delete config._isValid;
  2012. } else {
  2013. return;
  2014. }
  2015. configFromRFC2822(config);
  2016. if (config._isValid === false) {
  2017. delete config._isValid;
  2018. } else {
  2019. return;
  2020. }
  2021. // Final attempt, use Input Fallback
  2022. hooks.createFromInputFallback(config);
  2023. }
  2024. hooks.createFromInputFallback = deprecate(
  2025. 'value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), ' +
  2026. 'which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are ' +
  2027. 'discouraged and will be removed in an upcoming major release. Please refer to ' +
  2028. 'http://momentjs.com/guides/#/warnings/js-date/ for more info.',
  2029. function (config) {
  2030. config._d = new Date(config._i + (config._useUTC ? ' UTC' : ''));
  2031. }
  2032. );
  2033. // constant that refers to the ISO standard
  2034. hooks.ISO_8601 = function () {};
  2035. // constant that refers to the RFC 2822 form
  2036. hooks.RFC_2822 = function () {};
  2037. // date from string and format string
  2038. function configFromStringAndFormat(config) {
  2039. // TODO: Move this to another part of the creation flow to prevent circular deps
  2040. if (config._f === hooks.ISO_8601) {
  2041. configFromISO(config);
  2042. return;
  2043. }
  2044. if (config._f === hooks.RFC_2822) {
  2045. configFromRFC2822(config);
  2046. return;
  2047. }
  2048. config._a = [];
  2049. getParsingFlags(config).empty = true;
  2050. // This array is used to make a Date, either with `new Date` or `Date.UTC`
  2051. var string = '' + config._i,
  2052. i, parsedInput, tokens, token, skipped,
  2053. stringLength = string.length,
  2054. totalParsedInputLength = 0;
  2055. tokens = expandFormat(config._f, config._locale).match(formattingTokens) || [];
  2056. for (i = 0; i < tokens.length; i++) {
  2057. token = tokens[i];
  2058. parsedInput = (string.match(getParseRegexForToken(token, config)) || [])[0];
  2059. // console.log('token', token, 'parsedInput', parsedInput,
  2060. // 'regex', getParseRegexForToken(token, config));
  2061. if (parsedInput) {
  2062. skipped = string.substr(0, string.indexOf(parsedInput));
  2063. if (skipped.length > 0) {
  2064. getParsingFlags(config).unusedInput.push(skipped);
  2065. }
  2066. string = string.slice(string.indexOf(parsedInput) + parsedInput.length);
  2067. totalParsedInputLength += parsedInput.length;
  2068. }
  2069. // don't parse if it's not a known token
  2070. if (formatTokenFunctions[token]) {
  2071. if (parsedInput) {
  2072. getParsingFlags(config).empty = false;
  2073. }
  2074. else {
  2075. getParsingFlags(config).unusedTokens.push(token);
  2076. }
  2077. addTimeToArrayFromToken(token, parsedInput, config);
  2078. }
  2079. else if (config._strict && !parsedInput) {
  2080. getParsingFlags(config).unusedTokens.push(token);
  2081. }
  2082. }
  2083. // add remaining unparsed input length to the string
  2084. getParsingFlags(config).charsLeftOver = stringLength - totalParsedInputLength;
  2085. if (string.length > 0) {
  2086. getParsingFlags(config).unusedInput.push(string);
  2087. }
  2088. // clear _12h flag if hour is <= 12
  2089. if (config._a[HOUR] <= 12 &&
  2090. getParsingFlags(config).bigHour === true &&
  2091. config._a[HOUR] > 0) {
  2092. getParsingFlags(config).bigHour = undefined;
  2093. }
  2094. getParsingFlags(config).parsedDateParts = config._a.slice(0);
  2095. getParsingFlags(config).meridiem = config._meridiem;
  2096. // handle meridiem
  2097. config._a[HOUR] = meridiemFixWrap(config._locale, config._a[HOUR], config._meridiem);
  2098. configFromArray(config);
  2099. checkOverflow(config);
  2100. }
  2101. function meridiemFixWrap (locale, hour, meridiem) {
  2102. var isPm;
  2103. if (meridiem == null) {
  2104. // nothing to do
  2105. return hour;
  2106. }
  2107. if (locale.meridiemHour != null) {
  2108. return locale.meridiemHour(hour, meridiem);
  2109. } else if (locale.isPM != null) {
  2110. // Fallback
  2111. isPm = locale.isPM(meridiem);
  2112. if (isPm && hour < 12) {
  2113. hour += 12;
  2114. }
  2115. if (!isPm && hour === 12) {
  2116. hour = 0;
  2117. }
  2118. return hour;
  2119. } else {
  2120. // this is not supposed to happen
  2121. return hour;
  2122. }
  2123. }
  2124. // date from string and array of format strings
  2125. function configFromStringAndArray(config) {
  2126. var tempConfig,
  2127. bestMoment,
  2128. scoreToBeat,
  2129. i,
  2130. currentScore;
  2131. if (config._f.length === 0) {
  2132. getParsingFlags(config).invalidFormat = true;
  2133. config._d = new Date(NaN);
  2134. return;
  2135. }
  2136. for (i = 0; i < config._f.length; i++) {
  2137. currentScore = 0;
  2138. tempConfig = copyConfig({}, config);
  2139. if (config._useUTC != null) {
  2140. tempConfig._useUTC = config._useUTC;
  2141. }
  2142. tempConfig._f = config._f[i];
  2143. configFromStringAndFormat(tempConfig);
  2144. if (!isValid(tempConfig)) {
  2145. continue;
  2146. }
  2147. // if there is any input that was not parsed add a penalty for that format
  2148. currentScore += getParsingFlags(tempConfig).charsLeftOver;
  2149. //or tokens
  2150. currentScore += getParsingFlags(tempConfig).unusedTokens.length * 10;
  2151. getParsingFlags(tempConfig).score = currentScore;
  2152. if (scoreToBeat == null || currentScore < scoreToBeat) {
  2153. scoreToBeat = currentScore;
  2154. bestMoment = tempConfig;
  2155. }
  2156. }
  2157. extend(config, bestMoment || tempConfig);
  2158. }
  2159. function configFromObject(config) {
  2160. if (config._d) {
  2161. return;
  2162. }
  2163. var i = normalizeObjectUnits(config._i);
  2164. config._a = map([i.year, i.month, i.day || i.date, i.hour, i.minute, i.second, i.millisecond], function (obj) {
  2165. return obj && parseInt(obj, 10);
  2166. });
  2167. configFromArray(config);
  2168. }
  2169. function createFromConfig (config) {
  2170. var res = new Moment(checkOverflow(prepareConfig(config)));
  2171. if (res._nextDay) {
  2172. // Adding is smart enough around DST
  2173. res.add(1, 'd');
  2174. res._nextDay = undefined;
  2175. }
  2176. return res;
  2177. }
  2178. function prepareConfig (config) {
  2179. var input = config._i,
  2180. format = config._f;
  2181. config._locale = config._locale || getLocale(config._l);
  2182. if (input === null || (format === undefined && input === '')) {
  2183. return createInvalid({nullInput: true});
  2184. }
  2185. if (typeof input === 'string') {
  2186. config._i = input = config._locale.preparse(input);
  2187. }
  2188. if (isMoment(input)) {
  2189. return new Moment(checkOverflow(input));
  2190. } else if (isDate(input)) {
  2191. config._d = input;
  2192. } else if (isArray(format)) {
  2193. configFromStringAndArray(config);
  2194. } else if (format) {
  2195. configFromStringAndFormat(config);
  2196. } else {
  2197. configFromInput(config);
  2198. }
  2199. if (!isValid(config)) {
  2200. config._d = null;
  2201. }
  2202. return config;
  2203. }
  2204. function configFromInput(config) {
  2205. var input = config._i;
  2206. if (isUndefined(input)) {
  2207. config._d = new Date(hooks.now());
  2208. } else if (isDate(input)) {
  2209. config._d = new Date(input.valueOf());
  2210. } else if (typeof input === 'string') {
  2211. configFromString(config);
  2212. } else if (isArray(input)) {
  2213. config._a = map(input.slice(0), function (obj) {
  2214. return parseInt(obj, 10);
  2215. });
  2216. configFromArray(config);
  2217. } else if (isObject(input)) {
  2218. configFromObject(config);
  2219. } else if (isNumber(input)) {
  2220. // from milliseconds
  2221. config._d = new Date(input);
  2222. } else {
  2223. hooks.createFromInputFallback(config);
  2224. }
  2225. }
  2226. function createLocalOrUTC (input, format, locale, strict, isUTC) {
  2227. var c = {};
  2228. if (locale === true || locale === false) {
  2229. strict = locale;
  2230. locale = undefined;
  2231. }
  2232. if ((isObject(input) && isObjectEmpty(input)) ||
  2233. (isArray(input) && input.length === 0)) {
  2234. input = undefined;
  2235. }
  2236. // object construction must be done this way.
  2237. // https://github.com/moment/moment/issues/1423
  2238. c._isAMomentObject = true;
  2239. c._useUTC = c._isUTC = isUTC;
  2240. c._l = locale;
  2241. c._i = input;
  2242. c._f = format;
  2243. c._strict = strict;
  2244. return createFromConfig(c);
  2245. }
  2246. function createLocal (input, format, locale, strict) {
  2247. return createLocalOrUTC(input, format, locale, strict, false);
  2248. }
  2249. var prototypeMin = deprecate(
  2250. 'moment().min is deprecated, use moment.max instead. http://momentjs.com/guides/#/warnings/min-max/',
  2251. function () {
  2252. var other = createLocal.apply(null, arguments);
  2253. if (this.isValid() && other.isValid()) {
  2254. return other < this ? this : other;
  2255. } else {
  2256. return createInvalid();
  2257. }
  2258. }
  2259. );
  2260. var prototypeMax = deprecate(
  2261. 'moment().max is deprecated, use moment.min instead. http://momentjs.com/guides/#/warnings/min-max/',
  2262. function () {
  2263. var other = createLocal.apply(null, arguments);
  2264. if (this.isValid() && other.isValid()) {
  2265. return other > this ? this : other;
  2266. } else {
  2267. return createInvalid();
  2268. }
  2269. }
  2270. );
  2271. // Pick a moment m from moments so that m[fn](other) is true for all
  2272. // other. This relies on the function fn to be transitive.
  2273. //
  2274. // moments should either be an array of moment objects or an array, whose
  2275. // first element is an array of moment objects.
  2276. function pickBy(fn, moments) {
  2277. var res, i;
  2278. if (moments.length === 1 && isArray(moments[0])) {
  2279. moments = moments[0];
  2280. }
  2281. if (!moments.length) {
  2282. return createLocal();
  2283. }
  2284. res = moments[0];
  2285. for (i = 1; i < moments.length; ++i) {
  2286. if (!moments[i].isValid() || moments[i][fn](res)) {
  2287. res = moments[i];
  2288. }
  2289. }
  2290. return res;
  2291. }
  2292. // TODO: Use [].sort instead?
  2293. function min () {
  2294. var args = [].slice.call(arguments, 0);
  2295. return pickBy('isBefore', args);
  2296. }
  2297. function max () {
  2298. var args = [].slice.call(arguments, 0);
  2299. return pickBy('isAfter', args);
  2300. }
  2301. var now = function () {
  2302. return Date.now ? Date.now() : +(new Date());
  2303. };
  2304. var ordering = ['year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', 'millisecond'];
  2305. function isDurationValid(m) {
  2306. for (var key in m) {
  2307. if (!(indexOf.call(ordering, key) !== -1 && (m[key] == null || !isNaN(m[key])))) {
  2308. return false;
  2309. }
  2310. }
  2311. var unitHasDecimal = false;
  2312. for (var i = 0; i < ordering.length; ++i) {
  2313. if (m[ordering[i]]) {
  2314. if (unitHasDecimal) {
  2315. return false; // only allow non-integers for smallest unit
  2316. }
  2317. if (parseFloat(m[ordering[i]]) !== toInt(m[ordering[i]])) {
  2318. unitHasDecimal = true;
  2319. }
  2320. }
  2321. }
  2322. return true;
  2323. }
  2324. function isValid$1() {
  2325. return this._isValid;
  2326. }
  2327. function createInvalid$1() {
  2328. return createDuration(NaN);
  2329. }
  2330. function Duration (duration) {
  2331. var normalizedInput = normalizeObjectUnits(duration),
  2332. years = normalizedInput.year || 0,
  2333. quarters = normalizedInput.quarter || 0,
  2334. months = normalizedInput.month || 0,
  2335. weeks = normalizedInput.week || 0,
  2336. days = normalizedInput.day || 0,
  2337. hours = normalizedInput.hour || 0,
  2338. minutes = normalizedInput.minute || 0,
  2339. seconds = normalizedInput.second || 0,
  2340. milliseconds = normalizedInput.millisecond || 0;
  2341. this._isValid = isDurationValid(normalizedInput);
  2342. // representation for dateAddRemove
  2343. this._milliseconds = +milliseconds +
  2344. seconds * 1e3 + // 1000
  2345. minutes * 6e4 + // 1000 * 60
  2346. hours * 1000 * 60 * 60; //using 1000 * 60 * 60 instead of 36e5 to avoid floating point rounding errors https://github.com/moment/moment/issues/2978
  2347. // Because of dateAddRemove treats 24 hours as different from a
  2348. // day when working around DST, we need to store them separately
  2349. this._days = +days +
  2350. weeks * 7;
  2351. // It is impossible to translate months into days without knowing
  2352. // which months you are are talking about, so we have to store
  2353. // it separately.
  2354. this._months = +months +
  2355. quarters * 3 +
  2356. years * 12;
  2357. this._data = {};
  2358. this._locale = getLocale();
  2359. this._bubble();
  2360. }
  2361. function isDuration (obj) {
  2362. return obj instanceof Duration;
  2363. }
  2364. function absRound (number) {
  2365. if (number < 0) {
  2366. return Math.round(-1 * number) * -1;
  2367. } else {
  2368. return Math.round(number);
  2369. }
  2370. }
  2371. // FORMATTING
  2372. function offset (token, separator) {
  2373. addFormatToken(token, 0, 0, function () {
  2374. var offset = this.utcOffset();
  2375. var sign = '+';
  2376. if (offset < 0) {
  2377. offset = -offset;
  2378. sign = '-';
  2379. }
  2380. return sign + zeroFill(~~(offset / 60), 2) + separator + zeroFill(~~(offset) % 60, 2);
  2381. });
  2382. }
  2383. offset('Z', ':');
  2384. offset('ZZ', '');
  2385. // PARSING
  2386. addRegexToken('Z', matchShortOffset);
  2387. addRegexToken('ZZ', matchShortOffset);
  2388. addParseToken(['Z', 'ZZ'], function (input, array, config) {
  2389. config._useUTC = true;
  2390. config._tzm = offsetFromString(matchShortOffset, input);
  2391. });
  2392. // HELPERS
  2393. // timezone chunker
  2394. // '+10:00' > ['10', '00']
  2395. // '-1530' > ['-15', '30']
  2396. var chunkOffset = /([\+\-]|\d\d)/gi;
  2397. function offsetFromString(matcher, string) {
  2398. var matches = (string || '').match(matcher);
  2399. if (matches === null) {
  2400. return null;
  2401. }
  2402. var chunk = matches[matches.length - 1] || [];
  2403. var parts = (chunk + '').match(chunkOffset) || ['-', 0, 0];
  2404. var minutes = +(parts[1] * 60) + toInt(parts[2]);
  2405. return minutes === 0 ?
  2406. 0 :
  2407. parts[0] === '+' ? minutes : -minutes;
  2408. }
  2409. // Return a moment from input, that is local/utc/zone equivalent to model.
  2410. function cloneWithOffset(input, model) {
  2411. var res, diff;
  2412. if (model._isUTC) {
  2413. res = model.clone();
  2414. diff = (isMoment(input) || isDate(input) ? input.valueOf() : createLocal(input).valueOf()) - res.valueOf();
  2415. // Use low-level api, because this fn is low-level api.
  2416. res._d.setTime(res._d.valueOf() + diff);
  2417. hooks.updateOffset(res, false);
  2418. return res;
  2419. } else {
  2420. return createLocal(input).local();
  2421. }
  2422. }
  2423. function getDateOffset (m) {
  2424. // On Firefox.24 Date#getTimezoneOffset returns a floating point.
  2425. // https://github.com/moment/moment/pull/1871
  2426. return -Math.round(m._d.getTimezoneOffset() / 15) * 15;
  2427. }
  2428. // HOOKS
  2429. // This function will be called whenever a moment is mutated.
  2430. // It is intended to keep the offset in sync with the timezone.
  2431. hooks.updateOffset = function () {};
  2432. // MOMENTS
  2433. // keepLocalTime = true means only change the timezone, without
  2434. // affecting the local hour. So 5:31:26 +0300 --[utcOffset(2, true)]-->
  2435. // 5:31:26 +0200 It is possible that 5:31:26 doesn't exist with offset
  2436. // +0200, so we adjust the time as needed, to be valid.
  2437. //
  2438. // Keeping the time actually adds/subtracts (one hour)
  2439. // from the actual represented time. That is why we call updateOffset
  2440. // a second time. In case it wants us to change the offset again
  2441. // _changeInProgress == true case, then we have to adjust, because
  2442. // there is no such time in the given timezone.
  2443. function getSetOffset (input, keepLocalTime, keepMinutes) {
  2444. var offset = this._offset || 0,
  2445. localAdjust;
  2446. if (!this.isValid()) {
  2447. return input != null ? this : NaN;
  2448. }
  2449. if (input != null) {
  2450. if (typeof input === 'string') {
  2451. input = offsetFromString(matchShortOffset, input);
  2452. if (input === null) {
  2453. return this;
  2454. }
  2455. } else if (Math.abs(input) < 16 && !keepMinutes) {
  2456. input = input * 60;
  2457. }
  2458. if (!this._isUTC && keepLocalTime) {
  2459. localAdjust = getDateOffset(this);
  2460. }
  2461. this._offset = input;
  2462. this._isUTC = true;
  2463. if (localAdjust != null) {
  2464. this.add(localAdjust, 'm');
  2465. }
  2466. if (offset !== input) {
  2467. if (!keepLocalTime || this._changeInProgress) {
  2468. addSubtract(this, createDuration(input - offset, 'm'), 1, false);
  2469. } else if (!this._changeInProgress) {
  2470. this._changeInProgress = true;
  2471. hooks.updateOffset(this, true);
  2472. this._changeInProgress = null;
  2473. }
  2474. }
  2475. return this;
  2476. } else {
  2477. return this._isUTC ? offset : getDateOffset(this);
  2478. }
  2479. }
  2480. function getSetZone (input, keepLocalTime) {
  2481. if (input != null) {
  2482. if (typeof input !== 'string') {
  2483. input = -input;
  2484. }
  2485. this.utcOffset(input, keepLocalTime);
  2486. return this;
  2487. } else {
  2488. return -this.utcOffset();
  2489. }
  2490. }
  2491. function setOffsetToUTC (keepLocalTime) {
  2492. return this.utcOffset(0, keepLocalTime);
  2493. }
  2494. function setOffsetToLocal (keepLocalTime) {
  2495. if (this._isUTC) {
  2496. this.utcOffset(0, keepLocalTime);
  2497. this._isUTC = false;
  2498. if (keepLocalTime) {
  2499. this.subtract(getDateOffset(this), 'm');
  2500. }
  2501. }
  2502. return this;
  2503. }
  2504. function setOffsetToParsedOffset () {
  2505. if (this._tzm != null) {
  2506. this.utcOffset(this._tzm, false, true);
  2507. } else if (typeof this._i === 'string') {
  2508. var tZone = offsetFromString(matchOffset, this._i);
  2509. if (tZone != null) {
  2510. this.utcOffset(tZone);
  2511. }
  2512. else {
  2513. this.utcOffset(0, true);
  2514. }
  2515. }
  2516. return this;
  2517. }
  2518. function hasAlignedHourOffset (input) {
  2519. if (!this.isValid()) {
  2520. return false;
  2521. }
  2522. input = input ? createLocal(input).utcOffset() : 0;
  2523. return (this.utcOffset() - input) % 60 === 0;
  2524. }
  2525. function isDaylightSavingTime () {
  2526. return (
  2527. this.utcOffset() > this.clone().month(0).utcOffset() ||
  2528. this.utcOffset() > this.clone().month(5).utcOffset()
  2529. );
  2530. }
  2531. function isDaylightSavingTimeShifted () {
  2532. if (!isUndefined(this._isDSTShifted)) {
  2533. return this._isDSTShifted;
  2534. }
  2535. var c = {};
  2536. copyConfig(c, this);
  2537. c = prepareConfig(c);
  2538. if (c._a) {
  2539. var other = c._isUTC ? createUTC(c._a) : createLocal(c._a);
  2540. this._isDSTShifted = this.isValid() &&
  2541. compareArrays(c._a, other.toArray()) > 0;
  2542. } else {
  2543. this._isDSTShifted = false;
  2544. }
  2545. return this._isDSTShifted;
  2546. }
  2547. function isLocal () {
  2548. return this.isValid() ? !this._isUTC : false;
  2549. }
  2550. function isUtcOffset () {
  2551. return this.isValid() ? this._isUTC : false;
  2552. }
  2553. function isUtc () {
  2554. return this.isValid() ? this._isUTC && this._offset === 0 : false;
  2555. }
  2556. // ASP.NET json date format regex
  2557. var aspNetRegex = /^(\-|\+)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)(\.\d*)?)?$/;
  2558. // from http://docs.closure-library.googlecode.com/git/closure_goog_date_date.js.source.html
  2559. // somewhat more in line with 4.4.3.2 2004 spec, but allows decimal anywhere
  2560. // and further modified to allow for strings containing both week and day
  2561. var isoRegex = /^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/;
  2562. function createDuration (input, key) {
  2563. var duration = input,
  2564. // matching against regexp is expensive, do it on demand
  2565. match = null,
  2566. sign,
  2567. ret,
  2568. diffRes;
  2569. if (isDuration(input)) {
  2570. duration = {
  2571. ms : input._milliseconds,
  2572. d : input._days,
  2573. M : input._months
  2574. };
  2575. } else if (isNumber(input)) {
  2576. duration = {};
  2577. if (key) {
  2578. duration[key] = input;
  2579. } else {
  2580. duration.milliseconds = input;
  2581. }
  2582. } else if (!!(match = aspNetRegex.exec(input))) {
  2583. sign = (match[1] === '-') ? -1 : 1;
  2584. duration = {
  2585. y : 0,
  2586. d : toInt(match[DATE]) * sign,
  2587. h : toInt(match[HOUR]) * sign,
  2588. m : toInt(match[MINUTE]) * sign,
  2589. s : toInt(match[SECOND]) * sign,
  2590. ms : toInt(absRound(match[MILLISECOND] * 1000)) * sign // the millisecond decimal point is included in the match
  2591. };
  2592. } else if (!!(match = isoRegex.exec(input))) {
  2593. sign = (match[1] === '-') ? -1 : (match[1] === '+') ? 1 : 1;
  2594. duration = {
  2595. y : parseIso(match[2], sign),
  2596. M : parseIso(match[3], sign),
  2597. w : parseIso(match[4], sign),
  2598. d : parseIso(match[5], sign),
  2599. h : parseIso(match[6], sign),
  2600. m : parseIso(match[7], sign),
  2601. s : parseIso(match[8], sign)
  2602. };
  2603. } else if (duration == null) {// checks for null or undefined
  2604. duration = {};
  2605. } else if (typeof duration === 'object' && ('from' in duration || 'to' in duration)) {
  2606. diffRes = momentsDifference(createLocal(duration.from), createLocal(duration.to));
  2607. duration = {};
  2608. duration.ms = diffRes.milliseconds;
  2609. duration.M = diffRes.months;
  2610. }
  2611. ret = new Duration(duration);
  2612. if (isDuration(input) && hasOwnProp(input, '_locale')) {
  2613. ret._locale = input._locale;
  2614. }
  2615. return ret;
  2616. }
  2617. createDuration.fn = Duration.prototype;
  2618. createDuration.invalid = createInvalid$1;
  2619. function parseIso (inp, sign) {
  2620. // We'd normally use ~~inp for this, but unfortunately it also
  2621. // converts floats to ints.
  2622. // inp may be undefined, so careful calling replace on it.
  2623. var res = inp && parseFloat(inp.replace(',', '.'));
  2624. // apply sign while we're at it
  2625. return (isNaN(res) ? 0 : res) * sign;
  2626. }
  2627. function positiveMomentsDifference(base, other) {
  2628. var res = {milliseconds: 0, months: 0};
  2629. res.months = other.month() - base.month() +
  2630. (other.year() - base.year()) * 12;
  2631. if (base.clone().add(res.months, 'M').isAfter(other)) {
  2632. --res.months;
  2633. }
  2634. res.milliseconds = +other - +(base.clone().add(res.months, 'M'));
  2635. return res;
  2636. }
  2637. function momentsDifference(base, other) {
  2638. var res;
  2639. if (!(base.isValid() && other.isValid())) {
  2640. return {milliseconds: 0, months: 0};
  2641. }
  2642. other = cloneWithOffset(other, base);
  2643. if (base.isBefore(other)) {
  2644. res = positiveMomentsDifference(base, other);
  2645. } else {
  2646. res = positiveMomentsDifference(other, base);
  2647. res.milliseconds = -res.milliseconds;
  2648. res.months = -res.months;
  2649. }
  2650. return res;
  2651. }
  2652. // TODO: remove 'name' arg after deprecation is removed
  2653. function createAdder(direction, name) {
  2654. return function (val, period) {
  2655. var dur, tmp;
  2656. //invert the arguments, but complain about it
  2657. if (period !== null && !isNaN(+period)) {
  2658. deprecateSimple(name, 'moment().' + name + '(period, number) is deprecated. Please use moment().' + name + '(number, period). ' +
  2659. 'See http://momentjs.com/guides/#/warnings/add-inverted-param/ for more info.');
  2660. tmp = val; val = period; period = tmp;
  2661. }
  2662. val = typeof val === 'string' ? +val : val;
  2663. dur = createDuration(val, period);
  2664. addSubtract(this, dur, direction);
  2665. return this;
  2666. };
  2667. }
  2668. function addSubtract (mom, duration, isAdding, updateOffset) {
  2669. var milliseconds = duration._milliseconds,
  2670. days = absRound(duration._days),
  2671. months = absRound(duration._months);
  2672. if (!mom.isValid()) {
  2673. // No op
  2674. return;
  2675. }
  2676. updateOffset = updateOffset == null ? true : updateOffset;
  2677. if (months) {
  2678. setMonth(mom, get(mom, 'Month') + months * isAdding);
  2679. }
  2680. if (days) {
  2681. set$1(mom, 'Date', get(mom, 'Date') + days * isAdding);
  2682. }
  2683. if (milliseconds) {
  2684. mom._d.setTime(mom._d.valueOf() + milliseconds * isAdding);
  2685. }
  2686. if (updateOffset) {
  2687. hooks.updateOffset(mom, days || months);
  2688. }
  2689. }
  2690. var add = createAdder(1, 'add');
  2691. var subtract = createAdder(-1, 'subtract');
  2692. function getCalendarFormat(myMoment, now) {
  2693. var diff = myMoment.diff(now, 'days', true);
  2694. return diff < -6 ? 'sameElse' :
  2695. diff < -1 ? 'lastWeek' :
  2696. diff < 0 ? 'lastDay' :
  2697. diff < 1 ? 'sameDay' :
  2698. diff < 2 ? 'nextDay' :
  2699. diff < 7 ? 'nextWeek' : 'sameElse';
  2700. }
  2701. function calendar$1 (time, formats) {
  2702. // We want to compare the start of today, vs this.
  2703. // Getting start-of-today depends on whether we're local/utc/offset or not.
  2704. var now = time || createLocal(),
  2705. sod = cloneWithOffset(now, this).startOf('day'),
  2706. format = hooks.calendarFormat(this, sod) || 'sameElse';
  2707. var output = formats && (isFunction(formats[format]) ? formats[format].call(this, now) : formats[format]);
  2708. return this.format(output || this.localeData().calendar(format, this, createLocal(now)));
  2709. }
  2710. function clone () {
  2711. return new Moment(this);
  2712. }
  2713. function isAfter (input, units) {
  2714. var localInput = isMoment(input) ? input : createLocal(input);
  2715. if (!(this.isValid() && localInput.isValid())) {
  2716. return false;
  2717. }
  2718. units = normalizeUnits(!isUndefined(units) ? units : 'millisecond');
  2719. if (units === 'millisecond') {
  2720. return this.valueOf() > localInput.valueOf();
  2721. } else {
  2722. return localInput.valueOf() < this.clone().startOf(units).valueOf();
  2723. }
  2724. }
  2725. function isBefore (input, units) {
  2726. var localInput = isMoment(input) ? input : createLocal(input);
  2727. if (!(this.isValid() && localInput.isValid())) {
  2728. return false;
  2729. }
  2730. units = normalizeUnits(!isUndefined(units) ? units : 'millisecond');
  2731. if (units === 'millisecond') {
  2732. return this.valueOf() < localInput.valueOf();
  2733. } else {
  2734. return this.clone().endOf(units).valueOf() < localInput.valueOf();
  2735. }
  2736. }
  2737. function isBetween (from, to, units, inclusivity) {
  2738. inclusivity = inclusivity || '()';
  2739. return (inclusivity[0] === '(' ? this.isAfter(from, units) : !this.isBefore(from, units)) &&
  2740. (inclusivity[1] === ')' ? this.isBefore(to, units) : !this.isAfter(to, units));
  2741. }
  2742. function isSame (input, units) {
  2743. var localInput = isMoment(input) ? input : createLocal(input),
  2744. inputMs;
  2745. if (!(this.isValid() && localInput.isValid())) {
  2746. return false;
  2747. }
  2748. units = normalizeUnits(units || 'millisecond');
  2749. if (units === 'millisecond') {
  2750. return this.valueOf() === localInput.valueOf();
  2751. } else {
  2752. inputMs = localInput.valueOf();
  2753. return this.clone().startOf(units).valueOf() <= inputMs && inputMs <= this.clone().endOf(units).valueOf();
  2754. }
  2755. }
  2756. function isSameOrAfter (input, units) {
  2757. return this.isSame(input, units) || this.isAfter(input,units);
  2758. }
  2759. function isSameOrBefore (input, units) {
  2760. return this.isSame(input, units) || this.isBefore(input,units);
  2761. }
  2762. function diff (input, units, asFloat) {
  2763. var that,
  2764. zoneDelta,
  2765. delta, output;
  2766. if (!this.isValid()) {
  2767. return NaN;
  2768. }
  2769. that = cloneWithOffset(input, this);
  2770. if (!that.isValid()) {
  2771. return NaN;
  2772. }
  2773. zoneDelta = (that.utcOffset() - this.utcOffset()) * 6e4;
  2774. units = normalizeUnits(units);
  2775. switch (units) {
  2776. case 'year': output = monthDiff(this, that) / 12; break;
  2777. case 'month': output = monthDiff(this, that); break;
  2778. case 'quarter': output = monthDiff(this, that) / 3; break;
  2779. case 'second': output = (this - that) / 1e3; break; // 1000
  2780. case 'minute': output = (this - that) / 6e4; break; // 1000 * 60
  2781. case 'hour': output = (this - that) / 36e5; break; // 1000 * 60 * 60
  2782. case 'day': output = (this - that - zoneDelta) / 864e5; break; // 1000 * 60 * 60 * 24, negate dst
  2783. case 'week': output = (this - that - zoneDelta) / 6048e5; break; // 1000 * 60 * 60 * 24 * 7, negate dst
  2784. default: output = this - that;
  2785. }
  2786. return asFloat ? output : absFloor(output);
  2787. }
  2788. function monthDiff (a, b) {
  2789. // difference in months
  2790. var wholeMonthDiff = ((b.year() - a.year()) * 12) + (b.month() - a.month()),
  2791. // b is in (anchor - 1 month, anchor + 1 month)
  2792. anchor = a.clone().add(wholeMonthDiff, 'months'),
  2793. anchor2, adjust;
  2794. if (b - anchor < 0) {
  2795. anchor2 = a.clone().add(wholeMonthDiff - 1, 'months');
  2796. // linear across the month
  2797. adjust = (b - anchor) / (anchor - anchor2);
  2798. } else {
  2799. anchor2 = a.clone().add(wholeMonthDiff + 1, 'months');
  2800. // linear across the month
  2801. adjust = (b - anchor) / (anchor2 - anchor);
  2802. }
  2803. //check for negative zero, return zero if negative zero
  2804. return -(wholeMonthDiff + adjust) || 0;
  2805. }
  2806. hooks.defaultFormat = 'YYYY-MM-DDTHH:mm:ssZ';
  2807. hooks.defaultFormatUtc = 'YYYY-MM-DDTHH:mm:ss[Z]';
  2808. function toString () {
  2809. return this.clone().locale('en').format('ddd MMM DD YYYY HH:mm:ss [GMT]ZZ');
  2810. }
  2811. function toISOString(keepOffset) {
  2812. if (!this.isValid()) {
  2813. return null;
  2814. }
  2815. var utc = keepOffset !== true;
  2816. var m = utc ? this.clone().utc() : this;
  2817. if (m.year() < 0 || m.year() > 9999) {
  2818. return formatMoment(m, utc ? 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]' : 'YYYYYY-MM-DD[T]HH:mm:ss.SSSZ');
  2819. }
  2820. if (isFunction(Date.prototype.toISOString)) {
  2821. // native implementation is ~50x faster, use it when we can
  2822. if (utc) {
  2823. return this.toDate().toISOString();
  2824. } else {
  2825. return new Date(this._d.valueOf()).toISOString().replace('Z', formatMoment(m, 'Z'));
  2826. }
  2827. }
  2828. return formatMoment(m, utc ? 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]' : 'YYYY-MM-DD[T]HH:mm:ss.SSSZ');
  2829. }
  2830. /**
  2831. * Return a human readable representation of a moment that can
  2832. * also be evaluated to get a new moment which is the same
  2833. *
  2834. * @link https://nodejs.org/dist/latest/docs/api/util.html#util_custom_inspect_function_on_objects
  2835. */
  2836. function inspect () {
  2837. if (!this.isValid()) {
  2838. return 'moment.invalid(/* ' + this._i + ' */)';
  2839. }
  2840. var func = 'moment';
  2841. var zone = '';
  2842. if (!this.isLocal()) {
  2843. func = this.utcOffset() === 0 ? 'moment.utc' : 'moment.parseZone';
  2844. zone = 'Z';
  2845. }
  2846. var prefix = '[' + func + '("]';
  2847. var year = (0 <= this.year() && this.year() <= 9999) ? 'YYYY' : 'YYYYYY';
  2848. var datetime = '-MM-DD[T]HH:mm:ss.SSS';
  2849. var suffix = zone + '[")]';
  2850. return this.format(prefix + year + datetime + suffix);
  2851. }
  2852. function format (inputString) {
  2853. if (!inputString) {
  2854. inputString = this.isUtc() ? hooks.defaultFormatUtc : hooks.defaultFormat;
  2855. }
  2856. var output = formatMoment(this, inputString);
  2857. return this.localeData().postformat(output);
  2858. }
  2859. function from (time, withoutSuffix) {
  2860. if (this.isValid() &&
  2861. ((isMoment(time) && time.isValid()) ||
  2862. createLocal(time).isValid())) {
  2863. return createDuration({to: this, from: time}).locale(this.locale()).humanize(!withoutSuffix);
  2864. } else {
  2865. return this.localeData().invalidDate();
  2866. }
  2867. }
  2868. function fromNow (withoutSuffix) {
  2869. return this.from(createLocal(), withoutSuffix);
  2870. }
  2871. function to (time, withoutSuffix) {
  2872. if (this.isValid() &&
  2873. ((isMoment(time) && time.isValid()) ||
  2874. createLocal(time).isValid())) {
  2875. return createDuration({from: this, to: time}).locale(this.locale()).humanize(!withoutSuffix);
  2876. } else {
  2877. return this.localeData().invalidDate();
  2878. }
  2879. }
  2880. function toNow (withoutSuffix) {
  2881. return this.to(createLocal(), withoutSuffix);
  2882. }
  2883. // If passed a locale key, it will set the locale for this
  2884. // instance. Otherwise, it will return the locale configuration
  2885. // variables for this instance.
  2886. function locale (key) {
  2887. var newLocaleData;
  2888. if (key === undefined) {
  2889. return this._locale._abbr;
  2890. } else {
  2891. newLocaleData = getLocale(key);
  2892. if (newLocaleData != null) {
  2893. this._locale = newLocaleData;
  2894. }
  2895. return this;
  2896. }
  2897. }
  2898. var lang = deprecate(
  2899. 'moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.',
  2900. function (key) {
  2901. if (key === undefined) {
  2902. return this.localeData();
  2903. } else {
  2904. return this.locale(key);
  2905. }
  2906. }
  2907. );
  2908. function localeData () {
  2909. return this._locale;
  2910. }
  2911. function startOf (units) {
  2912. units = normalizeUnits(units);
  2913. // the following switch intentionally omits break keywords
  2914. // to utilize falling through the cases.
  2915. switch (units) {
  2916. case 'year':
  2917. this.month(0);
  2918. /* falls through */
  2919. case 'quarter':
  2920. case 'month':
  2921. this.date(1);
  2922. /* falls through */
  2923. case 'week':
  2924. case 'isoWeek':
  2925. case 'day':
  2926. case 'date':
  2927. this.hours(0);
  2928. /* falls through */
  2929. case 'hour':
  2930. this.minutes(0);
  2931. /* falls through */
  2932. case 'minute':
  2933. this.seconds(0);
  2934. /* falls through */
  2935. case 'second':
  2936. this.milliseconds(0);
  2937. }
  2938. // weeks are a special case
  2939. if (units === 'week') {
  2940. this.weekday(0);
  2941. }
  2942. if (units === 'isoWeek') {
  2943. this.isoWeekday(1);
  2944. }
  2945. // quarters are also special
  2946. if (units === 'quarter') {
  2947. this.month(Math.floor(this.month() / 3) * 3);
  2948. }
  2949. return this;
  2950. }
  2951. function endOf (units) {
  2952. units = normalizeUnits(units);
  2953. if (units === undefined || units === 'millisecond') {
  2954. return this;
  2955. }
  2956. // 'date' is an alias for 'day', so it should be considered as such.
  2957. if (units === 'date') {
  2958. units = 'day';
  2959. }
  2960. return this.startOf(units).add(1, (units === 'isoWeek' ? 'week' : units)).subtract(1, 'ms');
  2961. }
  2962. function valueOf () {
  2963. return this._d.valueOf() - ((this._offset || 0) * 60000);
  2964. }
  2965. function unix () {
  2966. return Math.floor(this.valueOf() / 1000);
  2967. }
  2968. function toDate () {
  2969. return new Date(this.valueOf());
  2970. }
  2971. function toArray () {
  2972. var m = this;
  2973. return [m.year(), m.month(), m.date(), m.hour(), m.minute(), m.second(), m.millisecond()];
  2974. }
  2975. function toObject () {
  2976. var m = this;
  2977. return {
  2978. years: m.year(),
  2979. months: m.month(),
  2980. date: m.date(),
  2981. hours: m.hours(),
  2982. minutes: m.minutes(),
  2983. seconds: m.seconds(),
  2984. milliseconds: m.milliseconds()
  2985. };
  2986. }
  2987. function toJSON () {
  2988. // new Date(NaN).toJSON() === null
  2989. return this.isValid() ? this.toISOString() : null;
  2990. }
  2991. function isValid$2 () {
  2992. return isValid(this);
  2993. }
  2994. function parsingFlags () {
  2995. return extend({}, getParsingFlags(this));
  2996. }
  2997. function invalidAt () {
  2998. return getParsingFlags(this).overflow;
  2999. }
  3000. function creationData() {
  3001. return {
  3002. input: this._i,
  3003. format: this._f,
  3004. locale: this._locale,
  3005. isUTC: this._isUTC,
  3006. strict: this._strict
  3007. };
  3008. }
  3009. // FORMATTING
  3010. addFormatToken(0, ['gg', 2], 0, function () {
  3011. return this.weekYear() % 100;
  3012. });
  3013. addFormatToken(0, ['GG', 2], 0, function () {
  3014. return this.isoWeekYear() % 100;
  3015. });
  3016. function addWeekYearFormatToken (token, getter) {
  3017. addFormatToken(0, [token, token.length], 0, getter);
  3018. }
  3019. addWeekYearFormatToken('gggg', 'weekYear');
  3020. addWeekYearFormatToken('ggggg', 'weekYear');
  3021. addWeekYearFormatToken('GGGG', 'isoWeekYear');
  3022. addWeekYearFormatToken('GGGGG', 'isoWeekYear');
  3023. // ALIASES
  3024. addUnitAlias('weekYear', 'gg');
  3025. addUnitAlias('isoWeekYear', 'GG');
  3026. // PRIORITY
  3027. addUnitPriority('weekYear', 1);
  3028. addUnitPriority('isoWeekYear', 1);
  3029. // PARSING
  3030. addRegexToken('G', matchSigned);
  3031. addRegexToken('g', matchSigned);
  3032. addRegexToken('GG', match1to2, match2);
  3033. addRegexToken('gg', match1to2, match2);
  3034. addRegexToken('GGGG', match1to4, match4);
  3035. addRegexToken('gggg', match1to4, match4);
  3036. addRegexToken('GGGGG', match1to6, match6);
  3037. addRegexToken('ggggg', match1to6, match6);
  3038. addWeekParseToken(['gggg', 'ggggg', 'GGGG', 'GGGGG'], function (input, week, config, token) {
  3039. week[token.substr(0, 2)] = toInt(input);
  3040. });
  3041. addWeekParseToken(['gg', 'GG'], function (input, week, config, token) {
  3042. week[token] = hooks.parseTwoDigitYear(input);
  3043. });
  3044. // MOMENTS
  3045. function getSetWeekYear (input) {
  3046. return getSetWeekYearHelper.call(this,
  3047. input,
  3048. this.week(),
  3049. this.weekday(),
  3050. this.localeData()._week.dow,
  3051. this.localeData()._week.doy);
  3052. }
  3053. function getSetISOWeekYear (input) {
  3054. return getSetWeekYearHelper.call(this,
  3055. input, this.isoWeek(), this.isoWeekday(), 1, 4);
  3056. }
  3057. function getISOWeeksInYear () {
  3058. return weeksInYear(this.year(), 1, 4);
  3059. }
  3060. function getWeeksInYear () {
  3061. var weekInfo = this.localeData()._week;
  3062. return weeksInYear(this.year(), weekInfo.dow, weekInfo.doy);
  3063. }
  3064. function getSetWeekYearHelper(input, week, weekday, dow, doy) {
  3065. var weeksTarget;
  3066. if (input == null) {
  3067. return weekOfYear(this, dow, doy).year;
  3068. } else {
  3069. weeksTarget = weeksInYear(input, dow, doy);
  3070. if (week > weeksTarget) {
  3071. week = weeksTarget;
  3072. }
  3073. return setWeekAll.call(this, input, week, weekday, dow, doy);
  3074. }
  3075. }
  3076. function setWeekAll(weekYear, week, weekday, dow, doy) {
  3077. var dayOfYearData = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy),
  3078. date = createUTCDate(dayOfYearData.year, 0, dayOfYearData.dayOfYear);
  3079. this.year(date.getUTCFullYear());
  3080. this.month(date.getUTCMonth());
  3081. this.date(date.getUTCDate());
  3082. return this;
  3083. }
  3084. // FORMATTING
  3085. addFormatToken('Q', 0, 'Qo', 'quarter');
  3086. // ALIASES
  3087. addUnitAlias('quarter', 'Q');
  3088. // PRIORITY
  3089. addUnitPriority('quarter', 7);
  3090. // PARSING
  3091. addRegexToken('Q', match1);
  3092. addParseToken('Q', function (input, array) {
  3093. array[MONTH] = (toInt(input) - 1) * 3;
  3094. });
  3095. // MOMENTS
  3096. function getSetQuarter (input) {
  3097. return input == null ? Math.ceil((this.month() + 1) / 3) : this.month((input - 1) * 3 + this.month() % 3);
  3098. }
  3099. // FORMATTING
  3100. addFormatToken('D', ['DD', 2], 'Do', 'date');
  3101. // ALIASES
  3102. addUnitAlias('date', 'D');
  3103. // PRIOROITY
  3104. addUnitPriority('date', 9);
  3105. // PARSING
  3106. addRegexToken('D', match1to2);
  3107. addRegexToken('DD', match1to2, match2);
  3108. addRegexToken('Do', function (isStrict, locale) {
  3109. // TODO: Remove "ordinalParse" fallback in next major release.
  3110. return isStrict ?
  3111. (locale._dayOfMonthOrdinalParse || locale._ordinalParse) :
  3112. locale._dayOfMonthOrdinalParseLenient;
  3113. });
  3114. addParseToken(['D', 'DD'], DATE);
  3115. addParseToken('Do', function (input, array) {
  3116. array[DATE] = toInt(input.match(match1to2)[0]);
  3117. });
  3118. // MOMENTS
  3119. var getSetDayOfMonth = makeGetSet('Date', true);
  3120. // FORMATTING
  3121. addFormatToken('DDD', ['DDDD', 3], 'DDDo', 'dayOfYear');
  3122. // ALIASES
  3123. addUnitAlias('dayOfYear', 'DDD');
  3124. // PRIORITY
  3125. addUnitPriority('dayOfYear', 4);
  3126. // PARSING
  3127. addRegexToken('DDD', match1to3);
  3128. addRegexToken('DDDD', match3);
  3129. addParseToken(['DDD', 'DDDD'], function (input, array, config) {
  3130. config._dayOfYear = toInt(input);
  3131. });
  3132. // HELPERS
  3133. // MOMENTS
  3134. function getSetDayOfYear (input) {
  3135. var dayOfYear = Math.round((this.clone().startOf('day') - this.clone().startOf('year')) / 864e5) + 1;
  3136. return input == null ? dayOfYear : this.add((input - dayOfYear), 'd');
  3137. }
  3138. // FORMATTING
  3139. addFormatToken('m', ['mm', 2], 0, 'minute');
  3140. // ALIASES
  3141. addUnitAlias('minute', 'm');
  3142. // PRIORITY
  3143. addUnitPriority('minute', 14);
  3144. // PARSING
  3145. addRegexToken('m', match1to2);
  3146. addRegexToken('mm', match1to2, match2);
  3147. addParseToken(['m', 'mm'], MINUTE);
  3148. // MOMENTS
  3149. var getSetMinute = makeGetSet('Minutes', false);
  3150. // FORMATTING
  3151. addFormatToken('s', ['ss', 2], 0, 'second');
  3152. // ALIASES
  3153. addUnitAlias('second', 's');
  3154. // PRIORITY
  3155. addUnitPriority('second', 15);
  3156. // PARSING
  3157. addRegexToken('s', match1to2);
  3158. addRegexToken('ss', match1to2, match2);
  3159. addParseToken(['s', 'ss'], SECOND);
  3160. // MOMENTS
  3161. var getSetSecond = makeGetSet('Seconds', false);
  3162. // FORMATTING
  3163. addFormatToken('S', 0, 0, function () {
  3164. return ~~(this.millisecond() / 100);
  3165. });
  3166. addFormatToken(0, ['SS', 2], 0, function () {
  3167. return ~~(this.millisecond() / 10);
  3168. });
  3169. addFormatToken(0, ['SSS', 3], 0, 'millisecond');
  3170. addFormatToken(0, ['SSSS', 4], 0, function () {
  3171. return this.millisecond() * 10;
  3172. });
  3173. addFormatToken(0, ['SSSSS', 5], 0, function () {
  3174. return this.millisecond() * 100;
  3175. });
  3176. addFormatToken(0, ['SSSSSS', 6], 0, function () {
  3177. return this.millisecond() * 1000;
  3178. });
  3179. addFormatToken(0, ['SSSSSSS', 7], 0, function () {
  3180. return this.millisecond() * 10000;
  3181. });
  3182. addFormatToken(0, ['SSSSSSSS', 8], 0, function () {
  3183. return this.millisecond() * 100000;
  3184. });
  3185. addFormatToken(0, ['SSSSSSSSS', 9], 0, function () {
  3186. return this.millisecond() * 1000000;
  3187. });
  3188. // ALIASES
  3189. addUnitAlias('millisecond', 'ms');
  3190. // PRIORITY
  3191. addUnitPriority('millisecond', 16);
  3192. // PARSING
  3193. addRegexToken('S', match1to3, match1);
  3194. addRegexToken('SS', match1to3, match2);
  3195. addRegexToken('SSS', match1to3, match3);
  3196. var token;
  3197. for (token = 'SSSS'; token.length <= 9; token += 'S') {
  3198. addRegexToken(token, matchUnsigned);
  3199. }
  3200. function parseMs(input, array) {
  3201. array[MILLISECOND] = toInt(('0.' + input) * 1000);
  3202. }
  3203. for (token = 'S'; token.length <= 9; token += 'S') {
  3204. addParseToken(token, parseMs);
  3205. }
  3206. // MOMENTS
  3207. var getSetMillisecond = makeGetSet('Milliseconds', false);
  3208. // FORMATTING
  3209. addFormatToken('z', 0, 0, 'zoneAbbr');
  3210. addFormatToken('zz', 0, 0, 'zoneName');
  3211. // MOMENTS
  3212. function getZoneAbbr () {
  3213. return this._isUTC ? 'UTC' : '';
  3214. }
  3215. function getZoneName () {
  3216. return this._isUTC ? 'Coordinated Universal Time' : '';
  3217. }
  3218. var proto = Moment.prototype;
  3219. proto.add = add;
  3220. proto.calendar = calendar$1;
  3221. proto.clone = clone;
  3222. proto.diff = diff;
  3223. proto.endOf = endOf;
  3224. proto.format = format;
  3225. proto.from = from;
  3226. proto.fromNow = fromNow;
  3227. proto.to = to;
  3228. proto.toNow = toNow;
  3229. proto.get = stringGet;
  3230. proto.invalidAt = invalidAt;
  3231. proto.isAfter = isAfter;
  3232. proto.isBefore = isBefore;
  3233. proto.isBetween = isBetween;
  3234. proto.isSame = isSame;
  3235. proto.isSameOrAfter = isSameOrAfter;
  3236. proto.isSameOrBefore = isSameOrBefore;
  3237. proto.isValid = isValid$2;
  3238. proto.lang = lang;
  3239. proto.locale = locale;
  3240. proto.localeData = localeData;
  3241. proto.max = prototypeMax;
  3242. proto.min = prototypeMin;
  3243. proto.parsingFlags = parsingFlags;
  3244. proto.set = stringSet;
  3245. proto.startOf = startOf;
  3246. proto.subtract = subtract;
  3247. proto.toArray = toArray;
  3248. proto.toObject = toObject;
  3249. proto.toDate = toDate;
  3250. proto.toISOString = toISOString;
  3251. proto.inspect = inspect;
  3252. proto.toJSON = toJSON;
  3253. proto.toString = toString;
  3254. proto.unix = unix;
  3255. proto.valueOf = valueOf;
  3256. proto.creationData = creationData;
  3257. // Year
  3258. proto.year = getSetYear;
  3259. proto.isLeapYear = getIsLeapYear;
  3260. // Week Year
  3261. proto.weekYear = getSetWeekYear;
  3262. proto.isoWeekYear = getSetISOWeekYear;
  3263. // Quarter
  3264. proto.quarter = proto.quarters = getSetQuarter;
  3265. // Month
  3266. proto.month = getSetMonth;
  3267. proto.daysInMonth = getDaysInMonth;
  3268. // Week
  3269. proto.week = proto.weeks = getSetWeek;
  3270. proto.isoWeek = proto.isoWeeks = getSetISOWeek;
  3271. proto.weeksInYear = getWeeksInYear;
  3272. proto.isoWeeksInYear = getISOWeeksInYear;
  3273. // Day
  3274. proto.date = getSetDayOfMonth;
  3275. proto.day = proto.days = getSetDayOfWeek;
  3276. proto.weekday = getSetLocaleDayOfWeek;
  3277. proto.isoWeekday = getSetISODayOfWeek;
  3278. proto.dayOfYear = getSetDayOfYear;
  3279. // Hour
  3280. proto.hour = proto.hours = getSetHour;
  3281. // Minute
  3282. proto.minute = proto.minutes = getSetMinute;
  3283. // Second
  3284. proto.second = proto.seconds = getSetSecond;
  3285. // Millisecond
  3286. proto.millisecond = proto.milliseconds = getSetMillisecond;
  3287. // Offset
  3288. proto.utcOffset = getSetOffset;
  3289. proto.utc = setOffsetToUTC;
  3290. proto.local = setOffsetToLocal;
  3291. proto.parseZone = setOffsetToParsedOffset;
  3292. proto.hasAlignedHourOffset = hasAlignedHourOffset;
  3293. proto.isDST = isDaylightSavingTime;
  3294. proto.isLocal = isLocal;
  3295. proto.isUtcOffset = isUtcOffset;
  3296. proto.isUtc = isUtc;
  3297. proto.isUTC = isUtc;
  3298. // Timezone
  3299. proto.zoneAbbr = getZoneAbbr;
  3300. proto.zoneName = getZoneName;
  3301. // Deprecations
  3302. proto.dates = deprecate('dates accessor is deprecated. Use date instead.', getSetDayOfMonth);
  3303. proto.months = deprecate('months accessor is deprecated. Use month instead', getSetMonth);
  3304. proto.years = deprecate('years accessor is deprecated. Use year instead', getSetYear);
  3305. proto.zone = deprecate('moment().zone is deprecated, use moment().utcOffset instead. http://momentjs.com/guides/#/warnings/zone/', getSetZone);
  3306. proto.isDSTShifted = deprecate('isDSTShifted is deprecated. See http://momentjs.com/guides/#/warnings/dst-shifted/ for more information', isDaylightSavingTimeShifted);
  3307. function createUnix (input) {
  3308. return createLocal(input * 1000);
  3309. }
  3310. function createInZone () {
  3311. return createLocal.apply(null, arguments).parseZone();
  3312. }
  3313. function preParsePostFormat (string) {
  3314. return string;
  3315. }
  3316. var proto$1 = Locale.prototype;
  3317. proto$1.calendar = calendar;
  3318. proto$1.longDateFormat = longDateFormat;
  3319. proto$1.invalidDate = invalidDate;
  3320. proto$1.ordinal = ordinal;
  3321. proto$1.preparse = preParsePostFormat;
  3322. proto$1.postformat = preParsePostFormat;
  3323. proto$1.relativeTime = relativeTime;
  3324. proto$1.pastFuture = pastFuture;
  3325. proto$1.set = set;
  3326. // Month
  3327. proto$1.months = localeMonths;
  3328. proto$1.monthsShort = localeMonthsShort;
  3329. proto$1.monthsParse = localeMonthsParse;
  3330. proto$1.monthsRegex = monthsRegex;
  3331. proto$1.monthsShortRegex = monthsShortRegex;
  3332. // Week
  3333. proto$1.week = localeWeek;
  3334. proto$1.firstDayOfYear = localeFirstDayOfYear;
  3335. proto$1.firstDayOfWeek = localeFirstDayOfWeek;
  3336. // Day of Week
  3337. proto$1.weekdays = localeWeekdays;
  3338. proto$1.weekdaysMin = localeWeekdaysMin;
  3339. proto$1.weekdaysShort = localeWeekdaysShort;
  3340. proto$1.weekdaysParse = localeWeekdaysParse;
  3341. proto$1.weekdaysRegex = weekdaysRegex;
  3342. proto$1.weekdaysShortRegex = weekdaysShortRegex;
  3343. proto$1.weekdaysMinRegex = weekdaysMinRegex;
  3344. // Hours
  3345. proto$1.isPM = localeIsPM;
  3346. proto$1.meridiem = localeMeridiem;
  3347. function get$1 (format, index, field, setter) {
  3348. var locale = getLocale();
  3349. var utc = createUTC().set(setter, index);
  3350. return locale[field](utc, format);
  3351. }
  3352. function listMonthsImpl (format, index, field) {
  3353. if (isNumber(format)) {
  3354. index = format;
  3355. format = undefined;
  3356. }
  3357. format = format || '';
  3358. if (index != null) {
  3359. return get$1(format, index, field, 'month');
  3360. }
  3361. var i;
  3362. var out = [];
  3363. for (i = 0; i < 12; i++) {
  3364. out[i] = get$1(format, i, field, 'month');
  3365. }
  3366. return out;
  3367. }
  3368. // ()
  3369. // (5)
  3370. // (fmt, 5)
  3371. // (fmt)
  3372. // (true)
  3373. // (true, 5)
  3374. // (true, fmt, 5)
  3375. // (true, fmt)
  3376. function listWeekdaysImpl (localeSorted, format, index, field) {
  3377. if (typeof localeSorted === 'boolean') {
  3378. if (isNumber(format)) {
  3379. index = format;
  3380. format = undefined;
  3381. }
  3382. format = format || '';
  3383. } else {
  3384. format = localeSorted;
  3385. index = format;
  3386. localeSorted = false;
  3387. if (isNumber(format)) {
  3388. index = format;
  3389. format = undefined;
  3390. }
  3391. format = format || '';
  3392. }
  3393. var locale = getLocale(),
  3394. shift = localeSorted ? locale._week.dow : 0;
  3395. if (index != null) {
  3396. return get$1(format, (index + shift) % 7, field, 'day');
  3397. }
  3398. var i;
  3399. var out = [];
  3400. for (i = 0; i < 7; i++) {
  3401. out[i] = get$1(format, (i + shift) % 7, field, 'day');
  3402. }
  3403. return out;
  3404. }
  3405. function listMonths (format, index) {
  3406. return listMonthsImpl(format, index, 'months');
  3407. }
  3408. function listMonthsShort (format, index) {
  3409. return listMonthsImpl(format, index, 'monthsShort');
  3410. }
  3411. function listWeekdays (localeSorted, format, index) {
  3412. return listWeekdaysImpl(localeSorted, format, index, 'weekdays');
  3413. }
  3414. function listWeekdaysShort (localeSorted, format, index) {
  3415. return listWeekdaysImpl(localeSorted, format, index, 'weekdaysShort');
  3416. }
  3417. function listWeekdaysMin (localeSorted, format, index) {
  3418. return listWeekdaysImpl(localeSorted, format, index, 'weekdaysMin');
  3419. }
  3420. getSetGlobalLocale('en', {
  3421. dayOfMonthOrdinalParse: /\d{1,2}(th|st|nd|rd)/,
  3422. ordinal : function (number) {
  3423. var b = number % 10,
  3424. output = (toInt(number % 100 / 10) === 1) ? 'th' :
  3425. (b === 1) ? 'st' :
  3426. (b === 2) ? 'nd' :
  3427. (b === 3) ? 'rd' : 'th';
  3428. return number + output;
  3429. }
  3430. });
  3431. // Side effect imports
  3432. hooks.lang = deprecate('moment.lang is deprecated. Use moment.locale instead.', getSetGlobalLocale);
  3433. hooks.langData = deprecate('moment.langData is deprecated. Use moment.localeData instead.', getLocale);
  3434. var mathAbs = Math.abs;
  3435. function abs () {
  3436. var data = this._data;
  3437. this._milliseconds = mathAbs(this._milliseconds);
  3438. this._days = mathAbs(this._days);
  3439. this._months = mathAbs(this._months);
  3440. data.milliseconds = mathAbs(data.milliseconds);
  3441. data.seconds = mathAbs(data.seconds);
  3442. data.minutes = mathAbs(data.minutes);
  3443. data.hours = mathAbs(data.hours);
  3444. data.months = mathAbs(data.months);
  3445. data.years = mathAbs(data.years);
  3446. return this;
  3447. }
  3448. function addSubtract$1 (duration, input, value, direction) {
  3449. var other = createDuration(input, value);
  3450. duration._milliseconds += direction * other._milliseconds;
  3451. duration._days += direction * other._days;
  3452. duration._months += direction * other._months;
  3453. return duration._bubble();
  3454. }
  3455. // supports only 2.0-style add(1, 's') or add(duration)
  3456. function add$1 (input, value) {
  3457. return addSubtract$1(this, input, value, 1);
  3458. }
  3459. // supports only 2.0-style subtract(1, 's') or subtract(duration)
  3460. function subtract$1 (input, value) {
  3461. return addSubtract$1(this, input, value, -1);
  3462. }
  3463. function absCeil (number) {
  3464. if (number < 0) {
  3465. return Math.floor(number);
  3466. } else {
  3467. return Math.ceil(number);
  3468. }
  3469. }
  3470. function bubble () {
  3471. var milliseconds = this._milliseconds;
  3472. var days = this._days;
  3473. var months = this._months;
  3474. var data = this._data;
  3475. var seconds, minutes, hours, years, monthsFromDays;
  3476. // if we have a mix of positive and negative values, bubble down first
  3477. // check: https://github.com/moment/moment/issues/2166
  3478. if (!((milliseconds >= 0 && days >= 0 && months >= 0) ||
  3479. (milliseconds <= 0 && days <= 0 && months <= 0))) {
  3480. milliseconds += absCeil(monthsToDays(months) + days) * 864e5;
  3481. days = 0;
  3482. months = 0;
  3483. }
  3484. // The following code bubbles up values, see the tests for
  3485. // examples of what that means.
  3486. data.milliseconds = milliseconds % 1000;
  3487. seconds = absFloor(milliseconds / 1000);
  3488. data.seconds = seconds % 60;
  3489. minutes = absFloor(seconds / 60);
  3490. data.minutes = minutes % 60;
  3491. hours = absFloor(minutes / 60);
  3492. data.hours = hours % 24;
  3493. days += absFloor(hours / 24);
  3494. // convert days to months
  3495. monthsFromDays = absFloor(daysToMonths(days));
  3496. months += monthsFromDays;
  3497. days -= absCeil(monthsToDays(monthsFromDays));
  3498. // 12 months -> 1 year
  3499. years = absFloor(months / 12);
  3500. months %= 12;
  3501. data.days = days;
  3502. data.months = months;
  3503. data.years = years;
  3504. return this;
  3505. }
  3506. function daysToMonths (days) {
  3507. // 400 years have 146097 days (taking into account leap year rules)
  3508. // 400 years have 12 months === 4800
  3509. return days * 4800 / 146097;
  3510. }
  3511. function monthsToDays (months) {
  3512. // the reverse of daysToMonths
  3513. return months * 146097 / 4800;
  3514. }
  3515. function as (units) {
  3516. if (!this.isValid()) {
  3517. return NaN;
  3518. }
  3519. var days;
  3520. var months;
  3521. var milliseconds = this._milliseconds;
  3522. units = normalizeUnits(units);
  3523. if (units === 'month' || units === 'year') {
  3524. days = this._days + milliseconds / 864e5;
  3525. months = this._months + daysToMonths(days);
  3526. return units === 'month' ? months : months / 12;
  3527. } else {
  3528. // handle milliseconds separately because of floating point math errors (issue #1867)
  3529. days = this._days + Math.round(monthsToDays(this._months));
  3530. switch (units) {
  3531. case 'week' : return days / 7 + milliseconds / 6048e5;
  3532. case 'day' : return days + milliseconds / 864e5;
  3533. case 'hour' : return days * 24 + milliseconds / 36e5;
  3534. case 'minute' : return days * 1440 + milliseconds / 6e4;
  3535. case 'second' : return days * 86400 + milliseconds / 1000;
  3536. // Math.floor prevents floating point math errors here
  3537. case 'millisecond': return Math.floor(days * 864e5) + milliseconds;
  3538. default: throw new Error('Unknown unit ' + units);
  3539. }
  3540. }
  3541. }
  3542. // TODO: Use this.as('ms')?
  3543. function valueOf$1 () {
  3544. if (!this.isValid()) {
  3545. return NaN;
  3546. }
  3547. return (
  3548. this._milliseconds +
  3549. this._days * 864e5 +
  3550. (this._months % 12) * 2592e6 +
  3551. toInt(this._months / 12) * 31536e6
  3552. );
  3553. }
  3554. function makeAs (alias) {
  3555. return function () {
  3556. return this.as(alias);
  3557. };
  3558. }
  3559. var asMilliseconds = makeAs('ms');
  3560. var asSeconds = makeAs('s');
  3561. var asMinutes = makeAs('m');
  3562. var asHours = makeAs('h');
  3563. var asDays = makeAs('d');
  3564. var asWeeks = makeAs('w');
  3565. var asMonths = makeAs('M');
  3566. var asYears = makeAs('y');
  3567. function clone$1 () {
  3568. return createDuration(this);
  3569. }
  3570. function get$2 (units) {
  3571. units = normalizeUnits(units);
  3572. return this.isValid() ? this[units + 's']() : NaN;
  3573. }
  3574. function makeGetter(name) {
  3575. return function () {
  3576. return this.isValid() ? this._data[name] : NaN;
  3577. };
  3578. }
  3579. var milliseconds = makeGetter('milliseconds');
  3580. var seconds = makeGetter('seconds');
  3581. var minutes = makeGetter('minutes');
  3582. var hours = makeGetter('hours');
  3583. var days = makeGetter('days');
  3584. var months = makeGetter('months');
  3585. var years = makeGetter('years');
  3586. function weeks () {
  3587. return absFloor(this.days() / 7);
  3588. }
  3589. var round = Math.round;
  3590. var thresholds = {
  3591. ss: 44, // a few seconds to seconds
  3592. s : 45, // seconds to minute
  3593. m : 45, // minutes to hour
  3594. h : 22, // hours to day
  3595. d : 26, // days to month
  3596. M : 11 // months to year
  3597. };
  3598. // helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize
  3599. function substituteTimeAgo(string, number, withoutSuffix, isFuture, locale) {
  3600. return locale.relativeTime(number || 1, !!withoutSuffix, string, isFuture);
  3601. }
  3602. function relativeTime$1 (posNegDuration, withoutSuffix, locale) {
  3603. var duration = createDuration(posNegDuration).abs();
  3604. var seconds = round(duration.as('s'));
  3605. var minutes = round(duration.as('m'));
  3606. var hours = round(duration.as('h'));
  3607. var days = round(duration.as('d'));
  3608. var months = round(duration.as('M'));
  3609. var years = round(duration.as('y'));
  3610. var a = seconds <= thresholds.ss && ['s', seconds] ||
  3611. seconds < thresholds.s && ['ss', seconds] ||
  3612. minutes <= 1 && ['m'] ||
  3613. minutes < thresholds.m && ['mm', minutes] ||
  3614. hours <= 1 && ['h'] ||
  3615. hours < thresholds.h && ['hh', hours] ||
  3616. days <= 1 && ['d'] ||
  3617. days < thresholds.d && ['dd', days] ||
  3618. months <= 1 && ['M'] ||
  3619. months < thresholds.M && ['MM', months] ||
  3620. years <= 1 && ['y'] || ['yy', years];
  3621. a[2] = withoutSuffix;
  3622. a[3] = +posNegDuration > 0;
  3623. a[4] = locale;
  3624. return substituteTimeAgo.apply(null, a);
  3625. }
  3626. // This function allows you to set the rounding function for relative time strings
  3627. function getSetRelativeTimeRounding (roundingFunction) {
  3628. if (roundingFunction === undefined) {
  3629. return round;
  3630. }
  3631. if (typeof(roundingFunction) === 'function') {
  3632. round = roundingFunction;
  3633. return true;
  3634. }
  3635. return false;
  3636. }
  3637. // This function allows you to set a threshold for relative time strings
  3638. function getSetRelativeTimeThreshold (threshold, limit) {
  3639. if (thresholds[threshold] === undefined) {
  3640. return false;
  3641. }
  3642. if (limit === undefined) {
  3643. return thresholds[threshold];
  3644. }
  3645. thresholds[threshold] = limit;
  3646. if (threshold === 's') {
  3647. thresholds.ss = limit - 1;
  3648. }
  3649. return true;
  3650. }
  3651. function humanize (withSuffix) {
  3652. if (!this.isValid()) {
  3653. return this.localeData().invalidDate();
  3654. }
  3655. var locale = this.localeData();
  3656. var output = relativeTime$1(this, !withSuffix, locale);
  3657. if (withSuffix) {
  3658. output = locale.pastFuture(+this, output);
  3659. }
  3660. return locale.postformat(output);
  3661. }
  3662. var abs$1 = Math.abs;
  3663. function sign(x) {
  3664. return ((x > 0) - (x < 0)) || +x;
  3665. }
  3666. function toISOString$1() {
  3667. // for ISO strings we do not use the normal bubbling rules:
  3668. // * milliseconds bubble up until they become hours
  3669. // * days do not bubble at all
  3670. // * months bubble up until they become years
  3671. // This is because there is no context-free conversion between hours and days
  3672. // (think of clock changes)
  3673. // and also not between days and months (28-31 days per month)
  3674. if (!this.isValid()) {
  3675. return this.localeData().invalidDate();
  3676. }
  3677. var seconds = abs$1(this._milliseconds) / 1000;
  3678. var days = abs$1(this._days);
  3679. var months = abs$1(this._months);
  3680. var minutes, hours, years;
  3681. // 3600 seconds -> 60 minutes -> 1 hour
  3682. minutes = absFloor(seconds / 60);
  3683. hours = absFloor(minutes / 60);
  3684. seconds %= 60;
  3685. minutes %= 60;
  3686. // 12 months -> 1 year
  3687. years = absFloor(months / 12);
  3688. months %= 12;
  3689. // inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js
  3690. var Y = years;
  3691. var M = months;
  3692. var D = days;
  3693. var h = hours;
  3694. var m = minutes;
  3695. var s = seconds ? seconds.toFixed(3).replace(/\.?0+$/, '') : '';
  3696. var total = this.asSeconds();
  3697. if (!total) {
  3698. // this is the same as C#'s (Noda) and python (isodate)...
  3699. // but not other JS (goog.date)
  3700. return 'P0D';
  3701. }
  3702. var totalSign = total < 0 ? '-' : '';
  3703. var ymSign = sign(this._months) !== sign(total) ? '-' : '';
  3704. var daysSign = sign(this._days) !== sign(total) ? '-' : '';
  3705. var hmsSign = sign(this._milliseconds) !== sign(total) ? '-' : '';
  3706. return totalSign + 'P' +
  3707. (Y ? ymSign + Y + 'Y' : '') +
  3708. (M ? ymSign + M + 'M' : '') +
  3709. (D ? daysSign + D + 'D' : '') +
  3710. ((h || m || s) ? 'T' : '') +
  3711. (h ? hmsSign + h + 'H' : '') +
  3712. (m ? hmsSign + m + 'M' : '') +
  3713. (s ? hmsSign + s + 'S' : '');
  3714. }
  3715. var proto$2 = Duration.prototype;
  3716. proto$2.isValid = isValid$1;
  3717. proto$2.abs = abs;
  3718. proto$2.add = add$1;
  3719. proto$2.subtract = subtract$1;
  3720. proto$2.as = as;
  3721. proto$2.asMilliseconds = asMilliseconds;
  3722. proto$2.asSeconds = asSeconds;
  3723. proto$2.asMinutes = asMinutes;
  3724. proto$2.asHours = asHours;
  3725. proto$2.asDays = asDays;
  3726. proto$2.asWeeks = asWeeks;
  3727. proto$2.asMonths = asMonths;
  3728. proto$2.asYears = asYears;
  3729. proto$2.valueOf = valueOf$1;
  3730. proto$2._bubble = bubble;
  3731. proto$2.clone = clone$1;
  3732. proto$2.get = get$2;
  3733. proto$2.milliseconds = milliseconds;
  3734. proto$2.seconds = seconds;
  3735. proto$2.minutes = minutes;
  3736. proto$2.hours = hours;
  3737. proto$2.days = days;
  3738. proto$2.weeks = weeks;
  3739. proto$2.months = months;
  3740. proto$2.years = years;
  3741. proto$2.humanize = humanize;
  3742. proto$2.toISOString = toISOString$1;
  3743. proto$2.toString = toISOString$1;
  3744. proto$2.toJSON = toISOString$1;
  3745. proto$2.locale = locale;
  3746. proto$2.localeData = localeData;
  3747. // Deprecations
  3748. proto$2.toIsoString = deprecate('toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)', toISOString$1);
  3749. proto$2.lang = lang;
  3750. // Side effect imports
  3751. // FORMATTING
  3752. addFormatToken('X', 0, 0, 'unix');
  3753. addFormatToken('x', 0, 0, 'valueOf');
  3754. // PARSING
  3755. addRegexToken('x', matchSigned);
  3756. addRegexToken('X', matchTimestamp);
  3757. addParseToken('X', function (input, array, config) {
  3758. config._d = new Date(parseFloat(input, 10) * 1000);
  3759. });
  3760. addParseToken('x', function (input, array, config) {
  3761. config._d = new Date(toInt(input));
  3762. });
  3763. // Side effect imports
  3764. hooks.version = '2.20.1';
  3765. setHookCallback(createLocal);
  3766. hooks.fn = proto;
  3767. hooks.min = min;
  3768. hooks.max = max;
  3769. hooks.now = now;
  3770. hooks.utc = createUTC;
  3771. hooks.unix = createUnix;
  3772. hooks.months = listMonths;
  3773. hooks.isDate = isDate;
  3774. hooks.locale = getSetGlobalLocale;
  3775. hooks.invalid = createInvalid;
  3776. hooks.duration = createDuration;
  3777. hooks.isMoment = isMoment;
  3778. hooks.weekdays = listWeekdays;
  3779. hooks.parseZone = createInZone;
  3780. hooks.localeData = getLocale;
  3781. hooks.isDuration = isDuration;
  3782. hooks.monthsShort = listMonthsShort;
  3783. hooks.weekdaysMin = listWeekdaysMin;
  3784. hooks.defineLocale = defineLocale;
  3785. hooks.updateLocale = updateLocale;
  3786. hooks.locales = listLocales;
  3787. hooks.weekdaysShort = listWeekdaysShort;
  3788. hooks.normalizeUnits = normalizeUnits;
  3789. hooks.relativeTimeRounding = getSetRelativeTimeRounding;
  3790. hooks.relativeTimeThreshold = getSetRelativeTimeThreshold;
  3791. hooks.calendarFormat = getCalendarFormat;
  3792. hooks.prototype = proto;
  3793. // currently HTML5 input type only supports 24-hour formats
  3794. hooks.HTML5_FMT = {
  3795. DATETIME_LOCAL: 'YYYY-MM-DDTHH:mm', // <input type="datetime-local" />
  3796. DATETIME_LOCAL_SECONDS: 'YYYY-MM-DDTHH:mm:ss', // <input type="datetime-local" step="1" />
  3797. DATETIME_LOCAL_MS: 'YYYY-MM-DDTHH:mm:ss.SSS', // <input type="datetime-local" step="0.001" />
  3798. DATE: 'YYYY-MM-DD', // <input type="date" />
  3799. TIME: 'HH:mm', // <input type="time" />
  3800. TIME_SECONDS: 'HH:mm:ss', // <input type="time" step="1" />
  3801. TIME_MS: 'HH:mm:ss.SSS', // <input type="time" step="0.001" />
  3802. WEEK: 'YYYY-[W]WW', // <input type="week" />
  3803. MONTH: 'YYYY-MM' // <input type="month" />
  3804. };
  3805. return hooks;
  3806. })));