tests.js 2.5 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196
  1. ;(function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined'
  3. && typeof require === 'function' ? factory(require('../../moment')) :
  4. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  5. factory(global.moment)
  6. }(this, function (moment) { 'use strict';
  7. /*global QUnit:false*/
  8. var test = QUnit.test;
  9. var expect = QUnit.expect;
  10. function module (name, lifecycle) {
  11. QUnit.module(name, {
  12. setup : function () {
  13. moment.locale('en');
  14. moment.createFromInputFallback = function (config) {
  15. throw new Error('input not handled by moment: ' + config._i);
  16. };
  17. if (lifecycle && lifecycle.setup) {
  18. lifecycle.setup();
  19. }
  20. },
  21. teardown : function () {
  22. if (lifecycle && lifecycle.teardown) {
  23. lifecycle.teardown();
  24. }
  25. }
  26. });
  27. }
  28. function localeModule (name, lifecycle) {
  29. QUnit.module('locale:' + name, {
  30. setup : function () {
  31. moment.locale(name);
  32. moment.createFromInputFallback = function (config) {
  33. throw new Error('input not handled by moment: ' + config._i);
  34. };
  35. if (lifecycle && lifecycle.setup) {
  36. lifecycle.setup();
  37. }
  38. },
  39. teardown : function () {
  40. moment.locale('en');
  41. if (lifecycle && lifecycle.teardown) {
  42. lifecycle.teardown();
  43. }
  44. }
  45. });
  46. }
  47. localeModule('af');
  48. test('parse', function (assert) {
  49. var tests = 'Januarie Jan_Februarie Feb_Maart Mar_April Apr_Mei Mei_Junie Jun_Julie Jul_Augustus Aug_September Sep_Oktober Okt_November Nov_Desember Des'.split('_'), i;
  50. function equalTest(input, mmm, i) {
  51. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  52. }
  53. for (i = 0; i < 12; i++) {
  54. tests[i] = tests[i].split(' ');
  55. equalTest(tests[i][0], 'MMM', i);
  56. equalTest(tests[i][1], 'MMM', i);
  57. equalTest(tests[i][0], 'MMMM', i);
  58. equalTest(tests[i][1], 'MMMM', i);
  59. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  60. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  61. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  62. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  63. }
  64. });
  65. test('format', function (assert) {
  66. var a = [
  67. ['dddd, MMMM Do YYYY, h:mm:ss a', 'Sondag, Februarie 14de 2010, 3:25:50 nm'],
  68. ['ddd, hA', 'Son, 3NM'],
  69. ['M Mo MM MMMM MMM', '2 2de 02 Februarie Feb'],
  70. ['YYYY YY', '2010 10'],
  71. ['D Do DD', '14 14de 14'],
  72. ['d do dddd ddd dd', '0 0de Sondag Son So'],
  73. ['DDD DDDo DDDD', '45 45ste 045'],
  74. ['w wo ww', '6 6de 06'],
  75. ['h hh', '3 03'],
  76. ['H HH', '15 15'],
  77. ['m mm', '25 25'],
  78. ['s ss', '50 50'],
  79. ['a A', 'nm NM'],
  80. ['[the] DDDo [day of the year]', 'the 45ste day of the year'],
  81. ['LT', '15:25'],
  82. ['LTS', '15:25:50'],
  83. ['L', '14/02/2010'],
  84. ['LL', '14 Februarie 2010'],
  85. ['LLL', '14 Februarie 2010 15:25'],
  86. ['LLLL', 'Sondag, 14 Februarie 2010 15:25'],
  87. ['l', '14/2/2010'],
  88. ['ll', '14 Feb 2010'],
  89. ['lll', '14 Feb 2010 15:25'],
  90. ['llll', 'Son, 14 Feb 2010 15:25']
  91. ],
  92. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  93. i;
  94. for (i = 0; i < a.length; i++) {
  95. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  96. }
  97. });
  98. test('format ordinal', function (assert) {
  99. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1ste', '1ste');
  100. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2de', '2de');
  101. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3de', '3de');
  102. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4de', '4de');
  103. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5de', '5de');
  104. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6de', '6de');
  105. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7de', '7de');
  106. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8ste', '8ste');
  107. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9de', '9de');
  108. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10de', '10de');
  109. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11de', '11de');
  110. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12de', '12de');
  111. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13de', '13de');
  112. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14de', '14de');
  113. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15de', '15de');
  114. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16de', '16de');
  115. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17de', '17de');
  116. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18de', '18de');
  117. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19de', '19de');
  118. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20ste', '20ste');
  119. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21ste', '21ste');
  120. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22ste', '22ste');
  121. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23ste', '23ste');
  122. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24ste', '24ste');
  123. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25ste', '25ste');
  124. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26ste', '26ste');
  125. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27ste', '27ste');
  126. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28ste', '28ste');
  127. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29ste', '29ste');
  128. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30ste', '30ste');
  129. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31ste', '31ste');
  130. });
  131. test('format month', function (assert) {
  132. var expected = 'Januarie Jan_Februarie Feb_Maart Mar_April Apr_Mei Mei_Junie Jun_Julie Jul_Augustus Aug_September Sep_Oktober Okt_November Nov_Desember Des'.split('_'), i;
  133. for (i = 0; i < expected.length; i++) {
  134. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  135. }
  136. });
  137. test('format week', function (assert) {
  138. var expected = 'Sondag Son So_Maandag Maa Ma_Dinsdag Din Di_Woensdag Woe Wo_Donderdag Don Do_Vrydag Vry Vr_Saterdag Sat Sa'.split('_'), i;
  139. for (i = 0; i < expected.length; i++) {
  140. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  141. }
  142. });
  143. test('from', function (assert) {
  144. var start = moment([2007, 1, 28]);
  145. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), '\'n paar sekondes', '44 seconds = a few seconds');
  146. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), '\'n minuut', '45 seconds = a minute');
  147. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), '\'n minuut', '89 seconds = a minute');
  148. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minute', '90 seconds = 2 minutes');
  149. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minute', '44 minutes = 44 minutes');
  150. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), '\'n uur', '45 minutes = an hour');
  151. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), '\'n uur', '89 minutes = an hour');
  152. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 ure', '90 minutes = 2 hours');
  153. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ure', '5 hours = 5 hours');
  154. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 ure', '21 hours = 21 hours');
  155. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), '\'n dag', '22 hours = a day');
  156. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), '\'n dag', '35 hours = a day');
  157. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dae', '36 hours = 2 days');
  158. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), '\'n dag', '1 day = a day');
  159. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dae', '5 days = 5 days');
  160. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dae', '25 days = 25 days');
  161. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), '\'n maand', '26 days = a month');
  162. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), '\'n maand', '30 days = a month');
  163. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), '\'n maand', '43 days = a month');
  164. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 maande', '46 days = 2 months');
  165. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 maande', '75 days = 2 months');
  166. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 maande', '76 days = 3 months');
  167. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), '\'n maand', '1 month = a month');
  168. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 maande', '5 months = 5 months');
  169. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), '\'n jaar', '345 days = a year');
  170. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 jaar', '548 days = 2 years');
  171. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), '\'n jaar', '1 year = a year');
  172. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 jaar', '5 years = 5 years');
  173. });
  174. test('suffix', function (assert) {
  175. assert.equal(moment(30000).from(0), 'oor \'n paar sekondes', 'prefix');
  176. assert.equal(moment(0).from(30000), '\'n paar sekondes gelede', 'suffix');
  177. });
  178. test('now from now', function (assert) {
  179. assert.equal(moment().fromNow(), '\'n paar sekondes gelede', 'now from now should display as in the past');
  180. });
  181. test('fromNow', function (assert) {
  182. assert.equal(moment().add({s: 30}).fromNow(), 'oor \'n paar sekondes', 'in a few seconds');
  183. assert.equal(moment().add({d: 5}).fromNow(), 'oor 5 dae', 'in 5 days');
  184. });
  185. test('calendar day', function (assert) {
  186. var a = moment().hours(2).minutes(0).seconds(0);
  187. assert.equal(moment(a).calendar(), 'Vandag om 02:00', 'today at the same time');
  188. assert.equal(moment(a).add({m: 25}).calendar(), 'Vandag om 02:25', 'Now plus 25 min');
  189. assert.equal(moment(a).add({h: 1}).calendar(), 'Vandag om 03:00', 'Now plus 1 hour');
  190. assert.equal(moment(a).add({d: 1}).calendar(), 'Môre om 02:00', 'tomorrow at the same time');
  191. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Vandag om 01:00', 'Now minus 1 hour');
  192. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Gister om 02:00', 'yesterday at the same time');
  193. });
  194. test('calendar next week', function (assert) {
  195. var i, m;
  196. for (i = 2; i < 7; i++) {
  197. m = moment().add({d: i});
  198. assert.equal(m.calendar(), m.format('dddd [om] LT'), 'Today + ' + i + ' days current time');
  199. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  200. assert.equal(m.calendar(), m.format('dddd [om] LT'), 'Today + ' + i + ' days beginning of day');
  201. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  202. assert.equal(m.calendar(), m.format('dddd [om] LT'), 'Today + ' + i + ' days end of day');
  203. }
  204. });
  205. test('calendar last week', function (assert) {
  206. var i, m;
  207. for (i = 2; i < 7; i++) {
  208. m = moment().subtract({d: i});
  209. assert.equal(m.calendar(), m.format('[Laas] dddd [om] LT'), 'Today - ' + i + ' days current time');
  210. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  211. assert.equal(m.calendar(), m.format('[Laas] dddd [om] LT'), 'Today - ' + i + ' days beginning of day');
  212. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  213. assert.equal(m.calendar(), m.format('[Laas] dddd [om] LT'), 'Today - ' + i + ' days end of day');
  214. }
  215. });
  216. test('calendar all else', function (assert) {
  217. var weeksAgo = moment().subtract({w: 1}),
  218. weeksFromNow = moment().add({w: 1});
  219. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  220. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  221. weeksAgo = moment().subtract({w: 2});
  222. weeksFromNow = moment().add({w: 2});
  223. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  224. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  225. });
  226. test('weeks year starting sunday', function (assert) {
  227. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  228. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  229. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  230. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  231. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  232. });
  233. test('weeks year starting monday', function (assert) {
  234. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  235. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  236. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  237. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  238. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  239. });
  240. test('weeks year starting tuesday', function (assert) {
  241. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  242. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  243. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  244. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  245. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  246. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  247. });
  248. test('weeks year starting wednesday', function (assert) {
  249. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  250. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  251. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  252. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  253. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  254. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  255. });
  256. test('weeks year starting thursday', function (assert) {
  257. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  258. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  259. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  260. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  261. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  262. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  263. });
  264. test('weeks year starting friday', function (assert) {
  265. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  266. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  267. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  268. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  269. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  270. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  271. });
  272. test('weeks year starting saturday', function (assert) {
  273. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  274. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  275. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  276. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  277. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  278. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  279. });
  280. test('weeks year starting sunday formatted', function (assert) {
  281. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52ste', 'Jan 1 2012 should be week 52');
  282. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1ste', 'Jan 2 2012 should be week 1');
  283. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1ste', 'Jan 8 2012 should be week 1');
  284. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2de', 'Jan 9 2012 should be week 2');
  285. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2de', 'Jan 15 2012 should be week 2');
  286. });
  287. test('lenient ordinal parsing', function (assert) {
  288. var i, ordinalStr, testMoment;
  289. for (i = 1; i <= 31; ++i) {
  290. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  291. testMoment = moment(ordinalStr, 'YYYY MM Do');
  292. assert.equal(testMoment.year(), 2014,
  293. 'lenient ordinal parsing ' + i + ' year check');
  294. assert.equal(testMoment.month(), 0,
  295. 'lenient ordinal parsing ' + i + ' month check');
  296. assert.equal(testMoment.date(), i,
  297. 'lenient ordinal parsing ' + i + ' date check');
  298. }
  299. });
  300. test('lenient ordinal parsing of number', function (assert) {
  301. var i, testMoment;
  302. for (i = 1; i <= 31; ++i) {
  303. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  304. assert.equal(testMoment.year(), 2014,
  305. 'lenient ordinal parsing of number ' + i + ' year check');
  306. assert.equal(testMoment.month(), 0,
  307. 'lenient ordinal parsing of number ' + i + ' month check');
  308. assert.equal(testMoment.date(), i,
  309. 'lenient ordinal parsing of number ' + i + ' date check');
  310. }
  311. });
  312. test('strict ordinal parsing', function (assert) {
  313. var i, ordinalStr, testMoment;
  314. for (i = 1; i <= 31; ++i) {
  315. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  316. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  317. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  318. }
  319. });
  320. }));
  321. ;(function (global, factory) {
  322. typeof exports === 'object' && typeof module !== 'undefined'
  323. && typeof require === 'function' ? factory(require('../../moment')) :
  324. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  325. factory(global.moment)
  326. }(this, function (moment) { 'use strict';
  327. /*global QUnit:false*/
  328. var test = QUnit.test;
  329. var expect = QUnit.expect;
  330. function module (name, lifecycle) {
  331. QUnit.module(name, {
  332. setup : function () {
  333. moment.locale('en');
  334. moment.createFromInputFallback = function (config) {
  335. throw new Error('input not handled by moment: ' + config._i);
  336. };
  337. if (lifecycle && lifecycle.setup) {
  338. lifecycle.setup();
  339. }
  340. },
  341. teardown : function () {
  342. if (lifecycle && lifecycle.teardown) {
  343. lifecycle.teardown();
  344. }
  345. }
  346. });
  347. }
  348. function localeModule (name, lifecycle) {
  349. QUnit.module('locale:' + name, {
  350. setup : function () {
  351. moment.locale(name);
  352. moment.createFromInputFallback = function (config) {
  353. throw new Error('input not handled by moment: ' + config._i);
  354. };
  355. if (lifecycle && lifecycle.setup) {
  356. lifecycle.setup();
  357. }
  358. },
  359. teardown : function () {
  360. moment.locale('en');
  361. if (lifecycle && lifecycle.teardown) {
  362. lifecycle.teardown();
  363. }
  364. }
  365. });
  366. }
  367. localeModule('ar-ma');
  368. test('parse', function (assert) {
  369. var tests = 'يناير:يناير_فبراير:فبراير_مارس:مارس_أبريل:أبريل_ماي:ماي_يونيو:يونيو_يوليوز:يوليوز_غشت:غشت_شتنبر:شتنبر_أكتوبر:أكتوبر_نونبر:نونبر_دجنبر:دجنبر'.split('_'), i;
  370. function equalTest(input, mmm, i) {
  371. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  372. }
  373. for (i = 0; i < 12; i++) {
  374. tests[i] = tests[i].split(':');
  375. equalTest(tests[i][0], 'MMM', i);
  376. equalTest(tests[i][1], 'MMM', i);
  377. equalTest(tests[i][0], 'MMMM', i);
  378. equalTest(tests[i][1], 'MMMM', i);
  379. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  380. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  381. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  382. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  383. }
  384. });
  385. test('format', function (assert) {
  386. var a = [
  387. ['dddd, MMMM Do YYYY, h:mm:ss a', 'الأحد, فبراير 14 2010, 3:25:50 pm'],
  388. ['ddd, hA', 'احد, 3PM'],
  389. ['M Mo MM MMMM MMM', '2 2 02 فبراير فبراير'],
  390. ['YYYY YY', '2010 10'],
  391. ['D Do DD', '14 14 14'],
  392. ['d do dddd ddd dd', '0 0 الأحد احد ح'],
  393. ['DDD DDDo DDDD', '45 45 045'],
  394. ['w wo ww', '8 8 08'],
  395. ['h hh', '3 03'],
  396. ['H HH', '15 15'],
  397. ['m mm', '25 25'],
  398. ['s ss', '50 50'],
  399. ['a A', 'pm PM'],
  400. ['[the] DDDo [day of the year]', 'the 45 day of the year'],
  401. ['LT', '15:25'],
  402. ['LTS', '15:25:50'],
  403. ['L', '14/02/2010'],
  404. ['LL', '14 فبراير 2010'],
  405. ['LLL', '14 فبراير 2010 15:25'],
  406. ['LLLL', 'الأحد 14 فبراير 2010 15:25'],
  407. ['l', '14/2/2010'],
  408. ['ll', '14 فبراير 2010'],
  409. ['lll', '14 فبراير 2010 15:25'],
  410. ['llll', 'احد 14 فبراير 2010 15:25']
  411. ],
  412. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  413. i;
  414. for (i = 0; i < a.length; i++) {
  415. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  416. }
  417. });
  418. test('format ordinal', function (assert) {
  419. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1');
  420. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2');
  421. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3');
  422. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4');
  423. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5');
  424. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6');
  425. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7');
  426. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8');
  427. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9');
  428. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10');
  429. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11');
  430. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12');
  431. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13');
  432. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14');
  433. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15');
  434. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16');
  435. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17');
  436. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18');
  437. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19');
  438. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20');
  439. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21');
  440. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22');
  441. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23');
  442. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24');
  443. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25');
  444. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26');
  445. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27');
  446. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28');
  447. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29');
  448. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30');
  449. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31');
  450. });
  451. test('format month', function (assert) {
  452. var expected = 'يناير يناير_فبراير فبراير_مارس مارس_أبريل أبريل_ماي ماي_يونيو يونيو_يوليوز يوليوز_غشت غشت_شتنبر شتنبر_أكتوبر أكتوبر_نونبر نونبر_دجنبر دجنبر'.split('_'), i;
  453. for (i = 0; i < expected.length; i++) {
  454. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  455. }
  456. });
  457. test('format week', function (assert) {
  458. var expected = 'الأحد احد ح_الإتنين اتنين ن_الثلاثاء ثلاثاء ث_الأربعاء اربعاء ر_الخميس خميس خ_الجمعة جمعة ج_السبت سبت س'.split('_'), i;
  459. for (i = 0; i < expected.length; i++) {
  460. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  461. }
  462. });
  463. test('from', function (assert) {
  464. var start = moment([2007, 1, 28]);
  465. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ثوان', '44 seconds = a few seconds');
  466. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'دقيقة', '45 seconds = a minute');
  467. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'دقيقة', '89 seconds = a minute');
  468. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 دقائق', '90 seconds = 2 minutes');
  469. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 دقائق', '44 minutes = 44 minutes');
  470. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ساعة', '45 minutes = an hour');
  471. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ساعة', '89 minutes = an hour');
  472. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 ساعات', '90 minutes = 2 hours');
  473. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ساعات', '5 hours = 5 hours');
  474. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 ساعات', '21 hours = 21 hours');
  475. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'يوم', '22 hours = a day');
  476. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'يوم', '35 hours = a day');
  477. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 أيام', '36 hours = 2 days');
  478. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'يوم', '1 day = a day');
  479. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 أيام', '5 days = 5 days');
  480. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 أيام', '25 days = 25 days');
  481. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'شهر', '26 days = a month');
  482. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'شهر', '30 days = a month');
  483. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'شهر', '43 days = a month');
  484. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 أشهر', '46 days = 2 months');
  485. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 أشهر', '75 days = 2 months');
  486. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 أشهر', '76 days = 3 months');
  487. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'شهر', '1 month = a month');
  488. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 أشهر', '5 months = 5 months');
  489. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'سنة', '345 days = a year');
  490. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 سنوات', '548 days = 2 years');
  491. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'سنة', '1 year = a year');
  492. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 سنوات', '5 years = 5 years');
  493. });
  494. test('suffix', function (assert) {
  495. assert.equal(moment(30000).from(0), 'في ثوان', 'prefix');
  496. assert.equal(moment(0).from(30000), 'منذ ثوان', 'suffix');
  497. });
  498. test('now from now', function (assert) {
  499. assert.equal(moment().fromNow(), 'منذ ثوان', 'now from now should display as in the past');
  500. });
  501. test('fromNow', function (assert) {
  502. assert.equal(moment().add({s: 30}).fromNow(), 'في ثوان', 'in a few seconds');
  503. assert.equal(moment().add({d: 5}).fromNow(), 'في 5 أيام', 'in 5 days');
  504. });
  505. test('calendar day', function (assert) {
  506. var a = moment().hours(2).minutes(0).seconds(0);
  507. assert.equal(moment(a).calendar(), 'اليوم على الساعة 02:00', 'today at the same time');
  508. assert.equal(moment(a).add({m: 25}).calendar(), 'اليوم على الساعة 02:25', 'Now plus 25 min');
  509. assert.equal(moment(a).add({h: 1}).calendar(), 'اليوم على الساعة 03:00', 'Now plus 1 hour');
  510. assert.equal(moment(a).add({d: 1}).calendar(), 'غدا على الساعة 02:00', 'tomorrow at the same time');
  511. assert.equal(moment(a).subtract({h: 1}).calendar(), 'اليوم على الساعة 01:00', 'Now minus 1 hour');
  512. assert.equal(moment(a).subtract({d: 1}).calendar(), 'أمس على الساعة 02:00', 'yesterday at the same time');
  513. });
  514. test('calendar next week', function (assert) {
  515. var i, m;
  516. for (i = 2; i < 7; i++) {
  517. m = moment().add({d: i});
  518. assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today + ' + i + ' days current time');
  519. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  520. assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today + ' + i + ' days beginning of day');
  521. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  522. assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today + ' + i + ' days end of day');
  523. }
  524. });
  525. test('calendar last week', function (assert) {
  526. var i, m;
  527. for (i = 2; i < 7; i++) {
  528. m = moment().subtract({d: i});
  529. assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today - ' + i + ' days current time');
  530. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  531. assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today - ' + i + ' days beginning of day');
  532. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  533. assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today - ' + i + ' days end of day');
  534. }
  535. });
  536. test('calendar all else', function (assert) {
  537. var weeksAgo = moment().subtract({w: 1}),
  538. weeksFromNow = moment().add({w: 1});
  539. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  540. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  541. weeksAgo = moment().subtract({w: 2});
  542. weeksFromNow = moment().add({w: 2});
  543. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  544. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  545. });
  546. test('weeks year starting sunday', function (assert) {
  547. assert.equal(moment([2011, 11, 31]).week(), 1, 'Dec 31 2011 should be week 1');
  548. assert.equal(moment([2012, 0, 6]).week(), 1, 'Jan 6 2012 should be week 1');
  549. assert.equal(moment([2012, 0, 7]).week(), 2, 'Jan 7 2012 should be week 2');
  550. assert.equal(moment([2012, 0, 13]).week(), 2, 'Jan 13 2012 should be week 2');
  551. assert.equal(moment([2012, 0, 14]).week(), 3, 'Jan 14 2012 should be week 3');
  552. });
  553. test('weeks year starting monday', function (assert) {
  554. assert.equal(moment([2006, 11, 30]).week(), 1, 'Dec 30 2006 should be week 1');
  555. assert.equal(moment([2007, 0, 5]).week(), 1, 'Jan 5 2007 should be week 1');
  556. assert.equal(moment([2007, 0, 6]).week(), 2, 'Jan 6 2007 should be week 2');
  557. assert.equal(moment([2007, 0, 12]).week(), 2, 'Jan 12 2007 should be week 2');
  558. assert.equal(moment([2007, 0, 13]).week(), 3, 'Jan 13 2007 should be week 3');
  559. });
  560. test('weeks year starting tuesday', function (assert) {
  561. assert.equal(moment([2007, 11, 29]).week(), 1, 'Dec 29 2007 should be week 1');
  562. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  563. assert.equal(moment([2008, 0, 4]).week(), 1, 'Jan 4 2008 should be week 1');
  564. assert.equal(moment([2008, 0, 5]).week(), 2, 'Jan 5 2008 should be week 2');
  565. assert.equal(moment([2008, 0, 11]).week(), 2, 'Jan 11 2008 should be week 2');
  566. assert.equal(moment([2008, 0, 12]).week(), 3, 'Jan 12 2008 should be week 3');
  567. });
  568. test('weeks year starting wednesday', function (assert) {
  569. assert.equal(moment([2002, 11, 28]).week(), 1, 'Dec 28 2002 should be week 1');
  570. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  571. assert.equal(moment([2003, 0, 3]).week(), 1, 'Jan 3 2003 should be week 1');
  572. assert.equal(moment([2003, 0, 4]).week(), 2, 'Jan 4 2003 should be week 2');
  573. assert.equal(moment([2003, 0, 10]).week(), 2, 'Jan 10 2003 should be week 2');
  574. assert.equal(moment([2003, 0, 11]).week(), 3, 'Jan 11 2003 should be week 3');
  575. });
  576. test('weeks year starting thursday', function (assert) {
  577. assert.equal(moment([2008, 11, 27]).week(), 1, 'Dec 27 2008 should be week 1');
  578. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  579. assert.equal(moment([2009, 0, 2]).week(), 1, 'Jan 2 2009 should be week 1');
  580. assert.equal(moment([2009, 0, 3]).week(), 2, 'Jan 3 2009 should be week 2');
  581. assert.equal(moment([2009, 0, 9]).week(), 2, 'Jan 9 2009 should be week 2');
  582. assert.equal(moment([2009, 0, 10]).week(), 3, 'Jan 10 2009 should be week 3');
  583. });
  584. test('weeks year starting friday', function (assert) {
  585. assert.equal(moment([2009, 11, 26]).week(), 1, 'Dec 26 2009 should be week 1');
  586. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  587. assert.equal(moment([2010, 0, 2]).week(), 2, 'Jan 2 2010 should be week 2');
  588. assert.equal(moment([2010, 0, 8]).week(), 2, 'Jan 8 2010 should be week 2');
  589. assert.equal(moment([2010, 0, 9]).week(), 3, 'Jan 9 2010 should be week 3');
  590. });
  591. test('weeks year starting saturday', function (assert) {
  592. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  593. assert.equal(moment([2011, 0, 7]).week(), 1, 'Jan 7 2011 should be week 1');
  594. assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2');
  595. assert.equal(moment([2011, 0, 14]).week(), 2, 'Jan 14 2011 should be week 2');
  596. assert.equal(moment([2011, 0, 15]).week(), 3, 'Jan 15 2011 should be week 3');
  597. });
  598. test('weeks year starting sunday formatted', function (assert) {
  599. assert.equal(moment([2011, 11, 31]).format('w ww wo'), '1 01 1', 'Dec 31 2011 should be week 1');
  600. assert.equal(moment([2012, 0, 6]).format('w ww wo'), '1 01 1', 'Jan 6 2012 should be week 1');
  601. assert.equal(moment([2012, 0, 7]).format('w ww wo'), '2 02 2', 'Jan 7 2012 should be week 2');
  602. assert.equal(moment([2012, 0, 13]).format('w ww wo'), '2 02 2', 'Jan 13 2012 should be week 2');
  603. assert.equal(moment([2012, 0, 14]).format('w ww wo'), '3 03 3', 'Jan 14 2012 should be week 3');
  604. });
  605. test('lenient ordinal parsing', function (assert) {
  606. var i, ordinalStr, testMoment;
  607. for (i = 1; i <= 31; ++i) {
  608. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  609. testMoment = moment(ordinalStr, 'YYYY MM Do');
  610. assert.equal(testMoment.year(), 2014,
  611. 'lenient ordinal parsing ' + i + ' year check');
  612. assert.equal(testMoment.month(), 0,
  613. 'lenient ordinal parsing ' + i + ' month check');
  614. assert.equal(testMoment.date(), i,
  615. 'lenient ordinal parsing ' + i + ' date check');
  616. }
  617. });
  618. test('lenient ordinal parsing of number', function (assert) {
  619. var i, testMoment;
  620. for (i = 1; i <= 31; ++i) {
  621. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  622. assert.equal(testMoment.year(), 2014,
  623. 'lenient ordinal parsing of number ' + i + ' year check');
  624. assert.equal(testMoment.month(), 0,
  625. 'lenient ordinal parsing of number ' + i + ' month check');
  626. assert.equal(testMoment.date(), i,
  627. 'lenient ordinal parsing of number ' + i + ' date check');
  628. }
  629. });
  630. test('strict ordinal parsing', function (assert) {
  631. var i, ordinalStr, testMoment;
  632. for (i = 1; i <= 31; ++i) {
  633. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  634. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  635. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  636. }
  637. });
  638. }));
  639. ;(function (global, factory) {
  640. typeof exports === 'object' && typeof module !== 'undefined'
  641. && typeof require === 'function' ? factory(require('../../moment')) :
  642. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  643. factory(global.moment)
  644. }(this, function (moment) { 'use strict';
  645. /*global QUnit:false*/
  646. var test = QUnit.test;
  647. var expect = QUnit.expect;
  648. function module (name, lifecycle) {
  649. QUnit.module(name, {
  650. setup : function () {
  651. moment.locale('en');
  652. moment.createFromInputFallback = function (config) {
  653. throw new Error('input not handled by moment: ' + config._i);
  654. };
  655. if (lifecycle && lifecycle.setup) {
  656. lifecycle.setup();
  657. }
  658. },
  659. teardown : function () {
  660. if (lifecycle && lifecycle.teardown) {
  661. lifecycle.teardown();
  662. }
  663. }
  664. });
  665. }
  666. function localeModule (name, lifecycle) {
  667. QUnit.module('locale:' + name, {
  668. setup : function () {
  669. moment.locale(name);
  670. moment.createFromInputFallback = function (config) {
  671. throw new Error('input not handled by moment: ' + config._i);
  672. };
  673. if (lifecycle && lifecycle.setup) {
  674. lifecycle.setup();
  675. }
  676. },
  677. teardown : function () {
  678. moment.locale('en');
  679. if (lifecycle && lifecycle.teardown) {
  680. lifecycle.teardown();
  681. }
  682. }
  683. });
  684. }
  685. localeModule('ar-sa');
  686. test('parse', function (assert) {
  687. var tests = 'يناير:يناير_فبراير:فبراير_مارس:مارس_أبريل:أبريل_مايو:مايو_يونيو:يونيو_يوليو:يوليو_أغسطس:أغسطس_سبتمبر:سبتمبر_أكتوبر:أكتوبر_نوفمبر:نوفمبر_ديسمبر:ديسمبر'.split('_'), i;
  688. function equalTest(input, mmm, i) {
  689. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1) + ' instead is month ' + moment(input, mmm).month());
  690. }
  691. for (i = 0; i < 12; i++) {
  692. tests[i] = tests[i].split(':');
  693. equalTest(tests[i][0], 'MMM', i);
  694. equalTest(tests[i][1], 'MMM', i);
  695. equalTest(tests[i][0], 'MMMM', i);
  696. equalTest(tests[i][1], 'MMMM', i);
  697. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  698. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  699. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  700. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  701. }
  702. });
  703. test('format', function (assert) {
  704. var a = [
  705. ['dddd, MMMM Do YYYY, h:mm:ss a', 'الأحد، فبراير ١٤ ٢٠١٠، ٣:٢٥:٥٠ م'],
  706. ['ddd, hA', 'أحد، ٣م'],
  707. ['M Mo MM MMMM MMM', '٢ ٢ ٠٢ فبراير فبراير'],
  708. ['YYYY YY', '٢٠١٠ ١٠'],
  709. ['D Do DD', '١٤ ١٤ ١٤'],
  710. ['d do dddd ddd dd', '٠ ٠ الأحد أحد ح'],
  711. ['DDD DDDo DDDD', '٤٥ ٤٥ ٠٤٥'],
  712. ['w wo ww', '٨ ٨ ٠٨'],
  713. ['h hh', '٣ ٠٣'],
  714. ['H HH', '١٥ ١٥'],
  715. ['m mm', '٢٥ ٢٥'],
  716. ['s ss', '٥٠ ٥٠'],
  717. ['a A', 'م م'],
  718. ['[the] DDDo [day of the year]', 'the ٤٥ day of the year'],
  719. ['LT', '١٥:٢٥'],
  720. ['LTS', '١٥:٢٥:٥٠'],
  721. ['L', '١٤/٠٢/٢٠١٠'],
  722. ['LL', '١٤ فبراير ٢٠١٠'],
  723. ['LLL', '١٤ فبراير ٢٠١٠ ١٥:٢٥'],
  724. ['LLLL', 'الأحد ١٤ فبراير ٢٠١٠ ١٥:٢٥'],
  725. ['l', '١٤/٢/٢٠١٠'],
  726. ['ll', '١٤ فبراير ٢٠١٠'],
  727. ['lll', '١٤ فبراير ٢٠١٠ ١٥:٢٥'],
  728. ['llll', 'أحد ١٤ فبراير ٢٠١٠ ١٥:٢٥']
  729. ],
  730. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  731. i;
  732. for (i = 0; i < a.length; i++) {
  733. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  734. }
  735. });
  736. test('format ordinal', function (assert) {
  737. assert.equal(moment([2011, 0, 1]).format('DDDo'), '١', '1');
  738. assert.equal(moment([2011, 0, 2]).format('DDDo'), '٢', '2');
  739. assert.equal(moment([2011, 0, 3]).format('DDDo'), '٣', '3');
  740. assert.equal(moment([2011, 0, 4]).format('DDDo'), '٤', '4');
  741. assert.equal(moment([2011, 0, 5]).format('DDDo'), '٥', '5');
  742. assert.equal(moment([2011, 0, 6]).format('DDDo'), '٦', '6');
  743. assert.equal(moment([2011, 0, 7]).format('DDDo'), '٧', '7');
  744. assert.equal(moment([2011, 0, 8]).format('DDDo'), '٨', '8');
  745. assert.equal(moment([2011, 0, 9]).format('DDDo'), '٩', '9');
  746. assert.equal(moment([2011, 0, 10]).format('DDDo'), '١٠', '10');
  747. assert.equal(moment([2011, 0, 11]).format('DDDo'), '١١', '11');
  748. assert.equal(moment([2011, 0, 12]).format('DDDo'), '١٢', '12');
  749. assert.equal(moment([2011, 0, 13]).format('DDDo'), '١٣', '13');
  750. assert.equal(moment([2011, 0, 14]).format('DDDo'), '١٤', '14');
  751. assert.equal(moment([2011, 0, 15]).format('DDDo'), '١٥', '15');
  752. assert.equal(moment([2011, 0, 16]).format('DDDo'), '١٦', '16');
  753. assert.equal(moment([2011, 0, 17]).format('DDDo'), '١٧', '17');
  754. assert.equal(moment([2011, 0, 18]).format('DDDo'), '١٨', '18');
  755. assert.equal(moment([2011, 0, 19]).format('DDDo'), '١٩', '19');
  756. assert.equal(moment([2011, 0, 20]).format('DDDo'), '٢٠', '20');
  757. assert.equal(moment([2011, 0, 21]).format('DDDo'), '٢١', '21');
  758. assert.equal(moment([2011, 0, 22]).format('DDDo'), '٢٢', '22');
  759. assert.equal(moment([2011, 0, 23]).format('DDDo'), '٢٣', '23');
  760. assert.equal(moment([2011, 0, 24]).format('DDDo'), '٢٤', '24');
  761. assert.equal(moment([2011, 0, 25]).format('DDDo'), '٢٥', '25');
  762. assert.equal(moment([2011, 0, 26]).format('DDDo'), '٢٦', '26');
  763. assert.equal(moment([2011, 0, 27]).format('DDDo'), '٢٧', '27');
  764. assert.equal(moment([2011, 0, 28]).format('DDDo'), '٢٨', '28');
  765. assert.equal(moment([2011, 0, 29]).format('DDDo'), '٢٩', '29');
  766. assert.equal(moment([2011, 0, 30]).format('DDDo'), '٣٠', '30');
  767. assert.equal(moment([2011, 0, 31]).format('DDDo'), '٣١', '31');
  768. });
  769. test('format month', function (assert) {
  770. var expected = 'يناير يناير_فبراير فبراير_مارس مارس_أبريل أبريل_مايو مايو_يونيو يونيو_يوليو يوليو_أغسطس أغسطس_سبتمبر سبتمبر_أكتوبر أكتوبر_نوفمبر نوفمبر_ديسمبر ديسمبر'.split('_'), i;
  771. for (i = 0; i < expected.length; i++) {
  772. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  773. }
  774. });
  775. test('format week', function (assert) {
  776. var expected = 'الأحد أحد ح_الإثنين إثنين ن_الثلاثاء ثلاثاء ث_الأربعاء أربعاء ر_الخميس خميس خ_الجمعة جمعة ج_السبت سبت س'.split('_'), i;
  777. for (i = 0; i < expected.length; i++) {
  778. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  779. }
  780. });
  781. test('from', function (assert) {
  782. var start = moment([2007, 1, 28]);
  783. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ثوان', '44 seconds = a few seconds');
  784. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'دقيقة', '45 seconds = a minute');
  785. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'دقيقة', '89 seconds = a minute');
  786. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '٢ دقائق', '90 seconds = 2 minutes');
  787. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '٤٤ دقائق', '44 minutes = 44 minutes');
  788. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ساعة', '45 minutes = an hour');
  789. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ساعة', '89 minutes = an hour');
  790. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '٢ ساعات', '90 minutes = 2 hours');
  791. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '٥ ساعات', '5 hours = 5 hours');
  792. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '٢١ ساعات', '21 hours = 21 hours');
  793. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'يوم', '22 hours = a day');
  794. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'يوم', '35 hours = a day');
  795. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '٢ أيام', '36 hours = 2 days');
  796. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'يوم', '1 day = a day');
  797. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '٥ أيام', '5 days = 5 days');
  798. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '٢٥ أيام', '25 days = 25 days');
  799. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'شهر', '26 days = a month');
  800. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'شهر', '30 days = a month');
  801. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'شهر', '43 days = a month');
  802. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '٢ أشهر', '46 days = 2 months');
  803. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '٢ أشهر', '75 days = 2 months');
  804. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '٣ أشهر', '76 days = 3 months');
  805. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'شهر', '1 month = a month');
  806. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '٥ أشهر', '5 months = 5 months');
  807. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'سنة', '345 days = a year');
  808. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '٢ سنوات', '548 days = 2 years');
  809. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'سنة', '1 year = a year');
  810. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '٥ سنوات', '5 years = 5 years');
  811. });
  812. test('suffix', function (assert) {
  813. assert.equal(moment(30000).from(0), 'في ثوان', 'prefix');
  814. assert.equal(moment(0).from(30000), 'منذ ثوان', 'suffix');
  815. });
  816. test('now from now', function (assert) {
  817. assert.equal(moment().fromNow(), 'منذ ثوان', 'now from now should display as in the past');
  818. });
  819. test('fromNow', function (assert) {
  820. assert.equal(moment().add({s: 30}).fromNow(), 'في ثوان', 'in a few seconds');
  821. assert.equal(moment().add({d: 5}).fromNow(), 'في ٥ أيام', 'in 5 days');
  822. });
  823. test('calendar day', function (assert) {
  824. var a = moment().hours(2).minutes(0).seconds(0);
  825. assert.equal(moment(a).calendar(), 'اليوم على الساعة ٠٢:٠٠', 'today at the same time');
  826. assert.equal(moment(a).add({m: 25}).calendar(), 'اليوم على الساعة ٠٢:٢٥', 'Now plus 25 min');
  827. assert.equal(moment(a).add({h: 1}).calendar(), 'اليوم على الساعة ٠٣:٠٠', 'Now plus 1 hour');
  828. assert.equal(moment(a).add({d: 1}).calendar(), 'غدا على الساعة ٠٢:٠٠', 'tomorrow at the same time');
  829. assert.equal(moment(a).subtract({h: 1}).calendar(), 'اليوم على الساعة ٠١:٠٠', 'Now minus 1 hour');
  830. assert.equal(moment(a).subtract({d: 1}).calendar(), 'أمس على الساعة ٠٢:٠٠', 'yesterday at the same time');
  831. });
  832. test('calendar next week', function (assert) {
  833. var i, m;
  834. for (i = 2; i < 7; i++) {
  835. m = moment().add({d: i});
  836. assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today + ' + i + ' days current time');
  837. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  838. assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today + ' + i + ' days beginning of day');
  839. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  840. assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today + ' + i + ' days end of day');
  841. }
  842. });
  843. test('calendar last week', function (assert) {
  844. var i, m;
  845. for (i = 2; i < 7; i++) {
  846. m = moment().subtract({d: i});
  847. assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today - ' + i + ' days current time');
  848. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  849. assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today - ' + i + ' days beginning of day');
  850. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  851. assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today - ' + i + ' days end of day');
  852. }
  853. });
  854. test('calendar all else', function (assert) {
  855. var weeksAgo = moment().subtract({w: 1}),
  856. weeksFromNow = moment().add({w: 1});
  857. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  858. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  859. weeksAgo = moment().subtract({w: 2});
  860. weeksFromNow = moment().add({w: 2});
  861. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  862. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  863. });
  864. test('weeks year starting sunday', function (assert) {
  865. assert.equal(moment([2011, 11, 31]).week(), 1, 'Dec 31 2011 should be week 1');
  866. assert.equal(moment([2012, 0, 6]).week(), 1, 'Jan 6 2012 should be week 1');
  867. assert.equal(moment([2012, 0, 7]).week(), 2, 'Jan 7 2012 should be week 2');
  868. assert.equal(moment([2012, 0, 13]).week(), 2, 'Jan 13 2012 should be week 2');
  869. assert.equal(moment([2012, 0, 14]).week(), 3, 'Jan 14 2012 should be week 3');
  870. });
  871. test('weeks year starting monday', function (assert) {
  872. assert.equal(moment([2006, 11, 30]).week(), 1, 'Dec 30 2006 should be week 1');
  873. assert.equal(moment([2007, 0, 5]).week(), 1, 'Jan 5 2007 should be week 1');
  874. assert.equal(moment([2007, 0, 6]).week(), 2, 'Jan 6 2007 should be week 2');
  875. assert.equal(moment([2007, 0, 12]).week(), 2, 'Jan 12 2007 should be week 2');
  876. assert.equal(moment([2007, 0, 13]).week(), 3, 'Jan 13 2007 should be week 3');
  877. });
  878. test('weeks year starting tuesday', function (assert) {
  879. assert.equal(moment([2007, 11, 29]).week(), 1, 'Dec 29 2007 should be week 1');
  880. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  881. assert.equal(moment([2008, 0, 4]).week(), 1, 'Jan 4 2008 should be week 1');
  882. assert.equal(moment([2008, 0, 5]).week(), 2, 'Jan 5 2008 should be week 2');
  883. assert.equal(moment([2008, 0, 11]).week(), 2, 'Jan 11 2008 should be week 2');
  884. assert.equal(moment([2008, 0, 12]).week(), 3, 'Jan 12 2008 should be week 3');
  885. });
  886. test('weeks year starting wednesday', function (assert) {
  887. assert.equal(moment([2002, 11, 28]).week(), 1, 'Dec 28 2002 should be week 1');
  888. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  889. assert.equal(moment([2003, 0, 3]).week(), 1, 'Jan 3 2003 should be week 1');
  890. assert.equal(moment([2003, 0, 4]).week(), 2, 'Jan 4 2003 should be week 2');
  891. assert.equal(moment([2003, 0, 10]).week(), 2, 'Jan 10 2003 should be week 2');
  892. assert.equal(moment([2003, 0, 11]).week(), 3, 'Jan 11 2003 should be week 3');
  893. assert.equal(moment('2003 1 6', 'gggg w d').format('YYYY-MM-DD'), '٢٠٠٢-١٢-٢٨', 'Week 1 of 2003 should be Dec 28 2002');
  894. assert.equal(moment('2003 1 0', 'gggg w e').format('YYYY-MM-DD'), '٢٠٠٢-١٢-٢٨', 'Week 1 of 2003 should be Dec 28 2002');
  895. assert.equal(moment('2003 1 6', 'gggg w d').format('gggg w d'), '٢٠٠٣ ١ ٦', 'Saturday of week 1 of 2003 parsed should be formatted as 2003 1 6');
  896. assert.equal(moment('2003 1 0', 'gggg w e').format('gggg w e'), '٢٠٠٣ ١ ٠', '1st day of week 1 of 2003 parsed should be formatted as 2003 1 0');
  897. });
  898. test('weeks year starting thursday', function (assert) {
  899. assert.equal(moment([2008, 11, 27]).week(), 1, 'Dec 27 2008 should be week 1');
  900. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  901. assert.equal(moment([2009, 0, 2]).week(), 1, 'Jan 2 2009 should be week 1');
  902. assert.equal(moment([2009, 0, 3]).week(), 2, 'Jan 3 2009 should be week 2');
  903. assert.equal(moment([2009, 0, 9]).week(), 2, 'Jan 9 2009 should be week 2');
  904. assert.equal(moment([2009, 0, 10]).week(), 3, 'Jan 10 2009 should be week 3');
  905. });
  906. test('weeks year starting friday', function (assert) {
  907. assert.equal(moment([2009, 11, 26]).week(), 1, 'Dec 26 2009 should be week 1');
  908. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  909. assert.equal(moment([2010, 0, 2]).week(), 2, 'Jan 2 2010 should be week 2');
  910. assert.equal(moment([2010, 0, 8]).week(), 2, 'Jan 8 2010 should be week 2');
  911. assert.equal(moment([2010, 0, 9]).week(), 3, 'Jan 9 2010 should be week 3');
  912. });
  913. test('weeks year starting saturday', function (assert) {
  914. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  915. assert.equal(moment([2011, 0, 7]).week(), 1, 'Jan 7 2011 should be week 1');
  916. assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2');
  917. assert.equal(moment([2011, 0, 14]).week(), 2, 'Jan 14 2011 should be week 2');
  918. assert.equal(moment([2011, 0, 15]).week(), 3, 'Jan 15 2011 should be week 3');
  919. });
  920. test('weeks year starting sunday formatted', function (assert) {
  921. assert.equal(moment([2011, 11, 31]).format('w ww wo'), '١ ٠١ ١', 'Dec 31 2011 should be week 1');
  922. assert.equal(moment([2012, 0, 6]).format('w ww wo'), '١ ٠١ ١', 'Jan 6 2012 should be week 1');
  923. assert.equal(moment([2012, 0, 7]).format('w ww wo'), '٢ ٠٢ ٢', 'Jan 7 2012 should be week 2');
  924. assert.equal(moment([2012, 0, 13]).format('w ww wo'), '٢ ٠٢ ٢', 'Jan 13 2012 should be week 2');
  925. assert.equal(moment([2012, 0, 14]).format('w ww wo'), '٣ ٠٣ ٣', 'Jan 14 2012 should be week 3');
  926. });
  927. test('lenient ordinal parsing', function (assert) {
  928. var i, ordinalStr, testMoment;
  929. for (i = 1; i <= 31; ++i) {
  930. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  931. testMoment = moment(ordinalStr, 'YYYY MM Do');
  932. assert.equal(testMoment.year(), 2014,
  933. 'lenient ordinal parsing ' + i + ' year check');
  934. assert.equal(testMoment.month(), 0,
  935. 'lenient ordinal parsing ' + i + ' month check');
  936. assert.equal(testMoment.date(), i,
  937. 'lenient ordinal parsing ' + i + ' date check');
  938. }
  939. });
  940. test('lenient ordinal parsing of number', function (assert) {
  941. var i, testMoment;
  942. for (i = 1; i <= 31; ++i) {
  943. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  944. assert.equal(testMoment.year(), 2014,
  945. 'lenient ordinal parsing of number ' + i + ' year check');
  946. assert.equal(testMoment.month(), 0,
  947. 'lenient ordinal parsing of number ' + i + ' month check');
  948. assert.equal(testMoment.date(), i,
  949. 'lenient ordinal parsing of number ' + i + ' date check');
  950. }
  951. });
  952. test('strict ordinal parsing', function (assert) {
  953. var i, ordinalStr, testMoment;
  954. for (i = 1; i <= 31; ++i) {
  955. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  956. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  957. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  958. }
  959. });
  960. }));
  961. ;(function (global, factory) {
  962. typeof exports === 'object' && typeof module !== 'undefined'
  963. && typeof require === 'function' ? factory(require('../../moment')) :
  964. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  965. factory(global.moment)
  966. }(this, function (moment) { 'use strict';
  967. /*global QUnit:false*/
  968. var test = QUnit.test;
  969. var expect = QUnit.expect;
  970. function module (name, lifecycle) {
  971. QUnit.module(name, {
  972. setup : function () {
  973. moment.locale('en');
  974. moment.createFromInputFallback = function (config) {
  975. throw new Error('input not handled by moment: ' + config._i);
  976. };
  977. if (lifecycle && lifecycle.setup) {
  978. lifecycle.setup();
  979. }
  980. },
  981. teardown : function () {
  982. if (lifecycle && lifecycle.teardown) {
  983. lifecycle.teardown();
  984. }
  985. }
  986. });
  987. }
  988. function localeModule (name, lifecycle) {
  989. QUnit.module('locale:' + name, {
  990. setup : function () {
  991. moment.locale(name);
  992. moment.createFromInputFallback = function (config) {
  993. throw new Error('input not handled by moment: ' + config._i);
  994. };
  995. if (lifecycle && lifecycle.setup) {
  996. lifecycle.setup();
  997. }
  998. },
  999. teardown : function () {
  1000. moment.locale('en');
  1001. if (lifecycle && lifecycle.teardown) {
  1002. lifecycle.teardown();
  1003. }
  1004. }
  1005. });
  1006. }
  1007. localeModule('ar-tn');
  1008. test('parse', function (assert) {
  1009. var tests = 'جانفي:جانفي_فيفري:فيفري_مارس:مارس_أفريل:أفريل_ماي:ماي_جوان:جوان_جويلية:جويلية_أوت:أوت_سبتمبر:سبتمبر_أكتوبر:أكتوبر_نوفمبر:نوفمبر_ديسمبر:ديسمبر'.split('_'),
  1010. i;
  1011. function equalTest(input, mmm, i) {
  1012. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  1013. }
  1014. for (i = 0; i < 12; i++) {
  1015. tests[i] = tests[i].split(':');
  1016. equalTest(tests[i][0], 'MMM', i);
  1017. equalTest(tests[i][1], 'MMM', i);
  1018. equalTest(tests[i][0], 'MMMM', i);
  1019. equalTest(tests[i][1], 'MMMM', i);
  1020. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  1021. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  1022. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  1023. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  1024. }
  1025. });
  1026. test('format', function (assert) {
  1027. var a = [
  1028. ['dddd, MMMM Do YYYY, h:mm:ss a', 'الأحد, فيفري 14 2010, 3:25:50 pm'],
  1029. ['ddd, hA', 'أحد, 3PM'],
  1030. ['M Mo MM MMMM MMM', '2 2 02 فيفري فيفري'],
  1031. ['YYYY YY', '2010 10'],
  1032. ['D Do DD', '14 14 14'],
  1033. ['d do dddd ddd dd', '0 0 الأحد أحد ح'],
  1034. ['DDD DDDo DDDD', '45 45 045'],
  1035. ['w wo ww', '6 6 06'],
  1036. ['h hh', '3 03'],
  1037. ['H HH', '15 15'],
  1038. ['m mm', '25 25'],
  1039. ['s ss', '50 50'],
  1040. ['a A', 'pm PM'],
  1041. ['[the] DDDo [day of the year]', 'the 45 day of the year'],
  1042. ['LT', '15:25'],
  1043. ['LTS', '15:25:50'],
  1044. ['L', '14/02/2010'],
  1045. ['LL', '14 فيفري 2010'],
  1046. ['LLL', '14 فيفري 2010 15:25'],
  1047. ['LLLL', 'الأحد 14 فيفري 2010 15:25'],
  1048. ['l', '14/2/2010'],
  1049. ['ll', '14 فيفري 2010'],
  1050. ['lll', '14 فيفري 2010 15:25'],
  1051. ['llll', 'أحد 14 فيفري 2010 15:25']
  1052. ],
  1053. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  1054. i;
  1055. for (i = 0; i < a.length; i++) {
  1056. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  1057. }
  1058. });
  1059. test('format ordinal', function (assert) {
  1060. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1');
  1061. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2');
  1062. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3');
  1063. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4');
  1064. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5');
  1065. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6');
  1066. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7');
  1067. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8');
  1068. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9');
  1069. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10');
  1070. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11');
  1071. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12');
  1072. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13');
  1073. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14');
  1074. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15');
  1075. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16');
  1076. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17');
  1077. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18');
  1078. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19');
  1079. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20');
  1080. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21');
  1081. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22');
  1082. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23');
  1083. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24');
  1084. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25');
  1085. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26');
  1086. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27');
  1087. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28');
  1088. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29');
  1089. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30');
  1090. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31');
  1091. });
  1092. test('format month', function (assert) {
  1093. var expected = 'جانفي جانفي_فيفري فيفري_مارس مارس_أفريل أفريل_ماي ماي_جوان جوان_جويلية جويلية_أوت أوت_سبتمبر سبتمبر_أكتوبر أكتوبر_نوفمبر نوفمبر_ديسمبر ديسمبر'.split('_'),
  1094. i;
  1095. for (i = 0; i < expected.length; i++) {
  1096. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  1097. }
  1098. });
  1099. test('format week', function (assert) {
  1100. var expected = 'الأحد أحد ح_الإثنين إثنين ن_الثلاثاء ثلاثاء ث_الأربعاء أربعاء ر_الخميس خميس خ_الجمعة جمعة ج_السبت سبت س'.split('_'),
  1101. i;
  1102. for (i = 0; i < expected.length; i++) {
  1103. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  1104. }
  1105. });
  1106. test('from', function (assert) {
  1107. var start = moment([2007, 1, 28]);
  1108. assert.equal(start.from(moment([2007, 1, 28]).add({
  1109. s: 44
  1110. }), true), 'ثوان', '44 seconds = a few seconds');
  1111. assert.equal(start.from(moment([2007, 1, 28]).add({
  1112. s: 45
  1113. }), true), 'دقيقة', '45 seconds = a minute');
  1114. assert.equal(start.from(moment([2007, 1, 28]).add({
  1115. s: 89
  1116. }), true), 'دقيقة', '89 seconds = a minute');
  1117. assert.equal(start.from(moment([2007, 1, 28]).add({
  1118. s: 90
  1119. }), true), '2 دقائق', '90 seconds = 2 minutes');
  1120. assert.equal(start.from(moment([2007, 1, 28]).add({
  1121. m: 44
  1122. }), true), '44 دقائق', '44 minutes = 44 minutes');
  1123. assert.equal(start.from(moment([2007, 1, 28]).add({
  1124. m: 45
  1125. }), true), 'ساعة', '45 minutes = an hour');
  1126. assert.equal(start.from(moment([2007, 1, 28]).add({
  1127. m: 89
  1128. }), true), 'ساعة', '89 minutes = an hour');
  1129. assert.equal(start.from(moment([2007, 1, 28]).add({
  1130. m: 90
  1131. }), true), '2 ساعات', '90 minutes = 2 hours');
  1132. assert.equal(start.from(moment([2007, 1, 28]).add({
  1133. h: 5
  1134. }), true), '5 ساعات', '5 hours = 5 hours');
  1135. assert.equal(start.from(moment([2007, 1, 28]).add({
  1136. h: 21
  1137. }), true), '21 ساعات', '21 hours = 21 hours');
  1138. assert.equal(start.from(moment([2007, 1, 28]).add({
  1139. h: 22
  1140. }), true), 'يوم', '22 hours = a day');
  1141. assert.equal(start.from(moment([2007, 1, 28]).add({
  1142. h: 35
  1143. }), true), 'يوم', '35 hours = a day');
  1144. assert.equal(start.from(moment([2007, 1, 28]).add({
  1145. h: 36
  1146. }), true), '2 أيام', '36 hours = 2 days');
  1147. assert.equal(start.from(moment([2007, 1, 28]).add({
  1148. d: 1
  1149. }), true), 'يوم', '1 day = a day');
  1150. assert.equal(start.from(moment([2007, 1, 28]).add({
  1151. d: 5
  1152. }), true), '5 أيام', '5 days = 5 days');
  1153. assert.equal(start.from(moment([2007, 1, 28]).add({
  1154. d: 25
  1155. }), true), '25 أيام', '25 days = 25 days');
  1156. assert.equal(start.from(moment([2007, 1, 28]).add({
  1157. d: 26
  1158. }), true), 'شهر', '26 days = a month');
  1159. assert.equal(start.from(moment([2007, 1, 28]).add({
  1160. d: 30
  1161. }), true), 'شهر', '30 days = a month');
  1162. assert.equal(start.from(moment([2007, 1, 28]).add({
  1163. d: 43
  1164. }), true), 'شهر', '43 days = a month');
  1165. assert.equal(start.from(moment([2007, 1, 28]).add({
  1166. d: 46
  1167. }), true), '2 أشهر', '46 days = 2 months');
  1168. assert.equal(start.from(moment([2007, 1, 28]).add({
  1169. d: 74
  1170. }), true), '2 أشهر', '75 days = 2 months');
  1171. assert.equal(start.from(moment([2007, 1, 28]).add({
  1172. d: 76
  1173. }), true), '3 أشهر', '76 days = 3 months');
  1174. assert.equal(start.from(moment([2007, 1, 28]).add({
  1175. M: 1
  1176. }), true), 'شهر', '1 month = a month');
  1177. assert.equal(start.from(moment([2007, 1, 28]).add({
  1178. M: 5
  1179. }), true), '5 أشهر', '5 months = 5 months');
  1180. assert.equal(start.from(moment([2007, 1, 28]).add({
  1181. d: 345
  1182. }), true), 'سنة', '345 days = a year');
  1183. assert.equal(start.from(moment([2007, 1, 28]).add({
  1184. d: 548
  1185. }), true), '2 سنوات', '548 days = 2 years');
  1186. assert.equal(start.from(moment([2007, 1, 28]).add({
  1187. y: 1
  1188. }), true), 'سنة', '1 year = a year');
  1189. assert.equal(start.from(moment([2007, 1, 28]).add({
  1190. y: 5
  1191. }), true), '5 سنوات', '5 years = 5 years');
  1192. });
  1193. test('suffix', function (assert) {
  1194. assert.equal(moment(30000).from(0), 'في ثوان', 'prefix');
  1195. assert.equal(moment(0).from(30000), 'منذ ثوان', 'suffix');
  1196. });
  1197. test('now from now', function (assert) {
  1198. assert.equal(moment().fromNow(), 'منذ ثوان', 'now from now should display as in the past');
  1199. });
  1200. test('fromNow', function (assert) {
  1201. assert.equal(moment().add({
  1202. s: 30
  1203. }).fromNow(), 'في ثوان', 'in a few seconds');
  1204. assert.equal(moment().add({
  1205. d: 5
  1206. }).fromNow(), 'في 5 أيام', 'in 5 days');
  1207. });
  1208. test('calendar day', function (assert) {
  1209. var a = moment().hours(2).minutes(0).seconds(0);
  1210. assert.equal(moment(a).calendar(), 'اليوم على الساعة 02:00', 'today at the same time');
  1211. assert.equal(moment(a).add({
  1212. m: 25
  1213. }).calendar(), 'اليوم على الساعة 02:25', 'Now plus 25 min');
  1214. assert.equal(moment(a).add({
  1215. h: 1
  1216. }).calendar(), 'اليوم على الساعة 03:00', 'Now plus 1 hour');
  1217. assert.equal(moment(a).add({
  1218. d: 1
  1219. }).calendar(), 'غدا على الساعة 02:00', 'tomorrow at the same time');
  1220. assert.equal(moment(a).subtract({
  1221. h: 1
  1222. }).calendar(), 'اليوم على الساعة 01:00', 'Now minus 1 hour');
  1223. assert.equal(moment(a).subtract({
  1224. d: 1
  1225. }).calendar(), 'أمس على الساعة 02:00', 'yesterday at the same time');
  1226. });
  1227. test('calendar next week', function (assert) {
  1228. var i, m;
  1229. for (i = 2; i < 7; i++) {
  1230. m = moment().add({
  1231. d: i
  1232. });
  1233. assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today + ' + i + ' days current time');
  1234. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  1235. assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today + ' + i + ' days beginning of day');
  1236. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  1237. assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today + ' + i + ' days end of day');
  1238. }
  1239. });
  1240. test('calendar last week', function (assert) {
  1241. var i, m;
  1242. for (i = 2; i < 7; i++) {
  1243. m = moment().subtract({
  1244. d: i
  1245. });
  1246. assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today - ' + i + ' days current time');
  1247. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  1248. assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today - ' + i + ' days beginning of day');
  1249. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  1250. assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today - ' + i + ' days end of day');
  1251. }
  1252. });
  1253. test('calendar all else', function (assert) {
  1254. var weeksAgo = moment().subtract({
  1255. w: 1
  1256. }),
  1257. weeksFromNow = moment().add({
  1258. w: 1
  1259. });
  1260. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  1261. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  1262. weeksAgo = moment().subtract({
  1263. w: 2
  1264. });
  1265. weeksFromNow = moment().add({
  1266. w: 2
  1267. });
  1268. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  1269. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  1270. });
  1271. test('weeks year starting sunday', function (assert) {
  1272. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  1273. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  1274. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  1275. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  1276. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  1277. });
  1278. test('weeks year starting monday', function (assert) {
  1279. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  1280. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  1281. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  1282. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  1283. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  1284. });
  1285. test('weeks year starting tuesday', function (assert) {
  1286. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  1287. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  1288. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  1289. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  1290. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  1291. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  1292. });
  1293. test('weeks year starting wednesday', function (assert) {
  1294. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  1295. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  1296. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  1297. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  1298. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  1299. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  1300. });
  1301. test('weeks year starting thursday', function (assert) {
  1302. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  1303. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  1304. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  1305. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  1306. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  1307. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  1308. });
  1309. test('weeks year starting friday', function (assert) {
  1310. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  1311. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  1312. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  1313. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  1314. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  1315. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  1316. });
  1317. test('weeks year starting saturday', function (assert) {
  1318. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  1319. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  1320. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  1321. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  1322. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  1323. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  1324. });
  1325. test('weeks year starting sunday formatted', function (assert) {
  1326. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52', 'Jan 1 2012 should be week 52');
  1327. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1', 'Jan 2 2012 should be week 1');
  1328. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1', 'Jan 8 2012 should be week 1');
  1329. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2', 'Jan 9 2012 should be week 2');
  1330. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2', 'Jan 15 2012 should be week 2');
  1331. });
  1332. test('lenient ordinal parsing', function (assert) {
  1333. var i, ordinalStr, testMoment;
  1334. for (i = 1; i <= 31; ++i) {
  1335. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  1336. testMoment = moment(ordinalStr, 'YYYY MM Do');
  1337. assert.equal(testMoment.year(), 2014,
  1338. 'lenient ordinal parsing ' + i + ' year check');
  1339. assert.equal(testMoment.month(), 0,
  1340. 'lenient ordinal parsing ' + i + ' month check');
  1341. assert.equal(testMoment.date(), i,
  1342. 'lenient ordinal parsing ' + i + ' date check');
  1343. }
  1344. });
  1345. test('lenient ordinal parsing of number', function (assert) {
  1346. var i, testMoment;
  1347. for (i = 1; i <= 31; ++i) {
  1348. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  1349. assert.equal(testMoment.year(), 2014,
  1350. 'lenient ordinal parsing of number ' + i + ' year check');
  1351. assert.equal(testMoment.month(), 0,
  1352. 'lenient ordinal parsing of number ' + i + ' month check');
  1353. assert.equal(testMoment.date(), i,
  1354. 'lenient ordinal parsing of number ' + i + ' date check');
  1355. }
  1356. });
  1357. test('strict ordinal parsing', function (assert) {
  1358. var i, ordinalStr, testMoment;
  1359. for (i = 1; i <= 31; ++i) {
  1360. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  1361. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  1362. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  1363. }
  1364. });
  1365. }));
  1366. ;(function (global, factory) {
  1367. typeof exports === 'object' && typeof module !== 'undefined'
  1368. && typeof require === 'function' ? factory(require('../../moment')) :
  1369. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  1370. factory(global.moment)
  1371. }(this, function (moment) { 'use strict';
  1372. /*global QUnit:false*/
  1373. var test = QUnit.test;
  1374. var expect = QUnit.expect;
  1375. function module (name, lifecycle) {
  1376. QUnit.module(name, {
  1377. setup : function () {
  1378. moment.locale('en');
  1379. moment.createFromInputFallback = function (config) {
  1380. throw new Error('input not handled by moment: ' + config._i);
  1381. };
  1382. if (lifecycle && lifecycle.setup) {
  1383. lifecycle.setup();
  1384. }
  1385. },
  1386. teardown : function () {
  1387. if (lifecycle && lifecycle.teardown) {
  1388. lifecycle.teardown();
  1389. }
  1390. }
  1391. });
  1392. }
  1393. function localeModule (name, lifecycle) {
  1394. QUnit.module('locale:' + name, {
  1395. setup : function () {
  1396. moment.locale(name);
  1397. moment.createFromInputFallback = function (config) {
  1398. throw new Error('input not handled by moment: ' + config._i);
  1399. };
  1400. if (lifecycle && lifecycle.setup) {
  1401. lifecycle.setup();
  1402. }
  1403. },
  1404. teardown : function () {
  1405. moment.locale('en');
  1406. if (lifecycle && lifecycle.teardown) {
  1407. lifecycle.teardown();
  1408. }
  1409. }
  1410. });
  1411. }
  1412. localeModule('ar');
  1413. var months = [
  1414. 'كانون الثاني يناير',
  1415. 'شباط فبراير',
  1416. 'آذار مارس',
  1417. 'نيسان أبريل',
  1418. 'أيار مايو',
  1419. 'حزيران يونيو',
  1420. 'تموز يوليو',
  1421. 'آب أغسطس',
  1422. 'أيلول سبتمبر',
  1423. 'تشرين الأول أكتوبر',
  1424. 'تشرين الثاني نوفمبر',
  1425. 'كانون الأول ديسمبر'
  1426. ];
  1427. test('parse', function (assert) {
  1428. var tests = months, i;
  1429. function equalTest(input, mmm, i) {
  1430. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1) + ' instead is month ' + moment(input, mmm).month());
  1431. }
  1432. for (i = 0; i < 12; i++) {
  1433. equalTest(tests[i], 'MMM', i);
  1434. equalTest(tests[i], 'MMM', i);
  1435. equalTest(tests[i], 'MMMM', i);
  1436. equalTest(tests[i], 'MMMM', i);
  1437. equalTest(tests[i].toLocaleLowerCase(), 'MMMM', i);
  1438. equalTest(tests[i].toLocaleLowerCase(), 'MMMM', i);
  1439. equalTest(tests[i].toLocaleUpperCase(), 'MMMM', i);
  1440. equalTest(tests[i].toLocaleUpperCase(), 'MMMM', i);
  1441. }
  1442. });
  1443. test('format', function (assert) {
  1444. var a = [
  1445. ['dddd, MMMM Do YYYY, h:mm:ss a', 'الأحد، شباط فبراير ١٤ ٢٠١٠، ٣:٢٥:٥٠ م'],
  1446. ['ddd, hA', 'أحد، ٣م'],
  1447. ['M Mo MM MMMM MMM', '٢ ٢ ٠٢ شباط فبراير شباط فبراير'],
  1448. ['YYYY YY', '٢٠١٠ ١٠'],
  1449. ['D Do DD', '١٤ ١٤ ١٤'],
  1450. ['d do dddd ddd dd', '٠ ٠ الأحد أحد ح'],
  1451. ['DDD DDDo DDDD', '٤٥ ٤٥ ٠٤٥'],
  1452. ['w wo ww', '٨ ٨ ٠٨'],
  1453. ['h hh', '٣ ٠٣'],
  1454. ['H HH', '١٥ ١٥'],
  1455. ['m mm', '٢٥ ٢٥'],
  1456. ['s ss', '٥٠ ٥٠'],
  1457. ['a A', 'م م'],
  1458. ['[the] DDDo [day of the year]', 'the ٤٥ day of the year'],
  1459. ['LT', '١٥:٢٥'],
  1460. ['LTS', '١٥:٢٥:٥٠'],
  1461. ['L', '١٤/\u200f٢/\u200f٢٠١٠'],
  1462. ['LL', '١٤ شباط فبراير ٢٠١٠'],
  1463. ['LLL', '١٤ شباط فبراير ٢٠١٠ ١٥:٢٥'],
  1464. ['LLLL', 'الأحد ١٤ شباط فبراير ٢٠١٠ ١٥:٢٥'],
  1465. ['l', '١٤/\u200f٢/\u200f٢٠١٠'],
  1466. ['ll', '١٤ شباط فبراير ٢٠١٠'],
  1467. ['lll', '١٤ شباط فبراير ٢٠١٠ ١٥:٢٥'],
  1468. ['llll', 'أحد ١٤ شباط فبراير ٢٠١٠ ١٥:٢٥']
  1469. ],
  1470. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  1471. i;
  1472. for (i = 0; i < a.length; i++) {
  1473. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  1474. }
  1475. });
  1476. test('format ordinal', function (assert) {
  1477. assert.equal(moment([2011, 0, 1]).format('DDDo'), '١', '1');
  1478. assert.equal(moment([2011, 0, 2]).format('DDDo'), '٢', '2');
  1479. assert.equal(moment([2011, 0, 3]).format('DDDo'), '٣', '3');
  1480. assert.equal(moment([2011, 0, 4]).format('DDDo'), '٤', '4');
  1481. assert.equal(moment([2011, 0, 5]).format('DDDo'), '٥', '5');
  1482. assert.equal(moment([2011, 0, 6]).format('DDDo'), '٦', '6');
  1483. assert.equal(moment([2011, 0, 7]).format('DDDo'), '٧', '7');
  1484. assert.equal(moment([2011, 0, 8]).format('DDDo'), '٨', '8');
  1485. assert.equal(moment([2011, 0, 9]).format('DDDo'), '٩', '9');
  1486. assert.equal(moment([2011, 0, 10]).format('DDDo'), '١٠', '10');
  1487. assert.equal(moment([2011, 0, 11]).format('DDDo'), '١١', '11');
  1488. assert.equal(moment([2011, 0, 12]).format('DDDo'), '١٢', '12');
  1489. assert.equal(moment([2011, 0, 13]).format('DDDo'), '١٣', '13');
  1490. assert.equal(moment([2011, 0, 14]).format('DDDo'), '١٤', '14');
  1491. assert.equal(moment([2011, 0, 15]).format('DDDo'), '١٥', '15');
  1492. assert.equal(moment([2011, 0, 16]).format('DDDo'), '١٦', '16');
  1493. assert.equal(moment([2011, 0, 17]).format('DDDo'), '١٧', '17');
  1494. assert.equal(moment([2011, 0, 18]).format('DDDo'), '١٨', '18');
  1495. assert.equal(moment([2011, 0, 19]).format('DDDo'), '١٩', '19');
  1496. assert.equal(moment([2011, 0, 20]).format('DDDo'), '٢٠', '20');
  1497. assert.equal(moment([2011, 0, 21]).format('DDDo'), '٢١', '21');
  1498. assert.equal(moment([2011, 0, 22]).format('DDDo'), '٢٢', '22');
  1499. assert.equal(moment([2011, 0, 23]).format('DDDo'), '٢٣', '23');
  1500. assert.equal(moment([2011, 0, 24]).format('DDDo'), '٢٤', '24');
  1501. assert.equal(moment([2011, 0, 25]).format('DDDo'), '٢٥', '25');
  1502. assert.equal(moment([2011, 0, 26]).format('DDDo'), '٢٦', '26');
  1503. assert.equal(moment([2011, 0, 27]).format('DDDo'), '٢٧', '27');
  1504. assert.equal(moment([2011, 0, 28]).format('DDDo'), '٢٨', '28');
  1505. assert.equal(moment([2011, 0, 29]).format('DDDo'), '٢٩', '29');
  1506. assert.equal(moment([2011, 0, 30]).format('DDDo'), '٣٠', '30');
  1507. assert.equal(moment([2011, 0, 31]).format('DDDo'), '٣١', '31');
  1508. });
  1509. test('format month', function (assert) {
  1510. var expected = months, i;
  1511. for (i = 0; i < expected.length; i++) {
  1512. assert.equal(moment([2011, i, 1]).format('MMMM'), expected[i], expected[i]);
  1513. assert.equal(moment([2011, i, 1]).format('MMM'), expected[i], expected[i]);
  1514. }
  1515. });
  1516. test('format week', function (assert) {
  1517. var expected = 'الأحد أحد ح_الإثنين إثنين ن_الثلاثاء ثلاثاء ث_الأربعاء أربعاء ر_الخميس خميس خ_الجمعة جمعة ج_السبت سبت س'.split('_'), i;
  1518. for (i = 0; i < expected.length; i++) {
  1519. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  1520. }
  1521. });
  1522. test('from', function (assert) {
  1523. var start = moment([2007, 1, 28]);
  1524. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), '٤٤ ثانية', '44 seconds = a few seconds');
  1525. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'دقيقة واحدة', '45 seconds = a minute');
  1526. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'دقيقة واحدة', '89 seconds = a minute');
  1527. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), 'دقيقتان', '90 seconds = 2 minutes');
  1528. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '٤٤ دقيقة', '44 minutes = 44 minutes');
  1529. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ساعة واحدة', '45 minutes = an hour');
  1530. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ساعة واحدة', '89 minutes = an hour');
  1531. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), 'ساعتان', '90 minutes = 2 hours');
  1532. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '٥ ساعات', '5 hours = 5 hours');
  1533. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '٢١ ساعة', '21 hours = 21 hours');
  1534. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'يوم واحد', '22 hours = a day');
  1535. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'يوم واحد', '35 hours = a day');
  1536. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), 'يومان', '36 hours = 2 days');
  1537. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'يوم واحد', '1 day = a day');
  1538. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '٥ أيام', '5 days = 5 days');
  1539. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '٢٥ يومًا', '25 days = 25 days');
  1540. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'شهر واحد', '26 days = a month');
  1541. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'شهر واحد', '30 days = a month');
  1542. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'شهر واحد', '43 days = a month');
  1543. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), 'شهران', '46 days = 2 months');
  1544. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), 'شهران', '75 days = 2 months');
  1545. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '٣ أشهر', '76 days = 3 months');
  1546. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'شهر واحد', '1 month = a month');
  1547. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '٥ أشهر', '5 months = 5 months');
  1548. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'عام واحد', '345 days = a year');
  1549. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), 'عامان', '548 days = 2 years');
  1550. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'عام واحد', '1 year = a year');
  1551. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '٥ أعوام', '5 years = 5 years');
  1552. });
  1553. test('suffix', function (assert) {
  1554. assert.equal(moment(30000).from(0), 'بعد ٣٠ ثانية', 'prefix');
  1555. assert.equal(moment(0).from(30000), 'منذ ٣٠ ثانية', 'suffix');
  1556. });
  1557. test('now from now', function (assert) {
  1558. assert.equal(moment().fromNow(), 'منذ ثانية واحدة', 'now from now should display as in the past');
  1559. });
  1560. test('fromNow', function (assert) {
  1561. assert.equal(moment().add({s: 30}).fromNow(), 'بعد ٣٠ ثانية', 'in a few seconds');
  1562. assert.equal(moment().add({d: 5}).fromNow(), 'بعد ٥ أيام', 'in 5 days');
  1563. });
  1564. test('calendar day', function (assert) {
  1565. var a = moment().hours(2).minutes(0).seconds(0);
  1566. assert.equal(moment(a).calendar(), 'اليوم عند الساعة ٠٢:٠٠', 'today at the same time');
  1567. assert.equal(moment(a).add({m: 25}).calendar(), 'اليوم عند الساعة ٠٢:٢٥', 'Now plus 25 min');
  1568. assert.equal(moment(a).add({h: 1}).calendar(), 'اليوم عند الساعة ٠٣:٠٠', 'Now plus 1 hour');
  1569. assert.equal(moment(a).add({d: 1}).calendar(), 'غدًا عند الساعة ٠٢:٠٠', 'tomorrow at the same time');
  1570. assert.equal(moment(a).subtract({h: 1}).calendar(), 'اليوم عند الساعة ٠١:٠٠', 'Now minus 1 hour');
  1571. assert.equal(moment(a).subtract({d: 1}).calendar(), 'أمس عند الساعة ٠٢:٠٠', 'yesterday at the same time');
  1572. });
  1573. test('calendar next week', function (assert) {
  1574. var i, m;
  1575. for (i = 2; i < 7; i++) {
  1576. m = moment().add({d: i});
  1577. assert.equal(m.calendar(), m.format('dddd [عند الساعة] LT'), 'Today + ' + i + ' days current time');
  1578. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  1579. assert.equal(m.calendar(), m.format('dddd [عند الساعة] LT'), 'Today + ' + i + ' days beginning of day');
  1580. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  1581. assert.equal(m.calendar(), m.format('dddd [عند الساعة] LT'), 'Today + ' + i + ' days end of day');
  1582. }
  1583. });
  1584. test('calendar last week', function (assert) {
  1585. var i, m;
  1586. for (i = 2; i < 7; i++) {
  1587. m = moment().subtract({d: i});
  1588. assert.equal(m.calendar(), m.format('dddd [عند الساعة] LT'), 'Today - ' + i + ' days current time');
  1589. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  1590. assert.equal(m.calendar(), m.format('dddd [عند الساعة] LT'), 'Today - ' + i + ' days beginning of day');
  1591. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  1592. assert.equal(m.calendar(), m.format('dddd [عند الساعة] LT'), 'Today - ' + i + ' days end of day');
  1593. }
  1594. });
  1595. test('calendar all else', function (assert) {
  1596. var weeksAgo = moment().subtract({w: 1}),
  1597. weeksFromNow = moment().add({w: 1});
  1598. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  1599. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  1600. weeksAgo = moment().subtract({w: 2});
  1601. weeksFromNow = moment().add({w: 2});
  1602. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  1603. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  1604. });
  1605. test('weeks year starting sunday', function (assert) {
  1606. assert.equal(moment([2011, 11, 31]).week(), 1, 'Dec 31 2011 should be week 1');
  1607. assert.equal(moment([2012, 0, 6]).week(), 1, 'Jan 6 2012 should be week 1');
  1608. assert.equal(moment([2012, 0, 7]).week(), 2, 'Jan 7 2012 should be week 2');
  1609. assert.equal(moment([2012, 0, 13]).week(), 2, 'Jan 13 2012 should be week 2');
  1610. assert.equal(moment([2012, 0, 14]).week(), 3, 'Jan 14 2012 should be week 3');
  1611. });
  1612. test('weeks year starting monday', function (assert) {
  1613. assert.equal(moment([2006, 11, 30]).week(), 1, 'Dec 30 2006 should be week 1');
  1614. assert.equal(moment([2007, 0, 5]).week(), 1, 'Jan 5 2007 should be week 1');
  1615. assert.equal(moment([2007, 0, 6]).week(), 2, 'Jan 6 2007 should be week 2');
  1616. assert.equal(moment([2007, 0, 12]).week(), 2, 'Jan 12 2007 should be week 2');
  1617. assert.equal(moment([2007, 0, 13]).week(), 3, 'Jan 13 2007 should be week 3');
  1618. });
  1619. test('weeks year starting tuesday', function (assert) {
  1620. assert.equal(moment([2007, 11, 29]).week(), 1, 'Dec 29 2007 should be week 1');
  1621. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  1622. assert.equal(moment([2008, 0, 4]).week(), 1, 'Jan 4 2008 should be week 1');
  1623. assert.equal(moment([2008, 0, 5]).week(), 2, 'Jan 5 2008 should be week 2');
  1624. assert.equal(moment([2008, 0, 11]).week(), 2, 'Jan 11 2008 should be week 2');
  1625. assert.equal(moment([2008, 0, 12]).week(), 3, 'Jan 12 2008 should be week 3');
  1626. });
  1627. test('weeks year starting wednesday', function (assert) {
  1628. assert.equal(moment([2002, 11, 28]).week(), 1, 'Dec 28 2002 should be week 1');
  1629. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  1630. assert.equal(moment([2003, 0, 3]).week(), 1, 'Jan 3 2003 should be week 1');
  1631. assert.equal(moment([2003, 0, 4]).week(), 2, 'Jan 4 2003 should be week 2');
  1632. assert.equal(moment([2003, 0, 10]).week(), 2, 'Jan 10 2003 should be week 2');
  1633. assert.equal(moment([2003, 0, 11]).week(), 3, 'Jan 11 2003 should be week 3');
  1634. assert.equal(moment('2003 1 6', 'gggg w d').format('YYYY-MM-DD'), '٢٠٠٢-١٢-٢٨', 'Week 1 of 2003 should be Dec 28 2002');
  1635. assert.equal(moment('2003 1 0', 'gggg w e').format('YYYY-MM-DD'), '٢٠٠٢-١٢-٢٨', 'Week 1 of 2003 should be Dec 28 2002');
  1636. assert.equal(moment('2003 1 6', 'gggg w d').format('gggg w d'), '٢٠٠٣ ١ ٦', 'Saturday of week 1 of 2003 parsed should be formatted as 2003 1 6');
  1637. assert.equal(moment('2003 1 0', 'gggg w e').format('gggg w e'), '٢٠٠٣ ١ ٠', '1st day of week 1 of 2003 parsed should be formatted as 2003 1 0');
  1638. });
  1639. test('weeks year starting thursday', function (assert) {
  1640. assert.equal(moment([2008, 11, 27]).week(), 1, 'Dec 27 2008 should be week 1');
  1641. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  1642. assert.equal(moment([2009, 0, 2]).week(), 1, 'Jan 2 2009 should be week 1');
  1643. assert.equal(moment([2009, 0, 3]).week(), 2, 'Jan 3 2009 should be week 2');
  1644. assert.equal(moment([2009, 0, 9]).week(), 2, 'Jan 9 2009 should be week 2');
  1645. assert.equal(moment([2009, 0, 10]).week(), 3, 'Jan 10 2009 should be week 3');
  1646. });
  1647. test('weeks year starting friday', function (assert) {
  1648. assert.equal(moment([2009, 11, 26]).week(), 1, 'Dec 26 2009 should be week 1');
  1649. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  1650. assert.equal(moment([2010, 0, 2]).week(), 2, 'Jan 2 2010 should be week 2');
  1651. assert.equal(moment([2010, 0, 8]).week(), 2, 'Jan 8 2010 should be week 2');
  1652. assert.equal(moment([2010, 0, 9]).week(), 3, 'Jan 9 2010 should be week 3');
  1653. });
  1654. test('weeks year starting saturday', function (assert) {
  1655. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  1656. assert.equal(moment([2011, 0, 7]).week(), 1, 'Jan 7 2011 should be week 1');
  1657. assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2');
  1658. assert.equal(moment([2011, 0, 14]).week(), 2, 'Jan 14 2011 should be week 2');
  1659. assert.equal(moment([2011, 0, 15]).week(), 3, 'Jan 15 2011 should be week 3');
  1660. });
  1661. test('weeks year starting sunday formatted', function (assert) {
  1662. assert.equal(moment([2011, 11, 31]).format('w ww wo'), '١ ٠١ ١', 'Dec 31 2011 should be week 1');
  1663. assert.equal(moment([2012, 0, 6]).format('w ww wo'), '١ ٠١ ١', 'Jan 6 2012 should be week 1');
  1664. assert.equal(moment([2012, 0, 7]).format('w ww wo'), '٢ ٠٢ ٢', 'Jan 7 2012 should be week 2');
  1665. assert.equal(moment([2012, 0, 13]).format('w ww wo'), '٢ ٠٢ ٢', 'Jan 13 2012 should be week 2');
  1666. assert.equal(moment([2012, 0, 14]).format('w ww wo'), '٣ ٠٣ ٣', 'Jan 14 2012 should be week 3');
  1667. });
  1668. test('lenient ordinal parsing', function (assert) {
  1669. var i, ordinalStr, testMoment;
  1670. for (i = 1; i <= 31; ++i) {
  1671. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  1672. testMoment = moment(ordinalStr, 'YYYY MM Do');
  1673. assert.equal(testMoment.year(), 2014,
  1674. 'lenient ordinal parsing ' + i + ' year check');
  1675. assert.equal(testMoment.month(), 0,
  1676. 'lenient ordinal parsing ' + i + ' month check');
  1677. assert.equal(testMoment.date(), i,
  1678. 'lenient ordinal parsing ' + i + ' date check');
  1679. }
  1680. });
  1681. test('lenient ordinal parsing of number', function (assert) {
  1682. var i, testMoment;
  1683. for (i = 1; i <= 31; ++i) {
  1684. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  1685. assert.equal(testMoment.year(), 2014,
  1686. 'lenient ordinal parsing of number ' + i + ' year check');
  1687. assert.equal(testMoment.month(), 0,
  1688. 'lenient ordinal parsing of number ' + i + ' month check');
  1689. assert.equal(testMoment.date(), i,
  1690. 'lenient ordinal parsing of number ' + i + ' date check');
  1691. }
  1692. });
  1693. test('strict ordinal parsing', function (assert) {
  1694. var i, ordinalStr, testMoment;
  1695. for (i = 1; i <= 31; ++i) {
  1696. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  1697. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  1698. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  1699. }
  1700. });
  1701. test('no leading zeros in long date formats', function (assert) {
  1702. var i, j, longDateStr, shortDateStr;
  1703. for (i = 1; i <= 9; ++i) {
  1704. for (j = 1; j <= 9; ++j) {
  1705. longDateStr = moment([2014, i, j]).format('L');
  1706. shortDateStr = moment([2014, i, j]).format('l');
  1707. assert.equal(longDateStr, shortDateStr, 'should not have leading zeros in month or day');
  1708. }
  1709. }
  1710. });
  1711. }));
  1712. ;(function (global, factory) {
  1713. typeof exports === 'object' && typeof module !== 'undefined'
  1714. && typeof require === 'function' ? factory(require('../../moment')) :
  1715. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  1716. factory(global.moment)
  1717. }(this, function (moment) { 'use strict';
  1718. /*global QUnit:false*/
  1719. var test = QUnit.test;
  1720. var expect = QUnit.expect;
  1721. function module (name, lifecycle) {
  1722. QUnit.module(name, {
  1723. setup : function () {
  1724. moment.locale('en');
  1725. moment.createFromInputFallback = function (config) {
  1726. throw new Error('input not handled by moment: ' + config._i);
  1727. };
  1728. if (lifecycle && lifecycle.setup) {
  1729. lifecycle.setup();
  1730. }
  1731. },
  1732. teardown : function () {
  1733. if (lifecycle && lifecycle.teardown) {
  1734. lifecycle.teardown();
  1735. }
  1736. }
  1737. });
  1738. }
  1739. function localeModule (name, lifecycle) {
  1740. QUnit.module('locale:' + name, {
  1741. setup : function () {
  1742. moment.locale(name);
  1743. moment.createFromInputFallback = function (config) {
  1744. throw new Error('input not handled by moment: ' + config._i);
  1745. };
  1746. if (lifecycle && lifecycle.setup) {
  1747. lifecycle.setup();
  1748. }
  1749. },
  1750. teardown : function () {
  1751. moment.locale('en');
  1752. if (lifecycle && lifecycle.teardown) {
  1753. lifecycle.teardown();
  1754. }
  1755. }
  1756. });
  1757. }
  1758. localeModule('az');
  1759. test('parse', function (assert) {
  1760. var tests = 'yanvar yan_fevral fev_mart mar_Aprel apr_may may_iyun iyn_iyul iyl_Avqust avq_sentyabr sen_oktyabr okt_noyabr noy_dekabr dek'.split('_'), i;
  1761. function equalTest(input, mmm, i) {
  1762. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  1763. }
  1764. for (i = 0; i < 12; i++) {
  1765. tests[i] = tests[i].split(' ');
  1766. equalTest(tests[i][0], 'MMM', i);
  1767. equalTest(tests[i][1], 'MMM', i);
  1768. equalTest(tests[i][0], 'MMMM', i);
  1769. equalTest(tests[i][1], 'MMMM', i);
  1770. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  1771. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  1772. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  1773. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  1774. }
  1775. });
  1776. test('format', function (assert) {
  1777. var a = [
  1778. ['dddd, D MMMM YYYY, HH:mm:ss', 'Bazar, 14 fevral 2010, 15:25:50'],
  1779. ['ddd, A h', 'Baz, gündüz 3'],
  1780. ['M Mo MM MMMM MMM', '2 2-nci 02 fevral fev'],
  1781. ['YYYY YY', '2010 10'],
  1782. ['D Do DD', '14 14-üncü 14'],
  1783. ['d do dddd ddd dd', '0 0-ıncı Bazar Baz Bz'],
  1784. ['DDD DDDo DDDD', '45 45-inci 045'],
  1785. ['w wo ww', '7 7-nci 07'],
  1786. ['h hh', '3 03'],
  1787. ['H HH', '15 15'],
  1788. ['m mm', '25 25'],
  1789. ['s ss', '50 50'],
  1790. ['a A', 'gündüz gündüz'],
  1791. ['[ilin] DDDo [günü]', 'ilin 45-inci günü'],
  1792. ['LT', '15:25'],
  1793. ['LTS', '15:25:50'],
  1794. ['L', '14.02.2010'],
  1795. ['LL', '14 fevral 2010'],
  1796. ['LLL', '14 fevral 2010 15:25'],
  1797. ['LLLL', 'Bazar, 14 fevral 2010 15:25'],
  1798. ['l', '14.2.2010'],
  1799. ['ll', '14 fev 2010'],
  1800. ['lll', '14 fev 2010 15:25'],
  1801. ['llll', 'Baz, 14 fev 2010 15:25']
  1802. ],
  1803. DDDo = [
  1804. [359, '360-ıncı'],
  1805. [199, '200-üncü'],
  1806. [149, '150-nci']
  1807. ],
  1808. dt = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  1809. DDDoDt,
  1810. i;
  1811. for (i = 0; i < a.length; i++) {
  1812. assert.equal(dt.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  1813. }
  1814. for (i = 0; i < DDDo.length; i++) {
  1815. DDDoDt = moment([2010]);
  1816. assert.equal(DDDoDt.add(DDDo[i][0], 'days').format('DDDo'), DDDo[i][1], DDDo[i][0] + ' ---> ' + DDDo[i][1]);
  1817. }
  1818. });
  1819. test('format ordinal', function (assert) {
  1820. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1-inci', '1st');
  1821. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2-nci', '2nd');
  1822. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3-üncü', '3rd');
  1823. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4-üncü', '4th');
  1824. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5-inci', '5th');
  1825. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6-ncı', '6th');
  1826. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7-nci', '7th');
  1827. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8-inci', '8th');
  1828. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9-uncu', '9th');
  1829. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10-uncu', '10th');
  1830. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11-inci', '11th');
  1831. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12-nci', '12th');
  1832. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13-üncü', '13th');
  1833. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14-üncü', '14th');
  1834. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15-inci', '15th');
  1835. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16-ncı', '16th');
  1836. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17-nci', '17th');
  1837. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18-inci', '18th');
  1838. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19-uncu', '19th');
  1839. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20-nci', '20th');
  1840. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21-inci', '21th');
  1841. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22-nci', '22th');
  1842. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23-üncü', '23th');
  1843. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24-üncü', '24th');
  1844. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25-inci', '25th');
  1845. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26-ncı', '26th');
  1846. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27-nci', '27th');
  1847. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28-inci', '28th');
  1848. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29-uncu', '29th');
  1849. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30-uncu', '30th');
  1850. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31-inci', '31st');
  1851. });
  1852. test('format month', function (assert) {
  1853. var expected = 'yanvar yan_fevral fev_mart mar_aprel apr_may may_iyun iyn_iyul iyl_avqust avq_sentyabr sen_oktyabr okt_noyabr noy_dekabr dek'.split('_'), i;
  1854. for (i = 0; i < expected.length; i++) {
  1855. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  1856. }
  1857. });
  1858. test('format week', function (assert) {
  1859. var expected = 'Bazar Baz Bz_Bazar ertəsi BzE BE_Çərşənbə axşamı ÇAx ÇA_Çərşənbə Çər Çə_Cümə axşamı CAx CA_Cümə Cüm Cü_Şənbə Şən Şə'.split('_'), i;
  1860. for (i = 0; i < expected.length; i++) {
  1861. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  1862. }
  1863. });
  1864. test('from', function (assert) {
  1865. var start = moment([2007, 1, 28]);
  1866. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'birneçə saniyyə', '44 seconds = a few seconds');
  1867. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'bir dəqiqə', '45 seconds = a minute');
  1868. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'bir dəqiqə', '89 seconds = a minute');
  1869. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 dəqiqə', '90 seconds = 2 minutes');
  1870. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 dəqiqə', '44 minutes = 44 minutes');
  1871. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'bir saat', '45 minutes = an hour');
  1872. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'bir saat', '89 minutes = an hour');
  1873. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 saat', '90 minutes = 2 hours');
  1874. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 saat', '5 hours = 5 hours');
  1875. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 saat', '21 hours = 21 hours');
  1876. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'bir gün', '22 hours = a day');
  1877. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'bir gün', '35 hours = a day');
  1878. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 gün', '36 hours = 2 days');
  1879. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'bir gün', '1 day = a day');
  1880. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 gün', '5 days = 5 days');
  1881. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 gün', '25 days = 25 days');
  1882. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'bir ay', '26 days = a month');
  1883. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'bir ay', '30 days = a month');
  1884. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 ay', '46 days = 2 months');
  1885. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 ay', '75 days = 2 months');
  1886. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 ay', '76 days = 3 months');
  1887. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'bir ay', '1 month = a month');
  1888. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 ay', '5 months = 5 months');
  1889. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'bir il', '345 days = a year');
  1890. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 il', '548 days = 2 years');
  1891. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'bir il', '1 year = a year');
  1892. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 il', '5 years = 5 years');
  1893. });
  1894. test('suffix', function (assert) {
  1895. assert.equal(moment(30000).from(0), 'birneçə saniyyə sonra', 'prefix');
  1896. assert.equal(moment(0).from(30000), 'birneçə saniyyə əvvəl', 'suffix');
  1897. });
  1898. test('now from now', function (assert) {
  1899. assert.equal(moment().fromNow(), 'birneçə saniyyə əvvəl', 'now from now should display as in the past');
  1900. });
  1901. test('fromNow', function (assert) {
  1902. assert.equal(moment().add({s: 30}).fromNow(), 'birneçə saniyyə sonra', 'in a few seconds');
  1903. assert.equal(moment().add({d: 5}).fromNow(), '5 gün sonra', 'in 5 days');
  1904. });
  1905. test('calendar day', function (assert) {
  1906. var a = moment().hours(2).minutes(0).seconds(0);
  1907. assert.equal(moment(a).calendar(), 'bugün saat 02:00', 'today at the same time');
  1908. assert.equal(moment(a).add({m: 25}).calendar(), 'bugün saat 02:25', 'Now plus 25 min');
  1909. assert.equal(moment(a).add({h: 1}).calendar(), 'bugün saat 03:00', 'Now plus 1 hour');
  1910. assert.equal(moment(a).add({d: 1}).calendar(), 'sabah saat 02:00', 'tomorrow at the same time');
  1911. assert.equal(moment(a).subtract({h: 1}).calendar(), 'bugün saat 01:00', 'Now minus 1 hour');
  1912. assert.equal(moment(a).subtract({d: 1}).calendar(), 'dünən 02:00', 'yesterday at the same time');
  1913. });
  1914. test('calendar next week', function (assert) {
  1915. var i, m;
  1916. for (i = 2; i < 7; i++) {
  1917. m = moment().add({d: i});
  1918. assert.equal(m.calendar(), m.format('[gələn həftə] dddd [saat] LT'), 'Today + ' + i + ' days current time');
  1919. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  1920. assert.equal(m.calendar(), m.format('[gələn həftə] dddd [saat] LT'), 'Today + ' + i + ' days beginning of day');
  1921. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  1922. assert.equal(m.calendar(), m.format('[gələn həftə] dddd [saat] LT'), 'Today + ' + i + ' days end of day');
  1923. }
  1924. });
  1925. test('calendar last week', function (assert) {
  1926. var i, m;
  1927. for (i = 2; i < 7; i++) {
  1928. m = moment().subtract({d: i});
  1929. assert.equal(m.calendar(), m.format('[keçən həftə] dddd [saat] LT'), 'Today - ' + i + ' days current time');
  1930. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  1931. assert.equal(m.calendar(), m.format('[keçən həftə] dddd [saat] LT'), 'Today - ' + i + ' days beginning of day');
  1932. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  1933. assert.equal(m.calendar(), m.format('[keçən həftə] dddd [saat] LT'), 'Today - ' + i + ' days end of day');
  1934. }
  1935. });
  1936. test('calendar all else', function (assert) {
  1937. var weeksAgo = moment().subtract({w: 1}),
  1938. weeksFromNow = moment().add({w: 1});
  1939. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  1940. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  1941. weeksAgo = moment().subtract({w: 2});
  1942. weeksFromNow = moment().add({w: 2});
  1943. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  1944. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  1945. });
  1946. test('weeks year starting sunday', function (assert) {
  1947. assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1');
  1948. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  1949. assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2');
  1950. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  1951. assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3');
  1952. });
  1953. test('weeks year starting monday', function (assert) {
  1954. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  1955. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  1956. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  1957. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  1958. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  1959. });
  1960. test('weeks year starting tuesday', function (assert) {
  1961. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  1962. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  1963. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  1964. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  1965. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  1966. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  1967. });
  1968. test('weeks year starting wednesday', function (assert) {
  1969. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  1970. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  1971. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  1972. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  1973. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  1974. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  1975. });
  1976. test('weeks year starting thursday', function (assert) {
  1977. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  1978. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  1979. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  1980. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  1981. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  1982. assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3');
  1983. });
  1984. test('weeks year starting friday', function (assert) {
  1985. assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1');
  1986. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  1987. assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1');
  1988. assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2');
  1989. assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2');
  1990. assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3');
  1991. });
  1992. test('weeks year starting saturday', function (assert) {
  1993. assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1');
  1994. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  1995. assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1');
  1996. assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2');
  1997. assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2');
  1998. assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3');
  1999. });
  2000. test('weeks year starting sunday formatted', function (assert) {
  2001. assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1-inci', 'Dec 26 2011 should be week 1');
  2002. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1-inci', 'Jan 1 2012 should be week 1');
  2003. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2-nci', 'Jan 2 2012 should be week 2');
  2004. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2-nci', 'Jan 8 2012 should be week 2');
  2005. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3-üncü', 'Jan 9 2012 should be week 3');
  2006. });
  2007. test('lenient ordinal parsing', function (assert) {
  2008. var i, ordinalStr, testMoment;
  2009. for (i = 1; i <= 31; ++i) {
  2010. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  2011. testMoment = moment(ordinalStr, 'YYYY MM Do');
  2012. assert.equal(testMoment.year(), 2014,
  2013. 'lenient ordinal parsing ' + i + ' year check');
  2014. assert.equal(testMoment.month(), 0,
  2015. 'lenient ordinal parsing ' + i + ' month check');
  2016. assert.equal(testMoment.date(), i,
  2017. 'lenient ordinal parsing ' + i + ' date check');
  2018. }
  2019. });
  2020. test('lenient ordinal parsing of number', function (assert) {
  2021. var i, testMoment;
  2022. for (i = 1; i <= 31; ++i) {
  2023. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  2024. assert.equal(testMoment.year(), 2014,
  2025. 'lenient ordinal parsing of number ' + i + ' year check');
  2026. assert.equal(testMoment.month(), 0,
  2027. 'lenient ordinal parsing of number ' + i + ' month check');
  2028. assert.equal(testMoment.date(), i,
  2029. 'lenient ordinal parsing of number ' + i + ' date check');
  2030. }
  2031. });
  2032. test('strict ordinal parsing', function (assert) {
  2033. var i, ordinalStr, testMoment;
  2034. for (i = 1; i <= 31; ++i) {
  2035. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  2036. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  2037. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  2038. }
  2039. });
  2040. }));
  2041. ;(function (global, factory) {
  2042. typeof exports === 'object' && typeof module !== 'undefined'
  2043. && typeof require === 'function' ? factory(require('../../moment')) :
  2044. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  2045. factory(global.moment)
  2046. }(this, function (moment) { 'use strict';
  2047. /*global QUnit:false*/
  2048. var test = QUnit.test;
  2049. var expect = QUnit.expect;
  2050. function module (name, lifecycle) {
  2051. QUnit.module(name, {
  2052. setup : function () {
  2053. moment.locale('en');
  2054. moment.createFromInputFallback = function (config) {
  2055. throw new Error('input not handled by moment: ' + config._i);
  2056. };
  2057. if (lifecycle && lifecycle.setup) {
  2058. lifecycle.setup();
  2059. }
  2060. },
  2061. teardown : function () {
  2062. if (lifecycle && lifecycle.teardown) {
  2063. lifecycle.teardown();
  2064. }
  2065. }
  2066. });
  2067. }
  2068. function localeModule (name, lifecycle) {
  2069. QUnit.module('locale:' + name, {
  2070. setup : function () {
  2071. moment.locale(name);
  2072. moment.createFromInputFallback = function (config) {
  2073. throw new Error('input not handled by moment: ' + config._i);
  2074. };
  2075. if (lifecycle && lifecycle.setup) {
  2076. lifecycle.setup();
  2077. }
  2078. },
  2079. teardown : function () {
  2080. moment.locale('en');
  2081. if (lifecycle && lifecycle.teardown) {
  2082. lifecycle.teardown();
  2083. }
  2084. }
  2085. });
  2086. }
  2087. localeModule('be');
  2088. test('parse', function (assert) {
  2089. var tests = 'студзень студ_люты лют_сакавік сак_красавік крас_травень трав_чэрвень чэрв_ліпень ліп_жнівень жнів_верасень вер_кастрычнік каст_лістапад ліст_снежань снеж'.split('_'), i;
  2090. function equalTest(input, mmm, i) {
  2091. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  2092. }
  2093. for (i = 0; i < 12; i++) {
  2094. tests[i] = tests[i].split(' ');
  2095. equalTest(tests[i][0], 'MMM', i);
  2096. equalTest(tests[i][1], 'MMM', i);
  2097. equalTest(tests[i][0], 'MMMM', i);
  2098. equalTest(tests[i][1], 'MMMM', i);
  2099. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  2100. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  2101. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  2102. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  2103. }
  2104. });
  2105. test('format', function (assert) {
  2106. var a = [
  2107. ['dddd, Do MMMM YYYY, HH:mm:ss', 'нядзеля, 14-га лютага 2010, 15:25:50'],
  2108. ['ddd, h A', 'нд, 3 дня'],
  2109. ['M Mo MM MMMM MMM', '2 2-і 02 люты лют'],
  2110. ['YYYY YY', '2010 10'],
  2111. ['D Do DD', '14 14-га 14'],
  2112. ['d do dddd ddd dd', '0 0-ы нядзеля нд нд'],
  2113. ['DDD DDDo DDDD', '45 45-ы 045'],
  2114. ['w wo ww', '7 7-ы 07'],
  2115. ['h hh', '3 03'],
  2116. ['H HH', '15 15'],
  2117. ['m mm', '25 25'],
  2118. ['s ss', '50 50'],
  2119. ['a A', 'дня дня'],
  2120. ['DDDo [дзень года]', '45-ы дзень года'],
  2121. ['LT', '15:25'],
  2122. ['LTS', '15:25:50'],
  2123. ['L', '14.02.2010'],
  2124. ['LL', '14 лютага 2010 г.'],
  2125. ['LLL', '14 лютага 2010 г., 15:25'],
  2126. ['LLLL', 'нядзеля, 14 лютага 2010 г., 15:25'],
  2127. ['l', '14.2.2010'],
  2128. ['ll', '14 лют 2010 г.'],
  2129. ['lll', '14 лют 2010 г., 15:25'],
  2130. ['llll', 'нд, 14 лют 2010 г., 15:25']
  2131. ],
  2132. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  2133. i;
  2134. for (i = 0; i < a.length; i++) {
  2135. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  2136. }
  2137. });
  2138. test('format meridiem', function (assert) {
  2139. assert.equal(moment([2012, 11, 28, 0, 0]).format('A'), 'ночы', 'night');
  2140. assert.equal(moment([2012, 11, 28, 3, 59]).format('A'), 'ночы', 'night');
  2141. assert.equal(moment([2012, 11, 28, 4, 0]).format('A'), 'раніцы', 'morning');
  2142. assert.equal(moment([2012, 11, 28, 11, 59]).format('A'), 'раніцы', 'morning');
  2143. assert.equal(moment([2012, 11, 28, 12, 0]).format('A'), 'дня', 'afternoon');
  2144. assert.equal(moment([2012, 11, 28, 16, 59]).format('A'), 'дня', 'afternoon');
  2145. assert.equal(moment([2012, 11, 28, 17, 0]).format('A'), 'вечара', 'evening');
  2146. assert.equal(moment([2012, 11, 28, 23, 59]).format('A'), 'вечара', 'evening');
  2147. });
  2148. test('format ordinal', function (assert) {
  2149. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1-ы', '1-ы');
  2150. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2-і', '2-і');
  2151. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3-і', '3-і');
  2152. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4-ы', '4-ы');
  2153. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5-ы', '5-ы');
  2154. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6-ы', '6-ы');
  2155. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7-ы', '7-ы');
  2156. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8-ы', '8-ы');
  2157. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9-ы', '9-ы');
  2158. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10-ы', '10-ы');
  2159. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11-ы', '11-ы');
  2160. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12-ы', '12-ы');
  2161. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13-ы', '13-ы');
  2162. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14-ы', '14-ы');
  2163. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15-ы', '15-ы');
  2164. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16-ы', '16-ы');
  2165. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17-ы', '17-ы');
  2166. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18-ы', '18-ы');
  2167. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19-ы', '19-ы');
  2168. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20-ы', '20-ы');
  2169. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21-ы', '21-ы');
  2170. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22-і', '22-і');
  2171. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23-і', '23-і');
  2172. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24-ы', '24-ы');
  2173. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25-ы', '25-ы');
  2174. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26-ы', '26-ы');
  2175. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27-ы', '27-ы');
  2176. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28-ы', '28-ы');
  2177. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29-ы', '29-ы');
  2178. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30-ы', '30-ы');
  2179. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31-ы', '31-ы');
  2180. });
  2181. test('format month', function (assert) {
  2182. var expected = 'студзень студ_люты лют_сакавік сак_красавік крас_травень трав_чэрвень чэрв_ліпень ліп_жнівень жнів_верасень вер_кастрычнік каст_лістапад ліст_снежань снеж'.split('_'), i;
  2183. for (i = 0; i < expected.length; i++) {
  2184. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  2185. }
  2186. });
  2187. test('format month case', function (assert) {
  2188. var months = {
  2189. 'nominative': 'студзень_люты_сакавік_красавік_травень_чэрвень_ліпень_жнівень_верасень_кастрычнік_лістапад_снежань'.split('_'),
  2190. 'accusative': 'студзеня_лютага_сакавіка_красавіка_траўня_чэрвеня_ліпеня_жніўня_верасня_кастрычніка_лістапада_снежня'.split('_')
  2191. }, i;
  2192. for (i = 0; i < 12; i++) {
  2193. assert.equal(moment([2011, i, 1]).format('D MMMM'), '1 ' + months.accusative[i], '1 ' + months.accusative[i]);
  2194. assert.equal(moment([2011, i, 1]).format('MMMM'), months.nominative[i], '1 ' + months.nominative[i]);
  2195. }
  2196. });
  2197. test('format month case with escaped symbols', function (assert) {
  2198. var months = {
  2199. 'nominative': 'студзень_люты_сакавік_красавік_травень_чэрвень_ліпень_жнівень_верасень_кастрычнік_лістапад_снежань'.split('_'),
  2200. 'accusative': 'студзеня_лютага_сакавіка_красавіка_траўня_чэрвеня_ліпеня_жніўня_верасня_кастрычніка_лістапада_снежня'.split('_')
  2201. }, i;
  2202. for (i = 0; i < 12; i++) {
  2203. assert.equal(moment([2013, i, 1]).format('D[] MMMM'), '1 ' + months.accusative[i], '1 ' + months.accusative[i]);
  2204. assert.equal(moment([2013, i, 1]).format('[<i>]D[</i>] [<b>]MMMM[</b>]'), '<i>1</i> <b>' + months.accusative[i] + '</b>', '1 <b>' + months.accusative[i] + '</b>');
  2205. assert.equal(moment([2013, i, 1]).format('D[-ы дзень] MMMM'), '1-ы дзень ' + months.accusative[i], '1-ы дзень ' + months.accusative[i]);
  2206. assert.equal(moment([2013, i, 1]).format('D, MMMM'), '1, ' + months.nominative[i], '1, ' + months.nominative[i]);
  2207. }
  2208. });
  2209. test('format week', function (assert) {
  2210. var expected = 'нядзеля нд нд_панядзелак пн пн_аўторак ат ат_серада ср ср_чацвер чц чц_пятніца пт пт_субота сб сб'.split('_'), i;
  2211. for (i = 0; i < expected.length; i++) {
  2212. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  2213. }
  2214. });
  2215. test('from', function (assert) {
  2216. var start = moment([2007, 1, 28]);
  2217. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'некалькі секунд', '44 seconds = a few seconds');
  2218. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'хвіліна', '45 seconds = a minute');
  2219. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'хвіліна', '89 seconds = a minute');
  2220. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 хвіліны', '90 seconds = 2 minutes');
  2221. assert.equal(start.from(moment([2007, 1, 28]).add({m: 31}), true), '31 хвіліна', '31 minutes = 31 minutes');
  2222. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 хвіліны', '44 minutes = 44 minutes');
  2223. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'гадзіна', '45 minutes = an hour');
  2224. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'гадзіна', '89 minutes = an hour');
  2225. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 гадзіны', '90 minutes = 2 hours');
  2226. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 гадзін', '5 hours = 5 hours');
  2227. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 гадзіна', '21 hours = 21 hours');
  2228. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'дзень', '22 hours = a day');
  2229. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'дзень', '35 hours = a day');
  2230. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 дні', '36 hours = 2 days');
  2231. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'дзень', '1 day = a day');
  2232. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 дзён', '5 days = 5 days');
  2233. assert.equal(start.from(moment([2007, 1, 28]).add({d: 11}), true), '11 дзён', '11 days = 11 days');
  2234. assert.equal(start.from(moment([2007, 1, 28]).add({d: 21}), true), '21 дзень', '21 days = 21 days');
  2235. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 дзён', '25 days = 25 days');
  2236. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'месяц', '26 days = a month');
  2237. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'месяц', '30 days = a month');
  2238. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'месяц', '43 days = a month');
  2239. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 месяцы', '46 days = 2 months');
  2240. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 месяцы', '75 days = 2 months');
  2241. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 месяцы', '76 days = 3 months');
  2242. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'месяц', '1 month = a month');
  2243. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 месяцаў', '5 months = 5 months');
  2244. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'год', '345 days = a year');
  2245. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 гады', '548 days = 2 years');
  2246. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'год', '1 year = a year');
  2247. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 гадоў', '5 years = 5 years');
  2248. });
  2249. test('suffix', function (assert) {
  2250. assert.equal(moment(30000).from(0), 'праз некалькі секунд', 'prefix');
  2251. assert.equal(moment(0).from(30000), 'некалькі секунд таму', 'suffix');
  2252. });
  2253. test('fromNow', function (assert) {
  2254. assert.equal(moment().add({s: 30}).fromNow(), 'праз некалькі секунд', 'in a few seconds');
  2255. assert.equal(moment().add({d: 5}).fromNow(), 'праз 5 дзён', 'in 5 days');
  2256. assert.equal(moment().add({m: 31}).fromNow(), 'праз 31 хвіліну', 'in 31 minutes = in 31 minutes');
  2257. assert.equal(moment().subtract({m: 31}).fromNow(), '31 хвіліну таму', '31 minutes ago = 31 minutes ago');
  2258. });
  2259. test('calendar day', function (assert) {
  2260. var a = moment().hours(2).minutes(0).seconds(0);
  2261. assert.equal(moment(a).calendar(), 'Сёння ў 02:00', 'today at the same time');
  2262. assert.equal(moment(a).add({m: 25}).calendar(), 'Сёння ў 02:25', 'Now plus 25 min');
  2263. assert.equal(moment(a).add({h: 1}).calendar(), 'Сёння ў 03:00', 'Now plus 1 hour');
  2264. assert.equal(moment(a).add({d: 1}).calendar(), 'Заўтра ў 02:00', 'tomorrow at the same time');
  2265. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Сёння ў 01:00', 'Now minus 1 hour');
  2266. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Учора ў 02:00', 'yesterday at the same time');
  2267. });
  2268. test('calendar next week', function (assert) {
  2269. var i, m;
  2270. function makeFormat(d) {
  2271. return '[У] dddd [ў] LT';
  2272. }
  2273. for (i = 2; i < 7; i++) {
  2274. m = moment().add({d: i});
  2275. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days current time');
  2276. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  2277. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days beginning of day');
  2278. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  2279. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days end of day');
  2280. }
  2281. });
  2282. test('calendar last week', function (assert) {
  2283. var i, m;
  2284. function makeFormat(d) {
  2285. switch (d.day()) {
  2286. case 0:
  2287. case 3:
  2288. case 5:
  2289. case 6:
  2290. return '[У мінулую] dddd [ў] LT';
  2291. case 1:
  2292. case 2:
  2293. case 4:
  2294. return '[У мінулы] dddd [ў] LT';
  2295. }
  2296. }
  2297. for (i = 2; i < 7; i++) {
  2298. m = moment().subtract({d: i});
  2299. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days current time');
  2300. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  2301. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days beginning of day');
  2302. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  2303. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days end of day');
  2304. }
  2305. });
  2306. test('calendar all else', function (assert) {
  2307. var weeksAgo = moment().subtract({w: 1}),
  2308. weeksFromNow = moment().add({w: 1});
  2309. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  2310. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  2311. weeksAgo = moment().subtract({w: 2});
  2312. weeksFromNow = moment().add({w: 2});
  2313. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  2314. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  2315. });
  2316. test('weeks year starting sunday', function (assert) {
  2317. assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1');
  2318. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  2319. assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2');
  2320. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  2321. assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3');
  2322. });
  2323. test('weeks year starting monday', function (assert) {
  2324. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  2325. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  2326. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  2327. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  2328. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  2329. });
  2330. test('weeks year starting tuesday', function (assert) {
  2331. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  2332. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  2333. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  2334. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  2335. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  2336. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  2337. });
  2338. test('weeks year starting wednesday', function (assert) {
  2339. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  2340. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  2341. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  2342. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  2343. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  2344. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  2345. });
  2346. test('weeks year starting thursday', function (assert) {
  2347. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  2348. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  2349. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  2350. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  2351. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  2352. assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3');
  2353. });
  2354. test('weeks year starting friday', function (assert) {
  2355. assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1');
  2356. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  2357. assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1');
  2358. assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2');
  2359. assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2');
  2360. assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3');
  2361. });
  2362. test('weeks year starting saturday', function (assert) {
  2363. assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1');
  2364. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  2365. assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1');
  2366. assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2');
  2367. assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2');
  2368. assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3');
  2369. });
  2370. test('weeks year starting sunday formatted', function (assert) {
  2371. assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1-ы', 'Dec 26 2011 should be week 1');
  2372. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1-ы', 'Jan 1 2012 should be week 1');
  2373. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2-і', 'Jan 2 2012 should be week 2');
  2374. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2-і', 'Jan 8 2012 should be week 2');
  2375. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3-і', 'Jan 9 2012 should be week 3');
  2376. });
  2377. test('lenient ordinal parsing', function (assert) {
  2378. var i, ordinalStr, testMoment;
  2379. for (i = 1; i <= 31; ++i) {
  2380. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  2381. testMoment = moment(ordinalStr, 'YYYY MM Do');
  2382. assert.equal(testMoment.year(), 2014,
  2383. 'lenient ordinal parsing ' + i + ' year check');
  2384. assert.equal(testMoment.month(), 0,
  2385. 'lenient ordinal parsing ' + i + ' month check');
  2386. assert.equal(testMoment.date(), i,
  2387. 'lenient ordinal parsing ' + i + ' date check');
  2388. }
  2389. });
  2390. test('lenient ordinal parsing of number', function (assert) {
  2391. var i, testMoment;
  2392. for (i = 1; i <= 31; ++i) {
  2393. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  2394. assert.equal(testMoment.year(), 2014,
  2395. 'lenient ordinal parsing of number ' + i + ' year check');
  2396. assert.equal(testMoment.month(), 0,
  2397. 'lenient ordinal parsing of number ' + i + ' month check');
  2398. assert.equal(testMoment.date(), i,
  2399. 'lenient ordinal parsing of number ' + i + ' date check');
  2400. }
  2401. });
  2402. test('strict ordinal parsing', function (assert) {
  2403. var i, ordinalStr, testMoment;
  2404. for (i = 1; i <= 31; ++i) {
  2405. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  2406. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  2407. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  2408. }
  2409. });
  2410. }));
  2411. ;(function (global, factory) {
  2412. typeof exports === 'object' && typeof module !== 'undefined'
  2413. && typeof require === 'function' ? factory(require('../../moment')) :
  2414. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  2415. factory(global.moment)
  2416. }(this, function (moment) { 'use strict';
  2417. /*global QUnit:false*/
  2418. var test = QUnit.test;
  2419. var expect = QUnit.expect;
  2420. function module (name, lifecycle) {
  2421. QUnit.module(name, {
  2422. setup : function () {
  2423. moment.locale('en');
  2424. moment.createFromInputFallback = function (config) {
  2425. throw new Error('input not handled by moment: ' + config._i);
  2426. };
  2427. if (lifecycle && lifecycle.setup) {
  2428. lifecycle.setup();
  2429. }
  2430. },
  2431. teardown : function () {
  2432. if (lifecycle && lifecycle.teardown) {
  2433. lifecycle.teardown();
  2434. }
  2435. }
  2436. });
  2437. }
  2438. function localeModule (name, lifecycle) {
  2439. QUnit.module('locale:' + name, {
  2440. setup : function () {
  2441. moment.locale(name);
  2442. moment.createFromInputFallback = function (config) {
  2443. throw new Error('input not handled by moment: ' + config._i);
  2444. };
  2445. if (lifecycle && lifecycle.setup) {
  2446. lifecycle.setup();
  2447. }
  2448. },
  2449. teardown : function () {
  2450. moment.locale('en');
  2451. if (lifecycle && lifecycle.teardown) {
  2452. lifecycle.teardown();
  2453. }
  2454. }
  2455. });
  2456. }
  2457. localeModule('bg');
  2458. test('parse', function (assert) {
  2459. var tests = 'януари янр_февруари фев_март мар_април апр_май май_юни юни_юли юли_август авг_септември сеп_октомври окт_ноември ное_декември дек'.split('_'), i;
  2460. function equalTest(input, mmm, i) {
  2461. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  2462. }
  2463. for (i = 0; i < 12; i++) {
  2464. tests[i] = tests[i].split(' ');
  2465. equalTest(tests[i][0], 'MMM', i);
  2466. equalTest(tests[i][1], 'MMM', i);
  2467. equalTest(tests[i][0], 'MMMM', i);
  2468. equalTest(tests[i][1], 'MMMM', i);
  2469. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  2470. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  2471. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  2472. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  2473. }
  2474. });
  2475. test('format', function (assert) {
  2476. var a = [
  2477. ['dddd, MMMM Do YYYY, H:mm:ss', 'неделя, февруари 14-ти 2010, 15:25:50'],
  2478. ['ddd, hA', 'нед, 3PM'],
  2479. ['M Mo MM MMMM MMM', '2 2-ри 02 февруари фев'],
  2480. ['YYYY YY', '2010 10'],
  2481. ['D Do DD', '14 14-ти 14'],
  2482. ['d do dddd ddd dd', '0 0-ев неделя нед нд'],
  2483. ['DDD DDDo DDDD', '45 45-ти 045'],
  2484. ['w wo ww', '7 7-ми 07'],
  2485. ['h hh', '3 03'],
  2486. ['H HH', '15 15'],
  2487. ['m mm', '25 25'],
  2488. ['s ss', '50 50'],
  2489. ['a A', 'pm PM'],
  2490. ['[the] DDDo [day of the year]', 'the 45-ти day of the year'],
  2491. ['LT', '15:25'],
  2492. ['LTS', '15:25:50'],
  2493. ['L', '14.02.2010'],
  2494. ['LL', '14 февруари 2010'],
  2495. ['LLL', '14 февруари 2010 15:25'],
  2496. ['LLLL', 'неделя, 14 февруари 2010 15:25'],
  2497. ['l', '14.2.2010'],
  2498. ['ll', '14 фев 2010'],
  2499. ['lll', '14 фев 2010 15:25'],
  2500. ['llll', 'нед, 14 фев 2010 15:25']
  2501. ],
  2502. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  2503. i;
  2504. for (i = 0; i < a.length; i++) {
  2505. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  2506. }
  2507. });
  2508. test('format ordinal', function (assert) {
  2509. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1-ви', '1-ви');
  2510. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2-ри', '2-ри');
  2511. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3-ти', '3-ти');
  2512. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4-ти', '4-ти');
  2513. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5-ти', '5-ти');
  2514. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6-ти', '6-ти');
  2515. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7-ми', '7-ми');
  2516. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8-ми', '8-ми');
  2517. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9-ти', '9-ти');
  2518. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10-ти', '10-ти');
  2519. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11-ти', '11-ти');
  2520. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12-ти', '12-ти');
  2521. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13-ти', '13-ти');
  2522. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14-ти', '14-ти');
  2523. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15-ти', '15-ти');
  2524. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16-ти', '16-ти');
  2525. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17-ти', '17-ти');
  2526. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18-ти', '18-ти');
  2527. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19-ти', '19-ти');
  2528. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20-ти', '20-ти');
  2529. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21-ви', '21-ви');
  2530. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22-ри', '22-ри');
  2531. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23-ти', '23-ти');
  2532. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24-ти', '24-ти');
  2533. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25-ти', '25-ти');
  2534. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26-ти', '26-ти');
  2535. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27-ми', '27-ми');
  2536. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28-ми', '28-ми');
  2537. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29-ти', '29-ти');
  2538. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30-ти', '30-ти');
  2539. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31-ви', '31-ви');
  2540. });
  2541. test('format month', function (assert) {
  2542. var expected = 'януари янр_февруари фев_март мар_април апр_май май_юни юни_юли юли_август авг_септември сеп_октомври окт_ноември ное_декември дек'.split('_'), i;
  2543. for (i = 0; i < expected.length; i++) {
  2544. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  2545. }
  2546. });
  2547. test('format week', function (assert) {
  2548. var expected = 'неделя нед нд_понеделник пон пн_вторник вто вт_сряда сря ср_четвъртък чет чт_петък пет пт_събота съб сб'.split('_'), i;
  2549. for (i = 0; i < expected.length; i++) {
  2550. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  2551. }
  2552. });
  2553. test('from', function (assert) {
  2554. var start = moment([2007, 1, 28]);
  2555. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'няколко секунди', '44 seconds = a few seconds');
  2556. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'минута', '45 seconds = a minute');
  2557. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'минута', '89 seconds = a minute');
  2558. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 минути', '90 seconds = 2 minutes');
  2559. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 минути', '44 minutes = 44 minutes');
  2560. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'час', '45 minutes = an hour');
  2561. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'час', '89 minutes = an hour');
  2562. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 часа', '90 minutes = 2 hours');
  2563. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 часа', '5 hours = 5 hours');
  2564. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 часа', '21 hours = 21 hours');
  2565. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ден', '22 hours = a day');
  2566. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ден', '35 hours = a day');
  2567. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 дни', '36 hours = 2 days');
  2568. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ден', '1 day = a day');
  2569. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 дни', '5 days = 5 days');
  2570. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 дни', '25 days = 25 days');
  2571. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'месец', '26 days = a month');
  2572. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'месец', '30 days = a month');
  2573. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'месец', '43 days = a month');
  2574. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 месеца', '46 days = 2 months');
  2575. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 месеца', '75 days = 2 months');
  2576. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 месеца', '76 days = 3 months');
  2577. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'месец', '1 month = a month');
  2578. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 месеца', '5 months = 5 months');
  2579. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'година', '345 days = a year');
  2580. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 години', '548 days = 2 years');
  2581. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'година', '1 year = a year');
  2582. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 години', '5 years = 5 years');
  2583. });
  2584. test('suffix', function (assert) {
  2585. assert.equal(moment(30000).from(0), 'след няколко секунди', 'prefix');
  2586. assert.equal(moment(0).from(30000), 'преди няколко секунди', 'suffix');
  2587. });
  2588. test('now from now', function (assert) {
  2589. assert.equal(moment().fromNow(), 'преди няколко секунди', 'now from now should display as in the past');
  2590. });
  2591. test('fromNow', function (assert) {
  2592. assert.equal(moment().add({s: 30}).fromNow(), 'след няколко секунди', 'in a few seconds');
  2593. assert.equal(moment().add({d: 5}).fromNow(), 'след 5 дни', 'in 5 days');
  2594. });
  2595. test('calendar day', function (assert) {
  2596. var a = moment().hours(2).minutes(0).seconds(0);
  2597. assert.equal(moment(a).calendar(), 'Днес в 2:00', 'today at the same time');
  2598. assert.equal(moment(a).add({m: 25}).calendar(), 'Днес в 2:25', 'Now plus 25 min');
  2599. assert.equal(moment(a).add({h: 1}).calendar(), 'Днес в 3:00', 'Now plus 1 hour');
  2600. assert.equal(moment(a).add({d: 1}).calendar(), 'Утре в 2:00', 'tomorrow at the same time');
  2601. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Днес в 1:00', 'Now minus 1 hour');
  2602. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Вчера в 2:00', 'yesterday at the same time');
  2603. });
  2604. test('calendar next week', function (assert) {
  2605. var i, m;
  2606. for (i = 2; i < 7; i++) {
  2607. m = moment().add({d: i});
  2608. assert.equal(m.calendar(), m.format('dddd [в] LT'), 'Today + ' + i + ' days current time');
  2609. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  2610. assert.equal(m.calendar(), m.format('dddd [в] LT'), 'Today + ' + i + ' days beginning of day');
  2611. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  2612. assert.equal(m.calendar(), m.format('dddd [в] LT'), 'Today + ' + i + ' days end of day');
  2613. }
  2614. });
  2615. test('calendar last week', function (assert) {
  2616. var i, m;
  2617. function makeFormat(d) {
  2618. switch (d.day()) {
  2619. case 0:
  2620. case 3:
  2621. case 6:
  2622. return '[В изминалата] dddd [в] LT';
  2623. case 1:
  2624. case 2:
  2625. case 4:
  2626. case 5:
  2627. return '[В изминалия] dddd [в] LT';
  2628. }
  2629. }
  2630. for (i = 2; i < 7; i++) {
  2631. m = moment().subtract({d: i});
  2632. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days current time');
  2633. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  2634. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days beginning of day');
  2635. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  2636. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days end of day');
  2637. }
  2638. });
  2639. test('calendar all else', function (assert) {
  2640. var weeksAgo = moment().subtract({w: 1}),
  2641. weeksFromNow = moment().add({w: 1});
  2642. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  2643. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  2644. weeksAgo = moment().subtract({w: 2});
  2645. weeksFromNow = moment().add({w: 2});
  2646. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  2647. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  2648. });
  2649. test('weeks year starting sunday', function (assert) {
  2650. assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1');
  2651. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  2652. assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2');
  2653. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  2654. assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3');
  2655. });
  2656. test('weeks year starting monday', function (assert) {
  2657. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  2658. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  2659. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  2660. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  2661. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  2662. });
  2663. test('weeks year starting tuesday', function (assert) {
  2664. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  2665. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  2666. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  2667. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  2668. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  2669. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  2670. });
  2671. test('weeks year starting wednesday', function (assert) {
  2672. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  2673. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  2674. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  2675. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  2676. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  2677. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  2678. });
  2679. test('weeks year starting thursday', function (assert) {
  2680. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  2681. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  2682. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  2683. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  2684. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  2685. assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3');
  2686. });
  2687. test('weeks year starting friday', function (assert) {
  2688. assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1');
  2689. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  2690. assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1');
  2691. assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2');
  2692. assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2');
  2693. assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3');
  2694. });
  2695. test('weeks year starting saturday', function (assert) {
  2696. assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1');
  2697. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  2698. assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1');
  2699. assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2');
  2700. assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2');
  2701. assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3');
  2702. });
  2703. test('weeks year starting sunday formatted', function (assert) {
  2704. assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1-ви', 'Dec 26 2011 should be week 1');
  2705. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1-ви', 'Jan 1 2012 should be week 1');
  2706. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2-ри', 'Jan 2 2012 should be week 2');
  2707. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2-ри', 'Jan 8 2012 should be week 2');
  2708. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3-ти', 'Jan 9 2012 should be week 3');
  2709. });
  2710. test('lenient ordinal parsing', function (assert) {
  2711. var i, ordinalStr, testMoment;
  2712. for (i = 1; i <= 31; ++i) {
  2713. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  2714. testMoment = moment(ordinalStr, 'YYYY MM Do');
  2715. assert.equal(testMoment.year(), 2014,
  2716. 'lenient ordinal parsing ' + i + ' year check');
  2717. assert.equal(testMoment.month(), 0,
  2718. 'lenient ordinal parsing ' + i + ' month check');
  2719. assert.equal(testMoment.date(), i,
  2720. 'lenient ordinal parsing ' + i + ' date check');
  2721. }
  2722. });
  2723. test('lenient ordinal parsing of number', function (assert) {
  2724. var i, testMoment;
  2725. for (i = 1; i <= 31; ++i) {
  2726. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  2727. assert.equal(testMoment.year(), 2014,
  2728. 'lenient ordinal parsing of number ' + i + ' year check');
  2729. assert.equal(testMoment.month(), 0,
  2730. 'lenient ordinal parsing of number ' + i + ' month check');
  2731. assert.equal(testMoment.date(), i,
  2732. 'lenient ordinal parsing of number ' + i + ' date check');
  2733. }
  2734. });
  2735. test('strict ordinal parsing', function (assert) {
  2736. var i, ordinalStr, testMoment;
  2737. for (i = 1; i <= 31; ++i) {
  2738. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  2739. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  2740. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  2741. }
  2742. });
  2743. }));
  2744. ;(function (global, factory) {
  2745. typeof exports === 'object' && typeof module !== 'undefined'
  2746. && typeof require === 'function' ? factory(require('../../moment')) :
  2747. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  2748. factory(global.moment)
  2749. }(this, function (moment) { 'use strict';
  2750. /*global QUnit:false*/
  2751. var test = QUnit.test;
  2752. var expect = QUnit.expect;
  2753. function module (name, lifecycle) {
  2754. QUnit.module(name, {
  2755. setup : function () {
  2756. moment.locale('en');
  2757. moment.createFromInputFallback = function (config) {
  2758. throw new Error('input not handled by moment: ' + config._i);
  2759. };
  2760. if (lifecycle && lifecycle.setup) {
  2761. lifecycle.setup();
  2762. }
  2763. },
  2764. teardown : function () {
  2765. if (lifecycle && lifecycle.teardown) {
  2766. lifecycle.teardown();
  2767. }
  2768. }
  2769. });
  2770. }
  2771. function localeModule (name, lifecycle) {
  2772. QUnit.module('locale:' + name, {
  2773. setup : function () {
  2774. moment.locale(name);
  2775. moment.createFromInputFallback = function (config) {
  2776. throw new Error('input not handled by moment: ' + config._i);
  2777. };
  2778. if (lifecycle && lifecycle.setup) {
  2779. lifecycle.setup();
  2780. }
  2781. },
  2782. teardown : function () {
  2783. moment.locale('en');
  2784. if (lifecycle && lifecycle.teardown) {
  2785. lifecycle.teardown();
  2786. }
  2787. }
  2788. });
  2789. }
  2790. localeModule('bn');
  2791. test('parse', function (assert) {
  2792. var tests = 'জানুয়ারী জানু_ফেবুয়ারী ফেব_মার্চ মার্চ_এপ্রিল এপর_মে মে_জুন জুন_জুলাই জুল_অগাস্ট অগ_সেপ্টেম্বর সেপ্ট_অক্টোবর অক্টো_নভেম্বর নভ_ডিসেম্বর ডিসেম্'.split('_'), i;
  2793. function equalTest(input, mmm, i) {
  2794. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  2795. }
  2796. for (i = 0; i < 12; i++) {
  2797. tests[i] = tests[i].split(' ');
  2798. equalTest(tests[i][0], 'MMM', i);
  2799. equalTest(tests[i][1], 'MMM', i);
  2800. equalTest(tests[i][0], 'MMMM', i);
  2801. equalTest(tests[i][1], 'MMMM', i);
  2802. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  2803. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  2804. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  2805. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  2806. }
  2807. });
  2808. test('format', function (assert) {
  2809. var a = [
  2810. ['dddd, Do MMMM YYYY, a h:mm:ss সময়', 'রবিবার, ১৪ ফেবুয়ারী ২০১০, দুপুর ৩:২৫:৫০ সময়'],
  2811. ['ddd, a h সময়', 'রবি, দুপুর ৩ সময়'],
  2812. ['M Mo MM MMMM MMM', '২ ২ ০২ ফেবুয়ারী ফেব'],
  2813. ['YYYY YY', '২০১০ ১০'],
  2814. ['D Do DD', '১৪ ১৪ ১৪'],
  2815. ['d do dddd ddd dd', '০ ০ রবিবার রবি রব'],
  2816. ['DDD DDDo DDDD', '৪৫ ৪৫ ০৪৫'],
  2817. ['w wo ww', '৮ ৮ ০৮'],
  2818. ['h hh', '৩ ০৩'],
  2819. ['H HH', '১৫ ১৫'],
  2820. ['m mm', '২৫ ২৫'],
  2821. ['s ss', '৫০ ৫০'],
  2822. ['a A', 'দুপুর দুপুর'],
  2823. ['LT', 'দুপুর ৩:২৫ সময়'],
  2824. ['LTS', 'দুপুর ৩:২৫:৫০ সময়'],
  2825. ['L', '১৪/০২/২০১০'],
  2826. ['LL', '১৪ ফেবুয়ারী ২০১০'],
  2827. ['LLL', '১৪ ফেবুয়ারী ২০১০, দুপুর ৩:২৫ সময়'],
  2828. ['LLLL', 'রবিবার, ১৪ ফেবুয়ারী ২০১০, দুপুর ৩:২৫ সময়'],
  2829. ['l', '১৪/২/২০১০'],
  2830. ['ll', '১৪ ফেব ২০১০'],
  2831. ['lll', '১৪ ফেব ২০১০, দুপুর ৩:২৫ সময়'],
  2832. ['llll', 'রবি, ১৪ ফেব ২০১০, দুপুর ৩:২৫ সময়']
  2833. ],
  2834. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  2835. i;
  2836. for (i = 0; i < a.length; i++) {
  2837. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  2838. }
  2839. });
  2840. test('format ordinal', function (assert) {
  2841. assert.equal(moment([2011, 0, 1]).format('DDDo'), '১', '১');
  2842. assert.equal(moment([2011, 0, 2]).format('DDDo'), '২', '২');
  2843. assert.equal(moment([2011, 0, 3]).format('DDDo'), '৩', '৩');
  2844. assert.equal(moment([2011, 0, 4]).format('DDDo'), '৪', '৪');
  2845. assert.equal(moment([2011, 0, 5]).format('DDDo'), '৫', '৫');
  2846. assert.equal(moment([2011, 0, 6]).format('DDDo'), '৬', '৬');
  2847. assert.equal(moment([2011, 0, 7]).format('DDDo'), '৭', '৭');
  2848. assert.equal(moment([2011, 0, 8]).format('DDDo'), '৮', '৮');
  2849. assert.equal(moment([2011, 0, 9]).format('DDDo'), '৯', '৯');
  2850. assert.equal(moment([2011, 0, 10]).format('DDDo'), '১০', '১০');
  2851. assert.equal(moment([2011, 0, 11]).format('DDDo'), '১১', '১১');
  2852. assert.equal(moment([2011, 0, 12]).format('DDDo'), '১২', '১২');
  2853. assert.equal(moment([2011, 0, 13]).format('DDDo'), '১৩', '১৩');
  2854. assert.equal(moment([2011, 0, 14]).format('DDDo'), '১৪', '১৪');
  2855. assert.equal(moment([2011, 0, 15]).format('DDDo'), '১৫', '১৫');
  2856. assert.equal(moment([2011, 0, 16]).format('DDDo'), '১৬', '১৬');
  2857. assert.equal(moment([2011, 0, 17]).format('DDDo'), '১৭', '১৭');
  2858. assert.equal(moment([2011, 0, 18]).format('DDDo'), '১৮', '১৮');
  2859. assert.equal(moment([2011, 0, 19]).format('DDDo'), '১৯', '১৯');
  2860. assert.equal(moment([2011, 0, 20]).format('DDDo'), '২০', '২০');
  2861. assert.equal(moment([2011, 0, 21]).format('DDDo'), '২১', '২১');
  2862. assert.equal(moment([2011, 0, 22]).format('DDDo'), '২২', '২২');
  2863. assert.equal(moment([2011, 0, 23]).format('DDDo'), '২৩', '২৩');
  2864. assert.equal(moment([2011, 0, 24]).format('DDDo'), '২৪', '২৪');
  2865. assert.equal(moment([2011, 0, 25]).format('DDDo'), '২৫', '২৫');
  2866. assert.equal(moment([2011, 0, 26]).format('DDDo'), '২৬', '২৬');
  2867. assert.equal(moment([2011, 0, 27]).format('DDDo'), '২৭', '২৭');
  2868. assert.equal(moment([2011, 0, 28]).format('DDDo'), '২৮', '२৮');
  2869. assert.equal(moment([2011, 0, 29]).format('DDDo'), '২৯', '২৯');
  2870. assert.equal(moment([2011, 0, 30]).format('DDDo'), '৩০', '৩০');
  2871. assert.equal(moment([2011, 0, 31]).format('DDDo'), '৩১', '৩১');
  2872. });
  2873. test('format month', function (assert) {
  2874. var expected = 'জানুয়ারী জানু_ফেবুয়ারী ফেব_মার্চ মার্চ_এপ্রিল এপর_মে মে_জুন জুন_জুলাই জুল_অগাস্ট অগ_সেপ্টেম্বর সেপ্ট_অক্টোবর অক্টো_নভেম্বর নভ_ডিসেম্বর ডিসেম্'.split('_'), i;
  2875. for (i = 0; i < expected.length; i++) {
  2876. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  2877. }
  2878. });
  2879. test('format week', function (assert) {
  2880. var expected = 'রবিবার রবি রব_সোমবার সোম সম_মঙ্গলবার মঙ্গল মঙ্গ_বুধবার বুধ বু_বৃহস্পত্তিবার বৃহস্পত্তি ব্রিহ_শুক্রবার শুক্র শু_শনিবার শনি শনি'.split('_'), i;
  2881. for (i = 0; i < expected.length; i++) {
  2882. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  2883. }
  2884. });
  2885. test('from', function (assert) {
  2886. var start = moment([2007, 1, 28]);
  2887. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'কয়েক সেকেন্ড', '44 seconds = a few seconds');
  2888. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'এক মিনিট', '45 seconds = a minute');
  2889. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'এক মিনিট', '89 seconds = a minute');
  2890. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '২ মিনিট', '90 seconds = 2 minutes');
  2891. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '৪৪ মিনিট', '44 minutes = 44 minutes');
  2892. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'এক ঘন্টা', '45 minutes = an hour');
  2893. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'এক ঘন্টা', '89 minutes = an hour');
  2894. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '২ ঘন্টা', '90 minutes = 2 hours');
  2895. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '৫ ঘন্টা', '5 hours = 5 hours');
  2896. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '২১ ঘন্টা', '21 hours = 21 hours');
  2897. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'এক দিন', '22 hours = a day');
  2898. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'এক দিন', '35 hours = a day');
  2899. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '২ দিন', '36 hours = 2 days');
  2900. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'এক দিন', '1 day = a day');
  2901. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '৫ দিন', '5 days = 5 days');
  2902. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '২৫ দিন', '25 days = 25 days');
  2903. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'এক মাস', '26 days = a month');
  2904. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'এক মাস', '30 days = a month');
  2905. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '২ মাস', '46 days = 2 months');
  2906. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '২ মাস', '75 days = 2 months');
  2907. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '৩ মাস', '76 days = 3 months');
  2908. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'এক মাস', '1 month = a month');
  2909. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '৫ মাস', '5 months = 5 months');
  2910. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'এক বছর', '345 days = a year');
  2911. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '২ বছর', '548 days = 2 years');
  2912. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'এক বছর', '1 year = a year');
  2913. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '৫ বছর', '5 years = 5 years');
  2914. });
  2915. test('suffix', function (assert) {
  2916. assert.equal(moment(30000).from(0), 'কয়েক সেকেন্ড পরে', 'prefix');
  2917. assert.equal(moment(0).from(30000), 'কয়েক সেকেন্ড আগে', 'suffix');
  2918. });
  2919. test('now from now', function (assert) {
  2920. assert.equal(moment().fromNow(), 'কয়েক সেকেন্ড আগে', 'now from now should display as in the past');
  2921. });
  2922. test('fromNow', function (assert) {
  2923. assert.equal(moment().add({s: 30}).fromNow(), 'কয়েক সেকেন্ড পরে', 'কয়েক সেকেন্ড পরে');
  2924. assert.equal(moment().add({d: 5}).fromNow(), '৫ দিন পরে', '৫ দিন পরে');
  2925. });
  2926. test('calendar day', function (assert) {
  2927. var a = moment().hours(2).minutes(0).seconds(0);
  2928. assert.equal(moment(a).calendar(), 'আজ রাত ২:০০ সময়', 'today at the same time');
  2929. assert.equal(moment(a).add({m: 25}).calendar(), 'আজ রাত ২:২৫ সময়', 'Now plus 25 min');
  2930. assert.equal(moment(a).add({h: 3}).calendar(), 'আজ সকাল ৫:০০ সময়', 'Now plus 3 hour');
  2931. assert.equal(moment(a).add({d: 1}).calendar(), 'আগামীকাল রাত ২:০০ সময়', 'tomorrow at the same time');
  2932. assert.equal(moment(a).subtract({h: 1}).calendar(), 'আজ রাত ১:০০ সময়', 'Now minus 1 hour');
  2933. assert.equal(moment(a).subtract({d: 1}).calendar(), 'গতকাল রাত ২:০০ সময়', 'yesterday at the same time');
  2934. });
  2935. test('calendar next week', function (assert) {
  2936. var i, m;
  2937. for (i = 2; i < 7; i++) {
  2938. m = moment().add({d: i});
  2939. assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days current time');
  2940. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  2941. assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days beginning of day');
  2942. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  2943. assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days end of day');
  2944. }
  2945. });
  2946. test('calendar last week', function (assert) {
  2947. var i, m;
  2948. for (i = 2; i < 7; i++) {
  2949. m = moment().subtract({d: i});
  2950. assert.equal(m.calendar(), m.format('[গত] dddd[,] LT'), 'Today - ' + i + ' days current time');
  2951. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  2952. assert.equal(m.calendar(), m.format('[গত] dddd[,] LT'), 'Today - ' + i + ' days beginning of day');
  2953. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  2954. assert.equal(m.calendar(), m.format('[গত] dddd[,] LT'), 'Today - ' + i + ' days end of day');
  2955. }
  2956. });
  2957. test('calendar all else', function (assert) {
  2958. var weeksAgo = moment().subtract({w: 1}),
  2959. weeksFromNow = moment().add({w: 1});
  2960. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  2961. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  2962. weeksAgo = moment().subtract({w: 2});
  2963. weeksFromNow = moment().add({w: 2});
  2964. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  2965. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  2966. });
  2967. test('meridiem', function (assert) {
  2968. assert.equal(moment([2011, 2, 23, 2, 30]).format('a'), 'রাত', 'before dawn');
  2969. assert.equal(moment([2011, 2, 23, 9, 30]).format('a'), 'সকাল', 'morning');
  2970. assert.equal(moment([2011, 2, 23, 14, 30]).format('a'), 'দুপুর', 'during day');
  2971. assert.equal(moment([2011, 2, 23, 17, 30]).format('a'), 'বিকাল', 'evening');
  2972. assert.equal(moment([2011, 2, 23, 19, 30]).format('a'), 'বিকাল', 'late evening');
  2973. assert.equal(moment([2011, 2, 23, 21, 20]).format('a'), 'রাত', 'night');
  2974. assert.equal(moment([2011, 2, 23, 2, 30]).format('A'), 'রাত', 'before dawn');
  2975. assert.equal(moment([2011, 2, 23, 9, 30]).format('A'), 'সকাল', 'morning');
  2976. assert.equal(moment([2011, 2, 23, 14, 30]).format('A'), 'দুপুর', ' during day');
  2977. assert.equal(moment([2011, 2, 23, 17, 30]).format('A'), 'বিকাল', 'evening');
  2978. assert.equal(moment([2011, 2, 23, 19, 30]).format('A'), 'বিকাল', 'late evening');
  2979. assert.equal(moment([2011, 2, 23, 21, 20]).format('A'), 'রাত', 'night');
  2980. });
  2981. test('weeks year starting sunday', function (assert) {
  2982. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  2983. assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1');
  2984. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  2985. assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2');
  2986. assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 3');
  2987. });
  2988. test('weeks year starting monday', function (assert) {
  2989. assert.equal(moment([2006, 11, 31]).week(), 1, 'Dec 31 2006 should be week 1');
  2990. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  2991. assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1');
  2992. assert.equal(moment([2007, 0, 7]).week(), 2, 'Jan 7 2007 should be week 2');
  2993. assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2');
  2994. assert.equal(moment([2007, 0, 14]).week(), 3, 'Jan 14 2007 should be week 3');
  2995. });
  2996. test('weeks year starting tuesday', function (assert) {
  2997. assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52');
  2998. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  2999. assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1');
  3000. assert.equal(moment([2008, 0, 6]).week(), 2, 'Jan 6 2008 should be week 2');
  3001. assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2');
  3002. assert.equal(moment([2008, 0, 13]).week(), 3, 'Jan 13 2008 should be week 3');
  3003. });
  3004. test('weeks year starting wednesday', function (assert) {
  3005. assert.equal(moment([2002, 11, 29]).week(), 1, 'Dec 29 2002 should be week 1');
  3006. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  3007. assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1');
  3008. assert.equal(moment([2003, 0, 5]).week(), 2, 'Jan 5 2003 should be week 2');
  3009. assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2');
  3010. assert.equal(moment([2003, 0, 12]).week(), 3, 'Jan 12 2003 should be week 3');
  3011. });
  3012. test('weeks year starting thursday', function (assert) {
  3013. assert.equal(moment([2008, 11, 28]).week(), 1, 'Dec 28 2008 should be week 1');
  3014. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  3015. assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1');
  3016. assert.equal(moment([2009, 0, 4]).week(), 2, 'Jan 4 2009 should be week 2');
  3017. assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2');
  3018. assert.equal(moment([2009, 0, 11]).week(), 3, 'Jan 11 2009 should be week 3');
  3019. });
  3020. test('weeks year starting friday', function (assert) {
  3021. assert.equal(moment([2009, 11, 27]).week(), 1, 'Dec 27 2009 should be week 1');
  3022. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  3023. assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 should be week 1');
  3024. assert.equal(moment([2010, 0, 3]).week(), 2, 'Jan 3 2010 should be week 2');
  3025. assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 should be week 2');
  3026. assert.equal(moment([2010, 0, 10]).week(), 3, 'Jan 10 2010 should be week 3');
  3027. });
  3028. test('weeks year starting saturday', function (assert) {
  3029. assert.equal(moment([2010, 11, 26]).week(), 1, 'Dec 26 2010 should be week 1');
  3030. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  3031. assert.equal(moment([2011, 0, 2]).week(), 2, 'Jan 2 2011 should be week 2');
  3032. assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2');
  3033. assert.equal(moment([2011, 0, 9]).week(), 3, 'Jan 9 2011 should be week 3');
  3034. });
  3035. test('weeks year starting sunday formatted', function (assert) {
  3036. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '১ ০১ ১', 'Jan 1 2012 should be week 1');
  3037. assert.equal(moment([2012, 0, 7]).format('w ww wo'), '১ ০১ ১', 'Jan 7 2012 should be week 1');
  3038. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '২ ০২ ২', 'Jan 8 2012 should be week 2');
  3039. assert.equal(moment([2012, 0, 14]).format('w ww wo'), '২ ০২ ২', 'Jan 14 2012 should be week 2');
  3040. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '৩ ০৩ ৩', 'Jan 15 2012 should be week 3');
  3041. });
  3042. test('lenient ordinal parsing', function (assert) {
  3043. var i, ordinalStr, testMoment;
  3044. for (i = 1; i <= 31; ++i) {
  3045. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  3046. testMoment = moment(ordinalStr, 'YYYY MM Do');
  3047. assert.equal(testMoment.year(), 2014,
  3048. 'lenient ordinal parsing ' + i + ' year check');
  3049. assert.equal(testMoment.month(), 0,
  3050. 'lenient ordinal parsing ' + i + ' month check');
  3051. assert.equal(testMoment.date(), i,
  3052. 'lenient ordinal parsing ' + i + ' date check');
  3053. }
  3054. });
  3055. test('lenient ordinal parsing of number', function (assert) {
  3056. var i, testMoment;
  3057. for (i = 1; i <= 31; ++i) {
  3058. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  3059. assert.equal(testMoment.year(), 2014,
  3060. 'lenient ordinal parsing of number ' + i + ' year check');
  3061. assert.equal(testMoment.month(), 0,
  3062. 'lenient ordinal parsing of number ' + i + ' month check');
  3063. assert.equal(testMoment.date(), i,
  3064. 'lenient ordinal parsing of number ' + i + ' date check');
  3065. }
  3066. });
  3067. test('strict ordinal parsing', function (assert) {
  3068. var i, ordinalStr, testMoment;
  3069. for (i = 1; i <= 31; ++i) {
  3070. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  3071. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  3072. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  3073. }
  3074. });
  3075. }));
  3076. ;(function (global, factory) {
  3077. typeof exports === 'object' && typeof module !== 'undefined'
  3078. && typeof require === 'function' ? factory(require('../../moment')) :
  3079. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  3080. factory(global.moment)
  3081. }(this, function (moment) { 'use strict';
  3082. /*global QUnit:false*/
  3083. var test = QUnit.test;
  3084. var expect = QUnit.expect;
  3085. function module (name, lifecycle) {
  3086. QUnit.module(name, {
  3087. setup : function () {
  3088. moment.locale('en');
  3089. moment.createFromInputFallback = function (config) {
  3090. throw new Error('input not handled by moment: ' + config._i);
  3091. };
  3092. if (lifecycle && lifecycle.setup) {
  3093. lifecycle.setup();
  3094. }
  3095. },
  3096. teardown : function () {
  3097. if (lifecycle && lifecycle.teardown) {
  3098. lifecycle.teardown();
  3099. }
  3100. }
  3101. });
  3102. }
  3103. function localeModule (name, lifecycle) {
  3104. QUnit.module('locale:' + name, {
  3105. setup : function () {
  3106. moment.locale(name);
  3107. moment.createFromInputFallback = function (config) {
  3108. throw new Error('input not handled by moment: ' + config._i);
  3109. };
  3110. if (lifecycle && lifecycle.setup) {
  3111. lifecycle.setup();
  3112. }
  3113. },
  3114. teardown : function () {
  3115. moment.locale('en');
  3116. if (lifecycle && lifecycle.teardown) {
  3117. lifecycle.teardown();
  3118. }
  3119. }
  3120. });
  3121. }
  3122. localeModule('bo');
  3123. test('parse', function (assert) {
  3124. var tests = 'ཟླ་བ་དང་པོ ཟླ་བ་དང་པོ._ཟླ་བ་གཉིས་པ ཟླ་བ་གཉིས་པ_ཟླ་བ་གསུམ་པ ཟླ་བ་གསུམ་པ_ཟླ་བ་བཞི་པ ཟླ་བ་བཞི་པ_ཟླ་བ་ལྔ་པ ཟླ་བ་ལྔ་པ_ཟླ་བ་དྲུག་པ ཟླ་བ་དྲུག་པ_ཟླ་བ་བདུན་པ ཟླ་བ་བདུན་པ_ཟླ་བ་བརྒྱད་པ ཟླ་བ་བརྒྱད་པ_ཟླ་བ་དགུ་པ ཟླ་བ་དགུ་པ_ཟླ་བ་བཅུ་པ ཟླ་བ་བཅུ་པ_ཟླ་བ་བཅུ་གཅིག་པ ཟླ་བ་བཅུ་གཅིག་པ_ཟླ་བ་བཅུ་གཉིས་པ ཟླ་བ་བཅུ་གཉིས་པ'.split('_'), i;
  3125. function equalTest(input, mmm, i) {
  3126. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  3127. }
  3128. for (i = 0; i < 12; i++) {
  3129. tests[i] = tests[i].split(' ');
  3130. equalTest(tests[i][0], 'MMM', i);
  3131. equalTest(tests[i][1], 'MMM', i);
  3132. equalTest(tests[i][0], 'MMMM', i);
  3133. equalTest(tests[i][1], 'MMMM', i);
  3134. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  3135. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  3136. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  3137. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  3138. }
  3139. });
  3140. test('format', function (assert) {
  3141. var a = [
  3142. ['dddd, Do MMMM YYYY, a h:mm:ss ལ་', 'གཟའ་ཉི་མ་, ༡༤ ཟླ་བ་གཉིས་པ ༢༠༡༠, ཉིན་གུང ༣:༢༥:༥༠ ལ་'],
  3143. ['ddd, a h ལ་', 'ཉི་མ་, ཉིན་གུང ༣ ལ་'],
  3144. ['M Mo MM MMMM MMM', '༢ ༢ ༠༢ ཟླ་བ་གཉིས་པ ཟླ་བ་གཉིས་པ'],
  3145. ['YYYY YY', '༢༠༡༠ ༡༠'],
  3146. ['D Do DD', '༡༤ ༡༤ ༡༤'],
  3147. ['d do dddd ddd dd', '༠ ༠ གཟའ་ཉི་མ་ ཉི་མ་ ཉི་མ་'],
  3148. ['DDD DDDo DDDD', '༤༥ ༤༥ ༠༤༥'],
  3149. ['w wo ww', '༨ ༨ ༠༨'],
  3150. ['h hh', '༣ ༠༣'],
  3151. ['H HH', '༡༥ ༡༥'],
  3152. ['m mm', '༢༥ ༢༥'],
  3153. ['s ss', '༥༠ ༥༠'],
  3154. ['a A', 'ཉིན་གུང ཉིན་གུང'],
  3155. ['LT', 'ཉིན་གུང ༣:༢༥'],
  3156. ['LTS', 'ཉིན་གུང ༣:༢༥:༥༠'],
  3157. ['L', '༡༤/༠༢/༢༠༡༠'],
  3158. ['LL', '༡༤ ཟླ་བ་གཉིས་པ ༢༠༡༠'],
  3159. ['LLL', '༡༤ ཟླ་བ་གཉིས་པ ༢༠༡༠, ཉིན་གུང ༣:༢༥'],
  3160. ['LLLL', 'གཟའ་ཉི་མ་, ༡༤ ཟླ་བ་གཉིས་པ ༢༠༡༠, ཉིན་གུང ༣:༢༥'],
  3161. ['l', '༡༤/༢/༢༠༡༠'],
  3162. ['ll', '༡༤ ཟླ་བ་གཉིས་པ ༢༠༡༠'],
  3163. ['lll', '༡༤ ཟླ་བ་གཉིས་པ ༢༠༡༠, ཉིན་གུང ༣:༢༥'],
  3164. ['llll', 'ཉི་མ་, ༡༤ ཟླ་བ་གཉིས་པ ༢༠༡༠, ཉིན་གུང ༣:༢༥']
  3165. ],
  3166. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  3167. i;
  3168. for (i = 0; i < a.length; i++) {
  3169. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  3170. }
  3171. });
  3172. test('format ordinal', function (assert) {
  3173. assert.equal(moment([2011, 0, 1]).format('DDDo'), '༡', '༡');
  3174. assert.equal(moment([2011, 0, 2]).format('DDDo'), '༢', '༢');
  3175. assert.equal(moment([2011, 0, 3]).format('DDDo'), '༣', '༣');
  3176. assert.equal(moment([2011, 0, 4]).format('DDDo'), '༤', '༤');
  3177. assert.equal(moment([2011, 0, 5]).format('DDDo'), '༥', '༥');
  3178. assert.equal(moment([2011, 0, 6]).format('DDDo'), '༦', '༦');
  3179. assert.equal(moment([2011, 0, 7]).format('DDDo'), '༧', '༧');
  3180. assert.equal(moment([2011, 0, 8]).format('DDDo'), '༨', '༨');
  3181. assert.equal(moment([2011, 0, 9]).format('DDDo'), '༩', '༩');
  3182. assert.equal(moment([2011, 0, 10]).format('DDDo'), '༡༠', '༡༠');
  3183. assert.equal(moment([2011, 0, 11]).format('DDDo'), '༡༡', '༡༡');
  3184. assert.equal(moment([2011, 0, 12]).format('DDDo'), '༡༢', '༡༢');
  3185. assert.equal(moment([2011, 0, 13]).format('DDDo'), '༡༣', '༡༣');
  3186. assert.equal(moment([2011, 0, 14]).format('DDDo'), '༡༤', '༡༤');
  3187. assert.equal(moment([2011, 0, 15]).format('DDDo'), '༡༥', '༡༥');
  3188. assert.equal(moment([2011, 0, 16]).format('DDDo'), '༡༦', '༡༦');
  3189. assert.equal(moment([2011, 0, 17]).format('DDDo'), '༡༧', '༡༧');
  3190. assert.equal(moment([2011, 0, 18]).format('DDDo'), '༡༨', '༡༨');
  3191. assert.equal(moment([2011, 0, 19]).format('DDDo'), '༡༩', '༡༩');
  3192. assert.equal(moment([2011, 0, 20]).format('DDDo'), '༢༠', '༢༠');
  3193. assert.equal(moment([2011, 0, 21]).format('DDDo'), '༢༡', '༢༡');
  3194. assert.equal(moment([2011, 0, 22]).format('DDDo'), '༢༢', '༢༢');
  3195. assert.equal(moment([2011, 0, 23]).format('DDDo'), '༢༣', '༢༣');
  3196. assert.equal(moment([2011, 0, 24]).format('DDDo'), '༢༤', '༢༤');
  3197. assert.equal(moment([2011, 0, 25]).format('DDDo'), '༢༥', '༢༥');
  3198. assert.equal(moment([2011, 0, 26]).format('DDDo'), '༢༦', '༢༦');
  3199. assert.equal(moment([2011, 0, 27]).format('DDDo'), '༢༧', '༢༧');
  3200. assert.equal(moment([2011, 0, 28]).format('DDDo'), '༢༨', '༢༨');
  3201. assert.equal(moment([2011, 0, 29]).format('DDDo'), '༢༩', '༢༩');
  3202. assert.equal(moment([2011, 0, 30]).format('DDDo'), '༣༠', '༣༠');
  3203. assert.equal(moment([2011, 0, 31]).format('DDDo'), '༣༡', '༣༡');
  3204. });
  3205. test('format month', function (assert) {
  3206. var expected = 'ཟླ་བ་དང་པོ ཟླ་བ་དང་པོ_ཟླ་བ་གཉིས་པ ཟླ་བ་གཉིས་པ_ཟླ་བ་གསུམ་པ ཟླ་བ་གསུམ་པ_ཟླ་བ་བཞི་པ ཟླ་བ་བཞི་པ_ཟླ་བ་ལྔ་པ ཟླ་བ་ལྔ་པ_ཟླ་བ་དྲུག་པ ཟླ་བ་དྲུག་པ_ཟླ་བ་བདུན་པ ཟླ་བ་བདུན་པ_ཟླ་བ་བརྒྱད་པ ཟླ་བ་བརྒྱད་པ_ཟླ་བ་དགུ་པ ཟླ་བ་དགུ་པ_ཟླ་བ་བཅུ་པ ཟླ་བ་བཅུ་པ_ཟླ་བ་བཅུ་གཅིག་པ ཟླ་བ་བཅུ་གཅིག་པ_ཟླ་བ་བཅུ་གཉིས་པ ཟླ་བ་བཅུ་གཉིས་པ'.split('_'), i;
  3207. for (i = 0; i < expected.length; i++) {
  3208. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  3209. }
  3210. });
  3211. test('format week', function (assert) {
  3212. var expected = 'གཟའ་ཉི་མ་ ཉི་མ་ ཉི་མ་_གཟའ་ཟླ་བ་ ཟླ་བ་ ཟླ་བ་_གཟའ་མིག་དམར་ མིག་དམར་ མིག་དམར་_གཟའ་ལྷག་པ་ ལྷག་པ་ ལྷག་པ་_གཟའ་ཕུར་བུ ཕུར་བུ ཕུར་བུ_གཟའ་པ་སངས་ པ་སངས་ པ་སངས་_གཟའ་སྤེན་པ་ སྤེན་པ་ སྤེན་པ་'.split('_'), i;
  3213. for (i = 0; i < expected.length; i++) {
  3214. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  3215. }
  3216. });
  3217. test('from', function (assert) {
  3218. var start = moment([2007, 1, 28]);
  3219. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ལམ་སང', '44 seconds = a few seconds');
  3220. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'སྐར་མ་གཅིག', '45 seconds = a minute');
  3221. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'སྐར་མ་གཅིག', '89 seconds = a minute');
  3222. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '༢ སྐར་མ', '90 seconds = 2 minutes');
  3223. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '༤༤ སྐར་མ', '44 minutes = 44 minutes');
  3224. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ཆུ་ཚོད་གཅིག', '45 minutes = an hour');
  3225. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ཆུ་ཚོད་གཅིག', '89 minutes = an hour');
  3226. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '༢ ཆུ་ཚོད', '90 minutes = 2 hours');
  3227. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '༥ ཆུ་ཚོད', '5 hours = 5 hours');
  3228. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '༢༡ ཆུ་ཚོད', '21 hours = 21 hours');
  3229. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ཉིན་གཅིག', '22 hours = a day');
  3230. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ཉིན་གཅིག', '35 hours = a day');
  3231. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '༢ ཉིན་', '36 hours = 2 days');
  3232. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ཉིན་གཅིག', '1 day = a day');
  3233. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '༥ ཉིན་', '5 days = 5 days');
  3234. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '༢༥ ཉིན་', '25 days = 25 days');
  3235. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ཟླ་བ་གཅིག', '26 days = a month');
  3236. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ཟླ་བ་གཅིག', '30 days = a month');
  3237. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ཟླ་བ་གཅིག', '43 days = a month');
  3238. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '༢ ཟླ་བ', '46 days = 2 months');
  3239. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '༢ ཟླ་བ', '75 days = 2 months');
  3240. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '༣ ཟླ་བ', '76 days = 3 months');
  3241. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ཟླ་བ་གཅིག', '1 month = a month');
  3242. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '༥ ཟླ་བ', '5 months = 5 months');
  3243. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ལོ་གཅིག', '345 days = a year');
  3244. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '༢ ལོ', '548 days = 2 years');
  3245. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ལོ་གཅིག', '1 year = a year');
  3246. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '༥ ལོ', '5 years = 5 years');
  3247. });
  3248. test('suffix', function (assert) {
  3249. assert.equal(moment(30000).from(0), 'ལམ་སང ལ་', 'prefix');
  3250. assert.equal(moment(0).from(30000), 'ལམ་སང སྔན་ལ', 'suffix');
  3251. });
  3252. test('now from now', function (assert) {
  3253. assert.equal(moment().fromNow(), 'ལམ་སང སྔན་ལ', 'now from now should display as in the past');
  3254. });
  3255. test('fromNow', function (assert) {
  3256. assert.equal(moment().add({s: 30}).fromNow(), 'ལམ་སང ལ་', 'ལམ་སང ལ་');
  3257. assert.equal(moment().add({d: 5}).fromNow(), '༥ ཉིན་ ལ་', '༥ ཉིན་ ལ་');
  3258. });
  3259. test('calendar day', function (assert) {
  3260. var a = moment().hours(2).minutes(0).seconds(0);
  3261. assert.equal(moment(a).calendar(), 'དི་རིང མཚན་མོ ༢:༠༠', 'today at the same time');
  3262. assert.equal(moment(a).add({m: 25}).calendar(), 'དི་རིང མཚན་མོ ༢:༢༥', 'Now plus 25 min');
  3263. assert.equal(moment(a).add({h: 3}).calendar(), 'དི་རིང ཞོགས་ཀས ༥:༠༠', 'Now plus 3 hour');
  3264. assert.equal(moment(a).add({d: 1}).calendar(), 'སང་ཉིན མཚན་མོ ༢:༠༠', 'tomorrow at the same time');
  3265. assert.equal(moment(a).subtract({h: 1}).calendar(), 'དི་རིང མཚན་མོ ༡:༠༠', 'Now minus 1 hour');
  3266. assert.equal(moment(a).subtract({d: 1}).calendar(), 'ཁ་སང མཚན་མོ ༢:༠༠', 'yesterday at the same time');
  3267. });
  3268. test('calendar next week', function (assert) {
  3269. var i, m;
  3270. for (i = 2; i < 7; i++) {
  3271. m = moment().add({d: i});
  3272. assert.equal(m.calendar(), m.format('[བདུན་ཕྲག་རྗེས་མ][,] LT'), 'Today + ' + i + ' days current time');
  3273. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  3274. assert.equal(m.calendar(), m.format('[བདུན་ཕྲག་རྗེས་མ][,] LT'), 'Today + ' + i + ' days beginning of day');
  3275. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  3276. assert.equal(m.calendar(), m.format('[བདུན་ཕྲག་རྗེས་མ][,] LT'), 'Today + ' + i + ' days end of day');
  3277. }
  3278. });
  3279. test('calendar last week', function (assert) {
  3280. var i, m;
  3281. for (i = 2; i < 7; i++) {
  3282. m = moment().subtract({d: i});
  3283. assert.equal(m.calendar(), m.format('[བདུན་ཕྲག་མཐའ་མ] dddd[,] LT'), 'Today - ' + i + ' days current time');
  3284. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  3285. assert.equal(m.calendar(), m.format('[བདུན་ཕྲག་མཐའ་མ] dddd[,] LT'), 'Today - ' + i + ' days beginning of day');
  3286. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  3287. assert.equal(m.calendar(), m.format('[བདུན་ཕྲག་མཐའ་མ] dddd[,] LT'), 'Today - ' + i + ' days end of day');
  3288. }
  3289. });
  3290. test('calendar all else', function (assert) {
  3291. var weeksAgo = moment().subtract({w: 1}),
  3292. weeksFromNow = moment().add({w: 1});
  3293. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  3294. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  3295. weeksAgo = moment().subtract({w: 2});
  3296. weeksFromNow = moment().add({w: 2});
  3297. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  3298. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  3299. });
  3300. test('meridiem', function (assert) {
  3301. assert.equal(moment([2011, 2, 23, 2, 30]).format('a'), 'མཚན་མོ', 'before dawn');
  3302. assert.equal(moment([2011, 2, 23, 9, 30]).format('a'), 'ཞོགས་ཀས', 'morning');
  3303. assert.equal(moment([2011, 2, 23, 14, 30]).format('a'), 'ཉིན་གུང', 'during day');
  3304. assert.equal(moment([2011, 2, 23, 17, 30]).format('a'), 'དགོང་དག', 'evening');
  3305. assert.equal(moment([2011, 2, 23, 19, 30]).format('a'), 'དགོང་དག', 'late evening');
  3306. assert.equal(moment([2011, 2, 23, 21, 20]).format('a'), 'མཚན་མོ', 'night');
  3307. assert.equal(moment([2011, 2, 23, 2, 30]).format('A'), 'མཚན་མོ', 'before dawn');
  3308. assert.equal(moment([2011, 2, 23, 9, 30]).format('A'), 'ཞོགས་ཀས', 'morning');
  3309. assert.equal(moment([2011, 2, 23, 14, 30]).format('A'), 'ཉིན་གུང', ' during day');
  3310. assert.equal(moment([2011, 2, 23, 17, 30]).format('A'), 'དགོང་དག', 'evening');
  3311. assert.equal(moment([2011, 2, 23, 19, 30]).format('A'), 'དགོང་དག', 'late evening');
  3312. assert.equal(moment([2011, 2, 23, 21, 20]).format('A'), 'མཚན་མོ', 'night');
  3313. });
  3314. test('weeks year starting sunday', function (assert) {
  3315. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  3316. assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1');
  3317. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  3318. assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2');
  3319. assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 3');
  3320. });
  3321. test('weeks year starting monday', function (assert) {
  3322. assert.equal(moment([2006, 11, 31]).week(), 1, 'Dec 31 2006 should be week 1');
  3323. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  3324. assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1');
  3325. assert.equal(moment([2007, 0, 7]).week(), 2, 'Jan 7 2007 should be week 2');
  3326. assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2');
  3327. assert.equal(moment([2007, 0, 14]).week(), 3, 'Jan 14 2007 should be week 3');
  3328. });
  3329. test('weeks year starting tuesday', function (assert) {
  3330. assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52');
  3331. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  3332. assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1');
  3333. assert.equal(moment([2008, 0, 6]).week(), 2, 'Jan 6 2008 should be week 2');
  3334. assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2');
  3335. assert.equal(moment([2008, 0, 13]).week(), 3, 'Jan 13 2008 should be week 3');
  3336. });
  3337. test('weeks year starting wednesday', function (assert) {
  3338. assert.equal(moment([2002, 11, 29]).week(), 1, 'Dec 29 2002 should be week 1');
  3339. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  3340. assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1');
  3341. assert.equal(moment([2003, 0, 5]).week(), 2, 'Jan 5 2003 should be week 2');
  3342. assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2');
  3343. assert.equal(moment([2003, 0, 12]).week(), 3, 'Jan 12 2003 should be week 3');
  3344. });
  3345. test('weeks year starting thursday', function (assert) {
  3346. assert.equal(moment([2008, 11, 28]).week(), 1, 'Dec 28 2008 should be week 1');
  3347. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  3348. assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1');
  3349. assert.equal(moment([2009, 0, 4]).week(), 2, 'Jan 4 2009 should be week 2');
  3350. assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2');
  3351. assert.equal(moment([2009, 0, 11]).week(), 3, 'Jan 11 2009 should be week 3');
  3352. });
  3353. test('weeks year starting friday', function (assert) {
  3354. assert.equal(moment([2009, 11, 27]).week(), 1, 'Dec 27 2009 should be week 1');
  3355. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  3356. assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 should be week 1');
  3357. assert.equal(moment([2010, 0, 3]).week(), 2, 'Jan 3 2010 should be week 2');
  3358. assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 should be week 2');
  3359. assert.equal(moment([2010, 0, 10]).week(), 3, 'Jan 10 2010 should be week 3');
  3360. });
  3361. test('weeks year starting saturday', function (assert) {
  3362. assert.equal(moment([2010, 11, 26]).week(), 1, 'Dec 26 2010 should be week 1');
  3363. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  3364. assert.equal(moment([2011, 0, 2]).week(), 2, 'Jan 2 2011 should be week 2');
  3365. assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2');
  3366. assert.equal(moment([2011, 0, 9]).week(), 3, 'Jan 9 2011 should be week 3');
  3367. });
  3368. test('weeks year starting sunday formatted', function (assert) {
  3369. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '༡ ༠༡ ༡', 'Jan 1 2012 should be week 1');
  3370. assert.equal(moment([2012, 0, 7]).format('w ww wo'), '༡ ༠༡ ༡', 'Jan 7 2012 should be week 1');
  3371. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '༢ ༠༢ ༢', 'Jan 8 2012 should be week 2');
  3372. assert.equal(moment([2012, 0, 14]).format('w ww wo'), '༢ ༠༢ ༢', 'Jan 14 2012 should be week 2');
  3373. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '༣ ༠༣ ༣', 'Jan 15 2012 should be week 3');
  3374. });
  3375. test('lenient ordinal parsing', function (assert) {
  3376. var i, ordinalStr, testMoment;
  3377. for (i = 1; i <= 31; ++i) {
  3378. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  3379. testMoment = moment(ordinalStr, 'YYYY MM Do');
  3380. assert.equal(testMoment.year(), 2014,
  3381. 'lenient ordinal parsing ' + i + ' year check');
  3382. assert.equal(testMoment.month(), 0,
  3383. 'lenient ordinal parsing ' + i + ' month check');
  3384. assert.equal(testMoment.date(), i,
  3385. 'lenient ordinal parsing ' + i + ' date check');
  3386. }
  3387. });
  3388. test('lenient ordinal parsing of number', function (assert) {
  3389. var i, testMoment;
  3390. for (i = 1; i <= 31; ++i) {
  3391. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  3392. assert.equal(testMoment.year(), 2014,
  3393. 'lenient ordinal parsing of number ' + i + ' year check');
  3394. assert.equal(testMoment.month(), 0,
  3395. 'lenient ordinal parsing of number ' + i + ' month check');
  3396. assert.equal(testMoment.date(), i,
  3397. 'lenient ordinal parsing of number ' + i + ' date check');
  3398. }
  3399. });
  3400. test('strict ordinal parsing', function (assert) {
  3401. var i, ordinalStr, testMoment;
  3402. for (i = 1; i <= 31; ++i) {
  3403. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  3404. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  3405. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  3406. }
  3407. });
  3408. }));
  3409. ;(function (global, factory) {
  3410. typeof exports === 'object' && typeof module !== 'undefined'
  3411. && typeof require === 'function' ? factory(require('../../moment')) :
  3412. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  3413. factory(global.moment)
  3414. }(this, function (moment) { 'use strict';
  3415. /*global QUnit:false*/
  3416. var test = QUnit.test;
  3417. var expect = QUnit.expect;
  3418. function module (name, lifecycle) {
  3419. QUnit.module(name, {
  3420. setup : function () {
  3421. moment.locale('en');
  3422. moment.createFromInputFallback = function (config) {
  3423. throw new Error('input not handled by moment: ' + config._i);
  3424. };
  3425. if (lifecycle && lifecycle.setup) {
  3426. lifecycle.setup();
  3427. }
  3428. },
  3429. teardown : function () {
  3430. if (lifecycle && lifecycle.teardown) {
  3431. lifecycle.teardown();
  3432. }
  3433. }
  3434. });
  3435. }
  3436. function localeModule (name, lifecycle) {
  3437. QUnit.module('locale:' + name, {
  3438. setup : function () {
  3439. moment.locale(name);
  3440. moment.createFromInputFallback = function (config) {
  3441. throw new Error('input not handled by moment: ' + config._i);
  3442. };
  3443. if (lifecycle && lifecycle.setup) {
  3444. lifecycle.setup();
  3445. }
  3446. },
  3447. teardown : function () {
  3448. moment.locale('en');
  3449. if (lifecycle && lifecycle.teardown) {
  3450. lifecycle.teardown();
  3451. }
  3452. }
  3453. });
  3454. }
  3455. localeModule('br');
  3456. test('parse', function (assert) {
  3457. var tests = 'Genver Gen_C\'hwevrer C\'hwe_Meurzh Meu_Ebrel Ebr_Mae Mae_Mezheven Eve_Gouere Gou_Eost Eos_Gwengolo Gwe_Here Her_Du Du_Kerzu Ker'.split('_'), i;
  3458. function equalTest(input, mmm, i) {
  3459. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  3460. }
  3461. for (i = 0; i < 12; i++) {
  3462. tests[i] = tests[i].split(' ');
  3463. equalTest(tests[i][0], 'MMM', i);
  3464. equalTest(tests[i][1], 'MMM', i);
  3465. equalTest(tests[i][0], 'MMMM', i);
  3466. equalTest(tests[i][1], 'MMMM', i);
  3467. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  3468. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  3469. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  3470. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  3471. }
  3472. });
  3473. test('format', function (assert) {
  3474. moment.locale('br');
  3475. var a = [
  3476. ['dddd, MMMM Do YYYY, h:mm:ss a', 'Sul, C\'hwevrer 14vet 2010, 3:25:50 pm'],
  3477. ['ddd, h A', 'Sul, 3 PM'],
  3478. ['M Mo MM MMMM MMM', '2 2vet 02 C\'hwevrer C\'hwe'],
  3479. ['YYYY YY', '2010 10'],
  3480. ['D Do DD', '14 14vet 14'],
  3481. ['d do dddd ddd dd', '0 0vet Sul Sul Su'],
  3482. ['DDD DDDo DDDD', '45 45vet 045'],
  3483. ['w wo ww', '6 6vet 06'],
  3484. ['h hh', '3 03'],
  3485. ['H HH', '15 15'],
  3486. ['m mm', '25 25'],
  3487. ['s ss', '50 50'],
  3488. ['DDDo [devezh] [ar] [vloaz]', '45vet devezh ar vloaz'],
  3489. ['L', '14/02/2010'],
  3490. ['LL', '14 a viz C\'hwevrer 2010'],
  3491. ['LLL', '14 a viz C\'hwevrer 2010 3e25 PM'],
  3492. ['LLLL', 'Sul, 14 a viz C\'hwevrer 2010 3e25 PM']
  3493. ],
  3494. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  3495. i;
  3496. for (i = 0; i < a.length; i++) {
  3497. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  3498. }
  3499. });
  3500. test('format ordinal', function (assert) {
  3501. moment.locale('br');
  3502. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1añ', '1añ');
  3503. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2vet', '2vet');
  3504. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3vet', '3vet');
  3505. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4vet', '4vet');
  3506. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5vet', '5vet');
  3507. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6vet', '6vet');
  3508. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7vet', '7vet');
  3509. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8vet', '8vet');
  3510. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9vet', '9vet');
  3511. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10vet', '10vet');
  3512. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11vet', '11vet');
  3513. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12vet', '12vet');
  3514. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13vet', '13vet');
  3515. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14vet', '14vet');
  3516. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15vet', '15vet');
  3517. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16vet', '16vet');
  3518. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17vet', '17vet');
  3519. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18vet', '18vet');
  3520. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19vet', '19vet');
  3521. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20vet', '20vet');
  3522. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21vet', '21vet');
  3523. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22vet', '22vet');
  3524. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23vet', '23vet');
  3525. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24vet', '24vet');
  3526. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25vet', '25vet');
  3527. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26vet', '26vet');
  3528. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27vet', '27vet');
  3529. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28vet', '28vet');
  3530. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29vet', '29vet');
  3531. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30vet', '30vet');
  3532. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31vet', '31vet');
  3533. });
  3534. test('format month', function (assert) {
  3535. moment.locale('br');
  3536. var expected = 'Genver Gen_C\'hwevrer C\'hwe_Meurzh Meu_Ebrel Ebr_Mae Mae_Mezheven Eve_Gouere Gou_Eost Eos_Gwengolo Gwe_Here Her_Du Du_Kerzu Ker'.split('_'), i;
  3537. for (i = 0; i < expected.length; i++) {
  3538. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  3539. }
  3540. });
  3541. test('format week', function (assert) {
  3542. moment.locale('br');
  3543. var expected = 'Sul Sul Su_Lun Lun Lu_Meurzh Meu Me_Merc\'her Mer Mer_Yaou Yao Ya_Gwener Gwe Gw_Sadorn Sad Sa'.split('_'), i;
  3544. for (i = 0; i < expected.length; i++) {
  3545. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  3546. }
  3547. });
  3548. test('from', function (assert) {
  3549. moment.locale('br');
  3550. var start = moment([2007, 1, 28]);
  3551. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'un nebeud segondennoù', '44 seconds = a few seconds');
  3552. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'ur vunutenn', '45 seconds = a minute');
  3553. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'ur vunutenn', '89 seconds = a minute');
  3554. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 vunutenn', '90 seconds = 2 minutes');
  3555. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 munutenn', '44 minutes = 44 minutes');
  3556. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'un eur', '45 minutes = an hour');
  3557. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'un eur', '89 minutes = an hour');
  3558. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 eur', '90 minutes = 2 hours');
  3559. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 eur', '5 hours = 5 hours');
  3560. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 eur', '21 hours = 21 hours');
  3561. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'un devezh', '22 hours = a day');
  3562. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'un devezh', '35 hours = a day');
  3563. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 zevezh', '36 hours = 2 days');
  3564. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'un devezh', '1 day = a day');
  3565. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 devezh', '5 days = 5 days');
  3566. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 devezh', '25 days = 25 days');
  3567. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ur miz', '26 days = a month');
  3568. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ur miz', '30 days = a month');
  3569. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ur miz', '43 days = a month');
  3570. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 viz', '46 days = 2 months');
  3571. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 viz', '75 days = 2 months');
  3572. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 miz', '76 days = 3 months');
  3573. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ur miz', '1 month = a month');
  3574. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 miz', '5 months = 5 months');
  3575. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ur bloaz', '345 days = a year');
  3576. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 vloaz', '548 days = 2 years');
  3577. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ur bloaz', '1 year = a year');
  3578. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 bloaz', '5 years = 5 years');
  3579. });
  3580. test('suffix', function (assert) {
  3581. moment.locale('br');
  3582. assert.equal(moment(30000).from(0), 'a-benn un nebeud segondennoù', 'prefix');
  3583. assert.equal(moment(0).from(30000), 'un nebeud segondennoù \'zo', 'suffix');
  3584. });
  3585. test('now from now', function (assert) {
  3586. moment.locale('br');
  3587. assert.equal(moment().fromNow(), 'un nebeud segondennoù \'zo', 'now from now should display as in the past');
  3588. });
  3589. test('fromNow', function (assert) {
  3590. moment.locale('br');
  3591. assert.equal(moment().add({s: 30}).fromNow(), 'a-benn un nebeud segondennoù', 'in a few seconds');
  3592. assert.equal(moment().add({d: 5}).fromNow(), 'a-benn 5 devezh', 'in 5 days');
  3593. });
  3594. test('calendar day', function (assert) {
  3595. moment.locale('br');
  3596. var a = moment().hours(2).minutes(0).seconds(0);
  3597. assert.equal(moment(a).calendar(), 'Hiziv da 2e00 AM', 'today at the same time');
  3598. assert.equal(moment(a).add({m: 25}).calendar(), 'Hiziv da 2e25 AM', 'Now plus 25 min');
  3599. assert.equal(moment(a).add({h: 1}).calendar(), 'Hiziv da 3e00 AM', 'Now plus 1 hour');
  3600. assert.equal(moment(a).add({d: 1}).calendar(), 'Warc\'hoazh da 2e00 AM', 'tomorrow at the same time');
  3601. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Hiziv da 1e00 AM', 'Now minus 1 hour');
  3602. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Dec\'h da 2e00 AM', 'yesterday at the same time');
  3603. });
  3604. test('calendar next week', function (assert) {
  3605. moment.locale('br');
  3606. var i, m;
  3607. for (i = 2; i < 7; i++) {
  3608. m = moment().add({d: i});
  3609. assert.equal(m.calendar(), m.format('dddd [da] LT'), 'Today + ' + i + ' days current time');
  3610. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  3611. assert.equal(m.calendar(), m.format('dddd [da] LT'), 'Today + ' + i + ' days beginning of day');
  3612. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  3613. assert.equal(m.calendar(), m.format('dddd [da] LT'), 'Today + ' + i + ' days end of day');
  3614. }
  3615. });
  3616. test('calendar last week', function (assert) {
  3617. moment.locale('br');
  3618. var i, m;
  3619. for (i = 2; i < 7; i++) {
  3620. m = moment().subtract({d: i});
  3621. assert.equal(m.calendar(), m.format('dddd [paset da] LT'), 'Today - ' + i + ' days current time');
  3622. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  3623. assert.equal(m.calendar(), m.format('dddd [paset da] LT'), 'Today - ' + i + ' days beginning of day');
  3624. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  3625. assert.equal(m.calendar(), m.format('dddd [paset da] LT'), 'Today - ' + i + ' days end of day');
  3626. }
  3627. });
  3628. test('calendar all else', function (assert) {
  3629. moment.locale('br');
  3630. var weeksAgo = moment().subtract({w: 1}),
  3631. weeksFromNow = moment().add({w: 1});
  3632. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  3633. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  3634. weeksAgo = moment().subtract({w: 2});
  3635. weeksFromNow = moment().add({w: 2});
  3636. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  3637. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  3638. });
  3639. test('special mutations for years', function (assert) {
  3640. moment.locale('br');
  3641. var start = moment([2007, 1, 28]);
  3642. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ur bloaz', 'mutation 1 year');
  3643. assert.equal(start.from(moment([2007, 1, 28]).add({y: 2}), true), '2 vloaz', 'mutation 2 years');
  3644. assert.equal(start.from(moment([2007, 1, 28]).add({y: 3}), true), '3 bloaz', 'mutation 3 years');
  3645. assert.equal(start.from(moment([2007, 1, 28]).add({y: 4}), true), '4 bloaz', 'mutation 4 years');
  3646. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 bloaz', 'mutation 5 years');
  3647. assert.equal(start.from(moment([2007, 1, 28]).add({y: 9}), true), '9 bloaz', 'mutation 9 years');
  3648. assert.equal(start.from(moment([2007, 1, 28]).add({y: 10}), true), '10 vloaz', 'mutation 10 years');
  3649. assert.equal(start.from(moment([2007, 1, 28]).add({y: 21}), true), '21 bloaz', 'mutation 21 years');
  3650. assert.equal(start.from(moment([2007, 1, 28]).add({y: 22}), true), '22 vloaz', 'mutation 22 years');
  3651. assert.equal(start.from(moment([2007, 1, 28]).add({y: 133}), true), '133 bloaz', 'mutation 133 years');
  3652. assert.equal(start.from(moment([2007, 1, 28]).add({y: 148}), true), '148 vloaz', 'mutation 148 years');
  3653. assert.equal(start.from(moment([2007, 1, 28]).add({y: 261}), true), '261 bloaz', 'mutation 261 years');
  3654. });
  3655. test('lenient ordinal parsing', function (assert) {
  3656. var i, ordinalStr, testMoment;
  3657. for (i = 1; i <= 31; ++i) {
  3658. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  3659. testMoment = moment(ordinalStr, 'YYYY MM Do');
  3660. assert.equal(testMoment.year(), 2014,
  3661. 'lenient ordinal parsing ' + i + ' year check');
  3662. assert.equal(testMoment.month(), 0,
  3663. 'lenient ordinal parsing ' + i + ' month check');
  3664. assert.equal(testMoment.date(), i,
  3665. 'lenient ordinal parsing ' + i + ' date check');
  3666. }
  3667. });
  3668. test('lenient ordinal parsing of number', function (assert) {
  3669. var i, testMoment;
  3670. for (i = 1; i <= 31; ++i) {
  3671. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  3672. assert.equal(testMoment.year(), 2014,
  3673. 'lenient ordinal parsing of number ' + i + ' year check');
  3674. assert.equal(testMoment.month(), 0,
  3675. 'lenient ordinal parsing of number ' + i + ' month check');
  3676. assert.equal(testMoment.date(), i,
  3677. 'lenient ordinal parsing of number ' + i + ' date check');
  3678. }
  3679. });
  3680. test('strict ordinal parsing', function (assert) {
  3681. var i, ordinalStr, testMoment;
  3682. for (i = 1; i <= 31; ++i) {
  3683. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  3684. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  3685. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  3686. }
  3687. });
  3688. }));
  3689. ;(function (global, factory) {
  3690. typeof exports === 'object' && typeof module !== 'undefined'
  3691. && typeof require === 'function' ? factory(require('../../moment')) :
  3692. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  3693. factory(global.moment)
  3694. }(this, function (moment) { 'use strict';
  3695. /*global QUnit:false*/
  3696. var test = QUnit.test;
  3697. var expect = QUnit.expect;
  3698. function module (name, lifecycle) {
  3699. QUnit.module(name, {
  3700. setup : function () {
  3701. moment.locale('en');
  3702. moment.createFromInputFallback = function (config) {
  3703. throw new Error('input not handled by moment: ' + config._i);
  3704. };
  3705. if (lifecycle && lifecycle.setup) {
  3706. lifecycle.setup();
  3707. }
  3708. },
  3709. teardown : function () {
  3710. if (lifecycle && lifecycle.teardown) {
  3711. lifecycle.teardown();
  3712. }
  3713. }
  3714. });
  3715. }
  3716. function localeModule (name, lifecycle) {
  3717. QUnit.module('locale:' + name, {
  3718. setup : function () {
  3719. moment.locale(name);
  3720. moment.createFromInputFallback = function (config) {
  3721. throw new Error('input not handled by moment: ' + config._i);
  3722. };
  3723. if (lifecycle && lifecycle.setup) {
  3724. lifecycle.setup();
  3725. }
  3726. },
  3727. teardown : function () {
  3728. moment.locale('en');
  3729. if (lifecycle && lifecycle.teardown) {
  3730. lifecycle.teardown();
  3731. }
  3732. }
  3733. });
  3734. }
  3735. localeModule('bs');
  3736. test('parse', function (assert) {
  3737. var tests = 'januar jan._februar feb._mart mar._april apr._maj maj._juni jun._juli jul._august aug._septembar sep._oktobar okt._novembar nov._decembar dec.'.split('_'), i;
  3738. function equalTest(input, mmm, i) {
  3739. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  3740. }
  3741. for (i = 0; i < 12; i++) {
  3742. tests[i] = tests[i].split(' ');
  3743. equalTest(tests[i][0], 'MMM', i);
  3744. equalTest(tests[i][1], 'MMM', i);
  3745. equalTest(tests[i][0], 'MMMM', i);
  3746. equalTest(tests[i][1], 'MMMM', i);
  3747. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  3748. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  3749. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  3750. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  3751. }
  3752. });
  3753. test('format', function (assert) {
  3754. var a = [
  3755. ['dddd, Do MMMM YYYY, h:mm:ss a', 'nedjelja, 14. februar 2010, 3:25:50 pm'],
  3756. ['ddd, hA', 'ned., 3PM'],
  3757. ['M Mo MM MMMM MMM', '2 2. 02 februar feb.'],
  3758. ['YYYY YY', '2010 10'],
  3759. ['D Do DD', '14 14. 14'],
  3760. ['d do dddd ddd dd', '0 0. nedjelja ned. ne'],
  3761. ['DDD DDDo DDDD', '45 45. 045'],
  3762. ['w wo ww', '7 7. 07'],
  3763. ['h hh', '3 03'],
  3764. ['H HH', '15 15'],
  3765. ['m mm', '25 25'],
  3766. ['s ss', '50 50'],
  3767. ['a A', 'pm PM'],
  3768. ['[the] DDDo [day of the year]', 'the 45. day of the year'],
  3769. ['LTS', '15:25:50'],
  3770. ['L', '14. 02. 2010'],
  3771. ['LL', '14. februar 2010'],
  3772. ['LLL', '14. februar 2010 15:25'],
  3773. ['LLLL', 'nedjelja, 14. februar 2010 15:25'],
  3774. ['l', '14. 2. 2010'],
  3775. ['ll', '14. feb. 2010'],
  3776. ['lll', '14. feb. 2010 15:25'],
  3777. ['llll', 'ned., 14. feb. 2010 15:25']
  3778. ],
  3779. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  3780. i;
  3781. for (i = 0; i < a.length; i++) {
  3782. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  3783. }
  3784. });
  3785. test('format ordinal', function (assert) {
  3786. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
  3787. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
  3788. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
  3789. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
  3790. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
  3791. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
  3792. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
  3793. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
  3794. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
  3795. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
  3796. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
  3797. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
  3798. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
  3799. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
  3800. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
  3801. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
  3802. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
  3803. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
  3804. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
  3805. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
  3806. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
  3807. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
  3808. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
  3809. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
  3810. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
  3811. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
  3812. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
  3813. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
  3814. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
  3815. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
  3816. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
  3817. });
  3818. test('format month', function (assert) {
  3819. var expected = 'januar jan._februar feb._mart mar._april apr._maj maj._juni jun._juli jul._august aug._septembar sep._oktobar okt._novembar nov._decembar dec.'.split('_'), i;
  3820. for (i = 0; i < expected.length; i++) {
  3821. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  3822. }
  3823. });
  3824. test('format week', function (assert) {
  3825. var expected = 'nedjelja ned. ne_ponedjeljak pon. po_utorak uto. ut_srijeda sri. sr_četvrtak čet. če_petak pet. pe_subota sub. su'.split('_'), i;
  3826. for (i = 0; i < expected.length; i++) {
  3827. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  3828. }
  3829. });
  3830. test('from', function (assert) {
  3831. var start = moment([2007, 1, 28]);
  3832. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'par sekundi', '44 seconds = a few seconds');
  3833. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'jedna minuta', '45 seconds = a minute');
  3834. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'jedna minuta', '89 seconds = a minute');
  3835. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minute', '90 seconds = 2 minutes');
  3836. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuta', '44 minutes = 44 minutes');
  3837. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'jedan sat', '45 minutes = an hour');
  3838. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'jedan sat', '89 minutes = an hour');
  3839. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 sata', '90 minutes = 2 hours');
  3840. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 sati', '5 hours = 5 hours');
  3841. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 sati', '21 hours = 21 hours');
  3842. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'dan', '22 hours = a day');
  3843. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'dan', '35 hours = a day');
  3844. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dana', '36 hours = 2 days');
  3845. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'dan', '1 day = a day');
  3846. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dana', '5 days = 5 days');
  3847. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dana', '25 days = 25 days');
  3848. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'mjesec', '26 days = a month');
  3849. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'mjesec', '30 days = a month');
  3850. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'mjesec', '43 days = a month');
  3851. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mjeseca', '46 days = 2 months');
  3852. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mjeseca', '75 days = 2 months');
  3853. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mjeseca', '76 days = 3 months');
  3854. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'mjesec', '1 month = a month');
  3855. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mjeseci', '5 months = 5 months');
  3856. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'godinu', '345 days = a year');
  3857. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 godine', '548 days = 2 years');
  3858. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'godinu', '1 year = a year');
  3859. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 godina', '5 years = 5 years');
  3860. });
  3861. test('suffix', function (assert) {
  3862. assert.equal(moment(30000).from(0), 'za par sekundi', 'prefix');
  3863. assert.equal(moment(0).from(30000), 'prije par sekundi', 'prefix');
  3864. });
  3865. test('now from now', function (assert) {
  3866. assert.equal(moment().fromNow(), 'prije par sekundi', 'now from now should display as in the past');
  3867. });
  3868. test('fromNow', function (assert) {
  3869. assert.equal(moment().add({s: 30}).fromNow(), 'za par sekundi', 'in a few seconds');
  3870. assert.equal(moment().add({d: 5}).fromNow(), 'za 5 dana', 'in 5 days');
  3871. });
  3872. test('calendar day', function (assert) {
  3873. var a = moment().hours(2).minutes(0).seconds(0);
  3874. assert.equal(moment(a).calendar(), 'danas u 2:00', 'today at the same time');
  3875. assert.equal(moment(a).add({m: 25}).calendar(), 'danas u 2:25', 'Now plus 25 min');
  3876. assert.equal(moment(a).add({h: 1}).calendar(), 'danas u 3:00', 'Now plus 1 hour');
  3877. assert.equal(moment(a).add({d: 1}).calendar(), 'sutra u 2:00', 'tomorrow at the same time');
  3878. assert.equal(moment(a).subtract({h: 1}).calendar(), 'danas u 1:00', 'Now minus 1 hour');
  3879. assert.equal(moment(a).subtract({d: 1}).calendar(), 'jučer u 2:00', 'yesterday at the same time');
  3880. });
  3881. test('calendar next week', function (assert) {
  3882. var i, m;
  3883. function makeFormat(d) {
  3884. switch (d.day()) {
  3885. case 0:
  3886. return '[u] [nedjelju] [u] LT';
  3887. case 3:
  3888. return '[u] [srijedu] [u] LT';
  3889. case 6:
  3890. return '[u] [subotu] [u] LT';
  3891. case 1:
  3892. case 2:
  3893. case 4:
  3894. case 5:
  3895. return '[u] dddd [u] LT';
  3896. }
  3897. }
  3898. for (i = 2; i < 7; i++) {
  3899. m = moment().add({d: i});
  3900. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days current time');
  3901. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  3902. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days beginning of day');
  3903. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  3904. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days end of day');
  3905. }
  3906. });
  3907. test('calendar last week', function (assert) {
  3908. var i, m;
  3909. function makeFormat(d) {
  3910. switch (d.day()) {
  3911. case 0:
  3912. case 3:
  3913. return '[prošlu] dddd [u] LT';
  3914. case 6:
  3915. return '[prošle] [subote] [u] LT';
  3916. case 1:
  3917. case 2:
  3918. case 4:
  3919. case 5:
  3920. return '[prošli] dddd [u] LT';
  3921. }
  3922. }
  3923. for (i = 2; i < 7; i++) {
  3924. m = moment().subtract({d: i});
  3925. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days current time');
  3926. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  3927. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days beginning of day');
  3928. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  3929. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days end of day');
  3930. }
  3931. });
  3932. test('calendar all else', function (assert) {
  3933. var weeksAgo = moment().subtract({w: 1}),
  3934. weeksFromNow = moment().add({w: 1});
  3935. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  3936. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  3937. weeksAgo = moment().subtract({w: 2});
  3938. weeksFromNow = moment().add({w: 2});
  3939. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  3940. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  3941. });
  3942. test('weeks year starting sunday', function (assert) {
  3943. assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1');
  3944. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  3945. assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2');
  3946. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  3947. assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3');
  3948. });
  3949. test('weeks year starting monday', function (assert) {
  3950. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  3951. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  3952. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  3953. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  3954. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  3955. });
  3956. test('weeks year starting tuesday', function (assert) {
  3957. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  3958. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  3959. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  3960. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  3961. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  3962. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  3963. });
  3964. test('weeks year starting wednesday', function (assert) {
  3965. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  3966. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  3967. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  3968. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  3969. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  3970. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  3971. });
  3972. test('weeks year starting thursday', function (assert) {
  3973. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  3974. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  3975. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  3976. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  3977. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  3978. assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3');
  3979. });
  3980. test('weeks year starting friday', function (assert) {
  3981. assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1');
  3982. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  3983. assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1');
  3984. assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2');
  3985. assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2');
  3986. assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3');
  3987. });
  3988. test('weeks year starting saturday', function (assert) {
  3989. assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1');
  3990. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  3991. assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1');
  3992. assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2');
  3993. assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2');
  3994. assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3');
  3995. });
  3996. test('weeks year starting sunday formatted', function (assert) {
  3997. assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1.', 'Dec 26 2011 should be week 1');
  3998. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1.', 'Jan 1 2012 should be week 1');
  3999. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2.', 'Jan 2 2012 should be week 2');
  4000. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2.', 'Jan 8 2012 should be week 2');
  4001. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3.', 'Jan 9 2012 should be week 3');
  4002. });
  4003. test('lenient ordinal parsing', function (assert) {
  4004. var i, ordinalStr, testMoment;
  4005. for (i = 1; i <= 31; ++i) {
  4006. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  4007. testMoment = moment(ordinalStr, 'YYYY MM Do');
  4008. assert.equal(testMoment.year(), 2014,
  4009. 'lenient ordinal parsing ' + i + ' year check');
  4010. assert.equal(testMoment.month(), 0,
  4011. 'lenient ordinal parsing ' + i + ' month check');
  4012. assert.equal(testMoment.date(), i,
  4013. 'lenient ordinal parsing ' + i + ' date check');
  4014. }
  4015. });
  4016. test('lenient ordinal parsing of number', function (assert) {
  4017. var i, testMoment;
  4018. for (i = 1; i <= 31; ++i) {
  4019. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  4020. assert.equal(testMoment.year(), 2014,
  4021. 'lenient ordinal parsing of number ' + i + ' year check');
  4022. assert.equal(testMoment.month(), 0,
  4023. 'lenient ordinal parsing of number ' + i + ' month check');
  4024. assert.equal(testMoment.date(), i,
  4025. 'lenient ordinal parsing of number ' + i + ' date check');
  4026. }
  4027. });
  4028. test('strict ordinal parsing', function (assert) {
  4029. var i, ordinalStr, testMoment;
  4030. for (i = 1; i <= 31; ++i) {
  4031. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  4032. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  4033. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  4034. }
  4035. });
  4036. }));
  4037. ;(function (global, factory) {
  4038. typeof exports === 'object' && typeof module !== 'undefined'
  4039. && typeof require === 'function' ? factory(require('../../moment')) :
  4040. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  4041. factory(global.moment)
  4042. }(this, function (moment) { 'use strict';
  4043. /*global QUnit:false*/
  4044. var test = QUnit.test;
  4045. var expect = QUnit.expect;
  4046. function module (name, lifecycle) {
  4047. QUnit.module(name, {
  4048. setup : function () {
  4049. moment.locale('en');
  4050. moment.createFromInputFallback = function (config) {
  4051. throw new Error('input not handled by moment: ' + config._i);
  4052. };
  4053. if (lifecycle && lifecycle.setup) {
  4054. lifecycle.setup();
  4055. }
  4056. },
  4057. teardown : function () {
  4058. if (lifecycle && lifecycle.teardown) {
  4059. lifecycle.teardown();
  4060. }
  4061. }
  4062. });
  4063. }
  4064. function localeModule (name, lifecycle) {
  4065. QUnit.module('locale:' + name, {
  4066. setup : function () {
  4067. moment.locale(name);
  4068. moment.createFromInputFallback = function (config) {
  4069. throw new Error('input not handled by moment: ' + config._i);
  4070. };
  4071. if (lifecycle && lifecycle.setup) {
  4072. lifecycle.setup();
  4073. }
  4074. },
  4075. teardown : function () {
  4076. moment.locale('en');
  4077. if (lifecycle && lifecycle.teardown) {
  4078. lifecycle.teardown();
  4079. }
  4080. }
  4081. });
  4082. }
  4083. localeModule('ca');
  4084. test('parse', function (assert) {
  4085. var tests = 'gener gen._febrer febr._març mar._abril abr._maig mai._juny jun._juliol jul._agost ag._setembre set._octubre oct._novembre nov._desembre des.'.split('_'), i;
  4086. function equalTest(input, mmm, i) {
  4087. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  4088. }
  4089. for (i = 0; i < 12; i++) {
  4090. tests[i] = tests[i].split(' ');
  4091. equalTest(tests[i][0], 'MMM', i);
  4092. equalTest(tests[i][1], 'MMM', i);
  4093. equalTest(tests[i][0], 'MMMM', i);
  4094. equalTest(tests[i][1], 'MMMM', i);
  4095. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  4096. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  4097. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  4098. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  4099. }
  4100. });
  4101. test('format', function (assert) {
  4102. var a = [
  4103. ['dddd, Do MMMM YYYY, h:mm:ss a', 'diumenge, 14è febrer 2010, 3:25:50 pm'],
  4104. ['ddd, hA', 'dg., 3PM'],
  4105. ['M Mo MM MMMM MMM', '2 2n 02 febrer febr.'],
  4106. ['YYYY YY', '2010 10'],
  4107. ['D Do DD', '14 14è 14'],
  4108. ['d do dddd ddd dd', '0 0è diumenge dg. Dg'],
  4109. ['DDD DDDo DDDD', '45 45è 045'],
  4110. ['w wo ww', '6 6a 06'],
  4111. ['h hh', '3 03'],
  4112. ['H HH', '15 15'],
  4113. ['m mm', '25 25'],
  4114. ['s ss', '50 50'],
  4115. ['a A', 'pm PM'],
  4116. ['[the] DDDo [day of the year]', 'the 45è day of the year'],
  4117. ['LTS', '15:25:50'],
  4118. ['L', '14/02/2010'],
  4119. ['LL', '14 febrer 2010'],
  4120. ['LLL', '14 febrer 2010 15:25'],
  4121. ['LLLL', 'diumenge 14 febrer 2010 15:25'],
  4122. ['l', '14/2/2010'],
  4123. ['ll', '14 febr. 2010'],
  4124. ['lll', '14 febr. 2010 15:25'],
  4125. ['llll', 'dg. 14 febr. 2010 15:25']
  4126. ],
  4127. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  4128. i;
  4129. for (i = 0; i < a.length; i++) {
  4130. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  4131. }
  4132. });
  4133. test('format ordinal', function (assert) {
  4134. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1r', '1r');
  4135. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2n', '2n');
  4136. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3r', '3r');
  4137. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4t', '4t');
  4138. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5è', '5è');
  4139. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6è', '6è');
  4140. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7è', '7è');
  4141. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8è', '8è');
  4142. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9è', '9è');
  4143. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10è', '10è');
  4144. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11è', '11è');
  4145. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12è', '12è');
  4146. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13è', '13è');
  4147. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14è', '14è');
  4148. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15è', '15è');
  4149. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16è', '16è');
  4150. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17è', '17è');
  4151. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18è', '18è');
  4152. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19è', '19è');
  4153. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20è', '20è');
  4154. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21è', '21è');
  4155. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22è', '22è');
  4156. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23è', '23è');
  4157. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24è', '24è');
  4158. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25è', '25è');
  4159. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26è', '26è');
  4160. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27è', '27è');
  4161. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28è', '28è');
  4162. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29è', '29è');
  4163. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30è', '30è');
  4164. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31è', '31è');
  4165. });
  4166. test('format month', function (assert) {
  4167. var expected = 'gener gen._febrer febr._març mar._abril abr._maig mai._juny jun._juliol jul._agost ag._setembre set._octubre oct._novembre nov._desembre des.'.split('_'), i;
  4168. for (i = 0; i < expected.length; i++) {
  4169. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  4170. }
  4171. });
  4172. test('format week', function (assert) {
  4173. var expected = 'diumenge dg. Dg_dilluns dl. Dl_dimarts dt. Dt_dimecres dc. Dc_dijous dj. Dj_divendres dv. Dv_dissabte ds. Ds'.split('_'), i;
  4174. for (i = 0; i < expected.length; i++) {
  4175. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  4176. }
  4177. });
  4178. test('from', function (assert) {
  4179. var start = moment([2007, 1, 28]);
  4180. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'uns segons', '44 seconds = a few seconds');
  4181. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'un minut', '45 seconds = a minute');
  4182. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'un minut', '89 seconds = a minute');
  4183. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuts', '90 seconds = 2 minutes');
  4184. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuts', '44 minutes = 44 minutes');
  4185. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'una hora', '45 minutes = an hour');
  4186. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'una hora', '89 minutes = an hour');
  4187. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 hores', '90 minutes = 2 hours');
  4188. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 hores', '5 hours = 5 hours');
  4189. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 hores', '21 hours = 21 hours');
  4190. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'un dia', '22 hours = a day');
  4191. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'un dia', '35 hours = a day');
  4192. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dies', '36 hours = 2 days');
  4193. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'un dia', '1 day = a day');
  4194. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dies', '5 days = 5 days');
  4195. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dies', '25 days = 25 days');
  4196. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'un mes', '26 days = a month');
  4197. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'un mes', '30 days = a month');
  4198. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'un mes', '43 days = a month');
  4199. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mesos', '46 days = 2 months');
  4200. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mesos', '75 days = 2 months');
  4201. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mesos', '76 days = 3 months');
  4202. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'un mes', '1 month = a month');
  4203. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mesos', '5 months = 5 months');
  4204. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'un any', '345 days = a year');
  4205. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 anys', '548 days = 2 years');
  4206. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'un any', '1 year = a year');
  4207. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 anys', '5 years = 5 years');
  4208. });
  4209. test('suffix', function (assert) {
  4210. assert.equal(moment(30000).from(0), 'en uns segons', 'prefix');
  4211. assert.equal(moment(0).from(30000), 'fa uns segons', 'suffix');
  4212. });
  4213. test('now from now', function (assert) {
  4214. assert.equal(moment().fromNow(), 'fa uns segons', 'now from now should display as in the past');
  4215. });
  4216. test('fromNow', function (assert) {
  4217. assert.equal(moment().add({s: 30}).fromNow(), 'en uns segons', 'en uns segons');
  4218. assert.equal(moment().add({d: 5}).fromNow(), 'en 5 dies', 'en 5 dies');
  4219. });
  4220. test('calendar day', function (assert) {
  4221. var a = moment().hours(2).minutes(0).seconds(0);
  4222. assert.equal(moment(a).calendar(), 'avui a les 2:00', 'today at the same time');
  4223. assert.equal(moment(a).add({m: 25}).calendar(), 'avui a les 2:25', 'Now plus 25 min');
  4224. assert.equal(moment(a).add({h: 1}).calendar(), 'avui a les 3:00', 'Now plus 1 hour');
  4225. assert.equal(moment(a).add({d: 1}).calendar(), 'demà a les 2:00', 'tomorrow at the same time');
  4226. assert.equal(moment(a).add({d: 1, h : -1}).calendar(), 'demà a la 1:00', 'tomorrow minus 1 hour');
  4227. assert.equal(moment(a).subtract({h: 1}).calendar(), 'avui a la 1:00', 'Now minus 1 hour');
  4228. assert.equal(moment(a).subtract({d: 1}).calendar(), 'ahir a les 2:00', 'yesterday at the same time');
  4229. });
  4230. test('calendar next week', function (assert) {
  4231. var i, m;
  4232. for (i = 2; i < 7; i++) {
  4233. m = moment().add({d: i});
  4234. assert.equal(m.calendar(), m.format('dddd [a ' + ((m.hours() !== 1) ? 'les' : 'la') + '] LT'), 'Today + ' + i + ' days current time');
  4235. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  4236. assert.equal(m.calendar(), m.format('dddd [a ' + ((m.hours() !== 1) ? 'les' : 'la') + '] LT'), 'Today + ' + i + ' days beginning of day');
  4237. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  4238. assert.equal(m.calendar(), m.format('dddd [a ' + ((m.hours() !== 1) ? 'les' : 'la') + '] LT'), 'Today + ' + i + ' days end of day');
  4239. }
  4240. });
  4241. test('calendar last week', function (assert) {
  4242. var i, m;
  4243. for (i = 2; i < 7; i++) {
  4244. m = moment().subtract({d: i});
  4245. assert.equal(m.calendar(), m.format('[el] dddd [passat a ' + ((m.hours() !== 1) ? 'les' : 'la') + '] LT'), 'Today - ' + i + ' days current time');
  4246. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  4247. assert.equal(m.calendar(), m.format('[el] dddd [passat a ' + ((m.hours() !== 1) ? 'les' : 'la') + '] LT'), 'Today - ' + i + ' days beginning of day');
  4248. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  4249. assert.equal(m.calendar(), m.format('[el] dddd [passat a ' + ((m.hours() !== 1) ? 'les' : 'la') + '] LT'), 'Today - ' + i + ' days end of day');
  4250. }
  4251. });
  4252. test('calendar all else', function (assert) {
  4253. var weeksAgo = moment().subtract({w: 1}),
  4254. weeksFromNow = moment().add({w: 1});
  4255. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  4256. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  4257. weeksAgo = moment().subtract({w: 2});
  4258. weeksFromNow = moment().add({w: 2});
  4259. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  4260. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  4261. });
  4262. test('weeks year starting sunday', function (assert) {
  4263. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  4264. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  4265. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  4266. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  4267. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  4268. });
  4269. test('weeks year starting monday', function (assert) {
  4270. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  4271. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  4272. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  4273. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  4274. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  4275. });
  4276. test('weeks year starting tuesday', function (assert) {
  4277. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  4278. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  4279. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  4280. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  4281. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  4282. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  4283. });
  4284. test('weeks year starting wednesday', function (assert) {
  4285. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  4286. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  4287. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  4288. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  4289. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  4290. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  4291. });
  4292. test('weeks year starting thursday', function (assert) {
  4293. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  4294. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  4295. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  4296. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  4297. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  4298. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  4299. });
  4300. test('weeks year starting friday', function (assert) {
  4301. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  4302. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  4303. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  4304. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  4305. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  4306. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  4307. });
  4308. test('weeks year starting saturday', function (assert) {
  4309. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  4310. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  4311. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  4312. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  4313. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  4314. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  4315. });
  4316. test('weeks year starting sunday formatted', function (assert) {
  4317. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52a', 'Jan 1 2012 should be week 52');
  4318. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1a', 'Jan 2 2012 should be week 1');
  4319. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1a', 'Jan 8 2012 should be week 1');
  4320. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2a', 'Jan 9 2012 should be week 2');
  4321. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2a', 'Jan 15 2012 should be week 2');
  4322. });
  4323. test('lenient ordinal parsing', function (assert) {
  4324. var i, ordinalStr, testMoment;
  4325. for (i = 1; i <= 31; ++i) {
  4326. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  4327. testMoment = moment(ordinalStr, 'YYYY MM Do');
  4328. assert.equal(testMoment.year(), 2014,
  4329. 'lenient ordinal parsing ' + i + ' year check');
  4330. assert.equal(testMoment.month(), 0,
  4331. 'lenient ordinal parsing ' + i + ' month check');
  4332. assert.equal(testMoment.date(), i,
  4333. 'lenient ordinal parsing ' + i + ' date check');
  4334. }
  4335. });
  4336. test('lenient ordinal parsing of number', function (assert) {
  4337. var i, testMoment;
  4338. for (i = 1; i <= 31; ++i) {
  4339. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  4340. assert.equal(testMoment.year(), 2014,
  4341. 'lenient ordinal parsing of number ' + i + ' year check');
  4342. assert.equal(testMoment.month(), 0,
  4343. 'lenient ordinal parsing of number ' + i + ' month check');
  4344. assert.equal(testMoment.date(), i,
  4345. 'lenient ordinal parsing of number ' + i + ' date check');
  4346. }
  4347. });
  4348. test('strict ordinal parsing', function (assert) {
  4349. var i, ordinalStr, testMoment;
  4350. for (i = 1; i <= 31; ++i) {
  4351. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  4352. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  4353. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  4354. }
  4355. });
  4356. }));
  4357. ;(function (global, factory) {
  4358. typeof exports === 'object' && typeof module !== 'undefined'
  4359. && typeof require === 'function' ? factory(require('../../moment')) :
  4360. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  4361. factory(global.moment)
  4362. }(this, function (moment) { 'use strict';
  4363. /*global QUnit:false*/
  4364. var test = QUnit.test;
  4365. var expect = QUnit.expect;
  4366. function module (name, lifecycle) {
  4367. QUnit.module(name, {
  4368. setup : function () {
  4369. moment.locale('en');
  4370. moment.createFromInputFallback = function (config) {
  4371. throw new Error('input not handled by moment: ' + config._i);
  4372. };
  4373. if (lifecycle && lifecycle.setup) {
  4374. lifecycle.setup();
  4375. }
  4376. },
  4377. teardown : function () {
  4378. if (lifecycle && lifecycle.teardown) {
  4379. lifecycle.teardown();
  4380. }
  4381. }
  4382. });
  4383. }
  4384. function localeModule (name, lifecycle) {
  4385. QUnit.module('locale:' + name, {
  4386. setup : function () {
  4387. moment.locale(name);
  4388. moment.createFromInputFallback = function (config) {
  4389. throw new Error('input not handled by moment: ' + config._i);
  4390. };
  4391. if (lifecycle && lifecycle.setup) {
  4392. lifecycle.setup();
  4393. }
  4394. },
  4395. teardown : function () {
  4396. moment.locale('en');
  4397. if (lifecycle && lifecycle.teardown) {
  4398. lifecycle.teardown();
  4399. }
  4400. }
  4401. });
  4402. }
  4403. localeModule('cs');
  4404. test('parse', function (assert) {
  4405. var tests = 'leden led_únor úno_březen bře_duben dub_květen kvě_červen čvn_červenec čvc_srpen srp_září zář_říjen říj_listopad lis_prosinec pro'.split('_'), i;
  4406. function equalTest(input, mmm, monthIndex) {
  4407. assert.equal(moment(input, mmm).month(), monthIndex, input + ' ' + mmm + ' should be month ' + (monthIndex + 1));
  4408. }
  4409. function equalTestStrict(input, mmm, monthIndex) {
  4410. assert.equal(moment(input, mmm, true).month(), monthIndex, input + ' ' + mmm + ' should be strict month ' + (monthIndex + 1));
  4411. }
  4412. for (i = 0; i < 12; i++) {
  4413. tests[i] = tests[i].split(' ');
  4414. equalTest(tests[i][0], 'MMM', i);
  4415. equalTest(tests[i][1], 'MMM', i);
  4416. equalTest(tests[i][0], 'MMMM', i);
  4417. equalTest(tests[i][1], 'MMMM', i);
  4418. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  4419. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  4420. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  4421. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  4422. equalTestStrict(tests[i][1], 'MMM', i);
  4423. equalTestStrict(tests[i][0], 'MMMM', i);
  4424. equalTestStrict(tests[i][1].toLocaleLowerCase(), 'MMM', i);
  4425. equalTestStrict(tests[i][1].toLocaleUpperCase(), 'MMM', i);
  4426. equalTestStrict(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  4427. equalTestStrict(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  4428. }
  4429. });
  4430. test('format', function (assert) {
  4431. var a = [
  4432. ['dddd, MMMM Do YYYY, h:mm:ss', 'neděle, únor 14. 2010, 3:25:50'],
  4433. ['ddd, h', 'ne, 3'],
  4434. ['M Mo MM MMMM MMM', '2 2. 02 únor úno'],
  4435. ['YYYY YY', '2010 10'],
  4436. ['D Do DD', '14 14. 14'],
  4437. ['d do dddd ddd dd', '0 0. neděle ne ne'],
  4438. ['DDD DDDo DDDD', '45 45. 045'],
  4439. ['w wo ww', '6 6. 06'],
  4440. ['h hh', '3 03'],
  4441. ['H HH', '15 15'],
  4442. ['m mm', '25 25'],
  4443. ['s ss', '50 50'],
  4444. ['a A', 'pm PM'],
  4445. ['DDDo [den v roce]', '45. den v roce'],
  4446. ['LTS', '15:25:50'],
  4447. ['L', '14.02.2010'],
  4448. ['LL', '14. únor 2010'],
  4449. ['LLL', '14. únor 2010 15:25'],
  4450. ['LLLL', 'neděle 14. únor 2010 15:25'],
  4451. ['l', '14.2.2010'],
  4452. ['ll', '14. úno 2010'],
  4453. ['lll', '14. úno 2010 15:25'],
  4454. ['llll', 'ne 14. úno 2010 15:25']
  4455. ],
  4456. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  4457. i;
  4458. for (i = 0; i < a.length; i++) {
  4459. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  4460. }
  4461. });
  4462. test('format ordinal', function (assert) {
  4463. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
  4464. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
  4465. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
  4466. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
  4467. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
  4468. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
  4469. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
  4470. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
  4471. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
  4472. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
  4473. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
  4474. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
  4475. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
  4476. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
  4477. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
  4478. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
  4479. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
  4480. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
  4481. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
  4482. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
  4483. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
  4484. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
  4485. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
  4486. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
  4487. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
  4488. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
  4489. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
  4490. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
  4491. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
  4492. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
  4493. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
  4494. });
  4495. test('format month', function (assert) {
  4496. var expected = 'leden led_únor úno_březen bře_duben dub_květen kvě_červen čvn_červenec čvc_srpen srp_září zář_říjen říj_listopad lis_prosinec pro'.split('_'), i;
  4497. for (i = 0; i < expected.length; i++) {
  4498. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  4499. }
  4500. });
  4501. test('format week', function (assert) {
  4502. var expected = 'neděle ne ne_pondělí po po_úterý út út_středa st st_čtvrtek čt čt_pátek pá pá_sobota so so'.split('_'), i;
  4503. for (i = 0; i < expected.length; i++) {
  4504. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  4505. }
  4506. });
  4507. test('from', function (assert) {
  4508. var start = moment([2007, 1, 28]);
  4509. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'pár sekund', '44 seconds = a few seconds');
  4510. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'minuta', '45 seconds = a minute');
  4511. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'minuta', '89 seconds = a minute');
  4512. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuty', '90 seconds = 2 minutes');
  4513. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minut', '44 minutes = 44 minutes');
  4514. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'hodina', '45 minutes = an hour');
  4515. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'hodina', '89 minutes = an hour');
  4516. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 hodiny', '90 minutes = 2 hours');
  4517. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 hodin', '5 hours = 5 hours');
  4518. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 hodin', '21 hours = 21 hours');
  4519. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'den', '22 hours = a day');
  4520. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'den', '35 hours = a day');
  4521. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dny', '36 hours = 2 days');
  4522. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'den', '1 day = a day');
  4523. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dní', '5 days = 5 days');
  4524. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dní', '25 days = 25 days');
  4525. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'měsíc', '26 days = a month');
  4526. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'měsíc', '30 days = a month');
  4527. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'měsíc', '43 days = a month');
  4528. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 měsíce', '46 days = 2 months');
  4529. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 měsíce', '75 days = 2 months');
  4530. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 měsíce', '76 days = 3 months');
  4531. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'měsíc', '1 month = a month');
  4532. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 měsíců', '5 months = 5 months');
  4533. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'rok', '345 days = a year');
  4534. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 roky', '548 days = 2 years');
  4535. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'rok', '1 year = a year');
  4536. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 let', '5 years = 5 years');
  4537. });
  4538. test('suffix', function (assert) {
  4539. assert.equal(moment(30000).from(0), 'za pár sekund', 'prefix');
  4540. assert.equal(moment(0).from(30000), 'před pár sekundami', 'suffix');
  4541. });
  4542. test('now from now', function (assert) {
  4543. assert.equal(moment().fromNow(), 'před pár sekundami', 'now from now should display as in the past');
  4544. });
  4545. test('fromNow (future)', function (assert) {
  4546. assert.equal(moment().add({s: 30}).fromNow(), 'za pár sekund', 'in a few seconds');
  4547. assert.equal(moment().add({m: 1}).fromNow(), 'za minutu', 'in a minute');
  4548. assert.equal(moment().add({m: 3}).fromNow(), 'za 3 minuty', 'in 3 minutes');
  4549. assert.equal(moment().add({m: 10}).fromNow(), 'za 10 minut', 'in 10 minutes');
  4550. assert.equal(moment().add({h: 1}).fromNow(), 'za hodinu', 'in an hour');
  4551. assert.equal(moment().add({h: 3}).fromNow(), 'za 3 hodiny', 'in 3 hours');
  4552. assert.equal(moment().add({h: 10}).fromNow(), 'za 10 hodin', 'in 10 hours');
  4553. assert.equal(moment().add({d: 1}).fromNow(), 'za den', 'in a day');
  4554. assert.equal(moment().add({d: 3}).fromNow(), 'za 3 dny', 'in 3 days');
  4555. assert.equal(moment().add({d: 10}).fromNow(), 'za 10 dní', 'in 10 days');
  4556. assert.equal(moment().add({M: 1}).fromNow(), 'za měsíc', 'in a month');
  4557. assert.equal(moment().add({M: 3}).fromNow(), 'za 3 měsíce', 'in 3 months');
  4558. assert.equal(moment().add({M: 10}).fromNow(), 'za 10 měsíců', 'in 10 months');
  4559. assert.equal(moment().add({y: 1}).fromNow(), 'za rok', 'in a year');
  4560. assert.equal(moment().add({y: 3}).fromNow(), 'za 3 roky', 'in 3 years');
  4561. assert.equal(moment().add({y: 10}).fromNow(), 'za 10 let', 'in 10 years');
  4562. });
  4563. test('fromNow (past)', function (assert) {
  4564. assert.equal(moment().subtract({s: 30}).fromNow(), 'před pár sekundami', 'a few seconds ago');
  4565. assert.equal(moment().subtract({m: 1}).fromNow(), 'před minutou', 'a minute ago');
  4566. assert.equal(moment().subtract({m: 3}).fromNow(), 'před 3 minutami', '3 minutes ago');
  4567. assert.equal(moment().subtract({m: 10}).fromNow(), 'před 10 minutami', '10 minutes ago');
  4568. assert.equal(moment().subtract({h: 1}).fromNow(), 'před hodinou', 'an hour ago');
  4569. assert.equal(moment().subtract({h: 3}).fromNow(), 'před 3 hodinami', '3 hours ago');
  4570. assert.equal(moment().subtract({h: 10}).fromNow(), 'před 10 hodinami', '10 hours ago');
  4571. assert.equal(moment().subtract({d: 1}).fromNow(), 'před dnem', 'a day ago');
  4572. assert.equal(moment().subtract({d: 3}).fromNow(), 'před 3 dny', '3 days ago');
  4573. assert.equal(moment().subtract({d: 10}).fromNow(), 'před 10 dny', '10 days ago');
  4574. assert.equal(moment().subtract({M: 1}).fromNow(), 'před měsícem', 'a month ago');
  4575. assert.equal(moment().subtract({M: 3}).fromNow(), 'před 3 měsíci', '3 months ago');
  4576. assert.equal(moment().subtract({M: 10}).fromNow(), 'před 10 měsíci', '10 months ago');
  4577. assert.equal(moment().subtract({y: 1}).fromNow(), 'před rokem', 'a year ago');
  4578. assert.equal(moment().subtract({y: 3}).fromNow(), 'před 3 lety', '3 years ago');
  4579. assert.equal(moment().subtract({y: 10}).fromNow(), 'před 10 lety', '10 years ago');
  4580. });
  4581. test('calendar day', function (assert) {
  4582. var a = moment().hours(2).minutes(0).seconds(0);
  4583. assert.equal(moment(a).calendar(), 'dnes v 2:00', 'today at the same time');
  4584. assert.equal(moment(a).add({m: 25}).calendar(), 'dnes v 2:25', 'Now plus 25 min');
  4585. assert.equal(moment(a).add({h: 1}).calendar(), 'dnes v 3:00', 'Now plus 1 hour');
  4586. assert.equal(moment(a).add({d: 1}).calendar(), 'zítra v 2:00', 'tomorrow at the same time');
  4587. assert.equal(moment(a).subtract({h: 1}).calendar(), 'dnes v 1:00', 'Now minus 1 hour');
  4588. assert.equal(moment(a).subtract({d: 1}).calendar(), 'včera v 2:00', 'yesterday at the same time');
  4589. });
  4590. test('calendar next week', function (assert) {
  4591. var i, m, nextDay;
  4592. for (i = 2; i < 7; i++) {
  4593. m = moment().add({d: i});
  4594. nextDay = '';
  4595. switch (m.day()) {
  4596. case 0:
  4597. nextDay = 'v neděli';
  4598. break;
  4599. case 1:
  4600. nextDay = 'v pondělí';
  4601. break;
  4602. case 2:
  4603. nextDay = 'v úterý';
  4604. break;
  4605. case 3:
  4606. nextDay = 've středu';
  4607. break;
  4608. case 4:
  4609. nextDay = 've čtvrtek';
  4610. break;
  4611. case 5:
  4612. nextDay = 'v pátek';
  4613. break;
  4614. case 6:
  4615. nextDay = 'v sobotu';
  4616. break;
  4617. }
  4618. assert.equal(m.calendar(), m.format('[' + nextDay + '] [v] LT'), 'Today + ' + i + ' days current time');
  4619. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  4620. assert.equal(m.calendar(), m.format('[' + nextDay + '] [v] LT'), 'Today + ' + i + ' days beginning of day');
  4621. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  4622. assert.equal(m.calendar(), m.format('[' + nextDay + '] [v] LT'), 'Today + ' + i + ' days end of day');
  4623. }
  4624. });
  4625. test('calendar last week', function (assert) {
  4626. var i, m, lastDay;
  4627. for (i = 2; i < 7; i++) {
  4628. m = moment().subtract({d: i});
  4629. lastDay = '';
  4630. switch (m.day()) {
  4631. case 0:
  4632. lastDay = 'minulou neděli';
  4633. break;
  4634. case 1:
  4635. lastDay = 'minulé pondělí';
  4636. break;
  4637. case 2:
  4638. lastDay = 'minulé úterý';
  4639. break;
  4640. case 3:
  4641. lastDay = 'minulou středu';
  4642. break;
  4643. case 4:
  4644. lastDay = 'minulý čtvrtek';
  4645. break;
  4646. case 5:
  4647. lastDay = 'minulý pátek';
  4648. break;
  4649. case 6:
  4650. lastDay = 'minulou sobotu';
  4651. break;
  4652. }
  4653. assert.equal(m.calendar(), m.format('[' + lastDay + '] [v] LT'), 'Today - ' + i + ' days current time');
  4654. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  4655. assert.equal(m.calendar(), m.format('[' + lastDay + '] [v] LT'), 'Today - ' + i + ' days beginning of day');
  4656. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  4657. assert.equal(m.calendar(), m.format('[' + lastDay + '] [v] LT'), 'Today - ' + i + ' days end of day');
  4658. }
  4659. });
  4660. test('calendar all else', function (assert) {
  4661. var weeksAgo = moment().subtract({w: 1}),
  4662. weeksFromNow = moment().add({w: 1});
  4663. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  4664. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  4665. weeksAgo = moment().subtract({w: 2});
  4666. weeksFromNow = moment().add({w: 2});
  4667. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  4668. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  4669. });
  4670. test('humanize duration', function (assert) {
  4671. assert.equal(moment.duration(1, 'minutes').humanize(), 'minuta', 'a minute (future)');
  4672. assert.equal(moment.duration(1, 'minutes').humanize(true), 'za minutu', 'in a minute');
  4673. assert.equal(moment.duration(-1, 'minutes').humanize(), 'minuta', 'a minute (past)');
  4674. assert.equal(moment.duration(-1, 'minutes').humanize(true), 'před minutou', 'a minute ago');
  4675. });
  4676. test('weeks year starting sunday', function (assert) {
  4677. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  4678. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  4679. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  4680. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  4681. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  4682. });
  4683. test('weeks year starting monday', function (assert) {
  4684. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  4685. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  4686. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  4687. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  4688. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  4689. });
  4690. test('weeks year starting tuesday', function (assert) {
  4691. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  4692. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  4693. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  4694. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  4695. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  4696. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  4697. });
  4698. test('weeks year starting wednesday', function (assert) {
  4699. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  4700. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  4701. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  4702. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  4703. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  4704. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  4705. });
  4706. test('weeks year starting thursday', function (assert) {
  4707. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  4708. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  4709. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  4710. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  4711. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  4712. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  4713. });
  4714. test('weeks year starting friday', function (assert) {
  4715. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  4716. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  4717. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  4718. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  4719. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  4720. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  4721. });
  4722. test('weeks year starting saturday', function (assert) {
  4723. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  4724. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  4725. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  4726. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  4727. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  4728. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  4729. });
  4730. test('weeks year starting sunday formatted', function (assert) {
  4731. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
  4732. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
  4733. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
  4734. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
  4735. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
  4736. });
  4737. test('lenient ordinal parsing', function (assert) {
  4738. var i, ordinalStr, testMoment;
  4739. for (i = 1; i <= 31; ++i) {
  4740. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  4741. testMoment = moment(ordinalStr, 'YYYY MM Do');
  4742. assert.equal(testMoment.year(), 2014,
  4743. 'lenient ordinal parsing ' + i + ' year check');
  4744. assert.equal(testMoment.month(), 0,
  4745. 'lenient ordinal parsing ' + i + ' month check');
  4746. assert.equal(testMoment.date(), i,
  4747. 'lenient ordinal parsing ' + i + ' date check');
  4748. }
  4749. });
  4750. test('lenient ordinal parsing of number', function (assert) {
  4751. var i, testMoment;
  4752. for (i = 1; i <= 31; ++i) {
  4753. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  4754. assert.equal(testMoment.year(), 2014,
  4755. 'lenient ordinal parsing of number ' + i + ' year check');
  4756. assert.equal(testMoment.month(), 0,
  4757. 'lenient ordinal parsing of number ' + i + ' month check');
  4758. assert.equal(testMoment.date(), i,
  4759. 'lenient ordinal parsing of number ' + i + ' date check');
  4760. }
  4761. });
  4762. test('strict ordinal parsing', function (assert) {
  4763. var i, ordinalStr, testMoment;
  4764. for (i = 1; i <= 31; ++i) {
  4765. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  4766. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  4767. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  4768. }
  4769. });
  4770. }));
  4771. ;(function (global, factory) {
  4772. typeof exports === 'object' && typeof module !== 'undefined'
  4773. && typeof require === 'function' ? factory(require('../../moment')) :
  4774. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  4775. factory(global.moment)
  4776. }(this, function (moment) { 'use strict';
  4777. /*global QUnit:false*/
  4778. var test = QUnit.test;
  4779. var expect = QUnit.expect;
  4780. function module (name, lifecycle) {
  4781. QUnit.module(name, {
  4782. setup : function () {
  4783. moment.locale('en');
  4784. moment.createFromInputFallback = function (config) {
  4785. throw new Error('input not handled by moment: ' + config._i);
  4786. };
  4787. if (lifecycle && lifecycle.setup) {
  4788. lifecycle.setup();
  4789. }
  4790. },
  4791. teardown : function () {
  4792. if (lifecycle && lifecycle.teardown) {
  4793. lifecycle.teardown();
  4794. }
  4795. }
  4796. });
  4797. }
  4798. function localeModule (name, lifecycle) {
  4799. QUnit.module('locale:' + name, {
  4800. setup : function () {
  4801. moment.locale(name);
  4802. moment.createFromInputFallback = function (config) {
  4803. throw new Error('input not handled by moment: ' + config._i);
  4804. };
  4805. if (lifecycle && lifecycle.setup) {
  4806. lifecycle.setup();
  4807. }
  4808. },
  4809. teardown : function () {
  4810. moment.locale('en');
  4811. if (lifecycle && lifecycle.teardown) {
  4812. lifecycle.teardown();
  4813. }
  4814. }
  4815. });
  4816. }
  4817. localeModule('cv');
  4818. test('parse', function (assert) {
  4819. var tests = 'кӑрлач кӑр_нарӑс нар_пуш пуш_ака ака_май май_ҫӗртме ҫӗр_утӑ утӑ_ҫурла ҫур_авӑн авн_юпа юпа_чӳк чӳк_раштав раш'.split('_'), i;
  4820. function equalTest(input, mmm, i) {
  4821. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  4822. }
  4823. for (i = 0; i < 12; i++) {
  4824. tests[i] = tests[i].split(' ');
  4825. equalTest(tests[i][0], 'MMM', i);
  4826. equalTest(tests[i][1], 'MMM', i);
  4827. equalTest(tests[i][0], 'MMMM', i);
  4828. equalTest(tests[i][1], 'MMMM', i);
  4829. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  4830. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  4831. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  4832. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  4833. }
  4834. });
  4835. test('format', function (assert) {
  4836. var a = [
  4837. ['dddd, MMMM Do YYYY, h:mm:ss a', 'вырсарникун, нарӑс 14-мӗш 2010, 3:25:50 pm'],
  4838. ['ddd, hA', 'выр, 3PM'],
  4839. ['M Mo MM MMMM MMM', '2 2-мӗш 02 нарӑс нар'],
  4840. ['YYYY YY', '2010 10'],
  4841. ['D Do DD', '14 14-мӗш 14'],
  4842. ['d do dddd ddd dd', '0 0-мӗш вырсарникун выр вр'],
  4843. ['DDD DDDo DDDD', '45 45-мӗш 045'],
  4844. ['w wo ww', '7 7-мӗш 07'],
  4845. ['h hh', '3 03'],
  4846. ['H HH', '15 15'],
  4847. ['m mm', '25 25'],
  4848. ['s ss', '50 50'],
  4849. ['a A', 'pm PM'],
  4850. ['Ҫулӑн DDDo кунӗ', 'Ҫулӑн 45-мӗш кунӗ'],
  4851. ['LTS', '15:25:50'],
  4852. ['L', '14-02-2010'],
  4853. ['LL', '2010 ҫулхи нарӑс уйӑхӗн 14-мӗшӗ'],
  4854. ['LLL', '2010 ҫулхи нарӑс уйӑхӗн 14-мӗшӗ, 15:25'],
  4855. ['LLLL', 'вырсарникун, 2010 ҫулхи нарӑс уйӑхӗн 14-мӗшӗ, 15:25'],
  4856. ['l', '14-2-2010'],
  4857. ['ll', '2010 ҫулхи нар уйӑхӗн 14-мӗшӗ'],
  4858. ['lll', '2010 ҫулхи нар уйӑхӗн 14-мӗшӗ, 15:25'],
  4859. ['llll', 'выр, 2010 ҫулхи нар уйӑхӗн 14-мӗшӗ, 15:25']
  4860. ],
  4861. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  4862. i;
  4863. for (i = 0; i < a.length; i++) {
  4864. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  4865. }
  4866. });
  4867. test('format ordinal', function (assert) {
  4868. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1-мӗш', '1-мӗш');
  4869. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2-мӗш', '2-мӗш');
  4870. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3-мӗш', '3-мӗш');
  4871. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4-мӗш', '4-мӗш');
  4872. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5-мӗш', '5-мӗш');
  4873. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6-мӗш', '6-мӗш');
  4874. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7-мӗш', '7-мӗш');
  4875. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8-мӗш', '8-мӗш');
  4876. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9-мӗш', '9-мӗш');
  4877. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10-мӗш', '10-мӗш');
  4878. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11-мӗш', '11-мӗш');
  4879. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12-мӗш', '12-мӗш');
  4880. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13-мӗш', '13-мӗш');
  4881. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14-мӗш', '14-мӗш');
  4882. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15-мӗш', '15-мӗш');
  4883. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16-мӗш', '16-мӗш');
  4884. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17-мӗш', '17-мӗш');
  4885. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18-мӗш', '18-мӗш');
  4886. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19-мӗш', '19-мӗш');
  4887. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20-мӗш', '20-мӗш');
  4888. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21-мӗш', '21-мӗш');
  4889. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22-мӗш', '22-мӗш');
  4890. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23-мӗш', '23-мӗш');
  4891. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24-мӗш', '24-мӗш');
  4892. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25-мӗш', '25-мӗш');
  4893. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26-мӗш', '26-мӗш');
  4894. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27-мӗш', '27-мӗш');
  4895. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28-мӗш', '28-мӗш');
  4896. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29-мӗш', '29-мӗш');
  4897. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30-мӗш', '30-мӗш');
  4898. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31-мӗш', '31-мӗш');
  4899. });
  4900. test('format month', function (assert) {
  4901. var expected = 'кӑрлач кӑр_нарӑс нар_пуш пуш_ака ака_май май_ҫӗртме ҫӗр_утӑ утӑ_ҫурла ҫур_авӑн авн_юпа юпа_чӳк чӳк_раштав раш'.split('_'), i;
  4902. for (i = 0; i < expected.length; i++) {
  4903. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  4904. }
  4905. });
  4906. test('format week', function (assert) {
  4907. var expected = 'вырсарникун выр вр_тунтикун тун тн_ытларикун ытл ыт_юнкун юн юн_кӗҫнерникун кӗҫ кҫ_эрнекун эрн эр_шӑматкун шӑм шм'.split('_'), i;
  4908. for (i = 0; i < expected.length; i++) {
  4909. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  4910. }
  4911. });
  4912. test('from', function (assert) {
  4913. var start = moment([2007, 1, 28]);
  4914. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'пӗр-ик ҫеккунт', '44 sekunder = a few seconds');
  4915. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'пӗр минут', '45 seconds = a minute');
  4916. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'пӗр минут', '89 seconds = a minute');
  4917. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 минут', '90 seconds = 2 minutes');
  4918. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 минут', '44 minutes = 44 minutes');
  4919. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'пӗр сехет', '45 minutes = an hour');
  4920. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'пӗр сехет', '89 minutes = an hour');
  4921. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 сехет', '90 minutes = 2 hours');
  4922. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 сехет', '5 hours = 5 hours');
  4923. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 сехет', '21 hours = 21 hours');
  4924. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'пӗр кун', '22 hours = a day');
  4925. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'пӗр кун', '35 hours = a day');
  4926. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 кун', '36 hours = 2 days');
  4927. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'пӗр кун', '1 day = a day');
  4928. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 кун', '5 days = 5 days');
  4929. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 кун', '25 days = 25 days');
  4930. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'пӗр уйӑх', '26 days = a month');
  4931. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'пӗр уйӑх', '30 days = a month');
  4932. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'пӗр уйӑх', '43 days = a month');
  4933. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 уйӑх', '46 days = 2 months');
  4934. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 уйӑх', '75 days = 2 months');
  4935. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 уйӑх', '76 days = 3 months');
  4936. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'пӗр уйӑх', '1 month = a month');
  4937. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 уйӑх', '5 months = 5 months');
  4938. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'пӗр ҫул', '345 days = a year');
  4939. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 ҫул', '548 days = 2 years');
  4940. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'пӗр ҫул', '1 year = a year');
  4941. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 ҫул', '5 years = 5 years');
  4942. });
  4943. test('suffix', function (assert) {
  4944. assert.equal(moment(30000).from(0), 'пӗр-ик ҫеккунтран', 'prefix');
  4945. assert.equal(moment(0).from(30000), 'пӗр-ик ҫеккунт каялла', 'suffix');
  4946. });
  4947. test('now from now', function (assert) {
  4948. assert.equal(moment().fromNow(), 'пӗр-ик ҫеккунт каялла', 'now from now should display as in the past');
  4949. });
  4950. test('fromNow', function (assert) {
  4951. assert.equal(moment().add({s: 30}).fromNow(), 'пӗр-ик ҫеккунтран', 'in a few seconds');
  4952. assert.equal(moment().add({d: 5}).fromNow(), '5 кунран', 'in 5 days');
  4953. assert.equal(moment().add({h: 2}).fromNow(), '2 сехетрен', 'in 2 hours, the right suffix!');
  4954. assert.equal(moment().add({y: 3}).fromNow(), '3 ҫултан', 'in 3 years, the right suffix!');
  4955. });
  4956. test('calendar day', function (assert) {
  4957. var a = moment().hours(2).minutes(0).seconds(0);
  4958. assert.equal(moment(a).calendar(), 'Паян 02:00 сехетре', 'today at the same time');
  4959. assert.equal(moment(a).add({m: 25}).calendar(), 'Паян 02:25 сехетре', 'Now plus 25 min');
  4960. assert.equal(moment(a).add({h: 1}).calendar(), 'Паян 03:00 сехетре', 'Now plus 1 hour');
  4961. assert.equal(moment(a).add({d: 1}).calendar(), 'Ыран 02:00 сехетре', 'tomorrow at the same time');
  4962. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Паян 01:00 сехетре', 'Now minus 1 hour');
  4963. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Ӗнер 02:00 сехетре', 'yesterday at the same time');
  4964. });
  4965. test('calendar next week', function (assert) {
  4966. var i, m;
  4967. for (i = 2; i < 7; i++) {
  4968. m = moment().add({d: i});
  4969. assert.equal(m.calendar(), m.format('[Ҫитес] dddd LT [сехетре]'), 'Today + ' + i + ' days current time');
  4970. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  4971. assert.equal(m.calendar(), m.format('[Ҫитес] dddd LT [сехетре]'), 'Today + ' + i + ' days beginning of day');
  4972. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  4973. assert.equal(m.calendar(), m.format('[Ҫитес] dddd LT [сехетре]'), 'Today + ' + i + ' days end of day');
  4974. }
  4975. });
  4976. test('calendar last week', function (assert) {
  4977. var i, m;
  4978. for (i = 2; i < 7; i++) {
  4979. m = moment().subtract({d: i});
  4980. assert.equal(m.calendar(), m.format('[Иртнӗ] dddd LT [сехетре]'), 'Today - ' + i + ' days current time');
  4981. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  4982. assert.equal(m.calendar(), m.format('[Иртнӗ] dddd LT [сехетре]'), 'Today - ' + i + ' days beginning of day');
  4983. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  4984. assert.equal(m.calendar(), m.format('[Иртнӗ] dddd LT [сехетре]'), 'Today - ' + i + ' days end of day');
  4985. }
  4986. });
  4987. test('calendar all else', function (assert) {
  4988. var weeksAgo = moment().subtract({w: 1}),
  4989. weeksFromNow = moment().add({w: 1});
  4990. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  4991. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  4992. weeksAgo = moment().subtract({w: 2});
  4993. weeksFromNow = moment().add({w: 2});
  4994. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  4995. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  4996. });
  4997. // Monday is the first day of the week.
  4998. // The week that contains Jan 1st is the first week of the year.
  4999. test('weeks year starting sunday', function (assert) {
  5000. assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1');
  5001. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  5002. assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2');
  5003. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  5004. assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3');
  5005. });
  5006. test('weeks year starting monday', function (assert) {
  5007. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  5008. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  5009. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  5010. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  5011. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  5012. });
  5013. test('weeks year starting tuesday', function (assert) {
  5014. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  5015. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  5016. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  5017. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  5018. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  5019. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  5020. });
  5021. test('weeks year starting wednesday', function (assert) {
  5022. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  5023. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  5024. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  5025. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  5026. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  5027. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  5028. });
  5029. test('weeks year starting thursday', function (assert) {
  5030. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  5031. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  5032. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  5033. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  5034. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  5035. assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3');
  5036. });
  5037. test('weeks year starting friday', function (assert) {
  5038. assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1');
  5039. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  5040. assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1');
  5041. assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2');
  5042. assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2');
  5043. assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3');
  5044. });
  5045. test('weeks year starting saturday', function (assert) {
  5046. assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1');
  5047. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  5048. assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1');
  5049. assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2');
  5050. assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2');
  5051. assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3');
  5052. });
  5053. test('weeks year starting sunday formatted', function (assert) {
  5054. assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1-мӗш', 'Dec 26 2011 should be week 1');
  5055. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1-мӗш', 'Jan 1 2012 should be week 1');
  5056. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2-мӗш', 'Jan 2 2012 should be week 2');
  5057. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2-мӗш', 'Jan 8 2012 should be week 2');
  5058. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3-мӗш', 'Jan 9 2012 should be week 3');
  5059. });
  5060. test('lenient ordinal parsing', function (assert) {
  5061. var i, ordinalStr, testMoment;
  5062. for (i = 1; i <= 31; ++i) {
  5063. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  5064. testMoment = moment(ordinalStr, 'YYYY MM Do');
  5065. assert.equal(testMoment.year(), 2014,
  5066. 'lenient ordinal parsing ' + i + ' year check');
  5067. assert.equal(testMoment.month(), 0,
  5068. 'lenient ordinal parsing ' + i + ' month check');
  5069. assert.equal(testMoment.date(), i,
  5070. 'lenient ordinal parsing ' + i + ' date check');
  5071. }
  5072. });
  5073. test('lenient ordinal parsing of number', function (assert) {
  5074. var i, testMoment;
  5075. for (i = 1; i <= 31; ++i) {
  5076. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  5077. assert.equal(testMoment.year(), 2014,
  5078. 'lenient ordinal parsing of number ' + i + ' year check');
  5079. assert.equal(testMoment.month(), 0,
  5080. 'lenient ordinal parsing of number ' + i + ' month check');
  5081. assert.equal(testMoment.date(), i,
  5082. 'lenient ordinal parsing of number ' + i + ' date check');
  5083. }
  5084. });
  5085. test('strict ordinal parsing', function (assert) {
  5086. var i, ordinalStr, testMoment;
  5087. for (i = 1; i <= 31; ++i) {
  5088. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  5089. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  5090. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  5091. }
  5092. });
  5093. }));
  5094. ;(function (global, factory) {
  5095. typeof exports === 'object' && typeof module !== 'undefined'
  5096. && typeof require === 'function' ? factory(require('../../moment')) :
  5097. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  5098. factory(global.moment)
  5099. }(this, function (moment) { 'use strict';
  5100. /*global QUnit:false*/
  5101. var test = QUnit.test;
  5102. var expect = QUnit.expect;
  5103. function module (name, lifecycle) {
  5104. QUnit.module(name, {
  5105. setup : function () {
  5106. moment.locale('en');
  5107. moment.createFromInputFallback = function (config) {
  5108. throw new Error('input not handled by moment: ' + config._i);
  5109. };
  5110. if (lifecycle && lifecycle.setup) {
  5111. lifecycle.setup();
  5112. }
  5113. },
  5114. teardown : function () {
  5115. if (lifecycle && lifecycle.teardown) {
  5116. lifecycle.teardown();
  5117. }
  5118. }
  5119. });
  5120. }
  5121. function localeModule (name, lifecycle) {
  5122. QUnit.module('locale:' + name, {
  5123. setup : function () {
  5124. moment.locale(name);
  5125. moment.createFromInputFallback = function (config) {
  5126. throw new Error('input not handled by moment: ' + config._i);
  5127. };
  5128. if (lifecycle && lifecycle.setup) {
  5129. lifecycle.setup();
  5130. }
  5131. },
  5132. teardown : function () {
  5133. moment.locale('en');
  5134. if (lifecycle && lifecycle.teardown) {
  5135. lifecycle.teardown();
  5136. }
  5137. }
  5138. });
  5139. }
  5140. localeModule('cy');
  5141. test('parse', function (assert) {
  5142. var tests = 'Ionawr Ion_Chwefror Chwe_Mawrth Maw_Ebrill Ebr_Mai Mai_Mehefin Meh_Gorffennaf Gor_Awst Aws_Medi Med_Hydref Hyd_Tachwedd Tach_Rhagfyr Rhag'.split('_'),
  5143. i;
  5144. function equalTest(input, mmm, i) {
  5145. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  5146. }
  5147. for (i = 0; i < 12; i++) {
  5148. tests[i] = tests[i].split(' ');
  5149. equalTest(tests[i][0], 'MMM', i);
  5150. equalTest(tests[i][1], 'MMM', i);
  5151. equalTest(tests[i][0], 'MMMM', i);
  5152. equalTest(tests[i][1], 'MMMM', i);
  5153. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  5154. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  5155. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  5156. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  5157. }
  5158. });
  5159. test('format', function (assert) {
  5160. var a = [
  5161. ['dddd, MMMM Do YYYY, h:mm:ss a', 'Dydd Sul, Chwefror 14eg 2010, 3:25:50 pm'],
  5162. ['ddd, hA', 'Sul, 3PM'],
  5163. ['M Mo MM MMMM MMM', '2 2il 02 Chwefror Chwe'],
  5164. ['YYYY YY', '2010 10'],
  5165. ['D Do DD', '14 14eg 14'],
  5166. ['d do dddd ddd dd', '0 0 Dydd Sul Sul Su'],
  5167. ['DDD DDDo DDDD', '45 45ain 045'],
  5168. ['w wo ww', '6 6ed 06'],
  5169. ['h hh', '3 03'],
  5170. ['H HH', '15 15'],
  5171. ['m mm', '25 25'],
  5172. ['s ss', '50 50'],
  5173. ['a A', 'pm PM'],
  5174. ['[the] DDDo [day of the year]', 'the 45ain day of the year'],
  5175. ['LTS', '15:25:50'],
  5176. ['L', '14/02/2010'],
  5177. ['LL', '14 Chwefror 2010'],
  5178. ['LLL', '14 Chwefror 2010 15:25'],
  5179. ['LLLL', 'Dydd Sul, 14 Chwefror 2010 15:25'],
  5180. ['l', '14/2/2010'],
  5181. ['ll', '14 Chwe 2010'],
  5182. ['lll', '14 Chwe 2010 15:25'],
  5183. ['llll', 'Sul, 14 Chwe 2010 15:25']
  5184. ],
  5185. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  5186. i;
  5187. for (i = 0; i < a.length; i++) {
  5188. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  5189. }
  5190. });
  5191. test('format ordinal', function (assert) {
  5192. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1af', '1af');
  5193. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2il', '2il');
  5194. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3ydd', '3ydd');
  5195. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4ydd', '4ydd');
  5196. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5ed', '5ed');
  5197. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6ed', '6ed');
  5198. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7ed', '7ed');
  5199. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8fed', '8fed');
  5200. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9fed', '9fed');
  5201. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10fed', '10fed');
  5202. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11eg', '11eg');
  5203. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12fed', '12fed');
  5204. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13eg', '13eg');
  5205. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14eg', '14eg');
  5206. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15fed', '15fed');
  5207. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16eg', '16eg');
  5208. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17eg', '17eg');
  5209. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18fed', '18fed');
  5210. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19eg', '19eg');
  5211. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20fed', '20fed');
  5212. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21ain', '21ain');
  5213. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22ain', '22ain');
  5214. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23ain', '23ain');
  5215. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24ain', '24ain');
  5216. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25ain', '25ain');
  5217. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26ain', '26ain');
  5218. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27ain', '27ain');
  5219. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28ain', '28ain');
  5220. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29ain', '29ain');
  5221. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30ain', '30ain');
  5222. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31ain', '31ain');
  5223. });
  5224. test('format month', function (assert) {
  5225. var expected = 'Ionawr Ion_Chwefror Chwe_Mawrth Maw_Ebrill Ebr_Mai Mai_Mehefin Meh_Gorffennaf Gor_Awst Aws_Medi Med_Hydref Hyd_Tachwedd Tach_Rhagfyr Rhag'.split('_'), i;
  5226. for (i = 0; i < expected.length; i++) {
  5227. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  5228. }
  5229. });
  5230. test('format week', function (assert) {
  5231. var expected = 'Dydd Sul Sul Su_Dydd Llun Llun Ll_Dydd Mawrth Maw Ma_Dydd Mercher Mer Me_Dydd Iau Iau Ia_Dydd Gwener Gwe Gw_Dydd Sadwrn Sad Sa'.split('_'), i;
  5232. for (i = 0; i < expected.length; i++) {
  5233. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  5234. }
  5235. });
  5236. test('from', function (assert) {
  5237. var start = moment([2007, 1, 28]);
  5238. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ychydig eiliadau', '44 seconds = a few seconds');
  5239. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'munud', '45 seconds = a minute');
  5240. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'munud', '89 seconds = a minute');
  5241. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 munud', '90 seconds = 2 minutes');
  5242. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 munud', '44 minutes = 44 minutes');
  5243. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'awr', '45 minutes = an hour');
  5244. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'awr', '89 minutes = an hour');
  5245. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 awr', '90 minutes = 2 hours');
  5246. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 awr', '5 hours = 5 hours');
  5247. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 awr', '21 hours = 21 hours');
  5248. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'diwrnod', '22 hours = a day');
  5249. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'diwrnod', '35 hours = a day');
  5250. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 diwrnod', '36 hours = 2 days');
  5251. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'diwrnod', '1 day = a day');
  5252. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 diwrnod', '5 days = 5 days');
  5253. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 diwrnod', '25 days = 25 days');
  5254. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'mis', '26 days = a month');
  5255. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'mis', '30 days = a month');
  5256. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'mis', '43 days = a month');
  5257. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mis', '46 days = 2 months');
  5258. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mis', '75 days = 2 months');
  5259. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mis', '76 days = 3 months');
  5260. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'mis', '1 month = a month');
  5261. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mis', '5 months = 5 months');
  5262. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'blwyddyn', '345 days = a year');
  5263. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 flynedd', '548 days = 2 years');
  5264. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'blwyddyn', '1 year = a year');
  5265. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 flynedd', '5 years = 5 years');
  5266. });
  5267. test('suffix', function (assert) {
  5268. assert.equal(moment(30000).from(0), 'mewn ychydig eiliadau', 'prefix');
  5269. assert.equal(moment(0).from(30000), 'ychydig eiliadau yn ôl', 'suffix');
  5270. });
  5271. test('fromNow', function (assert) {
  5272. assert.equal(moment().add({s: 30}).fromNow(), 'mewn ychydig eiliadau', 'in a few seconds');
  5273. assert.equal(moment().add({d: 5}).fromNow(), 'mewn 5 diwrnod', 'in 5 days');
  5274. });
  5275. test('same day', function (assert) {
  5276. var a = moment().hours(2).minutes(0).seconds(0);
  5277. assert.equal(moment(a).calendar(), 'Heddiw am 02:00', 'today at the same time');
  5278. assert.equal(moment(a).add({m: 25}).calendar(), 'Heddiw am 02:25', 'Now plus 25 min');
  5279. assert.equal(moment(a).add({h: 1}).calendar(), 'Heddiw am 03:00', 'Now plus 1 hour');
  5280. assert.equal(moment(a).add({d: 1}).calendar(), 'Yfory am 02:00', 'tomorrow at the same time');
  5281. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Heddiw am 01:00', 'Now minus 1 hour');
  5282. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Ddoe am 02:00', 'yesterday at the same time');
  5283. });
  5284. test('same next week', function (assert) {
  5285. var i, m;
  5286. for (i = 2; i < 7; i++) {
  5287. m = moment().add({d: i});
  5288. assert.equal(m.calendar(), m.format('dddd [am] LT'), 'Today + ' + i + ' days current time');
  5289. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  5290. assert.equal(m.calendar(), m.format('dddd [am] LT'), 'Today + ' + i + ' days beginning of day');
  5291. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  5292. assert.equal(m.calendar(), m.format('dddd [am] LT'), 'Today + ' + i + ' days end of day');
  5293. }
  5294. });
  5295. test('same last week', function (assert) {
  5296. var i, m;
  5297. for (i = 2; i < 7; i++) {
  5298. m = moment().subtract({d: i});
  5299. assert.equal(m.calendar(), m.format('dddd [diwethaf am] LT'), 'Today - ' + i + ' days current time');
  5300. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  5301. assert.equal(m.calendar(), m.format('dddd [diwethaf am] LT'), 'Today - ' + i + ' days beginning of day');
  5302. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  5303. assert.equal(m.calendar(), m.format('dddd [diwethaf am] LT'), 'Today - ' + i + ' days end of day');
  5304. }
  5305. });
  5306. test('same all else', function (assert) {
  5307. var weeksAgo = moment().subtract({w: 1}),
  5308. weeksFromNow = moment().add({w: 1});
  5309. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  5310. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  5311. weeksAgo = moment().subtract({w: 2});
  5312. weeksFromNow = moment().add({w: 2});
  5313. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  5314. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  5315. });
  5316. test('weeks year starting sunday', function (assert) {
  5317. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  5318. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  5319. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  5320. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  5321. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  5322. });
  5323. test('weeks year starting monday', function (assert) {
  5324. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  5325. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  5326. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  5327. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  5328. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  5329. });
  5330. test('weeks year starting tuesday', function (assert) {
  5331. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  5332. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  5333. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  5334. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  5335. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  5336. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  5337. });
  5338. test('weeks year starting wednesday', function (assert) {
  5339. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  5340. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  5341. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  5342. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  5343. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  5344. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  5345. });
  5346. test('weeks year starting thursday', function (assert) {
  5347. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  5348. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  5349. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  5350. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  5351. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  5352. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  5353. });
  5354. test('weeks year starting friday', function (assert) {
  5355. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  5356. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  5357. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  5358. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  5359. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  5360. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  5361. });
  5362. test('weeks year starting saturday', function (assert) {
  5363. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  5364. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  5365. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  5366. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  5367. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  5368. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  5369. });
  5370. test('weeks year starting sunday formatted', function (assert) {
  5371. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52ain', 'Jan 1 2012 should be week 52');
  5372. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1af', 'Jan 2 2012 should be week 1');
  5373. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1af', 'Jan 8 2012 should be week 1');
  5374. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2il', 'Jan 9 2012 should be week 2');
  5375. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2il', 'Jan 15 2012 should be week 2');
  5376. });
  5377. test('lenient ordinal parsing', function (assert) {
  5378. var i, ordinalStr, testMoment;
  5379. for (i = 1; i <= 31; ++i) {
  5380. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  5381. testMoment = moment(ordinalStr, 'YYYY MM Do');
  5382. assert.equal(testMoment.year(), 2014,
  5383. 'lenient ordinal parsing ' + i + ' year check');
  5384. assert.equal(testMoment.month(), 0,
  5385. 'lenient ordinal parsing ' + i + ' month check');
  5386. assert.equal(testMoment.date(), i,
  5387. 'lenient ordinal parsing ' + i + ' date check');
  5388. }
  5389. });
  5390. test('lenient ordinal parsing of number', function (assert) {
  5391. var i, testMoment;
  5392. for (i = 1; i <= 31; ++i) {
  5393. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  5394. assert.equal(testMoment.year(), 2014,
  5395. 'lenient ordinal parsing of number ' + i + ' year check');
  5396. assert.equal(testMoment.month(), 0,
  5397. 'lenient ordinal parsing of number ' + i + ' month check');
  5398. assert.equal(testMoment.date(), i,
  5399. 'lenient ordinal parsing of number ' + i + ' date check');
  5400. }
  5401. });
  5402. test('strict ordinal parsing', function (assert) {
  5403. var i, ordinalStr, testMoment;
  5404. for (i = 1; i <= 31; ++i) {
  5405. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  5406. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  5407. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  5408. }
  5409. });
  5410. }));
  5411. ;(function (global, factory) {
  5412. typeof exports === 'object' && typeof module !== 'undefined'
  5413. && typeof require === 'function' ? factory(require('../../moment')) :
  5414. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  5415. factory(global.moment)
  5416. }(this, function (moment) { 'use strict';
  5417. /*global QUnit:false*/
  5418. var test = QUnit.test;
  5419. var expect = QUnit.expect;
  5420. function module (name, lifecycle) {
  5421. QUnit.module(name, {
  5422. setup : function () {
  5423. moment.locale('en');
  5424. moment.createFromInputFallback = function (config) {
  5425. throw new Error('input not handled by moment: ' + config._i);
  5426. };
  5427. if (lifecycle && lifecycle.setup) {
  5428. lifecycle.setup();
  5429. }
  5430. },
  5431. teardown : function () {
  5432. if (lifecycle && lifecycle.teardown) {
  5433. lifecycle.teardown();
  5434. }
  5435. }
  5436. });
  5437. }
  5438. function localeModule (name, lifecycle) {
  5439. QUnit.module('locale:' + name, {
  5440. setup : function () {
  5441. moment.locale(name);
  5442. moment.createFromInputFallback = function (config) {
  5443. throw new Error('input not handled by moment: ' + config._i);
  5444. };
  5445. if (lifecycle && lifecycle.setup) {
  5446. lifecycle.setup();
  5447. }
  5448. },
  5449. teardown : function () {
  5450. moment.locale('en');
  5451. if (lifecycle && lifecycle.teardown) {
  5452. lifecycle.teardown();
  5453. }
  5454. }
  5455. });
  5456. }
  5457. localeModule('da');
  5458. test('parse', function (assert) {
  5459. var tests = 'januar jan_februar feb_marts mar_april apr_maj maj_juni jun_juli jul_august aug_september sep_oktober okt_november nov_december dec'.split('_'), i;
  5460. function equalTest(input, mmm, i) {
  5461. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  5462. }
  5463. for (i = 0; i < 12; i++) {
  5464. tests[i] = tests[i].split(' ');
  5465. equalTest(tests[i][0], 'MMM', i);
  5466. equalTest(tests[i][1], 'MMM', i);
  5467. equalTest(tests[i][0], 'MMMM', i);
  5468. equalTest(tests[i][1], 'MMMM', i);
  5469. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  5470. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  5471. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  5472. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  5473. }
  5474. });
  5475. test('format', function (assert) {
  5476. var a = [
  5477. ['dddd [den] Do MMMM YYYY, h:mm:ss a', 'søndag den 14. februar 2010, 3:25:50 pm'],
  5478. ['ddd hA', 'søn 3PM'],
  5479. ['M Mo MM MMMM MMM', '2 2. 02 februar feb'],
  5480. ['YYYY YY', '2010 10'],
  5481. ['D Do DD', '14 14. 14'],
  5482. ['d do dddd ddd dd', '0 0. søndag søn sø'],
  5483. ['DDD DDDo DDDD', '45 45. 045'],
  5484. ['w wo ww', '6 6. 06'],
  5485. ['h hh', '3 03'],
  5486. ['H HH', '15 15'],
  5487. ['m mm', '25 25'],
  5488. ['s ss', '50 50'],
  5489. ['a A', 'pm PM'],
  5490. ['[den] DDDo [dag på året]', 'den 45. dag på året'],
  5491. ['LTS', '15:25:50'],
  5492. ['L', '14/02/2010'],
  5493. ['LL', '14. februar 2010'],
  5494. ['LLL', '14. februar 2010 15:25'],
  5495. ['LLLL', 'søndag d. 14. februar 2010 15:25'],
  5496. ['l', '14/2/2010'],
  5497. ['ll', '14. feb 2010'],
  5498. ['lll', '14. feb 2010 15:25'],
  5499. ['llll', 'søn d. 14. feb 2010 15:25']
  5500. ],
  5501. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  5502. i;
  5503. for (i = 0; i < a.length; i++) {
  5504. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  5505. }
  5506. });
  5507. test('format ordinal', function (assert) {
  5508. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
  5509. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
  5510. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
  5511. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
  5512. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
  5513. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
  5514. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
  5515. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
  5516. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
  5517. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
  5518. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
  5519. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
  5520. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
  5521. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
  5522. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
  5523. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
  5524. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
  5525. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
  5526. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
  5527. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
  5528. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
  5529. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
  5530. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
  5531. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
  5532. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
  5533. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
  5534. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
  5535. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
  5536. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
  5537. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
  5538. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
  5539. });
  5540. test('format month', function (assert) {
  5541. var expected = 'januar jan_februar feb_marts mar_april apr_maj maj_juni jun_juli jul_august aug_september sep_oktober okt_november nov_december dec'.split('_'), i;
  5542. for (i = 0; i < expected.length; i++) {
  5543. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  5544. }
  5545. });
  5546. test('format week', function (assert) {
  5547. var expected = 'søndag søn sø_mandag man ma_tirsdag tir ti_onsdag ons on_torsdag tor to_fredag fre fr_lørdag lør lø'.split('_'), i;
  5548. for (i = 0; i < expected.length; i++) {
  5549. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  5550. }
  5551. });
  5552. test('from', function (assert) {
  5553. var start = moment([2007, 1, 28]);
  5554. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'få sekunder', '44 seconds = a few seconds');
  5555. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'et minut', '45 seconds = a minute');
  5556. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'et minut', '89 seconds = a minute');
  5557. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutter', '90 seconds = 2 minutes');
  5558. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutter', '44 minutes = 44 minutes');
  5559. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'en time', '45 minutes = an hour');
  5560. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'en time', '89 minutes = an hour');
  5561. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 timer', '90 minutes = 2 hours');
  5562. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 timer', '5 hours = 5 hours');
  5563. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 timer', '21 hours = 21 hours');
  5564. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'en dag', '22 hours = a day');
  5565. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'en dag', '35 hours = a day');
  5566. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dage', '36 hours = 2 days');
  5567. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'en dag', '1 day = a day');
  5568. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dage', '5 days = 5 days');
  5569. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dage', '25 days = 25 days');
  5570. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'en måned', '26 days = a month');
  5571. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'en måned', '30 days = a month');
  5572. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'en måned', '43 days = a month');
  5573. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 måneder', '46 days = 2 months');
  5574. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 måneder', '75 days = 2 months');
  5575. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 måneder', '76 days = 3 months');
  5576. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'en måned', '1 month = a month');
  5577. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 måneder', '5 months = 5 months');
  5578. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'et år', '345 days = a year');
  5579. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 år', '548 days = 2 years');
  5580. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'et år', '1 year = a year');
  5581. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 år', '5 years = 5 years');
  5582. });
  5583. test('suffix', function (assert) {
  5584. assert.equal(moment(30000).from(0), 'om få sekunder', 'prefix');
  5585. assert.equal(moment(0).from(30000), 'få sekunder siden', 'suffix');
  5586. });
  5587. test('now from now', function (assert) {
  5588. assert.equal(moment().fromNow(), 'få sekunder siden', 'now from now should display as in the past');
  5589. });
  5590. test('fromNow', function (assert) {
  5591. assert.equal(moment().add({s: 30}).fromNow(), 'om få sekunder', 'in a few seconds');
  5592. assert.equal(moment().add({d: 5}).fromNow(), 'om 5 dage', 'in 5 days');
  5593. });
  5594. test('weeks year starting sunday', function (assert) {
  5595. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  5596. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  5597. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  5598. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  5599. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  5600. });
  5601. test('weeks year starting monday', function (assert) {
  5602. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  5603. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  5604. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  5605. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  5606. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  5607. });
  5608. test('weeks year starting tuesday', function (assert) {
  5609. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  5610. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  5611. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  5612. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  5613. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  5614. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  5615. });
  5616. test('weeks year starting wednesday', function (assert) {
  5617. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  5618. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  5619. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  5620. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  5621. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  5622. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  5623. });
  5624. test('weeks year starting thursday', function (assert) {
  5625. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  5626. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  5627. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  5628. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  5629. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  5630. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  5631. });
  5632. test('weeks year starting friday', function (assert) {
  5633. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  5634. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  5635. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  5636. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  5637. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  5638. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  5639. });
  5640. test('weeks year starting saturday', function (assert) {
  5641. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  5642. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  5643. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  5644. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  5645. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  5646. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  5647. });
  5648. test('weeks year starting sunday formatted', function (assert) {
  5649. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
  5650. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
  5651. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
  5652. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
  5653. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
  5654. });
  5655. test('lenient ordinal parsing', function (assert) {
  5656. var i, ordinalStr, testMoment;
  5657. for (i = 1; i <= 31; ++i) {
  5658. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  5659. testMoment = moment(ordinalStr, 'YYYY MM Do');
  5660. assert.equal(testMoment.year(), 2014,
  5661. 'lenient ordinal parsing ' + i + ' year check');
  5662. assert.equal(testMoment.month(), 0,
  5663. 'lenient ordinal parsing ' + i + ' month check');
  5664. assert.equal(testMoment.date(), i,
  5665. 'lenient ordinal parsing ' + i + ' date check');
  5666. }
  5667. });
  5668. test('lenient ordinal parsing of number', function (assert) {
  5669. var i, testMoment;
  5670. for (i = 1; i <= 31; ++i) {
  5671. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  5672. assert.equal(testMoment.year(), 2014,
  5673. 'lenient ordinal parsing of number ' + i + ' year check');
  5674. assert.equal(testMoment.month(), 0,
  5675. 'lenient ordinal parsing of number ' + i + ' month check');
  5676. assert.equal(testMoment.date(), i,
  5677. 'lenient ordinal parsing of number ' + i + ' date check');
  5678. }
  5679. });
  5680. test('strict ordinal parsing', function (assert) {
  5681. var i, ordinalStr, testMoment;
  5682. for (i = 1; i <= 31; ++i) {
  5683. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  5684. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  5685. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  5686. }
  5687. });
  5688. }));
  5689. ;(function (global, factory) {
  5690. typeof exports === 'object' && typeof module !== 'undefined'
  5691. && typeof require === 'function' ? factory(require('../../moment')) :
  5692. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  5693. factory(global.moment)
  5694. }(this, function (moment) { 'use strict';
  5695. /*global QUnit:false*/
  5696. var test = QUnit.test;
  5697. var expect = QUnit.expect;
  5698. function module (name, lifecycle) {
  5699. QUnit.module(name, {
  5700. setup : function () {
  5701. moment.locale('en');
  5702. moment.createFromInputFallback = function (config) {
  5703. throw new Error('input not handled by moment: ' + config._i);
  5704. };
  5705. if (lifecycle && lifecycle.setup) {
  5706. lifecycle.setup();
  5707. }
  5708. },
  5709. teardown : function () {
  5710. if (lifecycle && lifecycle.teardown) {
  5711. lifecycle.teardown();
  5712. }
  5713. }
  5714. });
  5715. }
  5716. function localeModule (name, lifecycle) {
  5717. QUnit.module('locale:' + name, {
  5718. setup : function () {
  5719. moment.locale(name);
  5720. moment.createFromInputFallback = function (config) {
  5721. throw new Error('input not handled by moment: ' + config._i);
  5722. };
  5723. if (lifecycle && lifecycle.setup) {
  5724. lifecycle.setup();
  5725. }
  5726. },
  5727. teardown : function () {
  5728. moment.locale('en');
  5729. if (lifecycle && lifecycle.teardown) {
  5730. lifecycle.teardown();
  5731. }
  5732. }
  5733. });
  5734. }
  5735. localeModule('de-at');
  5736. test('parse', function (assert) {
  5737. var tests = 'Jänner Jän._Februar Febr._März Mrz._April Apr._Mai Mai_Juni Jun._Juli Jul._August Aug._September Sept._Oktober Okt._November Nov._Dezember Dez.'.split('_'), i;
  5738. function equalTest(input, mmm, i) {
  5739. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  5740. }
  5741. for (i = 0; i < 12; i++) {
  5742. tests[i] = tests[i].split(' ');
  5743. equalTest(tests[i][0], 'MMM', i);
  5744. equalTest(tests[i][1], 'MMM', i);
  5745. equalTest(tests[i][0], 'MMMM', i);
  5746. equalTest(tests[i][1], 'MMMM', i);
  5747. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  5748. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  5749. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  5750. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  5751. }
  5752. });
  5753. test('format', function (assert) {
  5754. var a = [
  5755. ['dddd, Do MMMM YYYY, h:mm:ss a', 'Sonntag, 14. Februar 2010, 3:25:50 pm'],
  5756. ['ddd, hA', 'So., 3PM'],
  5757. ['M Mo MM MMMM MMM', '2 2. 02 Februar Febr.'],
  5758. ['YYYY YY', '2010 10'],
  5759. ['D Do DD', '14 14. 14'],
  5760. ['d do dddd ddd dd', '0 0. Sonntag So. So'],
  5761. ['DDD DDDo DDDD', '45 45. 045'],
  5762. ['w wo ww', '6 6. 06'],
  5763. ['h hh', '3 03'],
  5764. ['H HH', '15 15'],
  5765. ['m mm', '25 25'],
  5766. ['s ss', '50 50'],
  5767. ['a A', 'pm PM'],
  5768. ['[the] DDDo [day of the year]', 'the 45. day of the year'],
  5769. ['LTS', '15:25:50'],
  5770. ['L', '14.02.2010'],
  5771. ['LL', '14. Februar 2010'],
  5772. ['LLL', '14. Februar 2010 15:25'],
  5773. ['LLLL', 'Sonntag, 14. Februar 2010 15:25'],
  5774. ['l', '14.2.2010'],
  5775. ['ll', '14. Febr. 2010'],
  5776. ['lll', '14. Febr. 2010 15:25'],
  5777. ['llll', 'So., 14. Febr. 2010 15:25']
  5778. ],
  5779. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  5780. i;
  5781. for (i = 0; i < a.length; i++) {
  5782. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  5783. }
  5784. });
  5785. test('format ordinal', function (assert) {
  5786. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
  5787. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
  5788. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
  5789. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
  5790. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
  5791. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
  5792. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
  5793. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
  5794. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
  5795. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
  5796. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
  5797. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
  5798. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
  5799. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
  5800. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
  5801. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
  5802. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
  5803. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
  5804. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
  5805. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
  5806. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
  5807. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
  5808. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
  5809. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
  5810. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
  5811. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
  5812. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
  5813. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
  5814. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
  5815. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
  5816. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
  5817. });
  5818. test('format month', function (assert) {
  5819. var expected = 'Jänner Jän._Februar Febr._März Mrz._April Apr._Mai Mai_Juni Jun._Juli Jul._August Aug._September Sept._Oktober Okt._November Nov._Dezember Dez.'.split('_'), i;
  5820. for (i = 0; i < expected.length; i++) {
  5821. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  5822. }
  5823. });
  5824. test('format week', function (assert) {
  5825. var expected = 'Sonntag So. So_Montag Mo. Mo_Dienstag Di. Di_Mittwoch Mi. Mi_Donnerstag Do. Do_Freitag Fr. Fr_Samstag Sa. Sa'.split('_'), i;
  5826. for (i = 0; i < expected.length; i++) {
  5827. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  5828. }
  5829. });
  5830. test('from', function (assert) {
  5831. var start = moment([2007, 1, 28]);
  5832. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ein paar Sekunden', '44 seconds = a few seconds');
  5833. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'eine Minute', '45 seconds = a minute');
  5834. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'eine Minute', '89 seconds = a minute');
  5835. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 Minuten', '90 seconds = 2 minutes');
  5836. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 Minuten', '44 minutes = 44 minutes');
  5837. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'eine Stunde', '45 minutes = an hour');
  5838. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'eine Stunde', '89 minutes = an hour');
  5839. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 Stunden', '90 minutes = 2 hours');
  5840. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 Stunden', '5 hours = 5 hours');
  5841. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 Stunden', '21 hours = 21 hours');
  5842. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ein Tag', '22 hours = a day');
  5843. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ein Tag', '35 hours = a day');
  5844. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 Tage', '36 hours = 2 days');
  5845. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ein Tag', '1 day = a day');
  5846. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 Tage', '5 days = 5 days');
  5847. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 Tage', '25 days = 25 days');
  5848. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ein Monat', '26 days = a month');
  5849. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ein Monat', '30 days = a month');
  5850. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 Monate', '46 days = 2 months');
  5851. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 Monate', '75 days = 2 months');
  5852. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 Monate', '76 days = 3 months');
  5853. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ein Monat', '1 month = a month');
  5854. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 Monate', '5 months = 5 months');
  5855. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ein Jahr', '345 days = a year');
  5856. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 Jahre', '548 days = 2 years');
  5857. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ein Jahr', '1 year = a year');
  5858. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 Jahre', '5 years = 5 years');
  5859. });
  5860. test('suffix', function (assert) {
  5861. assert.equal(moment(30000).from(0), 'in ein paar Sekunden', 'prefix');
  5862. assert.equal(moment(0).from(30000), 'vor ein paar Sekunden', 'suffix');
  5863. });
  5864. test('fromNow', function (assert) {
  5865. assert.equal(moment().add({s: 30}).fromNow(), 'in ein paar Sekunden', 'in a few seconds');
  5866. assert.equal(moment().add({d: 5}).fromNow(), 'in 5 Tagen', 'in 5 days');
  5867. });
  5868. test('calendar day', function (assert) {
  5869. var a = moment().hours(2).minutes(0).seconds(0);
  5870. assert.equal(moment(a).calendar(), 'heute um 02:00 Uhr', 'today at the same time');
  5871. assert.equal(moment(a).add({m: 25}).calendar(), 'heute um 02:25 Uhr', 'Now plus 25 min');
  5872. assert.equal(moment(a).add({h: 1}).calendar(), 'heute um 03:00 Uhr', 'Now plus 1 hour');
  5873. assert.equal(moment(a).add({d: 1}).calendar(), 'morgen um 02:00 Uhr', 'tomorrow at the same time');
  5874. assert.equal(moment(a).subtract({h: 1}).calendar(), 'heute um 01:00 Uhr', 'Now minus 1 hour');
  5875. assert.equal(moment(a).subtract({d: 1}).calendar(), 'gestern um 02:00 Uhr', 'yesterday at the same time');
  5876. });
  5877. test('calendar next week', function (assert) {
  5878. var i, m;
  5879. for (i = 2; i < 7; i++) {
  5880. m = moment().add({d: i});
  5881. assert.equal(m.calendar(), m.format('dddd [um] LT [Uhr]'), 'Today + ' + i + ' days current time');
  5882. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  5883. assert.equal(m.calendar(), m.format('dddd [um] LT [Uhr]'), 'Today + ' + i + ' days beginning of day');
  5884. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  5885. assert.equal(m.calendar(), m.format('dddd [um] LT [Uhr]'), 'Today + ' + i + ' days end of day');
  5886. }
  5887. });
  5888. test('calendar last week', function (assert) {
  5889. var i, m;
  5890. for (i = 2; i < 7; i++) {
  5891. m = moment().subtract({d: i});
  5892. assert.equal(m.calendar(), m.format('[letzten] dddd [um] LT [Uhr]'), 'Today + ' + i + ' days current time');
  5893. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  5894. assert.equal(m.calendar(), m.format('[letzten] dddd [um] LT [Uhr]'), 'Today + ' + i + ' days beginning of day');
  5895. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  5896. assert.equal(m.calendar(), m.format('[letzten] dddd [um] LT [Uhr]'), 'Today + ' + i + ' days end of day');
  5897. }
  5898. });
  5899. test('calendar all else', function (assert) {
  5900. var weeksAgo = moment().subtract({w: 1}),
  5901. weeksFromNow = moment().add({w: 1});
  5902. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  5903. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  5904. weeksAgo = moment().subtract({w: 2});
  5905. weeksFromNow = moment().add({w: 2});
  5906. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  5907. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  5908. });
  5909. test('weeks year starting sunday', function (assert) {
  5910. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  5911. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  5912. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  5913. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  5914. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  5915. });
  5916. test('weeks year starting monday', function (assert) {
  5917. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  5918. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  5919. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  5920. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  5921. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  5922. });
  5923. test('weeks year starting tuesday', function (assert) {
  5924. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  5925. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  5926. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  5927. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  5928. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  5929. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  5930. });
  5931. test('weeks year starting wednesday', function (assert) {
  5932. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  5933. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  5934. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  5935. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  5936. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  5937. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  5938. });
  5939. test('weeks year starting thursday', function (assert) {
  5940. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  5941. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  5942. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  5943. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  5944. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  5945. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  5946. });
  5947. test('weeks year starting friday', function (assert) {
  5948. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  5949. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  5950. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  5951. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  5952. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  5953. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  5954. });
  5955. test('weeks year starting saturday', function (assert) {
  5956. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  5957. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  5958. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  5959. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  5960. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  5961. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  5962. });
  5963. test('weeks year starting sunday formatted', function (assert) {
  5964. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
  5965. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
  5966. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
  5967. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
  5968. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
  5969. });
  5970. test('lenient ordinal parsing', function (assert) {
  5971. var i, ordinalStr, testMoment;
  5972. for (i = 1; i <= 31; ++i) {
  5973. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  5974. testMoment = moment(ordinalStr, 'YYYY MM Do');
  5975. assert.equal(testMoment.year(), 2014,
  5976. 'lenient ordinal parsing ' + i + ' year check');
  5977. assert.equal(testMoment.month(), 0,
  5978. 'lenient ordinal parsing ' + i + ' month check');
  5979. assert.equal(testMoment.date(), i,
  5980. 'lenient ordinal parsing ' + i + ' date check');
  5981. }
  5982. });
  5983. test('lenient ordinal parsing of number', function (assert) {
  5984. var i, testMoment;
  5985. for (i = 1; i <= 31; ++i) {
  5986. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  5987. assert.equal(testMoment.year(), 2014,
  5988. 'lenient ordinal parsing of number ' + i + ' year check');
  5989. assert.equal(testMoment.month(), 0,
  5990. 'lenient ordinal parsing of number ' + i + ' month check');
  5991. assert.equal(testMoment.date(), i,
  5992. 'lenient ordinal parsing of number ' + i + ' date check');
  5993. }
  5994. });
  5995. test('strict ordinal parsing', function (assert) {
  5996. var i, ordinalStr, testMoment;
  5997. for (i = 1; i <= 31; ++i) {
  5998. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  5999. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  6000. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  6001. }
  6002. });
  6003. }));
  6004. ;(function (global, factory) {
  6005. typeof exports === 'object' && typeof module !== 'undefined'
  6006. && typeof require === 'function' ? factory(require('../../moment')) :
  6007. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  6008. factory(global.moment)
  6009. }(this, function (moment) { 'use strict';
  6010. /*global QUnit:false*/
  6011. var test = QUnit.test;
  6012. var expect = QUnit.expect;
  6013. function module (name, lifecycle) {
  6014. QUnit.module(name, {
  6015. setup : function () {
  6016. moment.locale('en');
  6017. moment.createFromInputFallback = function (config) {
  6018. throw new Error('input not handled by moment: ' + config._i);
  6019. };
  6020. if (lifecycle && lifecycle.setup) {
  6021. lifecycle.setup();
  6022. }
  6023. },
  6024. teardown : function () {
  6025. if (lifecycle && lifecycle.teardown) {
  6026. lifecycle.teardown();
  6027. }
  6028. }
  6029. });
  6030. }
  6031. function localeModule (name, lifecycle) {
  6032. QUnit.module('locale:' + name, {
  6033. setup : function () {
  6034. moment.locale(name);
  6035. moment.createFromInputFallback = function (config) {
  6036. throw new Error('input not handled by moment: ' + config._i);
  6037. };
  6038. if (lifecycle && lifecycle.setup) {
  6039. lifecycle.setup();
  6040. }
  6041. },
  6042. teardown : function () {
  6043. moment.locale('en');
  6044. if (lifecycle && lifecycle.teardown) {
  6045. lifecycle.teardown();
  6046. }
  6047. }
  6048. });
  6049. }
  6050. localeModule('de');
  6051. test('parse', function (assert) {
  6052. var tests = 'Januar Jan._Februar Febr._März Mrz._April Apr._Mai Mai_Juni Jun._Juli Jul._August Aug._September Sept._Oktober Okt._November Nov._Dezember Dez.'.split('_'), i;
  6053. function equalTest(input, mmm, i) {
  6054. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  6055. }
  6056. for (i = 0; i < 12; i++) {
  6057. tests[i] = tests[i].split(' ');
  6058. equalTest(tests[i][0], 'MMM', i);
  6059. equalTest(tests[i][1], 'MMM', i);
  6060. equalTest(tests[i][0], 'MMMM', i);
  6061. equalTest(tests[i][1], 'MMMM', i);
  6062. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  6063. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  6064. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  6065. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  6066. }
  6067. });
  6068. test('format', function (assert) {
  6069. var a = [
  6070. ['dddd, Do MMMM YYYY, h:mm:ss a', 'Sonntag, 14. Februar 2010, 3:25:50 pm'],
  6071. ['ddd, hA', 'So., 3PM'],
  6072. ['M Mo MM MMMM MMM', '2 2. 02 Februar Febr.'],
  6073. ['YYYY YY', '2010 10'],
  6074. ['D Do DD', '14 14. 14'],
  6075. ['d do dddd ddd dd', '0 0. Sonntag So. So'],
  6076. ['DDD DDDo DDDD', '45 45. 045'],
  6077. ['w wo ww', '6 6. 06'],
  6078. ['h hh', '3 03'],
  6079. ['H HH', '15 15'],
  6080. ['m mm', '25 25'],
  6081. ['s ss', '50 50'],
  6082. ['a A', 'pm PM'],
  6083. ['[the] DDDo [day of the year]', 'the 45. day of the year'],
  6084. ['LTS', '15:25:50'],
  6085. ['L', '14.02.2010'],
  6086. ['LL', '14. Februar 2010'],
  6087. ['LLL', '14. Februar 2010 15:25'],
  6088. ['LLLL', 'Sonntag, 14. Februar 2010 15:25'],
  6089. ['l', '14.2.2010'],
  6090. ['ll', '14. Febr. 2010'],
  6091. ['lll', '14. Febr. 2010 15:25'],
  6092. ['llll', 'So., 14. Febr. 2010 15:25']
  6093. ],
  6094. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  6095. i;
  6096. for (i = 0; i < a.length; i++) {
  6097. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  6098. }
  6099. });
  6100. test('format ordinal', function (assert) {
  6101. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
  6102. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
  6103. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
  6104. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
  6105. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
  6106. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
  6107. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
  6108. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
  6109. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
  6110. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
  6111. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
  6112. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
  6113. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
  6114. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
  6115. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
  6116. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
  6117. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
  6118. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
  6119. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
  6120. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
  6121. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
  6122. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
  6123. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
  6124. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
  6125. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
  6126. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
  6127. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
  6128. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
  6129. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
  6130. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
  6131. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
  6132. });
  6133. test('format month', function (assert) {
  6134. var expected = 'Januar Jan._Februar Febr._März Mrz._April Apr._Mai Mai_Juni Jun._Juli Jul._August Aug._September Sept._Oktober Okt._November Nov._Dezember Dez.'.split('_'), i;
  6135. for (i = 0; i < expected.length; i++) {
  6136. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  6137. }
  6138. });
  6139. test('format week', function (assert) {
  6140. var expected = 'Sonntag So. So_Montag Mo. Mo_Dienstag Di. Di_Mittwoch Mi. Mi_Donnerstag Do. Do_Freitag Fr. Fr_Samstag Sa. Sa'.split('_'), i;
  6141. for (i = 0; i < expected.length; i++) {
  6142. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  6143. }
  6144. });
  6145. test('from', function (assert) {
  6146. var start = moment([2007, 1, 28]);
  6147. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ein paar Sekunden', '44 seconds = a few seconds');
  6148. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'eine Minute', '45 seconds = a minute');
  6149. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'eine Minute', '89 seconds = a minute');
  6150. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 Minuten', '90 seconds = 2 minutes');
  6151. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 Minuten', '44 minutes = 44 minutes');
  6152. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'eine Stunde', '45 minutes = an hour');
  6153. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'eine Stunde', '89 minutes = an hour');
  6154. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 Stunden', '90 minutes = 2 hours');
  6155. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 Stunden', '5 hours = 5 hours');
  6156. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 Stunden', '21 hours = 21 hours');
  6157. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ein Tag', '22 hours = a day');
  6158. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ein Tag', '35 hours = a day');
  6159. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 Tage', '36 hours = 2 days');
  6160. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ein Tag', '1 day = a day');
  6161. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 Tage', '5 days = 5 days');
  6162. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 Tage', '25 days = 25 days');
  6163. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ein Monat', '26 days = a month');
  6164. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ein Monat', '30 days = a month');
  6165. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ein Monat', '43 days = a month');
  6166. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 Monate', '46 days = 2 months');
  6167. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 Monate', '75 days = 2 months');
  6168. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 Monate', '76 days = 3 months');
  6169. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ein Monat', '1 month = a month');
  6170. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 Monate', '5 months = 5 months');
  6171. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ein Jahr', '345 days = a year');
  6172. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 Jahre', '548 days = 2 years');
  6173. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ein Jahr', '1 year = a year');
  6174. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 Jahre', '5 years = 5 years');
  6175. });
  6176. test('suffix', function (assert) {
  6177. assert.equal(moment(30000).from(0), 'in ein paar Sekunden', 'prefix');
  6178. assert.equal(moment(0).from(30000), 'vor ein paar Sekunden', 'suffix');
  6179. });
  6180. test('fromNow', function (assert) {
  6181. assert.equal(moment().add({s: 30}).fromNow(), 'in ein paar Sekunden', 'in a few seconds');
  6182. assert.equal(moment().add({d: 5}).fromNow(), 'in 5 Tagen', 'in 5 days');
  6183. });
  6184. test('calendar day', function (assert) {
  6185. var a = moment().hours(2).minutes(0).seconds(0);
  6186. assert.equal(moment(a).calendar(), 'heute um 02:00 Uhr', 'today at the same time');
  6187. assert.equal(moment(a).add({m: 25}).calendar(), 'heute um 02:25 Uhr', 'Now plus 25 min');
  6188. assert.equal(moment(a).add({h: 1}).calendar(), 'heute um 03:00 Uhr', 'Now plus 1 hour');
  6189. assert.equal(moment(a).add({d: 1}).calendar(), 'morgen um 02:00 Uhr', 'tomorrow at the same time');
  6190. assert.equal(moment(a).subtract({h: 1}).calendar(), 'heute um 01:00 Uhr', 'Now minus 1 hour');
  6191. assert.equal(moment(a).subtract({d: 1}).calendar(), 'gestern um 02:00 Uhr', 'yesterday at the same time');
  6192. });
  6193. test('calendar next week', function (assert) {
  6194. var i, m;
  6195. for (i = 2; i < 7; i++) {
  6196. m = moment().add({d: i});
  6197. assert.equal(m.calendar(), m.format('dddd [um] LT [Uhr]'), 'Today + ' + i + ' days current time');
  6198. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  6199. assert.equal(m.calendar(), m.format('dddd [um] LT [Uhr]'), 'Today + ' + i + ' days beginning of day');
  6200. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  6201. assert.equal(m.calendar(), m.format('dddd [um] LT [Uhr]'), 'Today + ' + i + ' days end of day');
  6202. }
  6203. });
  6204. test('calendar last week', function (assert) {
  6205. var i, m;
  6206. for (i = 2; i < 7; i++) {
  6207. m = moment().subtract({d: i});
  6208. assert.equal(m.calendar(), m.format('[letzten] dddd [um] LT [Uhr]'), 'Today + ' + i + ' days current time');
  6209. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  6210. assert.equal(m.calendar(), m.format('[letzten] dddd [um] LT [Uhr]'), 'Today + ' + i + ' days beginning of day');
  6211. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  6212. assert.equal(m.calendar(), m.format('[letzten] dddd [um] LT [Uhr]'), 'Today + ' + i + ' days end of day');
  6213. }
  6214. });
  6215. test('calendar all else', function (assert) {
  6216. var weeksAgo = moment().subtract({w: 1}),
  6217. weeksFromNow = moment().add({w: 1});
  6218. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  6219. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  6220. weeksAgo = moment().subtract({w: 2});
  6221. weeksFromNow = moment().add({w: 2});
  6222. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  6223. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  6224. });
  6225. test('weeks year starting sunday', function (assert) {
  6226. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  6227. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  6228. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  6229. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  6230. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  6231. });
  6232. test('weeks year starting monday', function (assert) {
  6233. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  6234. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  6235. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  6236. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  6237. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  6238. });
  6239. test('weeks year starting tuesday', function (assert) {
  6240. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  6241. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  6242. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  6243. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  6244. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  6245. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  6246. });
  6247. test('weeks year starting wednesday', function (assert) {
  6248. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  6249. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  6250. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  6251. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  6252. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  6253. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  6254. });
  6255. test('weeks year starting thursday', function (assert) {
  6256. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  6257. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  6258. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  6259. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  6260. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  6261. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  6262. });
  6263. test('weeks year starting friday', function (assert) {
  6264. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  6265. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  6266. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  6267. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  6268. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  6269. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  6270. });
  6271. test('weeks year starting saturday', function (assert) {
  6272. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  6273. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  6274. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  6275. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  6276. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  6277. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  6278. });
  6279. test('weeks year starting sunday formatted', function (assert) {
  6280. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
  6281. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
  6282. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
  6283. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
  6284. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
  6285. });
  6286. test('lenient ordinal parsing', function (assert) {
  6287. var i, ordinalStr, testMoment;
  6288. for (i = 1; i <= 31; ++i) {
  6289. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  6290. testMoment = moment(ordinalStr, 'YYYY MM Do');
  6291. assert.equal(testMoment.year(), 2014,
  6292. 'lenient ordinal parsing ' + i + ' year check');
  6293. assert.equal(testMoment.month(), 0,
  6294. 'lenient ordinal parsing ' + i + ' month check');
  6295. assert.equal(testMoment.date(), i,
  6296. 'lenient ordinal parsing ' + i + ' date check');
  6297. }
  6298. });
  6299. test('lenient ordinal parsing of number', function (assert) {
  6300. var i, testMoment;
  6301. for (i = 1; i <= 31; ++i) {
  6302. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  6303. assert.equal(testMoment.year(), 2014,
  6304. 'lenient ordinal parsing of number ' + i + ' year check');
  6305. assert.equal(testMoment.month(), 0,
  6306. 'lenient ordinal parsing of number ' + i + ' month check');
  6307. assert.equal(testMoment.date(), i,
  6308. 'lenient ordinal parsing of number ' + i + ' date check');
  6309. }
  6310. });
  6311. test('strict ordinal parsing', function (assert) {
  6312. var i, ordinalStr, testMoment;
  6313. for (i = 1; i <= 31; ++i) {
  6314. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  6315. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  6316. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  6317. }
  6318. });
  6319. }));
  6320. ;(function (global, factory) {
  6321. typeof exports === 'object' && typeof module !== 'undefined'
  6322. && typeof require === 'function' ? factory(require('../../moment')) :
  6323. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  6324. factory(global.moment)
  6325. }(this, function (moment) { 'use strict';
  6326. /*global QUnit:false*/
  6327. var test = QUnit.test;
  6328. var expect = QUnit.expect;
  6329. function module (name, lifecycle) {
  6330. QUnit.module(name, {
  6331. setup : function () {
  6332. moment.locale('en');
  6333. moment.createFromInputFallback = function (config) {
  6334. throw new Error('input not handled by moment: ' + config._i);
  6335. };
  6336. if (lifecycle && lifecycle.setup) {
  6337. lifecycle.setup();
  6338. }
  6339. },
  6340. teardown : function () {
  6341. if (lifecycle && lifecycle.teardown) {
  6342. lifecycle.teardown();
  6343. }
  6344. }
  6345. });
  6346. }
  6347. function localeModule (name, lifecycle) {
  6348. QUnit.module('locale:' + name, {
  6349. setup : function () {
  6350. moment.locale(name);
  6351. moment.createFromInputFallback = function (config) {
  6352. throw new Error('input not handled by moment: ' + config._i);
  6353. };
  6354. if (lifecycle && lifecycle.setup) {
  6355. lifecycle.setup();
  6356. }
  6357. },
  6358. teardown : function () {
  6359. moment.locale('en');
  6360. if (lifecycle && lifecycle.teardown) {
  6361. lifecycle.teardown();
  6362. }
  6363. }
  6364. });
  6365. }
  6366. localeModule('dv');
  6367. test('parse', function (assert) {
  6368. var i,
  6369. tests = [
  6370. 'ޖެނުއަރީ',
  6371. 'ފެބްރުއަރީ',
  6372. 'މާރިޗު',
  6373. 'އޭޕްރީލު',
  6374. 'މޭ',
  6375. 'ޖޫން',
  6376. 'ޖުލައި',
  6377. 'އޯގަސްޓު',
  6378. 'ސެޕްޓެމްބަރު',
  6379. 'އޮކްޓޯބަރު',
  6380. 'ނޮވެމްބަރު',
  6381. 'ޑިސެމްބަރު'
  6382. ];
  6383. function equalTest(input, mmm, i) {
  6384. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  6385. }
  6386. for (i = 0; i < 12; i++) {
  6387. equalTest(tests[i], 'MMM', i);
  6388. equalTest(tests[i], 'MMMM', i);
  6389. equalTest(tests[i].toLocaleLowerCase(), 'MMMM', i);
  6390. equalTest(tests[i].toLocaleUpperCase(), 'MMMM', i);
  6391. }
  6392. });
  6393. test('format', function (assert) {
  6394. var a = [
  6395. ['dddd, MMMM Do YYYY, h:mm:ss a', 'އާދިއްތަ، ފެބްރުއަރީ 14 2010، 3:25:50 މފ'],
  6396. ['ddd, hA', 'އާދިއްތަ، 3މފ'],
  6397. ['M Mo MM MMMM MMM', '2 2 02 ފެބްރުއަރީ ފެބްރުއަރީ'],
  6398. ['YYYY YY', '2010 10'],
  6399. ['D Do DD', '14 14 14'],
  6400. ['d do dddd ddd dd', '0 0 އާދިއްތަ އާދިއްތަ އާދި'],
  6401. ['DDD DDDo DDDD', '45 45 045'],
  6402. ['w wo ww', '8 8 08'],
  6403. ['h hh', '3 03'],
  6404. ['H HH', '15 15'],
  6405. ['m mm', '25 25'],
  6406. ['s ss', '50 50'],
  6407. ['a A', 'މފ މފ'],
  6408. ['LTS', '15:25:50'],
  6409. ['L', '14/2/2010'],
  6410. ['LL', '14 ފެބްރުއަރީ 2010'],
  6411. ['LLL', '14 ފެބްރުއަރީ 2010 15:25'],
  6412. ['LLLL', 'އާދިއްތަ 14 ފެބްރުއަރީ 2010 15:25'],
  6413. ['l', '14/2/2010'],
  6414. ['ll', '14 ފެބްރުއަރީ 2010'],
  6415. ['lll', '14 ފެބްރުއަރީ 2010 15:25'],
  6416. ['llll', 'އާދިއްތަ 14 ފެބްރުއަރީ 2010 15:25']
  6417. ],
  6418. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  6419. i;
  6420. for (i = 0; i < a.length; i++) {
  6421. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  6422. }
  6423. });
  6424. test('format month', function (assert) {
  6425. var i,
  6426. expected = [
  6427. 'ޖެނުއަރީ',
  6428. 'ފެބްރުއަރީ',
  6429. 'މާރިޗު',
  6430. 'އޭޕްރީލު',
  6431. 'މޭ',
  6432. 'ޖޫން',
  6433. 'ޖުލައި',
  6434. 'އޯގަސްޓު',
  6435. 'ސެޕްޓެމްބަރު',
  6436. 'އޮކްޓޯބަރު',
  6437. 'ނޮވެމްބަރު',
  6438. 'ޑިސެމްބަރު'
  6439. ];
  6440. for (i = 0; i < expected.length; i++) {
  6441. assert.equal(moment([2011, i, 1]).format('MMMM'), expected[i]);
  6442. }
  6443. });
  6444. test('format week', function (assert) {
  6445. var i,
  6446. expected = [
  6447. 'އާދިއްތަ',
  6448. 'ހޯމަ',
  6449. 'އަންގާރަ',
  6450. 'ބުދަ',
  6451. 'ބުރާސްފަތި',
  6452. 'ހުކުރު',
  6453. 'ހޮނިހިރު'
  6454. ];
  6455. for (i = 0; i < expected.length; i++) {
  6456. assert.equal(moment([2011, 0, 2 + i]).format('dddd'), expected[i]);
  6457. }
  6458. });
  6459. }));
  6460. ;(function (global, factory) {
  6461. typeof exports === 'object' && typeof module !== 'undefined'
  6462. && typeof require === 'function' ? factory(require('../../moment')) :
  6463. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  6464. factory(global.moment)
  6465. }(this, function (moment) { 'use strict';
  6466. /*global QUnit:false*/
  6467. var test = QUnit.test;
  6468. var expect = QUnit.expect;
  6469. function module (name, lifecycle) {
  6470. QUnit.module(name, {
  6471. setup : function () {
  6472. moment.locale('en');
  6473. moment.createFromInputFallback = function (config) {
  6474. throw new Error('input not handled by moment: ' + config._i);
  6475. };
  6476. if (lifecycle && lifecycle.setup) {
  6477. lifecycle.setup();
  6478. }
  6479. },
  6480. teardown : function () {
  6481. if (lifecycle && lifecycle.teardown) {
  6482. lifecycle.teardown();
  6483. }
  6484. }
  6485. });
  6486. }
  6487. function localeModule (name, lifecycle) {
  6488. QUnit.module('locale:' + name, {
  6489. setup : function () {
  6490. moment.locale(name);
  6491. moment.createFromInputFallback = function (config) {
  6492. throw new Error('input not handled by moment: ' + config._i);
  6493. };
  6494. if (lifecycle && lifecycle.setup) {
  6495. lifecycle.setup();
  6496. }
  6497. },
  6498. teardown : function () {
  6499. moment.locale('en');
  6500. if (lifecycle && lifecycle.teardown) {
  6501. lifecycle.teardown();
  6502. }
  6503. }
  6504. });
  6505. }
  6506. localeModule('el');
  6507. test('parse', function (assert) {
  6508. var i,
  6509. tests = 'Ιανουάριος Ιαν_Φεβρουάριος Φεβ_Μάρτιος Μαρ_Απρίλιος Απρ_Μάιος Μαϊ_Ιούνιος Ιουν_Ιούλιος Ιουλ_Αύγουστος Αυγ_Σεπτέμβριος Σεπ_Οκτώβριος Οκτ_Νοέμβριος Νοε_Δεκέμβριος Δεκ'.split('_');
  6510. function equalTest(input, mmm, i) {
  6511. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  6512. }
  6513. for (i = 0; i < 12; i++) {
  6514. tests[i] = tests[i].split(' ');
  6515. equalTest(tests[i][0], 'MMM', i);
  6516. equalTest(tests[i][1], 'MMM', i);
  6517. equalTest(tests[i][0], 'MMMM', i);
  6518. equalTest(tests[i][1], 'MMMM', i);
  6519. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  6520. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  6521. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  6522. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  6523. }
  6524. });
  6525. test('parse meridiem', function (assert) {
  6526. var i,
  6527. b = moment(),
  6528. meridiemTests = [
  6529. // h a patterns, expected hours, isValid
  6530. ['10 πμ', 10, true],
  6531. ['10 μμ', 22, true],
  6532. ['10 π.μ.', 10, true],
  6533. ['10 μ.μ.', 22, true],
  6534. ['10 π', 10, true],
  6535. ['10 μ', 22, true],
  6536. ['10 ΠΜ', 10, true],
  6537. ['10 ΜΜ', 22, true],
  6538. ['10 Π.Μ.', 10, true],
  6539. ['10 Μ.Μ.', 22, true],
  6540. ['10 Π', 10, true],
  6541. ['10 Μ', 22, true],
  6542. ['10 am', 10, false],
  6543. ['10 pm', 10, false]
  6544. ],
  6545. parsed;
  6546. // test that a formatted moment including meridiem string can be parsed back to the same moment
  6547. assert.ok(b.isSame(moment(b.format('h:mm:ss a'), 'h:mm:ss a', 'el', true), 'seconds'), b.format('h:mm:ss a') + ' should be equal to ' + moment(b.format('h:mm:ss a'), 'h:mm:ss a', 'el', true).format('h:mm:ss a'));
  6548. // test that a formatted moment having a meridiem string can be parsed with strict flag
  6549. assert.ok(moment(b.format('h:mm:ss a'), 'h:mm:ss a', 'el', true).isValid(), b.format('h:mm:ss a') + ' should be parsed as valid');
  6550. for (i = 0; i < meridiemTests.length; i++) {
  6551. parsed = moment(meridiemTests[i][0], 'h a', 'el', true);
  6552. assert.equal(parsed.isValid(), meridiemTests[i][2], 'validity for ' + meridiemTests[i][0]);
  6553. if (parsed.isValid()) {
  6554. assert.equal(parsed.hours(), meridiemTests[i][1], 'hours for ' + meridiemTests[i][0]);
  6555. }
  6556. }
  6557. });
  6558. test('format', function (assert) {
  6559. var a = [
  6560. ['dddd, MMMM Do YYYY, h:mm:ss a', 'Κυριακή, Φεβρουάριος 14η 2010, 3:25:50 μμ'],
  6561. ['dddd, D MMMM YYYY, h:mm:ss a', 'Κυριακή, 14 Φεβρουαρίου 2010, 3:25:50 μμ'],
  6562. ['ddd, hA', 'Κυρ, 3ΜΜ'],
  6563. ['dddd, MMMM YYYY', 'Κυριακή, Φεβρουάριος 2010'],
  6564. ['M Mo MM MMMM MMM', '2 2η 02 Φεβρουάριος Φεβ'],
  6565. ['YYYY YY', '2010 10'],
  6566. ['D Do DD', '14 14η 14'],
  6567. ['d do dddd ddd dd', '0 0η Κυριακή Κυρ Κυ'],
  6568. ['DDD DDDo DDDD', '45 45η 045'],
  6569. ['w wo ww', '6 6η 06'],
  6570. ['h hh', '3 03'],
  6571. ['H HH', '15 15'],
  6572. ['m mm', '25 25'],
  6573. ['s ss', '50 50'],
  6574. ['a A', 'μμ ΜΜ'],
  6575. ['[the] DDDo [day of the year]', 'the 45η day of the year'],
  6576. ['LTS', '3:25:50 ΜΜ'],
  6577. ['L', '14/02/2010'],
  6578. ['LL', '14 Φεβρουαρίου 2010'],
  6579. ['LLL', '14 Φεβρουαρίου 2010 3:25 ΜΜ'],
  6580. ['LLLL', 'Κυριακή, 14 Φεβρουαρίου 2010 3:25 ΜΜ'],
  6581. ['l', '14/2/2010'],
  6582. ['ll', '14 Φεβ 2010'],
  6583. ['lll', '14 Φεβ 2010 3:25 ΜΜ'],
  6584. ['llll', 'Κυρ, 14 Φεβ 2010 3:25 ΜΜ']
  6585. ],
  6586. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  6587. i;
  6588. for (i = 0; i < a.length; i++) {
  6589. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  6590. }
  6591. });
  6592. test('format ordinal', function (assert) {
  6593. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1η', '1η');
  6594. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2η', '2η');
  6595. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3η', '3η');
  6596. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4η', '4η');
  6597. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5η', '5η');
  6598. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6η', '6η');
  6599. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7η', '7η');
  6600. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8η', '8η');
  6601. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9η', '9η');
  6602. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10η', '10η');
  6603. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11η', '11η');
  6604. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12η', '12η');
  6605. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13η', '13η');
  6606. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14η', '14η');
  6607. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15η', '15η');
  6608. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16η', '16η');
  6609. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17η', '17η');
  6610. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18η', '18η');
  6611. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19η', '19η');
  6612. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20η', '20η');
  6613. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21η', '21η');
  6614. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22η', '22η');
  6615. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23η', '23η');
  6616. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24η', '24η');
  6617. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25η', '25η');
  6618. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26η', '26η');
  6619. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27η', '27η');
  6620. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28η', '28η');
  6621. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29η', '29η');
  6622. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30η', '30η');
  6623. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31η', '31η');
  6624. });
  6625. test('format month', function (assert) {
  6626. var i,
  6627. expected = 'Ιανουάριος Ιαν_Φεβρουάριος Φεβ_Μάρτιος Μαρ_Απρίλιος Απρ_Μάιος Μαϊ_Ιούνιος Ιουν_Ιούλιος Ιουλ_Αύγουστος Αυγ_Σεπτέμβριος Σεπ_Οκτώβριος Οκτ_Νοέμβριος Νοε_Δεκέμβριος Δεκ'.split('_');
  6628. for (i = 0; i < expected.length; i++) {
  6629. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  6630. }
  6631. });
  6632. test('format week', function (assert) {
  6633. var i,
  6634. expected = 'Κυριακή Κυρ Κυ_Δευτέρα Δευ Δε_Τρίτη Τρι Τρ_Τετάρτη Τετ Τε_Πέμπτη Πεμ Πε_Παρασκευή Παρ Πα_Σάββατο Σαβ Σα'.split('_');
  6635. for (i = 0; i < expected.length; i++) {
  6636. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  6637. }
  6638. });
  6639. test('from', function (assert) {
  6640. var start = moment([2007, 1, 28]);
  6641. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'λίγα δευτερόλεπτα', '44 seconds = a few seconds');
  6642. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'ένα λεπτό', '45 seconds = a minute');
  6643. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'ένα λεπτό', '89 seconds = a minute');
  6644. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 λεπτά', '90 seconds = 2 minutes');
  6645. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 λεπτά', '44 minutes = 44 minutes');
  6646. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'μία ώρα', '45 minutes = an hour');
  6647. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'μία ώρα', '89 minutes = an hour');
  6648. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 ώρες', '90 minutes = 2 hours');
  6649. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ώρες', '5 hours = 5 hours');
  6650. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 ώρες', '21 hours = 21 hours');
  6651. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'μία μέρα', '22 hours = a day');
  6652. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'μία μέρα', '35 hours = a day');
  6653. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 μέρες', '36 hours = 2 days');
  6654. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'μία μέρα', '1 day = a day');
  6655. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 μέρες', '5 days = 5 days');
  6656. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 μέρες', '25 days = 25 days');
  6657. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ένας μήνας', '26 days = a month');
  6658. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ένας μήνας', '30 days = a month');
  6659. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ένας μήνας', '43 days = a month');
  6660. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 μήνες', '46 days = 2 months');
  6661. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 μήνες', '75 days = 2 months');
  6662. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 μήνες', '76 days = 3 months');
  6663. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ένας μήνας', '1 month = a month');
  6664. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 μήνες', '5 months = 5 months');
  6665. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ένας χρόνος', '345 days = a year');
  6666. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 χρόνια', '548 days = 2 years');
  6667. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ένας χρόνος', '1 year = a year');
  6668. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 χρόνια', '5 years = 5 years');
  6669. });
  6670. test('suffix', function (assert) {
  6671. assert.equal(moment(30000).from(0), 'σε λίγα δευτερόλεπτα', 'prefix');
  6672. assert.equal(moment(0).from(30000), 'λίγα δευτερόλεπτα πριν', 'suffix');
  6673. });
  6674. test('now from now', function (assert) {
  6675. assert.equal(moment().fromNow(), 'λίγα δευτερόλεπτα πριν', 'now from now should display as in the past');
  6676. });
  6677. test('fromNow', function (assert) {
  6678. assert.equal(moment().add({s: 30}).fromNow(), 'σε λίγα δευτερόλεπτα', 'in a few seconds');
  6679. assert.equal(moment().add({d: 5}).fromNow(), 'σε 5 μέρες', 'in 5 days');
  6680. });
  6681. test('calendar day', function (assert) {
  6682. var a = moment().hours(2).minutes(0).seconds(0);
  6683. assert.equal(moment(a).calendar(), 'Σήμερα στις 2:00 ΠΜ', 'today at the same time');
  6684. assert.equal(moment(a).add({m: 25}).calendar(), 'Σήμερα στις 2:25 ΠΜ', 'Now plus 25 min');
  6685. assert.equal(moment(a).add({h: 1}).calendar(), 'Σήμερα στις 3:00 ΠΜ', 'Now plus 1 hour');
  6686. assert.equal(moment(a).add({d: 1}).calendar(), 'Αύριο στις 2:00 ΠΜ', 'tomorrow at the same time');
  6687. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Σήμερα στη 1:00 ΠΜ', 'Now minus 1 hour');
  6688. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Χθες στις 2:00 ΠΜ', 'yesterday at the same time');
  6689. });
  6690. test('calendar next week', function (assert) {
  6691. var i, m;
  6692. for (i = 2; i < 7; i++) {
  6693. m = moment().add({d: i});
  6694. assert.equal(m.calendar(), m.format('dddd [' + (m.hours() % 12 === 1 ? 'στη' : 'στις') + '] LT'), 'Today + ' + i + ' days current time');
  6695. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  6696. assert.equal(m.calendar(), m.format('dddd [στις] LT'), 'Today + ' + i + ' days beginning of day');
  6697. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  6698. assert.equal(m.calendar(), m.format('dddd [στις] LT'), 'Today + ' + i + ' days end of day');
  6699. }
  6700. });
  6701. test('calendar last week', function (assert) {
  6702. var i, m, dayString;
  6703. for (i = 2; i < 7; i++) {
  6704. m = moment().subtract({d: i});
  6705. dayString = m.day() === 6 ? '[το προηγούμενο Σάββατο]' : '[την προηγούμενη] dddd';
  6706. assert.equal(m.calendar(), m.format(dayString + ' [' + (m.hours() % 12 === 1 ? 'στη' : 'στις') + '] LT'), 'Today - ' + i + ' days current time');
  6707. m.hours(1).minutes(30).seconds(0).milliseconds(0);
  6708. assert.equal(m.calendar(), m.format(dayString + ' [στη] LT'), 'Today - ' + i + ' days one o clock');
  6709. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  6710. assert.equal(m.calendar(), m.format(dayString + ' [στις] LT'), 'Today - ' + i + ' days beginning of day');
  6711. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  6712. assert.equal(m.calendar(), m.format(dayString + ' [στις] LT'), 'Today - ' + i + ' days end of day');
  6713. }
  6714. });
  6715. test('calendar all else', function (assert) {
  6716. var weeksAgo = moment().subtract({w: 1}),
  6717. weeksFromNow = moment().add({w: 1});
  6718. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  6719. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  6720. weeksAgo = moment().subtract({w: 2});
  6721. weeksFromNow = moment().add({w: 2});
  6722. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  6723. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  6724. });
  6725. test('weeks year starting sunday', function (assert) {
  6726. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  6727. assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1');
  6728. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  6729. assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2');
  6730. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  6731. });
  6732. test('weeks year starting monday', function (assert) {
  6733. assert.equal(moment([2006, 11, 31]).week(), 52, 'Dec 31 2006 should be week 52');
  6734. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  6735. assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1');
  6736. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  6737. assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2');
  6738. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  6739. });
  6740. test('weeks year starting tuesday', function (assert) {
  6741. assert.equal(moment([2007, 11, 30]).week(), 52, 'Dec 30 2007 should be week 52');
  6742. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  6743. assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1');
  6744. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  6745. assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2');
  6746. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  6747. });
  6748. test('weeks year starting wednesday', function (assert) {
  6749. assert.equal(moment([2002, 11, 29]).week(), 52, 'Dec 29 2002 should be week 52');
  6750. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  6751. assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1');
  6752. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  6753. assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2');
  6754. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  6755. });
  6756. test('weeks year starting thursday', function (assert) {
  6757. assert.equal(moment([2008, 11, 28]).week(), 52, 'Dec 28 2008 should be week 52');
  6758. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  6759. assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1');
  6760. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  6761. assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2');
  6762. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  6763. });
  6764. test('weeks year starting friday', function (assert) {
  6765. assert.equal(moment([2009, 11, 27]).week(), 52, 'Dec 27 2009 should be week 52');
  6766. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  6767. assert.equal(moment([2010, 0, 2]).week(), 53, 'Jan 2 2010 should be week 53');
  6768. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 1');
  6769. assert.equal(moment([2010, 0, 9]).week(), 1, 'Jan 9 2010 should be week 1');
  6770. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  6771. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  6772. });
  6773. test('weeks year starting saturday', function (assert) {
  6774. assert.equal(moment([2010, 11, 26]).week(), 51, 'Dec 26 2010 should be week 51');
  6775. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  6776. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  6777. assert.equal(moment([2011, 0, 8]).week(), 1, 'Jan 8 2011 should be week 1');
  6778. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  6779. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  6780. });
  6781. test('weeks year starting sunday format', function (assert) {
  6782. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52η', 'Jan 1 2012 should be week 52');
  6783. assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1η', 'Jan 7 2012 should be week 1');
  6784. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1η', 'Jan 8 2012 should be week 1');
  6785. assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2η', 'Jan 14 2012 should be week 2');
  6786. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2η', 'Jan 15 2012 should be week 2');
  6787. });
  6788. test('lenient ordinal parsing', function (assert) {
  6789. var i, ordinalStr, testMoment;
  6790. for (i = 1; i <= 31; ++i) {
  6791. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  6792. testMoment = moment(ordinalStr, 'YYYY MM Do');
  6793. assert.equal(testMoment.year(), 2014,
  6794. 'lenient ordinal parsing ' + i + ' year check');
  6795. assert.equal(testMoment.month(), 0,
  6796. 'lenient ordinal parsing ' + i + ' month check');
  6797. assert.equal(testMoment.date(), i,
  6798. 'lenient ordinal parsing ' + i + ' date check');
  6799. }
  6800. });
  6801. test('lenient ordinal parsing of number', function (assert) {
  6802. var i, testMoment;
  6803. for (i = 1; i <= 31; ++i) {
  6804. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  6805. assert.equal(testMoment.year(), 2014,
  6806. 'lenient ordinal parsing of number ' + i + ' year check');
  6807. assert.equal(testMoment.month(), 0,
  6808. 'lenient ordinal parsing of number ' + i + ' month check');
  6809. assert.equal(testMoment.date(), i,
  6810. 'lenient ordinal parsing of number ' + i + ' date check');
  6811. }
  6812. });
  6813. test('strict ordinal parsing', function (assert) {
  6814. var i, ordinalStr, testMoment;
  6815. for (i = 1; i <= 31; ++i) {
  6816. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  6817. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  6818. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  6819. }
  6820. });
  6821. }));
  6822. ;(function (global, factory) {
  6823. typeof exports === 'object' && typeof module !== 'undefined'
  6824. && typeof require === 'function' ? factory(require('../../moment')) :
  6825. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  6826. factory(global.moment)
  6827. }(this, function (moment) { 'use strict';
  6828. /*global QUnit:false*/
  6829. var test = QUnit.test;
  6830. var expect = QUnit.expect;
  6831. function module (name, lifecycle) {
  6832. QUnit.module(name, {
  6833. setup : function () {
  6834. moment.locale('en');
  6835. moment.createFromInputFallback = function (config) {
  6836. throw new Error('input not handled by moment: ' + config._i);
  6837. };
  6838. if (lifecycle && lifecycle.setup) {
  6839. lifecycle.setup();
  6840. }
  6841. },
  6842. teardown : function () {
  6843. if (lifecycle && lifecycle.teardown) {
  6844. lifecycle.teardown();
  6845. }
  6846. }
  6847. });
  6848. }
  6849. function localeModule (name, lifecycle) {
  6850. QUnit.module('locale:' + name, {
  6851. setup : function () {
  6852. moment.locale(name);
  6853. moment.createFromInputFallback = function (config) {
  6854. throw new Error('input not handled by moment: ' + config._i);
  6855. };
  6856. if (lifecycle && lifecycle.setup) {
  6857. lifecycle.setup();
  6858. }
  6859. },
  6860. teardown : function () {
  6861. moment.locale('en');
  6862. if (lifecycle && lifecycle.teardown) {
  6863. lifecycle.teardown();
  6864. }
  6865. }
  6866. });
  6867. }
  6868. localeModule('en-au');
  6869. test('parse', function (assert) {
  6870. var tests = 'January Jan_February Feb_March Mar_April Apr_May May_June Jun_July Jul_August Aug_September Sep_October Oct_November Nov_December Dec'.split('_'), i;
  6871. function equalTest(input, mmm, i) {
  6872. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  6873. }
  6874. for (i = 0; i < 12; i++) {
  6875. tests[i] = tests[i].split(' ');
  6876. equalTest(tests[i][0], 'MMM', i);
  6877. equalTest(tests[i][1], 'MMM', i);
  6878. equalTest(tests[i][0], 'MMMM', i);
  6879. equalTest(tests[i][1], 'MMMM', i);
  6880. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  6881. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  6882. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  6883. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  6884. }
  6885. });
  6886. test('format', function (assert) {
  6887. var a = [
  6888. ['dddd, MMMM Do YYYY, h:mm:ss a', 'Sunday, February 14th 2010, 3:25:50 pm'],
  6889. ['ddd, hA', 'Sun, 3PM'],
  6890. ['M Mo MM MMMM MMM', '2 2nd 02 February Feb'],
  6891. ['YYYY YY', '2010 10'],
  6892. ['D Do DD', '14 14th 14'],
  6893. ['d do dddd ddd dd', '0 0th Sunday Sun Su'],
  6894. ['DDD DDDo DDDD', '45 45th 045'],
  6895. ['w wo ww', '6 6th 06'],
  6896. ['h hh', '3 03'],
  6897. ['H HH', '15 15'],
  6898. ['m mm', '25 25'],
  6899. ['s ss', '50 50'],
  6900. ['a A', 'pm PM'],
  6901. ['[the] DDDo [day of the year]', 'the 45th day of the year'],
  6902. ['LTS', '3:25:50 PM'],
  6903. ['L', '14/02/2010'],
  6904. ['LL', '14 February 2010'],
  6905. ['LLL', '14 February 2010 3:25 PM'],
  6906. ['LLLL', 'Sunday, 14 February 2010 3:25 PM'],
  6907. ['l', '14/2/2010'],
  6908. ['ll', '14 Feb 2010'],
  6909. ['lll', '14 Feb 2010 3:25 PM'],
  6910. ['llll', 'Sun, 14 Feb 2010 3:25 PM']
  6911. ],
  6912. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  6913. i;
  6914. for (i = 0; i < a.length; i++) {
  6915. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  6916. }
  6917. });
  6918. test('format ordinal', function (assert) {
  6919. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1st', '1st');
  6920. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2nd', '2nd');
  6921. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3rd', '3rd');
  6922. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4th', '4th');
  6923. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5th', '5th');
  6924. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6th', '6th');
  6925. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7th', '7th');
  6926. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8th', '8th');
  6927. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9th', '9th');
  6928. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10th', '10th');
  6929. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11th', '11th');
  6930. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12th', '12th');
  6931. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13th', '13th');
  6932. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14th', '14th');
  6933. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15th', '15th');
  6934. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16th', '16th');
  6935. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17th', '17th');
  6936. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18th', '18th');
  6937. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19th', '19th');
  6938. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20th', '20th');
  6939. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21st', '21st');
  6940. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22nd', '22nd');
  6941. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23rd', '23rd');
  6942. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24th', '24th');
  6943. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25th', '25th');
  6944. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26th', '26th');
  6945. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27th', '27th');
  6946. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28th', '28th');
  6947. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29th', '29th');
  6948. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30th', '30th');
  6949. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31st', '31st');
  6950. });
  6951. test('format month', function (assert) {
  6952. var expected = 'January Jan_February Feb_March Mar_April Apr_May May_June Jun_July Jul_August Aug_September Sep_October Oct_November Nov_December Dec'.split('_'), i;
  6953. for (i = 0; i < expected.length; i++) {
  6954. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  6955. }
  6956. });
  6957. test('format week', function (assert) {
  6958. var expected = 'Sunday Sun Su_Monday Mon Mo_Tuesday Tue Tu_Wednesday Wed We_Thursday Thu Th_Friday Fri Fr_Saturday Sat Sa'.split('_'), i;
  6959. for (i = 0; i < expected.length; i++) {
  6960. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  6961. }
  6962. });
  6963. test('from', function (assert) {
  6964. var start = moment([2007, 1, 28]);
  6965. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'a few seconds', '44 seconds = a few seconds');
  6966. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'a minute', '45 seconds = a minute');
  6967. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'a minute', '89 seconds = a minute');
  6968. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutes', '90 seconds = 2 minutes');
  6969. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutes', '44 minutes = 44 minutes');
  6970. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'an hour', '45 minutes = an hour');
  6971. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'an hour', '89 minutes = an hour');
  6972. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 hours', '90 minutes = 2 hours');
  6973. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 hours', '5 hours = 5 hours');
  6974. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 hours', '21 hours = 21 hours');
  6975. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'a day', '22 hours = a day');
  6976. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'a day', '35 hours = a day');
  6977. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 days', '36 hours = 2 days');
  6978. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'a day', '1 day = a day');
  6979. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 days', '5 days = 5 days');
  6980. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 days', '25 days = 25 days');
  6981. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'a month', '26 days = a month');
  6982. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'a month', '30 days = a month');
  6983. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'a month', '43 days = a month');
  6984. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 months', '46 days = 2 months');
  6985. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 months', '75 days = 2 months');
  6986. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 months', '76 days = 3 months');
  6987. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'a month', '1 month = a month');
  6988. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 months', '5 months = 5 months');
  6989. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'a year', '345 days = a year');
  6990. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 years', '548 days = 2 years');
  6991. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'a year', '1 year = a year');
  6992. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 years', '5 years = 5 years');
  6993. });
  6994. test('suffix', function (assert) {
  6995. assert.equal(moment(30000).from(0), 'in a few seconds', 'prefix');
  6996. assert.equal(moment(0).from(30000), 'a few seconds ago', 'suffix');
  6997. });
  6998. test('now from now', function (assert) {
  6999. assert.equal(moment().fromNow(), 'a few seconds ago', 'now from now should display as in the past');
  7000. });
  7001. test('fromNow', function (assert) {
  7002. assert.equal(moment().add({s: 30}).fromNow(), 'in a few seconds', 'in a few seconds');
  7003. assert.equal(moment().add({d: 5}).fromNow(), 'in 5 days', 'in 5 days');
  7004. });
  7005. test('calendar day', function (assert) {
  7006. var a = moment().hours(2).minutes(0).seconds(0);
  7007. assert.equal(moment(a).calendar(), 'Today at 2:00 AM', 'today at the same time');
  7008. assert.equal(moment(a).add({m: 25}).calendar(), 'Today at 2:25 AM', 'Now plus 25 min');
  7009. assert.equal(moment(a).add({h: 1}).calendar(), 'Today at 3:00 AM', 'Now plus 1 hour');
  7010. assert.equal(moment(a).add({d: 1}).calendar(), 'Tomorrow at 2:00 AM', 'tomorrow at the same time');
  7011. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Today at 1:00 AM', 'Now minus 1 hour');
  7012. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Yesterday at 2:00 AM', 'yesterday at the same time');
  7013. });
  7014. test('calendar next week', function (assert) {
  7015. var i, m;
  7016. for (i = 2; i < 7; i++) {
  7017. m = moment().add({d: i});
  7018. assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days current time');
  7019. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  7020. assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days beginning of day');
  7021. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  7022. assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days end of day');
  7023. }
  7024. });
  7025. test('calendar last week', function (assert) {
  7026. var i, m;
  7027. for (i = 2; i < 7; i++) {
  7028. m = moment().subtract({d: i});
  7029. assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days current time');
  7030. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  7031. assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days beginning of day');
  7032. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  7033. assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days end of day');
  7034. }
  7035. });
  7036. test('calendar all else', function (assert) {
  7037. var weeksAgo = moment().subtract({w: 1}),
  7038. weeksFromNow = moment().add({w: 1});
  7039. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  7040. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  7041. weeksAgo = moment().subtract({w: 2});
  7042. weeksFromNow = moment().add({w: 2});
  7043. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  7044. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  7045. });
  7046. test('weeks year starting sunday', function (assert) {
  7047. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  7048. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  7049. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  7050. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  7051. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  7052. });
  7053. test('weeks year starting monday', function (assert) {
  7054. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  7055. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  7056. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  7057. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  7058. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  7059. });
  7060. test('weeks year starting tuesday', function (assert) {
  7061. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  7062. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  7063. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  7064. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  7065. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  7066. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  7067. });
  7068. test('weeks year starting wednesday', function (assert) {
  7069. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  7070. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  7071. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  7072. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  7073. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  7074. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  7075. });
  7076. test('weeks year starting thursday', function (assert) {
  7077. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  7078. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  7079. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  7080. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  7081. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  7082. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  7083. });
  7084. test('weeks year starting friday', function (assert) {
  7085. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  7086. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  7087. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  7088. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  7089. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  7090. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  7091. });
  7092. test('weeks year starting saturday', function (assert) {
  7093. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  7094. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  7095. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  7096. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  7097. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  7098. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  7099. });
  7100. test('weeks year starting sunday formatted', function (assert) {
  7101. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52nd', 'Jan 1 2012 should be week 52');
  7102. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1st', 'Jan 2 2012 should be week 1');
  7103. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1st', 'Jan 8 2012 should be week 1');
  7104. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2nd', 'Jan 9 2012 should be week 2');
  7105. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2nd', 'Jan 15 2012 should be week 2');
  7106. });
  7107. test('lenient ordinal parsing', function (assert) {
  7108. var i, ordinalStr, testStr;
  7109. for (i = 1; i <= 31; ++i) {
  7110. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  7111. testStr = moment(ordinalStr, 'YYYY MM Do').format('YYYY MM D');
  7112. assert.equal(testStr, '2014 01 ' + i, 'lenient ordinal parsing ' + i);
  7113. }
  7114. });
  7115. test('lenient ordinal parsing of number', function (assert) {
  7116. var i, testStr;
  7117. for (i = 1; i <= 31; ++i) {
  7118. testStr = moment('2014 01 ' + i, 'YYYY MM Do').format('YYYY MM D');
  7119. assert.equal(testStr, '2014 01 ' + i,
  7120. 'lenient ordinal parsing of number ' + i);
  7121. }
  7122. });
  7123. test('strict ordinal parsing', function (assert) {
  7124. var i, ordinalStr, testMoment;
  7125. for (i = 1; i <= 31; ++i) {
  7126. ordinalStr = moment([2014, 0, i]).format('YYYY MMM Do');
  7127. testMoment = moment(ordinalStr, 'YYYY MMM Do', true);
  7128. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  7129. }
  7130. });
  7131. }));
  7132. ;(function (global, factory) {
  7133. typeof exports === 'object' && typeof module !== 'undefined'
  7134. && typeof require === 'function' ? factory(require('../../moment')) :
  7135. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  7136. factory(global.moment)
  7137. }(this, function (moment) { 'use strict';
  7138. /*global QUnit:false*/
  7139. var test = QUnit.test;
  7140. var expect = QUnit.expect;
  7141. function module (name, lifecycle) {
  7142. QUnit.module(name, {
  7143. setup : function () {
  7144. moment.locale('en');
  7145. moment.createFromInputFallback = function (config) {
  7146. throw new Error('input not handled by moment: ' + config._i);
  7147. };
  7148. if (lifecycle && lifecycle.setup) {
  7149. lifecycle.setup();
  7150. }
  7151. },
  7152. teardown : function () {
  7153. if (lifecycle && lifecycle.teardown) {
  7154. lifecycle.teardown();
  7155. }
  7156. }
  7157. });
  7158. }
  7159. function localeModule (name, lifecycle) {
  7160. QUnit.module('locale:' + name, {
  7161. setup : function () {
  7162. moment.locale(name);
  7163. moment.createFromInputFallback = function (config) {
  7164. throw new Error('input not handled by moment: ' + config._i);
  7165. };
  7166. if (lifecycle && lifecycle.setup) {
  7167. lifecycle.setup();
  7168. }
  7169. },
  7170. teardown : function () {
  7171. moment.locale('en');
  7172. if (lifecycle && lifecycle.teardown) {
  7173. lifecycle.teardown();
  7174. }
  7175. }
  7176. });
  7177. }
  7178. localeModule('en-ca');
  7179. test('parse', function (assert) {
  7180. var i,
  7181. tests = 'January Jan_February Feb_March Mar_April Apr_May May_June Jun_July Jul_August Aug_September Sep_October Oct_November Nov_December Dec'.split('_');
  7182. function equalTest(input, mmm, i) {
  7183. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  7184. }
  7185. for (i = 0; i < 12; i++) {
  7186. tests[i] = tests[i].split(' ');
  7187. equalTest(tests[i][0], 'MMM', i);
  7188. equalTest(tests[i][1], 'MMM', i);
  7189. equalTest(tests[i][0], 'MMMM', i);
  7190. equalTest(tests[i][1], 'MMMM', i);
  7191. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  7192. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  7193. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  7194. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  7195. }
  7196. });
  7197. test('format', function (assert) {
  7198. var a = [
  7199. ['dddd, MMMM Do YYYY, h:mm:ss a', 'Sunday, February 14th 2010, 3:25:50 pm'],
  7200. ['ddd, hA', 'Sun, 3PM'],
  7201. ['M Mo MM MMMM MMM', '2 2nd 02 February Feb'],
  7202. ['YYYY YY', '2010 10'],
  7203. ['D Do DD', '14 14th 14'],
  7204. ['d do dddd ddd dd', '0 0th Sunday Sun Su'],
  7205. ['DDD DDDo DDDD', '45 45th 045'],
  7206. ['w wo ww', '8 8th 08'],
  7207. ['h hh', '3 03'],
  7208. ['H HH', '15 15'],
  7209. ['m mm', '25 25'],
  7210. ['s ss', '50 50'],
  7211. ['a A', 'pm PM'],
  7212. ['[the] DDDo [day of the year]', 'the 45th day of the year'],
  7213. ['L', '2010-02-14'],
  7214. ['LTS', '3:25:50 PM'],
  7215. ['LL', '14 February, 2010'],
  7216. ['LLL', '14 February, 2010 3:25 PM'],
  7217. ['LLLL', 'Sunday, 14 February, 2010 3:25 PM'],
  7218. ['l', '2010-2-14'],
  7219. ['ll', '14 Feb, 2010'],
  7220. ['lll', '14 Feb, 2010 3:25 PM'],
  7221. ['llll', 'Sun, 14 Feb, 2010 3:25 PM']
  7222. ],
  7223. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  7224. i;
  7225. for (i = 0; i < a.length; i++) {
  7226. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  7227. }
  7228. });
  7229. test('format ordinal', function (assert) {
  7230. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1st', '1st');
  7231. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2nd', '2nd');
  7232. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3rd', '3rd');
  7233. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4th', '4th');
  7234. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5th', '5th');
  7235. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6th', '6th');
  7236. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7th', '7th');
  7237. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8th', '8th');
  7238. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9th', '9th');
  7239. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10th', '10th');
  7240. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11th', '11th');
  7241. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12th', '12th');
  7242. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13th', '13th');
  7243. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14th', '14th');
  7244. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15th', '15th');
  7245. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16th', '16th');
  7246. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17th', '17th');
  7247. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18th', '18th');
  7248. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19th', '19th');
  7249. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20th', '20th');
  7250. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21st', '21st');
  7251. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22nd', '22nd');
  7252. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23rd', '23rd');
  7253. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24th', '24th');
  7254. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25th', '25th');
  7255. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26th', '26th');
  7256. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27th', '27th');
  7257. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28th', '28th');
  7258. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29th', '29th');
  7259. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30th', '30th');
  7260. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31st', '31st');
  7261. });
  7262. test('format month', function (assert) {
  7263. var i,
  7264. expected = 'January Jan_February Feb_March Mar_April Apr_May May_June Jun_July Jul_August Aug_September Sep_October Oct_November Nov_December Dec'.split('_');
  7265. for (i = 0; i < expected.length; i++) {
  7266. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  7267. }
  7268. });
  7269. test('format week', function (assert) {
  7270. var i,
  7271. expected = 'Sunday Sun Su_Monday Mon Mo_Tuesday Tue Tu_Wednesday Wed We_Thursday Thu Th_Friday Fri Fr_Saturday Sat Sa'.split('_');
  7272. for (i = 0; i < expected.length; i++) {
  7273. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  7274. }
  7275. });
  7276. test('from', function (assert) {
  7277. var start = moment([2007, 1, 28]);
  7278. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'a few seconds', '44 seconds = a few seconds');
  7279. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'a minute', '45 seconds = a minute');
  7280. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'a minute', '89 seconds = a minute');
  7281. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutes', '90 seconds = 2 minutes');
  7282. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutes', '44 minutes = 44 minutes');
  7283. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'an hour', '45 minutes = an hour');
  7284. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'an hour', '89 minutes = an hour');
  7285. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 hours', '90 minutes = 2 hours');
  7286. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 hours', '5 hours = 5 hours');
  7287. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 hours', '21 hours = 21 hours');
  7288. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'a day', '22 hours = a day');
  7289. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'a day', '35 hours = a day');
  7290. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 days', '36 hours = 2 days');
  7291. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'a day', '1 day = a day');
  7292. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 days', '5 days = 5 days');
  7293. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 days', '25 days = 25 days');
  7294. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'a month', '26 days = a month');
  7295. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'a month', '30 days = a month');
  7296. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'a month', '43 days = a month');
  7297. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 months', '46 days = 2 months');
  7298. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 months', '75 days = 2 months');
  7299. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 months', '76 days = 3 months');
  7300. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'a month', '1 month = a month');
  7301. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 months', '5 months = 5 months');
  7302. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'a year', '345 days = a year');
  7303. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 years', '548 days = 2 years');
  7304. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'a year', '1 year = a year');
  7305. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 years', '5 years = 5 years');
  7306. });
  7307. test('suffix', function (assert) {
  7308. assert.equal(moment(30000).from(0), 'in a few seconds', 'prefix');
  7309. assert.equal(moment(0).from(30000), 'a few seconds ago', 'suffix');
  7310. });
  7311. test('now from now', function (assert) {
  7312. assert.equal(moment().fromNow(), 'a few seconds ago', 'now from now should display as in the past');
  7313. });
  7314. test('fromNow', function (assert) {
  7315. assert.equal(moment().add({s: 30}).fromNow(), 'in a few seconds', 'in a few seconds');
  7316. assert.equal(moment().add({d: 5}).fromNow(), 'in 5 days', 'in 5 days');
  7317. });
  7318. test('calendar day', function (assert) {
  7319. var a = moment().hours(2).minutes(0).seconds(0);
  7320. assert.equal(moment(a).calendar(), 'Today at 2:00 AM', 'today at the same time');
  7321. assert.equal(moment(a).add({m: 25}).calendar(), 'Today at 2:25 AM', 'Now plus 25 min');
  7322. assert.equal(moment(a).add({h: 1}).calendar(), 'Today at 3:00 AM', 'Now plus 1 hour');
  7323. assert.equal(moment(a).add({d: 1}).calendar(), 'Tomorrow at 2:00 AM', 'tomorrow at the same time');
  7324. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Today at 1:00 AM', 'Now minus 1 hour');
  7325. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Yesterday at 2:00 AM', 'yesterday at the same time');
  7326. });
  7327. test('calendar next week', function (assert) {
  7328. var i, m;
  7329. for (i = 2; i < 7; i++) {
  7330. m = moment().add({d: i});
  7331. assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days current time');
  7332. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  7333. assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days beginning of day');
  7334. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  7335. assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days end of day');
  7336. }
  7337. });
  7338. test('calendar last week', function (assert) {
  7339. var i, m;
  7340. for (i = 2; i < 7; i++) {
  7341. m = moment().subtract({d: i});
  7342. assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days current time');
  7343. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  7344. assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days beginning of day');
  7345. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  7346. assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days end of day');
  7347. }
  7348. });
  7349. test('calendar all else', function (assert) {
  7350. var weeksAgo = moment().subtract({w: 1}),
  7351. weeksFromNow = moment().add({w: 1});
  7352. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  7353. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  7354. weeksAgo = moment().subtract({w: 2});
  7355. weeksFromNow = moment().add({w: 2});
  7356. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  7357. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  7358. });
  7359. test('weeks year starting sunday', function (assert) {
  7360. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  7361. assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1');
  7362. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  7363. assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2');
  7364. assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 3');
  7365. });
  7366. test('weeks year starting monday', function (assert) {
  7367. assert.equal(moment([2006, 11, 31]).week(), 1, 'Dec 31 2006 should be week 1');
  7368. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  7369. assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1');
  7370. assert.equal(moment([2007, 0, 7]).week(), 2, 'Jan 7 2007 should be week 2');
  7371. assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2');
  7372. assert.equal(moment([2007, 0, 14]).week(), 3, 'Jan 14 2007 should be week 3');
  7373. });
  7374. test('weeks year starting tuesday', function (assert) {
  7375. assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52');
  7376. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  7377. assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1');
  7378. assert.equal(moment([2008, 0, 6]).week(), 2, 'Jan 6 2008 should be week 2');
  7379. assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2');
  7380. assert.equal(moment([2008, 0, 13]).week(), 3, 'Jan 13 2008 should be week 3');
  7381. });
  7382. test('weeks year starting wednesday', function (assert) {
  7383. assert.equal(moment([2002, 11, 29]).week(), 1, 'Dec 29 2002 should be week 1');
  7384. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  7385. assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1');
  7386. assert.equal(moment([2003, 0, 5]).week(), 2, 'Jan 5 2003 should be week 2');
  7387. assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2');
  7388. assert.equal(moment([2003, 0, 12]).week(), 3, 'Jan 12 2003 should be week 3');
  7389. });
  7390. test('weeks year starting thursday', function (assert) {
  7391. assert.equal(moment([2008, 11, 28]).week(), 1, 'Dec 28 2008 should be week 1');
  7392. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  7393. assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1');
  7394. assert.equal(moment([2009, 0, 4]).week(), 2, 'Jan 4 2009 should be week 2');
  7395. assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2');
  7396. assert.equal(moment([2009, 0, 11]).week(), 3, 'Jan 11 2009 should be week 3');
  7397. });
  7398. test('weeks year starting friday', function (assert) {
  7399. assert.equal(moment([2009, 11, 27]).week(), 1, 'Dec 27 2009 should be week 1');
  7400. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  7401. assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 should be week 1');
  7402. assert.equal(moment([2010, 0, 3]).week(), 2, 'Jan 3 2010 should be week 2');
  7403. assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 should be week 2');
  7404. assert.equal(moment([2010, 0, 10]).week(), 3, 'Jan 10 2010 should be week 3');
  7405. });
  7406. test('weeks year starting saturday', function (assert) {
  7407. assert.equal(moment([2010, 11, 26]).week(), 1, 'Dec 26 2010 should be week 1');
  7408. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  7409. assert.equal(moment([2011, 0, 2]).week(), 2, 'Jan 2 2011 should be week 2');
  7410. assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2');
  7411. assert.equal(moment([2011, 0, 9]).week(), 3, 'Jan 9 2011 should be week 3');
  7412. });
  7413. test('weeks year starting sunday format', function (assert) {
  7414. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1st', 'Jan 1 2012 should be week 1');
  7415. assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1st', 'Jan 7 2012 should be week 1');
  7416. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2nd', 'Jan 8 2012 should be week 2');
  7417. assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2nd', 'Jan 14 2012 should be week 2');
  7418. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3rd', 'Jan 15 2012 should be week 3');
  7419. });
  7420. test('lenient ordinal parsing', function (assert) {
  7421. var i, ordinalStr, testMoment;
  7422. for (i = 1; i <= 31; ++i) {
  7423. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  7424. testMoment = moment(ordinalStr, 'YYYY MM Do');
  7425. assert.equal(testMoment.year(), 2014,
  7426. 'lenient ordinal parsing ' + i + ' year check');
  7427. assert.equal(testMoment.month(), 0,
  7428. 'lenient ordinal parsing ' + i + ' month check');
  7429. assert.equal(testMoment.date(), i,
  7430. 'lenient ordinal parsing ' + i + ' date check');
  7431. }
  7432. });
  7433. test('lenient ordinal parsing of number', function (assert) {
  7434. var i, testMoment;
  7435. for (i = 1; i <= 31; ++i) {
  7436. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  7437. assert.equal(testMoment.year(), 2014,
  7438. 'lenient ordinal parsing of number ' + i + ' year check');
  7439. assert.equal(testMoment.month(), 0,
  7440. 'lenient ordinal parsing of number ' + i + ' month check');
  7441. assert.equal(testMoment.date(), i,
  7442. 'lenient ordinal parsing of number ' + i + ' date check');
  7443. }
  7444. });
  7445. test('strict ordinal parsing', function (assert) {
  7446. var i, ordinalStr, testMoment;
  7447. for (i = 1; i <= 31; ++i) {
  7448. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  7449. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  7450. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  7451. }
  7452. });
  7453. }));
  7454. ;(function (global, factory) {
  7455. typeof exports === 'object' && typeof module !== 'undefined'
  7456. && typeof require === 'function' ? factory(require('../../moment')) :
  7457. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  7458. factory(global.moment)
  7459. }(this, function (moment) { 'use strict';
  7460. /*global QUnit:false*/
  7461. var test = QUnit.test;
  7462. var expect = QUnit.expect;
  7463. function module (name, lifecycle) {
  7464. QUnit.module(name, {
  7465. setup : function () {
  7466. moment.locale('en');
  7467. moment.createFromInputFallback = function (config) {
  7468. throw new Error('input not handled by moment: ' + config._i);
  7469. };
  7470. if (lifecycle && lifecycle.setup) {
  7471. lifecycle.setup();
  7472. }
  7473. },
  7474. teardown : function () {
  7475. if (lifecycle && lifecycle.teardown) {
  7476. lifecycle.teardown();
  7477. }
  7478. }
  7479. });
  7480. }
  7481. function localeModule (name, lifecycle) {
  7482. QUnit.module('locale:' + name, {
  7483. setup : function () {
  7484. moment.locale(name);
  7485. moment.createFromInputFallback = function (config) {
  7486. throw new Error('input not handled by moment: ' + config._i);
  7487. };
  7488. if (lifecycle && lifecycle.setup) {
  7489. lifecycle.setup();
  7490. }
  7491. },
  7492. teardown : function () {
  7493. moment.locale('en');
  7494. if (lifecycle && lifecycle.teardown) {
  7495. lifecycle.teardown();
  7496. }
  7497. }
  7498. });
  7499. }
  7500. localeModule('en-gb');
  7501. test('parse', function (assert) {
  7502. var tests = 'January Jan_February Feb_March Mar_April Apr_May May_June Jun_July Jul_August Aug_September Sep_October Oct_November Nov_December Dec'.split('_'), i;
  7503. function equalTest(input, mmm, i) {
  7504. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  7505. }
  7506. for (i = 0; i < 12; i++) {
  7507. tests[i] = tests[i].split(' ');
  7508. equalTest(tests[i][0], 'MMM', i);
  7509. equalTest(tests[i][1], 'MMM', i);
  7510. equalTest(tests[i][0], 'MMMM', i);
  7511. equalTest(tests[i][1], 'MMMM', i);
  7512. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  7513. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  7514. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  7515. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  7516. }
  7517. });
  7518. test('format', function (assert) {
  7519. var a = [
  7520. ['dddd, MMMM Do YYYY, h:mm:ss a', 'Sunday, February 14th 2010, 3:25:50 pm'],
  7521. ['ddd, hA', 'Sun, 3PM'],
  7522. ['M Mo MM MMMM MMM', '2 2nd 02 February Feb'],
  7523. ['YYYY YY', '2010 10'],
  7524. ['D Do DD', '14 14th 14'],
  7525. ['d do dddd ddd dd', '0 0th Sunday Sun Su'],
  7526. ['DDD DDDo DDDD', '45 45th 045'],
  7527. ['w wo ww', '6 6th 06'],
  7528. ['h hh', '3 03'],
  7529. ['H HH', '15 15'],
  7530. ['m mm', '25 25'],
  7531. ['s ss', '50 50'],
  7532. ['a A', 'pm PM'],
  7533. ['[the] DDDo [day of the year]', 'the 45th day of the year'],
  7534. ['LTS', '15:25:50'],
  7535. ['L', '14/02/2010'],
  7536. ['LL', '14 February 2010'],
  7537. ['LLL', '14 February 2010 15:25'],
  7538. ['LLLL', 'Sunday, 14 February 2010 15:25'],
  7539. ['l', '14/2/2010'],
  7540. ['ll', '14 Feb 2010'],
  7541. ['lll', '14 Feb 2010 15:25'],
  7542. ['llll', 'Sun, 14 Feb 2010 15:25']
  7543. ],
  7544. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  7545. i;
  7546. for (i = 0; i < a.length; i++) {
  7547. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  7548. }
  7549. });
  7550. test('format ordinal', function (assert) {
  7551. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1st', '1st');
  7552. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2nd', '2nd');
  7553. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3rd', '3rd');
  7554. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4th', '4th');
  7555. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5th', '5th');
  7556. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6th', '6th');
  7557. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7th', '7th');
  7558. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8th', '8th');
  7559. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9th', '9th');
  7560. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10th', '10th');
  7561. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11th', '11th');
  7562. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12th', '12th');
  7563. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13th', '13th');
  7564. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14th', '14th');
  7565. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15th', '15th');
  7566. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16th', '16th');
  7567. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17th', '17th');
  7568. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18th', '18th');
  7569. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19th', '19th');
  7570. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20th', '20th');
  7571. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21st', '21st');
  7572. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22nd', '22nd');
  7573. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23rd', '23rd');
  7574. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24th', '24th');
  7575. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25th', '25th');
  7576. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26th', '26th');
  7577. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27th', '27th');
  7578. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28th', '28th');
  7579. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29th', '29th');
  7580. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30th', '30th');
  7581. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31st', '31st');
  7582. });
  7583. test('format month', function (assert) {
  7584. var expected = 'January Jan_February Feb_March Mar_April Apr_May May_June Jun_July Jul_August Aug_September Sep_October Oct_November Nov_December Dec'.split('_'), i;
  7585. for (i = 0; i < expected.length; i++) {
  7586. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  7587. }
  7588. });
  7589. test('format week', function (assert) {
  7590. var expected = 'Sunday Sun Su_Monday Mon Mo_Tuesday Tue Tu_Wednesday Wed We_Thursday Thu Th_Friday Fri Fr_Saturday Sat Sa'.split('_'), i;
  7591. for (i = 0; i < expected.length; i++) {
  7592. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  7593. }
  7594. });
  7595. test('from', function (assert) {
  7596. var start = moment([2007, 1, 28]);
  7597. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'a few seconds', '44 seconds = a few seconds');
  7598. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'a minute', '45 seconds = a minute');
  7599. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'a minute', '89 seconds = a minute');
  7600. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutes', '90 seconds = 2 minutes');
  7601. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutes', '44 minutes = 44 minutes');
  7602. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'an hour', '45 minutes = an hour');
  7603. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'an hour', '89 minutes = an hour');
  7604. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 hours', '90 minutes = 2 hours');
  7605. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 hours', '5 hours = 5 hours');
  7606. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 hours', '21 hours = 21 hours');
  7607. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'a day', '22 hours = a day');
  7608. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'a day', '35 hours = a day');
  7609. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 days', '36 hours = 2 days');
  7610. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'a day', '1 day = a day');
  7611. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 days', '5 days = 5 days');
  7612. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 days', '25 days = 25 days');
  7613. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'a month', '26 days = a month');
  7614. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'a month', '30 days = a month');
  7615. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'a month', '43 days = a month');
  7616. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 months', '46 days = 2 months');
  7617. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 months', '75 days = 2 months');
  7618. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 months', '76 days = 3 months');
  7619. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'a month', '1 month = a month');
  7620. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 months', '5 months = 5 months');
  7621. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'a year', '345 days = a year');
  7622. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 years', '548 days = 2 years');
  7623. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'a year', '1 year = a year');
  7624. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 years', '5 years = 5 years');
  7625. });
  7626. test('suffix', function (assert) {
  7627. assert.equal(moment(30000).from(0), 'in a few seconds', 'prefix');
  7628. assert.equal(moment(0).from(30000), 'a few seconds ago', 'suffix');
  7629. });
  7630. test('now from now', function (assert) {
  7631. assert.equal(moment().fromNow(), 'a few seconds ago', 'now from now should display as in the past');
  7632. });
  7633. test('fromNow', function (assert) {
  7634. assert.equal(moment().add({s: 30}).fromNow(), 'in a few seconds', 'in a few seconds');
  7635. assert.equal(moment().add({d: 5}).fromNow(), 'in 5 days', 'in 5 days');
  7636. });
  7637. test('calendar day', function (assert) {
  7638. var a = moment().hours(2).minutes(0).seconds(0);
  7639. assert.equal(moment(a).calendar(), 'Today at 02:00', 'today at the same time');
  7640. assert.equal(moment(a).add({m: 25}).calendar(), 'Today at 02:25', 'Now plus 25 min');
  7641. assert.equal(moment(a).add({h: 1}).calendar(), 'Today at 03:00', 'Now plus 1 hour');
  7642. assert.equal(moment(a).add({d: 1}).calendar(), 'Tomorrow at 02:00', 'tomorrow at the same time');
  7643. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Today at 01:00', 'Now minus 1 hour');
  7644. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Yesterday at 02:00', 'yesterday at the same time');
  7645. });
  7646. test('calendar next week', function (assert) {
  7647. var i, m;
  7648. for (i = 2; i < 7; i++) {
  7649. m = moment().add({d: i});
  7650. assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days current time');
  7651. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  7652. assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days beginning of day');
  7653. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  7654. assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days end of day');
  7655. }
  7656. });
  7657. test('calendar last week', function (assert) {
  7658. var i, m;
  7659. for (i = 2; i < 7; i++) {
  7660. m = moment().subtract({d: i});
  7661. assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days current time');
  7662. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  7663. assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days beginning of day');
  7664. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  7665. assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days end of day');
  7666. }
  7667. });
  7668. test('calendar all else', function (assert) {
  7669. var weeksAgo = moment().subtract({w: 1}),
  7670. weeksFromNow = moment().add({w: 1});
  7671. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  7672. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  7673. weeksAgo = moment().subtract({w: 2});
  7674. weeksFromNow = moment().add({w: 2});
  7675. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  7676. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  7677. });
  7678. test('weeks year starting sunday', function (assert) {
  7679. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  7680. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  7681. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  7682. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  7683. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  7684. });
  7685. test('weeks year starting monday', function (assert) {
  7686. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  7687. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  7688. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  7689. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  7690. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  7691. });
  7692. test('weeks year starting tuesday', function (assert) {
  7693. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  7694. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  7695. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  7696. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  7697. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  7698. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  7699. });
  7700. test('weeks year starting wednesday', function (assert) {
  7701. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  7702. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  7703. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  7704. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  7705. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  7706. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  7707. });
  7708. test('weeks year starting thursday', function (assert) {
  7709. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  7710. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  7711. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  7712. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  7713. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  7714. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  7715. });
  7716. test('weeks year starting friday', function (assert) {
  7717. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  7718. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  7719. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  7720. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  7721. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  7722. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  7723. });
  7724. test('weeks year starting saturday', function (assert) {
  7725. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  7726. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  7727. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  7728. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  7729. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  7730. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  7731. });
  7732. test('weeks year starting sunday formatted', function (assert) {
  7733. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52nd', 'Jan 1 2012 should be week 52');
  7734. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1st', 'Jan 2 2012 should be week 1');
  7735. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1st', 'Jan 8 2012 should be week 1');
  7736. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2nd', 'Jan 9 2012 should be week 2');
  7737. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2nd', 'Jan 15 2012 should be week 2');
  7738. });
  7739. test('lenient ordinal parsing', function (assert) {
  7740. var i, ordinalStr, testMoment;
  7741. for (i = 1; i <= 31; ++i) {
  7742. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  7743. testMoment = moment(ordinalStr, 'YYYY MM Do');
  7744. assert.equal(testMoment.year(), 2014,
  7745. 'lenient ordinal parsing ' + i + ' year check');
  7746. assert.equal(testMoment.month(), 0,
  7747. 'lenient ordinal parsing ' + i + ' month check');
  7748. assert.equal(testMoment.date(), i,
  7749. 'lenient ordinal parsing ' + i + ' date check');
  7750. }
  7751. });
  7752. test('lenient ordinal parsing of number', function (assert) {
  7753. var i, testMoment;
  7754. for (i = 1; i <= 31; ++i) {
  7755. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  7756. assert.equal(testMoment.year(), 2014,
  7757. 'lenient ordinal parsing of number ' + i + ' year check');
  7758. assert.equal(testMoment.month(), 0,
  7759. 'lenient ordinal parsing of number ' + i + ' month check');
  7760. assert.equal(testMoment.date(), i,
  7761. 'lenient ordinal parsing of number ' + i + ' date check');
  7762. }
  7763. });
  7764. test('strict ordinal parsing', function (assert) {
  7765. var i, ordinalStr, testMoment;
  7766. for (i = 1; i <= 31; ++i) {
  7767. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  7768. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  7769. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  7770. }
  7771. });
  7772. }));
  7773. ;(function (global, factory) {
  7774. typeof exports === 'object' && typeof module !== 'undefined'
  7775. && typeof require === 'function' ? factory(require('../../moment')) :
  7776. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  7777. factory(global.moment)
  7778. }(this, function (moment) { 'use strict';
  7779. /*global QUnit:false*/
  7780. var test = QUnit.test;
  7781. var expect = QUnit.expect;
  7782. function module (name, lifecycle) {
  7783. QUnit.module(name, {
  7784. setup : function () {
  7785. moment.locale('en');
  7786. moment.createFromInputFallback = function (config) {
  7787. throw new Error('input not handled by moment: ' + config._i);
  7788. };
  7789. if (lifecycle && lifecycle.setup) {
  7790. lifecycle.setup();
  7791. }
  7792. },
  7793. teardown : function () {
  7794. if (lifecycle && lifecycle.teardown) {
  7795. lifecycle.teardown();
  7796. }
  7797. }
  7798. });
  7799. }
  7800. function localeModule (name, lifecycle) {
  7801. QUnit.module('locale:' + name, {
  7802. setup : function () {
  7803. moment.locale(name);
  7804. moment.createFromInputFallback = function (config) {
  7805. throw new Error('input not handled by moment: ' + config._i);
  7806. };
  7807. if (lifecycle && lifecycle.setup) {
  7808. lifecycle.setup();
  7809. }
  7810. },
  7811. teardown : function () {
  7812. moment.locale('en');
  7813. if (lifecycle && lifecycle.teardown) {
  7814. lifecycle.teardown();
  7815. }
  7816. }
  7817. });
  7818. }
  7819. localeModule('en-ie');
  7820. test('parse', function (assert) {
  7821. var tests = 'January Jan_February Feb_March Mar_April Apr_May May_June Jun_July Jul_August Aug_September Sep_October Oct_November Nov_December Dec'.split('_'), i;
  7822. function equalTest(input, mmm, i) {
  7823. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  7824. }
  7825. for (i = 0; i < 12; i++) {
  7826. tests[i] = tests[i].split(' ');
  7827. equalTest(tests[i][0], 'MMM', i);
  7828. equalTest(tests[i][1], 'MMM', i);
  7829. equalTest(tests[i][0], 'MMMM', i);
  7830. equalTest(tests[i][1], 'MMMM', i);
  7831. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  7832. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  7833. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  7834. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  7835. }
  7836. });
  7837. test('format', function (assert) {
  7838. var a = [
  7839. ['dddd, MMMM Do YYYY, h:mm:ss a', 'Sunday, February 14th 2010, 3:25:50 pm'],
  7840. ['ddd, hA', 'Sun, 3PM'],
  7841. ['M Mo MM MMMM MMM', '2 2nd 02 February Feb'],
  7842. ['YYYY YY', '2010 10'],
  7843. ['D Do DD', '14 14th 14'],
  7844. ['d do dddd ddd dd', '0 0th Sunday Sun Su'],
  7845. ['DDD DDDo DDDD', '45 45th 045'],
  7846. ['w wo ww', '6 6th 06'],
  7847. ['h hh', '3 03'],
  7848. ['H HH', '15 15'],
  7849. ['m mm', '25 25'],
  7850. ['s ss', '50 50'],
  7851. ['a A', 'pm PM'],
  7852. ['[the] DDDo [day of the year]', 'the 45th day of the year'],
  7853. ['LTS', '15:25:50'],
  7854. ['L', '14-02-2010'],
  7855. ['LL', '14 February 2010'],
  7856. ['LLL', '14 February 2010 15:25'],
  7857. ['LLLL', 'Sunday 14 February 2010 15:25'],
  7858. ['l', '14-2-2010'],
  7859. ['ll', '14 Feb 2010'],
  7860. ['lll', '14 Feb 2010 15:25'],
  7861. ['llll', 'Sun 14 Feb 2010 15:25']
  7862. ],
  7863. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  7864. i;
  7865. for (i = 0; i < a.length; i++) {
  7866. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  7867. }
  7868. });
  7869. test('format ordinal', function (assert) {
  7870. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1st', '1st');
  7871. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2nd', '2nd');
  7872. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3rd', '3rd');
  7873. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4th', '4th');
  7874. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5th', '5th');
  7875. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6th', '6th');
  7876. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7th', '7th');
  7877. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8th', '8th');
  7878. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9th', '9th');
  7879. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10th', '10th');
  7880. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11th', '11th');
  7881. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12th', '12th');
  7882. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13th', '13th');
  7883. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14th', '14th');
  7884. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15th', '15th');
  7885. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16th', '16th');
  7886. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17th', '17th');
  7887. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18th', '18th');
  7888. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19th', '19th');
  7889. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20th', '20th');
  7890. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21st', '21st');
  7891. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22nd', '22nd');
  7892. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23rd', '23rd');
  7893. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24th', '24th');
  7894. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25th', '25th');
  7895. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26th', '26th');
  7896. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27th', '27th');
  7897. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28th', '28th');
  7898. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29th', '29th');
  7899. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30th', '30th');
  7900. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31st', '31st');
  7901. });
  7902. test('format month', function (assert) {
  7903. var expected = 'January Jan_February Feb_March Mar_April Apr_May May_June Jun_July Jul_August Aug_September Sep_October Oct_November Nov_December Dec'.split('_'), i;
  7904. for (i = 0; i < expected.length; i++) {
  7905. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  7906. }
  7907. });
  7908. test('format week', function (assert) {
  7909. var expected = 'Sunday Sun Su_Monday Mon Mo_Tuesday Tue Tu_Wednesday Wed We_Thursday Thu Th_Friday Fri Fr_Saturday Sat Sa'.split('_'), i;
  7910. for (i = 0; i < expected.length; i++) {
  7911. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  7912. }
  7913. });
  7914. test('from', function (assert) {
  7915. var start = moment([2007, 1, 28]);
  7916. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'a few seconds', '44 seconds = a few seconds');
  7917. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'a minute', '45 seconds = a minute');
  7918. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'a minute', '89 seconds = a minute');
  7919. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutes', '90 seconds = 2 minutes');
  7920. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutes', '44 minutes = 44 minutes');
  7921. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'an hour', '45 minutes = an hour');
  7922. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'an hour', '89 minutes = an hour');
  7923. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 hours', '90 minutes = 2 hours');
  7924. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 hours', '5 hours = 5 hours');
  7925. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 hours', '21 hours = 21 hours');
  7926. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'a day', '22 hours = a day');
  7927. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'a day', '35 hours = a day');
  7928. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 days', '36 hours = 2 days');
  7929. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'a day', '1 day = a day');
  7930. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 days', '5 days = 5 days');
  7931. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 days', '25 days = 25 days');
  7932. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'a month', '26 days = a month');
  7933. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'a month', '30 days = a month');
  7934. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'a month', '43 days = a month');
  7935. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 months', '46 days = 2 months');
  7936. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 months', '75 days = 2 months');
  7937. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 months', '76 days = 3 months');
  7938. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'a month', '1 month = a month');
  7939. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 months', '5 months = 5 months');
  7940. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'a year', '345 days = a year');
  7941. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 years', '548 days = 2 years');
  7942. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'a year', '1 year = a year');
  7943. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 years', '5 years = 5 years');
  7944. });
  7945. test('suffix', function (assert) {
  7946. assert.equal(moment(30000).from(0), 'in a few seconds', 'prefix');
  7947. assert.equal(moment(0).from(30000), 'a few seconds ago', 'suffix');
  7948. });
  7949. test('now from now', function (assert) {
  7950. assert.equal(moment().fromNow(), 'a few seconds ago', 'now from now should display as in the past');
  7951. });
  7952. test('fromNow', function (assert) {
  7953. assert.equal(moment().add({s: 30}).fromNow(), 'in a few seconds', 'in a few seconds');
  7954. assert.equal(moment().add({d: 5}).fromNow(), 'in 5 days', 'in 5 days');
  7955. });
  7956. test('calendar day', function (assert) {
  7957. var a = moment().hours(2).minutes(0).seconds(0);
  7958. assert.equal(moment(a).calendar(), 'Today at 02:00', 'today at the same time');
  7959. assert.equal(moment(a).add({m: 25}).calendar(), 'Today at 02:25', 'Now plus 25 min');
  7960. assert.equal(moment(a).add({h: 1}).calendar(), 'Today at 03:00', 'Now plus 1 hour');
  7961. assert.equal(moment(a).add({d: 1}).calendar(), 'Tomorrow at 02:00', 'tomorrow at the same time');
  7962. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Today at 01:00', 'Now minus 1 hour');
  7963. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Yesterday at 02:00', 'yesterday at the same time');
  7964. });
  7965. test('calendar next week', function (assert) {
  7966. var i, m;
  7967. for (i = 2; i < 7; i++) {
  7968. m = moment().add({d: i});
  7969. assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days current time');
  7970. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  7971. assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days beginning of day');
  7972. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  7973. assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days end of day');
  7974. }
  7975. });
  7976. test('calendar last week', function (assert) {
  7977. var i, m;
  7978. for (i = 2; i < 7; i++) {
  7979. m = moment().subtract({d: i});
  7980. assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days current time');
  7981. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  7982. assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days beginning of day');
  7983. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  7984. assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days end of day');
  7985. }
  7986. });
  7987. test('calendar all else', function (assert) {
  7988. var weeksAgo = moment().subtract({w: 1}),
  7989. weeksFromNow = moment().add({w: 1});
  7990. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  7991. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  7992. weeksAgo = moment().subtract({w: 2});
  7993. weeksFromNow = moment().add({w: 2});
  7994. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  7995. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  7996. });
  7997. test('weeks year starting sunday', function (assert) {
  7998. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  7999. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  8000. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  8001. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  8002. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  8003. });
  8004. test('weeks year starting monday', function (assert) {
  8005. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  8006. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  8007. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  8008. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  8009. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  8010. });
  8011. test('weeks year starting tuesday', function (assert) {
  8012. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  8013. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  8014. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  8015. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  8016. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  8017. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  8018. });
  8019. test('weeks year starting wednesday', function (assert) {
  8020. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  8021. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  8022. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  8023. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  8024. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  8025. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  8026. });
  8027. test('weeks year starting thursday', function (assert) {
  8028. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  8029. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  8030. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  8031. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  8032. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  8033. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  8034. });
  8035. test('weeks year starting friday', function (assert) {
  8036. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  8037. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  8038. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  8039. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  8040. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  8041. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  8042. });
  8043. test('weeks year starting saturday', function (assert) {
  8044. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  8045. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  8046. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  8047. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  8048. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  8049. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  8050. });
  8051. test('weeks year starting sunday formatted', function (assert) {
  8052. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52nd', 'Jan 1 2012 should be week 52');
  8053. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1st', 'Jan 2 2012 should be week 1');
  8054. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1st', 'Jan 8 2012 should be week 1');
  8055. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2nd', 'Jan 9 2012 should be week 2');
  8056. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2nd', 'Jan 15 2012 should be week 2');
  8057. });
  8058. test('lenient ordinal parsing', function (assert) {
  8059. var i, ordinalStr, testMoment;
  8060. for (i = 1; i <= 31; ++i) {
  8061. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  8062. testMoment = moment(ordinalStr, 'YYYY MM Do');
  8063. assert.equal(testMoment.year(), 2014,
  8064. 'lenient ordinal parsing ' + i + ' year check');
  8065. assert.equal(testMoment.month(), 0,
  8066. 'lenient ordinal parsing ' + i + ' month check');
  8067. assert.equal(testMoment.date(), i,
  8068. 'lenient ordinal parsing ' + i + ' date check');
  8069. }
  8070. });
  8071. test('lenient ordinal parsing of number', function (assert) {
  8072. var i, testMoment;
  8073. for (i = 1; i <= 31; ++i) {
  8074. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  8075. assert.equal(testMoment.year(), 2014,
  8076. 'lenient ordinal parsing of number ' + i + ' year check');
  8077. assert.equal(testMoment.month(), 0,
  8078. 'lenient ordinal parsing of number ' + i + ' month check');
  8079. assert.equal(testMoment.date(), i,
  8080. 'lenient ordinal parsing of number ' + i + ' date check');
  8081. }
  8082. });
  8083. test('strict ordinal parsing', function (assert) {
  8084. var i, ordinalStr, testMoment;
  8085. for (i = 1; i <= 31; ++i) {
  8086. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  8087. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  8088. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  8089. }
  8090. });
  8091. }));
  8092. ;(function (global, factory) {
  8093. typeof exports === 'object' && typeof module !== 'undefined'
  8094. && typeof require === 'function' ? factory(require('../../moment')) :
  8095. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  8096. factory(global.moment)
  8097. }(this, function (moment) { 'use strict';
  8098. /*global QUnit:false*/
  8099. var test = QUnit.test;
  8100. var expect = QUnit.expect;
  8101. function module (name, lifecycle) {
  8102. QUnit.module(name, {
  8103. setup : function () {
  8104. moment.locale('en');
  8105. moment.createFromInputFallback = function (config) {
  8106. throw new Error('input not handled by moment: ' + config._i);
  8107. };
  8108. if (lifecycle && lifecycle.setup) {
  8109. lifecycle.setup();
  8110. }
  8111. },
  8112. teardown : function () {
  8113. if (lifecycle && lifecycle.teardown) {
  8114. lifecycle.teardown();
  8115. }
  8116. }
  8117. });
  8118. }
  8119. function localeModule (name, lifecycle) {
  8120. QUnit.module('locale:' + name, {
  8121. setup : function () {
  8122. moment.locale(name);
  8123. moment.createFromInputFallback = function (config) {
  8124. throw new Error('input not handled by moment: ' + config._i);
  8125. };
  8126. if (lifecycle && lifecycle.setup) {
  8127. lifecycle.setup();
  8128. }
  8129. },
  8130. teardown : function () {
  8131. moment.locale('en');
  8132. if (lifecycle && lifecycle.teardown) {
  8133. lifecycle.teardown();
  8134. }
  8135. }
  8136. });
  8137. }
  8138. localeModule('en-nz');
  8139. test('parse', function (assert) {
  8140. var tests = 'January Jan_February Feb_March Mar_April Apr_May May_June Jun_July Jul_August Aug_September Sep_October Oct_November Nov_December Dec'.split('_'), i;
  8141. function equalTest(input, mmm, i) {
  8142. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  8143. }
  8144. for (i = 0; i < 12; i++) {
  8145. tests[i] = tests[i].split(' ');
  8146. equalTest(tests[i][0], 'MMM', i);
  8147. equalTest(tests[i][1], 'MMM', i);
  8148. equalTest(tests[i][0], 'MMMM', i);
  8149. equalTest(tests[i][1], 'MMMM', i);
  8150. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  8151. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  8152. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  8153. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  8154. }
  8155. });
  8156. test('format', function (assert) {
  8157. var a = [
  8158. ['dddd, MMMM Do YYYY, h:mm:ss a', 'Sunday, February 14th 2010, 3:25:50 pm'],
  8159. ['ddd, hA', 'Sun, 3PM'],
  8160. ['M Mo MM MMMM MMM', '2 2nd 02 February Feb'],
  8161. ['YYYY YY', '2010 10'],
  8162. ['D Do DD', '14 14th 14'],
  8163. ['d do dddd ddd dd', '0 0th Sunday Sun Su'],
  8164. ['DDD DDDo DDDD', '45 45th 045'],
  8165. ['w wo ww', '6 6th 06'],
  8166. ['h hh', '3 03'],
  8167. ['H HH', '15 15'],
  8168. ['m mm', '25 25'],
  8169. ['s ss', '50 50'],
  8170. ['a A', 'pm PM'],
  8171. ['[the] DDDo [day of the year]', 'the 45th day of the year'],
  8172. ['LTS', '3:25:50 PM'],
  8173. ['L', '14/02/2010'],
  8174. ['LL', '14 February 2010'],
  8175. ['LLL', '14 February 2010 3:25 PM'],
  8176. ['LLLL', 'Sunday, 14 February 2010 3:25 PM'],
  8177. ['l', '14/2/2010'],
  8178. ['ll', '14 Feb 2010'],
  8179. ['lll', '14 Feb 2010 3:25 PM'],
  8180. ['llll', 'Sun, 14 Feb 2010 3:25 PM']
  8181. ],
  8182. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  8183. i;
  8184. for (i = 0; i < a.length; i++) {
  8185. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  8186. }
  8187. });
  8188. test('format ordinal', function (assert) {
  8189. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1st', '1st');
  8190. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2nd', '2nd');
  8191. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3rd', '3rd');
  8192. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4th', '4th');
  8193. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5th', '5th');
  8194. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6th', '6th');
  8195. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7th', '7th');
  8196. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8th', '8th');
  8197. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9th', '9th');
  8198. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10th', '10th');
  8199. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11th', '11th');
  8200. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12th', '12th');
  8201. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13th', '13th');
  8202. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14th', '14th');
  8203. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15th', '15th');
  8204. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16th', '16th');
  8205. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17th', '17th');
  8206. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18th', '18th');
  8207. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19th', '19th');
  8208. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20th', '20th');
  8209. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21st', '21st');
  8210. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22nd', '22nd');
  8211. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23rd', '23rd');
  8212. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24th', '24th');
  8213. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25th', '25th');
  8214. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26th', '26th');
  8215. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27th', '27th');
  8216. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28th', '28th');
  8217. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29th', '29th');
  8218. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30th', '30th');
  8219. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31st', '31st');
  8220. });
  8221. test('format month', function (assert) {
  8222. var expected = 'January Jan_February Feb_March Mar_April Apr_May May_June Jun_July Jul_August Aug_September Sep_October Oct_November Nov_December Dec'.split('_'), i;
  8223. for (i = 0; i < expected.length; i++) {
  8224. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  8225. }
  8226. });
  8227. test('format week', function (assert) {
  8228. var expected = 'Sunday Sun Su_Monday Mon Mo_Tuesday Tue Tu_Wednesday Wed We_Thursday Thu Th_Friday Fri Fr_Saturday Sat Sa'.split('_'), i;
  8229. for (i = 0; i < expected.length; i++) {
  8230. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  8231. }
  8232. });
  8233. test('from', function (assert) {
  8234. var start = moment([2007, 1, 28]);
  8235. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'a few seconds', '44 seconds = a few seconds');
  8236. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'a minute', '45 seconds = a minute');
  8237. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'a minute', '89 seconds = a minute');
  8238. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutes', '90 seconds = 2 minutes');
  8239. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutes', '44 minutes = 44 minutes');
  8240. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'an hour', '45 minutes = an hour');
  8241. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'an hour', '89 minutes = an hour');
  8242. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 hours', '90 minutes = 2 hours');
  8243. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 hours', '5 hours = 5 hours');
  8244. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 hours', '21 hours = 21 hours');
  8245. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'a day', '22 hours = a day');
  8246. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'a day', '35 hours = a day');
  8247. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 days', '36 hours = 2 days');
  8248. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'a day', '1 day = a day');
  8249. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 days', '5 days = 5 days');
  8250. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 days', '25 days = 25 days');
  8251. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'a month', '26 days = a month');
  8252. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'a month', '30 days = a month');
  8253. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'a month', '43 days = a month');
  8254. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 months', '46 days = 2 months');
  8255. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 months', '75 days = 2 months');
  8256. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 months', '76 days = 3 months');
  8257. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'a month', '1 month = a month');
  8258. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 months', '5 months = 5 months');
  8259. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'a year', '345 days = a year');
  8260. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 years', '548 days = 2 years');
  8261. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'a year', '1 year = a year');
  8262. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 years', '5 years = 5 years');
  8263. });
  8264. test('suffix', function (assert) {
  8265. assert.equal(moment(30000).from(0), 'in a few seconds', 'prefix');
  8266. assert.equal(moment(0).from(30000), 'a few seconds ago', 'suffix');
  8267. });
  8268. test('now from now', function (assert) {
  8269. assert.equal(moment().fromNow(), 'a few seconds ago', 'now from now should display as in the past');
  8270. });
  8271. test('fromNow', function (assert) {
  8272. assert.equal(moment().add({s: 30}).fromNow(), 'in a few seconds', 'in a few seconds');
  8273. assert.equal(moment().add({d: 5}).fromNow(), 'in 5 days', 'in 5 days');
  8274. });
  8275. test('calendar day', function (assert) {
  8276. var a = moment().hours(2).minutes(0).seconds(0);
  8277. assert.equal(moment(a).calendar(), 'Today at 2:00 AM', 'today at the same time');
  8278. assert.equal(moment(a).add({m: 25}).calendar(), 'Today at 2:25 AM', 'Now plus 25 min');
  8279. assert.equal(moment(a).add({h: 1}).calendar(), 'Today at 3:00 AM', 'Now plus 1 hour');
  8280. assert.equal(moment(a).add({d: 1}).calendar(), 'Tomorrow at 2:00 AM', 'tomorrow at the same time');
  8281. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Today at 1:00 AM', 'Now minus 1 hour');
  8282. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Yesterday at 2:00 AM', 'yesterday at the same time');
  8283. });
  8284. test('calendar next week', function (assert) {
  8285. var i, m;
  8286. for (i = 2; i < 7; i++) {
  8287. m = moment().add({d: i});
  8288. assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days current time');
  8289. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  8290. assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days beginning of day');
  8291. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  8292. assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days end of day');
  8293. }
  8294. });
  8295. test('calendar last week', function (assert) {
  8296. var i, m;
  8297. for (i = 2; i < 7; i++) {
  8298. m = moment().subtract({d: i});
  8299. assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days current time');
  8300. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  8301. assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days beginning of day');
  8302. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  8303. assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days end of day');
  8304. }
  8305. });
  8306. test('calendar all else', function (assert) {
  8307. var weeksAgo = moment().subtract({w: 1}),
  8308. weeksFromNow = moment().add({w: 1});
  8309. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  8310. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  8311. weeksAgo = moment().subtract({w: 2});
  8312. weeksFromNow = moment().add({w: 2});
  8313. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  8314. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  8315. });
  8316. test('weeks year starting sunday', function (assert) {
  8317. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  8318. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  8319. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  8320. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  8321. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  8322. });
  8323. test('weeks year starting monday', function (assert) {
  8324. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  8325. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  8326. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  8327. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  8328. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  8329. });
  8330. test('weeks year starting tuesday', function (assert) {
  8331. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  8332. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  8333. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  8334. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  8335. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  8336. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  8337. });
  8338. test('weeks year starting wednesday', function (assert) {
  8339. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  8340. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  8341. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  8342. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  8343. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  8344. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  8345. });
  8346. test('weeks year starting thursday', function (assert) {
  8347. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  8348. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  8349. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  8350. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  8351. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  8352. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  8353. });
  8354. test('weeks year starting friday', function (assert) {
  8355. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  8356. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  8357. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  8358. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  8359. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  8360. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  8361. });
  8362. test('weeks year starting saturday', function (assert) {
  8363. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  8364. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  8365. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  8366. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  8367. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  8368. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  8369. });
  8370. test('weeks year starting sunday formatted', function (assert) {
  8371. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52nd', 'Jan 1 2012 should be week 52');
  8372. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1st', 'Jan 2 2012 should be week 1');
  8373. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1st', 'Jan 8 2012 should be week 1');
  8374. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2nd', 'Jan 9 2012 should be week 2');
  8375. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2nd', 'Jan 15 2012 should be week 2');
  8376. });
  8377. test('lenient ordinal parsing', function (assert) {
  8378. var i, ordinalStr, testStr;
  8379. for (i = 1; i <= 31; ++i) {
  8380. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  8381. testStr = moment(ordinalStr, 'YYYY MM Do').format('YYYY MM D');
  8382. assert.equal(testStr, '2014 01 ' + i, 'lenient ordinal parsing ' + i);
  8383. }
  8384. });
  8385. test('lenient ordinal parsing of number', function (assert) {
  8386. var i, testStr;
  8387. for (i = 1; i <= 31; ++i) {
  8388. testStr = moment('2014 01 ' + i, 'YYYY MM Do').format('YYYY MM D');
  8389. assert.equal(testStr, '2014 01 ' + i,
  8390. 'lenient ordinal parsing of number ' + i);
  8391. }
  8392. });
  8393. test('strict ordinal parsing', function (assert) {
  8394. var i, ordinalStr, testMoment;
  8395. for (i = 1; i <= 31; ++i) {
  8396. ordinalStr = moment([2014, 0, i]).format('YYYY MMM Do');
  8397. testMoment = moment(ordinalStr, 'YYYY MMM Do', true);
  8398. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  8399. }
  8400. });
  8401. }));
  8402. ;(function (global, factory) {
  8403. typeof exports === 'object' && typeof module !== 'undefined'
  8404. && typeof require === 'function' ? factory(require('../../moment')) :
  8405. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  8406. factory(global.moment)
  8407. }(this, function (moment) { 'use strict';
  8408. /*global QUnit:false*/
  8409. var test = QUnit.test;
  8410. var expect = QUnit.expect;
  8411. function module (name, lifecycle) {
  8412. QUnit.module(name, {
  8413. setup : function () {
  8414. moment.locale('en');
  8415. moment.createFromInputFallback = function (config) {
  8416. throw new Error('input not handled by moment: ' + config._i);
  8417. };
  8418. if (lifecycle && lifecycle.setup) {
  8419. lifecycle.setup();
  8420. }
  8421. },
  8422. teardown : function () {
  8423. if (lifecycle && lifecycle.teardown) {
  8424. lifecycle.teardown();
  8425. }
  8426. }
  8427. });
  8428. }
  8429. function localeModule (name, lifecycle) {
  8430. QUnit.module('locale:' + name, {
  8431. setup : function () {
  8432. moment.locale(name);
  8433. moment.createFromInputFallback = function (config) {
  8434. throw new Error('input not handled by moment: ' + config._i);
  8435. };
  8436. if (lifecycle && lifecycle.setup) {
  8437. lifecycle.setup();
  8438. }
  8439. },
  8440. teardown : function () {
  8441. moment.locale('en');
  8442. if (lifecycle && lifecycle.teardown) {
  8443. lifecycle.teardown();
  8444. }
  8445. }
  8446. });
  8447. }
  8448. localeModule('en');
  8449. test('parse', function (assert) {
  8450. var i,
  8451. tests = 'January Jan_February Feb_March Mar_April Apr_May May_June Jun_July Jul_August Aug_September Sep_October Oct_November Nov_December Dec'.split('_');
  8452. function equalTest(input, mmm, i) {
  8453. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  8454. }
  8455. for (i = 0; i < 12; i++) {
  8456. tests[i] = tests[i].split(' ');
  8457. equalTest(tests[i][0], 'MMM', i);
  8458. equalTest(tests[i][1], 'MMM', i);
  8459. equalTest(tests[i][0], 'MMMM', i);
  8460. equalTest(tests[i][1], 'MMMM', i);
  8461. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  8462. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  8463. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  8464. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  8465. }
  8466. });
  8467. test('format', function (assert) {
  8468. var a = [
  8469. ['dddd, MMMM Do YYYY, h:mm:ss a', 'Sunday, February 14th 2010, 3:25:50 pm'],
  8470. ['ddd, hA', 'Sun, 3PM'],
  8471. ['M Mo MM MMMM MMM', '2 2nd 02 February Feb'],
  8472. ['YYYY YY', '2010 10'],
  8473. ['D Do DD', '14 14th 14'],
  8474. ['d do dddd ddd dd', '0 0th Sunday Sun Su'],
  8475. ['DDD DDDo DDDD', '45 45th 045'],
  8476. ['w wo ww', '8 8th 08'],
  8477. ['h hh', '3 03'],
  8478. ['H HH', '15 15'],
  8479. ['m mm', '25 25'],
  8480. ['s ss', '50 50'],
  8481. ['a A', 'pm PM'],
  8482. ['[the] DDDo [day of the year]', 'the 45th day of the year'],
  8483. ['LTS', '3:25:50 PM'],
  8484. ['L', '02/14/2010'],
  8485. ['LL', 'February 14, 2010'],
  8486. ['LLL', 'February 14, 2010 3:25 PM'],
  8487. ['LLLL', 'Sunday, February 14, 2010 3:25 PM'],
  8488. ['l', '2/14/2010'],
  8489. ['ll', 'Feb 14, 2010'],
  8490. ['lll', 'Feb 14, 2010 3:25 PM'],
  8491. ['llll', 'Sun, Feb 14, 2010 3:25 PM']
  8492. ],
  8493. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  8494. i;
  8495. for (i = 0; i < a.length; i++) {
  8496. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  8497. }
  8498. });
  8499. test('format ordinal', function (assert) {
  8500. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1st', '1st');
  8501. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2nd', '2nd');
  8502. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3rd', '3rd');
  8503. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4th', '4th');
  8504. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5th', '5th');
  8505. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6th', '6th');
  8506. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7th', '7th');
  8507. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8th', '8th');
  8508. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9th', '9th');
  8509. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10th', '10th');
  8510. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11th', '11th');
  8511. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12th', '12th');
  8512. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13th', '13th');
  8513. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14th', '14th');
  8514. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15th', '15th');
  8515. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16th', '16th');
  8516. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17th', '17th');
  8517. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18th', '18th');
  8518. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19th', '19th');
  8519. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20th', '20th');
  8520. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21st', '21st');
  8521. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22nd', '22nd');
  8522. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23rd', '23rd');
  8523. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24th', '24th');
  8524. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25th', '25th');
  8525. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26th', '26th');
  8526. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27th', '27th');
  8527. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28th', '28th');
  8528. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29th', '29th');
  8529. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30th', '30th');
  8530. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31st', '31st');
  8531. });
  8532. test('format month', function (assert) {
  8533. var i,
  8534. expected = 'January Jan_February Feb_March Mar_April Apr_May May_June Jun_July Jul_August Aug_September Sep_October Oct_November Nov_December Dec'.split('_');
  8535. for (i = 0; i < expected.length; i++) {
  8536. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  8537. }
  8538. });
  8539. test('format week', function (assert) {
  8540. var i,
  8541. expected = 'Sunday Sun Su_Monday Mon Mo_Tuesday Tue Tu_Wednesday Wed We_Thursday Thu Th_Friday Fri Fr_Saturday Sat Sa'.split('_');
  8542. for (i = 0; i < expected.length; i++) {
  8543. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  8544. }
  8545. });
  8546. test('from', function (assert) {
  8547. var start = moment([2007, 1, 28]);
  8548. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'a few seconds', '44 seconds = a few seconds');
  8549. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'a minute', '45 seconds = a minute');
  8550. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'a minute', '89 seconds = a minute');
  8551. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutes', '90 seconds = 2 minutes');
  8552. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutes', '44 minutes = 44 minutes');
  8553. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'an hour', '45 minutes = an hour');
  8554. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'an hour', '89 minutes = an hour');
  8555. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 hours', '90 minutes = 2 hours');
  8556. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 hours', '5 hours = 5 hours');
  8557. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 hours', '21 hours = 21 hours');
  8558. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'a day', '22 hours = a day');
  8559. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'a day', '35 hours = a day');
  8560. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 days', '36 hours = 2 days');
  8561. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'a day', '1 day = a day');
  8562. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 days', '5 days = 5 days');
  8563. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 days', '25 days = 25 days');
  8564. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'a month', '26 days = a month');
  8565. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'a month', '30 days = a month');
  8566. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'a month', '43 days = a month');
  8567. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 months', '46 days = 2 months');
  8568. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 months', '75 days = 2 months');
  8569. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 months', '76 days = 3 months');
  8570. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'a month', '1 month = a month');
  8571. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 months', '5 months = 5 months');
  8572. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'a year', '345 days = a year');
  8573. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 years', '548 days = 2 years');
  8574. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'a year', '1 year = a year');
  8575. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 years', '5 years = 5 years');
  8576. });
  8577. test('suffix', function (assert) {
  8578. assert.equal(moment(30000).from(0), 'in a few seconds', 'prefix');
  8579. assert.equal(moment(0).from(30000), 'a few seconds ago', 'suffix');
  8580. });
  8581. test('now from now', function (assert) {
  8582. assert.equal(moment().fromNow(), 'a few seconds ago', 'now from now should display as in the past');
  8583. });
  8584. test('fromNow', function (assert) {
  8585. assert.equal(moment().add({s: 30}).fromNow(), 'in a few seconds', 'in a few seconds');
  8586. assert.equal(moment().add({d: 5}).fromNow(), 'in 5 days', 'in 5 days');
  8587. });
  8588. test('calendar day', function (assert) {
  8589. var a = moment().hours(2).minutes(0).seconds(0);
  8590. assert.equal(moment(a).calendar(), 'Today at 2:00 AM', 'today at the same time');
  8591. assert.equal(moment(a).add({m: 25}).calendar(), 'Today at 2:25 AM', 'Now plus 25 min');
  8592. assert.equal(moment(a).add({h: 1}).calendar(), 'Today at 3:00 AM', 'Now plus 1 hour');
  8593. assert.equal(moment(a).add({d: 1}).calendar(), 'Tomorrow at 2:00 AM', 'tomorrow at the same time');
  8594. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Today at 1:00 AM', 'Now minus 1 hour');
  8595. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Yesterday at 2:00 AM', 'yesterday at the same time');
  8596. });
  8597. test('calendar next week', function (assert) {
  8598. var i, m;
  8599. for (i = 2; i < 7; i++) {
  8600. m = moment().add({d: i});
  8601. assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days current time');
  8602. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  8603. assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days beginning of day');
  8604. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  8605. assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days end of day');
  8606. }
  8607. });
  8608. test('calendar last week', function (assert) {
  8609. var i, m;
  8610. for (i = 2; i < 7; i++) {
  8611. m = moment().subtract({d: i});
  8612. assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days current time');
  8613. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  8614. assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days beginning of day');
  8615. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  8616. assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days end of day');
  8617. }
  8618. });
  8619. test('calendar all else', function (assert) {
  8620. var weeksAgo = moment().subtract({w: 1}),
  8621. weeksFromNow = moment().add({w: 1});
  8622. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  8623. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  8624. weeksAgo = moment().subtract({w: 2});
  8625. weeksFromNow = moment().add({w: 2});
  8626. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  8627. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  8628. });
  8629. test('weeks year starting sunday', function (assert) {
  8630. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  8631. assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1');
  8632. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  8633. assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2');
  8634. assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 3');
  8635. });
  8636. test('weeks year starting monday', function (assert) {
  8637. assert.equal(moment([2006, 11, 31]).week(), 1, 'Dec 31 2006 should be week 1');
  8638. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  8639. assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1');
  8640. assert.equal(moment([2007, 0, 7]).week(), 2, 'Jan 7 2007 should be week 2');
  8641. assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2');
  8642. assert.equal(moment([2007, 0, 14]).week(), 3, 'Jan 14 2007 should be week 3');
  8643. });
  8644. test('weeks year starting tuesday', function (assert) {
  8645. assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52');
  8646. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  8647. assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1');
  8648. assert.equal(moment([2008, 0, 6]).week(), 2, 'Jan 6 2008 should be week 2');
  8649. assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2');
  8650. assert.equal(moment([2008, 0, 13]).week(), 3, 'Jan 13 2008 should be week 3');
  8651. });
  8652. test('weeks year starting wednesday', function (assert) {
  8653. assert.equal(moment([2002, 11, 29]).week(), 1, 'Dec 29 2002 should be week 1');
  8654. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  8655. assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1');
  8656. assert.equal(moment([2003, 0, 5]).week(), 2, 'Jan 5 2003 should be week 2');
  8657. assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2');
  8658. assert.equal(moment([2003, 0, 12]).week(), 3, 'Jan 12 2003 should be week 3');
  8659. });
  8660. test('weeks year starting thursday', function (assert) {
  8661. assert.equal(moment([2008, 11, 28]).week(), 1, 'Dec 28 2008 should be week 1');
  8662. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  8663. assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1');
  8664. assert.equal(moment([2009, 0, 4]).week(), 2, 'Jan 4 2009 should be week 2');
  8665. assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2');
  8666. assert.equal(moment([2009, 0, 11]).week(), 3, 'Jan 11 2009 should be week 3');
  8667. });
  8668. test('weeks year starting friday', function (assert) {
  8669. assert.equal(moment([2009, 11, 27]).week(), 1, 'Dec 27 2009 should be week 1');
  8670. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  8671. assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 should be week 1');
  8672. assert.equal(moment([2010, 0, 3]).week(), 2, 'Jan 3 2010 should be week 2');
  8673. assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 should be week 2');
  8674. assert.equal(moment([2010, 0, 10]).week(), 3, 'Jan 10 2010 should be week 3');
  8675. });
  8676. test('weeks year starting saturday', function (assert) {
  8677. assert.equal(moment([2010, 11, 26]).week(), 1, 'Dec 26 2010 should be week 1');
  8678. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  8679. assert.equal(moment([2011, 0, 2]).week(), 2, 'Jan 2 2011 should be week 2');
  8680. assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2');
  8681. assert.equal(moment([2011, 0, 9]).week(), 3, 'Jan 9 2011 should be week 3');
  8682. });
  8683. test('weeks year starting sunday format', function (assert) {
  8684. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1st', 'Jan 1 2012 should be week 1');
  8685. assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1st', 'Jan 7 2012 should be week 1');
  8686. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2nd', 'Jan 8 2012 should be week 2');
  8687. assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2nd', 'Jan 14 2012 should be week 2');
  8688. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3rd', 'Jan 15 2012 should be week 3');
  8689. });
  8690. test('lenient ordinal parsing', function (assert) {
  8691. var i, ordinalStr, testMoment;
  8692. for (i = 1; i <= 31; ++i) {
  8693. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  8694. testMoment = moment(ordinalStr, 'YYYY MM Do');
  8695. assert.equal(testMoment.year(), 2014,
  8696. 'lenient ordinal parsing ' + i + ' year check');
  8697. assert.equal(testMoment.month(), 0,
  8698. 'lenient ordinal parsing ' + i + ' month check');
  8699. assert.equal(testMoment.date(), i,
  8700. 'lenient ordinal parsing ' + i + ' date check');
  8701. }
  8702. });
  8703. test('weekdays strict parsing', function (assert) {
  8704. var m = moment('2015-01-01T12', moment.ISO_8601, true),
  8705. enLocale = moment.localeData('en');
  8706. for (var i = 0; i < 7; ++i) {
  8707. assert.equal(moment(enLocale.weekdays(m.day(i), ''), 'dddd', true).isValid(), true, 'parse weekday ' + i);
  8708. assert.equal(moment(enLocale.weekdaysShort(m.day(i), ''), 'ddd', true).isValid(), true, 'parse short weekday ' + i);
  8709. assert.equal(moment(enLocale.weekdaysMin(m.day(i), ''), 'dd', true).isValid(), true, 'parse min weekday ' + i);
  8710. // negative tests
  8711. assert.equal(moment(enLocale.weekdaysMin(m.day(i), ''), 'ddd', true).isValid(), false, 'parse short weekday ' + i);
  8712. assert.equal(moment(enLocale.weekdaysShort(m.day(i), ''), 'dd', true).isValid(), false, 'parse min weekday ' + i);
  8713. }
  8714. });
  8715. test('lenient ordinal parsing of number', function (assert) {
  8716. var i, testMoment;
  8717. for (i = 1; i <= 31; ++i) {
  8718. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  8719. assert.equal(testMoment.year(), 2014,
  8720. 'lenient ordinal parsing of number ' + i + ' year check');
  8721. assert.equal(testMoment.month(), 0,
  8722. 'lenient ordinal parsing of number ' + i + ' month check');
  8723. assert.equal(testMoment.date(), i,
  8724. 'lenient ordinal parsing of number ' + i + ' date check');
  8725. }
  8726. });
  8727. test('strict ordinal parsing', function (assert) {
  8728. var i, ordinalStr, testMoment;
  8729. for (i = 1; i <= 31; ++i) {
  8730. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  8731. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  8732. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  8733. }
  8734. });
  8735. }));
  8736. ;(function (global, factory) {
  8737. typeof exports === 'object' && typeof module !== 'undefined'
  8738. && typeof require === 'function' ? factory(require('../../moment')) :
  8739. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  8740. factory(global.moment)
  8741. }(this, function (moment) { 'use strict';
  8742. /*global QUnit:false*/
  8743. var test = QUnit.test;
  8744. var expect = QUnit.expect;
  8745. function module (name, lifecycle) {
  8746. QUnit.module(name, {
  8747. setup : function () {
  8748. moment.locale('en');
  8749. moment.createFromInputFallback = function (config) {
  8750. throw new Error('input not handled by moment: ' + config._i);
  8751. };
  8752. if (lifecycle && lifecycle.setup) {
  8753. lifecycle.setup();
  8754. }
  8755. },
  8756. teardown : function () {
  8757. if (lifecycle && lifecycle.teardown) {
  8758. lifecycle.teardown();
  8759. }
  8760. }
  8761. });
  8762. }
  8763. function localeModule (name, lifecycle) {
  8764. QUnit.module('locale:' + name, {
  8765. setup : function () {
  8766. moment.locale(name);
  8767. moment.createFromInputFallback = function (config) {
  8768. throw new Error('input not handled by moment: ' + config._i);
  8769. };
  8770. if (lifecycle && lifecycle.setup) {
  8771. lifecycle.setup();
  8772. }
  8773. },
  8774. teardown : function () {
  8775. moment.locale('en');
  8776. if (lifecycle && lifecycle.teardown) {
  8777. lifecycle.teardown();
  8778. }
  8779. }
  8780. });
  8781. }
  8782. localeModule('eo');
  8783. test('parse', function (assert) {
  8784. var tests = 'januaro jan_februaro feb_marto mar_aprilo apr_majo maj_junio jun_julio jul_aŭgusto aŭg_septembro sep_oktobro okt_novembro nov_decembro dec'.split('_'), i;
  8785. function equalTest(input, mmm, i) {
  8786. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  8787. }
  8788. for (i = 0; i < 12; i++) {
  8789. tests[i] = tests[i].split(' ');
  8790. equalTest(tests[i][0], 'MMM', i);
  8791. equalTest(tests[i][1], 'MMM', i);
  8792. equalTest(tests[i][0], 'MMMM', i);
  8793. equalTest(tests[i][1], 'MMMM', i);
  8794. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  8795. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  8796. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  8797. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  8798. }
  8799. });
  8800. test('format', function (assert) {
  8801. var a = [
  8802. ['dddd, MMMM Do YYYY, h:mm:ss a', 'Dimanĉo, februaro 14a 2010, 3:25:50 p.t.m.'],
  8803. ['ddd, hA', 'Dim, 3P.T.M.'],
  8804. ['M Mo MM MMMM MMM', '2 2a 02 februaro feb'],
  8805. ['YYYY YY', '2010 10'],
  8806. ['D Do DD', '14 14a 14'],
  8807. ['d do dddd ddd dd', '0 0a Dimanĉo Dim Di'],
  8808. ['DDD DDDo DDDD', '45 45a 045'],
  8809. ['w wo ww', '7 7a 07'],
  8810. ['h hh', '3 03'],
  8811. ['H HH', '15 15'],
  8812. ['m mm', '25 25'],
  8813. ['s ss', '50 50'],
  8814. ['a A', 'p.t.m. P.T.M.'],
  8815. ['[la] DDDo [tago] [de] [la] [jaro]', 'la 45a tago de la jaro'],
  8816. ['LTS', '15:25:50'],
  8817. ['L', '2010-02-14'],
  8818. ['LL', '14-an de februaro, 2010'],
  8819. ['LLL', '14-an de februaro, 2010 15:25'],
  8820. ['LLLL', 'Dimanĉo, la 14-an de februaro, 2010 15:25'],
  8821. ['l', '2010-2-14'],
  8822. ['ll', '14-an de feb, 2010'],
  8823. ['lll', '14-an de feb, 2010 15:25'],
  8824. ['llll', 'Dim, la 14-an de feb, 2010 15:25']
  8825. ],
  8826. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  8827. i;
  8828. for (i = 0; i < a.length; i++) {
  8829. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  8830. }
  8831. });
  8832. test('format ordinal', function (assert) {
  8833. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1a', '1a');
  8834. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2a', '2a');
  8835. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3a', '3a');
  8836. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4a', '4a');
  8837. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5a', '5a');
  8838. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6a', '6a');
  8839. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7a', '7a');
  8840. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8a', '8a');
  8841. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9a', '9a');
  8842. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10a', '10a');
  8843. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11a', '11a');
  8844. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12a', '12a');
  8845. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13a', '13a');
  8846. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14a', '14a');
  8847. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15a', '15a');
  8848. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16a', '16a');
  8849. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17a', '17a');
  8850. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18a', '18a');
  8851. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19a', '19a');
  8852. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20a', '20a');
  8853. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21a', '21a');
  8854. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22a', '22a');
  8855. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23a', '23a');
  8856. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24a', '24a');
  8857. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25a', '25a');
  8858. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26a', '26a');
  8859. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27a', '27a');
  8860. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28a', '28a');
  8861. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29a', '29a');
  8862. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30a', '30a');
  8863. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31a', '31a');
  8864. });
  8865. test('format month', function (assert) {
  8866. var expected = 'januaro jan_februaro feb_marto mar_aprilo apr_majo maj_junio jun_julio jul_aŭgusto aŭg_septembro sep_oktobro okt_novembro nov_decembro dec'.split('_'), i;
  8867. for (i = 0; i < expected.length; i++) {
  8868. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  8869. }
  8870. });
  8871. test('format week', function (assert) {
  8872. var expected = 'Dimanĉo Dim Di_Lundo Lun Lu_Mardo Mard Ma_Merkredo Merk Me_Ĵaŭdo Ĵaŭ Ĵa_Vendredo Ven Ve_Sabato Sab Sa'.split('_'), i;
  8873. for (i = 0; i < expected.length; i++) {
  8874. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  8875. }
  8876. });
  8877. test('from', function (assert) {
  8878. var start = moment([2007, 1, 28]);
  8879. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'sekundoj', '44 seconds = a few seconds');
  8880. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'minuto', '45 seconds = a minute');
  8881. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'minuto', '89 seconds = a minute');
  8882. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutoj', '90 seconds = 2 minutes');
  8883. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutoj', '44 minutes = 44 minutes');
  8884. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'horo', '45 minutes = an hour');
  8885. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'horo', '89 minutes = an hour');
  8886. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 horoj', '90 minutes = 2 hours');
  8887. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 horoj', '5 hours = 5 hours');
  8888. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 horoj', '21 hours = 21 hours');
  8889. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'tago', '22 hours = a day');
  8890. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'tago', '35 hours = a day');
  8891. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 tagoj', '36 hours = 2 days');
  8892. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'tago', '1 day = a day');
  8893. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 tagoj', '5 days = 5 days');
  8894. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 tagoj', '25 days = 25 days');
  8895. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'monato', '26 days = a month');
  8896. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'monato', '30 days = a month');
  8897. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'monato', '43 days = a month');
  8898. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 monatoj', '46 days = 2 months');
  8899. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 monatoj', '75 days = 2 months');
  8900. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 monatoj', '76 days = 3 months');
  8901. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'monato', '1 month = a month');
  8902. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 monatoj', '5 months = 5 months');
  8903. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'jaro', '345 days = a year');
  8904. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 jaroj', '548 days = 2 years');
  8905. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'jaro', '1 year = a year');
  8906. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 jaroj', '5 years = 5 years');
  8907. });
  8908. test('suffix', function (assert) {
  8909. assert.equal(moment(30000).from(0), 'je sekundoj', 'je prefix');
  8910. assert.equal(moment(0).from(30000), 'antaŭ sekundoj', 'antaŭ prefix');
  8911. });
  8912. test('now from now', function (assert) {
  8913. assert.equal(moment().fromNow(), 'antaŭ sekundoj', 'now from now should display as in the past');
  8914. });
  8915. test('fromNow', function (assert) {
  8916. assert.equal(moment().add({s: 30}).fromNow(), 'je sekundoj', 'je sekundoj');
  8917. assert.equal(moment().add({d: 5}).fromNow(), 'je 5 tagoj', 'je 5 tagoj');
  8918. });
  8919. test('calendar day', function (assert) {
  8920. var a = moment().hours(2).minutes(0).seconds(0);
  8921. assert.equal(moment(a).calendar(), 'Hodiaŭ je 02:00', 'today at the same time');
  8922. assert.equal(moment(a).add({m: 25}).calendar(), 'Hodiaŭ je 02:25', 'Now plus 25 min');
  8923. assert.equal(moment(a).add({h: 1}).calendar(), 'Hodiaŭ je 03:00', 'Now plus 1 hour');
  8924. assert.equal(moment(a).add({d: 1}).calendar(), 'Morgaŭ je 02:00', 'tomorrow at the same time');
  8925. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Hodiaŭ je 01:00', 'Now minus 1 hour');
  8926. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Hieraŭ je 02:00', 'yesterday at the same time');
  8927. });
  8928. test('calendar next week', function (assert) {
  8929. var i, m;
  8930. for (i = 2; i < 7; i++) {
  8931. m = moment().add({d: i});
  8932. assert.equal(m.calendar(), m.format('dddd [je] LT'), 'Today + ' + i + ' days current time');
  8933. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  8934. assert.equal(m.calendar(), m.format('dddd [je] LT'), 'Today + ' + i + ' days beginning of day');
  8935. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  8936. assert.equal(m.calendar(), m.format('dddd [je] LT'), 'Today + ' + i + ' days end of day');
  8937. }
  8938. });
  8939. test('calendar last week', function (assert) {
  8940. var i, m;
  8941. for (i = 2; i < 7; i++) {
  8942. m = moment().subtract({d: i});
  8943. assert.equal(m.calendar(), m.format('[pasinta] dddd [je] LT'), 'Today - ' + i + ' days current time');
  8944. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  8945. assert.equal(m.calendar(), m.format('[pasinta] dddd [je] LT'), 'Today - ' + i + ' days beginning of day');
  8946. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  8947. assert.equal(m.calendar(), m.format('[pasinta] dddd [je] LT'), 'Today - ' + i + ' days end of day');
  8948. }
  8949. });
  8950. test('calendar all else', function (assert) {
  8951. var weeksAgo = moment().subtract({w: 1}),
  8952. weeksFromNow = moment().add({w: 1});
  8953. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  8954. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  8955. weeksAgo = moment().subtract({w: 2});
  8956. weeksFromNow = moment().add({w: 2});
  8957. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  8958. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  8959. });
  8960. test('weeks year starting sunday', function (assert) {
  8961. assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1');
  8962. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  8963. assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2');
  8964. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  8965. assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3');
  8966. });
  8967. test('weeks year starting monday', function (assert) {
  8968. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  8969. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  8970. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  8971. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  8972. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  8973. });
  8974. test('weeks year starting tuesday', function (assert) {
  8975. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  8976. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  8977. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  8978. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  8979. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  8980. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  8981. });
  8982. test('weeks year starting wednesday', function (assert) {
  8983. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  8984. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  8985. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  8986. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  8987. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  8988. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  8989. });
  8990. test('weeks year starting thursday', function (assert) {
  8991. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  8992. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  8993. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  8994. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  8995. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  8996. assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3');
  8997. });
  8998. test('weeks year starting friday', function (assert) {
  8999. assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1');
  9000. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  9001. assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1');
  9002. assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2');
  9003. assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2');
  9004. assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3');
  9005. });
  9006. test('weeks year starting saturday', function (assert) {
  9007. assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1');
  9008. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  9009. assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1');
  9010. assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2');
  9011. assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2');
  9012. assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3');
  9013. });
  9014. test('weeks year starting sunday formatted', function (assert) {
  9015. assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1a', 'Dec 26 2011 should be week 1');
  9016. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1a', 'Jan 1 2012 should be week 1');
  9017. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2a', 'Jan 2 2012 should be week 2');
  9018. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2a', 'Jan 8 2012 should be week 2');
  9019. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3a', 'Jan 9 2012 should be week 3');
  9020. });
  9021. test('lenient ordinal parsing', function (assert) {
  9022. var i, ordinalStr, testMoment;
  9023. for (i = 1; i <= 31; ++i) {
  9024. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  9025. testMoment = moment(ordinalStr, 'YYYY MM Do');
  9026. assert.equal(testMoment.year(), 2014,
  9027. 'lenient ordinal parsing ' + i + ' year check');
  9028. assert.equal(testMoment.month(), 0,
  9029. 'lenient ordinal parsing ' + i + ' month check');
  9030. assert.equal(testMoment.date(), i,
  9031. 'lenient ordinal parsing ' + i + ' date check');
  9032. }
  9033. });
  9034. test('lenient ordinal parsing of number', function (assert) {
  9035. var i, testMoment;
  9036. for (i = 1; i <= 31; ++i) {
  9037. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  9038. assert.equal(testMoment.year(), 2014,
  9039. 'lenient ordinal parsing of number ' + i + ' year check');
  9040. assert.equal(testMoment.month(), 0,
  9041. 'lenient ordinal parsing of number ' + i + ' month check');
  9042. assert.equal(testMoment.date(), i,
  9043. 'lenient ordinal parsing of number ' + i + ' date check');
  9044. }
  9045. });
  9046. test('strict ordinal parsing', function (assert) {
  9047. var i, ordinalStr, testMoment;
  9048. for (i = 1; i <= 31; ++i) {
  9049. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  9050. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  9051. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  9052. }
  9053. });
  9054. }));
  9055. ;(function (global, factory) {
  9056. typeof exports === 'object' && typeof module !== 'undefined'
  9057. && typeof require === 'function' ? factory(require('../../moment')) :
  9058. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  9059. factory(global.moment)
  9060. }(this, function (moment) { 'use strict';
  9061. /*global QUnit:false*/
  9062. var test = QUnit.test;
  9063. var expect = QUnit.expect;
  9064. function module (name, lifecycle) {
  9065. QUnit.module(name, {
  9066. setup : function () {
  9067. moment.locale('en');
  9068. moment.createFromInputFallback = function (config) {
  9069. throw new Error('input not handled by moment: ' + config._i);
  9070. };
  9071. if (lifecycle && lifecycle.setup) {
  9072. lifecycle.setup();
  9073. }
  9074. },
  9075. teardown : function () {
  9076. if (lifecycle && lifecycle.teardown) {
  9077. lifecycle.teardown();
  9078. }
  9079. }
  9080. });
  9081. }
  9082. function localeModule (name, lifecycle) {
  9083. QUnit.module('locale:' + name, {
  9084. setup : function () {
  9085. moment.locale(name);
  9086. moment.createFromInputFallback = function (config) {
  9087. throw new Error('input not handled by moment: ' + config._i);
  9088. };
  9089. if (lifecycle && lifecycle.setup) {
  9090. lifecycle.setup();
  9091. }
  9092. },
  9093. teardown : function () {
  9094. moment.locale('en');
  9095. if (lifecycle && lifecycle.teardown) {
  9096. lifecycle.teardown();
  9097. }
  9098. }
  9099. });
  9100. }
  9101. localeModule('es');
  9102. test('parse', function (assert) {
  9103. var tests = 'enero ene._febrero feb._marzo mar._abril abr._mayo may._junio jun._julio jul._agosto ago._septiembre sep._octubre oct._noviembre nov._diciembre dic.'.split('_'), i;
  9104. function equalTest(input, mmm, i) {
  9105. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  9106. }
  9107. for (i = 0; i < 12; i++) {
  9108. tests[i] = tests[i].split(' ');
  9109. equalTest(tests[i][0], 'MMM', i);
  9110. equalTest(tests[i][1], 'MMM', i);
  9111. equalTest(tests[i][0], 'MMMM', i);
  9112. equalTest(tests[i][1], 'MMMM', i);
  9113. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  9114. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  9115. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  9116. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  9117. }
  9118. });
  9119. test('format', function (assert) {
  9120. var a = [
  9121. ['dddd, MMMM Do YYYY, h:mm:ss a', 'domingo, febrero 14º 2010, 3:25:50 pm'],
  9122. ['ddd, hA', 'dom., 3PM'],
  9123. ['M Mo MM MMMM MMM', '2 2º 02 febrero feb.'],
  9124. ['YYYY YY', '2010 10'],
  9125. ['D Do DD', '14 14º 14'],
  9126. ['d do dddd ddd dd', '0 0º domingo dom. do'],
  9127. ['DDD DDDo DDDD', '45 45º 045'],
  9128. ['w wo ww', '6 6º 06'],
  9129. ['YYYY-MMM-DD', '2010-feb-14'],
  9130. ['h hh', '3 03'],
  9131. ['H HH', '15 15'],
  9132. ['m mm', '25 25'],
  9133. ['s ss', '50 50'],
  9134. ['a A', 'pm PM'],
  9135. ['[the] DDDo [day of the year]', 'the 45º day of the year'],
  9136. ['LTS', '15:25:50'],
  9137. ['L', '14/02/2010'],
  9138. ['LL', '14 de febrero de 2010'],
  9139. ['LLL', '14 de febrero de 2010 15:25'],
  9140. ['LLLL', 'domingo, 14 de febrero de 2010 15:25'],
  9141. ['l', '14/2/2010'],
  9142. ['ll', '14 de feb. de 2010'],
  9143. ['lll', '14 de feb. de 2010 15:25'],
  9144. ['llll', 'dom., 14 de feb. de 2010 15:25']
  9145. ],
  9146. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  9147. i;
  9148. for (i = 0; i < a.length; i++) {
  9149. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  9150. }
  9151. });
  9152. test('format ordinal', function (assert) {
  9153. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1º', '1º');
  9154. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2º', '2º');
  9155. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3º', '3º');
  9156. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4º', '4º');
  9157. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5º', '5º');
  9158. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6º', '6º');
  9159. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7º', '7º');
  9160. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8º', '8º');
  9161. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9º', '9º');
  9162. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10º', '10º');
  9163. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11º', '11º');
  9164. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12º', '12º');
  9165. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13º', '13º');
  9166. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14º', '14º');
  9167. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15º', '15º');
  9168. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16º', '16º');
  9169. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17º', '17º');
  9170. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18º', '18º');
  9171. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19º', '19º');
  9172. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20º', '20º');
  9173. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21º', '21º');
  9174. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22º', '22º');
  9175. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23º', '23º');
  9176. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24º', '24º');
  9177. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25º', '25º');
  9178. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26º', '26º');
  9179. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27º', '27º');
  9180. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28º', '28º');
  9181. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29º', '29º');
  9182. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30º', '30º');
  9183. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31º', '31º');
  9184. });
  9185. test('format month', function (assert) {
  9186. var expected = 'enero ene._febrero feb._marzo mar._abril abr._mayo may._junio jun._julio jul._agosto ago._septiembre sep._octubre oct._noviembre nov._diciembre dic.'.split('_'), i;
  9187. for (i = 0; i < expected.length; i++) {
  9188. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  9189. }
  9190. });
  9191. test('format week', function (assert) {
  9192. var expected = 'domingo dom. do_lunes lun. lu_martes mar. ma_miércoles mié. mi_jueves jue. ju_viernes vie. vi_sábado sáb. sá'.split('_'), i;
  9193. for (i = 0; i < expected.length; i++) {
  9194. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  9195. }
  9196. });
  9197. test('from', function (assert) {
  9198. var start = moment([2007, 1, 28]);
  9199. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'unos segundos', '44 seconds = a few seconds');
  9200. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'un minuto', '45 seconds = a minute');
  9201. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'un minuto', '89 seconds = a minute');
  9202. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutos', '90 seconds = 2 minutes');
  9203. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutos', '44 minutes = 44 minutes');
  9204. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'una hora', '45 minutes = an hour');
  9205. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'una hora', '89 minutes = an hour');
  9206. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 horas', '90 minutes = 2 hours');
  9207. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 horas', '5 hours = 5 hours');
  9208. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 horas', '21 hours = 21 hours');
  9209. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'un día', '22 hours = a day');
  9210. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'un día', '35 hours = a day');
  9211. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 días', '36 hours = 2 days');
  9212. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'un día', '1 day = a day');
  9213. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 días', '5 days = 5 days');
  9214. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 días', '25 days = 25 days');
  9215. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'un mes', '26 days = a month');
  9216. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'un mes', '30 days = a month');
  9217. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'un mes', '43 days = a month');
  9218. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 meses', '46 days = 2 months');
  9219. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 meses', '75 days = 2 months');
  9220. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 meses', '76 days = 3 months');
  9221. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'un mes', '1 month = a month');
  9222. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 meses', '5 months = 5 months');
  9223. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'un año', '345 days = a year');
  9224. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 años', '548 days = 2 years');
  9225. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'un año', '1 year = a year');
  9226. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 años', '5 years = 5 years');
  9227. });
  9228. test('suffix', function (assert) {
  9229. assert.equal(moment(30000).from(0), 'en unos segundos', 'prefix');
  9230. assert.equal(moment(0).from(30000), 'hace unos segundos', 'suffix');
  9231. });
  9232. test('now from now', function (assert) {
  9233. assert.equal(moment().fromNow(), 'hace unos segundos', 'now from now should display as in the past');
  9234. });
  9235. test('fromNow', function (assert) {
  9236. assert.equal(moment().add({s: 30}).fromNow(), 'en unos segundos', 'en unos segundos');
  9237. assert.equal(moment().add({d: 5}).fromNow(), 'en 5 días', 'en 5 días');
  9238. });
  9239. test('calendar day', function (assert) {
  9240. var a = moment().hours(2).minutes(0).seconds(0);
  9241. assert.equal(moment(a).calendar(), 'hoy a las 2:00', 'today at the same time');
  9242. assert.equal(moment(a).add({m: 25}).calendar(), 'hoy a las 2:25', 'Now plus 25 min');
  9243. assert.equal(moment(a).add({h: 1}).calendar(), 'hoy a las 3:00', 'Now plus 1 hour');
  9244. assert.equal(moment(a).add({d: 1}).calendar(), 'mañana a las 2:00', 'tomorrow at the same time');
  9245. assert.equal(moment(a).add({d: 1, h : -1}).calendar(), 'mañana a la 1:00', 'tomorrow minus 1 hour');
  9246. assert.equal(moment(a).subtract({h: 1}).calendar(), 'hoy a la 1:00', 'Now minus 1 hour');
  9247. assert.equal(moment(a).subtract({d: 1}).calendar(), 'ayer a las 2:00', 'yesterday at the same time');
  9248. });
  9249. test('calendar next week', function (assert) {
  9250. var i, m;
  9251. for (i = 2; i < 7; i++) {
  9252. m = moment().add({d: i});
  9253. assert.equal(m.calendar(), m.format('dddd [a la' + ((m.hours() !== 1) ? 's' : '') + '] LT'), 'Today + ' + i + ' days current time');
  9254. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  9255. assert.equal(m.calendar(), m.format('dddd [a la' + ((m.hours() !== 1) ? 's' : '') + '] LT'), 'Today + ' + i + ' days beginning of day');
  9256. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  9257. assert.equal(m.calendar(), m.format('dddd [a la' + ((m.hours() !== 1) ? 's' : '') + '] LT'), 'Today + ' + i + ' days end of day');
  9258. }
  9259. });
  9260. test('calendar last week', function (assert) {
  9261. var i, m;
  9262. for (i = 2; i < 7; i++) {
  9263. m = moment().subtract({d: i});
  9264. assert.equal(m.calendar(), m.format('[el] dddd [pasado a la' + ((m.hours() !== 1) ? 's' : '') + '] LT'), 'Today - ' + i + ' days current time');
  9265. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  9266. assert.equal(m.calendar(), m.format('[el] dddd [pasado a la' + ((m.hours() !== 1) ? 's' : '') + '] LT'), 'Today - ' + i + ' days beginning of day');
  9267. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  9268. assert.equal(m.calendar(), m.format('[el] dddd [pasado a la' + ((m.hours() !== 1) ? 's' : '') + '] LT'), 'Today - ' + i + ' days end of day');
  9269. }
  9270. });
  9271. test('calendar all else', function (assert) {
  9272. var weeksAgo = moment().subtract({w: 1}),
  9273. weeksFromNow = moment().add({w: 1});
  9274. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  9275. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  9276. weeksAgo = moment().subtract({w: 2});
  9277. weeksFromNow = moment().add({w: 2});
  9278. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  9279. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  9280. });
  9281. test('weeks year starting sunday', function (assert) {
  9282. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  9283. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  9284. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  9285. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  9286. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  9287. });
  9288. test('weeks year starting monday', function (assert) {
  9289. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  9290. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  9291. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  9292. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  9293. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  9294. });
  9295. test('weeks year starting tuesday', function (assert) {
  9296. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  9297. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  9298. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  9299. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  9300. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  9301. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  9302. });
  9303. test('weeks year starting wednesday', function (assert) {
  9304. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  9305. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  9306. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  9307. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  9308. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  9309. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  9310. });
  9311. test('weeks year starting thursday', function (assert) {
  9312. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  9313. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  9314. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  9315. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  9316. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  9317. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  9318. });
  9319. test('weeks year starting friday', function (assert) {
  9320. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  9321. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  9322. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  9323. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  9324. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  9325. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  9326. });
  9327. test('weeks year starting saturday', function (assert) {
  9328. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  9329. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  9330. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  9331. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  9332. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  9333. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  9334. });
  9335. test('weeks year starting sunday formatted', function (assert) {
  9336. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52º', 'Jan 1 2012 should be week 52');
  9337. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1º', 'Jan 2 2012 should be week 1');
  9338. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1º', 'Jan 8 2012 should be week 1');
  9339. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2º', 'Jan 9 2012 should be week 2');
  9340. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2º', 'Jan 15 2012 should be week 2');
  9341. });
  9342. test('lenient ordinal parsing', function (assert) {
  9343. var i, ordinalStr, testMoment;
  9344. for (i = 1; i <= 31; ++i) {
  9345. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  9346. testMoment = moment(ordinalStr, 'YYYY MM Do');
  9347. assert.equal(testMoment.year(), 2014,
  9348. 'lenient ordinal parsing ' + i + ' year check');
  9349. assert.equal(testMoment.month(), 0,
  9350. 'lenient ordinal parsing ' + i + ' month check');
  9351. assert.equal(testMoment.date(), i,
  9352. 'lenient ordinal parsing ' + i + ' date check');
  9353. }
  9354. });
  9355. test('lenient ordinal parsing of number', function (assert) {
  9356. var i, testMoment;
  9357. for (i = 1; i <= 31; ++i) {
  9358. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  9359. assert.equal(testMoment.year(), 2014,
  9360. 'lenient ordinal parsing of number ' + i + ' year check');
  9361. assert.equal(testMoment.month(), 0,
  9362. 'lenient ordinal parsing of number ' + i + ' month check');
  9363. assert.equal(testMoment.date(), i,
  9364. 'lenient ordinal parsing of number ' + i + ' date check');
  9365. }
  9366. });
  9367. test('strict ordinal parsing', function (assert) {
  9368. var i, ordinalStr, testMoment;
  9369. for (i = 1; i <= 31; ++i) {
  9370. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  9371. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  9372. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  9373. }
  9374. });
  9375. }));
  9376. ;(function (global, factory) {
  9377. typeof exports === 'object' && typeof module !== 'undefined'
  9378. && typeof require === 'function' ? factory(require('../../moment')) :
  9379. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  9380. factory(global.moment)
  9381. }(this, function (moment) { 'use strict';
  9382. /*global QUnit:false*/
  9383. var test = QUnit.test;
  9384. var expect = QUnit.expect;
  9385. function module (name, lifecycle) {
  9386. QUnit.module(name, {
  9387. setup : function () {
  9388. moment.locale('en');
  9389. moment.createFromInputFallback = function (config) {
  9390. throw new Error('input not handled by moment: ' + config._i);
  9391. };
  9392. if (lifecycle && lifecycle.setup) {
  9393. lifecycle.setup();
  9394. }
  9395. },
  9396. teardown : function () {
  9397. if (lifecycle && lifecycle.teardown) {
  9398. lifecycle.teardown();
  9399. }
  9400. }
  9401. });
  9402. }
  9403. function localeModule (name, lifecycle) {
  9404. QUnit.module('locale:' + name, {
  9405. setup : function () {
  9406. moment.locale(name);
  9407. moment.createFromInputFallback = function (config) {
  9408. throw new Error('input not handled by moment: ' + config._i);
  9409. };
  9410. if (lifecycle && lifecycle.setup) {
  9411. lifecycle.setup();
  9412. }
  9413. },
  9414. teardown : function () {
  9415. moment.locale('en');
  9416. if (lifecycle && lifecycle.teardown) {
  9417. lifecycle.teardown();
  9418. }
  9419. }
  9420. });
  9421. }
  9422. localeModule('et');
  9423. test('parse', function (assert) {
  9424. var tests = 'jaanuar jaan_veebruar veebr_märts märts_aprill apr_mai mai_juuni juuni_juuli juuli_august aug_september sept_oktoober okt_november nov_detsember dets'.split('_'), i;
  9425. function equalTest(input, mmm, i) {
  9426. assert.equal(moment(input, mmm).month(), i, input + ' peaks olema kuu ' + (i + 1));
  9427. }
  9428. for (i = 0; i < 12; i++) {
  9429. tests[i] = tests[i].split(' ');
  9430. equalTest(tests[i][0], 'MMM', i);
  9431. equalTest(tests[i][1], 'MMM', i);
  9432. equalTest(tests[i][0], 'MMMM', i);
  9433. equalTest(tests[i][1], 'MMMM', i);
  9434. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  9435. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  9436. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  9437. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  9438. }
  9439. });
  9440. test('format', function (assert) {
  9441. var a = [
  9442. ['dddd, Do MMMM YYYY, H:mm:ss', 'pühapäev, 14. veebruar 2010, 15:25:50'],
  9443. ['ddd, h', 'P, 3'],
  9444. ['M Mo MM MMMM MMM', '2 2. 02 veebruar veebr'],
  9445. ['YYYY YY', '2010 10'],
  9446. ['D Do DD', '14 14. 14'],
  9447. ['d do dddd ddd dd', '0 0. pühapäev P P'],
  9448. ['DDD DDDo DDDD', '45 45. 045'],
  9449. ['w wo ww', '6 6. 06'],
  9450. ['h hh', '3 03'],
  9451. ['H HH', '15 15'],
  9452. ['m mm', '25 25'],
  9453. ['s ss', '50 50'],
  9454. ['a A', 'pm PM'],
  9455. ['[aasta] DDDo [päev]', 'aasta 45. päev'],
  9456. ['LTS', '15:25:50'],
  9457. ['L', '14.02.2010'],
  9458. ['LL', '14. veebruar 2010'],
  9459. ['LLL', '14. veebruar 2010 15:25'],
  9460. ['LLLL', 'pühapäev, 14. veebruar 2010 15:25'],
  9461. ['l', '14.2.2010'],
  9462. ['ll', '14. veebr 2010'],
  9463. ['lll', '14. veebr 2010 15:25'],
  9464. ['llll', 'P, 14. veebr 2010 15:25']
  9465. ],
  9466. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  9467. i;
  9468. for (i = 0; i < a.length; i++) {
  9469. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  9470. }
  9471. });
  9472. test('format ordinal', function (assert) {
  9473. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
  9474. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
  9475. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
  9476. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
  9477. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
  9478. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
  9479. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
  9480. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
  9481. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
  9482. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
  9483. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
  9484. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
  9485. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
  9486. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
  9487. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
  9488. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
  9489. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
  9490. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
  9491. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
  9492. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
  9493. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
  9494. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
  9495. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
  9496. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
  9497. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
  9498. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
  9499. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
  9500. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
  9501. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
  9502. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
  9503. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
  9504. });
  9505. test('format month', function (assert) {
  9506. var expected = 'jaanuar jaan_veebruar veebr_märts märts_aprill apr_mai mai_juuni juuni_juuli juuli_august aug_september sept_oktoober okt_november nov_detsember dets'.split('_'), i;
  9507. for (i = 0; i < expected.length; i++) {
  9508. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  9509. }
  9510. });
  9511. test('format week', function (assert) {
  9512. var expected = 'pühapäev P P_esmaspäev E E_teisipäev T T_kolmapäev K K_neljapäev N N_reede R R_laupäev L L'.split('_'), i;
  9513. for (i = 0; i < expected.length; i++) {
  9514. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  9515. }
  9516. });
  9517. test('from', function (assert) {
  9518. var start = moment([2007, 1, 28]);
  9519. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'paar sekundit', '44 seconds = paar sekundit');
  9520. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'üks minut', '45 seconds = üks minut');
  9521. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'üks minut', '89 seconds = üks minut');
  9522. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutit', '90 seconds = 2 minutit');
  9523. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutit', '44 minutes = 44 minutit');
  9524. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'üks tund', '45 minutes = tund aega');
  9525. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'üks tund', '89 minutes = üks tund');
  9526. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 tundi', '90 minutes = 2 tundi');
  9527. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 tundi', '5 hours = 5 tundi');
  9528. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 tundi', '21 hours = 21 tundi');
  9529. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'üks päev', '22 hours = üks päev');
  9530. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'üks päev', '35 hours = üks päev');
  9531. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 päeva', '36 hours = 2 päeva');
  9532. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'üks päev', '1 day = üks päev');
  9533. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 päeva', '5 days = 5 päeva');
  9534. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 päeva', '25 days = 25 päeva');
  9535. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'üks kuu', '26 days = üks kuu');
  9536. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'üks kuu', '30 days = üks kuu');
  9537. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'üks kuu', '43 days = üks kuu');
  9538. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 kuud', '46 days = 2 kuud');
  9539. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 kuud', '75 days = 2 kuud');
  9540. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 kuud', '76 days = 3 kuud');
  9541. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'üks kuu', '1 month = üks kuu');
  9542. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 kuud', '5 months = 5 kuud');
  9543. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'üks aasta', '345 days = üks aasta');
  9544. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 aastat', '548 days = 2 aastat');
  9545. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'üks aasta', '1 year = üks aasta');
  9546. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 aastat', '5 years = 5 aastat');
  9547. });
  9548. test('suffix', function (assert) {
  9549. assert.equal(moment(30000).from(0), 'mõne sekundi pärast', 'prefix');
  9550. assert.equal(moment(0).from(30000), 'mõni sekund tagasi', 'suffix');
  9551. });
  9552. test('now from now', function (assert) {
  9553. assert.equal(moment().fromNow(), 'mõni sekund tagasi', 'now from now should display as in the past');
  9554. });
  9555. test('fromNow', function (assert) {
  9556. assert.equal(moment().add({s: 30}).fromNow(), 'mõne sekundi pärast', 'in a few seconds');
  9557. assert.equal(moment().subtract({s: 30}).fromNow(), 'mõni sekund tagasi', 'a few seconds ago');
  9558. assert.equal(moment().add({m: 1}).fromNow(), 'ühe minuti pärast', 'in a minute');
  9559. assert.equal(moment().subtract({m: 1}).fromNow(), 'üks minut tagasi', 'a minute ago');
  9560. assert.equal(moment().add({m: 5}).fromNow(), '5 minuti pärast', 'in 5 minutes');
  9561. assert.equal(moment().subtract({m: 5}).fromNow(), '5 minutit tagasi', '5 minutes ago');
  9562. assert.equal(moment().add({d: 1}).fromNow(), 'ühe päeva pärast', 'in one day');
  9563. assert.equal(moment().subtract({d: 1}).fromNow(), 'üks päev tagasi', 'one day ago');
  9564. assert.equal(moment().add({d: 5}).fromNow(), '5 päeva pärast', 'in 5 days');
  9565. assert.equal(moment().subtract({d: 5}).fromNow(), '5 päeva tagasi', '5 days ago');
  9566. assert.equal(moment().add({M: 1}).fromNow(), 'kuu aja pärast', 'in a month');
  9567. assert.equal(moment().subtract({M: 1}).fromNow(), 'kuu aega tagasi', 'a month ago');
  9568. assert.equal(moment().add({M: 5}).fromNow(), '5 kuu pärast', 'in 5 months');
  9569. assert.equal(moment().subtract({M: 5}).fromNow(), '5 kuud tagasi', '5 months ago');
  9570. assert.equal(moment().add({y: 1}).fromNow(), 'ühe aasta pärast', 'in a year');
  9571. assert.equal(moment().subtract({y: 1}).fromNow(), 'aasta tagasi', 'a year ago');
  9572. assert.equal(moment().add({y: 5}).fromNow(), '5 aasta pärast', 'in 5 years');
  9573. assert.equal(moment().subtract({y: 5}).fromNow(), '5 aastat tagasi', '5 years ago');
  9574. });
  9575. test('calendar day', function (assert) {
  9576. var a = moment().hours(2).minutes(0).seconds(0);
  9577. assert.equal(moment(a).calendar(), 'Täna, 2:00', 'today at the same time');
  9578. assert.equal(moment(a).add({m: 25}).calendar(), 'Täna, 2:25', 'Now plus 25 min');
  9579. assert.equal(moment(a).add({h: 1}).calendar(), 'Täna, 3:00', 'Now plus 1 hour');
  9580. assert.equal(moment(a).add({d: 1}).calendar(), 'Homme, 2:00', 'tomorrow at the same time');
  9581. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Täna, 1:00', 'Now minus 1 hour');
  9582. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Eile, 2:00', 'yesterday at the same time');
  9583. });
  9584. test('calendar next week', function (assert) {
  9585. var i, m;
  9586. for (i = 2; i < 7; i++) {
  9587. m = moment().add({d: i});
  9588. assert.equal(m.calendar(), m.format('[Järgmine] dddd LT'), 'Today + ' + i + ' days current time');
  9589. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  9590. assert.equal(m.calendar(), m.format('[Järgmine] dddd LT'), 'Today + ' + i + ' days beginning of day');
  9591. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  9592. assert.equal(m.calendar(), m.format('[Järgmine] dddd LT'), 'Today + ' + i + ' days end of day');
  9593. }
  9594. });
  9595. test('calendar last week', function (assert) {
  9596. var i, m;
  9597. for (i = 2; i < 7; i++) {
  9598. m = moment().subtract({d: i});
  9599. assert.equal(m.calendar(), m.format('[Eelmine] dddd LT'), 'Today - ' + i + ' days current time');
  9600. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  9601. assert.equal(m.calendar(), m.format('[Eelmine] dddd LT'), 'Today - ' + i + ' days beginning of day');
  9602. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  9603. assert.equal(m.calendar(), m.format('[Eelmine] dddd LT'), 'Today - ' + i + ' days end of day');
  9604. }
  9605. });
  9606. test('calendar all else', function (assert) {
  9607. var weeksAgo = moment().subtract({w: 1}),
  9608. weeksFromNow = moment().add({w: 1});
  9609. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 nädal tagasi');
  9610. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), '1 nädala pärast');
  9611. weeksAgo = moment().subtract({w: 2});
  9612. weeksFromNow = moment().add({w: 2});
  9613. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 nädalat tagasi');
  9614. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), '2 nädala pärast');
  9615. });
  9616. test('weeks year starting sunday', function (assert) {
  9617. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  9618. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  9619. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  9620. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  9621. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  9622. });
  9623. test('weeks year starting monday', function (assert) {
  9624. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  9625. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  9626. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  9627. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  9628. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  9629. });
  9630. test('weeks year starting tuesday', function (assert) {
  9631. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  9632. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  9633. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  9634. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  9635. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  9636. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  9637. });
  9638. test('weeks year starting wednesday', function (assert) {
  9639. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  9640. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  9641. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  9642. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  9643. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  9644. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  9645. });
  9646. test('weeks year starting thursday', function (assert) {
  9647. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  9648. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  9649. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  9650. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  9651. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  9652. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  9653. });
  9654. test('weeks year starting friday', function (assert) {
  9655. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  9656. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  9657. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  9658. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  9659. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  9660. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  9661. });
  9662. test('weeks year starting saturday', function (assert) {
  9663. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  9664. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  9665. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  9666. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  9667. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  9668. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  9669. });
  9670. test('weeks year starting sunday formatted', function (assert) {
  9671. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
  9672. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
  9673. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
  9674. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
  9675. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
  9676. });
  9677. test('lenient ordinal parsing', function (assert) {
  9678. var i, ordinalStr, testMoment;
  9679. for (i = 1; i <= 31; ++i) {
  9680. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  9681. testMoment = moment(ordinalStr, 'YYYY MM Do');
  9682. assert.equal(testMoment.year(), 2014,
  9683. 'lenient ordinal parsing ' + i + ' year check');
  9684. assert.equal(testMoment.month(), 0,
  9685. 'lenient ordinal parsing ' + i + ' month check');
  9686. assert.equal(testMoment.date(), i,
  9687. 'lenient ordinal parsing ' + i + ' date check');
  9688. }
  9689. });
  9690. test('lenient ordinal parsing of number', function (assert) {
  9691. var i, testMoment;
  9692. for (i = 1; i <= 31; ++i) {
  9693. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  9694. assert.equal(testMoment.year(), 2014,
  9695. 'lenient ordinal parsing of number ' + i + ' year check');
  9696. assert.equal(testMoment.month(), 0,
  9697. 'lenient ordinal parsing of number ' + i + ' month check');
  9698. assert.equal(testMoment.date(), i,
  9699. 'lenient ordinal parsing of number ' + i + ' date check');
  9700. }
  9701. });
  9702. test('strict ordinal parsing', function (assert) {
  9703. var i, ordinalStr, testMoment;
  9704. for (i = 1; i <= 31; ++i) {
  9705. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  9706. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  9707. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  9708. }
  9709. });
  9710. }));
  9711. ;(function (global, factory) {
  9712. typeof exports === 'object' && typeof module !== 'undefined'
  9713. && typeof require === 'function' ? factory(require('../../moment')) :
  9714. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  9715. factory(global.moment)
  9716. }(this, function (moment) { 'use strict';
  9717. /*global QUnit:false*/
  9718. var test = QUnit.test;
  9719. var expect = QUnit.expect;
  9720. function module (name, lifecycle) {
  9721. QUnit.module(name, {
  9722. setup : function () {
  9723. moment.locale('en');
  9724. moment.createFromInputFallback = function (config) {
  9725. throw new Error('input not handled by moment: ' + config._i);
  9726. };
  9727. if (lifecycle && lifecycle.setup) {
  9728. lifecycle.setup();
  9729. }
  9730. },
  9731. teardown : function () {
  9732. if (lifecycle && lifecycle.teardown) {
  9733. lifecycle.teardown();
  9734. }
  9735. }
  9736. });
  9737. }
  9738. function localeModule (name, lifecycle) {
  9739. QUnit.module('locale:' + name, {
  9740. setup : function () {
  9741. moment.locale(name);
  9742. moment.createFromInputFallback = function (config) {
  9743. throw new Error('input not handled by moment: ' + config._i);
  9744. };
  9745. if (lifecycle && lifecycle.setup) {
  9746. lifecycle.setup();
  9747. }
  9748. },
  9749. teardown : function () {
  9750. moment.locale('en');
  9751. if (lifecycle && lifecycle.teardown) {
  9752. lifecycle.teardown();
  9753. }
  9754. }
  9755. });
  9756. }
  9757. localeModule('eu');
  9758. test('parse', function (assert) {
  9759. var tests = 'urtarrila urt._otsaila ots._martxoa mar._apirila api._maiatza mai._ekaina eka._uztaila uzt._abuztua abu._iraila ira._urria urr._azaroa aza._abendua abe.'.split('_'), i;
  9760. function equalTest(input, mmm, i) {
  9761. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  9762. }
  9763. for (i = 0; i < 12; i++) {
  9764. tests[i] = tests[i].split(' ');
  9765. equalTest(tests[i][0], 'MMM', i);
  9766. equalTest(tests[i][1], 'MMM', i);
  9767. equalTest(tests[i][0], 'MMMM', i);
  9768. equalTest(tests[i][1], 'MMMM', i);
  9769. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  9770. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  9771. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  9772. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  9773. }
  9774. });
  9775. test('format', function (assert) {
  9776. var a = [
  9777. ['dddd, MMMM Do YYYY, h:mm:ss a', 'igandea, otsaila 14. 2010, 3:25:50 pm'],
  9778. ['ddd, hA', 'ig., 3PM'],
  9779. ['M Mo MM MMMM MMM', '2 2. 02 otsaila ots.'],
  9780. ['YYYY YY', '2010 10'],
  9781. ['D Do DD', '14 14. 14'],
  9782. ['d do dddd ddd dd', '0 0. igandea ig. ig'],
  9783. ['DDD DDDo DDDD', '45 45. 045'],
  9784. ['w wo ww', '7 7. 07'],
  9785. ['h hh', '3 03'],
  9786. ['H HH', '15 15'],
  9787. ['m mm', '25 25'],
  9788. ['s ss', '50 50'],
  9789. ['a A', 'pm PM'],
  9790. ['[the] DDDo [day of the year]', 'the 45. day of the year'],
  9791. ['LTS', '15:25:50'],
  9792. ['L', '2010-02-14'],
  9793. ['LL', '2010ko otsailaren 14a'],
  9794. ['LLL', '2010ko otsailaren 14a 15:25'],
  9795. ['LLLL', 'igandea, 2010ko otsailaren 14a 15:25'],
  9796. ['l', '2010-2-14'],
  9797. ['ll', '2010ko ots. 14a'],
  9798. ['lll', '2010ko ots. 14a 15:25'],
  9799. ['llll', 'ig., 2010ko ots. 14a 15:25']
  9800. ],
  9801. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  9802. i;
  9803. for (i = 0; i < a.length; i++) {
  9804. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  9805. }
  9806. });
  9807. test('format ordinal', function (assert) {
  9808. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
  9809. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
  9810. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
  9811. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
  9812. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
  9813. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
  9814. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
  9815. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
  9816. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
  9817. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
  9818. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
  9819. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
  9820. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
  9821. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
  9822. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
  9823. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
  9824. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
  9825. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
  9826. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
  9827. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
  9828. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
  9829. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
  9830. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
  9831. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
  9832. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
  9833. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
  9834. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
  9835. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
  9836. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
  9837. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
  9838. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
  9839. });
  9840. test('format month', function (assert) {
  9841. var expected = 'urtarrila urt._otsaila ots._martxoa mar._apirila api._maiatza mai._ekaina eka._uztaila uzt._abuztua abu._iraila ira._urria urr._azaroa aza._abendua abe.'.split('_'), i;
  9842. for (i = 0; i < expected.length; i++) {
  9843. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  9844. }
  9845. });
  9846. test('format week', function (assert) {
  9847. var expected = 'igandea ig. ig_astelehena al. al_asteartea ar. ar_asteazkena az. az_osteguna og. og_ostirala ol. ol_larunbata lr. lr'.split('_'), i;
  9848. for (i = 0; i < expected.length; i++) {
  9849. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  9850. }
  9851. });
  9852. test('from', function (assert) {
  9853. var start = moment([2007, 1, 28]);
  9854. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'segundo batzuk', '44 seconds = a few seconds');
  9855. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'minutu bat', '45 seconds = a minute');
  9856. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'minutu bat', '89 seconds = a minute');
  9857. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutu', '90 seconds = 2 minutes');
  9858. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutu', '44 minutes = 44 minutes');
  9859. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ordu bat', '45 minutes = an hour');
  9860. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ordu bat', '89 minutes = an hour');
  9861. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 ordu', '90 minutes = 2 hours');
  9862. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ordu', '5 hours = 5 hours');
  9863. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 ordu', '21 hours = 21 hours');
  9864. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'egun bat', '22 hours = a day');
  9865. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'egun bat', '35 hours = a day');
  9866. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 egun', '36 hours = 2 days');
  9867. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'egun bat', '1 day = a day');
  9868. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 egun', '5 days = 5 days');
  9869. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 egun', '25 days = 25 days');
  9870. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'hilabete bat', '26 days = a month');
  9871. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'hilabete bat', '30 days = a month');
  9872. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'hilabete bat', '43 days = a month');
  9873. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 hilabete', '46 days = 2 months');
  9874. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 hilabete', '75 days = 2 months');
  9875. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 hilabete', '76 days = 3 months');
  9876. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'hilabete bat', '1 month = a month');
  9877. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 hilabete', '5 months = 5 months');
  9878. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'urte bat', '345 days = a year');
  9879. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 urte', '548 days = 2 years');
  9880. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'urte bat', '1 year = a year');
  9881. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 urte', '5 years = 5 years');
  9882. });
  9883. test('suffix', function (assert) {
  9884. assert.equal(moment(30000).from(0), 'segundo batzuk barru', 'prefix');
  9885. assert.equal(moment(0).from(30000), 'duela segundo batzuk', 'suffix');
  9886. });
  9887. test('now from now', function (assert) {
  9888. assert.equal(moment().fromNow(), 'duela segundo batzuk', 'now from now should display as in the past');
  9889. });
  9890. test('fromNow', function (assert) {
  9891. assert.equal(moment().add({s: 30}).fromNow(), 'segundo batzuk barru', 'in seconds');
  9892. assert.equal(moment().add({d: 5}).fromNow(), '5 egun barru', 'in 5 days');
  9893. });
  9894. test('calendar day', function (assert) {
  9895. var a = moment().hours(2).minutes(0).seconds(0);
  9896. assert.equal(moment(a).calendar(), 'gaur 02:00etan', 'today at the same time');
  9897. assert.equal(moment(a).add({m: 25}).calendar(), 'gaur 02:25etan', 'now plus 25 min');
  9898. assert.equal(moment(a).add({h: 1}).calendar(), 'gaur 03:00etan', 'now plus 1 hour');
  9899. assert.equal(moment(a).add({d: 1}).calendar(), 'bihar 02:00etan', 'tomorrow at the same time');
  9900. assert.equal(moment(a).subtract({h: 1}).calendar(), 'gaur 01:00etan', 'now minus 1 hour');
  9901. assert.equal(moment(a).subtract({d: 1}).calendar(), 'atzo 02:00etan', 'yesterday at the same time');
  9902. });
  9903. test('calendar next week', function (assert) {
  9904. var i, m;
  9905. for (i = 2; i < 7; i++) {
  9906. m = moment().add({d: i});
  9907. assert.equal(m.calendar(), m.format('dddd LT[etan]'), 'Today + ' + i + ' days current time');
  9908. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  9909. assert.equal(m.calendar(), m.format('dddd LT[etan]'), 'Today + ' + i + ' days beginning of day');
  9910. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  9911. assert.equal(m.calendar(), m.format('dddd LT[etan]'), 'Today + ' + i + ' days end of day');
  9912. }
  9913. });
  9914. test('calendar last week', function (assert) {
  9915. var i, m;
  9916. for (i = 2; i < 7; i++) {
  9917. m = moment().subtract({d: i});
  9918. assert.equal(m.calendar(), m.format('[aurreko] dddd LT[etan]'), 'Today - ' + i + ' days current time');
  9919. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  9920. assert.equal(m.calendar(), m.format('[aurreko] dddd LT[etan]'), 'Today - ' + i + ' days beginning of day');
  9921. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  9922. assert.equal(m.calendar(), m.format('[aurreko] dddd LT[etan]'), 'Today - ' + i + ' days end of day');
  9923. }
  9924. });
  9925. test('calendar all else', function (assert) {
  9926. var weeksAgo = moment().subtract({w: 1}),
  9927. weeksFromNow = moment().add({w: 1});
  9928. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  9929. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  9930. weeksAgo = moment().subtract({w: 2});
  9931. weeksFromNow = moment().add({w: 2});
  9932. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  9933. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  9934. });
  9935. test('weeks year starting sunday', function (assert) {
  9936. assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1');
  9937. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  9938. assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2');
  9939. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  9940. assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3');
  9941. });
  9942. test('weeks year starting monday', function (assert) {
  9943. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  9944. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  9945. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  9946. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  9947. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  9948. });
  9949. test('weeks year starting tuesday', function (assert) {
  9950. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  9951. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  9952. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  9953. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  9954. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  9955. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  9956. });
  9957. test('weeks year starting wednesday', function (assert) {
  9958. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  9959. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  9960. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  9961. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  9962. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  9963. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  9964. });
  9965. test('weeks year starting thursday', function (assert) {
  9966. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  9967. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  9968. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  9969. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  9970. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  9971. assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3');
  9972. });
  9973. test('weeks year starting friday', function (assert) {
  9974. assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1');
  9975. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  9976. assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1');
  9977. assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2');
  9978. assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2');
  9979. assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3');
  9980. });
  9981. test('weeks year starting saturday', function (assert) {
  9982. assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1');
  9983. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  9984. assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1');
  9985. assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2');
  9986. assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2');
  9987. assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3');
  9988. });
  9989. test('weeks year starting sunday formatted', function (assert) {
  9990. assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1.', 'Dec 26 2011 should be week 1');
  9991. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1.', 'Jan 1 2012 should be week 1');
  9992. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2.', 'Jan 2 2012 should be week 2');
  9993. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2.', 'Jan 8 2012 should be week 2');
  9994. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3.', 'Jan 9 2012 should be week 3');
  9995. });
  9996. test('lenient ordinal parsing', function (assert) {
  9997. var i, ordinalStr, testMoment;
  9998. for (i = 1; i <= 31; ++i) {
  9999. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  10000. testMoment = moment(ordinalStr, 'YYYY MM Do');
  10001. assert.equal(testMoment.year(), 2014,
  10002. 'lenient ordinal parsing ' + i + ' year check');
  10003. assert.equal(testMoment.month(), 0,
  10004. 'lenient ordinal parsing ' + i + ' month check');
  10005. assert.equal(testMoment.date(), i,
  10006. 'lenient ordinal parsing ' + i + ' date check');
  10007. }
  10008. });
  10009. test('lenient ordinal parsing of number', function (assert) {
  10010. var i, testMoment;
  10011. for (i = 1; i <= 31; ++i) {
  10012. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  10013. assert.equal(testMoment.year(), 2014,
  10014. 'lenient ordinal parsing of number ' + i + ' year check');
  10015. assert.equal(testMoment.month(), 0,
  10016. 'lenient ordinal parsing of number ' + i + ' month check');
  10017. assert.equal(testMoment.date(), i,
  10018. 'lenient ordinal parsing of number ' + i + ' date check');
  10019. }
  10020. });
  10021. test('strict ordinal parsing', function (assert) {
  10022. var i, ordinalStr, testMoment;
  10023. for (i = 1; i <= 31; ++i) {
  10024. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  10025. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  10026. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  10027. }
  10028. });
  10029. }));
  10030. ;(function (global, factory) {
  10031. typeof exports === 'object' && typeof module !== 'undefined'
  10032. && typeof require === 'function' ? factory(require('../../moment')) :
  10033. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  10034. factory(global.moment)
  10035. }(this, function (moment) { 'use strict';
  10036. /*global QUnit:false*/
  10037. var test = QUnit.test;
  10038. var expect = QUnit.expect;
  10039. function module (name, lifecycle) {
  10040. QUnit.module(name, {
  10041. setup : function () {
  10042. moment.locale('en');
  10043. moment.createFromInputFallback = function (config) {
  10044. throw new Error('input not handled by moment: ' + config._i);
  10045. };
  10046. if (lifecycle && lifecycle.setup) {
  10047. lifecycle.setup();
  10048. }
  10049. },
  10050. teardown : function () {
  10051. if (lifecycle && lifecycle.teardown) {
  10052. lifecycle.teardown();
  10053. }
  10054. }
  10055. });
  10056. }
  10057. function localeModule (name, lifecycle) {
  10058. QUnit.module('locale:' + name, {
  10059. setup : function () {
  10060. moment.locale(name);
  10061. moment.createFromInputFallback = function (config) {
  10062. throw new Error('input not handled by moment: ' + config._i);
  10063. };
  10064. if (lifecycle && lifecycle.setup) {
  10065. lifecycle.setup();
  10066. }
  10067. },
  10068. teardown : function () {
  10069. moment.locale('en');
  10070. if (lifecycle && lifecycle.teardown) {
  10071. lifecycle.teardown();
  10072. }
  10073. }
  10074. });
  10075. }
  10076. localeModule('fa');
  10077. test('parse', function (assert) {
  10078. var tests = 'ژانویه_فوریه_مارس_آوریل_مه_ژوئن_ژوئیه_اوت_سپتامبر_اکتبر_نوامبر_دسامبر'.split('_'), i;
  10079. function equalTest(input, mmm, i) {
  10080. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1) + ' instead is month ' + moment(input, mmm).month());
  10081. }
  10082. for (i = 0; i < 12; i++) {
  10083. equalTest(tests[i], 'MMM', i);
  10084. equalTest(tests[i], 'MMMM', i);
  10085. }
  10086. });
  10087. test('format', function (assert) {
  10088. var a = [
  10089. ['dddd, MMMM Do YYYY, h:mm:ss a', 'یک\u200cشنبه، فوریه ۱۴م ۲۰۱۰، ۳:۲۵:۵۰ بعد از ظهر'],
  10090. ['ddd, hA', 'یک\u200cشنبه، ۳بعد از ظهر'],
  10091. ['M Mo MM MMMM MMM', '۲ ۲م ۰۲ فوریه فوریه'],
  10092. ['YYYY YY', '۲۰۱۰ ۱۰'],
  10093. ['D Do DD', '۱۴ ۱۴م ۱۴'],
  10094. ['d do dddd ddd dd', '۰ ۰م یک\u200cشنبه یک\u200cشنبه ی'],
  10095. ['DDD DDDo DDDD', '۴۵ ۴۵م ۰۴۵'],
  10096. ['w wo ww', '۸ ۸م ۰۸'],
  10097. ['h hh', '۳ ۰۳'],
  10098. ['H HH', '۱۵ ۱۵'],
  10099. ['m mm', '۲۵ ۲۵'],
  10100. ['s ss', '۵۰ ۵۰'],
  10101. ['a A', 'بعد از ظهر بعد از ظهر'],
  10102. ['DDDo [روز سال]', '۴۵م روز سال'],
  10103. ['LTS', '۱۵:۲۵:۵۰'],
  10104. ['L', '۱۴/۰۲/۲۰۱۰'],
  10105. ['LL', '۱۴ فوریه ۲۰۱۰'],
  10106. ['LLL', '۱۴ فوریه ۲۰۱۰ ۱۵:۲۵'],
  10107. ['LLLL', 'یک\u200cشنبه، ۱۴ فوریه ۲۰۱۰ ۱۵:۲۵'],
  10108. ['l', '۱۴/۲/۲۰۱۰'],
  10109. ['ll', '۱۴ فوریه ۲۰۱۰'],
  10110. ['lll', '۱۴ فوریه ۲۰۱۰ ۱۵:۲۵'],
  10111. ['llll', 'یک\u200cشنبه، ۱۴ فوریه ۲۰۱۰ ۱۵:۲۵']
  10112. ],
  10113. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  10114. i;
  10115. for (i = 0; i < a.length; i++) {
  10116. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  10117. }
  10118. });
  10119. test('format ordinal', function (assert) {
  10120. assert.equal(moment([2011, 0, 1]).format('DDDo'), '۱م', '1');
  10121. assert.equal(moment([2011, 0, 2]).format('DDDo'), '۲م', '2');
  10122. assert.equal(moment([2011, 0, 3]).format('DDDo'), '۳م', '3');
  10123. assert.equal(moment([2011, 0, 4]).format('DDDo'), '۴م', '4');
  10124. assert.equal(moment([2011, 0, 5]).format('DDDo'), '۵م', '5');
  10125. assert.equal(moment([2011, 0, 6]).format('DDDo'), '۶م', '6');
  10126. assert.equal(moment([2011, 0, 7]).format('DDDo'), '۷م', '7');
  10127. assert.equal(moment([2011, 0, 8]).format('DDDo'), '۸م', '8');
  10128. assert.equal(moment([2011, 0, 9]).format('DDDo'), '۹م', '9');
  10129. assert.equal(moment([2011, 0, 10]).format('DDDo'), '۱۰م', '10');
  10130. assert.equal(moment([2011, 0, 11]).format('DDDo'), '۱۱م', '11');
  10131. assert.equal(moment([2011, 0, 12]).format('DDDo'), '۱۲م', '12');
  10132. assert.equal(moment([2011, 0, 13]).format('DDDo'), '۱۳م', '13');
  10133. assert.equal(moment([2011, 0, 14]).format('DDDo'), '۱۴م', '14');
  10134. assert.equal(moment([2011, 0, 15]).format('DDDo'), '۱۵م', '15');
  10135. assert.equal(moment([2011, 0, 16]).format('DDDo'), '۱۶م', '16');
  10136. assert.equal(moment([2011, 0, 17]).format('DDDo'), '۱۷م', '17');
  10137. assert.equal(moment([2011, 0, 18]).format('DDDo'), '۱۸م', '18');
  10138. assert.equal(moment([2011, 0, 19]).format('DDDo'), '۱۹م', '19');
  10139. assert.equal(moment([2011, 0, 20]).format('DDDo'), '۲۰م', '20');
  10140. assert.equal(moment([2011, 0, 21]).format('DDDo'), '۲۱م', '21');
  10141. assert.equal(moment([2011, 0, 22]).format('DDDo'), '۲۲م', '22');
  10142. assert.equal(moment([2011, 0, 23]).format('DDDo'), '۲۳م', '23');
  10143. assert.equal(moment([2011, 0, 24]).format('DDDo'), '۲۴م', '24');
  10144. assert.equal(moment([2011, 0, 25]).format('DDDo'), '۲۵م', '25');
  10145. assert.equal(moment([2011, 0, 26]).format('DDDo'), '۲۶م', '26');
  10146. assert.equal(moment([2011, 0, 27]).format('DDDo'), '۲۷م', '27');
  10147. assert.equal(moment([2011, 0, 28]).format('DDDo'), '۲۸م', '28');
  10148. assert.equal(moment([2011, 0, 29]).format('DDDo'), '۲۹م', '29');
  10149. assert.equal(moment([2011, 0, 30]).format('DDDo'), '۳۰م', '30');
  10150. assert.equal(moment([2011, 0, 31]).format('DDDo'), '۳۱م', '31');
  10151. });
  10152. test('format month', function (assert) {
  10153. var expected = 'ژانویه ژانویه_فوریه فوریه_مارس مارس_آوریل آوریل_مه مه_ژوئن ژوئن_ژوئیه ژوئیه_اوت اوت_سپتامبر سپتامبر_اکتبر اکتبر_نوامبر نوامبر_دسامبر دسامبر'.split('_'), i;
  10154. for (i = 0; i < expected.length; i++) {
  10155. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  10156. }
  10157. });
  10158. test('format week', function (assert) {
  10159. var expected = 'یک\u200cشنبه یک\u200cشنبه ی_دوشنبه دوشنبه د_سه\u200cشنبه سه\u200cشنبه س_چهارشنبه چهارشنبه چ_پنج\u200cشنبه پنج\u200cشنبه پ_جمعه جمعه ج_شنبه شنبه ش'.split('_'), i;
  10160. for (i = 0; i < expected.length; i++) {
  10161. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  10162. }
  10163. });
  10164. test('from', function (assert) {
  10165. var start = moment([2007, 1, 28]);
  10166. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'چندین ثانیه', '44 seconds = a few seconds');
  10167. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'یک دقیقه', '45 seconds = a minute');
  10168. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'یک دقیقه', '89 seconds = a minute');
  10169. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '۲ دقیقه', '90 seconds = 2 minutes');
  10170. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '۴۴ دقیقه', '44 minutes = 44 minutes');
  10171. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'یک ساعت', '45 minutes = an hour');
  10172. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'یک ساعت', '89 minutes = an hour');
  10173. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '۲ ساعت', '90 minutes = 2 hours');
  10174. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '۵ ساعت', '5 hours = 5 hours');
  10175. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '۲۱ ساعت', '21 hours = 21 hours');
  10176. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'یک روز', '22 hours = a day');
  10177. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'یک روز', '35 hours = a day');
  10178. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '۲ روز', '36 hours = 2 days');
  10179. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'یک روز', '1 day = a day');
  10180. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '۵ روز', '5 days = 5 days');
  10181. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '۲۵ روز', '25 days = 25 days');
  10182. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'یک ماه', '26 days = a month');
  10183. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'یک ماه', '30 days = a month');
  10184. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'یک ماه', '43 days = a month');
  10185. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '۲ ماه', '46 days = 2 months');
  10186. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '۲ ماه', '75 days = 2 months');
  10187. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '۳ ماه', '76 days = 3 months');
  10188. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'یک ماه', '1 month = a month');
  10189. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '۵ ماه', '5 months = 5 months');
  10190. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'یک سال', '345 days = a year');
  10191. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '۲ سال', '548 days = 2 years');
  10192. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'یک سال', '1 year = a year');
  10193. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '۵ سال', '5 years = 5 years');
  10194. });
  10195. test('suffix', function (assert) {
  10196. assert.equal(moment(30000).from(0), 'در چندین ثانیه', 'prefix');
  10197. assert.equal(moment(0).from(30000), 'چندین ثانیه پیش', 'suffix');
  10198. });
  10199. test('now from now', function (assert) {
  10200. assert.equal(moment().fromNow(), 'چندین ثانیه پیش', 'now from now should display as in the past');
  10201. });
  10202. test('fromNow', function (assert) {
  10203. assert.equal(moment().add({s: 30}).fromNow(), 'در چندین ثانیه', 'in a few seconds');
  10204. assert.equal(moment().add({d: 5}).fromNow(), 'در ۵ روز', 'in 5 days');
  10205. });
  10206. test('calendar day', function (assert) {
  10207. var a = moment().hours(2).minutes(0).seconds(0);
  10208. assert.equal(moment(a).calendar(), 'امروز ساعت ۰۲:۰۰', 'today at the same time');
  10209. assert.equal(moment(a).add({m: 25}).calendar(), 'امروز ساعت ۰۲:۲۵', 'Now plus 25 min');
  10210. assert.equal(moment(a).add({h: 1}).calendar(), 'امروز ساعت ۰۳:۰۰', 'Now plus 1 hour');
  10211. assert.equal(moment(a).add({d: 1}).calendar(), 'فردا ساعت ۰۲:۰۰', 'tomorrow at the same time');
  10212. assert.equal(moment(a).subtract({h: 1}).calendar(), 'امروز ساعت ۰۱:۰۰', 'Now minus 1 hour');
  10213. assert.equal(moment(a).subtract({d: 1}).calendar(), 'دیروز ساعت ۰۲:۰۰', 'yesterday at the same time');
  10214. });
  10215. test('calendar next week', function (assert) {
  10216. var i, m;
  10217. for (i = 2; i < 7; i++) {
  10218. m = moment().add({d: i});
  10219. assert.equal(m.calendar(), m.format('dddd [ساعت] LT'), 'Today + ' + i + ' days current time');
  10220. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  10221. assert.equal(m.calendar(), m.format('dddd [ساعت] LT'), 'Today + ' + i + ' days beginning of day');
  10222. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  10223. assert.equal(m.calendar(), m.format('dddd [ساعت] LT'), 'Today + ' + i + ' days end of day');
  10224. }
  10225. });
  10226. test('calendar last week', function (assert) {
  10227. var i, m;
  10228. for (i = 2; i < 7; i++) {
  10229. m = moment().subtract({d: i});
  10230. assert.equal(m.calendar(), m.format('dddd [پیش ساعت] LT'), 'Today - ' + i + ' days current time');
  10231. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  10232. assert.equal(m.calendar(), m.format('dddd [پیش ساعت] LT'), 'Today - ' + i + ' days beginning of day');
  10233. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  10234. assert.equal(m.calendar(), m.format('dddd [پیش ساعت] LT'), 'Today - ' + i + ' days end of day');
  10235. }
  10236. });
  10237. test('calendar all else', function (assert) {
  10238. var weeksAgo = moment().subtract({w: 1}),
  10239. weeksFromNow = moment().add({w: 1});
  10240. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  10241. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  10242. weeksAgo = moment().subtract({w: 2});
  10243. weeksFromNow = moment().add({w: 2});
  10244. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  10245. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  10246. });
  10247. test('weeks year starting sunday', function (assert) {
  10248. assert.equal(moment([2011, 11, 31]).week(), 1, 'Dec 31 2011 should be week 1');
  10249. assert.equal(moment([2012, 0, 6]).week(), 1, 'Jan 6 2012 should be week 1');
  10250. assert.equal(moment([2012, 0, 7]).week(), 2, 'Jan 7 2012 should be week 2');
  10251. assert.equal(moment([2012, 0, 13]).week(), 2, 'Jan 13 2012 should be week 2');
  10252. assert.equal(moment([2012, 0, 14]).week(), 3, 'Jan 14 2012 should be week 3');
  10253. });
  10254. test('weeks year starting monday', function (assert) {
  10255. assert.equal(moment([2006, 11, 30]).week(), 1, 'Dec 30 2006 should be week 1');
  10256. assert.equal(moment([2007, 0, 5]).week(), 1, 'Jan 5 2007 should be week 1');
  10257. assert.equal(moment([2007, 0, 6]).week(), 2, 'Jan 6 2007 should be week 2');
  10258. assert.equal(moment([2007, 0, 12]).week(), 2, 'Jan 12 2007 should be week 2');
  10259. assert.equal(moment([2007, 0, 13]).week(), 3, 'Jan 13 2007 should be week 3');
  10260. });
  10261. test('weeks year starting tuesday', function (assert) {
  10262. assert.equal(moment([2007, 11, 29]).week(), 1, 'Dec 29 2007 should be week 1');
  10263. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  10264. assert.equal(moment([2008, 0, 4]).week(), 1, 'Jan 4 2008 should be week 1');
  10265. assert.equal(moment([2008, 0, 5]).week(), 2, 'Jan 5 2008 should be week 2');
  10266. assert.equal(moment([2008, 0, 11]).week(), 2, 'Jan 11 2008 should be week 2');
  10267. assert.equal(moment([2008, 0, 12]).week(), 3, 'Jan 12 2008 should be week 3');
  10268. });
  10269. test('weeks year starting wednesday', function (assert) {
  10270. assert.equal(moment([2002, 11, 28]).week(), 1, 'Dec 28 2002 should be week 1');
  10271. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  10272. assert.equal(moment([2003, 0, 3]).week(), 1, 'Jan 3 2003 should be week 1');
  10273. assert.equal(moment([2003, 0, 4]).week(), 2, 'Jan 4 2003 should be week 2');
  10274. assert.equal(moment([2003, 0, 10]).week(), 2, 'Jan 10 2003 should be week 2');
  10275. assert.equal(moment([2003, 0, 11]).week(), 3, 'Jan 11 2003 should be week 3');
  10276. });
  10277. test('weeks year starting thursday', function (assert) {
  10278. assert.equal(moment([2008, 11, 27]).week(), 1, 'Dec 27 2008 should be week 1');
  10279. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  10280. assert.equal(moment([2009, 0, 2]).week(), 1, 'Jan 2 2009 should be week 1');
  10281. assert.equal(moment([2009, 0, 3]).week(), 2, 'Jan 3 2009 should be week 2');
  10282. assert.equal(moment([2009, 0, 9]).week(), 2, 'Jan 9 2009 should be week 2');
  10283. assert.equal(moment([2009, 0, 10]).week(), 3, 'Jan 10 2009 should be week 3');
  10284. });
  10285. test('weeks year starting friday', function (assert) {
  10286. assert.equal(moment([2009, 11, 26]).week(), 1, 'Dec 26 2009 should be week 1');
  10287. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  10288. assert.equal(moment([2010, 0, 2]).week(), 2, 'Jan 2 2010 should be week 2');
  10289. assert.equal(moment([2010, 0, 8]).week(), 2, 'Jan 8 2010 should be week 2');
  10290. assert.equal(moment([2010, 0, 9]).week(), 3, 'Jan 9 2010 should be week 3');
  10291. });
  10292. test('weeks year starting saturday', function (assert) {
  10293. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  10294. assert.equal(moment([2011, 0, 7]).week(), 1, 'Jan 7 2011 should be week 1');
  10295. assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2');
  10296. assert.equal(moment([2011, 0, 14]).week(), 2, 'Jan 14 2011 should be week 2');
  10297. assert.equal(moment([2011, 0, 15]).week(), 3, 'Jan 15 2011 should be week 3');
  10298. });
  10299. test('weeks year starting sunday formatted', function (assert) {
  10300. assert.equal(moment([2011, 11, 31]).format('w ww wo'), '۱ ۰۱ ۱م', 'Dec 31 2011 should be week 1');
  10301. assert.equal(moment([2012, 0, 6]).format('w ww wo'), '۱ ۰۱ ۱م', 'Jan 6 2012 should be week 1');
  10302. assert.equal(moment([2012, 0, 7]).format('w ww wo'), '۲ ۰۲ ۲م', 'Jan 7 2012 should be week 2');
  10303. assert.equal(moment([2012, 0, 13]).format('w ww wo'), '۲ ۰۲ ۲م', 'Jan 13 2012 should be week 2');
  10304. assert.equal(moment([2012, 0, 14]).format('w ww wo'), '۳ ۰۳ ۳م', 'Jan 14 2012 should be week 3');
  10305. });
  10306. test('lenient ordinal parsing', function (assert) {
  10307. var i, ordinalStr, testMoment;
  10308. for (i = 1; i <= 31; ++i) {
  10309. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  10310. testMoment = moment(ordinalStr, 'YYYY MM Do');
  10311. assert.equal(testMoment.year(), 2014,
  10312. 'lenient ordinal parsing ' + i + ' year check');
  10313. assert.equal(testMoment.month(), 0,
  10314. 'lenient ordinal parsing ' + i + ' month check');
  10315. assert.equal(testMoment.date(), i,
  10316. 'lenient ordinal parsing ' + i + ' date check');
  10317. }
  10318. });
  10319. test('lenient ordinal parsing of number', function (assert) {
  10320. var i, testMoment;
  10321. for (i = 1; i <= 31; ++i) {
  10322. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  10323. assert.equal(testMoment.year(), 2014,
  10324. 'lenient ordinal parsing of number ' + i + ' year check');
  10325. assert.equal(testMoment.month(), 0,
  10326. 'lenient ordinal parsing of number ' + i + ' month check');
  10327. assert.equal(testMoment.date(), i,
  10328. 'lenient ordinal parsing of number ' + i + ' date check');
  10329. }
  10330. });
  10331. test('strict ordinal parsing', function (assert) {
  10332. var i, ordinalStr, testMoment;
  10333. for (i = 1; i <= 31; ++i) {
  10334. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  10335. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  10336. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  10337. }
  10338. });
  10339. }));
  10340. ;(function (global, factory) {
  10341. typeof exports === 'object' && typeof module !== 'undefined'
  10342. && typeof require === 'function' ? factory(require('../../moment')) :
  10343. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  10344. factory(global.moment)
  10345. }(this, function (moment) { 'use strict';
  10346. /*global QUnit:false*/
  10347. var test = QUnit.test;
  10348. var expect = QUnit.expect;
  10349. function module (name, lifecycle) {
  10350. QUnit.module(name, {
  10351. setup : function () {
  10352. moment.locale('en');
  10353. moment.createFromInputFallback = function (config) {
  10354. throw new Error('input not handled by moment: ' + config._i);
  10355. };
  10356. if (lifecycle && lifecycle.setup) {
  10357. lifecycle.setup();
  10358. }
  10359. },
  10360. teardown : function () {
  10361. if (lifecycle && lifecycle.teardown) {
  10362. lifecycle.teardown();
  10363. }
  10364. }
  10365. });
  10366. }
  10367. function localeModule (name, lifecycle) {
  10368. QUnit.module('locale:' + name, {
  10369. setup : function () {
  10370. moment.locale(name);
  10371. moment.createFromInputFallback = function (config) {
  10372. throw new Error('input not handled by moment: ' + config._i);
  10373. };
  10374. if (lifecycle && lifecycle.setup) {
  10375. lifecycle.setup();
  10376. }
  10377. },
  10378. teardown : function () {
  10379. moment.locale('en');
  10380. if (lifecycle && lifecycle.teardown) {
  10381. lifecycle.teardown();
  10382. }
  10383. }
  10384. });
  10385. }
  10386. localeModule('fi');
  10387. test('parse', function (assert) {
  10388. var tests = 'tammikuu tammi_helmikuu helmi_maaliskuu maalis_huhtikuu huhti_toukokuu touko_kesäkuu kesä_heinäkuu heinä_elokuu elo_syyskuu syys_lokakuu loka_marraskuu marras_joulukuu joulu'.split('_'), i;
  10389. function equalTest(input, mmm, i) {
  10390. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  10391. }
  10392. for (i = 0; i < 12; i++) {
  10393. tests[i] = tests[i].split(' ');
  10394. equalTest(tests[i][0], 'MMM', i);
  10395. equalTest(tests[i][1], 'MMM', i);
  10396. equalTest(tests[i][0], 'MMMM', i);
  10397. equalTest(tests[i][1], 'MMMM', i);
  10398. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  10399. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  10400. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  10401. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  10402. }
  10403. });
  10404. test('format', function (assert) {
  10405. var a = [
  10406. ['dddd, MMMM Do YYYY, h:mm:ss a', 'sunnuntai, helmikuu 14. 2010, 3:25:50 pm'],
  10407. ['ddd, hA', 'su, 3PM'],
  10408. ['M Mo MM MMMM MMM', '2 2. 02 helmikuu helmi'],
  10409. ['YYYY YY', '2010 10'],
  10410. ['D Do DD', '14 14. 14'],
  10411. ['d do dddd ddd dd', '0 0. sunnuntai su su'],
  10412. ['DDD DDDo DDDD', '45 45. 045'],
  10413. ['w wo ww', '6 6. 06'],
  10414. ['h hh', '3 03'],
  10415. ['H HH', '15 15'],
  10416. ['m mm', '25 25'],
  10417. ['s ss', '50 50'],
  10418. ['a A', 'pm PM'],
  10419. ['[vuoden] DDDo [päivä]', 'vuoden 45. päivä'],
  10420. ['LTS', '15.25.50'],
  10421. ['L', '14.02.2010'],
  10422. ['LL', '14. helmikuuta 2010'],
  10423. ['LLL', '14. helmikuuta 2010, klo 15.25'],
  10424. ['LLLL', 'sunnuntai, 14. helmikuuta 2010, klo 15.25'],
  10425. ['l', '14.2.2010'],
  10426. ['ll', '14. helmi 2010'],
  10427. ['lll', '14. helmi 2010, klo 15.25'],
  10428. ['llll', 'su, 14. helmi 2010, klo 15.25']
  10429. ],
  10430. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  10431. i;
  10432. for (i = 0; i < a.length; i++) {
  10433. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  10434. }
  10435. });
  10436. test('format ordinal', function (assert) {
  10437. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1st');
  10438. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2nd');
  10439. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3rd');
  10440. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4th');
  10441. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5th');
  10442. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6th');
  10443. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7th');
  10444. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8th');
  10445. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9th');
  10446. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10th');
  10447. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11th');
  10448. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12th');
  10449. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13th');
  10450. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14th');
  10451. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15th');
  10452. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16th');
  10453. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17th');
  10454. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18th');
  10455. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19th');
  10456. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20th');
  10457. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21st');
  10458. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22nd');
  10459. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23rd');
  10460. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24th');
  10461. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25th');
  10462. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26th');
  10463. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27th');
  10464. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28th');
  10465. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29th');
  10466. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30th');
  10467. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31st');
  10468. });
  10469. test('format month', function (assert) {
  10470. var expected = 'tammikuu tammi_helmikuu helmi_maaliskuu maalis_huhtikuu huhti_toukokuu touko_kesäkuu kesä_heinäkuu heinä_elokuu elo_syyskuu syys_lokakuu loka_marraskuu marras_joulukuu joulu'.split('_'), i;
  10471. for (i = 0; i < expected.length; i++) {
  10472. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  10473. }
  10474. });
  10475. test('format week', function (assert) {
  10476. var expected = 'sunnuntai su su_maanantai ma ma_tiistai ti ti_keskiviikko ke ke_torstai to to_perjantai pe pe_lauantai la la'.split('_'), i;
  10477. for (i = 0; i < expected.length; i++) {
  10478. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  10479. }
  10480. });
  10481. test('from', function (assert) {
  10482. var start = moment([2007, 1, 28]);
  10483. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'muutama sekunti', '44 seconds = few seconds');
  10484. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'minuutti', '45 seconds = a minute');
  10485. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'minuutti', '89 seconds = a minute');
  10486. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), 'kaksi minuuttia', '90 seconds = 2 minutes');
  10487. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuuttia', '44 minutes = 44 minutes');
  10488. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'tunti', '45 minutes = an hour');
  10489. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'tunti', '89 minutes = an hour');
  10490. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), 'kaksi tuntia', '90 minutes = 2 hours');
  10491. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), 'viisi tuntia', '5 hours = 5 hours');
  10492. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 tuntia', '21 hours = 21 hours');
  10493. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'päivä', '22 hours = a day');
  10494. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'päivä', '35 hours = a day');
  10495. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), 'kaksi päivää', '36 hours = 2 days');
  10496. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'päivä', '1 day = a day');
  10497. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), 'viisi päivää', '5 days = 5 days');
  10498. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 päivää', '25 days = 25 days');
  10499. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'kuukausi', '26 days = a month');
  10500. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'kuukausi', '30 days = a month');
  10501. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'kuukausi', '43 days = a month');
  10502. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), 'kaksi kuukautta', '46 days = 2 months');
  10503. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), 'kaksi kuukautta', '75 days = 2 months');
  10504. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), 'kolme kuukautta', '76 days = 3 months');
  10505. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'kuukausi', '1 month = a month');
  10506. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), 'viisi kuukautta', '5 months = 5 months');
  10507. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'vuosi', '345 days = a year');
  10508. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), 'kaksi vuotta', '548 days = 2 years');
  10509. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'vuosi', '1 year = a year');
  10510. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), 'viisi vuotta', '5 years = 5 years');
  10511. });
  10512. test('suffix', function (assert) {
  10513. assert.equal(moment(30000).from(0), 'muutaman sekunnin päästä', 'prefix');
  10514. assert.equal(moment(0).from(30000), 'muutama sekunti sitten', 'suffix');
  10515. });
  10516. test('now from now', function (assert) {
  10517. assert.equal(moment().fromNow(), 'muutama sekunti sitten', 'now from now should display as in the past');
  10518. });
  10519. test('fromNow', function (assert) {
  10520. assert.equal(moment().add({s: 30}).fromNow(), 'muutaman sekunnin päästä', 'in a few seconds');
  10521. assert.equal(moment().add({d: 5}).fromNow(), 'viiden päivän päästä', 'in 5 days');
  10522. });
  10523. test('calendar day', function (assert) {
  10524. var a = moment().hours(2).minutes(0).seconds(0);
  10525. assert.equal(moment(a).calendar(), 'tänään klo 02.00', 'today at the same time');
  10526. assert.equal(moment(a).add({m: 25}).calendar(), 'tänään klo 02.25', 'Now plus 25 min');
  10527. assert.equal(moment(a).add({h: 1}).calendar(), 'tänään klo 03.00', 'Now plus 1 hour');
  10528. assert.equal(moment(a).add({d: 1}).calendar(), 'huomenna klo 02.00', 'tomorrow at the same time');
  10529. assert.equal(moment(a).subtract({h: 1}).calendar(), 'tänään klo 01.00', 'Now minus 1 hour');
  10530. assert.equal(moment(a).subtract({d: 1}).calendar(), 'eilen klo 02.00', 'yesterday at the same time');
  10531. });
  10532. test('calendar next week', function (assert) {
  10533. var i, m;
  10534. for (i = 2; i < 7; i++) {
  10535. m = moment().add({d: i});
  10536. assert.equal(m.calendar(), m.format('dddd [klo] LT'), 'today + ' + i + ' days current time');
  10537. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  10538. assert.equal(m.calendar(), m.format('dddd [klo] LT'), 'today + ' + i + ' days beginning of day');
  10539. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  10540. assert.equal(m.calendar(), m.format('dddd [klo] LT'), 'today + ' + i + ' days end of day');
  10541. }
  10542. });
  10543. test('calendar last week', function (assert) {
  10544. var i, m;
  10545. for (i = 2; i < 7; i++) {
  10546. m = moment().subtract({d: i});
  10547. assert.equal(m.calendar(), m.format('[viime] dddd[na] [klo] LT'), 'today - ' + i + ' days current time');
  10548. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  10549. assert.equal(m.calendar(), m.format('[viime] dddd[na] [klo] LT'), 'today - ' + i + ' days beginning of day');
  10550. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  10551. assert.equal(m.calendar(), m.format('[viime] dddd[na] [klo] LT'), 'today - ' + i + ' days end of day');
  10552. }
  10553. });
  10554. test('calendar all else', function (assert) {
  10555. var weeksAgo = moment().subtract({w: 1}),
  10556. weeksFromNow = moment().add({w: 1});
  10557. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), 'yksi viikko sitten');
  10558. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'yhden viikon päästä');
  10559. weeksAgo = moment().subtract({w: 2});
  10560. weeksFromNow = moment().add({w: 2});
  10561. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), 'kaksi viikkoa sitten');
  10562. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'kaden viikon päästä');
  10563. });
  10564. test('weeks year starting sunday', function (assert) {
  10565. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  10566. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  10567. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  10568. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  10569. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  10570. });
  10571. test('weeks year starting monday', function (assert) {
  10572. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  10573. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  10574. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  10575. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  10576. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  10577. });
  10578. test('weeks year starting tuesday', function (assert) {
  10579. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  10580. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  10581. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  10582. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  10583. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  10584. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  10585. });
  10586. test('weeks year starting wednesday', function (assert) {
  10587. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  10588. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  10589. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  10590. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  10591. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  10592. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  10593. });
  10594. test('weeks year starting thursday', function (assert) {
  10595. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  10596. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  10597. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  10598. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  10599. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  10600. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  10601. });
  10602. test('weeks year starting friday', function (assert) {
  10603. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  10604. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  10605. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  10606. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  10607. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  10608. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  10609. });
  10610. test('weeks year starting saturday', function (assert) {
  10611. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  10612. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  10613. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  10614. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  10615. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  10616. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  10617. });
  10618. test('weeks year starting sunday formatted', function (assert) {
  10619. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
  10620. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
  10621. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
  10622. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
  10623. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
  10624. });
  10625. test('lenient ordinal parsing', function (assert) {
  10626. var i, ordinalStr, testMoment;
  10627. for (i = 1; i <= 31; ++i) {
  10628. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  10629. testMoment = moment(ordinalStr, 'YYYY MM Do');
  10630. assert.equal(testMoment.year(), 2014,
  10631. 'lenient ordinal parsing ' + i + ' year check');
  10632. assert.equal(testMoment.month(), 0,
  10633. 'lenient ordinal parsing ' + i + ' month check');
  10634. assert.equal(testMoment.date(), i,
  10635. 'lenient ordinal parsing ' + i + ' date check');
  10636. }
  10637. });
  10638. test('lenient ordinal parsing of number', function (assert) {
  10639. var i, testMoment;
  10640. for (i = 1; i <= 31; ++i) {
  10641. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  10642. assert.equal(testMoment.year(), 2014,
  10643. 'lenient ordinal parsing of number ' + i + ' year check');
  10644. assert.equal(testMoment.month(), 0,
  10645. 'lenient ordinal parsing of number ' + i + ' month check');
  10646. assert.equal(testMoment.date(), i,
  10647. 'lenient ordinal parsing of number ' + i + ' date check');
  10648. }
  10649. });
  10650. test('strict ordinal parsing', function (assert) {
  10651. var i, ordinalStr, testMoment;
  10652. for (i = 1; i <= 31; ++i) {
  10653. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  10654. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  10655. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  10656. }
  10657. });
  10658. }));
  10659. ;(function (global, factory) {
  10660. typeof exports === 'object' && typeof module !== 'undefined'
  10661. && typeof require === 'function' ? factory(require('../../moment')) :
  10662. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  10663. factory(global.moment)
  10664. }(this, function (moment) { 'use strict';
  10665. /*global QUnit:false*/
  10666. var test = QUnit.test;
  10667. var expect = QUnit.expect;
  10668. function module (name, lifecycle) {
  10669. QUnit.module(name, {
  10670. setup : function () {
  10671. moment.locale('en');
  10672. moment.createFromInputFallback = function (config) {
  10673. throw new Error('input not handled by moment: ' + config._i);
  10674. };
  10675. if (lifecycle && lifecycle.setup) {
  10676. lifecycle.setup();
  10677. }
  10678. },
  10679. teardown : function () {
  10680. if (lifecycle && lifecycle.teardown) {
  10681. lifecycle.teardown();
  10682. }
  10683. }
  10684. });
  10685. }
  10686. function localeModule (name, lifecycle) {
  10687. QUnit.module('locale:' + name, {
  10688. setup : function () {
  10689. moment.locale(name);
  10690. moment.createFromInputFallback = function (config) {
  10691. throw new Error('input not handled by moment: ' + config._i);
  10692. };
  10693. if (lifecycle && lifecycle.setup) {
  10694. lifecycle.setup();
  10695. }
  10696. },
  10697. teardown : function () {
  10698. moment.locale('en');
  10699. if (lifecycle && lifecycle.teardown) {
  10700. lifecycle.teardown();
  10701. }
  10702. }
  10703. });
  10704. }
  10705. localeModule('fo');
  10706. test('parse', function (assert) {
  10707. var tests = 'januar jan_februar feb_mars mar_apríl apr_mai mai_juni jun_juli jul_august aug_september sep_oktober okt_november nov_desember des'.split('_'), i;
  10708. function equalTest(input, mmm, i) {
  10709. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  10710. }
  10711. for (i = 0; i < 12; i++) {
  10712. tests[i] = tests[i].split(' ');
  10713. equalTest(tests[i][0], 'MMM', i);
  10714. equalTest(tests[i][1], 'MMM', i);
  10715. equalTest(tests[i][0], 'MMMM', i);
  10716. equalTest(tests[i][1], 'MMMM', i);
  10717. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  10718. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  10719. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  10720. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  10721. }
  10722. });
  10723. test('format', function (assert) {
  10724. var a = [
  10725. ['dddd [tann] Do MMMM YYYY, h:mm:ss a', 'sunnudagur tann 14. februar 2010, 3:25:50 pm'],
  10726. ['ddd hA', 'sun 3PM'],
  10727. ['M Mo MM MMMM MMM', '2 2. 02 februar feb'],
  10728. ['YYYY YY', '2010 10'],
  10729. ['D Do DD', '14 14. 14'],
  10730. ['d do dddd ddd dd', '0 0. sunnudagur sun su'],
  10731. ['DDD DDDo DDDD', '45 45. 045'],
  10732. ['w wo ww', '6 6. 06'],
  10733. ['h hh', '3 03'],
  10734. ['H HH', '15 15'],
  10735. ['m mm', '25 25'],
  10736. ['s ss', '50 50'],
  10737. ['a A', 'pm PM'],
  10738. ['[tann] DDDo [dagin á árinum]', 'tann 45. dagin á árinum'],
  10739. ['LTS', '15:25:50'],
  10740. ['L', '14/02/2010'],
  10741. ['LL', '14 februar 2010'],
  10742. ['LLL', '14 februar 2010 15:25'],
  10743. ['LLLL', 'sunnudagur 14. februar, 2010 15:25'],
  10744. ['l', '14/2/2010'],
  10745. ['ll', '14 feb 2010'],
  10746. ['lll', '14 feb 2010 15:25'],
  10747. ['llll', 'sun 14. feb, 2010 15:25']
  10748. ],
  10749. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  10750. i;
  10751. for (i = 0; i < a.length; i++) {
  10752. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  10753. }
  10754. });
  10755. test('format ordinal', function (assert) {
  10756. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
  10757. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
  10758. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
  10759. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
  10760. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
  10761. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
  10762. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
  10763. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
  10764. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
  10765. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
  10766. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
  10767. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
  10768. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
  10769. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
  10770. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
  10771. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
  10772. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
  10773. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
  10774. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
  10775. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
  10776. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
  10777. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
  10778. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
  10779. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
  10780. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
  10781. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
  10782. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
  10783. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
  10784. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
  10785. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
  10786. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
  10787. });
  10788. test('format month', function (assert) {
  10789. var expected = 'januar jan_februar feb_mars mar_apríl apr_mai mai_juni jun_juli jul_august aug_september sep_oktober okt_november nov_desember des'.split('_'), i;
  10790. for (i = 0; i < expected.length; i++) {
  10791. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  10792. }
  10793. });
  10794. test('format week', function (assert) {
  10795. var expected = 'sunnudagur sun su_mánadagur mán má_týsdagur týs tý_mikudagur mik mi_hósdagur hós hó_fríggjadagur frí fr_leygardagur ley le'.split('_'), i;
  10796. for (i = 0; i < expected.length; i++) {
  10797. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  10798. }
  10799. });
  10800. test('from', function (assert) {
  10801. var start = moment([2007, 1, 28]);
  10802. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'fá sekund', '44 seconds = a few seconds');
  10803. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'ein minutt', '45 seconds = a minute');
  10804. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'ein minutt', '89 seconds = a minute');
  10805. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuttir', '90 seconds = 2 minutes');
  10806. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuttir', '44 minutes = 44 minutes');
  10807. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ein tími', '45 minutes = an hour');
  10808. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ein tími', '89 minutes = an hour');
  10809. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 tímar', '90 minutes = 2 hours');
  10810. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 tímar', '5 hours = 5 hours');
  10811. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 tímar', '21 hours = 21 hours');
  10812. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ein dagur', '22 hours = a day');
  10813. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ein dagur', '35 hours = a day');
  10814. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dagar', '36 hours = 2 days');
  10815. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ein dagur', '1 day = a day');
  10816. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dagar', '5 days = 5 days');
  10817. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dagar', '25 days = 25 days');
  10818. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ein mánaði', '26 days = a month');
  10819. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ein mánaði', '30 days = a month');
  10820. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ein mánaði', '43 days = a month');
  10821. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mánaðir', '46 days = 2 months');
  10822. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mánaðir', '75 days = 2 months');
  10823. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mánaðir', '76 days = 3 months');
  10824. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ein mánaði', '1 month = a month');
  10825. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mánaðir', '5 months = 5 months');
  10826. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'eitt ár', '345 days = a year');
  10827. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 ár', '548 days = 2 years');
  10828. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'eitt ár', '1 year = a year');
  10829. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 ár', '5 years = 5 years');
  10830. });
  10831. test('suffix', function (assert) {
  10832. assert.equal(moment(30000).from(0), 'um fá sekund', 'prefix');
  10833. assert.equal(moment(0).from(30000), 'fá sekund síðani', 'suffix');
  10834. });
  10835. test('now from now', function (assert) {
  10836. assert.equal(moment().fromNow(), 'fá sekund síðani', 'now from now should display as in the past');
  10837. });
  10838. test('fromNow', function (assert) {
  10839. assert.equal(moment().add({s: 30}).fromNow(), 'um fá sekund', 'in a few seconds');
  10840. assert.equal(moment().add({d: 5}).fromNow(), 'um 5 dagar', 'in 5 days');
  10841. });
  10842. test('weeks year starting sunday', function (assert) {
  10843. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  10844. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  10845. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  10846. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  10847. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  10848. });
  10849. test('weeks year starting monday', function (assert) {
  10850. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  10851. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  10852. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  10853. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  10854. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  10855. });
  10856. test('weeks year starting tuesday', function (assert) {
  10857. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  10858. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  10859. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  10860. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  10861. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  10862. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  10863. });
  10864. test('weeks year starting wednesday', function (assert) {
  10865. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  10866. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  10867. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  10868. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  10869. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  10870. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  10871. });
  10872. test('weeks year starting thursday', function (assert) {
  10873. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  10874. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  10875. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  10876. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  10877. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  10878. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  10879. });
  10880. test('weeks year starting friday', function (assert) {
  10881. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  10882. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  10883. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  10884. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  10885. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  10886. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  10887. });
  10888. test('weeks year starting saturday', function (assert) {
  10889. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  10890. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  10891. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  10892. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  10893. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  10894. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  10895. });
  10896. test('weeks year starting sunday formatted', function (assert) {
  10897. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
  10898. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
  10899. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
  10900. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
  10901. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
  10902. });
  10903. test('lenient ordinal parsing', function (assert) {
  10904. var i, ordinalStr, testMoment;
  10905. for (i = 1; i <= 31; ++i) {
  10906. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  10907. testMoment = moment(ordinalStr, 'YYYY MM Do');
  10908. assert.equal(testMoment.year(), 2014,
  10909. 'lenient ordinal parsing ' + i + ' year check');
  10910. assert.equal(testMoment.month(), 0,
  10911. 'lenient ordinal parsing ' + i + ' month check');
  10912. assert.equal(testMoment.date(), i,
  10913. 'lenient ordinal parsing ' + i + ' date check');
  10914. }
  10915. });
  10916. test('lenient ordinal parsing of number', function (assert) {
  10917. var i, testMoment;
  10918. for (i = 1; i <= 31; ++i) {
  10919. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  10920. assert.equal(testMoment.year(), 2014,
  10921. 'lenient ordinal parsing of number ' + i + ' year check');
  10922. assert.equal(testMoment.month(), 0,
  10923. 'lenient ordinal parsing of number ' + i + ' month check');
  10924. assert.equal(testMoment.date(), i,
  10925. 'lenient ordinal parsing of number ' + i + ' date check');
  10926. }
  10927. });
  10928. test('strict ordinal parsing', function (assert) {
  10929. var i, ordinalStr, testMoment;
  10930. for (i = 1; i <= 31; ++i) {
  10931. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  10932. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  10933. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  10934. }
  10935. });
  10936. }));
  10937. ;(function (global, factory) {
  10938. typeof exports === 'object' && typeof module !== 'undefined'
  10939. && typeof require === 'function' ? factory(require('../../moment')) :
  10940. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  10941. factory(global.moment)
  10942. }(this, function (moment) { 'use strict';
  10943. /*global QUnit:false*/
  10944. var test = QUnit.test;
  10945. var expect = QUnit.expect;
  10946. function module (name, lifecycle) {
  10947. QUnit.module(name, {
  10948. setup : function () {
  10949. moment.locale('en');
  10950. moment.createFromInputFallback = function (config) {
  10951. throw new Error('input not handled by moment: ' + config._i);
  10952. };
  10953. if (lifecycle && lifecycle.setup) {
  10954. lifecycle.setup();
  10955. }
  10956. },
  10957. teardown : function () {
  10958. if (lifecycle && lifecycle.teardown) {
  10959. lifecycle.teardown();
  10960. }
  10961. }
  10962. });
  10963. }
  10964. function localeModule (name, lifecycle) {
  10965. QUnit.module('locale:' + name, {
  10966. setup : function () {
  10967. moment.locale(name);
  10968. moment.createFromInputFallback = function (config) {
  10969. throw new Error('input not handled by moment: ' + config._i);
  10970. };
  10971. if (lifecycle && lifecycle.setup) {
  10972. lifecycle.setup();
  10973. }
  10974. },
  10975. teardown : function () {
  10976. moment.locale('en');
  10977. if (lifecycle && lifecycle.teardown) {
  10978. lifecycle.teardown();
  10979. }
  10980. }
  10981. });
  10982. }
  10983. localeModule('fr-ca');
  10984. test('parse', function (assert) {
  10985. var i,
  10986. tests = 'janvier janv._février févr._mars mars_avril avr._mai mai_juin juin_juillet juil._août août_septembre sept._octobre oct._novembre nov._décembre déc.'.split('_');
  10987. function equalTest(input, mmm, i) {
  10988. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  10989. }
  10990. for (i = 0; i < 12; i++) {
  10991. tests[i] = tests[i].split(' ');
  10992. equalTest(tests[i][0], 'MMM', i);
  10993. equalTest(tests[i][1], 'MMM', i);
  10994. equalTest(tests[i][0], 'MMMM', i);
  10995. equalTest(tests[i][1], 'MMMM', i);
  10996. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  10997. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  10998. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  10999. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  11000. }
  11001. });
  11002. test('format', function (assert) {
  11003. var a = [
  11004. ['dddd, MMMM Do YYYY, h:mm:ss a', 'dimanche, février 14e 2010, 3:25:50 pm'],
  11005. ['ddd, hA', 'dim., 3PM'],
  11006. ['M Mo MM MMMM MMM', '2 2e 02 février févr.'],
  11007. ['YYYY YY', '2010 10'],
  11008. ['D Do DD', '14 14e 14'],
  11009. ['d do dddd ddd dd', '0 0e dimanche dim. Di'],
  11010. ['DDD DDDo DDDD', '45 45e 045'],
  11011. ['w wo ww', '8 8e 08'],
  11012. ['h hh', '3 03'],
  11013. ['H HH', '15 15'],
  11014. ['m mm', '25 25'],
  11015. ['s ss', '50 50'],
  11016. ['a A', 'pm PM'],
  11017. ['[the] DDDo [day of the year]', 'the 45e day of the year'],
  11018. ['LTS', '15:25:50'],
  11019. ['L', '2010-02-14'],
  11020. ['LL', '14 février 2010'],
  11021. ['LLL', '14 février 2010 15:25'],
  11022. ['LLLL', 'dimanche 14 février 2010 15:25'],
  11023. ['l', '2010-2-14'],
  11024. ['ll', '14 févr. 2010'],
  11025. ['lll', '14 févr. 2010 15:25'],
  11026. ['llll', 'dim. 14 févr. 2010 15:25']
  11027. ],
  11028. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  11029. i;
  11030. for (i = 0; i < a.length; i++) {
  11031. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  11032. }
  11033. });
  11034. test('format ordinal', function (assert) {
  11035. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1er', '1er');
  11036. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2e', '2e');
  11037. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3e', '3e');
  11038. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4e', '4e');
  11039. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5e', '5e');
  11040. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6e', '6e');
  11041. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7e', '7e');
  11042. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8e', '8e');
  11043. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9e', '9e');
  11044. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10e', '10e');
  11045. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11e', '11e');
  11046. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12e', '12e');
  11047. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13e', '13e');
  11048. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14e', '14e');
  11049. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15e', '15e');
  11050. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16e', '16e');
  11051. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17e', '17e');
  11052. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18e', '18e');
  11053. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19e', '19e');
  11054. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20e', '20e');
  11055. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21e', '21e');
  11056. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22e', '22e');
  11057. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23e', '23e');
  11058. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24e', '24e');
  11059. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25e', '25e');
  11060. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26e', '26e');
  11061. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27e', '27e');
  11062. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28e', '28e');
  11063. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29e', '29e');
  11064. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30e', '30e');
  11065. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31e', '31e');
  11066. });
  11067. test('format month', function (assert) {
  11068. var i,
  11069. expected = 'janvier janv._février févr._mars mars_avril avr._mai mai_juin juin_juillet juil._août août_septembre sept._octobre oct._novembre nov._décembre déc.'.split('_');
  11070. for (i = 0; i < expected.length; i++) {
  11071. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  11072. }
  11073. });
  11074. test('format week', function (assert) {
  11075. var i,
  11076. expected = 'dimanche dim. Di_lundi lun. Lu_mardi mar. Ma_mercredi mer. Me_jeudi jeu. Je_vendredi ven. Ve_samedi sam. Sa'.split('_');
  11077. for (i = 0; i < expected.length; i++) {
  11078. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  11079. }
  11080. });
  11081. test('from', function (assert) {
  11082. var start = moment([2007, 1, 28]);
  11083. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'quelques secondes', '44 seconds = a few seconds');
  11084. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'une minute', '45 seconds = a minute');
  11085. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'une minute', '89 seconds = a minute');
  11086. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutes', '90 seconds = 2 minutes');
  11087. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutes', '44 minutes = 44 minutes');
  11088. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'une heure', '45 minutes = an hour');
  11089. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'une heure', '89 minutes = an hour');
  11090. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 heures', '90 minutes = 2 hours');
  11091. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 heures', '5 hours = 5 hours');
  11092. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 heures', '21 hours = 21 hours');
  11093. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'un jour', '22 hours = a day');
  11094. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'un jour', '35 hours = a day');
  11095. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 jours', '36 hours = 2 days');
  11096. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'un jour', '1 day = a day');
  11097. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 jours', '5 days = 5 days');
  11098. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 jours', '25 days = 25 days');
  11099. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'un mois', '26 days = a month');
  11100. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'un mois', '30 days = a month');
  11101. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'un mois', '43 days = a month');
  11102. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mois', '46 days = 2 months');
  11103. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mois', '75 days = 2 months');
  11104. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mois', '76 days = 3 months');
  11105. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'un mois', '1 month = a month');
  11106. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mois', '5 months = 5 months');
  11107. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'un an', '345 days = a year');
  11108. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 ans', '548 days = 2 years');
  11109. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'un an', '1 year = a year');
  11110. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 ans', '5 years = 5 years');
  11111. });
  11112. test('suffix', function (assert) {
  11113. assert.equal(moment(30000).from(0), 'dans quelques secondes', 'prefix');
  11114. assert.equal(moment(0).from(30000), 'il y a quelques secondes', 'suffix');
  11115. });
  11116. test('fromNow', function (assert) {
  11117. assert.equal(moment().add({s: 30}).fromNow(), 'dans quelques secondes', 'in a few seconds');
  11118. assert.equal(moment().add({d: 5}).fromNow(), 'dans 5 jours', 'in 5 days');
  11119. });
  11120. test('same day', function (assert) {
  11121. var a = moment().hours(2).minutes(0).seconds(0);
  11122. assert.equal(moment(a).calendar(), 'Aujourd\'hui à 02:00', 'today at the same time');
  11123. assert.equal(moment(a).add({m: 25}).calendar(), 'Aujourd\'hui à 02:25', 'Now plus 25 min');
  11124. assert.equal(moment(a).add({h: 1}).calendar(), 'Aujourd\'hui à 03:00', 'Now plus 1 hour');
  11125. assert.equal(moment(a).add({d: 1}).calendar(), 'Demain à 02:00', 'tomorrow at the same time');
  11126. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Aujourd\'hui à 01:00', 'Now minus 1 hour');
  11127. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Hier à 02:00', 'yesterday at the same time');
  11128. });
  11129. test('same next week', function (assert) {
  11130. var i, m;
  11131. for (i = 2; i < 7; i++) {
  11132. m = moment().add({d: i});
  11133. assert.equal(m.calendar(), m.format('dddd [à] LT'), 'Today + ' + i + ' days current time');
  11134. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  11135. assert.equal(m.calendar(), m.format('dddd [à] LT'), 'Today + ' + i + ' days beginning of day');
  11136. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  11137. assert.equal(m.calendar(), m.format('dddd [à] LT'), 'Today + ' + i + ' days end of day');
  11138. }
  11139. });
  11140. test('same last week', function (assert) {
  11141. var i, m;
  11142. for (i = 2; i < 7; i++) {
  11143. m = moment().subtract({d: i});
  11144. assert.equal(m.calendar(), m.format('dddd [dernier à] LT'), 'Today - ' + i + ' days current time');
  11145. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  11146. assert.equal(m.calendar(), m.format('dddd [dernier à] LT'), 'Today - ' + i + ' days beginning of day');
  11147. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  11148. assert.equal(m.calendar(), m.format('dddd [dernier à] LT'), 'Today - ' + i + ' days end of day');
  11149. }
  11150. });
  11151. test('same all else', function (assert) {
  11152. var weeksAgo = moment().subtract({w: 1}),
  11153. weeksFromNow = moment().add({w: 1});
  11154. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  11155. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  11156. weeksAgo = moment().subtract({w: 2});
  11157. weeksFromNow = moment().add({w: 2});
  11158. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  11159. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  11160. });
  11161. test('weeks year starting sunday', function (assert) {
  11162. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  11163. assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1');
  11164. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  11165. assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2');
  11166. assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 3');
  11167. });
  11168. test('weeks year starting monday', function (assert) {
  11169. assert.equal(moment([2006, 11, 31]).week(), 1, 'Dec 31 2006 should be week 1');
  11170. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  11171. assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1');
  11172. assert.equal(moment([2007, 0, 7]).week(), 2, 'Jan 7 2007 should be week 2');
  11173. assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2');
  11174. assert.equal(moment([2007, 0, 14]).week(), 3, 'Jan 14 2007 should be week 3');
  11175. });
  11176. test('weeks year starting tuesday', function (assert) {
  11177. assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52');
  11178. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  11179. assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1');
  11180. assert.equal(moment([2008, 0, 6]).week(), 2, 'Jan 6 2008 should be week 2');
  11181. assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2');
  11182. assert.equal(moment([2008, 0, 13]).week(), 3, 'Jan 13 2008 should be week 3');
  11183. });
  11184. test('weeks year starting wednesday', function (assert) {
  11185. assert.equal(moment([2002, 11, 29]).week(), 1, 'Dec 29 2002 should be week 1');
  11186. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  11187. assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1');
  11188. assert.equal(moment([2003, 0, 5]).week(), 2, 'Jan 5 2003 should be week 2');
  11189. assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2');
  11190. assert.equal(moment([2003, 0, 12]).week(), 3, 'Jan 12 2003 should be week 3');
  11191. });
  11192. test('weeks year starting thursday', function (assert) {
  11193. assert.equal(moment([2008, 11, 28]).week(), 1, 'Dec 28 2008 should be week 1');
  11194. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  11195. assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1');
  11196. assert.equal(moment([2009, 0, 4]).week(), 2, 'Jan 4 2009 should be week 2');
  11197. assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2');
  11198. assert.equal(moment([2009, 0, 11]).week(), 3, 'Jan 11 2009 should be week 3');
  11199. });
  11200. test('weeks year starting friday', function (assert) {
  11201. assert.equal(moment([2009, 11, 27]).week(), 1, 'Dec 27 2009 should be week 1');
  11202. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  11203. assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 should be week 1');
  11204. assert.equal(moment([2010, 0, 3]).week(), 2, 'Jan 3 2010 should be week 2');
  11205. assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 should be week 2');
  11206. assert.equal(moment([2010, 0, 10]).week(), 3, 'Jan 10 2010 should be week 3');
  11207. });
  11208. test('weeks year starting saturday', function (assert) {
  11209. assert.equal(moment([2010, 11, 26]).week(), 1, 'Dec 26 2010 should be week 1');
  11210. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  11211. assert.equal(moment([2011, 0, 2]).week(), 2, 'Jan 2 2011 should be week 2');
  11212. assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2');
  11213. assert.equal(moment([2011, 0, 9]).week(), 3, 'Jan 9 2011 should be week 3');
  11214. });
  11215. test('weeks year starting sunday format', function (assert) {
  11216. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1er', 'Jan 1 2012 should be week 1');
  11217. assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1er', 'Jan 7 2012 should be week 1');
  11218. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2e', 'Jan 8 2012 should be week 2');
  11219. assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2e', 'Jan 14 2012 should be week 2');
  11220. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3e', 'Jan 15 2012 should be week 3');
  11221. });
  11222. test('lenient ordinal parsing', function (assert) {
  11223. var i, ordinalStr, testMoment;
  11224. for (i = 1; i <= 31; ++i) {
  11225. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  11226. testMoment = moment(ordinalStr, 'YYYY MM Do');
  11227. assert.equal(testMoment.year(), 2014,
  11228. 'lenient ordinal parsing ' + i + ' year check');
  11229. assert.equal(testMoment.month(), 0,
  11230. 'lenient ordinal parsing ' + i + ' month check');
  11231. assert.equal(testMoment.date(), i,
  11232. 'lenient ordinal parsing ' + i + ' date check');
  11233. }
  11234. });
  11235. test('lenient ordinal parsing of number', function (assert) {
  11236. var i, testMoment;
  11237. for (i = 1; i <= 31; ++i) {
  11238. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  11239. assert.equal(testMoment.year(), 2014,
  11240. 'lenient ordinal parsing of number ' + i + ' year check');
  11241. assert.equal(testMoment.month(), 0,
  11242. 'lenient ordinal parsing of number ' + i + ' month check');
  11243. assert.equal(testMoment.date(), i,
  11244. 'lenient ordinal parsing of number ' + i + ' date check');
  11245. }
  11246. });
  11247. test('strict ordinal parsing', function (assert) {
  11248. var i, ordinalStr, testMoment;
  11249. for (i = 1; i <= 31; ++i) {
  11250. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  11251. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  11252. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  11253. }
  11254. });
  11255. }));
  11256. ;(function (global, factory) {
  11257. typeof exports === 'object' && typeof module !== 'undefined'
  11258. && typeof require === 'function' ? factory(require('../../moment')) :
  11259. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  11260. factory(global.moment)
  11261. }(this, function (moment) { 'use strict';
  11262. /*global QUnit:false*/
  11263. var test = QUnit.test;
  11264. var expect = QUnit.expect;
  11265. function module (name, lifecycle) {
  11266. QUnit.module(name, {
  11267. setup : function () {
  11268. moment.locale('en');
  11269. moment.createFromInputFallback = function (config) {
  11270. throw new Error('input not handled by moment: ' + config._i);
  11271. };
  11272. if (lifecycle && lifecycle.setup) {
  11273. lifecycle.setup();
  11274. }
  11275. },
  11276. teardown : function () {
  11277. if (lifecycle && lifecycle.teardown) {
  11278. lifecycle.teardown();
  11279. }
  11280. }
  11281. });
  11282. }
  11283. function localeModule (name, lifecycle) {
  11284. QUnit.module('locale:' + name, {
  11285. setup : function () {
  11286. moment.locale(name);
  11287. moment.createFromInputFallback = function (config) {
  11288. throw new Error('input not handled by moment: ' + config._i);
  11289. };
  11290. if (lifecycle && lifecycle.setup) {
  11291. lifecycle.setup();
  11292. }
  11293. },
  11294. teardown : function () {
  11295. moment.locale('en');
  11296. if (lifecycle && lifecycle.teardown) {
  11297. lifecycle.teardown();
  11298. }
  11299. }
  11300. });
  11301. }
  11302. localeModule('fr-ch');
  11303. test('parse', function (assert) {
  11304. var i,
  11305. tests = 'janvier janv._février févr._mars mars_avril avr._mai mai_juin juin_juillet juil._août août_septembre sept._octobre oct._novembre nov._décembre déc.'.split('_');
  11306. function equalTest(input, mmm, i) {
  11307. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  11308. }
  11309. for (i = 0; i < 12; i++) {
  11310. tests[i] = tests[i].split(' ');
  11311. equalTest(tests[i][0], 'MMM', i);
  11312. equalTest(tests[i][1], 'MMM', i);
  11313. equalTest(tests[i][0], 'MMMM', i);
  11314. equalTest(tests[i][1], 'MMMM', i);
  11315. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  11316. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  11317. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  11318. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  11319. }
  11320. });
  11321. test('format', function (assert) {
  11322. var a = [
  11323. ['dddd, MMMM Do YYYY, h:mm:ss a', 'dimanche, février 14e 2010, 3:25:50 pm'],
  11324. ['ddd, hA', 'dim., 3PM'],
  11325. ['M Mo MM MMMM MMM', '2 2e 02 février févr.'],
  11326. ['YYYY YY', '2010 10'],
  11327. ['D Do DD', '14 14e 14'],
  11328. ['d do dddd ddd dd', '0 0e dimanche dim. Di'],
  11329. ['DDD DDDo DDDD', '45 45e 045'],
  11330. ['w wo ww', '6 6e 06'],
  11331. ['h hh', '3 03'],
  11332. ['H HH', '15 15'],
  11333. ['m mm', '25 25'],
  11334. ['s ss', '50 50'],
  11335. ['a A', 'pm PM'],
  11336. ['[the] DDDo [day of the year]', 'the 45e day of the year'],
  11337. ['LTS', '15:25:50'],
  11338. ['L', '14.02.2010'],
  11339. ['LL', '14 février 2010'],
  11340. ['LLL', '14 février 2010 15:25'],
  11341. ['LLLL', 'dimanche 14 février 2010 15:25'],
  11342. ['l', '14.2.2010'],
  11343. ['ll', '14 févr. 2010'],
  11344. ['lll', '14 févr. 2010 15:25'],
  11345. ['llll', 'dim. 14 févr. 2010 15:25']
  11346. ],
  11347. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  11348. i;
  11349. for (i = 0; i < a.length; i++) {
  11350. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  11351. }
  11352. });
  11353. test('format ordinal', function (assert) {
  11354. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1er', '1er');
  11355. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2e', '2e');
  11356. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3e', '3e');
  11357. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4e', '4e');
  11358. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5e', '5e');
  11359. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6e', '6e');
  11360. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7e', '7e');
  11361. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8e', '8e');
  11362. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9e', '9e');
  11363. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10e', '10e');
  11364. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11e', '11e');
  11365. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12e', '12e');
  11366. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13e', '13e');
  11367. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14e', '14e');
  11368. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15e', '15e');
  11369. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16e', '16e');
  11370. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17e', '17e');
  11371. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18e', '18e');
  11372. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19e', '19e');
  11373. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20e', '20e');
  11374. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21e', '21e');
  11375. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22e', '22e');
  11376. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23e', '23e');
  11377. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24e', '24e');
  11378. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25e', '25e');
  11379. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26e', '26e');
  11380. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27e', '27e');
  11381. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28e', '28e');
  11382. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29e', '29e');
  11383. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30e', '30e');
  11384. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31e', '31e');
  11385. });
  11386. test('format month', function (assert) {
  11387. var i,
  11388. expected = 'janvier janv._février févr._mars mars_avril avr._mai mai_juin juin_juillet juil._août août_septembre sept._octobre oct._novembre nov._décembre déc.'.split('_');
  11389. for (i = 0; i < expected.length; i++) {
  11390. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  11391. }
  11392. });
  11393. test('format week', function (assert) {
  11394. var i,
  11395. expected = 'dimanche dim. Di_lundi lun. Lu_mardi mar. Ma_mercredi mer. Me_jeudi jeu. Je_vendredi ven. Ve_samedi sam. Sa'.split('_');
  11396. for (i = 0; i < expected.length; i++) {
  11397. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  11398. }
  11399. });
  11400. test('from', function (assert) {
  11401. var start = moment([2007, 1, 28]);
  11402. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'quelques secondes', '44 seconds = a few seconds');
  11403. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'une minute', '45 seconds = a minute');
  11404. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'une minute', '89 seconds = a minute');
  11405. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutes', '90 seconds = 2 minutes');
  11406. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutes', '44 minutes = 44 minutes');
  11407. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'une heure', '45 minutes = an hour');
  11408. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'une heure', '89 minutes = an hour');
  11409. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 heures', '90 minutes = 2 hours');
  11410. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 heures', '5 hours = 5 hours');
  11411. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 heures', '21 hours = 21 hours');
  11412. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'un jour', '22 hours = a day');
  11413. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'un jour', '35 hours = a day');
  11414. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 jours', '36 hours = 2 days');
  11415. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'un jour', '1 day = a day');
  11416. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 jours', '5 days = 5 days');
  11417. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 jours', '25 days = 25 days');
  11418. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'un mois', '26 days = a month');
  11419. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'un mois', '30 days = a month');
  11420. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'un mois', '43 days = a month');
  11421. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mois', '46 days = 2 months');
  11422. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mois', '75 days = 2 months');
  11423. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mois', '76 days = 3 months');
  11424. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'un mois', '1 month = a month');
  11425. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mois', '5 months = 5 months');
  11426. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'un an', '345 days = a year');
  11427. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 ans', '548 days = 2 years');
  11428. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'un an', '1 year = a year');
  11429. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 ans', '5 years = 5 years');
  11430. });
  11431. test('suffix', function (assert) {
  11432. assert.equal(moment(30000).from(0), 'dans quelques secondes', 'prefix');
  11433. assert.equal(moment(0).from(30000), 'il y a quelques secondes', 'suffix');
  11434. });
  11435. test('fromNow', function (assert) {
  11436. assert.equal(moment().add({s: 30}).fromNow(), 'dans quelques secondes', 'in a few seconds');
  11437. assert.equal(moment().add({d: 5}).fromNow(), 'dans 5 jours', 'in 5 days');
  11438. });
  11439. test('same day', function (assert) {
  11440. var a = moment().hours(2).minutes(0).seconds(0);
  11441. assert.equal(moment(a).calendar(), 'Aujourd\'hui à 02:00', 'today at the same time');
  11442. assert.equal(moment(a).add({m: 25}).calendar(), 'Aujourd\'hui à 02:25', 'Now plus 25 min');
  11443. assert.equal(moment(a).add({h: 1}).calendar(), 'Aujourd\'hui à 03:00', 'Now plus 1 hour');
  11444. assert.equal(moment(a).add({d: 1}).calendar(), 'Demain à 02:00', 'tomorrow at the same time');
  11445. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Aujourd\'hui à 01:00', 'Now minus 1 hour');
  11446. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Hier à 02:00', 'yesterday at the same time');
  11447. });
  11448. test('same next week', function (assert) {
  11449. var i, m;
  11450. for (i = 2; i < 7; i++) {
  11451. m = moment().add({d: i});
  11452. assert.equal(m.calendar(), m.format('dddd [à] LT'), 'Today + ' + i + ' days current time');
  11453. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  11454. assert.equal(m.calendar(), m.format('dddd [à] LT'), 'Today + ' + i + ' days beginning of day');
  11455. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  11456. assert.equal(m.calendar(), m.format('dddd [à] LT'), 'Today + ' + i + ' days end of day');
  11457. }
  11458. });
  11459. test('same last week', function (assert) {
  11460. var i, m;
  11461. for (i = 2; i < 7; i++) {
  11462. m = moment().subtract({d: i});
  11463. assert.equal(m.calendar(), m.format('dddd [dernier à] LT'), 'Today - ' + i + ' days current time');
  11464. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  11465. assert.equal(m.calendar(), m.format('dddd [dernier à] LT'), 'Today - ' + i + ' days beginning of day');
  11466. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  11467. assert.equal(m.calendar(), m.format('dddd [dernier à] LT'), 'Today - ' + i + ' days end of day');
  11468. }
  11469. });
  11470. test('same all else', function (assert) {
  11471. var weeksAgo = moment().subtract({w: 1}),
  11472. weeksFromNow = moment().add({w: 1});
  11473. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  11474. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  11475. weeksAgo = moment().subtract({w: 2});
  11476. weeksFromNow = moment().add({w: 2});
  11477. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  11478. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  11479. });
  11480. test('weeks year starting sunday', function (assert) {
  11481. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  11482. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  11483. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  11484. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  11485. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  11486. });
  11487. test('weeks year starting monday', function (assert) {
  11488. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  11489. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  11490. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  11491. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  11492. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  11493. });
  11494. test('weeks year starting tuesday', function (assert) {
  11495. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  11496. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  11497. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  11498. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  11499. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  11500. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  11501. });
  11502. test('weeks year starting wednesday', function (assert) {
  11503. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  11504. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  11505. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  11506. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  11507. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  11508. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  11509. });
  11510. test('weeks year starting thursday', function (assert) {
  11511. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  11512. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  11513. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  11514. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  11515. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  11516. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  11517. });
  11518. test('weeks year starting friday', function (assert) {
  11519. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  11520. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  11521. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  11522. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  11523. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  11524. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  11525. });
  11526. test('weeks year starting saturday', function (assert) {
  11527. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  11528. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  11529. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  11530. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  11531. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  11532. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  11533. });
  11534. test('weeks year starting sunday formatted', function (assert) {
  11535. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52e', 'Jan 1 2012 should be week 52');
  11536. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1er', 'Jan 2 2012 should be week 1');
  11537. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1er', 'Jan 8 2012 should be week 1');
  11538. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2e', 'Jan 9 2012 should be week 2');
  11539. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2e', 'Jan 15 2012 should be week 2');
  11540. });
  11541. test('lenient ordinal parsing', function (assert) {
  11542. var i, ordinalStr, testMoment;
  11543. for (i = 1; i <= 31; ++i) {
  11544. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  11545. testMoment = moment(ordinalStr, 'YYYY MM Do');
  11546. assert.equal(testMoment.year(), 2014,
  11547. 'lenient ordinal parsing ' + i + ' year check');
  11548. assert.equal(testMoment.month(), 0,
  11549. 'lenient ordinal parsing ' + i + ' month check');
  11550. assert.equal(testMoment.date(), i,
  11551. 'lenient ordinal parsing ' + i + ' date check');
  11552. }
  11553. });
  11554. test('lenient ordinal parsing of number', function (assert) {
  11555. var i, testMoment;
  11556. for (i = 1; i <= 31; ++i) {
  11557. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  11558. assert.equal(testMoment.year(), 2014,
  11559. 'lenient ordinal parsing of number ' + i + ' year check');
  11560. assert.equal(testMoment.month(), 0,
  11561. 'lenient ordinal parsing of number ' + i + ' month check');
  11562. assert.equal(testMoment.date(), i,
  11563. 'lenient ordinal parsing of number ' + i + ' date check');
  11564. }
  11565. });
  11566. test('strict ordinal parsing', function (assert) {
  11567. var i, ordinalStr, testMoment;
  11568. for (i = 1; i <= 31; ++i) {
  11569. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  11570. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  11571. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  11572. }
  11573. });
  11574. }));
  11575. ;(function (global, factory) {
  11576. typeof exports === 'object' && typeof module !== 'undefined'
  11577. && typeof require === 'function' ? factory(require('../../moment')) :
  11578. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  11579. factory(global.moment)
  11580. }(this, function (moment) { 'use strict';
  11581. /*global QUnit:false*/
  11582. var test = QUnit.test;
  11583. var expect = QUnit.expect;
  11584. function module (name, lifecycle) {
  11585. QUnit.module(name, {
  11586. setup : function () {
  11587. moment.locale('en');
  11588. moment.createFromInputFallback = function (config) {
  11589. throw new Error('input not handled by moment: ' + config._i);
  11590. };
  11591. if (lifecycle && lifecycle.setup) {
  11592. lifecycle.setup();
  11593. }
  11594. },
  11595. teardown : function () {
  11596. if (lifecycle && lifecycle.teardown) {
  11597. lifecycle.teardown();
  11598. }
  11599. }
  11600. });
  11601. }
  11602. function localeModule (name, lifecycle) {
  11603. QUnit.module('locale:' + name, {
  11604. setup : function () {
  11605. moment.locale(name);
  11606. moment.createFromInputFallback = function (config) {
  11607. throw new Error('input not handled by moment: ' + config._i);
  11608. };
  11609. if (lifecycle && lifecycle.setup) {
  11610. lifecycle.setup();
  11611. }
  11612. },
  11613. teardown : function () {
  11614. moment.locale('en');
  11615. if (lifecycle && lifecycle.teardown) {
  11616. lifecycle.teardown();
  11617. }
  11618. }
  11619. });
  11620. }
  11621. localeModule('fr');
  11622. test('parse', function (assert) {
  11623. var tests = 'janvier janv._février févr._mars mars_avril avr._mai mai_juin juin_juillet juil._août août_septembre sept._octobre oct._novembre nov._décembre déc.'.split('_'),
  11624. i;
  11625. function equalTest(input, mmm, i) {
  11626. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  11627. }
  11628. for (i = 0; i < 12; i++) {
  11629. tests[i] = tests[i].split(' ');
  11630. equalTest(tests[i][0], 'MMM', i);
  11631. equalTest(tests[i][1], 'MMM', i);
  11632. equalTest(tests[i][0], 'MMMM', i);
  11633. equalTest(tests[i][1], 'MMMM', i);
  11634. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  11635. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  11636. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  11637. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  11638. }
  11639. });
  11640. test('format', function (assert) {
  11641. var a = [
  11642. ['dddd, MMMM Do YYYY, h:mm:ss a', 'dimanche, février 14 2010, 3:25:50 pm'],
  11643. ['ddd, hA', 'dim., 3PM'],
  11644. ['M Mo MM MMMM MMM', '2 2 02 février févr.'],
  11645. ['YYYY YY', '2010 10'],
  11646. ['D Do DD', '14 14 14'],
  11647. ['d do dddd ddd dd', '0 0 dimanche dim. Di'],
  11648. ['DDD DDDo DDDD', '45 45 045'],
  11649. ['w wo ww', '6 6 06'],
  11650. ['h hh', '3 03'],
  11651. ['H HH', '15 15'],
  11652. ['m mm', '25 25'],
  11653. ['s ss', '50 50'],
  11654. ['a A', 'pm PM'],
  11655. ['[the] DDDo [day of the year]', 'the 45 day of the year'],
  11656. ['LTS', '15:25:50'],
  11657. ['L', '14/02/2010'],
  11658. ['LL', '14 février 2010'],
  11659. ['LLL', '14 février 2010 15:25'],
  11660. ['LLLL', 'dimanche 14 février 2010 15:25'],
  11661. ['l', '14/2/2010'],
  11662. ['ll', '14 févr. 2010'],
  11663. ['lll', '14 févr. 2010 15:25'],
  11664. ['llll', 'dim. 14 févr. 2010 15:25']
  11665. ],
  11666. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  11667. i;
  11668. for (i = 0; i < a.length; i++) {
  11669. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  11670. }
  11671. });
  11672. test('format ordinal', function (assert) {
  11673. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1er', '1er');
  11674. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2');
  11675. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3');
  11676. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4');
  11677. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5');
  11678. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6');
  11679. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7');
  11680. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8');
  11681. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9');
  11682. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10');
  11683. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11');
  11684. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12');
  11685. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13');
  11686. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14');
  11687. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15');
  11688. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16');
  11689. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17');
  11690. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18');
  11691. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19');
  11692. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20');
  11693. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21');
  11694. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22');
  11695. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23');
  11696. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24');
  11697. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25');
  11698. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26');
  11699. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27');
  11700. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28');
  11701. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29');
  11702. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30');
  11703. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31');
  11704. });
  11705. test('format month', function (assert) {
  11706. var expected = 'janvier janv._février févr._mars mars_avril avr._mai mai_juin juin_juillet juil._août août_septembre sept._octobre oct._novembre nov._décembre déc.'.split('_'), i;
  11707. for (i = 0; i < expected.length; i++) {
  11708. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  11709. }
  11710. });
  11711. test('format week', function (assert) {
  11712. var expected = 'dimanche dim. Di_lundi lun. Lu_mardi mar. Ma_mercredi mer. Me_jeudi jeu. Je_vendredi ven. Ve_samedi sam. Sa'.split('_'), i;
  11713. for (i = 0; i < expected.length; i++) {
  11714. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  11715. }
  11716. });
  11717. test('from', function (assert) {
  11718. var start = moment([2007, 1, 28]);
  11719. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'quelques secondes', '44 seconds = a few seconds');
  11720. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'une minute', '45 seconds = a minute');
  11721. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'une minute', '89 seconds = a minute');
  11722. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutes', '90 seconds = 2 minutes');
  11723. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutes', '44 minutes = 44 minutes');
  11724. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'une heure', '45 minutes = an hour');
  11725. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'une heure', '89 minutes = an hour');
  11726. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 heures', '90 minutes = 2 hours');
  11727. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 heures', '5 hours = 5 hours');
  11728. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 heures', '21 hours = 21 hours');
  11729. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'un jour', '22 hours = a day');
  11730. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'un jour', '35 hours = a day');
  11731. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 jours', '36 hours = 2 days');
  11732. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'un jour', '1 day = a day');
  11733. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 jours', '5 days = 5 days');
  11734. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 jours', '25 days = 25 days');
  11735. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'un mois', '26 days = a month');
  11736. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'un mois', '30 days = a month');
  11737. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'un mois', '43 days = a month');
  11738. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mois', '46 days = 2 months');
  11739. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mois', '75 days = 2 months');
  11740. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mois', '76 days = 3 months');
  11741. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'un mois', '1 month = a month');
  11742. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mois', '5 months = 5 months');
  11743. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'un an', '345 days = a year');
  11744. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 ans', '548 days = 2 years');
  11745. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'un an', '1 year = a year');
  11746. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 ans', '5 years = 5 years');
  11747. });
  11748. test('suffix', function (assert) {
  11749. assert.equal(moment(30000).from(0), 'dans quelques secondes', 'prefix');
  11750. assert.equal(moment(0).from(30000), 'il y a quelques secondes', 'suffix');
  11751. });
  11752. test('fromNow', function (assert) {
  11753. assert.equal(moment().add({s: 30}).fromNow(), 'dans quelques secondes', 'in a few seconds');
  11754. assert.equal(moment().add({d: 5}).fromNow(), 'dans 5 jours', 'in 5 days');
  11755. });
  11756. test('same day', function (assert) {
  11757. var a = moment().hours(2).minutes(0).seconds(0);
  11758. assert.equal(moment(a).calendar(), 'Aujourd\'hui à 02:00', 'today at the same time');
  11759. assert.equal(moment(a).add({m: 25}).calendar(), 'Aujourd\'hui à 02:25', 'Now plus 25 min');
  11760. assert.equal(moment(a).add({h: 1}).calendar(), 'Aujourd\'hui à 03:00', 'Now plus 1 hour');
  11761. assert.equal(moment(a).add({d: 1}).calendar(), 'Demain à 02:00', 'tomorrow at the same time');
  11762. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Aujourd\'hui à 01:00', 'Now minus 1 hour');
  11763. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Hier à 02:00', 'yesterday at the same time');
  11764. });
  11765. test('same next week', function (assert) {
  11766. var i, m;
  11767. for (i = 2; i < 7; i++) {
  11768. m = moment().add({d: i});
  11769. assert.equal(m.calendar(), m.format('dddd [à] LT'), 'Today + ' + i + ' days current time');
  11770. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  11771. assert.equal(m.calendar(), m.format('dddd [à] LT'), 'Today + ' + i + ' days beginning of day');
  11772. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  11773. assert.equal(m.calendar(), m.format('dddd [à] LT'), 'Today + ' + i + ' days end of day');
  11774. }
  11775. });
  11776. test('same last week', function (assert) {
  11777. var i, m;
  11778. for (i = 2; i < 7; i++) {
  11779. m = moment().subtract({d: i});
  11780. assert.equal(m.calendar(), m.format('dddd [dernier à] LT'), 'Today - ' + i + ' days current time');
  11781. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  11782. assert.equal(m.calendar(), m.format('dddd [dernier à] LT'), 'Today - ' + i + ' days beginning of day');
  11783. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  11784. assert.equal(m.calendar(), m.format('dddd [dernier à] LT'), 'Today - ' + i + ' days end of day');
  11785. }
  11786. });
  11787. test('same all else', function (assert) {
  11788. var weeksAgo = moment().subtract({w: 1}),
  11789. weeksFromNow = moment().add({w: 1});
  11790. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  11791. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  11792. weeksAgo = moment().subtract({w: 2});
  11793. weeksFromNow = moment().add({w: 2});
  11794. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  11795. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  11796. });
  11797. test('weeks year starting sunday', function (assert) {
  11798. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  11799. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  11800. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  11801. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  11802. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  11803. });
  11804. test('weeks year starting monday', function (assert) {
  11805. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  11806. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  11807. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  11808. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  11809. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  11810. });
  11811. test('weeks year starting tuesday', function (assert) {
  11812. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  11813. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  11814. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  11815. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  11816. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  11817. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  11818. });
  11819. test('weeks year starting wednesday', function (assert) {
  11820. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  11821. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  11822. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  11823. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  11824. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  11825. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  11826. });
  11827. test('weeks year starting thursday', function (assert) {
  11828. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  11829. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  11830. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  11831. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  11832. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  11833. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  11834. });
  11835. test('weeks year starting friday', function (assert) {
  11836. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  11837. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  11838. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  11839. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  11840. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  11841. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  11842. });
  11843. test('weeks year starting saturday', function (assert) {
  11844. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  11845. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  11846. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  11847. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  11848. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  11849. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  11850. });
  11851. test('weeks year starting sunday formatted', function (assert) {
  11852. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52', 'Jan 1 2012 should be week 52');
  11853. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1er', 'Jan 2 2012 should be week 1');
  11854. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1er', 'Jan 8 2012 should be week 1');
  11855. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2', 'Jan 9 2012 should be week 2');
  11856. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2', 'Jan 15 2012 should be week 2');
  11857. });
  11858. test('lenient ordinal parsing', function (assert) {
  11859. var i, ordinalStr, testMoment;
  11860. for (i = 1; i <= 31; ++i) {
  11861. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  11862. testMoment = moment(ordinalStr, 'YYYY MM Do');
  11863. assert.equal(testMoment.year(), 2014,
  11864. 'lenient ordinal parsing ' + i + ' year check');
  11865. assert.equal(testMoment.month(), 0,
  11866. 'lenient ordinal parsing ' + i + ' month check');
  11867. assert.equal(testMoment.date(), i,
  11868. 'lenient ordinal parsing ' + i + ' date check');
  11869. }
  11870. });
  11871. test('lenient ordinal parsing of number', function (assert) {
  11872. var i, testMoment;
  11873. for (i = 1; i <= 31; ++i) {
  11874. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  11875. assert.equal(testMoment.year(), 2014,
  11876. 'lenient ordinal parsing of number ' + i + ' year check');
  11877. assert.equal(testMoment.month(), 0,
  11878. 'lenient ordinal parsing of number ' + i + ' month check');
  11879. assert.equal(testMoment.date(), i,
  11880. 'lenient ordinal parsing of number ' + i + ' date check');
  11881. }
  11882. });
  11883. test('strict ordinal parsing', function (assert) {
  11884. var i, ordinalStr, testMoment;
  11885. for (i = 1; i <= 31; ++i) {
  11886. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  11887. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  11888. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  11889. }
  11890. });
  11891. }));
  11892. ;(function (global, factory) {
  11893. typeof exports === 'object' && typeof module !== 'undefined'
  11894. && typeof require === 'function' ? factory(require('../../moment')) :
  11895. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  11896. factory(global.moment)
  11897. }(this, function (moment) { 'use strict';
  11898. /*global QUnit:false*/
  11899. var test = QUnit.test;
  11900. var expect = QUnit.expect;
  11901. function module (name, lifecycle) {
  11902. QUnit.module(name, {
  11903. setup : function () {
  11904. moment.locale('en');
  11905. moment.createFromInputFallback = function (config) {
  11906. throw new Error('input not handled by moment: ' + config._i);
  11907. };
  11908. if (lifecycle && lifecycle.setup) {
  11909. lifecycle.setup();
  11910. }
  11911. },
  11912. teardown : function () {
  11913. if (lifecycle && lifecycle.teardown) {
  11914. lifecycle.teardown();
  11915. }
  11916. }
  11917. });
  11918. }
  11919. function localeModule (name, lifecycle) {
  11920. QUnit.module('locale:' + name, {
  11921. setup : function () {
  11922. moment.locale(name);
  11923. moment.createFromInputFallback = function (config) {
  11924. throw new Error('input not handled by moment: ' + config._i);
  11925. };
  11926. if (lifecycle && lifecycle.setup) {
  11927. lifecycle.setup();
  11928. }
  11929. },
  11930. teardown : function () {
  11931. moment.locale('en');
  11932. if (lifecycle && lifecycle.teardown) {
  11933. lifecycle.teardown();
  11934. }
  11935. }
  11936. });
  11937. }
  11938. localeModule('fy');
  11939. test('parse', function (assert) {
  11940. var tests = 'jannewaris jan._febrewaris feb._maart mrt._april apr._maaie mai._juny jun._july jul._augustus aug._septimber sep._oktober okt._novimber nov._desimber des.'.split('_'), i;
  11941. function equalTest(input, mmm, i) {
  11942. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  11943. }
  11944. for (i = 0; i < 12; i++) {
  11945. tests[i] = tests[i].split(' ');
  11946. equalTest(tests[i][0], 'MMM', i);
  11947. equalTest(tests[i][1], 'MMM', i);
  11948. equalTest(tests[i][0], 'MMMM', i);
  11949. equalTest(tests[i][1], 'MMMM', i);
  11950. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  11951. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  11952. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  11953. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  11954. }
  11955. });
  11956. test('format', function (assert) {
  11957. var a = [
  11958. ['dddd, MMMM Do YYYY, HH:mm:ss', 'snein, febrewaris 14de 2010, 15:25:50'],
  11959. ['ddd, HH', 'si., 15'],
  11960. ['M Mo MM MMMM MMM', '2 2de 02 febrewaris feb.'],
  11961. ['YYYY YY', '2010 10'],
  11962. ['D Do DD', '14 14de 14'],
  11963. ['d do dddd ddd dd', '0 0de snein si. Si'],
  11964. ['DDD DDDo DDDD', '45 45ste 045'],
  11965. ['w wo ww', '6 6de 06'],
  11966. ['h hh', '3 03'],
  11967. ['H HH', '15 15'],
  11968. ['m mm', '25 25'],
  11969. ['s ss', '50 50'],
  11970. ['a A', 'pm PM'],
  11971. ['[the] DDDo [day of the year]', 'the 45ste day of the year'],
  11972. ['LTS', '15:25:50'],
  11973. ['L', '14-02-2010'],
  11974. ['LL', '14 febrewaris 2010'],
  11975. ['LLL', '14 febrewaris 2010 15:25'],
  11976. ['LLLL', 'snein 14 febrewaris 2010 15:25'],
  11977. ['l', '14-2-2010'],
  11978. ['ll', '14 feb. 2010'],
  11979. ['lll', '14 feb. 2010 15:25'],
  11980. ['llll', 'si. 14 feb. 2010 15:25']
  11981. ],
  11982. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  11983. i;
  11984. for (i = 0; i < a.length; i++) {
  11985. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  11986. }
  11987. });
  11988. test('format ordinal', function (assert) {
  11989. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1ste', '1ste');
  11990. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2de', '2de');
  11991. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3de', '3de');
  11992. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4de', '4de');
  11993. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5de', '5de');
  11994. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6de', '6de');
  11995. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7de', '7de');
  11996. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8ste', '8ste');
  11997. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9de', '9de');
  11998. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10de', '10de');
  11999. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11de', '11de');
  12000. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12de', '12de');
  12001. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13de', '13de');
  12002. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14de', '14de');
  12003. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15de', '15de');
  12004. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16de', '16de');
  12005. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17de', '17de');
  12006. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18de', '18de');
  12007. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19de', '19de');
  12008. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20ste', '20ste');
  12009. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21ste', '21ste');
  12010. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22ste', '22ste');
  12011. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23ste', '23ste');
  12012. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24ste', '24ste');
  12013. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25ste', '25ste');
  12014. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26ste', '26ste');
  12015. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27ste', '27ste');
  12016. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28ste', '28ste');
  12017. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29ste', '29ste');
  12018. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30ste', '30ste');
  12019. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31ste', '31ste');
  12020. });
  12021. test('format month', function (assert) {
  12022. var expected = 'jannewaris jan._febrewaris feb._maart mrt._april apr._maaie mai_juny jun._july jul._augustus aug._septimber sep._oktober okt._novimber nov._desimber des.'.split('_'), i;
  12023. for (i = 0; i < expected.length; i++) {
  12024. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  12025. }
  12026. });
  12027. test('format week', function (assert) {
  12028. var expected = 'snein si. Si_moandei mo. Mo_tiisdei ti. Ti_woansdei wo. Wo_tongersdei to. To_freed fr. Fr_sneon so. So'.split('_'), i;
  12029. for (i = 0; i < expected.length; i++) {
  12030. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  12031. }
  12032. });
  12033. test('from', function (assert) {
  12034. var start = moment([2007, 1, 28]);
  12035. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'in pear sekonden', '44 seconds = a few seconds');
  12036. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'ien minút', '45 seconds = a minute');
  12037. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'ien minút', '89 seconds = a minute');
  12038. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuten', '90 seconds = 2 minutes');
  12039. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuten', '44 minutes = 44 minutes');
  12040. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ien oere', '45 minutes = an hour');
  12041. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ien oere', '89 minutes = an hour');
  12042. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 oeren', '90 minutes = 2 hours');
  12043. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 oeren', '5 hours = 5 hours');
  12044. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 oeren', '21 hours = 21 hours');
  12045. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ien dei', '22 hours = a day');
  12046. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ien dei', '35 hours = a day');
  12047. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dagen', '36 hours = 2 days');
  12048. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ien dei', '1 day = a day');
  12049. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dagen', '5 days = 5 days');
  12050. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dagen', '25 days = 25 days');
  12051. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ien moanne', '26 days = a month');
  12052. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ien moanne', '30 days = a month');
  12053. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ien moanne', '43 days = a month');
  12054. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 moannen', '46 days = 2 months');
  12055. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 moannen', '75 days = 2 months');
  12056. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 moannen', '76 days = 3 months');
  12057. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ien moanne', '1 month = a month');
  12058. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 moannen', '5 months = 5 months');
  12059. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ien jier', '345 days = a year');
  12060. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 jierren', '548 days = 2 years');
  12061. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ien jier', '1 year = a year');
  12062. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 jierren', '5 years = 5 years');
  12063. });
  12064. test('suffix', function (assert) {
  12065. assert.equal(moment(30000).from(0), 'oer in pear sekonden', 'prefix');
  12066. assert.equal(moment(0).from(30000), 'in pear sekonden lyn', 'suffix');
  12067. });
  12068. test('now from now', function (assert) {
  12069. assert.equal(moment().fromNow(), 'in pear sekonden lyn', 'now from now should display as in the past');
  12070. });
  12071. test('fromNow', function (assert) {
  12072. assert.equal(moment().add({s: 30}).fromNow(), 'oer in pear sekonden', 'in a few seconds');
  12073. assert.equal(moment().add({d: 5}).fromNow(), 'oer 5 dagen', 'in 5 days');
  12074. });
  12075. test('calendar day', function (assert) {
  12076. var a = moment().hours(2).minutes(0).seconds(0);
  12077. assert.equal(moment(a).calendar(), 'hjoed om 02:00', 'today at the same time');
  12078. assert.equal(moment(a).add({m: 25}).calendar(), 'hjoed om 02:25', 'Now plus 25 min');
  12079. assert.equal(moment(a).add({h: 1}).calendar(), 'hjoed om 03:00', 'Now plus 1 hour');
  12080. assert.equal(moment(a).add({d: 1}).calendar(), 'moarn om 02:00', 'tomorrow at the same time');
  12081. assert.equal(moment(a).subtract({h: 1}).calendar(), 'hjoed om 01:00', 'Now minus 1 hour');
  12082. assert.equal(moment(a).subtract({d: 1}).calendar(), 'juster om 02:00', 'yesterday at the same time');
  12083. });
  12084. test('calendar next week', function (assert) {
  12085. var i, m;
  12086. for (i = 2; i < 7; i++) {
  12087. m = moment().add({d: i});
  12088. assert.equal(m.calendar(), m.format('dddd [om] LT'), 'Today + ' + i + ' days current time');
  12089. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  12090. assert.equal(m.calendar(), m.format('dddd [om] LT'), 'Today + ' + i + ' days beginning of day');
  12091. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  12092. assert.equal(m.calendar(), m.format('dddd [om] LT'), 'Today + ' + i + ' days end of day');
  12093. }
  12094. });
  12095. test('calendar last week', function (assert) {
  12096. var i, m;
  12097. for (i = 2; i < 7; i++) {
  12098. m = moment().subtract({d: i});
  12099. assert.equal(m.calendar(), m.format('[ôfrûne] dddd [om] LT'), 'Today - ' + i + ' days current time');
  12100. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  12101. assert.equal(m.calendar(), m.format('[ôfrûne] dddd [om] LT'), 'Today - ' + i + ' days beginning of day');
  12102. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  12103. assert.equal(m.calendar(), m.format('[ôfrûne] dddd [om] LT'), 'Today - ' + i + ' days end of day');
  12104. }
  12105. });
  12106. test('calendar all else', function (assert) {
  12107. var weeksAgo = moment().subtract({w: 1}),
  12108. weeksFromNow = moment().add({w: 1});
  12109. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  12110. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  12111. weeksAgo = moment().subtract({w: 2});
  12112. weeksFromNow = moment().add({w: 2});
  12113. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  12114. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  12115. });
  12116. test('month abbreviation', function (assert) {
  12117. assert.equal(moment([2012, 5, 23]).format('D-MMM-YYYY'), '23-jun-2012', 'format month abbreviation surrounded by dashes should not include a dot');
  12118. assert.equal(moment([2012, 5, 23]).format('D MMM YYYY'), '23 jun. 2012', 'format month abbreviation not surrounded by dashes should include a dot');
  12119. });
  12120. test('weeks year starting sunday', function (assert) {
  12121. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  12122. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  12123. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  12124. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  12125. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  12126. });
  12127. test('weeks year starting monday', function (assert) {
  12128. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  12129. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  12130. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  12131. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  12132. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  12133. });
  12134. test('weeks year starting tuesday', function (assert) {
  12135. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  12136. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  12137. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  12138. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  12139. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  12140. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  12141. });
  12142. test('weeks year starting wednesday', function (assert) {
  12143. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  12144. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  12145. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  12146. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  12147. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  12148. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  12149. });
  12150. test('weeks year starting thursday', function (assert) {
  12151. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  12152. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  12153. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  12154. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  12155. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  12156. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  12157. });
  12158. test('weeks year starting friday', function (assert) {
  12159. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  12160. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  12161. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  12162. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  12163. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  12164. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  12165. });
  12166. test('weeks year starting saturday', function (assert) {
  12167. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  12168. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  12169. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  12170. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  12171. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  12172. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  12173. });
  12174. test('weeks year starting sunday formatted', function (assert) {
  12175. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52ste', 'Jan 1 2012 should be week 52');
  12176. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1ste', 'Jan 2 2012 should be week 1');
  12177. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1ste', 'Jan 8 2012 should be week 1');
  12178. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2de', 'Jan 9 2012 should be week 2');
  12179. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2de', 'Jan 15 2012 should be week 2');
  12180. });
  12181. test('lenient ordinal parsing', function (assert) {
  12182. var i, ordinalStr, testMoment;
  12183. for (i = 1; i <= 31; ++i) {
  12184. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  12185. testMoment = moment(ordinalStr, 'YYYY MM Do');
  12186. assert.equal(testMoment.year(), 2014,
  12187. 'lenient ordinal parsing ' + i + ' year check');
  12188. assert.equal(testMoment.month(), 0,
  12189. 'lenient ordinal parsing ' + i + ' month check');
  12190. assert.equal(testMoment.date(), i,
  12191. 'lenient ordinal parsing ' + i + ' date check');
  12192. }
  12193. });
  12194. test('lenient ordinal parsing of number', function (assert) {
  12195. var i, testMoment;
  12196. for (i = 1; i <= 31; ++i) {
  12197. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  12198. assert.equal(testMoment.year(), 2014,
  12199. 'lenient ordinal parsing of number ' + i + ' year check');
  12200. assert.equal(testMoment.month(), 0,
  12201. 'lenient ordinal parsing of number ' + i + ' month check');
  12202. assert.equal(testMoment.date(), i,
  12203. 'lenient ordinal parsing of number ' + i + ' date check');
  12204. }
  12205. });
  12206. test('strict ordinal parsing', function (assert) {
  12207. var i, ordinalStr, testMoment;
  12208. for (i = 1; i <= 31; ++i) {
  12209. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  12210. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  12211. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  12212. }
  12213. });
  12214. }));
  12215. ;(function (global, factory) {
  12216. typeof exports === 'object' && typeof module !== 'undefined'
  12217. && typeof require === 'function' ? factory(require('../../moment')) :
  12218. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  12219. factory(global.moment)
  12220. }(this, function (moment) { 'use strict';
  12221. /*global QUnit:false*/
  12222. var test = QUnit.test;
  12223. var expect = QUnit.expect;
  12224. function module (name, lifecycle) {
  12225. QUnit.module(name, {
  12226. setup : function () {
  12227. moment.locale('en');
  12228. moment.createFromInputFallback = function (config) {
  12229. throw new Error('input not handled by moment: ' + config._i);
  12230. };
  12231. if (lifecycle && lifecycle.setup) {
  12232. lifecycle.setup();
  12233. }
  12234. },
  12235. teardown : function () {
  12236. if (lifecycle && lifecycle.teardown) {
  12237. lifecycle.teardown();
  12238. }
  12239. }
  12240. });
  12241. }
  12242. function localeModule (name, lifecycle) {
  12243. QUnit.module('locale:' + name, {
  12244. setup : function () {
  12245. moment.locale(name);
  12246. moment.createFromInputFallback = function (config) {
  12247. throw new Error('input not handled by moment: ' + config._i);
  12248. };
  12249. if (lifecycle && lifecycle.setup) {
  12250. lifecycle.setup();
  12251. }
  12252. },
  12253. teardown : function () {
  12254. moment.locale('en');
  12255. if (lifecycle && lifecycle.teardown) {
  12256. lifecycle.teardown();
  12257. }
  12258. }
  12259. });
  12260. }
  12261. localeModule('gd');
  12262. var months = [
  12263. 'Am Faoilleach,Faoi',
  12264. 'An Gearran,Gear',
  12265. 'Am Màrt,Màrt',
  12266. 'An Giblean,Gibl',
  12267. 'An Cèitean,Cèit',
  12268. 'An t-Ògmhios,Ògmh',
  12269. 'An t-Iuchar,Iuch',
  12270. 'An Lùnastal,Lùn',
  12271. 'An t-Sultain,Sult',
  12272. 'An Dàmhair,Dàmh',
  12273. 'An t-Samhain,Samh',
  12274. 'An Dùbhlachd,Dùbh'
  12275. ];
  12276. test('parse', function (assert) {
  12277. function equalTest(monthName, monthFormat, monthNum) {
  12278. assert.equal(moment(monthName, monthFormat).month(), monthNum, monthName + ' should be month ' + (monthNum + 1));
  12279. }
  12280. for (var i = 0; i < 12; i++) {
  12281. var testMonth = months[i].split(',');
  12282. equalTest(testMonth[0], 'MMM', i);
  12283. equalTest(testMonth[1], 'MMM', i);
  12284. equalTest(testMonth[0], 'MMMM', i);
  12285. equalTest(testMonth[1], 'MMMM', i);
  12286. equalTest(testMonth[0].toLocaleLowerCase(), 'MMMM', i);
  12287. equalTest(testMonth[1].toLocaleLowerCase(), 'MMMM', i);
  12288. equalTest(testMonth[0].toLocaleUpperCase(), 'MMMM', i);
  12289. equalTest(testMonth[1].toLocaleUpperCase(), 'MMMM', i);
  12290. }
  12291. });
  12292. test('format', function (assert) {
  12293. var a = [
  12294. ['dddd, MMMM Do YYYY, h:mm:ss a', 'Didòmhnaich, An Gearran 14mh 2010, 3:25:50 pm'],
  12295. ['ddd, hA', 'Did, 3PM'],
  12296. ['M Mo MM MMMM MMM', '2 2na 02 An Gearran Gear'],
  12297. ['YYYY YY', '2010 10'],
  12298. ['D Do DD', '14 14mh 14'],
  12299. ['d do dddd ddd dd', '0 0mh Didòmhnaich Did Dò'],
  12300. ['DDD DDDo DDDD', '45 45mh 045'],
  12301. ['w wo ww', '6 6mh 06'],
  12302. ['h hh', '3 03'],
  12303. ['H HH', '15 15'],
  12304. ['m mm', '25 25'],
  12305. ['s ss', '50 50'],
  12306. ['a A', 'pm PM'],
  12307. ['[an] DDDo [latha den bhliadhna]', 'an 45mh latha den bhliadhna'],
  12308. ['LTS', '15:25:50'],
  12309. ['L', '14/02/2010'],
  12310. ['LL', '14 An Gearran 2010'],
  12311. ['LLL', '14 An Gearran 2010 15:25'],
  12312. ['LLLL', 'Didòmhnaich, 14 An Gearran 2010 15:25'],
  12313. ['l', '14/2/2010'],
  12314. ['ll', '14 Gear 2010'],
  12315. ['lll', '14 Gear 2010 15:25'],
  12316. ['llll', 'Did, 14 Gear 2010 15:25']
  12317. ],
  12318. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  12319. i;
  12320. for (i = 0; i < a.length; i++) {
  12321. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  12322. }
  12323. });
  12324. test('format ordinal', function (assert) {
  12325. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1d', '1d');
  12326. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2na', '2na');
  12327. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3mh', '3mh');
  12328. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4mh', '4mh');
  12329. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5mh', '5mh');
  12330. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6mh', '6mh');
  12331. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7mh', '7mh');
  12332. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8mh', '8mh');
  12333. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9mh', '9mh');
  12334. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10mh', '10mh');
  12335. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11mh', '11mh');
  12336. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12na', '12na');
  12337. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13mh', '13mh');
  12338. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14mh', '14mh');
  12339. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15mh', '15mh');
  12340. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16mh', '16mh');
  12341. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17mh', '17mh');
  12342. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18mh', '18mh');
  12343. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19mh', '19mh');
  12344. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20mh', '20mh');
  12345. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21mh', '21mh');
  12346. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22na', '22na');
  12347. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23mh', '23mh');
  12348. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24mh', '24mh');
  12349. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25mh', '25mh');
  12350. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26mh', '26mh');
  12351. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27mh', '27mh');
  12352. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28mh', '28mh');
  12353. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29mh', '29mh');
  12354. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30mh', '30mh');
  12355. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31mh', '31mh');
  12356. });
  12357. test('format month', function (assert) {
  12358. var expected = months;
  12359. for (var i = 0; i < expected.length; i++) {
  12360. assert.equal(moment([2011, i, 1]).format('MMMM,MMM'), expected[i], expected[i]);
  12361. }
  12362. });
  12363. test('format week', function (assert) {
  12364. var expected = ['Didòmhnaich Did Dò', 'Diluain Dil Lu', 'Dimàirt Dim Mà', 'Diciadain Dic Ci', 'Diardaoin Dia Ar', 'Dihaoine Dih Ha', 'Disathairne Dis Sa'];
  12365. for (var i = 0; i < expected.length; i++) {
  12366. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  12367. }
  12368. });
  12369. test('from', function (assert) {
  12370. var start = moment([2007, 1, 28]);
  12371. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'beagan diogan', '44 seconds = a few seconds');
  12372. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'mionaid', '45 seconds = a minute');
  12373. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'mionaid', '89 seconds = a minute');
  12374. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 mionaidean', '90 seconds = 2 minutes');
  12375. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 mionaidean', '44 minutes = 44 minutes');
  12376. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'uair', '45 minutes = an hour');
  12377. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'uair', '89 minutes = an hour');
  12378. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 uairean', '90 minutes = 2 hours');
  12379. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 uairean', '5 hours = 5 hours');
  12380. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 uairean', '21 hours = 21 hours');
  12381. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'latha', '22 hours = a day');
  12382. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'latha', '35 hours = a day');
  12383. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 latha', '36 hours = 2 days');
  12384. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'latha', '1 day = a day');
  12385. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 latha', '5 days = 5 days');
  12386. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 latha', '25 days = 25 days');
  12387. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'mìos', '26 days = a month');
  12388. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'mìos', '30 days = a month');
  12389. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'mìos', '43 days = a month');
  12390. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mìosan', '46 days = 2 months');
  12391. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mìosan', '75 days = 2 months');
  12392. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mìosan', '76 days = 3 months');
  12393. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'mìos', '1 month = a month');
  12394. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mìosan', '5 months = 5 months');
  12395. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'bliadhna', '345 days = a year');
  12396. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 bliadhna', '548 days = 2 years');
  12397. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'bliadhna', '1 year = a year');
  12398. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 bliadhna', '5 years = 5 years');
  12399. });
  12400. test('suffix', function (assert) {
  12401. assert.equal(moment(30000).from(0), 'ann an beagan diogan', 'prefix');
  12402. assert.equal(moment(0).from(30000), 'bho chionn beagan diogan', 'suffix');
  12403. });
  12404. test('now from now', function (assert) {
  12405. assert.equal(moment().fromNow(), 'bho chionn beagan diogan', 'now from now should display as in the past');
  12406. });
  12407. test('fromNow', function (assert) {
  12408. assert.equal(moment().add({s: 30}).fromNow(), 'ann an beagan diogan', 'in a few seconds');
  12409. assert.equal(moment().add({d: 5}).fromNow(), 'ann an 5 latha', 'in 5 days');
  12410. });
  12411. test('calendar day', function (assert) {
  12412. var a = moment().hours(2).minutes(0).seconds(0);
  12413. assert.equal(moment(a).calendar(), 'An-diugh aig 02:00', 'today at the same time');
  12414. assert.equal(moment(a).add({m: 25}).calendar(), 'An-diugh aig 02:25', 'Now plus 25 min');
  12415. assert.equal(moment(a).add({h: 1}).calendar(), 'An-diugh aig 03:00', 'Now plus 1 hour');
  12416. assert.equal(moment(a).add({d: 1}).calendar(), 'A-màireach aig 02:00', 'tomorrow at the same time');
  12417. assert.equal(moment(a).subtract({h: 1}).calendar(), 'An-diugh aig 01:00', 'Now minus 1 hour');
  12418. assert.equal(moment(a).subtract({d: 1}).calendar(), 'An-dè aig 02:00', 'yesterday at the same time');
  12419. });
  12420. test('calendar next week', function (assert) {
  12421. var i, m;
  12422. for (i = 2; i < 7; i++) {
  12423. m = moment().add({d: i});
  12424. assert.equal(m.calendar(), m.format('dddd [aig] LT'), 'Today + ' + i + ' days current time');
  12425. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  12426. assert.equal(m.calendar(), m.format('dddd [aig] LT'), 'Today + ' + i + ' days beginning of day');
  12427. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  12428. assert.equal(m.calendar(), m.format('dddd [aig] LT'), 'Today + ' + i + ' days end of day');
  12429. }
  12430. });
  12431. test('calendar last week', function (assert) {
  12432. var i, m;
  12433. for (i = 2; i < 7; i++) {
  12434. m = moment().subtract({d: i});
  12435. assert.equal(m.calendar(), m.format('dddd [seo chaidh] [aig] LT'), 'Today - ' + i + ' days current time');
  12436. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  12437. assert.equal(m.calendar(), m.format('dddd [seo chaidh] [aig] LT'), 'Today - ' + i + ' days beginning of day');
  12438. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  12439. assert.equal(m.calendar(), m.format('dddd [seo chaidh] [aig] LT'), 'Today - ' + i + ' days end of day');
  12440. }
  12441. });
  12442. test('calendar all else', function (assert) {
  12443. var weeksAgo = moment().subtract({w: 1}),
  12444. weeksFromNow = moment().add({w: 1});
  12445. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  12446. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  12447. weeksAgo = moment().subtract({w: 2});
  12448. weeksFromNow = moment().add({w: 2});
  12449. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  12450. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  12451. });
  12452. test('weeks year starting sunday', function (assert) {
  12453. assert.equal(moment([2012, 0, 1]).week(), 52, 'Faoi 1 2012 should be week 52');
  12454. assert.equal(moment([2012, 0, 2]).week(), 1, 'Faoi 2 2012 should be week 1');
  12455. assert.equal(moment([2012, 0, 8]).week(), 1, 'Faoi 8 2012 should be week 1');
  12456. assert.equal(moment([2012, 0, 9]).week(), 2, 'Faoi 9 2012 should be week 2');
  12457. assert.equal(moment([2012, 0, 15]).week(), 2, 'Faoi 15 2012 should be week 2');
  12458. });
  12459. test('weeks year starting monday', function (assert) {
  12460. assert.equal(moment([2007, 0, 1]).week(), 1, 'Faoi 1 2007 should be week 1');
  12461. assert.equal(moment([2007, 0, 7]).week(), 1, 'Faoi 7 2007 should be week 1');
  12462. assert.equal(moment([2007, 0, 8]).week(), 2, 'Faoi 8 2007 should be week 2');
  12463. assert.equal(moment([2007, 0, 14]).week(), 2, 'Faoi 14 2007 should be week 2');
  12464. assert.equal(moment([2007, 0, 15]).week(), 3, 'Faoi 15 2007 should be week 3');
  12465. });
  12466. test('weeks year starting tuesday', function (assert) {
  12467. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dùbh 31 2007 should be week 1');
  12468. assert.equal(moment([2008, 0, 1]).week(), 1, 'Faoi 1 2008 should be week 1');
  12469. assert.equal(moment([2008, 0, 6]).week(), 1, 'Faoi 6 2008 should be week 1');
  12470. assert.equal(moment([2008, 0, 7]).week(), 2, 'Faoi 7 2008 should be week 2');
  12471. assert.equal(moment([2008, 0, 13]).week(), 2, 'Faoi 13 2008 should be week 2');
  12472. assert.equal(moment([2008, 0, 14]).week(), 3, 'Faoi 14 2008 should be week 3');
  12473. });
  12474. test('weeks year starting wednesday', function (assert) {
  12475. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dùbh 30 2002 should be week 1');
  12476. assert.equal(moment([2003, 0, 1]).week(), 1, 'Faoi 1 2003 should be week 1');
  12477. assert.equal(moment([2003, 0, 5]).week(), 1, 'Faoi 5 2003 should be week 1');
  12478. assert.equal(moment([2003, 0, 6]).week(), 2, 'Faoi 6 2003 should be week 2');
  12479. assert.equal(moment([2003, 0, 12]).week(), 2, 'Faoi 12 2003 should be week 2');
  12480. assert.equal(moment([2003, 0, 13]).week(), 3, 'Faoi 13 2003 should be week 3');
  12481. });
  12482. test('weeks year starting thursday', function (assert) {
  12483. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dùbh 29 2008 should be week 1');
  12484. assert.equal(moment([2009, 0, 1]).week(), 1, 'Faoi 1 2009 should be week 1');
  12485. assert.equal(moment([2009, 0, 4]).week(), 1, 'Faoi 4 2009 should be week 1');
  12486. assert.equal(moment([2009, 0, 5]).week(), 2, 'Faoi 5 2009 should be week 2');
  12487. assert.equal(moment([2009, 0, 11]).week(), 2, 'Faoi 11 2009 should be week 2');
  12488. assert.equal(moment([2009, 0, 13]).week(), 3, 'Faoi 12 2009 should be week 3');
  12489. });
  12490. test('weeks year starting friday', function (assert) {
  12491. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dùbh 28 2009 should be week 53');
  12492. assert.equal(moment([2010, 0, 1]).week(), 53, 'Faoi 1 2010 should be week 53');
  12493. assert.equal(moment([2010, 0, 3]).week(), 53, 'Faoi 3 2010 should be week 53');
  12494. assert.equal(moment([2010, 0, 4]).week(), 1, 'Faoi 4 2010 should be week 1');
  12495. assert.equal(moment([2010, 0, 10]).week(), 1, 'Faoi 10 2010 should be week 1');
  12496. assert.equal(moment([2010, 0, 11]).week(), 2, 'Faoi 11 2010 should be week 2');
  12497. });
  12498. test('weeks year starting saturday', function (assert) {
  12499. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dùbh 27 2010 should be week 52');
  12500. assert.equal(moment([2011, 0, 1]).week(), 52, 'Faoi 1 2011 should be week 52');
  12501. assert.equal(moment([2011, 0, 2]).week(), 52, 'Faoi 2 2011 should be week 52');
  12502. assert.equal(moment([2011, 0, 3]).week(), 1, 'Faoi 3 2011 should be week 1');
  12503. assert.equal(moment([2011, 0, 9]).week(), 1, 'Faoi 9 2011 should be week 1');
  12504. assert.equal(moment([2011, 0, 10]).week(), 2, 'Faoi 10 2011 should be week 2');
  12505. });
  12506. test('weeks year starting sunday formatted', function (assert) {
  12507. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52na', 'Faoi 1 2012 should be week 52');
  12508. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1d', 'Faoi 2 2012 should be week 1');
  12509. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1d', 'Faoi 8 2012 should be week 1');
  12510. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2na', 'Faoi 9 2012 should be week 2');
  12511. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2na', 'Faoi 15 2012 should be week 2');
  12512. });
  12513. test('lenient ordinal parsing', function (assert) {
  12514. var i, ordinalStr, testMoment;
  12515. for (i = 1; i <= 31; ++i) {
  12516. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  12517. testMoment = moment(ordinalStr, 'YYYY MM Do');
  12518. assert.equal(testMoment.year(), 2014,
  12519. 'lenient ordinal parsing ' + i + ' year check');
  12520. assert.equal(testMoment.month(), 0,
  12521. 'lenient ordinal parsing ' + i + ' month check');
  12522. assert.equal(testMoment.date(), i,
  12523. 'lenient ordinal parsing ' + i + ' date check');
  12524. }
  12525. });
  12526. test('lenient ordinal parsing of number', function (assert) {
  12527. var i, testMoment;
  12528. for (i = 1; i <= 31; ++i) {
  12529. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  12530. assert.equal(testMoment.year(), 2014,
  12531. 'lenient ordinal parsing of number ' + i + ' year check');
  12532. assert.equal(testMoment.month(), 0,
  12533. 'lenient ordinal parsing of number ' + i + ' month check');
  12534. assert.equal(testMoment.date(), i,
  12535. 'lenient ordinal parsing of number ' + i + ' date check');
  12536. }
  12537. });
  12538. test('strict ordinal parsing', function (assert) {
  12539. var i, ordinalStr, testMoment;
  12540. for (i = 1; i <= 31; ++i) {
  12541. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  12542. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  12543. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  12544. }
  12545. });
  12546. }));
  12547. ;(function (global, factory) {
  12548. typeof exports === 'object' && typeof module !== 'undefined'
  12549. && typeof require === 'function' ? factory(require('../../moment')) :
  12550. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  12551. factory(global.moment)
  12552. }(this, function (moment) { 'use strict';
  12553. /*global QUnit:false*/
  12554. var test = QUnit.test;
  12555. var expect = QUnit.expect;
  12556. function module (name, lifecycle) {
  12557. QUnit.module(name, {
  12558. setup : function () {
  12559. moment.locale('en');
  12560. moment.createFromInputFallback = function (config) {
  12561. throw new Error('input not handled by moment: ' + config._i);
  12562. };
  12563. if (lifecycle && lifecycle.setup) {
  12564. lifecycle.setup();
  12565. }
  12566. },
  12567. teardown : function () {
  12568. if (lifecycle && lifecycle.teardown) {
  12569. lifecycle.teardown();
  12570. }
  12571. }
  12572. });
  12573. }
  12574. function localeModule (name, lifecycle) {
  12575. QUnit.module('locale:' + name, {
  12576. setup : function () {
  12577. moment.locale(name);
  12578. moment.createFromInputFallback = function (config) {
  12579. throw new Error('input not handled by moment: ' + config._i);
  12580. };
  12581. if (lifecycle && lifecycle.setup) {
  12582. lifecycle.setup();
  12583. }
  12584. },
  12585. teardown : function () {
  12586. moment.locale('en');
  12587. if (lifecycle && lifecycle.teardown) {
  12588. lifecycle.teardown();
  12589. }
  12590. }
  12591. });
  12592. }
  12593. localeModule('gl');
  12594. test('parse', function (assert) {
  12595. var tests = 'Xaneiro Xan._Febreiro Feb._Marzo Mar._Abril Abr._Maio Mai._Xuño Xuñ._Xullo Xul._Agosto Ago._Setembro Set._Outubro Out._Novembro Nov._Decembro Dec.'.split('_'), i;
  12596. function equalTest(input, mmm, i) {
  12597. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  12598. }
  12599. for (i = 0; i < 12; i++) {
  12600. tests[i] = tests[i].split(' ');
  12601. equalTest(tests[i][0], 'MMM', i);
  12602. equalTest(tests[i][1], 'MMM', i);
  12603. equalTest(tests[i][0], 'MMMM', i);
  12604. equalTest(tests[i][1], 'MMMM', i);
  12605. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  12606. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  12607. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  12608. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  12609. }
  12610. });
  12611. test('format', function (assert) {
  12612. var a = [
  12613. ['dddd, MMMM Do YYYY, h:mm:ss a', 'Domingo, Febreiro 14º 2010, 3:25:50 pm'],
  12614. ['ddd, hA', 'Dom., 3PM'],
  12615. ['M Mo MM MMMM MMM', '2 2º 02 Febreiro Feb.'],
  12616. ['YYYY YY', '2010 10'],
  12617. ['D Do DD', '14 14º 14'],
  12618. ['d do dddd ddd dd', '0 0º Domingo Dom. Do'],
  12619. ['DDD DDDo DDDD', '45 45º 045'],
  12620. ['w wo ww', '7 7º 07'],
  12621. ['h hh', '3 03'],
  12622. ['H HH', '15 15'],
  12623. ['m mm', '25 25'],
  12624. ['s ss', '50 50'],
  12625. ['a A', 'pm PM'],
  12626. ['[the] DDDo [day of the year]', 'the 45º day of the year'],
  12627. ['LTS', '15:25:50'],
  12628. ['L', '14/02/2010'],
  12629. ['LL', '14 Febreiro 2010'],
  12630. ['LLL', '14 Febreiro 2010 15:25'],
  12631. ['LLLL', 'Domingo 14 Febreiro 2010 15:25'],
  12632. ['l', '14/2/2010'],
  12633. ['ll', '14 Feb. 2010'],
  12634. ['lll', '14 Feb. 2010 15:25'],
  12635. ['llll', 'Dom. 14 Feb. 2010 15:25']
  12636. ],
  12637. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  12638. i;
  12639. for (i = 0; i < a.length; i++) {
  12640. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  12641. }
  12642. });
  12643. test('format ordinal', function (assert) {
  12644. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1º', '1º');
  12645. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2º', '2º');
  12646. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3º', '3º');
  12647. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4º', '4º');
  12648. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5º', '5º');
  12649. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6º', '6º');
  12650. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7º', '7º');
  12651. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8º', '8º');
  12652. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9º', '9º');
  12653. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10º', '10º');
  12654. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11º', '11º');
  12655. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12º', '12º');
  12656. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13º', '13º');
  12657. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14º', '14º');
  12658. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15º', '15º');
  12659. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16º', '16º');
  12660. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17º', '17º');
  12661. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18º', '18º');
  12662. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19º', '19º');
  12663. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20º', '20º');
  12664. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21º', '21º');
  12665. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22º', '22º');
  12666. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23º', '23º');
  12667. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24º', '24º');
  12668. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25º', '25º');
  12669. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26º', '26º');
  12670. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27º', '27º');
  12671. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28º', '28º');
  12672. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29º', '29º');
  12673. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30º', '30º');
  12674. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31º', '31º');
  12675. });
  12676. test('format month', function (assert) {
  12677. var expected = 'Xaneiro Xan._Febreiro Feb._Marzo Mar._Abril Abr._Maio Mai._Xuño Xuñ._Xullo Xul._Agosto Ago._Setembro Set._Outubro Out._Novembro Nov._Decembro Dec.'.split('_'), i;
  12678. for (i = 0; i < expected.length; i++) {
  12679. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  12680. }
  12681. });
  12682. test('format week', function (assert) {
  12683. var expected = 'Domingo Dom. Do_Luns Lun. Lu_Martes Mar. Ma_Mércores Mér. Mé_Xoves Xov. Xo_Venres Ven. Ve_Sábado Sáb. Sá'.split('_'),
  12684. i;
  12685. for (i = 0; i < expected.length; i++) {
  12686. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  12687. }
  12688. });
  12689. test('from', function (assert) {
  12690. var start = moment([2007, 1, 28]);
  12691. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'uns segundos', '44 seconds = a few seconds');
  12692. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'un minuto', '45 seconds = a minute');
  12693. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'un minuto', '89 seconds = a minute');
  12694. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutos', '90 seconds = 2 minutes');
  12695. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutos', '44 minutes = 44 minutes');
  12696. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'unha hora', '45 minutes = an hour');
  12697. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'unha hora', '89 minutes = an hour');
  12698. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 horas', '90 minutes = 2 hours');
  12699. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 horas', '5 hours = 5 hours');
  12700. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 horas', '21 hours = 21 hours');
  12701. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'un día', '22 hours = a day');
  12702. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'un día', '35 hours = a day');
  12703. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 días', '36 hours = 2 days');
  12704. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'un día', '1 day = a day');
  12705. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 días', '5 days = 5 days');
  12706. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 días', '25 days = 25 days');
  12707. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'un mes', '26 days = a month');
  12708. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'un mes', '30 days = a month');
  12709. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'un mes', '43 days = a month');
  12710. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 meses', '46 days = 2 months');
  12711. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 meses', '75 days = 2 months');
  12712. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 meses', '76 days = 3 months');
  12713. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'un mes', '1 month = a month');
  12714. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 meses', '5 months = 5 months');
  12715. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'un ano', '345 days = a year');
  12716. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 anos', '548 days = 2 years');
  12717. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'un ano', '1 year = a year');
  12718. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 anos', '5 years = 5 years');
  12719. });
  12720. test('suffix', function (assert) {
  12721. assert.equal(moment(30000).from(0), 'nuns segundos', 'prefix');
  12722. assert.equal(moment(0).from(30000), 'hai uns segundos', 'suffix');
  12723. });
  12724. test('now from now', function (assert) {
  12725. assert.equal(moment().fromNow(), 'hai uns segundos', 'now from now should display as in the past');
  12726. });
  12727. test('fromNow', function (assert) {
  12728. assert.equal(moment().add({s: 30}).fromNow(), 'nuns segundos', 'en unos segundos');
  12729. assert.equal(moment().add({d: 5}).fromNow(), 'en 5 días', 'en 5 días');
  12730. });
  12731. test('calendar day', function (assert) {
  12732. var a = moment().hours(2).minutes(0).seconds(0);
  12733. assert.equal(moment(a).calendar(), 'hoxe ás 2:00', 'today at the same time');
  12734. assert.equal(moment(a).add({m: 25}).calendar(), 'hoxe ás 2:25', 'Now plus 25 min');
  12735. assert.equal(moment(a).add({h: 1}).calendar(), 'hoxe ás 3:00', 'Now plus 1 hour');
  12736. assert.equal(moment(a).add({d: 1}).calendar(), 'mañá ás 2:00', 'tomorrow at the same time');
  12737. assert.equal(moment(a).add({d: 1, h : -1}).calendar(), 'mañá á 1:00', 'tomorrow minus 1 hour');
  12738. assert.equal(moment(a).subtract({h: 1}).calendar(), 'hoxe á 1:00', 'Now minus 1 hour');
  12739. assert.equal(moment(a).subtract({d: 1}).calendar(), 'onte á 2:00', 'yesterday at the same time');
  12740. });
  12741. test('calendar next week', function (assert) {
  12742. var i, m;
  12743. for (i = 2; i < 7; i++) {
  12744. m = moment().add({d: i});
  12745. assert.equal(m.calendar(), m.format('dddd [' + ((m.hours() !== 1) ? 'ás' : 'a') + '] LT'), 'Today + ' + i + ' days current time');
  12746. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  12747. assert.equal(m.calendar(), m.format('dddd [' + ((m.hours() !== 1) ? 'ás' : 'a') + '] LT'), 'Today + ' + i + ' days beginning of day');
  12748. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  12749. assert.equal(m.calendar(), m.format('dddd [' + ((m.hours() !== 1) ? 'ás' : 'a') + '] LT'), 'Today + ' + i + ' days end of day');
  12750. }
  12751. });
  12752. test('calendar last week', function (assert) {
  12753. var i, m;
  12754. for (i = 2; i < 7; i++) {
  12755. m = moment().subtract({d: i});
  12756. assert.equal(m.calendar(), m.format('[o] dddd [pasado ' + ((m.hours() !== 1) ? 'ás' : 'a') + '] LT'), 'Today - ' + i + ' days current time');
  12757. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  12758. assert.equal(m.calendar(), m.format('[o] dddd [pasado ' + ((m.hours() !== 1) ? 'ás' : 'a') + '] LT'), 'Today - ' + i + ' days beginning of day');
  12759. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  12760. assert.equal(m.calendar(), m.format('[o] dddd [pasado ' + ((m.hours() !== 1) ? 'ás' : 'a') + '] LT'), 'Today - ' + i + ' days end of day');
  12761. }
  12762. });
  12763. test('calendar all else', function (assert) {
  12764. var weeksAgo = moment().subtract({w: 1}),
  12765. weeksFromNow = moment().add({w: 1});
  12766. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  12767. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  12768. weeksAgo = moment().subtract({w: 2});
  12769. weeksFromNow = moment().add({w: 2});
  12770. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  12771. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  12772. });
  12773. test('regression tests', function (assert) {
  12774. var lastWeek = moment().subtract({d: 4}).hours(1);
  12775. assert.equal(lastWeek.calendar(), lastWeek.format('[o] dddd [pasado a] LT'), '1 o\'clock bug');
  12776. });
  12777. test('weeks year starting sunday', function (assert) {
  12778. assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1');
  12779. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  12780. assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2');
  12781. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  12782. assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3');
  12783. });
  12784. test('weeks year starting monday', function (assert) {
  12785. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  12786. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  12787. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  12788. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  12789. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  12790. });
  12791. test('weeks year starting tuesday', function (assert) {
  12792. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  12793. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  12794. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  12795. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  12796. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  12797. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  12798. });
  12799. test('weeks year starting wednesday', function (assert) {
  12800. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  12801. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  12802. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  12803. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  12804. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  12805. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  12806. });
  12807. test('weeks year starting thursday', function (assert) {
  12808. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  12809. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  12810. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  12811. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  12812. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  12813. assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3');
  12814. });
  12815. test('weeks year starting friday', function (assert) {
  12816. assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1');
  12817. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  12818. assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1');
  12819. assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2');
  12820. assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2');
  12821. assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3');
  12822. });
  12823. test('weeks year starting saturday', function (assert) {
  12824. assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1');
  12825. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  12826. assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1');
  12827. assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2');
  12828. assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2');
  12829. assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3');
  12830. });
  12831. test('weeks year starting sunday formatted', function (assert) {
  12832. assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1º', 'Dec 26 2011 should be week 1');
  12833. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1º', 'Jan 1 2012 should be week 1');
  12834. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2º', 'Jan 2 2012 should be week 2');
  12835. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2º', 'Jan 8 2012 should be week 2');
  12836. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3º', 'Jan 9 2012 should be week 3');
  12837. });
  12838. test('lenient ordinal parsing', function (assert) {
  12839. var i, ordinalStr, testMoment;
  12840. for (i = 1; i <= 31; ++i) {
  12841. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  12842. testMoment = moment(ordinalStr, 'YYYY MM Do');
  12843. assert.equal(testMoment.year(), 2014,
  12844. 'lenient ordinal parsing ' + i + ' year check');
  12845. assert.equal(testMoment.month(), 0,
  12846. 'lenient ordinal parsing ' + i + ' month check');
  12847. assert.equal(testMoment.date(), i,
  12848. 'lenient ordinal parsing ' + i + ' date check');
  12849. }
  12850. });
  12851. test('lenient ordinal parsing of number', function (assert) {
  12852. var i, testMoment;
  12853. for (i = 1; i <= 31; ++i) {
  12854. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  12855. assert.equal(testMoment.year(), 2014,
  12856. 'lenient ordinal parsing of number ' + i + ' year check');
  12857. assert.equal(testMoment.month(), 0,
  12858. 'lenient ordinal parsing of number ' + i + ' month check');
  12859. assert.equal(testMoment.date(), i,
  12860. 'lenient ordinal parsing of number ' + i + ' date check');
  12861. }
  12862. });
  12863. test('strict ordinal parsing', function (assert) {
  12864. var i, ordinalStr, testMoment;
  12865. for (i = 1; i <= 31; ++i) {
  12866. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  12867. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  12868. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  12869. }
  12870. });
  12871. }));
  12872. ;(function (global, factory) {
  12873. typeof exports === 'object' && typeof module !== 'undefined'
  12874. && typeof require === 'function' ? factory(require('../../moment')) :
  12875. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  12876. factory(global.moment)
  12877. }(this, function (moment) { 'use strict';
  12878. /*global QUnit:false*/
  12879. var test = QUnit.test;
  12880. var expect = QUnit.expect;
  12881. function module (name, lifecycle) {
  12882. QUnit.module(name, {
  12883. setup : function () {
  12884. moment.locale('en');
  12885. moment.createFromInputFallback = function (config) {
  12886. throw new Error('input not handled by moment: ' + config._i);
  12887. };
  12888. if (lifecycle && lifecycle.setup) {
  12889. lifecycle.setup();
  12890. }
  12891. },
  12892. teardown : function () {
  12893. if (lifecycle && lifecycle.teardown) {
  12894. lifecycle.teardown();
  12895. }
  12896. }
  12897. });
  12898. }
  12899. function localeModule (name, lifecycle) {
  12900. QUnit.module('locale:' + name, {
  12901. setup : function () {
  12902. moment.locale(name);
  12903. moment.createFromInputFallback = function (config) {
  12904. throw new Error('input not handled by moment: ' + config._i);
  12905. };
  12906. if (lifecycle && lifecycle.setup) {
  12907. lifecycle.setup();
  12908. }
  12909. },
  12910. teardown : function () {
  12911. moment.locale('en');
  12912. if (lifecycle && lifecycle.teardown) {
  12913. lifecycle.teardown();
  12914. }
  12915. }
  12916. });
  12917. }
  12918. localeModule('he');
  12919. test('parse', function (assert) {
  12920. var tests = 'ינואר ינו׳_פברואר פבר׳_מרץ מרץ_אפריל אפר׳_מאי מאי_יוני יוני_יולי יולי_אוגוסט אוג׳_ספטמבר ספט׳_אוקטובר אוק׳_נובמבר נוב׳_דצמבר דצמ׳'.split('_'), i;
  12921. function equalTest(input, mmm, i) {
  12922. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  12923. }
  12924. for (i = 0; i < 12; i++) {
  12925. tests[i] = tests[i].split(' ');
  12926. equalTest(tests[i][0], 'MMM', i);
  12927. equalTest(tests[i][1], 'MMM', i);
  12928. equalTest(tests[i][0], 'MMMM', i);
  12929. equalTest(tests[i][1], 'MMMM', i);
  12930. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  12931. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  12932. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  12933. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  12934. }
  12935. });
  12936. test('format', function (assert) {
  12937. var a = [
  12938. ['dddd, MMMM Do YYYY, h:mm:ss a', 'ראשון, פברואר 14 2010, 3:25:50 pm'],
  12939. ['ddd, hA', 'א׳, 3PM'],
  12940. ['M Mo MM MMMM MMM', '2 2 02 פברואר פבר׳'],
  12941. ['YYYY YY', '2010 10'],
  12942. ['D Do DD', '14 14 14'],
  12943. ['d do dddd ddd dd', '0 0 ראשון א׳ א'],
  12944. ['DDD DDDo DDDD', '45 45 045'],
  12945. ['w wo ww', '8 8 08'],
  12946. ['h hh', '3 03'],
  12947. ['H HH', '15 15'],
  12948. ['m mm', '25 25'],
  12949. ['s ss', '50 50'],
  12950. ['a A', 'pm PM'],
  12951. ['[the] DDDo [day of the year]', 'the 45 day of the year'],
  12952. ['LTS', '15:25:50'],
  12953. ['L', '14/02/2010'],
  12954. ['LL', '14 בפברואר 2010'],
  12955. ['LLL', '14 בפברואר 2010 15:25'],
  12956. ['LLLL', 'ראשון, 14 בפברואר 2010 15:25'],
  12957. ['l', '14/2/2010'],
  12958. ['ll', '14 פבר׳ 2010'],
  12959. ['lll', '14 פבר׳ 2010 15:25'],
  12960. ['llll', 'א׳, 14 פבר׳ 2010 15:25']
  12961. ],
  12962. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  12963. i;
  12964. for (i = 0; i < a.length; i++) {
  12965. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  12966. }
  12967. });
  12968. test('format month', function (assert) {
  12969. var expected = 'ינואר ינו׳_פברואר פבר׳_מרץ מרץ_אפריל אפר׳_מאי מאי_יוני יוני_יולי יולי_אוגוסט אוג׳_ספטמבר ספט׳_אוקטובר אוק׳_נובמבר נוב׳_דצמבר דצמ׳'.split('_'), i;
  12970. for (i = 0; i < expected.length; i++) {
  12971. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  12972. }
  12973. });
  12974. test('format week', function (assert) {
  12975. var expected = 'ראשון א׳ א|שני ב׳ ב|שלישי ג׳ ג|רביעי ד׳ ד|חמישי ה׳ ה|שישי ו׳ ו|שבת ש׳ ש'.split('|'), i;
  12976. for (i = 0; i < expected.length; i++) {
  12977. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  12978. }
  12979. });
  12980. test('from', function (assert) {
  12981. var start = moment([2007, 1, 28]);
  12982. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'מספר שניות', '44 seconds = a few seconds');
  12983. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'דקה', '45 seconds = a minute');
  12984. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'דקה', '89 seconds = a minute');
  12985. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 דקות', '90 seconds = 2 minutes');
  12986. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 דקות', '44 minutes = 44 minutes');
  12987. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'שעה', '45 minutes = an hour');
  12988. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'שעה', '89 minutes = an hour');
  12989. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), 'שעתיים', '90 minutes = 2 hours');
  12990. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 שעות', '5 hours = 5 hours');
  12991. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 שעות', '21 hours = 21 hours');
  12992. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'יום', '22 hours = a day');
  12993. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'יום', '35 hours = a day');
  12994. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), 'יומיים', '36 hours = 2 days');
  12995. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'יום', '1 day = a day');
  12996. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 ימים', '5 days = 5 days');
  12997. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 ימים', '25 days = 25 days');
  12998. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'חודש', '26 days = a month');
  12999. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'חודש', '30 days = a month');
  13000. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'חודש', '43 days = a month');
  13001. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), 'חודשיים', '46 days = 2 months');
  13002. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), 'חודשיים', '75 days = 2 months');
  13003. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 חודשים', '76 days = 3 months');
  13004. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'חודש', '1 month = a month');
  13005. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 חודשים', '5 months = 5 months');
  13006. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'שנה', '345 days = a year');
  13007. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), 'שנתיים', '548 days = 2 years');
  13008. assert.equal(start.from(moment([2007, 1, 28]).add({d: 3699}), true), '10 שנים', '345 days = 10 years');
  13009. assert.equal(start.from(moment([2007, 1, 28]).add({d: 7340}), true), '20 שנה', '548 days = 20 years');
  13010. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'שנה', '1 year = a year');
  13011. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 שנים', '5 years = 5 years');
  13012. });
  13013. test('suffix', function (assert) {
  13014. assert.equal(moment(30000).from(0), 'בעוד מספר שניות', 'prefix');
  13015. assert.equal(moment(0).from(30000), 'לפני מספר שניות', 'suffix');
  13016. });
  13017. test('now from now', function (assert) {
  13018. assert.equal(moment().fromNow(), 'לפני מספר שניות', 'now from now should display as in the past');
  13019. });
  13020. test('fromNow', function (assert) {
  13021. assert.equal(moment().add({s: 30}).fromNow(), 'בעוד מספר שניות', 'in a few seconds');
  13022. assert.equal(moment().add({d: 5}).fromNow(), 'בעוד 5 ימים', 'in 5 days');
  13023. });
  13024. test('calendar day', function (assert) {
  13025. var a = moment().hours(2).minutes(0).seconds(0);
  13026. assert.equal(moment(a).calendar(), 'היום ב־02:00', 'today at the same time');
  13027. assert.equal(moment(a).add({m: 25}).calendar(), 'היום ב־02:25', 'Now plus 25 min');
  13028. assert.equal(moment(a).add({h: 1}).calendar(), 'היום ב־03:00', 'Now plus 1 hour');
  13029. assert.equal(moment(a).add({d: 1}).calendar(), 'מחר ב־02:00', 'tomorrow at the same time');
  13030. assert.equal(moment(a).subtract({h: 1}).calendar(), 'היום ב־01:00', 'Now minus 1 hour');
  13031. assert.equal(moment(a).subtract({d: 1}).calendar(), 'אתמול ב־02:00', 'yesterday at the same time');
  13032. });
  13033. test('calendar next week', function (assert) {
  13034. var i, m;
  13035. for (i = 2; i < 7; i++) {
  13036. m = moment().add({d: i});
  13037. assert.equal(m.calendar(), m.format('dddd [בשעה] LT'), 'Today + ' + i + ' days current time');
  13038. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  13039. assert.equal(m.calendar(), m.format('dddd [בשעה] LT'), 'Today + ' + i + ' days beginning of day');
  13040. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  13041. assert.equal(m.calendar(), m.format('dddd [בשעה] LT'), 'Today + ' + i + ' days end of day');
  13042. }
  13043. });
  13044. test('calendar last week', function (assert) {
  13045. var i, m;
  13046. for (i = 2; i < 7; i++) {
  13047. m = moment().subtract({d: i});
  13048. assert.equal(m.calendar(), m.format('[ביום] dddd [האחרון בשעה] LT'), 'Today - ' + i + ' days current time');
  13049. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  13050. assert.equal(m.calendar(), m.format('[ביום] dddd [האחרון בשעה] LT'), 'Today - ' + i + ' days beginning of day');
  13051. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  13052. assert.equal(m.calendar(), m.format('[ביום] dddd [האחרון בשעה] LT'), 'Today - ' + i + ' days end of day');
  13053. }
  13054. });
  13055. test('calendar all else', function (assert) {
  13056. var weeksAgo = moment().subtract({w: 1}),
  13057. weeksFromNow = moment().add({w: 1});
  13058. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  13059. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  13060. weeksAgo = moment().subtract({w: 2});
  13061. weeksFromNow = moment().add({w: 2});
  13062. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  13063. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  13064. });
  13065. test('weeks year starting sunday', function (assert) {
  13066. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  13067. assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1');
  13068. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  13069. assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2');
  13070. assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 3');
  13071. });
  13072. test('weeks year starting monday', function (assert) {
  13073. assert.equal(moment([2006, 11, 31]).week(), 1, 'Dec 31 2006 should be week 1');
  13074. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  13075. assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1');
  13076. assert.equal(moment([2007, 0, 7]).week(), 2, 'Jan 7 2007 should be week 2');
  13077. assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2');
  13078. assert.equal(moment([2007, 0, 14]).week(), 3, 'Jan 14 2007 should be week 3');
  13079. });
  13080. test('weeks year starting tuesday', function (assert) {
  13081. assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52');
  13082. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  13083. assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1');
  13084. assert.equal(moment([2008, 0, 6]).week(), 2, 'Jan 6 2008 should be week 2');
  13085. assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2');
  13086. assert.equal(moment([2008, 0, 13]).week(), 3, 'Jan 13 2008 should be week 3');
  13087. });
  13088. test('weeks year starting wednesday', function (assert) {
  13089. assert.equal(moment([2002, 11, 29]).week(), 1, 'Dec 29 2002 should be week 1');
  13090. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  13091. assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1');
  13092. assert.equal(moment([2003, 0, 5]).week(), 2, 'Jan 5 2003 should be week 2');
  13093. assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2');
  13094. assert.equal(moment([2003, 0, 12]).week(), 3, 'Jan 12 2003 should be week 3');
  13095. });
  13096. test('weeks year starting thursday', function (assert) {
  13097. assert.equal(moment([2008, 11, 28]).week(), 1, 'Dec 28 2008 should be week 1');
  13098. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  13099. assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1');
  13100. assert.equal(moment([2009, 0, 4]).week(), 2, 'Jan 4 2009 should be week 2');
  13101. assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2');
  13102. assert.equal(moment([2009, 0, 11]).week(), 3, 'Jan 11 2009 should be week 3');
  13103. });
  13104. test('weeks year starting friday', function (assert) {
  13105. assert.equal(moment([2009, 11, 27]).week(), 1, 'Dec 27 2009 should be week 1');
  13106. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  13107. assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 should be week 1');
  13108. assert.equal(moment([2010, 0, 3]).week(), 2, 'Jan 3 2010 should be week 2');
  13109. assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 should be week 2');
  13110. assert.equal(moment([2010, 0, 10]).week(), 3, 'Jan 10 2010 should be week 3');
  13111. });
  13112. test('weeks year starting saturday', function (assert) {
  13113. assert.equal(moment([2010, 11, 26]).week(), 1, 'Dec 26 2010 should be week 1');
  13114. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  13115. assert.equal(moment([2011, 0, 2]).week(), 2, 'Jan 2 2011 should be week 2');
  13116. assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2');
  13117. assert.equal(moment([2011, 0, 9]).week(), 3, 'Jan 9 2011 should be week 3');
  13118. });
  13119. test('weeks year starting sunday format', function (assert) {
  13120. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1', 'Jan 1 2012 should be week 1');
  13121. assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1', 'Jan 7 2012 should be week 1');
  13122. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2', 'Jan 8 2012 should be week 2');
  13123. assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2', 'Jan 14 2012 should be week 2');
  13124. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3', 'Jan 15 2012 should be week 3');
  13125. });
  13126. test('lenient ordinal parsing', function (assert) {
  13127. var i, ordinalStr, testMoment;
  13128. for (i = 1; i <= 31; ++i) {
  13129. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  13130. testMoment = moment(ordinalStr, 'YYYY MM Do');
  13131. assert.equal(testMoment.year(), 2014,
  13132. 'lenient ordinal parsing ' + i + ' year check');
  13133. assert.equal(testMoment.month(), 0,
  13134. 'lenient ordinal parsing ' + i + ' month check');
  13135. assert.equal(testMoment.date(), i,
  13136. 'lenient ordinal parsing ' + i + ' date check');
  13137. }
  13138. });
  13139. test('lenient ordinal parsing of number', function (assert) {
  13140. var i, testMoment;
  13141. for (i = 1; i <= 31; ++i) {
  13142. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  13143. assert.equal(testMoment.year(), 2014,
  13144. 'lenient ordinal parsing of number ' + i + ' year check');
  13145. assert.equal(testMoment.month(), 0,
  13146. 'lenient ordinal parsing of number ' + i + ' month check');
  13147. assert.equal(testMoment.date(), i,
  13148. 'lenient ordinal parsing of number ' + i + ' date check');
  13149. }
  13150. });
  13151. test('strict ordinal parsing', function (assert) {
  13152. var i, ordinalStr, testMoment;
  13153. for (i = 1; i <= 31; ++i) {
  13154. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  13155. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  13156. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  13157. }
  13158. });
  13159. }));
  13160. ;(function (global, factory) {
  13161. typeof exports === 'object' && typeof module !== 'undefined'
  13162. && typeof require === 'function' ? factory(require('../../moment')) :
  13163. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  13164. factory(global.moment)
  13165. }(this, function (moment) { 'use strict';
  13166. /*global QUnit:false*/
  13167. var test = QUnit.test;
  13168. var expect = QUnit.expect;
  13169. function module (name, lifecycle) {
  13170. QUnit.module(name, {
  13171. setup : function () {
  13172. moment.locale('en');
  13173. moment.createFromInputFallback = function (config) {
  13174. throw new Error('input not handled by moment: ' + config._i);
  13175. };
  13176. if (lifecycle && lifecycle.setup) {
  13177. lifecycle.setup();
  13178. }
  13179. },
  13180. teardown : function () {
  13181. if (lifecycle && lifecycle.teardown) {
  13182. lifecycle.teardown();
  13183. }
  13184. }
  13185. });
  13186. }
  13187. function localeModule (name, lifecycle) {
  13188. QUnit.module('locale:' + name, {
  13189. setup : function () {
  13190. moment.locale(name);
  13191. moment.createFromInputFallback = function (config) {
  13192. throw new Error('input not handled by moment: ' + config._i);
  13193. };
  13194. if (lifecycle && lifecycle.setup) {
  13195. lifecycle.setup();
  13196. }
  13197. },
  13198. teardown : function () {
  13199. moment.locale('en');
  13200. if (lifecycle && lifecycle.teardown) {
  13201. lifecycle.teardown();
  13202. }
  13203. }
  13204. });
  13205. }
  13206. localeModule('hi');
  13207. test('parse', function (assert) {
  13208. var tests = 'जनवरी जन._फ़रवरी फ़र._मार्च मार्च_अप्रैल अप्रै._मई मई_जून जून_जुलाई जुल._अगस्त अग._सितम्बर सित._अक्टूबर अक्टू._नवम्बर नव._दिसम्बर दिस.'.split('_'), i;
  13209. function equalTest(input, mmm, i) {
  13210. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  13211. }
  13212. for (i = 0; i < 12; i++) {
  13213. tests[i] = tests[i].split(' ');
  13214. equalTest(tests[i][0], 'MMM', i);
  13215. equalTest(tests[i][1], 'MMM', i);
  13216. equalTest(tests[i][0], 'MMMM', i);
  13217. equalTest(tests[i][1], 'MMMM', i);
  13218. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  13219. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  13220. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  13221. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  13222. }
  13223. });
  13224. test('format', function (assert) {
  13225. var a = [
  13226. ['dddd, Do MMMM YYYY, a h:mm:ss बजे', 'रविवार, १४ फ़रवरी २०१०, दोपहर ३:२५:५० बजे'],
  13227. ['ddd, a h बजे', 'रवि, दोपहर ३ बजे'],
  13228. ['M Mo MM MMMM MMM', '२ २ ०२ फ़रवरी फ़र.'],
  13229. ['YYYY YY', '२०१० १०'],
  13230. ['D Do DD', '१४ १४ १४'],
  13231. ['d do dddd ddd dd', '० ० रविवार रवि र'],
  13232. ['DDD DDDo DDDD', '४५ ४५ ०४५'],
  13233. ['w wo ww', '८ ८ ०८'],
  13234. ['h hh', '३ ०३'],
  13235. ['H HH', '१५ १५'],
  13236. ['m mm', '२५ २५'],
  13237. ['s ss', '५० ५०'],
  13238. ['a A', 'दोपहर दोपहर'],
  13239. ['LTS', 'दोपहर ३:२५:५० बजे'],
  13240. ['L', '१४/०२/२०१०'],
  13241. ['LL', '१४ फ़रवरी २०१०'],
  13242. ['LLL', '१४ फ़रवरी २०१०, दोपहर ३:२५ बजे'],
  13243. ['LLLL', 'रविवार, १४ फ़रवरी २०१०, दोपहर ३:२५ बजे'],
  13244. ['l', '१४/२/२०१०'],
  13245. ['ll', '१४ फ़र. २०१०'],
  13246. ['lll', '१४ फ़र. २०१०, दोपहर ३:२५ बजे'],
  13247. ['llll', 'रवि, १४ फ़र. २०१०, दोपहर ३:२५ बजे']
  13248. ],
  13249. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  13250. i;
  13251. for (i = 0; i < a.length; i++) {
  13252. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  13253. }
  13254. });
  13255. test('format ordinal', function (assert) {
  13256. assert.equal(moment([2011, 0, 1]).format('DDDo'), '१', '१');
  13257. assert.equal(moment([2011, 0, 2]).format('DDDo'), '२', '२');
  13258. assert.equal(moment([2011, 0, 3]).format('DDDo'), '३', '३');
  13259. assert.equal(moment([2011, 0, 4]).format('DDDo'), '४', '४');
  13260. assert.equal(moment([2011, 0, 5]).format('DDDo'), '५', '५');
  13261. assert.equal(moment([2011, 0, 6]).format('DDDo'), '६', '६');
  13262. assert.equal(moment([2011, 0, 7]).format('DDDo'), '७', '७');
  13263. assert.equal(moment([2011, 0, 8]).format('DDDo'), '८', '८');
  13264. assert.equal(moment([2011, 0, 9]).format('DDDo'), '९', '९');
  13265. assert.equal(moment([2011, 0, 10]).format('DDDo'), '१०', '१०');
  13266. assert.equal(moment([2011, 0, 11]).format('DDDo'), '११', '११');
  13267. assert.equal(moment([2011, 0, 12]).format('DDDo'), '१२', '१२');
  13268. assert.equal(moment([2011, 0, 13]).format('DDDo'), '१३', '१३');
  13269. assert.equal(moment([2011, 0, 14]).format('DDDo'), '१४', '१४');
  13270. assert.equal(moment([2011, 0, 15]).format('DDDo'), '१५', '१५');
  13271. assert.equal(moment([2011, 0, 16]).format('DDDo'), '१६', '१६');
  13272. assert.equal(moment([2011, 0, 17]).format('DDDo'), '१७', '१७');
  13273. assert.equal(moment([2011, 0, 18]).format('DDDo'), '१८', '१८');
  13274. assert.equal(moment([2011, 0, 19]).format('DDDo'), '१९', '१९');
  13275. assert.equal(moment([2011, 0, 20]).format('DDDo'), '२०', '२०');
  13276. assert.equal(moment([2011, 0, 21]).format('DDDo'), '२१', '२१');
  13277. assert.equal(moment([2011, 0, 22]).format('DDDo'), '२२', '२२');
  13278. assert.equal(moment([2011, 0, 23]).format('DDDo'), '२३', '२३');
  13279. assert.equal(moment([2011, 0, 24]).format('DDDo'), '२४', '२४');
  13280. assert.equal(moment([2011, 0, 25]).format('DDDo'), '२५', '२५');
  13281. assert.equal(moment([2011, 0, 26]).format('DDDo'), '२६', '२६');
  13282. assert.equal(moment([2011, 0, 27]).format('DDDo'), '२७', '२७');
  13283. assert.equal(moment([2011, 0, 28]).format('DDDo'), '२८', '२८');
  13284. assert.equal(moment([2011, 0, 29]).format('DDDo'), '२९', '२९');
  13285. assert.equal(moment([2011, 0, 30]).format('DDDo'), '३०', '३०');
  13286. assert.equal(moment([2011, 0, 31]).format('DDDo'), '३१', '३१');
  13287. });
  13288. test('format month', function (assert) {
  13289. var expected = 'जनवरी जन._फ़रवरी फ़र._मार्च मार्च_अप्रैल अप्रै._मई मई_जून जून_जुलाई जुल._अगस्त अग._सितम्बर सित._अक्टूबर अक्टू._नवम्बर नव._दिसम्बर दिस.'.split('_'), i;
  13290. for (i = 0; i < expected.length; i++) {
  13291. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  13292. }
  13293. });
  13294. test('format week', function (assert) {
  13295. var expected = 'रविवार रवि र_सोमवार सोम सो_मंगलवार मंगल मं_बुधवार बुध बु_गुरूवार गुरू गु_शुक्रवार शुक्र शु_शनिवार शनि श'.split('_'), i;
  13296. for (i = 0; i < expected.length; i++) {
  13297. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  13298. }
  13299. });
  13300. test('from', function (assert) {
  13301. var start = moment([2007, 1, 28]);
  13302. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'कुछ ही क्षण', '44 seconds = a few seconds');
  13303. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'एक मिनट', '45 seconds = a minute');
  13304. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'एक मिनट', '89 seconds = a minute');
  13305. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '२ मिनट', '90 seconds = 2 minutes');
  13306. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '४४ मिनट', '44 minutes = 44 minutes');
  13307. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'एक घंटा', '45 minutes = an hour');
  13308. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'एक घंटा', '89 minutes = an hour');
  13309. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '२ घंटे', '90 minutes = 2 hours');
  13310. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '५ घंटे', '5 hours = 5 hours');
  13311. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '२१ घंटे', '21 hours = 21 hours');
  13312. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'एक दिन', '22 hours = a day');
  13313. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'एक दिन', '35 hours = a day');
  13314. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '२ दिन', '36 hours = 2 days');
  13315. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'एक दिन', '1 day = a day');
  13316. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '५ दिन', '5 days = 5 days');
  13317. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '२५ दिन', '25 days = 25 days');
  13318. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'एक महीने', '26 days = a month');
  13319. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'एक महीने', '30 days = a month');
  13320. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'एक महीने', '43 days = a month');
  13321. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '२ महीने', '46 days = 2 months');
  13322. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '२ महीने', '75 days = 2 months');
  13323. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '३ महीने', '76 days = 3 months');
  13324. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'एक महीने', '1 month = a month');
  13325. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '५ महीने', '5 months = 5 months');
  13326. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'एक वर्ष', '345 days = a year');
  13327. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '२ वर्ष', '548 days = 2 years');
  13328. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'एक वर्ष', '1 year = a year');
  13329. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '५ वर्ष', '5 years = 5 years');
  13330. });
  13331. test('suffix', function (assert) {
  13332. assert.equal(moment(30000).from(0), 'कुछ ही क्षण में', 'prefix');
  13333. assert.equal(moment(0).from(30000), 'कुछ ही क्षण पहले', 'suffix');
  13334. });
  13335. test('now from now', function (assert) {
  13336. assert.equal(moment().fromNow(), 'कुछ ही क्षण पहले', 'now from now should display as in the past');
  13337. });
  13338. test('fromNow', function (assert) {
  13339. assert.equal(moment().add({s: 30}).fromNow(), 'कुछ ही क्षण में', 'कुछ ही क्षण में');
  13340. assert.equal(moment().add({d: 5}).fromNow(), '५ दिन में', '५ दिन में');
  13341. });
  13342. test('calendar day', function (assert) {
  13343. var a = moment().hours(2).minutes(0).seconds(0);
  13344. assert.equal(moment(a).calendar(), 'आज रात २:०० बजे', 'today at the same time');
  13345. assert.equal(moment(a).add({m: 25}).calendar(), 'आज रात २:२५ बजे', 'Now plus 25 min');
  13346. assert.equal(moment(a).add({h: 3}).calendar(), 'आज सुबह ५:०० बजे', 'Now plus 3 hour');
  13347. assert.equal(moment(a).add({d: 1}).calendar(), 'कल रात २:०० बजे', 'tomorrow at the same time');
  13348. assert.equal(moment(a).subtract({h: 1}).calendar(), 'आज रात १:०० बजे', 'Now minus 1 hour');
  13349. assert.equal(moment(a).subtract({d: 1}).calendar(), 'कल रात २:०० बजे', 'yesterday at the same time');
  13350. });
  13351. test('calendar next week', function (assert) {
  13352. var i, m;
  13353. for (i = 2; i < 7; i++) {
  13354. m = moment().add({d: i});
  13355. assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days current time');
  13356. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  13357. assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days beginning of day');
  13358. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  13359. assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days end of day');
  13360. }
  13361. });
  13362. test('calendar last week', function (assert) {
  13363. var i, m;
  13364. for (i = 2; i < 7; i++) {
  13365. m = moment().subtract({d: i});
  13366. assert.equal(m.calendar(), m.format('[पिछले] dddd[,] LT'), 'Today - ' + i + ' days current time');
  13367. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  13368. assert.equal(m.calendar(), m.format('[पिछले] dddd[,] LT'), 'Today - ' + i + ' days beginning of day');
  13369. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  13370. assert.equal(m.calendar(), m.format('[पिछले] dddd[,] LT'), 'Today - ' + i + ' days end of day');
  13371. }
  13372. });
  13373. test('calendar all else', function (assert) {
  13374. var weeksAgo = moment().subtract({w: 1}),
  13375. weeksFromNow = moment().add({w: 1});
  13376. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  13377. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  13378. weeksAgo = moment().subtract({w: 2});
  13379. weeksFromNow = moment().add({w: 2});
  13380. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  13381. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  13382. });
  13383. test('meridiem invariant', function (assert) {
  13384. assert.equal(moment([2011, 2, 23, 2, 30]).format('a'), 'रात', 'before dawn');
  13385. assert.equal(moment([2011, 2, 23, 9, 30]).format('a'), 'सुबह', 'morning');
  13386. assert.equal(moment([2011, 2, 23, 14, 30]).format('a'), 'दोपहर', 'during day');
  13387. assert.equal(moment([2011, 2, 23, 17, 30]).format('a'), 'शाम', 'evening');
  13388. assert.equal(moment([2011, 2, 23, 19, 30]).format('a'), 'शाम', 'late evening');
  13389. assert.equal(moment([2011, 2, 23, 21, 20]).format('a'), 'रात', 'night');
  13390. assert.equal(moment([2011, 2, 23, 2, 30]).format('A'), 'रात', 'before dawn');
  13391. assert.equal(moment([2011, 2, 23, 9, 30]).format('A'), 'सुबह', 'morning');
  13392. assert.equal(moment([2011, 2, 23, 14, 30]).format('A'), 'दोपहर', ' during day');
  13393. assert.equal(moment([2011, 2, 23, 17, 30]).format('A'), 'शाम', 'evening');
  13394. assert.equal(moment([2011, 2, 23, 19, 30]).format('A'), 'शाम', 'late evening');
  13395. assert.equal(moment([2011, 2, 23, 21, 20]).format('A'), 'रात', 'night');
  13396. });
  13397. test('weeks year starting sunday', function (assert) {
  13398. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  13399. assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1');
  13400. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  13401. assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2');
  13402. assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 3');
  13403. });
  13404. test('weeks year starting monday', function (assert) {
  13405. assert.equal(moment([2006, 11, 31]).week(), 1, 'Dec 31 2006 should be week 1');
  13406. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  13407. assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1');
  13408. assert.equal(moment([2007, 0, 7]).week(), 2, 'Jan 7 2007 should be week 2');
  13409. assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2');
  13410. assert.equal(moment([2007, 0, 14]).week(), 3, 'Jan 14 2007 should be week 3');
  13411. });
  13412. test('weeks year starting tuesday', function (assert) {
  13413. assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52');
  13414. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  13415. assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1');
  13416. assert.equal(moment([2008, 0, 6]).week(), 2, 'Jan 6 2008 should be week 2');
  13417. assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2');
  13418. assert.equal(moment([2008, 0, 13]).week(), 3, 'Jan 13 2008 should be week 3');
  13419. });
  13420. test('weeks year starting wednesday', function (assert) {
  13421. assert.equal(moment([2002, 11, 29]).week(), 1, 'Dec 29 2002 should be week 1');
  13422. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  13423. assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1');
  13424. assert.equal(moment([2003, 0, 5]).week(), 2, 'Jan 5 2003 should be week 2');
  13425. assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2');
  13426. assert.equal(moment([2003, 0, 12]).week(), 3, 'Jan 12 2003 should be week 3');
  13427. });
  13428. test('weeks year starting thursday', function (assert) {
  13429. assert.equal(moment([2008, 11, 28]).week(), 1, 'Dec 28 2008 should be week 1');
  13430. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  13431. assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1');
  13432. assert.equal(moment([2009, 0, 4]).week(), 2, 'Jan 4 2009 should be week 2');
  13433. assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2');
  13434. assert.equal(moment([2009, 0, 11]).week(), 3, 'Jan 11 2009 should be week 3');
  13435. });
  13436. test('weeks year starting friday', function (assert) {
  13437. assert.equal(moment([2009, 11, 27]).week(), 1, 'Dec 27 2009 should be week 1');
  13438. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  13439. assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 should be week 1');
  13440. assert.equal(moment([2010, 0, 3]).week(), 2, 'Jan 3 2010 should be week 2');
  13441. assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 should be week 2');
  13442. assert.equal(moment([2010, 0, 10]).week(), 3, 'Jan 10 2010 should be week 3');
  13443. });
  13444. test('weeks year starting saturday', function (assert) {
  13445. assert.equal(moment([2010, 11, 26]).week(), 1, 'Dec 26 2010 should be week 1');
  13446. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  13447. assert.equal(moment([2011, 0, 2]).week(), 2, 'Jan 2 2011 should be week 2');
  13448. assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2');
  13449. assert.equal(moment([2011, 0, 9]).week(), 3, 'Jan 9 2011 should be week 3');
  13450. });
  13451. test('weeks year starting sunday formatted', function (assert) {
  13452. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '१ ०१ १', 'Jan 1 2012 should be week 1');
  13453. assert.equal(moment([2012, 0, 7]).format('w ww wo'), '१ ०१ १', 'Jan 7 2012 should be week 1');
  13454. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '२ ०२ २', 'Jan 8 2012 should be week 2');
  13455. assert.equal(moment([2012, 0, 14]).format('w ww wo'), '२ ०२ २', 'Jan 14 2012 should be week 2');
  13456. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '३ ०३ ३', 'Jan 15 2012 should be week 3');
  13457. });
  13458. test('lenient ordinal parsing', function (assert) {
  13459. var i, ordinalStr, testMoment;
  13460. for (i = 1; i <= 31; ++i) {
  13461. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  13462. testMoment = moment(ordinalStr, 'YYYY MM Do');
  13463. assert.equal(testMoment.year(), 2014,
  13464. 'lenient ordinal parsing ' + i + ' year check');
  13465. assert.equal(testMoment.month(), 0,
  13466. 'lenient ordinal parsing ' + i + ' month check');
  13467. assert.equal(testMoment.date(), i,
  13468. 'lenient ordinal parsing ' + i + ' date check');
  13469. }
  13470. });
  13471. test('lenient ordinal parsing of number', function (assert) {
  13472. var i, testMoment;
  13473. for (i = 1; i <= 31; ++i) {
  13474. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  13475. assert.equal(testMoment.year(), 2014,
  13476. 'lenient ordinal parsing of number ' + i + ' year check');
  13477. assert.equal(testMoment.month(), 0,
  13478. 'lenient ordinal parsing of number ' + i + ' month check');
  13479. assert.equal(testMoment.date(), i,
  13480. 'lenient ordinal parsing of number ' + i + ' date check');
  13481. }
  13482. });
  13483. test('meridiem', function (assert) {
  13484. var h, m, t1, t2;
  13485. for (h = 0; h < 24; ++h) {
  13486. for (m = 0; m < 60; m += 15) {
  13487. t1 = moment.utc([2000, 0, 1, h, m]);
  13488. t2 = moment(t1.format('A h:mm'), 'A h:mm');
  13489. assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
  13490. 'meridiem at ' + t1.format('HH:mm'));
  13491. }
  13492. }
  13493. });
  13494. test('strict ordinal parsing', function (assert) {
  13495. var i, ordinalStr, testMoment;
  13496. for (i = 1; i <= 31; ++i) {
  13497. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  13498. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  13499. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  13500. }
  13501. });
  13502. }));
  13503. ;(function (global, factory) {
  13504. typeof exports === 'object' && typeof module !== 'undefined'
  13505. && typeof require === 'function' ? factory(require('../../moment')) :
  13506. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  13507. factory(global.moment)
  13508. }(this, function (moment) { 'use strict';
  13509. /*global QUnit:false*/
  13510. var test = QUnit.test;
  13511. var expect = QUnit.expect;
  13512. function module (name, lifecycle) {
  13513. QUnit.module(name, {
  13514. setup : function () {
  13515. moment.locale('en');
  13516. moment.createFromInputFallback = function (config) {
  13517. throw new Error('input not handled by moment: ' + config._i);
  13518. };
  13519. if (lifecycle && lifecycle.setup) {
  13520. lifecycle.setup();
  13521. }
  13522. },
  13523. teardown : function () {
  13524. if (lifecycle && lifecycle.teardown) {
  13525. lifecycle.teardown();
  13526. }
  13527. }
  13528. });
  13529. }
  13530. function localeModule (name, lifecycle) {
  13531. QUnit.module('locale:' + name, {
  13532. setup : function () {
  13533. moment.locale(name);
  13534. moment.createFromInputFallback = function (config) {
  13535. throw new Error('input not handled by moment: ' + config._i);
  13536. };
  13537. if (lifecycle && lifecycle.setup) {
  13538. lifecycle.setup();
  13539. }
  13540. },
  13541. teardown : function () {
  13542. moment.locale('en');
  13543. if (lifecycle && lifecycle.teardown) {
  13544. lifecycle.teardown();
  13545. }
  13546. }
  13547. });
  13548. }
  13549. localeModule('hr');
  13550. test('parse', function (assert) {
  13551. var tests = 'siječanj sij._veljača velj._ožujak ožu._travanj tra._svibanj svi._lipanj lip._srpanj srp._kolovoz kol._rujan ruj._listopad lis._studeni stu._prosinac pro.'.split('_'), i;
  13552. function equalTest(input, mmm, i) {
  13553. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  13554. }
  13555. for (i = 0; i < 12; i++) {
  13556. tests[i] = tests[i].split(' ');
  13557. equalTest(tests[i][0], 'MMM', i);
  13558. equalTest(tests[i][1], 'MMM', i);
  13559. equalTest(tests[i][0], 'MMMM', i);
  13560. equalTest(tests[i][1], 'MMMM', i);
  13561. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  13562. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  13563. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  13564. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  13565. }
  13566. });
  13567. test('format', function (assert) {
  13568. var a = [
  13569. ['dddd, Do MMMM YYYY, h:mm:ss a', 'nedjelja, 14. veljače 2010, 3:25:50 pm'],
  13570. ['ddd, hA', 'ned., 3PM'],
  13571. ['M Mo MM MMMM MMM', '2 2. 02 veljača velj.'],
  13572. ['YYYY YY', '2010 10'],
  13573. ['D Do DD', '14 14. 14'],
  13574. ['d do dddd ddd dd', '0 0. nedjelja ned. ne'],
  13575. ['DDD DDDo DDDD', '45 45. 045'],
  13576. ['w wo ww', '7 7. 07'],
  13577. ['h hh', '3 03'],
  13578. ['H HH', '15 15'],
  13579. ['m mm', '25 25'],
  13580. ['s ss', '50 50'],
  13581. ['a A', 'pm PM'],
  13582. ['[the] DDDo [day of the year]', 'the 45. day of the year'],
  13583. ['LTS', '15:25:50'],
  13584. ['L', '14. 02. 2010'],
  13585. ['LL', '14. veljača 2010'],
  13586. ['LLL', '14. veljača 2010 15:25'],
  13587. ['LLLL', 'nedjelja, 14. veljača 2010 15:25'],
  13588. ['l', '14. 2. 2010'],
  13589. ['ll', '14. velj. 2010'],
  13590. ['lll', '14. velj. 2010 15:25'],
  13591. ['llll', 'ned., 14. velj. 2010 15:25']
  13592. ],
  13593. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  13594. i;
  13595. for (i = 0; i < a.length; i++) {
  13596. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  13597. }
  13598. });
  13599. test('format ordinal', function (assert) {
  13600. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
  13601. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
  13602. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
  13603. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
  13604. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
  13605. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
  13606. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
  13607. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
  13608. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
  13609. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
  13610. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
  13611. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
  13612. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
  13613. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
  13614. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
  13615. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
  13616. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
  13617. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
  13618. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
  13619. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
  13620. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
  13621. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
  13622. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
  13623. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
  13624. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
  13625. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
  13626. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
  13627. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
  13628. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
  13629. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
  13630. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
  13631. });
  13632. test('format month', function (assert) {
  13633. var expected = 'siječanj sij._veljača velj._ožujak ožu._travanj tra._svibanj svi._lipanj lip._srpanj srp._kolovoz kol._rujan ruj._listopad lis._studeni stu._prosinac pro.'.split('_'), i;
  13634. for (i = 0; i < expected.length; i++) {
  13635. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  13636. }
  13637. });
  13638. test('format week', function (assert) {
  13639. var expected = 'nedjelja ned. ne_ponedjeljak pon. po_utorak uto. ut_srijeda sri. sr_četvrtak čet. če_petak pet. pe_subota sub. su'.split('_'), i;
  13640. for (i = 0; i < expected.length; i++) {
  13641. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  13642. }
  13643. });
  13644. test('from', function (assert) {
  13645. var start = moment([2007, 1, 28]);
  13646. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'par sekundi', '44 seconds = a few seconds');
  13647. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'jedna minuta', '45 seconds = a minute');
  13648. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'jedna minuta', '89 seconds = a minute');
  13649. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minute', '90 seconds = 2 minutes');
  13650. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuta', '44 minutes = 44 minutes');
  13651. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'jedan sat', '45 minutes = an hour');
  13652. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'jedan sat', '89 minutes = an hour');
  13653. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 sata', '90 minutes = 2 hours');
  13654. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 sati', '5 hours = 5 hours');
  13655. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 sati', '21 hours = 21 hours');
  13656. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'dan', '22 hours = a day');
  13657. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'dan', '35 hours = a day');
  13658. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dana', '36 hours = 2 days');
  13659. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'dan', '1 day = a day');
  13660. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dana', '5 days = 5 days');
  13661. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dana', '25 days = 25 days');
  13662. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'mjesec', '26 days = a month');
  13663. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'mjesec', '30 days = a month');
  13664. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'mjesec', '43 days = a month');
  13665. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mjeseca', '46 days = 2 months');
  13666. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mjeseca', '75 days = 2 months');
  13667. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mjeseca', '76 days = 3 months');
  13668. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'mjesec', '1 month = a month');
  13669. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mjeseci', '5 months = 5 months');
  13670. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'godinu', '345 days = a year');
  13671. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 godine', '548 days = 2 years');
  13672. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'godinu', '1 year = a year');
  13673. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 godina', '5 years = 5 years');
  13674. });
  13675. test('suffix', function (assert) {
  13676. assert.equal(moment(30000).from(0), 'za par sekundi', 'prefix');
  13677. assert.equal(moment(0).from(30000), 'prije par sekundi', 'prefix');
  13678. });
  13679. test('now from now', function (assert) {
  13680. assert.equal(moment().fromNow(), 'prije par sekundi', 'now from now should display as in the past');
  13681. });
  13682. test('fromNow', function (assert) {
  13683. assert.equal(moment().add({s: 30}).fromNow(), 'za par sekundi', 'in a few seconds');
  13684. assert.equal(moment().add({d: 5}).fromNow(), 'za 5 dana', 'in 5 days');
  13685. });
  13686. test('calendar day', function (assert) {
  13687. var a = moment().hours(2).minutes(0).seconds(0);
  13688. assert.equal(moment(a).calendar(), 'danas u 2:00', 'today at the same time');
  13689. assert.equal(moment(a).add({m: 25}).calendar(), 'danas u 2:25', 'Now plus 25 min');
  13690. assert.equal(moment(a).add({h: 1}).calendar(), 'danas u 3:00', 'Now plus 1 hour');
  13691. assert.equal(moment(a).add({d: 1}).calendar(), 'sutra u 2:00', 'tomorrow at the same time');
  13692. assert.equal(moment(a).subtract({h: 1}).calendar(), 'danas u 1:00', 'Now minus 1 hour');
  13693. assert.equal(moment(a).subtract({d: 1}).calendar(), 'jučer u 2:00', 'yesterday at the same time');
  13694. });
  13695. test('calendar next week', function (assert) {
  13696. var i, m;
  13697. function makeFormat(d) {
  13698. switch (d.day()) {
  13699. case 0:
  13700. return '[u] [nedjelju] [u] LT';
  13701. case 3:
  13702. return '[u] [srijedu] [u] LT';
  13703. case 6:
  13704. return '[u] [subotu] [u] LT';
  13705. case 1:
  13706. case 2:
  13707. case 4:
  13708. case 5:
  13709. return '[u] dddd [u] LT';
  13710. }
  13711. }
  13712. for (i = 2; i < 7; i++) {
  13713. m = moment().add({d: i});
  13714. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days current time');
  13715. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  13716. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days beginning of day');
  13717. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  13718. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days end of day');
  13719. }
  13720. });
  13721. test('calendar last week', function (assert) {
  13722. var i, m;
  13723. function makeFormat(d) {
  13724. switch (d.day()) {
  13725. case 0:
  13726. case 3:
  13727. return '[prošlu] dddd [u] LT';
  13728. case 6:
  13729. return '[prošle] [subote] [u] LT';
  13730. case 1:
  13731. case 2:
  13732. case 4:
  13733. case 5:
  13734. return '[prošli] dddd [u] LT';
  13735. }
  13736. }
  13737. for (i = 2; i < 7; i++) {
  13738. m = moment().subtract({d: i});
  13739. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days current time');
  13740. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  13741. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days beginning of day');
  13742. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  13743. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days end of day');
  13744. }
  13745. });
  13746. test('calendar all else', function (assert) {
  13747. var weeksAgo = moment().subtract({w: 1}),
  13748. weeksFromNow = moment().add({w: 1});
  13749. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  13750. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  13751. weeksAgo = moment().subtract({w: 2});
  13752. weeksFromNow = moment().add({w: 2});
  13753. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  13754. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  13755. });
  13756. test('weeks year starting sunday', function (assert) {
  13757. assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1');
  13758. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  13759. assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2');
  13760. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  13761. assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3');
  13762. });
  13763. test('weeks year starting monday', function (assert) {
  13764. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  13765. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  13766. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  13767. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  13768. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  13769. });
  13770. test('weeks year starting tuesday', function (assert) {
  13771. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  13772. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  13773. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  13774. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  13775. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  13776. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  13777. });
  13778. test('weeks year starting wednesday', function (assert) {
  13779. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  13780. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  13781. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  13782. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  13783. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  13784. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  13785. });
  13786. test('weeks year starting thursday', function (assert) {
  13787. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  13788. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  13789. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  13790. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  13791. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  13792. assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3');
  13793. });
  13794. test('weeks year starting friday', function (assert) {
  13795. assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1');
  13796. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  13797. assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1');
  13798. assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2');
  13799. assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2');
  13800. assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3');
  13801. });
  13802. test('weeks year starting saturday', function (assert) {
  13803. assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1');
  13804. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  13805. assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1');
  13806. assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2');
  13807. assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2');
  13808. assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3');
  13809. });
  13810. test('weeks year starting sunday formatted', function (assert) {
  13811. assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1.', 'Dec 26 2011 should be week 1');
  13812. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1.', 'Jan 1 2012 should be week 1');
  13813. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2.', 'Jan 2 2012 should be week 2');
  13814. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2.', 'Jan 8 2012 should be week 2');
  13815. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3.', 'Jan 9 2012 should be week 3');
  13816. });
  13817. test('lenient ordinal parsing', function (assert) {
  13818. var i, ordinalStr, testMoment;
  13819. for (i = 1; i <= 31; ++i) {
  13820. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  13821. testMoment = moment(ordinalStr, 'YYYY MM Do');
  13822. assert.equal(testMoment.year(), 2014,
  13823. 'lenient ordinal parsing ' + i + ' year check');
  13824. assert.equal(testMoment.month(), 0,
  13825. 'lenient ordinal parsing ' + i + ' month check');
  13826. assert.equal(testMoment.date(), i,
  13827. 'lenient ordinal parsing ' + i + ' date check');
  13828. }
  13829. });
  13830. test('lenient ordinal parsing of number', function (assert) {
  13831. var i, testMoment;
  13832. for (i = 1; i <= 31; ++i) {
  13833. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  13834. assert.equal(testMoment.year(), 2014,
  13835. 'lenient ordinal parsing of number ' + i + ' year check');
  13836. assert.equal(testMoment.month(), 0,
  13837. 'lenient ordinal parsing of number ' + i + ' month check');
  13838. assert.equal(testMoment.date(), i,
  13839. 'lenient ordinal parsing of number ' + i + ' date check');
  13840. }
  13841. });
  13842. test('strict ordinal parsing', function (assert) {
  13843. var i, ordinalStr, testMoment;
  13844. for (i = 1; i <= 31; ++i) {
  13845. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  13846. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  13847. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  13848. }
  13849. });
  13850. }));
  13851. ;(function (global, factory) {
  13852. typeof exports === 'object' && typeof module !== 'undefined'
  13853. && typeof require === 'function' ? factory(require('../../moment')) :
  13854. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  13855. factory(global.moment)
  13856. }(this, function (moment) { 'use strict';
  13857. /*global QUnit:false*/
  13858. var test = QUnit.test;
  13859. var expect = QUnit.expect;
  13860. function module (name, lifecycle) {
  13861. QUnit.module(name, {
  13862. setup : function () {
  13863. moment.locale('en');
  13864. moment.createFromInputFallback = function (config) {
  13865. throw new Error('input not handled by moment: ' + config._i);
  13866. };
  13867. if (lifecycle && lifecycle.setup) {
  13868. lifecycle.setup();
  13869. }
  13870. },
  13871. teardown : function () {
  13872. if (lifecycle && lifecycle.teardown) {
  13873. lifecycle.teardown();
  13874. }
  13875. }
  13876. });
  13877. }
  13878. function localeModule (name, lifecycle) {
  13879. QUnit.module('locale:' + name, {
  13880. setup : function () {
  13881. moment.locale(name);
  13882. moment.createFromInputFallback = function (config) {
  13883. throw new Error('input not handled by moment: ' + config._i);
  13884. };
  13885. if (lifecycle && lifecycle.setup) {
  13886. lifecycle.setup();
  13887. }
  13888. },
  13889. teardown : function () {
  13890. moment.locale('en');
  13891. if (lifecycle && lifecycle.teardown) {
  13892. lifecycle.teardown();
  13893. }
  13894. }
  13895. });
  13896. }
  13897. localeModule('hu');
  13898. test('parse', function (assert) {
  13899. var tests = 'január jan_február feb_március márc_április ápr_május máj_június jún_július júl_augusztus aug_szeptember szept_október okt_november nov_december dec'.split('_'),
  13900. i;
  13901. function equalTest(input, mmm, i) {
  13902. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  13903. }
  13904. for (i = 0; i < 12; i++) {
  13905. tests[i] = tests[i].split(' ');
  13906. equalTest(tests[i][0], 'MMM', i);
  13907. equalTest(tests[i][1], 'MMM', i);
  13908. equalTest(tests[i][0], 'MMMM', i);
  13909. equalTest(tests[i][1], 'MMMM', i);
  13910. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  13911. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  13912. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  13913. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  13914. }
  13915. });
  13916. test('format', function (assert) {
  13917. var a = [
  13918. ['dddd, MMMM Do YYYY, HH:mm:ss', 'vasárnap, február 14. 2010, 15:25:50'],
  13919. ['ddd, HH', 'vas, 15'],
  13920. ['M Mo MM MMMM MMM', '2 2. 02 február feb'],
  13921. ['YYYY YY', '2010 10'],
  13922. ['D Do DD', '14 14. 14'],
  13923. ['d do dddd ddd dd', '0 0. vasárnap vas v'],
  13924. ['DDD DDDo DDDD', '45 45. 045'],
  13925. ['w wo ww', '7 7. 07'],
  13926. ['H HH', '15 15'],
  13927. ['m mm', '25 25'],
  13928. ['s ss', '50 50'],
  13929. ['[az év] DDDo [napja]', 'az év 45. napja'],
  13930. ['LTS', '15:25:50'],
  13931. ['L', '2010.02.14.'],
  13932. ['LL', '2010. február 14.'],
  13933. ['LLL', '2010. február 14. 15:25'],
  13934. ['LLLL', '2010. február 14., vasárnap 15:25'],
  13935. ['l', '2010.2.14.'],
  13936. ['ll', '2010. feb 14.'],
  13937. ['lll', '2010. feb 14. 15:25'],
  13938. ['llll', '2010. feb 14., vas 15:25']
  13939. ],
  13940. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  13941. i;
  13942. for (i = 0; i < a.length; i++) {
  13943. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  13944. }
  13945. });
  13946. test('meridiem', function (assert) {
  13947. assert.equal(moment([2011, 2, 23, 0, 0]).format('a'), 'de', 'am');
  13948. assert.equal(moment([2011, 2, 23, 11, 59]).format('a'), 'de', 'am');
  13949. assert.equal(moment([2011, 2, 23, 12, 0]).format('a'), 'du', 'pm');
  13950. assert.equal(moment([2011, 2, 23, 23, 59]).format('a'), 'du', 'pm');
  13951. assert.equal(moment([2011, 2, 23, 0, 0]).format('A'), 'DE', 'AM');
  13952. assert.equal(moment([2011, 2, 23, 11, 59]).format('A'), 'DE', 'AM');
  13953. assert.equal(moment([2011, 2, 23, 12, 0]).format('A'), 'DU', 'PM');
  13954. assert.equal(moment([2011, 2, 23, 23, 59]).format('A'), 'DU', 'PM');
  13955. });
  13956. test('format ordinal', function (assert) {
  13957. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
  13958. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
  13959. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
  13960. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
  13961. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
  13962. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
  13963. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
  13964. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
  13965. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
  13966. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
  13967. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
  13968. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
  13969. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
  13970. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
  13971. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
  13972. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
  13973. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
  13974. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
  13975. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
  13976. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
  13977. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
  13978. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
  13979. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
  13980. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
  13981. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
  13982. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
  13983. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
  13984. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
  13985. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
  13986. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
  13987. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
  13988. });
  13989. test('format month', function (assert) {
  13990. var expected = 'január jan_február feb_március márc_április ápr_május máj_június jún_július júl_augusztus aug_szeptember szept_október okt_november nov_december dec'.split('_'),
  13991. i;
  13992. for (i = 0; i < expected.length; i++) {
  13993. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  13994. }
  13995. });
  13996. test('format week', function (assert) {
  13997. var expected = 'vasárnap vas_hétfő hét_kedd kedd_szerda sze_csütörtök csüt_péntek pén_szombat szo'.split('_'),
  13998. i;
  13999. for (i = 0; i < expected.length; i++) {
  14000. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd'), expected[i], expected[i]);
  14001. }
  14002. });
  14003. test('from', function (assert) {
  14004. var start = moment([2007, 1, 28]);
  14005. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'néhány másodperc', '44 másodperc = néhány másodperc');
  14006. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'egy perc', '45 másodperc = egy perc');
  14007. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'egy perc', '89 másodperc = egy perc');
  14008. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 perc', '90 másodperc = 2 perc');
  14009. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 perc', '44 perc = 44 perc');
  14010. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'egy óra', '45 perc = egy óra');
  14011. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'egy óra', '89 perc = egy óra');
  14012. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 óra', '90 perc = 2 óra');
  14013. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 óra', '5 óra = 5 óra');
  14014. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 óra', '21 óra = 21 óra');
  14015. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'egy nap', '22 óra = egy nap');
  14016. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'egy nap', '35 óra = egy nap');
  14017. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 nap', '36 óra = 2 nap');
  14018. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'egy nap', '1 nap = egy nap');
  14019. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 nap', '5 nap = 5 nap');
  14020. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 nap', '25 nap = 25 nap');
  14021. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'egy hónap', '26 nap = egy hónap');
  14022. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'egy hónap', '30 nap = egy hónap');
  14023. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'egy hónap', '45 nap = egy hónap');
  14024. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 hónap', '46 nap = 2 hónap');
  14025. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 hónap', '75 nap = 2 hónap');
  14026. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 hónap', '76 nap = 3 hónap');
  14027. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'egy hónap', '1 hónap = egy hónap');
  14028. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 hónap', '5 hónap = 5 hónap');
  14029. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'egy év', '345 nap = egy év');
  14030. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 év', '548 nap = 2 év');
  14031. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'egy év', '1 év = egy év');
  14032. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 év', '5 év = 5 év');
  14033. });
  14034. test('suffix', function (assert) {
  14035. assert.equal(moment(30000).from(0), 'néhány másodperc múlva', 'prefix');
  14036. assert.equal(moment(0).from(30000), 'néhány másodperce', 'suffix');
  14037. });
  14038. test('now from now', function (assert) {
  14039. assert.equal(moment().fromNow(), 'néhány másodperce', 'now from now should display as in the past');
  14040. });
  14041. test('fromNow', function (assert) {
  14042. assert.equal(moment().add({s: 30}).fromNow(), 'néhány másodperc múlva', 'néhány másodperc múlva');
  14043. assert.equal(moment().add({d: 5}).fromNow(), '5 nap múlva', '5 nap múlva');
  14044. });
  14045. test('calendar day', function (assert) {
  14046. var a = moment().hours(2).minutes(0).seconds(0);
  14047. assert.equal(moment(a).calendar(), 'ma 2:00-kor', 'today at the same time');
  14048. assert.equal(moment(a).add({m: 25}).calendar(), 'ma 2:25-kor', 'Now plus 25 min');
  14049. assert.equal(moment(a).add({h: 1}).calendar(), 'ma 3:00-kor', 'Now plus 1 hour');
  14050. assert.equal(moment(a).add({d: 1}).calendar(), 'holnap 2:00-kor', 'tomorrow at the same time');
  14051. assert.equal(moment(a).subtract({h: 1}).calendar(), 'ma 1:00-kor', 'Now minus 1 hour');
  14052. assert.equal(moment(a).subtract({d: 1}).calendar(), 'tegnap 2:00-kor', 'yesterday at the same time');
  14053. });
  14054. test('calendar next week', function (assert) {
  14055. var i, m, days = 'vasárnap_hétfőn_kedden_szerdán_csütörtökön_pénteken_szombaton'.split('_');
  14056. for (i = 2; i < 7; i++) {
  14057. m = moment().add({d: i});
  14058. assert.equal(m.calendar(), m.format('[' + days[m.day()] + '] LT[-kor]'), 'today + ' + i + ' days current time');
  14059. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  14060. assert.equal(m.calendar(), m.format('[' + days[m.day()] + '] LT[-kor]'), 'today + ' + i + ' days beginning of day');
  14061. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  14062. assert.equal(m.calendar(), m.format('[' + days[m.day()] + '] LT[-kor]'), 'today + ' + i + ' days end of day');
  14063. }
  14064. });
  14065. test('calendar last week', function (assert) {
  14066. var i, m, days = 'vasárnap_hétfőn_kedden_szerdán_csütörtökön_pénteken_szombaton'.split('_');
  14067. for (i = 2; i < 7; i++) {
  14068. m = moment().subtract({d: i});
  14069. assert.equal(m.calendar(), m.format('[múlt ' + days[m.day()] + '] LT[-kor]'), 'today - ' + i + ' days current time');
  14070. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  14071. assert.equal(m.calendar(), m.format('[múlt ' + days[m.day()] + '] LT[-kor]'), 'today - ' + i + ' days beginning of day');
  14072. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  14073. assert.equal(m.calendar(), m.format('[múlt ' + days[m.day()] + '] LT[-kor]'), 'today - ' + i + ' days end of day');
  14074. }
  14075. });
  14076. test('calendar all else', function (assert) {
  14077. var weeksAgo = moment().subtract({w: 1}),
  14078. weeksFromNow = moment().add({w: 1});
  14079. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), 'egy héte');
  14080. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'egy hét múlva');
  14081. weeksAgo = moment().subtract({w: 2});
  14082. weeksFromNow = moment().add({w: 2});
  14083. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 hete');
  14084. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), '2 hét múlva');
  14085. });
  14086. test('weeks year starting sunday', function (assert) {
  14087. assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1');
  14088. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  14089. assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2');
  14090. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  14091. assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3');
  14092. });
  14093. test('weeks year starting monday', function (assert) {
  14094. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  14095. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  14096. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  14097. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  14098. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  14099. });
  14100. test('weeks year starting tuesday', function (assert) {
  14101. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  14102. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  14103. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  14104. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  14105. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  14106. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  14107. });
  14108. test('weeks year starting wednesday', function (assert) {
  14109. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  14110. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  14111. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  14112. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  14113. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  14114. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  14115. });
  14116. test('weeks year starting thursday', function (assert) {
  14117. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  14118. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  14119. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  14120. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  14121. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  14122. assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3');
  14123. });
  14124. test('weeks year starting friday', function (assert) {
  14125. assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1');
  14126. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  14127. assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1');
  14128. assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2');
  14129. assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2');
  14130. assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3');
  14131. });
  14132. test('weeks year starting saturday', function (assert) {
  14133. assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1');
  14134. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  14135. assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1');
  14136. assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2');
  14137. assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2');
  14138. assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3');
  14139. });
  14140. test('weeks year starting sunday formatted', function (assert) {
  14141. assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1.', 'Dec 26 2011 should be week 1');
  14142. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1.', 'Jan 1 2012 should be week 1');
  14143. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2.', 'Jan 2 2012 should be week 2');
  14144. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2.', 'Jan 8 2012 should be week 2');
  14145. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3.', 'Jan 9 2012 should be week 3');
  14146. });
  14147. test('lenient ordinal parsing', function (assert) {
  14148. var i, ordinalStr, testMoment;
  14149. for (i = 1; i <= 31; ++i) {
  14150. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  14151. testMoment = moment(ordinalStr, 'YYYY MM Do');
  14152. assert.equal(testMoment.year(), 2014,
  14153. 'lenient ordinal parsing ' + i + ' year check');
  14154. assert.equal(testMoment.month(), 0,
  14155. 'lenient ordinal parsing ' + i + ' month check');
  14156. assert.equal(testMoment.date(), i,
  14157. 'lenient ordinal parsing ' + i + ' date check');
  14158. }
  14159. });
  14160. test('lenient ordinal parsing of number', function (assert) {
  14161. var i, testMoment;
  14162. for (i = 1; i <= 31; ++i) {
  14163. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  14164. assert.equal(testMoment.year(), 2014,
  14165. 'lenient ordinal parsing of number ' + i + ' year check');
  14166. assert.equal(testMoment.month(), 0,
  14167. 'lenient ordinal parsing of number ' + i + ' month check');
  14168. assert.equal(testMoment.date(), i,
  14169. 'lenient ordinal parsing of number ' + i + ' date check');
  14170. }
  14171. });
  14172. test('strict ordinal parsing', function (assert) {
  14173. var i, ordinalStr, testMoment;
  14174. for (i = 1; i <= 31; ++i) {
  14175. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  14176. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  14177. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  14178. }
  14179. });
  14180. }));
  14181. ;(function (global, factory) {
  14182. typeof exports === 'object' && typeof module !== 'undefined'
  14183. && typeof require === 'function' ? factory(require('../../moment')) :
  14184. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  14185. factory(global.moment)
  14186. }(this, function (moment) { 'use strict';
  14187. /*global QUnit:false*/
  14188. var test = QUnit.test;
  14189. var expect = QUnit.expect;
  14190. function module (name, lifecycle) {
  14191. QUnit.module(name, {
  14192. setup : function () {
  14193. moment.locale('en');
  14194. moment.createFromInputFallback = function (config) {
  14195. throw new Error('input not handled by moment: ' + config._i);
  14196. };
  14197. if (lifecycle && lifecycle.setup) {
  14198. lifecycle.setup();
  14199. }
  14200. },
  14201. teardown : function () {
  14202. if (lifecycle && lifecycle.teardown) {
  14203. lifecycle.teardown();
  14204. }
  14205. }
  14206. });
  14207. }
  14208. function localeModule (name, lifecycle) {
  14209. QUnit.module('locale:' + name, {
  14210. setup : function () {
  14211. moment.locale(name);
  14212. moment.createFromInputFallback = function (config) {
  14213. throw new Error('input not handled by moment: ' + config._i);
  14214. };
  14215. if (lifecycle && lifecycle.setup) {
  14216. lifecycle.setup();
  14217. }
  14218. },
  14219. teardown : function () {
  14220. moment.locale('en');
  14221. if (lifecycle && lifecycle.teardown) {
  14222. lifecycle.teardown();
  14223. }
  14224. }
  14225. });
  14226. }
  14227. localeModule('hy-am');
  14228. test('parse', function (assert) {
  14229. var tests = 'հունվար հնվ_փետրվար փտր_մարտ մրտ_ապրիլ ապր_մայիս մյս_հունիս հնս_հուլիս հլս_օգոստոս օգս_սեպտեմբեր սպտ_հոկտեմբեր հկտ_նոյեմբեր նմբ_դեկտեմբեր դկտ'.split('_'), i;
  14230. function equalTest(input, mmm, i) {
  14231. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  14232. }
  14233. for (i = 0; i < 12; i++) {
  14234. tests[i] = tests[i].split(' ');
  14235. equalTest(tests[i][0], 'MMM', i);
  14236. equalTest(tests[i][1], 'MMM', i);
  14237. equalTest(tests[i][0], 'MMMM', i);
  14238. equalTest(tests[i][1], 'MMMM', i);
  14239. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  14240. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  14241. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  14242. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  14243. }
  14244. });
  14245. test('parse exceptional case', function (assert) {
  14246. assert.equal(moment('11 մայիսի 1989', ['DD MMMM YYYY']).format('DD-MM-YYYY'), '11-05-1989');
  14247. });
  14248. test('format', function (assert) {
  14249. var a = [
  14250. ['dddd, Do MMMM YYYY, HH:mm:ss', 'կիրակի, 14 փետրվարի 2010, 15:25:50'],
  14251. ['ddd, h A', 'կրկ, 3 ցերեկվա'],
  14252. ['M Mo MM MMMM MMM', '2 2 02 փետրվար փտր'],
  14253. ['YYYY YY', '2010 10'],
  14254. ['D Do DD', '14 14 14'],
  14255. ['d do dddd ddd dd', '0 0 կիրակի կրկ կրկ'],
  14256. ['DDD DDDo DDDD', '45 45-րդ 045'],
  14257. ['w wo ww', '7 7-րդ 07'],
  14258. ['h hh', '3 03'],
  14259. ['H HH', '15 15'],
  14260. ['m mm', '25 25'],
  14261. ['s ss', '50 50'],
  14262. ['a A', 'ցերեկվա ցերեկվա'],
  14263. ['[տարվա] DDDo [օրը]', 'տարվա 45-րդ օրը'],
  14264. ['LTS', '15:25:50'],
  14265. ['L', '14.02.2010'],
  14266. ['LL', '14 փետրվարի 2010 թ.'],
  14267. ['LLL', '14 փետրվարի 2010 թ., 15:25'],
  14268. ['LLLL', 'կիրակի, 14 փետրվարի 2010 թ., 15:25'],
  14269. ['l', '14.2.2010'],
  14270. ['ll', '14 փտր 2010 թ.'],
  14271. ['lll', '14 փտր 2010 թ., 15:25'],
  14272. ['llll', 'կրկ, 14 փտր 2010 թ., 15:25']
  14273. ],
  14274. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  14275. i;
  14276. for (i = 0; i < a.length; i++) {
  14277. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  14278. }
  14279. });
  14280. test('format meridiem', function (assert) {
  14281. assert.equal(moment([2012, 11, 28, 0, 0]).format('A'), 'գիշերվա', 'night');
  14282. assert.equal(moment([2012, 11, 28, 3, 59]).format('A'), 'գիշերվա', 'night');
  14283. assert.equal(moment([2012, 11, 28, 4, 0]).format('A'), 'առավոտվա', 'morning');
  14284. assert.equal(moment([2012, 11, 28, 11, 59]).format('A'), 'առավոտվա', 'morning');
  14285. assert.equal(moment([2012, 11, 28, 12, 0]).format('A'), 'ցերեկվա', 'afternoon');
  14286. assert.equal(moment([2012, 11, 28, 16, 59]).format('A'), 'ցերեկվա', 'afternoon');
  14287. assert.equal(moment([2012, 11, 28, 17, 0]).format('A'), 'երեկոյան', 'evening');
  14288. assert.equal(moment([2012, 11, 28, 23, 59]).format('A'), 'երեկոյան', 'evening');
  14289. });
  14290. test('format ordinal', function (assert) {
  14291. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1-ին', '1-ին');
  14292. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2-րդ', '2-րդ');
  14293. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3-րդ', '3-րդ');
  14294. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4-րդ', '4-րդ');
  14295. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5-րդ', '5-րդ');
  14296. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6-րդ', '6-րդ');
  14297. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7-րդ', '7-րդ');
  14298. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8-րդ', '8-րդ');
  14299. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9-րդ', '9-րդ');
  14300. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10-րդ', '10-րդ');
  14301. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11-րդ', '11-րդ');
  14302. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12-րդ', '12-րդ');
  14303. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13-րդ', '13-րդ');
  14304. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14-րդ', '14-րդ');
  14305. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15-րդ', '15-րդ');
  14306. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16-րդ', '16-րդ');
  14307. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17-րդ', '17-րդ');
  14308. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18-րդ', '18-րդ');
  14309. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19-րդ', '19-րդ');
  14310. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20-րդ', '20-րդ');
  14311. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21-րդ', '21-րդ');
  14312. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22-րդ', '22-րդ');
  14313. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23-րդ', '23-րդ');
  14314. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24-րդ', '24-րդ');
  14315. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25-րդ', '25-րդ');
  14316. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26-րդ', '26-րդ');
  14317. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27-րդ', '27-րդ');
  14318. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28-րդ', '28-րդ');
  14319. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29-րդ', '29-րդ');
  14320. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30-րդ', '30-րդ');
  14321. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31-րդ', '31-րդ');
  14322. });
  14323. test('format month', function (assert) {
  14324. var expected = 'հունվար հնվ_փետրվար փտր_մարտ մրտ_ապրիլ ապր_մայիս մյս_հունիս հնս_հուլիս հլս_օգոստոս օգս_սեպտեմբեր սպտ_հոկտեմբեր հկտ_նոյեմբեր նմբ_դեկտեմբեր դկտ'.split('_'), i;
  14325. for (i = 0; i < expected.length; i++) {
  14326. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  14327. }
  14328. });
  14329. test('format month case', function (assert) {
  14330. var months = {
  14331. 'nominative': 'հունվար_փետրվար_մարտ_ապրիլ_մայիս_հունիս_հուլիս_օգոստոս_սեպտեմբեր_հոկտեմբեր_նոյեմբեր_դեկտեմբեր'.split('_'),
  14332. 'accusative': 'հունվարի_փետրվարի_մարտի_ապրիլի_մայիսի_հունիսի_հուլիսի_օգոստոսի_սեպտեմբերի_հոկտեմբերի_նոյեմբերի_դեկտեմբերի'.split('_')
  14333. }, i;
  14334. for (i = 0; i < 12; i++) {
  14335. assert.equal(moment([2011, i, 1]).format('D MMMM'), '1 ' + months.accusative[i], '1 ' + months.accusative[i]);
  14336. assert.equal(moment([2011, i, 1]).format('MMMM'), months.nominative[i], '1 ' + months.nominative[i]);
  14337. }
  14338. });
  14339. test('format month short case', function (assert) {
  14340. var monthsShort = {
  14341. 'nominative': 'հնվ_փտր_մրտ_ապր_մյս_հնս_հլս_օգս_սպտ_հկտ_նմբ_դկտ'.split('_'),
  14342. 'accusative': 'հնվ_փտր_մրտ_ապր_մյս_հնս_հլս_օգս_սպտ_հկտ_նմբ_դկտ'.split('_')
  14343. }, i;
  14344. for (i = 0; i < 12; i++) {
  14345. assert.equal(moment([2011, i, 1]).format('D MMM'), '1 ' + monthsShort.accusative[i], '1 ' + monthsShort.accusative[i]);
  14346. assert.equal(moment([2011, i, 1]).format('MMM'), monthsShort.nominative[i], '1 ' + monthsShort.nominative[i]);
  14347. }
  14348. });
  14349. test('format month case with escaped symbols', function (assert) {
  14350. var months = {
  14351. 'nominative': 'հունվար_փետրվար_մարտ_ապրիլ_մայիս_հունիս_հուլիս_օգոստոս_սեպտեմբեր_հոկտեմբեր_նոյեմբեր_դեկտեմբեր'.split('_'),
  14352. 'accusative': 'հունվարի_փետրվարի_մարտի_ապրիլի_մայիսի_հունիսի_հուլիսի_օգոստոսի_սեպտեմբերի_հոկտեմբերի_նոյեմբերի_դեկտեմբերի'.split('_')
  14353. }, i;
  14354. for (i = 0; i < 12; i++) {
  14355. assert.equal(moment([2013, i, 1]).format('D[] MMMM'), '1 ' + months.accusative[i], '1 ' + months.accusative[i]);
  14356. assert.equal(moment([2013, i, 1]).format('[<i>]D[</i>] [<b>]MMMM[</b>]'), '<i>1</i> <b>' + months.accusative[i] + '</b>', '1 <b>' + months.accusative[i] + '</b>');
  14357. assert.equal(moment([2013, i, 1]).format('D[-ին օրը] MMMM'), '1-ին օրը ' + months.accusative[i], '1-ին օրը ' + months.accusative[i]);
  14358. assert.equal(moment([2013, i, 1]).format('D, MMMM'), '1, ' + months.nominative[i], '1, ' + months.nominative[i]);
  14359. }
  14360. });
  14361. test('format month short case with escaped symbols', function (assert) {
  14362. var monthsShort = {
  14363. 'nominative': 'հնվ_փտր_մրտ_ապր_մյս_հնս_հլս_օգս_սպտ_հկտ_նմբ_դկտ'.split('_'),
  14364. 'accusative': 'հնվ_փտր_մրտ_ապր_մյս_հնս_հլս_օգս_սպտ_հկտ_նմբ_դկտ'.split('_')
  14365. }, i;
  14366. for (i = 0; i < 12; i++) {
  14367. assert.equal(moment([2013, i, 1]).format('D[] MMM'), '1 ' + monthsShort.accusative[i], '1 ' + monthsShort.accusative[i]);
  14368. assert.equal(moment([2013, i, 1]).format('[<i>]D[</i>] [<b>]MMM[</b>]'), '<i>1</i> <b>' + monthsShort.accusative[i] + '</b>', '1 <b>' + monthsShort.accusative[i] + '</b>');
  14369. assert.equal(moment([2013, i, 1]).format('D[-ին օրը] MMM'), '1-ին օրը ' + monthsShort.accusative[i], '1-ին օրը ' + monthsShort.accusative[i]);
  14370. assert.equal(moment([2013, i, 1]).format('D, MMM'), '1, ' + monthsShort.nominative[i], '1, ' + monthsShort.nominative[i]);
  14371. }
  14372. });
  14373. test('format week', function (assert) {
  14374. var expected = 'կիրակի կրկ կրկ_երկուշաբթի երկ երկ_երեքշաբթի երք երք_չորեքշաբթի չրք չրք_հինգշաբթի հնգ հնգ_ուրբաթ ուրբ ուրբ_շաբաթ շբթ շբթ'.split('_'), i;
  14375. for (i = 0; i < expected.length; i++) {
  14376. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  14377. }
  14378. });
  14379. test('from', function (assert) {
  14380. var start = moment([2007, 1, 28]);
  14381. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'մի քանի վայրկյան', '44 seconds = seconds');
  14382. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'րոպե', '45 seconds = a minute');
  14383. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'րոպե', '89 seconds = a minute');
  14384. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 րոպե', '90 seconds = 2 minutes');
  14385. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 րոպե', '44 minutes = 44 minutes');
  14386. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ժամ', '45 minutes = an hour');
  14387. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ժամ', '89 minutes = an hour');
  14388. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 ժամ', '90 minutes = 2 hours');
  14389. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ժամ', '5 hours = 5 hours');
  14390. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 ժամ', '21 hours = 21 hours');
  14391. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'օր', '22 hours = a day');
  14392. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'օր', '35 hours = a day');
  14393. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 օր', '36 hours = 2 days');
  14394. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'օր', '1 day = a day');
  14395. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 օր', '5 days = 5 days');
  14396. assert.equal(start.from(moment([2007, 1, 28]).add({d: 11}), true), '11 օր', '11 days = 11 days');
  14397. assert.equal(start.from(moment([2007, 1, 28]).add({d: 21}), true), '21 օր', '21 days = 21 days');
  14398. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 օր', '25 days = 25 days');
  14399. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ամիս', '26 days = a month');
  14400. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ամիս', '30 days = a month');
  14401. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ամիս', '43 days = a month');
  14402. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 ամիս', '46 days = 2 months');
  14403. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 ամիս', '75 days = 2 months');
  14404. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 ամիս', '76 days = 3 months');
  14405. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ամիս', '1 month = a month');
  14406. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 ամիս', '5 months = 5 months');
  14407. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'տարի', '345 days = a year');
  14408. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 տարի', '548 days = 2 years');
  14409. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'տարի', '1 year = a year');
  14410. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 տարի', '5 years = 5 years');
  14411. });
  14412. test('suffix', function (assert) {
  14413. assert.equal(moment(30000).from(0), 'մի քանի վայրկյան հետո', 'prefix');
  14414. assert.equal(moment(0).from(30000), 'մի քանի վայրկյան առաջ', 'suffix');
  14415. });
  14416. test('fromNow', function (assert) {
  14417. assert.equal(moment().add({s: 30}).fromNow(), 'մի քանի վայրկյան հետո', 'in seconds');
  14418. assert.equal(moment().add({d: 5}).fromNow(), '5 օր հետո', 'in 5 days');
  14419. });
  14420. test('calendar day', function (assert) {
  14421. var a = moment().hours(2).minutes(0).seconds(0);
  14422. assert.equal(moment(a).calendar(), 'այսօր 02:00', 'today at the same time');
  14423. assert.equal(moment(a).add({m: 25}).calendar(), 'այսօր 02:25', 'Now plus 25 min');
  14424. assert.equal(moment(a).add({h: 1}).calendar(), 'այսօր 03:00', 'Now plus 1 hour');
  14425. assert.equal(moment(a).add({d: 1}).calendar(), 'վաղը 02:00', 'tomorrow at the same time');
  14426. assert.equal(moment(a).subtract({h: 1}).calendar(), 'այսօր 01:00', 'Now minus 1 hour');
  14427. assert.equal(moment(a).subtract({d: 1}).calendar(), 'երեկ 02:00', 'yesterday at the same time');
  14428. });
  14429. test('calendar next week', function (assert) {
  14430. var i, m;
  14431. function makeFormat(d) {
  14432. return 'dddd [օրը ժամը] LT';
  14433. }
  14434. for (i = 2; i < 7; i++) {
  14435. m = moment().add({d: i});
  14436. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days current time');
  14437. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  14438. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days beginning of day');
  14439. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  14440. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days end of day');
  14441. }
  14442. });
  14443. test('calendar last week', function (assert) {
  14444. var i, m;
  14445. function makeFormat(d) {
  14446. return '[անցած] dddd [օրը ժամը] LT';
  14447. }
  14448. for (i = 2; i < 7; i++) {
  14449. m = moment().subtract({d: i});
  14450. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days current time');
  14451. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  14452. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days beginning of day');
  14453. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  14454. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days end of day');
  14455. }
  14456. });
  14457. test('calendar all else', function (assert) {
  14458. var weeksAgo = moment().subtract({w: 1}),
  14459. weeksFromNow = moment().add({w: 1});
  14460. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  14461. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  14462. weeksAgo = moment().subtract({w: 2});
  14463. weeksFromNow = moment().add({w: 2});
  14464. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  14465. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  14466. });
  14467. test('weeks year starting sunday', function (assert) {
  14468. assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1');
  14469. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  14470. assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2');
  14471. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  14472. assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3');
  14473. });
  14474. test('weeks year starting monday', function (assert) {
  14475. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  14476. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  14477. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  14478. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  14479. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  14480. });
  14481. test('weeks year starting tuesday', function (assert) {
  14482. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  14483. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  14484. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  14485. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  14486. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  14487. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  14488. });
  14489. test('weeks year starting wednesday', function (assert) {
  14490. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  14491. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  14492. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  14493. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  14494. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  14495. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  14496. });
  14497. test('weeks year starting thursday', function (assert) {
  14498. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  14499. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  14500. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  14501. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  14502. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  14503. assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3');
  14504. });
  14505. test('weeks year starting friday', function (assert) {
  14506. assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1');
  14507. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  14508. assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1');
  14509. assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2');
  14510. assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2');
  14511. assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3');
  14512. });
  14513. test('weeks year starting saturday', function (assert) {
  14514. assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1');
  14515. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  14516. assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1');
  14517. assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2');
  14518. assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2');
  14519. assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3');
  14520. });
  14521. test('weeks year starting sunday formatted', function (assert) {
  14522. assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1-ին', 'Dec 26 2011 should be week 1');
  14523. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1-ին', 'Jan 1 2012 should be week 1');
  14524. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2-րդ', 'Jan 2 2012 should be week 2');
  14525. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2-րդ', 'Jan 8 2012 should be week 2');
  14526. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3-րդ', 'Jan 9 2012 should be week 3');
  14527. });
  14528. test('lenient ordinal parsing', function (assert) {
  14529. var i, ordinalStr, testMoment;
  14530. for (i = 1; i <= 31; ++i) {
  14531. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  14532. testMoment = moment(ordinalStr, 'YYYY MM Do');
  14533. assert.equal(testMoment.year(), 2014,
  14534. 'lenient ordinal parsing ' + i + ' year check');
  14535. assert.equal(testMoment.month(), 0,
  14536. 'lenient ordinal parsing ' + i + ' month check');
  14537. assert.equal(testMoment.date(), i,
  14538. 'lenient ordinal parsing ' + i + ' date check');
  14539. }
  14540. });
  14541. test('lenient ordinal parsing of number', function (assert) {
  14542. var i, testMoment;
  14543. for (i = 1; i <= 31; ++i) {
  14544. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  14545. assert.equal(testMoment.year(), 2014,
  14546. 'lenient ordinal parsing of number ' + i + ' year check');
  14547. assert.equal(testMoment.month(), 0,
  14548. 'lenient ordinal parsing of number ' + i + ' month check');
  14549. assert.equal(testMoment.date(), i,
  14550. 'lenient ordinal parsing of number ' + i + ' date check');
  14551. }
  14552. });
  14553. test('strict ordinal parsing', function (assert) {
  14554. var i, ordinalStr, testMoment;
  14555. for (i = 1; i <= 31; ++i) {
  14556. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  14557. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  14558. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  14559. }
  14560. });
  14561. }));
  14562. ;(function (global, factory) {
  14563. typeof exports === 'object' && typeof module !== 'undefined'
  14564. && typeof require === 'function' ? factory(require('../../moment')) :
  14565. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  14566. factory(global.moment)
  14567. }(this, function (moment) { 'use strict';
  14568. /*global QUnit:false*/
  14569. var test = QUnit.test;
  14570. var expect = QUnit.expect;
  14571. function module (name, lifecycle) {
  14572. QUnit.module(name, {
  14573. setup : function () {
  14574. moment.locale('en');
  14575. moment.createFromInputFallback = function (config) {
  14576. throw new Error('input not handled by moment: ' + config._i);
  14577. };
  14578. if (lifecycle && lifecycle.setup) {
  14579. lifecycle.setup();
  14580. }
  14581. },
  14582. teardown : function () {
  14583. if (lifecycle && lifecycle.teardown) {
  14584. lifecycle.teardown();
  14585. }
  14586. }
  14587. });
  14588. }
  14589. function localeModule (name, lifecycle) {
  14590. QUnit.module('locale:' + name, {
  14591. setup : function () {
  14592. moment.locale(name);
  14593. moment.createFromInputFallback = function (config) {
  14594. throw new Error('input not handled by moment: ' + config._i);
  14595. };
  14596. if (lifecycle && lifecycle.setup) {
  14597. lifecycle.setup();
  14598. }
  14599. },
  14600. teardown : function () {
  14601. moment.locale('en');
  14602. if (lifecycle && lifecycle.teardown) {
  14603. lifecycle.teardown();
  14604. }
  14605. }
  14606. });
  14607. }
  14608. localeModule('id');
  14609. test('parse', function (assert) {
  14610. var tests = 'Januari Jan_Februari Feb_Maret Mar_April Apr_Mei Mei_Juni Jun_Juli Jul_Agustus Ags_September Sep_Oktober Okt_November Nov_Desember Des'.split('_'), i;
  14611. function equalTest(input, mmm, i) {
  14612. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  14613. }
  14614. for (i = 0; i < 12; i++) {
  14615. tests[i] = tests[i].split(' ');
  14616. equalTest(tests[i][0], 'MMM', i);
  14617. equalTest(tests[i][1], 'MMM', i);
  14618. equalTest(tests[i][0], 'MMMM', i);
  14619. equalTest(tests[i][1], 'MMMM', i);
  14620. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  14621. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  14622. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  14623. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  14624. }
  14625. });
  14626. test('format', function (assert) {
  14627. var a = [
  14628. ['dddd, MMMM Do YYYY, h:mm:ss a', 'Minggu, Februari 14 2010, 3:25:50 sore'],
  14629. ['ddd, hA', 'Min, 3sore'],
  14630. ['M Mo MM MMMM MMM', '2 2 02 Februari Feb'],
  14631. ['YYYY YY', '2010 10'],
  14632. ['D Do DD', '14 14 14'],
  14633. ['d do dddd ddd dd', '0 0 Minggu Min Mg'],
  14634. ['DDD DDDo DDDD', '45 45 045'],
  14635. ['w wo ww', '7 7 07'],
  14636. ['h hh', '3 03'],
  14637. ['H HH', '15 15'],
  14638. ['m mm', '25 25'],
  14639. ['s ss', '50 50'],
  14640. ['a A', 'sore sore'],
  14641. ['[the] DDDo [day of the year]', 'the 45 day of the year'],
  14642. ['LTS', '15.25.50'],
  14643. ['L', '14/02/2010'],
  14644. ['LL', '14 Februari 2010'],
  14645. ['LLL', '14 Februari 2010 pukul 15.25'],
  14646. ['LLLL', 'Minggu, 14 Februari 2010 pukul 15.25'],
  14647. ['l', '14/2/2010'],
  14648. ['ll', '14 Feb 2010'],
  14649. ['lll', '14 Feb 2010 pukul 15.25'],
  14650. ['llll', 'Min, 14 Feb 2010 pukul 15.25']
  14651. ],
  14652. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  14653. i;
  14654. for (i = 0; i < a.length; i++) {
  14655. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  14656. }
  14657. });
  14658. test('format month', function (assert) {
  14659. var expected = 'Januari Jan_Februari Feb_Maret Mar_April Apr_Mei Mei_Juni Jun_Juli Jul_Agustus Ags_September Sep_Oktober Okt_November Nov_Desember Des'.split('_'), i;
  14660. for (i = 0; i < expected.length; i++) {
  14661. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  14662. }
  14663. });
  14664. test('format week', function (assert) {
  14665. var expected = 'Minggu Min Mg_Senin Sen Sn_Selasa Sel Sl_Rabu Rab Rb_Kamis Kam Km_Jumat Jum Jm_Sabtu Sab Sb'.split('_'), i;
  14666. for (i = 0; i < expected.length; i++) {
  14667. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  14668. }
  14669. });
  14670. test('from', function (assert) {
  14671. var start = moment([2007, 1, 28]);
  14672. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'beberapa detik', '44 seconds = a few seconds');
  14673. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'semenit', '45 seconds = a minute');
  14674. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'semenit', '89 seconds = a minute');
  14675. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 menit', '90 seconds = 2 minutes');
  14676. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 menit', '44 minutes = 44 minutes');
  14677. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'sejam', '45 minutes = an hour');
  14678. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'sejam', '89 minutes = an hour');
  14679. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 jam', '90 minutes = 2 hours');
  14680. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 jam', '5 hours = 5 hours');
  14681. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 jam', '21 hours = 21 hours');
  14682. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'sehari', '22 hours = a day');
  14683. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'sehari', '35 hours = a day');
  14684. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 hari', '36 hours = 2 days');
  14685. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'sehari', '1 day = a day');
  14686. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 hari', '5 days = 5 days');
  14687. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 hari', '25 days = 25 days');
  14688. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'sebulan', '26 days = a month');
  14689. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'sebulan', '30 days = a month');
  14690. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'sebulan', '43 days = a month');
  14691. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 bulan', '46 days = 2 months');
  14692. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 bulan', '75 days = 2 months');
  14693. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 bulan', '76 days = 3 months');
  14694. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'sebulan', '1 month = a month');
  14695. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 bulan', '5 months = 5 months');
  14696. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'setahun', '345 days = a year');
  14697. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 tahun', '548 days = 2 years');
  14698. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'setahun', '1 year = a year');
  14699. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 tahun', '5 years = 5 years');
  14700. });
  14701. test('suffix', function (assert) {
  14702. assert.equal(moment(30000).from(0), 'dalam beberapa detik', 'prefix');
  14703. assert.equal(moment(0).from(30000), 'beberapa detik yang lalu', 'suffix');
  14704. });
  14705. test('now from now', function (assert) {
  14706. assert.equal(moment().fromNow(), 'beberapa detik yang lalu', 'now from now should display as in the past');
  14707. });
  14708. test('fromNow', function (assert) {
  14709. assert.equal(moment().add({s: 30}).fromNow(), 'dalam beberapa detik', 'in a few seconds');
  14710. assert.equal(moment().add({d: 5}).fromNow(), 'dalam 5 hari', 'in 5 days');
  14711. });
  14712. test('calendar day', function (assert) {
  14713. var a = moment().hours(2).minutes(0).seconds(0);
  14714. assert.equal(moment(a).calendar(), 'Hari ini pukul 02.00', 'today at the same time');
  14715. assert.equal(moment(a).add({m: 25}).calendar(), 'Hari ini pukul 02.25', 'Now plus 25 min');
  14716. assert.equal(moment(a).add({h: 1}).calendar(), 'Hari ini pukul 03.00', 'Now plus 1 hour');
  14717. assert.equal(moment(a).add({d: 1}).calendar(), 'Besok pukul 02.00', 'tomorrow at the same time');
  14718. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Hari ini pukul 01.00', 'Now minus 1 hour');
  14719. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Kemarin pukul 02.00', 'yesterday at the same time');
  14720. });
  14721. test('calendar next week', function (assert) {
  14722. var i, m;
  14723. for (i = 2; i < 7; i++) {
  14724. m = moment().add({d: i});
  14725. assert.equal(m.calendar(), m.format('dddd [pukul] LT'), 'Today + ' + i + ' days current time');
  14726. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  14727. assert.equal(m.calendar(), m.format('dddd [pukul] LT'), 'Today + ' + i + ' days beginning of day');
  14728. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  14729. assert.equal(m.calendar(), m.format('dddd [pukul] LT'), 'Today + ' + i + ' days end of day');
  14730. }
  14731. });
  14732. test('calendar last week', function (assert) {
  14733. var i, m;
  14734. for (i = 2; i < 7; i++) {
  14735. m = moment().subtract({d: i});
  14736. assert.equal(m.calendar(), m.format('dddd [lalu pukul] LT'), 'Today - ' + i + ' days current time');
  14737. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  14738. assert.equal(m.calendar(), m.format('dddd [lalu pukul] LT'), 'Today - ' + i + ' days beginning of day');
  14739. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  14740. assert.equal(m.calendar(), m.format('dddd [lalu pukul] LT'), 'Today - ' + i + ' days end of day');
  14741. }
  14742. });
  14743. test('calendar all else', function (assert) {
  14744. var weeksAgo = moment().subtract({w: 1}),
  14745. weeksFromNow = moment().add({w: 1});
  14746. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  14747. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  14748. weeksAgo = moment().subtract({w: 2});
  14749. weeksFromNow = moment().add({w: 2});
  14750. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  14751. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  14752. });
  14753. test('weeks year starting sunday', function (assert) {
  14754. assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1');
  14755. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  14756. assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2');
  14757. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  14758. assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3');
  14759. });
  14760. test('weeks year starting monday', function (assert) {
  14761. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  14762. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  14763. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  14764. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  14765. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  14766. });
  14767. test('weeks year starting tuesday', function (assert) {
  14768. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  14769. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  14770. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  14771. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  14772. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  14773. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  14774. });
  14775. test('weeks year starting wednesday', function (assert) {
  14776. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  14777. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  14778. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  14779. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  14780. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  14781. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  14782. });
  14783. test('weeks year starting thursday', function (assert) {
  14784. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  14785. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  14786. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  14787. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  14788. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  14789. assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3');
  14790. });
  14791. test('weeks year starting friday', function (assert) {
  14792. assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1');
  14793. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  14794. assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1');
  14795. assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2');
  14796. assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2');
  14797. assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3');
  14798. });
  14799. test('weeks year starting saturday', function (assert) {
  14800. assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1');
  14801. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  14802. assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1');
  14803. assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2');
  14804. assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2');
  14805. assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3');
  14806. });
  14807. test('weeks year starting sunday formatted', function (assert) {
  14808. assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1', 'Dec 26 2011 should be week 1');
  14809. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1', 'Jan 1 2012 should be week 1');
  14810. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2', 'Jan 2 2012 should be week 2');
  14811. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2', 'Jan 8 2012 should be week 2');
  14812. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3', 'Jan 9 2012 should be week 3');
  14813. });
  14814. test('lenient ordinal parsing', function (assert) {
  14815. var i, ordinalStr, testMoment;
  14816. for (i = 1; i <= 31; ++i) {
  14817. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  14818. testMoment = moment(ordinalStr, 'YYYY MM Do');
  14819. assert.equal(testMoment.year(), 2014,
  14820. 'lenient ordinal parsing ' + i + ' year check');
  14821. assert.equal(testMoment.month(), 0,
  14822. 'lenient ordinal parsing ' + i + ' month check');
  14823. assert.equal(testMoment.date(), i,
  14824. 'lenient ordinal parsing ' + i + ' date check');
  14825. }
  14826. });
  14827. test('lenient ordinal parsing of number', function (assert) {
  14828. var i, testMoment;
  14829. for (i = 1; i <= 31; ++i) {
  14830. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  14831. assert.equal(testMoment.year(), 2014,
  14832. 'lenient ordinal parsing of number ' + i + ' year check');
  14833. assert.equal(testMoment.month(), 0,
  14834. 'lenient ordinal parsing of number ' + i + ' month check');
  14835. assert.equal(testMoment.date(), i,
  14836. 'lenient ordinal parsing of number ' + i + ' date check');
  14837. }
  14838. });
  14839. test('meridiem invariant', function (assert) {
  14840. var h, m, t1, t2;
  14841. for (h = 0; h < 24; ++h) {
  14842. for (m = 0; m < 60; m += 15) {
  14843. t1 = moment.utc([2000, 0, 1, h, m]);
  14844. t2 = moment(t1.format('A h:mm'), 'A h:mm');
  14845. assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
  14846. 'meridiem at ' + t1.format('HH:mm'));
  14847. }
  14848. }
  14849. });
  14850. test('strict ordinal parsing', function (assert) {
  14851. var i, ordinalStr, testMoment;
  14852. for (i = 1; i <= 31; ++i) {
  14853. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  14854. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  14855. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  14856. }
  14857. });
  14858. }));
  14859. ;(function (global, factory) {
  14860. typeof exports === 'object' && typeof module !== 'undefined'
  14861. && typeof require === 'function' ? factory(require('../../moment')) :
  14862. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  14863. factory(global.moment)
  14864. }(this, function (moment) { 'use strict';
  14865. /*global QUnit:false*/
  14866. var test = QUnit.test;
  14867. var expect = QUnit.expect;
  14868. function module (name, lifecycle) {
  14869. QUnit.module(name, {
  14870. setup : function () {
  14871. moment.locale('en');
  14872. moment.createFromInputFallback = function (config) {
  14873. throw new Error('input not handled by moment: ' + config._i);
  14874. };
  14875. if (lifecycle && lifecycle.setup) {
  14876. lifecycle.setup();
  14877. }
  14878. },
  14879. teardown : function () {
  14880. if (lifecycle && lifecycle.teardown) {
  14881. lifecycle.teardown();
  14882. }
  14883. }
  14884. });
  14885. }
  14886. function localeModule (name, lifecycle) {
  14887. QUnit.module('locale:' + name, {
  14888. setup : function () {
  14889. moment.locale(name);
  14890. moment.createFromInputFallback = function (config) {
  14891. throw new Error('input not handled by moment: ' + config._i);
  14892. };
  14893. if (lifecycle && lifecycle.setup) {
  14894. lifecycle.setup();
  14895. }
  14896. },
  14897. teardown : function () {
  14898. moment.locale('en');
  14899. if (lifecycle && lifecycle.teardown) {
  14900. lifecycle.teardown();
  14901. }
  14902. }
  14903. });
  14904. }
  14905. localeModule('is');
  14906. test('parse', function (assert) {
  14907. var tests = 'janúar jan_febrúar feb_mars mar_apríl apr_maí maí_júní jún_júlí júl_ágúst ágú_september sep_október okt_nóvember nóv_desember des'.split('_'), i;
  14908. function equalTest(input, mmm, i) {
  14909. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  14910. }
  14911. for (i = 0; i < 12; i++) {
  14912. tests[i] = tests[i].split(' ');
  14913. equalTest(tests[i][0], 'MMM', i);
  14914. equalTest(tests[i][1], 'MMM', i);
  14915. equalTest(tests[i][0], 'MMMM', i);
  14916. equalTest(tests[i][1], 'MMMM', i);
  14917. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  14918. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  14919. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  14920. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  14921. }
  14922. });
  14923. test('format', function (assert) {
  14924. var a = [
  14925. ['dddd, Do MMMM YYYY, h:mm:ss a', 'sunnudagur, 14. febrúar 2010, 3:25:50 pm'],
  14926. ['ddd, hA', 'sun, 3PM'],
  14927. ['M Mo MM MMMM MMM', '2 2. 02 febrúar feb'],
  14928. ['YYYY YY', '2010 10'],
  14929. ['D Do DD', '14 14. 14'],
  14930. ['d do dddd ddd dd', '0 0. sunnudagur sun Su'],
  14931. ['DDD DDDo DDDD', '45 45. 045'],
  14932. ['w wo ww', '6 6. 06'],
  14933. ['h hh', '3 03'],
  14934. ['H HH', '15 15'],
  14935. ['m mm', '25 25'],
  14936. ['s ss', '50 50'],
  14937. ['a A', 'pm PM'],
  14938. ['[the] DDDo [day of the year]', 'the 45. day of the year'],
  14939. ['LTS', '15:25:50'],
  14940. ['L', '14/02/2010'],
  14941. ['LL', '14. febrúar 2010'],
  14942. ['LLL', '14. febrúar 2010 kl. 15:25'],
  14943. ['LLLL', 'sunnudagur, 14. febrúar 2010 kl. 15:25'],
  14944. ['l', '14/2/2010'],
  14945. ['ll', '14. feb 2010'],
  14946. ['lll', '14. feb 2010 kl. 15:25'],
  14947. ['llll', 'sun, 14. feb 2010 kl. 15:25']
  14948. ],
  14949. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  14950. i;
  14951. for (i = 0; i < a.length; i++) {
  14952. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  14953. }
  14954. });
  14955. test('format ordinal', function (assert) {
  14956. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
  14957. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
  14958. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
  14959. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
  14960. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
  14961. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
  14962. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
  14963. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
  14964. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
  14965. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
  14966. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
  14967. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
  14968. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
  14969. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
  14970. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
  14971. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
  14972. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
  14973. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
  14974. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
  14975. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
  14976. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
  14977. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
  14978. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
  14979. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
  14980. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
  14981. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
  14982. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
  14983. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
  14984. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
  14985. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
  14986. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
  14987. });
  14988. test('format month', function (assert) {
  14989. var expected = 'janúar jan_febrúar feb_mars mar_apríl apr_maí maí_júní jún_júlí júl_ágúst ágú_september sep_október okt_nóvember nóv_desember des'.split('_'), i;
  14990. for (i = 0; i < expected.length; i++) {
  14991. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  14992. }
  14993. });
  14994. test('format week', function (assert) {
  14995. var expected = 'sunnudagur sun Su_mánudagur mán Má_þriðjudagur þri Þr_miðvikudagur mið Mi_fimmtudagur fim Fi_föstudagur fös Fö_laugardagur lau La'.split('_'), i;
  14996. for (i = 0; i < expected.length; i++) {
  14997. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  14998. }
  14999. });
  15000. test('from', function (assert) {
  15001. var start = moment([2007, 1, 28]);
  15002. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'nokkrar sekúndur', '44 seconds = a few seconds');
  15003. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'mínúta', '45 seconds = a minute');
  15004. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'mínúta', '89 seconds = a minute');
  15005. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 mínútur', '90 seconds = 2 minutes');
  15006. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 mínútur', '44 minutes = 44 minutes');
  15007. assert.equal(start.from(moment([2007, 1, 28]).add({m: 21}), true), '21 mínúta', '21 minutes = 21 minutes');
  15008. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'klukkustund', '45 minutes = an hour');
  15009. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'klukkustund', '89 minutes = an hour');
  15010. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 klukkustundir', '90 minutes = 2 hours');
  15011. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 klukkustundir', '5 hours = 5 hours');
  15012. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 klukkustund', '21 hours = 21 hours');
  15013. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'dagur', '22 hours = a day');
  15014. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'dagur', '35 hours = a day');
  15015. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dagar', '36 hours = 2 days');
  15016. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'dagur', '1 day = a day');
  15017. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dagar', '5 days = 5 days');
  15018. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dagar', '25 days = 25 days');
  15019. assert.equal(start.from(moment([2007, 1, 28]).add({d: 11}), true), '11 dagar', '11 days = 11 days');
  15020. assert.equal(start.from(moment([2007, 1, 28]).add({d: 21}), true), '21 dagur', '21 days = 21 days');
  15021. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'mánuður', '26 days = a month');
  15022. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'mánuður', '30 days = a month');
  15023. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'mánuður', '43 days = a month');
  15024. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mánuðir', '46 days = 2 months');
  15025. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mánuðir', '75 days = 2 months');
  15026. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mánuðir', '76 days = 3 months');
  15027. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'mánuður', '1 month = a month');
  15028. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mánuðir', '5 months = 5 months');
  15029. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ár', '345 days = a year');
  15030. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 ár', '548 days = 2 years');
  15031. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ár', '1 year = a year');
  15032. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 ár', '5 years = 5 years');
  15033. assert.equal(start.from(moment([2007, 1, 28]).add({y: 21}), true), '21 ár', '21 years = 21 years');
  15034. });
  15035. test('suffix', function (assert) {
  15036. assert.equal(moment(30000).from(0), 'eftir nokkrar sekúndur', 'prefix');
  15037. assert.equal(moment(0).from(30000), 'fyrir nokkrum sekúndum síðan', 'suffix');
  15038. assert.equal(moment().subtract({m: 1}).fromNow(), 'fyrir mínútu síðan', 'a minute ago');
  15039. });
  15040. test('now from now', function (assert) {
  15041. assert.equal(moment().fromNow(), 'fyrir nokkrum sekúndum síðan', 'now from now should display as in the past');
  15042. });
  15043. test('fromNow', function (assert) {
  15044. assert.equal(moment().add({s: 30}).fromNow(), 'eftir nokkrar sekúndur', 'in a few seconds');
  15045. assert.equal(moment().add({m: 1}).fromNow(), 'eftir mínútu', 'in a minute');
  15046. assert.equal(moment().add({d: 5}).fromNow(), 'eftir 5 daga', 'in 5 days');
  15047. });
  15048. test('calendar day', function (assert) {
  15049. var a = moment().hours(2).minutes(0).seconds(0);
  15050. assert.equal(moment(a).calendar(), 'í dag kl. 2:00', 'today at the same time');
  15051. assert.equal(moment(a).add({m: 25}).calendar(), 'í dag kl. 2:25', 'Now plus 25 min');
  15052. assert.equal(moment(a).add({h: 1}).calendar(), 'í dag kl. 3:00', 'Now plus 1 hour');
  15053. assert.equal(moment(a).add({d: 1}).calendar(), 'á morgun kl. 2:00', 'tomorrow at the same time');
  15054. assert.equal(moment(a).subtract({h: 1}).calendar(), 'í dag kl. 1:00', 'Now minus 1 hour');
  15055. assert.equal(moment(a).subtract({d: 1}).calendar(), 'í gær kl. 2:00', 'yesterday at the same time');
  15056. });
  15057. test('calendar next week', function (assert) {
  15058. var i, m;
  15059. for (i = 2; i < 7; i++) {
  15060. m = moment().add({d: i});
  15061. assert.equal(m.calendar(), m.format('dddd [kl.] LT'), 'Today + ' + i + ' days current time');
  15062. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  15063. assert.equal(m.calendar(), m.format('dddd [kl.] LT'), 'Today + ' + i + ' days beginning of day');
  15064. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  15065. assert.equal(m.calendar(), m.format('dddd [kl.] LT'), 'Today + ' + i + ' days end of day');
  15066. }
  15067. });
  15068. test('calendar last week', function (assert) {
  15069. var i, m;
  15070. for (i = 2; i < 7; i++) {
  15071. m = moment().subtract({d: i});
  15072. assert.equal(m.calendar(), m.format('[síðasta] dddd [kl.] LT'), 'Today - ' + i + ' days current time');
  15073. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  15074. assert.equal(m.calendar(), m.format('[síðasta] dddd [kl.] LT'), 'Today - ' + i + ' days beginning of day');
  15075. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  15076. assert.equal(m.calendar(), m.format('[síðasta] dddd [kl.] LT'), 'Today - ' + i + ' days end of day');
  15077. }
  15078. });
  15079. test('calendar all else', function (assert) {
  15080. var weeksAgo = moment().subtract({w: 1}),
  15081. weeksFromNow = moment().add({w: 1});
  15082. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  15083. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  15084. weeksAgo = moment().subtract({w: 2});
  15085. weeksFromNow = moment().add({w: 2});
  15086. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  15087. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  15088. });
  15089. test('weeks year starting sunday', function (assert) {
  15090. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  15091. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  15092. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  15093. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  15094. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  15095. });
  15096. test('weeks year starting monday', function (assert) {
  15097. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  15098. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  15099. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  15100. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  15101. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  15102. });
  15103. test('weeks year starting tuesday', function (assert) {
  15104. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  15105. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  15106. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  15107. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  15108. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  15109. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  15110. });
  15111. test('weeks year starting wednesday', function (assert) {
  15112. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  15113. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  15114. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  15115. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  15116. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  15117. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  15118. });
  15119. test('weeks year starting thursday', function (assert) {
  15120. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  15121. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  15122. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  15123. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  15124. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  15125. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  15126. });
  15127. test('weeks year starting friday', function (assert) {
  15128. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  15129. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  15130. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  15131. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  15132. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  15133. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  15134. });
  15135. test('weeks year starting saturday', function (assert) {
  15136. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  15137. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  15138. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  15139. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  15140. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  15141. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  15142. });
  15143. test('weeks year starting sunday formatted', function (assert) {
  15144. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
  15145. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
  15146. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
  15147. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
  15148. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
  15149. });
  15150. test('lenient ordinal parsing', function (assert) {
  15151. var i, ordinalStr, testMoment;
  15152. for (i = 1; i <= 31; ++i) {
  15153. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  15154. testMoment = moment(ordinalStr, 'YYYY MM Do');
  15155. assert.equal(testMoment.year(), 2014,
  15156. 'lenient ordinal parsing ' + i + ' year check');
  15157. assert.equal(testMoment.month(), 0,
  15158. 'lenient ordinal parsing ' + i + ' month check');
  15159. assert.equal(testMoment.date(), i,
  15160. 'lenient ordinal parsing ' + i + ' date check');
  15161. }
  15162. });
  15163. test('lenient ordinal parsing of number', function (assert) {
  15164. var i, testMoment;
  15165. for (i = 1; i <= 31; ++i) {
  15166. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  15167. assert.equal(testMoment.year(), 2014,
  15168. 'lenient ordinal parsing of number ' + i + ' year check');
  15169. assert.equal(testMoment.month(), 0,
  15170. 'lenient ordinal parsing of number ' + i + ' month check');
  15171. assert.equal(testMoment.date(), i,
  15172. 'lenient ordinal parsing of number ' + i + ' date check');
  15173. }
  15174. });
  15175. test('strict ordinal parsing', function (assert) {
  15176. var i, ordinalStr, testMoment;
  15177. for (i = 1; i <= 31; ++i) {
  15178. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  15179. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  15180. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  15181. }
  15182. });
  15183. }));
  15184. ;(function (global, factory) {
  15185. typeof exports === 'object' && typeof module !== 'undefined'
  15186. && typeof require === 'function' ? factory(require('../../moment')) :
  15187. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  15188. factory(global.moment)
  15189. }(this, function (moment) { 'use strict';
  15190. /*global QUnit:false*/
  15191. var test = QUnit.test;
  15192. var expect = QUnit.expect;
  15193. function module (name, lifecycle) {
  15194. QUnit.module(name, {
  15195. setup : function () {
  15196. moment.locale('en');
  15197. moment.createFromInputFallback = function (config) {
  15198. throw new Error('input not handled by moment: ' + config._i);
  15199. };
  15200. if (lifecycle && lifecycle.setup) {
  15201. lifecycle.setup();
  15202. }
  15203. },
  15204. teardown : function () {
  15205. if (lifecycle && lifecycle.teardown) {
  15206. lifecycle.teardown();
  15207. }
  15208. }
  15209. });
  15210. }
  15211. function localeModule (name, lifecycle) {
  15212. QUnit.module('locale:' + name, {
  15213. setup : function () {
  15214. moment.locale(name);
  15215. moment.createFromInputFallback = function (config) {
  15216. throw new Error('input not handled by moment: ' + config._i);
  15217. };
  15218. if (lifecycle && lifecycle.setup) {
  15219. lifecycle.setup();
  15220. }
  15221. },
  15222. teardown : function () {
  15223. moment.locale('en');
  15224. if (lifecycle && lifecycle.teardown) {
  15225. lifecycle.teardown();
  15226. }
  15227. }
  15228. });
  15229. }
  15230. localeModule('it');
  15231. test('parse', function (assert) {
  15232. var tests = 'gennaio gen_febbraio feb_marzo mar_aprile apr_maggio mag_giugno giu_luglio lug_agosto ago_settembre set_ottobre ott_novembre nov_dicembre dic'.split('_'), i;
  15233. function equalTest(input, mmm, i) {
  15234. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  15235. }
  15236. for (i = 0; i < 12; i++) {
  15237. tests[i] = tests[i].split(' ');
  15238. equalTest(tests[i][0], 'MMM', i);
  15239. equalTest(tests[i][1], 'MMM', i);
  15240. equalTest(tests[i][0], 'MMMM', i);
  15241. equalTest(tests[i][1], 'MMMM', i);
  15242. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  15243. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  15244. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  15245. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  15246. }
  15247. });
  15248. test('format', function (assert) {
  15249. var a = [
  15250. ['dddd, MMMM Do YYYY, h:mm:ss a', 'Domenica, febbraio 14º 2010, 3:25:50 pm'],
  15251. ['ddd, hA', 'Dom, 3PM'],
  15252. ['M Mo MM MMMM MMM', '2 2º 02 febbraio feb'],
  15253. ['YYYY YY', '2010 10'],
  15254. ['D Do DD', '14 14º 14'],
  15255. ['d do dddd ddd dd', '0 0º Domenica Dom Do'],
  15256. ['DDD DDDo DDDD', '45 45º 045'],
  15257. ['w wo ww', '6 6º 06'],
  15258. ['h hh', '3 03'],
  15259. ['H HH', '15 15'],
  15260. ['m mm', '25 25'],
  15261. ['s ss', '50 50'],
  15262. ['a A', 'pm PM'],
  15263. ['[the] DDDo [day of the year]', 'the 45º day of the year'],
  15264. ['LTS', '15:25:50'],
  15265. ['L', '14/02/2010'],
  15266. ['LL', '14 febbraio 2010'],
  15267. ['LLL', '14 febbraio 2010 15:25'],
  15268. ['LLLL', 'Domenica, 14 febbraio 2010 15:25'],
  15269. ['l', '14/2/2010'],
  15270. ['ll', '14 feb 2010'],
  15271. ['lll', '14 feb 2010 15:25'],
  15272. ['llll', 'Dom, 14 feb 2010 15:25']
  15273. ],
  15274. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  15275. i;
  15276. for (i = 0; i < a.length; i++) {
  15277. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  15278. }
  15279. });
  15280. test('format ordinal', function (assert) {
  15281. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1º', '1º');
  15282. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2º', '2º');
  15283. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3º', '3º');
  15284. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4º', '4º');
  15285. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5º', '5º');
  15286. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6º', '6º');
  15287. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7º', '7º');
  15288. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8º', '8º');
  15289. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9º', '9º');
  15290. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10º', '10º');
  15291. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11º', '11º');
  15292. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12º', '12º');
  15293. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13º', '13º');
  15294. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14º', '14º');
  15295. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15º', '15º');
  15296. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16º', '16º');
  15297. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17º', '17º');
  15298. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18º', '18º');
  15299. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19º', '19º');
  15300. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20º', '20º');
  15301. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21º', '21º');
  15302. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22º', '22º');
  15303. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23º', '23º');
  15304. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24º', '24º');
  15305. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25º', '25º');
  15306. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26º', '26º');
  15307. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27º', '27º');
  15308. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28º', '28º');
  15309. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29º', '29º');
  15310. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30º', '30º');
  15311. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31º', '31º');
  15312. });
  15313. test('format month', function (assert) {
  15314. var expected = 'gennaio gen_febbraio feb_marzo mar_aprile apr_maggio mag_giugno giu_luglio lug_agosto ago_settembre set_ottobre ott_novembre nov_dicembre dic'.split('_'), i;
  15315. for (i = 0; i < expected.length; i++) {
  15316. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  15317. }
  15318. });
  15319. test('format week', function (assert) {
  15320. var expected = 'Domenica Dom Do_Lunedì Lun Lu_Martedì Mar Ma_Mercoledì Mer Me_Giovedì Gio Gi_Venerdì Ven Ve_Sabato Sab Sa'.split('_'), i;
  15321. for (i = 0; i < expected.length; i++) {
  15322. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  15323. }
  15324. });
  15325. test('from', function (assert) {
  15326. var start = moment([2007, 1, 28]);
  15327. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'alcuni secondi', '44 seconds = seconds');
  15328. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'un minuto', '45 seconds = a minute');
  15329. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'un minuto', '89 seconds = a minute');
  15330. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuti', '90 seconds = 2 minutes');
  15331. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuti', '44 minutes = 44 minutes');
  15332. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'un\'ora', '45 minutes = an hour');
  15333. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'un\'ora', '89 minutes = an hour');
  15334. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 ore', '90 minutes = 2 hours');
  15335. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ore', '5 hours = 5 hours');
  15336. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 ore', '21 hours = 21 hours');
  15337. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'un giorno', '22 hours = a day');
  15338. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'un giorno', '35 hours = a day');
  15339. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 giorni', '36 hours = 2 days');
  15340. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'un giorno', '1 day = a day');
  15341. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 giorni', '5 days = 5 days');
  15342. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 giorni', '25 days = 25 days');
  15343. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'un mese', '26 days = a month');
  15344. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'un mese', '30 days = a month');
  15345. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'un mese', '43 days = a month');
  15346. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mesi', '46 days = 2 months');
  15347. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mesi', '75 days = 2 months');
  15348. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mesi', '76 days = 3 months');
  15349. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'un mese', '1 month = a month');
  15350. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mesi', '5 months = 5 months');
  15351. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'un anno', '345 days = a year');
  15352. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 anni', '548 days = 2 years');
  15353. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'un anno', '1 year = a year');
  15354. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 anni', '5 years = 5 years');
  15355. });
  15356. test('suffix', function (assert) {
  15357. assert.equal(moment(30000).from(0), 'in alcuni secondi', 'prefix');
  15358. assert.equal(moment(0).from(30000), 'alcuni secondi fa', 'suffix');
  15359. });
  15360. test('fromNow', function (assert) {
  15361. assert.equal(moment().add({s: 30}).fromNow(), 'in alcuni secondi', 'in seconds');
  15362. assert.equal(moment().add({d: 5}).fromNow(), 'tra 5 giorni', 'in 5 days');
  15363. });
  15364. test('calendar day', function (assert) {
  15365. var a = moment().hours(2).minutes(0).seconds(0);
  15366. assert.equal(moment(a).calendar(), 'Oggi alle 02:00', 'today at the same time');
  15367. assert.equal(moment(a).add({m: 25}).calendar(), 'Oggi alle 02:25', 'Now plus 25 min');
  15368. assert.equal(moment(a).add({h: 1}).calendar(), 'Oggi alle 03:00', 'Now plus 1 hour');
  15369. assert.equal(moment(a).add({d: 1}).calendar(), 'Domani alle 02:00', 'tomorrow at the same time');
  15370. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Oggi alle 01:00', 'Now minus 1 hour');
  15371. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Ieri alle 02:00', 'yesterday at the same time');
  15372. });
  15373. test('calendar next week', function (assert) {
  15374. var i, m;
  15375. for (i = 2; i < 7; i++) {
  15376. m = moment().add({d: i});
  15377. assert.equal(m.calendar(), m.format('dddd [alle] LT'), 'Today + ' + i + ' days current time');
  15378. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  15379. assert.equal(m.calendar(), m.format('dddd [alle] LT'), 'Today + ' + i + ' days beginning of day');
  15380. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  15381. assert.equal(m.calendar(), m.format('dddd [alle] LT'), 'Today + ' + i + ' days end of day');
  15382. }
  15383. });
  15384. test('calendar last week', function (assert) {
  15385. var i, m, weekday, datestring;
  15386. for (i = 2; i < 7; i++) {
  15387. m = moment().subtract({d: i});
  15388. // Different date string
  15389. weekday = parseInt(m.format('d'), 10);
  15390. datestring = (weekday === 0) ? '[la scorsa] dddd [alle] LT' : '[lo scorso] dddd [alle] LT';
  15391. assert.equal(m.calendar(), m.format(datestring), 'Today - ' + i + ' days current time');
  15392. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  15393. assert.equal(m.calendar(), m.format(datestring), 'Today - ' + i + ' days beginning of day');
  15394. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  15395. assert.equal(m.calendar(), m.format(datestring), 'Today - ' + i + ' days end of day');
  15396. }
  15397. });
  15398. test('calendar all else', function (assert) {
  15399. var weeksAgo = moment().subtract({w: 1}),
  15400. weeksFromNow = moment().add({w: 1});
  15401. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  15402. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  15403. weeksAgo = moment().subtract({w: 2});
  15404. weeksFromNow = moment().add({w: 2});
  15405. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  15406. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  15407. });
  15408. test('weeks year starting sunday', function (assert) {
  15409. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  15410. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  15411. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  15412. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  15413. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  15414. });
  15415. test('weeks year starting monday', function (assert) {
  15416. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  15417. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  15418. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  15419. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  15420. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  15421. });
  15422. test('weeks year starting tuesday', function (assert) {
  15423. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  15424. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  15425. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  15426. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  15427. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  15428. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  15429. });
  15430. test('weeks year starting wednesday', function (assert) {
  15431. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  15432. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  15433. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  15434. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  15435. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  15436. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  15437. });
  15438. test('weeks year starting thursday', function (assert) {
  15439. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  15440. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  15441. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  15442. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  15443. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  15444. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  15445. });
  15446. test('weeks year starting friday', function (assert) {
  15447. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  15448. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  15449. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  15450. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  15451. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  15452. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  15453. });
  15454. test('weeks year starting saturday', function (assert) {
  15455. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  15456. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  15457. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  15458. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  15459. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  15460. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  15461. });
  15462. test('weeks year starting sunday formatted', function (assert) {
  15463. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52º', 'Jan 1 2012 should be week 52');
  15464. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1º', 'Jan 2 2012 should be week 1');
  15465. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1º', 'Jan 8 2012 should be week 1');
  15466. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2º', 'Jan 9 2012 should be week 2');
  15467. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2º', 'Jan 15 2012 should be week 2');
  15468. });
  15469. test('lenient ordinal parsing', function (assert) {
  15470. var i, ordinalStr, testMoment;
  15471. for (i = 1; i <= 31; ++i) {
  15472. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  15473. testMoment = moment(ordinalStr, 'YYYY MM Do');
  15474. assert.equal(testMoment.year(), 2014,
  15475. 'lenient ordinal parsing ' + i + ' year check');
  15476. assert.equal(testMoment.month(), 0,
  15477. 'lenient ordinal parsing ' + i + ' month check');
  15478. assert.equal(testMoment.date(), i,
  15479. 'lenient ordinal parsing ' + i + ' date check');
  15480. }
  15481. });
  15482. test('lenient ordinal parsing of number', function (assert) {
  15483. var i, testMoment;
  15484. for (i = 1; i <= 31; ++i) {
  15485. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  15486. assert.equal(testMoment.year(), 2014,
  15487. 'lenient ordinal parsing of number ' + i + ' year check');
  15488. assert.equal(testMoment.month(), 0,
  15489. 'lenient ordinal parsing of number ' + i + ' month check');
  15490. assert.equal(testMoment.date(), i,
  15491. 'lenient ordinal parsing of number ' + i + ' date check');
  15492. }
  15493. });
  15494. test('strict ordinal parsing', function (assert) {
  15495. var i, ordinalStr, testMoment;
  15496. for (i = 1; i <= 31; ++i) {
  15497. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  15498. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  15499. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  15500. }
  15501. });
  15502. }));
  15503. ;(function (global, factory) {
  15504. typeof exports === 'object' && typeof module !== 'undefined'
  15505. && typeof require === 'function' ? factory(require('../../moment')) :
  15506. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  15507. factory(global.moment)
  15508. }(this, function (moment) { 'use strict';
  15509. /*global QUnit:false*/
  15510. var test = QUnit.test;
  15511. var expect = QUnit.expect;
  15512. function module (name, lifecycle) {
  15513. QUnit.module(name, {
  15514. setup : function () {
  15515. moment.locale('en');
  15516. moment.createFromInputFallback = function (config) {
  15517. throw new Error('input not handled by moment: ' + config._i);
  15518. };
  15519. if (lifecycle && lifecycle.setup) {
  15520. lifecycle.setup();
  15521. }
  15522. },
  15523. teardown : function () {
  15524. if (lifecycle && lifecycle.teardown) {
  15525. lifecycle.teardown();
  15526. }
  15527. }
  15528. });
  15529. }
  15530. function localeModule (name, lifecycle) {
  15531. QUnit.module('locale:' + name, {
  15532. setup : function () {
  15533. moment.locale(name);
  15534. moment.createFromInputFallback = function (config) {
  15535. throw new Error('input not handled by moment: ' + config._i);
  15536. };
  15537. if (lifecycle && lifecycle.setup) {
  15538. lifecycle.setup();
  15539. }
  15540. },
  15541. teardown : function () {
  15542. moment.locale('en');
  15543. if (lifecycle && lifecycle.teardown) {
  15544. lifecycle.teardown();
  15545. }
  15546. }
  15547. });
  15548. }
  15549. localeModule('ja');
  15550. test('parse', function (assert) {
  15551. var tests = '1月 1月_2月 2月_3月 3月_4月 4月_5月 5月_6月 6月_7月 7月_8月 8月_9月 9月_10月 10月_11月 11月_12月 12月'.split('_'), i;
  15552. function equalTest(input, mmm, i) {
  15553. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  15554. }
  15555. for (i = 0; i < 12; i++) {
  15556. tests[i] = tests[i].split(' ');
  15557. equalTest(tests[i][0], 'MMM', i);
  15558. equalTest(tests[i][1], 'MMM', i);
  15559. equalTest(tests[i][0], 'MMMM', i);
  15560. equalTest(tests[i][1], 'MMMM', i);
  15561. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  15562. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  15563. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  15564. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  15565. }
  15566. });
  15567. test('format', function (assert) {
  15568. var a = [
  15569. ['dddd, MMMM Do YYYY, a h:mm:ss', '日曜日, 2月 14 2010, 午後 3:25:50'],
  15570. ['ddd, Ah', '日, 午後3'],
  15571. ['M Mo MM MMMM MMM', '2 2 02 2月 2月'],
  15572. ['YYYY YY', '2010 10'],
  15573. ['D Do DD', '14 14 14'],
  15574. ['d do dddd ddd dd', '0 0 日曜日 日 日'],
  15575. ['DDD DDDo DDDD', '45 45 045'],
  15576. ['w wo ww', '8 8 08'],
  15577. ['h hh', '3 03'],
  15578. ['H HH', '15 15'],
  15579. ['m mm', '25 25'],
  15580. ['s ss', '50 50'],
  15581. ['a A', '午後 午後'],
  15582. ['[the] DDDo [day of the year]', 'the 45 day of the year'],
  15583. ['LTS', '午後3時25分50秒'],
  15584. ['L', '2010/02/14'],
  15585. ['LL', '2010年2月14日'],
  15586. ['LLL', '2010年2月14日午後3時25分'],
  15587. ['LLLL', '2010年2月14日午後3時25分 日曜日'],
  15588. ['l', '2010/2/14'],
  15589. ['ll', '2010年2月14日'],
  15590. ['lll', '2010年2月14日午後3時25分'],
  15591. ['llll', '2010年2月14日午後3時25分 日']
  15592. ],
  15593. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  15594. i;
  15595. for (i = 0; i < a.length; i++) {
  15596. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  15597. }
  15598. });
  15599. test('format month', function (assert) {
  15600. var expected = '1月 1月_2月 2月_3月 3月_4月 4月_5月 5月_6月 6月_7月 7月_8月 8月_9月 9月_10月 10月_11月 11月_12月 12月'.split('_'), i;
  15601. for (i = 0; i < expected.length; i++) {
  15602. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  15603. }
  15604. });
  15605. test('format week', function (assert) {
  15606. var expected = '日曜日 日 日_月曜日 月 月_火曜日 火 火_水曜日 水 水_木曜日 木 木_金曜日 金 金_土曜日 土 土'.split('_'), i;
  15607. for (i = 0; i < expected.length; i++) {
  15608. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  15609. }
  15610. });
  15611. test('from', function (assert) {
  15612. var start = moment([2007, 1, 28]);
  15613. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), '数秒', '44 seconds = a few seconds');
  15614. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), '1分', '45 seconds = a minute');
  15615. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), '1分', '89 seconds = a minute');
  15616. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2分', '90 seconds = 2 minutes');
  15617. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44分', '44 minutes = 44 minutes');
  15618. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), '1時間', '45 minutes = an hour');
  15619. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), '1時間', '89 minutes = an hour');
  15620. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2時間', '90 minutes = 2 hours');
  15621. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5時間', '5 hours = 5 hours');
  15622. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21時間', '21 hours = 21 hours');
  15623. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), '1日', '22 hours = a day');
  15624. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), '1日', '35 hours = a day');
  15625. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2日', '36 hours = 2 days');
  15626. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), '1日', '1 day = a day');
  15627. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5日', '5 days = 5 days');
  15628. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25日', '25 days = 25 days');
  15629. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), '1ヶ月', '26 days = a month');
  15630. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), '1ヶ月', '30 days = a month');
  15631. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), '1ヶ月', '43 days = a month');
  15632. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2ヶ月', '46 days = 2 months');
  15633. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2ヶ月', '75 days = 2 months');
  15634. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3ヶ月', '76 days = 3 months');
  15635. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), '1ヶ月', '1 month = a month');
  15636. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5ヶ月', '5 months = 5 months');
  15637. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), '1年', '345 days = a year');
  15638. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2年', '548 days = 2 years');
  15639. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), '1年', '1 year = a year');
  15640. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5年', '5 years = 5 years');
  15641. });
  15642. test('suffix', function (assert) {
  15643. assert.equal(moment(30000).from(0), '数秒後', 'prefix');
  15644. assert.equal(moment(0).from(30000), '数秒前', 'suffix');
  15645. });
  15646. test('now from now', function (assert) {
  15647. assert.equal(moment().fromNow(), '数秒前', 'now from now should display as in the past');
  15648. });
  15649. test('fromNow', function (assert) {
  15650. assert.equal(moment().add({s: 30}).fromNow(), '数秒後', 'in a few seconds');
  15651. assert.equal(moment().add({d: 5}).fromNow(), '5日後', 'in 5 days');
  15652. });
  15653. test('calendar day', function (assert) {
  15654. var a = moment().hours(2).minutes(0).seconds(0);
  15655. assert.equal(moment(a).calendar(), '今日 午前2時0分', 'today at the same time');
  15656. assert.equal(moment(a).add({m: 25}).calendar(), '今日 午前2時25分', 'Now plus 25 min');
  15657. assert.equal(moment(a).add({h: 1}).calendar(), '今日 午前3時0分', 'Now plus 1 hour');
  15658. assert.equal(moment(a).add({d: 1}).calendar(), '明日 午前2時0分', 'tomorrow at the same time');
  15659. assert.equal(moment(a).subtract({h: 1}).calendar(), '今日 午前1時0分', 'Now minus 1 hour');
  15660. assert.equal(moment(a).subtract({d: 1}).calendar(), '昨日 午前2時0分', 'yesterday at the same time');
  15661. });
  15662. test('calendar next week', function (assert) {
  15663. var i, m;
  15664. for (i = 2; i < 7; i++) {
  15665. m = moment().add({d: i});
  15666. assert.equal(m.calendar(), m.format('[来週]dddd LT'), 'Today + ' + i + ' days current time');
  15667. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  15668. assert.equal(m.calendar(), m.format('[来週]dddd LT'), 'Today + ' + i + ' days beginning of day');
  15669. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  15670. assert.equal(m.calendar(), m.format('[来週]dddd LT'), 'Today + ' + i + ' days end of day');
  15671. }
  15672. });
  15673. test('calendar last week', function (assert) {
  15674. var i, m;
  15675. for (i = 2; i < 7; i++) {
  15676. m = moment().subtract({d: i});
  15677. assert.equal(m.calendar(), m.format('[前週]dddd LT'), 'Today - ' + i + ' days current time');
  15678. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  15679. assert.equal(m.calendar(), m.format('[前週]dddd LT'), 'Today - ' + i + ' days beginning of day');
  15680. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  15681. assert.equal(m.calendar(), m.format('[前週]dddd LT'), 'Today - ' + i + ' days end of day');
  15682. }
  15683. });
  15684. test('calendar all else', function (assert) {
  15685. var weeksAgo = moment().subtract({w: 1}),
  15686. weeksFromNow = moment().add({w: 1});
  15687. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  15688. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  15689. weeksAgo = moment().subtract({w: 2});
  15690. weeksFromNow = moment().add({w: 2});
  15691. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  15692. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  15693. });
  15694. test('weeks year starting sunday', function (assert) {
  15695. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  15696. assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1');
  15697. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  15698. assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2');
  15699. assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 3');
  15700. });
  15701. test('weeks year starting monday', function (assert) {
  15702. assert.equal(moment([2006, 11, 31]).week(), 1, 'Dec 31 2006 should be week 1');
  15703. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  15704. assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1');
  15705. assert.equal(moment([2007, 0, 7]).week(), 2, 'Jan 7 2007 should be week 2');
  15706. assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2');
  15707. assert.equal(moment([2007, 0, 14]).week(), 3, 'Jan 14 2007 should be week 3');
  15708. });
  15709. test('weeks year starting tuesday', function (assert) {
  15710. assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52');
  15711. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  15712. assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1');
  15713. assert.equal(moment([2008, 0, 6]).week(), 2, 'Jan 6 2008 should be week 2');
  15714. assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2');
  15715. assert.equal(moment([2008, 0, 13]).week(), 3, 'Jan 13 2008 should be week 3');
  15716. });
  15717. test('weeks year starting wednesday', function (assert) {
  15718. assert.equal(moment([2002, 11, 29]).week(), 1, 'Dec 29 2002 should be week 1');
  15719. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  15720. assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1');
  15721. assert.equal(moment([2003, 0, 5]).week(), 2, 'Jan 5 2003 should be week 2');
  15722. assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2');
  15723. assert.equal(moment([2003, 0, 12]).week(), 3, 'Jan 12 2003 should be week 3');
  15724. });
  15725. test('weeks year starting thursday', function (assert) {
  15726. assert.equal(moment([2008, 11, 28]).week(), 1, 'Dec 28 2008 should be week 1');
  15727. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  15728. assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1');
  15729. assert.equal(moment([2009, 0, 4]).week(), 2, 'Jan 4 2009 should be week 2');
  15730. assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2');
  15731. assert.equal(moment([2009, 0, 11]).week(), 3, 'Jan 11 2009 should be week 3');
  15732. });
  15733. test('weeks year starting friday', function (assert) {
  15734. assert.equal(moment([2009, 11, 27]).week(), 1, 'Dec 27 2009 should be week 1');
  15735. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  15736. assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 should be week 1');
  15737. assert.equal(moment([2010, 0, 3]).week(), 2, 'Jan 3 2010 should be week 2');
  15738. assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 should be week 2');
  15739. assert.equal(moment([2010, 0, 10]).week(), 3, 'Jan 10 2010 should be week 3');
  15740. });
  15741. test('weeks year starting saturday', function (assert) {
  15742. assert.equal(moment([2010, 11, 26]).week(), 1, 'Dec 26 2010 should be week 1');
  15743. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  15744. assert.equal(moment([2011, 0, 2]).week(), 2, 'Jan 2 2011 should be week 2');
  15745. assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2');
  15746. assert.equal(moment([2011, 0, 9]).week(), 3, 'Jan 9 2011 should be week 3');
  15747. });
  15748. test('weeks year starting sunday format', function (assert) {
  15749. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1', 'Jan 1 2012 should be week 1');
  15750. assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1', 'Jan 7 2012 should be week 1');
  15751. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2', 'Jan 8 2012 should be week 2');
  15752. assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2', 'Jan 14 2012 should be week 2');
  15753. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3', 'Jan 15 2012 should be week 3');
  15754. });
  15755. test('lenient ordinal parsing', function (assert) {
  15756. var i, ordinalStr, testMoment;
  15757. for (i = 1; i <= 31; ++i) {
  15758. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  15759. testMoment = moment(ordinalStr, 'YYYY MM Do');
  15760. assert.equal(testMoment.year(), 2014,
  15761. 'lenient ordinal parsing ' + i + ' year check');
  15762. assert.equal(testMoment.month(), 0,
  15763. 'lenient ordinal parsing ' + i + ' month check');
  15764. assert.equal(testMoment.date(), i,
  15765. 'lenient ordinal parsing ' + i + ' date check');
  15766. }
  15767. });
  15768. test('lenient ordinal parsing of number', function (assert) {
  15769. var i, testMoment;
  15770. for (i = 1; i <= 31; ++i) {
  15771. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  15772. assert.equal(testMoment.year(), 2014,
  15773. 'lenient ordinal parsing of number ' + i + ' year check');
  15774. assert.equal(testMoment.month(), 0,
  15775. 'lenient ordinal parsing of number ' + i + ' month check');
  15776. assert.equal(testMoment.date(), i,
  15777. 'lenient ordinal parsing of number ' + i + ' date check');
  15778. }
  15779. });
  15780. test('strict ordinal parsing', function (assert) {
  15781. var i, ordinalStr, testMoment;
  15782. for (i = 1; i <= 31; ++i) {
  15783. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  15784. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  15785. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  15786. }
  15787. });
  15788. }));
  15789. ;(function (global, factory) {
  15790. typeof exports === 'object' && typeof module !== 'undefined'
  15791. && typeof require === 'function' ? factory(require('../../moment')) :
  15792. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  15793. factory(global.moment)
  15794. }(this, function (moment) { 'use strict';
  15795. /*global QUnit:false*/
  15796. var test = QUnit.test;
  15797. var expect = QUnit.expect;
  15798. function module (name, lifecycle) {
  15799. QUnit.module(name, {
  15800. setup : function () {
  15801. moment.locale('en');
  15802. moment.createFromInputFallback = function (config) {
  15803. throw new Error('input not handled by moment: ' + config._i);
  15804. };
  15805. if (lifecycle && lifecycle.setup) {
  15806. lifecycle.setup();
  15807. }
  15808. },
  15809. teardown : function () {
  15810. if (lifecycle && lifecycle.teardown) {
  15811. lifecycle.teardown();
  15812. }
  15813. }
  15814. });
  15815. }
  15816. function localeModule (name, lifecycle) {
  15817. QUnit.module('locale:' + name, {
  15818. setup : function () {
  15819. moment.locale(name);
  15820. moment.createFromInputFallback = function (config) {
  15821. throw new Error('input not handled by moment: ' + config._i);
  15822. };
  15823. if (lifecycle && lifecycle.setup) {
  15824. lifecycle.setup();
  15825. }
  15826. },
  15827. teardown : function () {
  15828. moment.locale('en');
  15829. if (lifecycle && lifecycle.teardown) {
  15830. lifecycle.teardown();
  15831. }
  15832. }
  15833. });
  15834. }
  15835. localeModule('jv');
  15836. test('parse', function (assert) {
  15837. var tests = 'Januari Jan_Februari Feb_Maret Mar_April Apr_Mei Mei_Juni Jun_Juli Jul_Agustus Ags_September Sep_Oktober Okt_Nopember Nop_Desember Des'.split('_'), i;
  15838. function equalTest(input, mmm, i) {
  15839. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  15840. }
  15841. for (i = 0; i < 12; i++) {
  15842. tests[i] = tests[i].split(' ');
  15843. equalTest(tests[i][0], 'MMM', i);
  15844. equalTest(tests[i][1], 'MMM', i);
  15845. equalTest(tests[i][0], 'MMMM', i);
  15846. equalTest(tests[i][1], 'MMMM', i);
  15847. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  15848. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  15849. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  15850. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  15851. }
  15852. });
  15853. test('format', function (assert) {
  15854. var a = [
  15855. ['dddd, MMMM Do YYYY, h:mm:ss a', 'Minggu, Februari 14 2010, 3:25:50 sonten'],
  15856. ['ddd, hA', 'Min, 3sonten'],
  15857. ['M Mo MM MMMM MMM', '2 2 02 Februari Feb'],
  15858. ['YYYY YY', '2010 10'],
  15859. ['D Do DD', '14 14 14'],
  15860. ['d do dddd ddd dd', '0 0 Minggu Min Mg'],
  15861. ['DDD DDDo DDDD', '45 45 045'],
  15862. ['w wo ww', '7 7 07'],
  15863. ['h hh', '3 03'],
  15864. ['H HH', '15 15'],
  15865. ['m mm', '25 25'],
  15866. ['s ss', '50 50'],
  15867. ['a A', 'sonten sonten'],
  15868. ['[the] DDDo [day of the year]', 'the 45 day of the year'],
  15869. ['LTS', '15.25.50'],
  15870. ['L', '14/02/2010'],
  15871. ['LL', '14 Februari 2010'],
  15872. ['LLL', '14 Februari 2010 pukul 15.25'],
  15873. ['LLLL', 'Minggu, 14 Februari 2010 pukul 15.25'],
  15874. ['l', '14/2/2010'],
  15875. ['ll', '14 Feb 2010'],
  15876. ['lll', '14 Feb 2010 pukul 15.25'],
  15877. ['llll', 'Min, 14 Feb 2010 pukul 15.25']
  15878. ],
  15879. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  15880. i;
  15881. for (i = 0; i < a.length; i++) {
  15882. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  15883. }
  15884. });
  15885. test('format month', function (assert) {
  15886. var expected = 'Januari Jan_Februari Feb_Maret Mar_April Apr_Mei Mei_Juni Jun_Juli Jul_Agustus Ags_September Sep_Oktober Okt_Nopember Nop_Desember Des'.split('_'), i;
  15887. for (i = 0; i < expected.length; i++) {
  15888. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  15889. }
  15890. });
  15891. test('format week', function (assert) {
  15892. var expected = 'Minggu Min Mg_Senen Sen Sn_Seloso Sel Sl_Rebu Reb Rb_Kemis Kem Km_Jemuwah Jem Jm_Septu Sep Sp'.split('_'), i;
  15893. for (i = 0; i < expected.length; i++) {
  15894. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  15895. }
  15896. });
  15897. test('from', function (assert) {
  15898. var start = moment([2007, 1, 28]);
  15899. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'sawetawis detik', '44 seconds = a few seconds');
  15900. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'setunggal menit', '45 seconds = a minute');
  15901. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'setunggal menit', '89 seconds = a minute');
  15902. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 menit', '90 seconds = 2 minutes');
  15903. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 menit', '44 minutes = 44 minutes');
  15904. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'setunggal jam', '45 minutes = an hour');
  15905. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'setunggal jam', '89 minutes = an hour');
  15906. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 jam', '90 minutes = 2 hours');
  15907. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 jam', '5 hours = 5 hours');
  15908. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 jam', '21 hours = 21 hours');
  15909. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'sedinten', '22 hours = a day');
  15910. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'sedinten', '35 hours = a day');
  15911. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dinten', '36 hours = 2 days');
  15912. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'sedinten', '1 day = a day');
  15913. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dinten', '5 days = 5 days');
  15914. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dinten', '25 days = 25 days');
  15915. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'sewulan', '26 days = a month');
  15916. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'sewulan', '30 days = a month');
  15917. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'sewulan', '43 days = a month');
  15918. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 wulan', '46 days = 2 months');
  15919. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 wulan', '75 days = 2 months');
  15920. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 wulan', '76 days = 3 months');
  15921. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'sewulan', '1 month = a month');
  15922. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 wulan', '5 months = 5 months');
  15923. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'setaun', '345 days = a year');
  15924. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 taun', '548 days = 2 years');
  15925. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'setaun', '1 year = a year');
  15926. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 taun', '5 years = 5 years');
  15927. });
  15928. test('suffix', function (assert) {
  15929. assert.equal(moment(30000).from(0), 'wonten ing sawetawis detik', 'prefix');
  15930. assert.equal(moment(0).from(30000), 'sawetawis detik ingkang kepengker', 'suffix');
  15931. });
  15932. test('now from now', function (assert) {
  15933. assert.equal(moment().fromNow(), 'sawetawis detik ingkang kepengker', 'now from now should display as in the past');
  15934. });
  15935. test('fromNow', function (assert) {
  15936. assert.equal(moment().add({s: 30}).fromNow(), 'wonten ing sawetawis detik', 'in a few seconds');
  15937. assert.equal(moment().add({d: 5}).fromNow(), 'wonten ing 5 dinten', 'in 5 days');
  15938. });
  15939. test('calendar day', function (assert) {
  15940. var a = moment().hours(2).minutes(0).seconds(0);
  15941. assert.equal(moment(a).calendar(), 'Dinten puniko pukul 02.00', 'today at the same time');
  15942. assert.equal(moment(a).add({m: 25}).calendar(), 'Dinten puniko pukul 02.25', 'Now plus 25 min');
  15943. assert.equal(moment(a).add({h: 1}).calendar(), 'Dinten puniko pukul 03.00', 'Now plus 1 hour');
  15944. assert.equal(moment(a).add({d: 1}).calendar(), 'Mbenjang pukul 02.00', 'tomorrow at the same time');
  15945. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Dinten puniko pukul 01.00', 'Now minus 1 hour');
  15946. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Kala wingi pukul 02.00', 'yesterday at the same time');
  15947. });
  15948. test('calendar next week', function (assert) {
  15949. var i, m;
  15950. for (i = 2; i < 7; i++) {
  15951. m = moment().add({d: i});
  15952. assert.equal(m.calendar(), m.format('dddd [pukul] LT'), 'Today + ' + i + ' days current time');
  15953. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  15954. assert.equal(m.calendar(), m.format('dddd [pukul] LT'), 'Today + ' + i + ' days beginning of day');
  15955. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  15956. assert.equal(m.calendar(), m.format('dddd [pukul] LT'), 'Today + ' + i + ' days end of day');
  15957. }
  15958. });
  15959. test('calendar last week', function (assert) {
  15960. var i, m;
  15961. for (i = 2; i < 7; i++) {
  15962. m = moment().subtract({d: i});
  15963. assert.equal(m.calendar(), m.format('dddd [kepengker pukul] LT'), 'Today - ' + i + ' days current time');
  15964. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  15965. assert.equal(m.calendar(), m.format('dddd [kepengker pukul] LT'), 'Today - ' + i + ' days beginning of day');
  15966. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  15967. assert.equal(m.calendar(), m.format('dddd [kepengker pukul] LT'), 'Today - ' + i + ' days end of day');
  15968. }
  15969. });
  15970. test('calendar all else', function (assert) {
  15971. var weeksAgo = moment().subtract({w: 1}),
  15972. weeksFromNow = moment().add({w: 1});
  15973. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  15974. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  15975. weeksAgo = moment().subtract({w: 2});
  15976. weeksFromNow = moment().add({w: 2});
  15977. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  15978. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  15979. });
  15980. // Monday is the first day of the week.
  15981. // The week that contains Jan 1st is the first week of the year.
  15982. test('weeks year starting sunday', function (assert) {
  15983. assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1');
  15984. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  15985. assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2');
  15986. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  15987. assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3');
  15988. });
  15989. test('weeks year starting monday', function (assert) {
  15990. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  15991. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  15992. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  15993. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  15994. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  15995. });
  15996. test('weeks year starting tuesday', function (assert) {
  15997. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  15998. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  15999. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  16000. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  16001. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  16002. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  16003. });
  16004. test('weeks year starting wednesday', function (assert) {
  16005. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  16006. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  16007. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  16008. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  16009. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  16010. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  16011. });
  16012. test('weeks year starting thursday', function (assert) {
  16013. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  16014. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  16015. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  16016. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  16017. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  16018. assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3');
  16019. });
  16020. test('weeks year starting friday', function (assert) {
  16021. assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1');
  16022. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  16023. assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1');
  16024. assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2');
  16025. assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2');
  16026. assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3');
  16027. });
  16028. test('weeks year starting saturday', function (assert) {
  16029. assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1');
  16030. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  16031. assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1');
  16032. assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2');
  16033. assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2');
  16034. assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3');
  16035. });
  16036. test('weeks year starting sunday formatted', function (assert) {
  16037. assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1', 'Dec 26 2011 should be week 1');
  16038. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1', 'Jan 1 2012 should be week 1');
  16039. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2', 'Jan 2 2012 should be week 2');
  16040. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2', 'Jan 8 2012 should be week 2');
  16041. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3', 'Jan 9 2012 should be week 3');
  16042. });
  16043. test('lenient ordinal parsing', function (assert) {
  16044. var i, ordinalStr, testMoment;
  16045. for (i = 1; i <= 31; ++i) {
  16046. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  16047. testMoment = moment(ordinalStr, 'YYYY MM Do');
  16048. assert.equal(testMoment.year(), 2014,
  16049. 'lenient ordinal parsing ' + i + ' year check');
  16050. assert.equal(testMoment.month(), 0,
  16051. 'lenient ordinal parsing ' + i + ' month check');
  16052. assert.equal(testMoment.date(), i,
  16053. 'lenient ordinal parsing ' + i + ' date check');
  16054. }
  16055. });
  16056. test('lenient ordinal parsing of number', function (assert) {
  16057. var i, testMoment;
  16058. for (i = 1; i <= 31; ++i) {
  16059. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  16060. assert.equal(testMoment.year(), 2014,
  16061. 'lenient ordinal parsing of number ' + i + ' year check');
  16062. assert.equal(testMoment.month(), 0,
  16063. 'lenient ordinal parsing of number ' + i + ' month check');
  16064. assert.equal(testMoment.date(), i,
  16065. 'lenient ordinal parsing of number ' + i + ' date check');
  16066. }
  16067. });
  16068. test('meridiem invariant', function (assert) {
  16069. var h, m, t1, t2;
  16070. for (h = 0; h < 24; ++h) {
  16071. for (m = 0; m < 60; m += 15) {
  16072. t1 = moment.utc([2000, 0, 1, h, m]);
  16073. t2 = moment(t1.format('A h:mm'), 'A h:mm');
  16074. assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
  16075. 'meridiem at ' + t1.format('HH:mm'));
  16076. }
  16077. }
  16078. });
  16079. test('strict ordinal parsing', function (assert) {
  16080. var i, ordinalStr, testMoment;
  16081. for (i = 1; i <= 31; ++i) {
  16082. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  16083. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  16084. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  16085. }
  16086. });
  16087. }));
  16088. ;(function (global, factory) {
  16089. typeof exports === 'object' && typeof module !== 'undefined'
  16090. && typeof require === 'function' ? factory(require('../../moment')) :
  16091. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  16092. factory(global.moment)
  16093. }(this, function (moment) { 'use strict';
  16094. /*global QUnit:false*/
  16095. var test = QUnit.test;
  16096. var expect = QUnit.expect;
  16097. function module (name, lifecycle) {
  16098. QUnit.module(name, {
  16099. setup : function () {
  16100. moment.locale('en');
  16101. moment.createFromInputFallback = function (config) {
  16102. throw new Error('input not handled by moment: ' + config._i);
  16103. };
  16104. if (lifecycle && lifecycle.setup) {
  16105. lifecycle.setup();
  16106. }
  16107. },
  16108. teardown : function () {
  16109. if (lifecycle && lifecycle.teardown) {
  16110. lifecycle.teardown();
  16111. }
  16112. }
  16113. });
  16114. }
  16115. function localeModule (name, lifecycle) {
  16116. QUnit.module('locale:' + name, {
  16117. setup : function () {
  16118. moment.locale(name);
  16119. moment.createFromInputFallback = function (config) {
  16120. throw new Error('input not handled by moment: ' + config._i);
  16121. };
  16122. if (lifecycle && lifecycle.setup) {
  16123. lifecycle.setup();
  16124. }
  16125. },
  16126. teardown : function () {
  16127. moment.locale('en');
  16128. if (lifecycle && lifecycle.teardown) {
  16129. lifecycle.teardown();
  16130. }
  16131. }
  16132. });
  16133. }
  16134. localeModule('ka');
  16135. test('parse', function (assert) {
  16136. var i,
  16137. tests = 'იანვარი იან_თებერვალი თებ_მარტი მარ_აპრილი აპრ_მაისი მაი_ივნისი ივნ_ივლისი ივლ_აგვისტო აგვ_სექტემბერი სექ_ოქტომბერი ოქტ_ნოემბერი ნოე_დეკემბერი დეკ'.split('_');
  16138. function equalTest(input, mmm, i) {
  16139. assert.equal(moment(input, mmm).month(), i, input + ' უნდა იყოს თვე ' + (i + 1));
  16140. }
  16141. for (i = 0; i < 12; i++) {
  16142. tests[i] = tests[i].split(' ');
  16143. equalTest(tests[i][0], 'MMM', i);
  16144. equalTest(tests[i][1], 'MMM', i);
  16145. equalTest(tests[i][0], 'MMMM', i);
  16146. equalTest(tests[i][1], 'MMMM', i);
  16147. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  16148. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  16149. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  16150. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  16151. }
  16152. });
  16153. test('format', function (assert) {
  16154. var a = [
  16155. ['dddd, MMMM Do YYYY, h:mm:ss a', 'კვირა, თებერვალი მე-14 2010, 3:25:50 pm'],
  16156. ['ddd, hA', 'კვი, 3PM'],
  16157. ['M Mo MM MMMM MMM', '2 მე-2 02 თებერვალი თებ'],
  16158. ['YYYY YY', '2010 10'],
  16159. ['D Do DD', '14 მე-14 14'],
  16160. ['d do dddd ddd dd', '0 0 კვირა კვი კვ'],
  16161. ['DDD DDDo DDDD', '45 45-ე 045'],
  16162. ['w wo ww', '7 მე-7 07'],
  16163. ['h hh', '3 03'],
  16164. ['H HH', '15 15'],
  16165. ['m mm', '25 25'],
  16166. ['s ss', '50 50'],
  16167. ['a A', 'pm PM'],
  16168. ['წლის DDDo დღე', 'წლის 45-ე დღე'],
  16169. ['LTS', '3:25:50 PM'],
  16170. ['L', '14/02/2010'],
  16171. ['LL', '14 თებერვალს 2010'],
  16172. ['LLL', '14 თებერვალს 2010 3:25 PM'],
  16173. ['LLLL', 'კვირა, 14 თებერვალს 2010 3:25 PM'],
  16174. ['l', '14/2/2010'],
  16175. ['ll', '14 თებ 2010'],
  16176. ['lll', '14 თებ 2010 3:25 PM'],
  16177. ['llll', 'კვი, 14 თებ 2010 3:25 PM']
  16178. ],
  16179. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  16180. i;
  16181. for (i = 0; i < a.length; i++) {
  16182. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  16183. }
  16184. });
  16185. test('format ordinal', function (assert) {
  16186. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1-ლი', '1-ლი');
  16187. assert.equal(moment([2011, 0, 2]).format('DDDo'), 'მე-2', 'მე-2');
  16188. assert.equal(moment([2011, 0, 3]).format('DDDo'), 'მე-3', 'მე-3');
  16189. assert.equal(moment([2011, 0, 4]).format('DDDo'), 'მე-4', 'მე-4');
  16190. assert.equal(moment([2011, 0, 5]).format('DDDo'), 'მე-5', 'მე-5');
  16191. assert.equal(moment([2011, 0, 6]).format('DDDo'), 'მე-6', 'მე-6');
  16192. assert.equal(moment([2011, 0, 7]).format('DDDo'), 'მე-7', 'მე-7');
  16193. assert.equal(moment([2011, 0, 8]).format('DDDo'), 'მე-8', 'მე-8');
  16194. assert.equal(moment([2011, 0, 9]).format('DDDo'), 'მე-9', 'მე-9');
  16195. assert.equal(moment([2011, 0, 10]).format('DDDo'), 'მე-10', 'მე-10');
  16196. assert.equal(moment([2011, 0, 11]).format('DDDo'), 'მე-11', 'მე-11');
  16197. assert.equal(moment([2011, 0, 12]).format('DDDo'), 'მე-12', 'მე-12');
  16198. assert.equal(moment([2011, 0, 13]).format('DDDo'), 'მე-13', 'მე-13');
  16199. assert.equal(moment([2011, 0, 14]).format('DDDo'), 'მე-14', 'მე-14');
  16200. assert.equal(moment([2011, 0, 15]).format('DDDo'), 'მე-15', 'მე-15');
  16201. assert.equal(moment([2011, 0, 16]).format('DDDo'), 'მე-16', 'მე-16');
  16202. assert.equal(moment([2011, 0, 17]).format('DDDo'), 'მე-17', 'მე-17');
  16203. assert.equal(moment([2011, 0, 18]).format('DDDo'), 'მე-18', 'მე-18');
  16204. assert.equal(moment([2011, 0, 19]).format('DDDo'), 'მე-19', 'მე-19');
  16205. assert.equal(moment([2011, 0, 20]).format('DDDo'), 'მე-20', 'მე-20');
  16206. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21-ე', '21-ე');
  16207. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22-ე', '22-ე');
  16208. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23-ე', '23-ე');
  16209. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24-ე', '24-ე');
  16210. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25-ე', '25-ე');
  16211. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26-ე', '26-ე');
  16212. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27-ე', '27-ე');
  16213. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28-ე', '28-ე');
  16214. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29-ე', '29-ე');
  16215. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30-ე', '30-ე');
  16216. assert.equal(moment('2011 40', 'YYYY DDD').format('DDDo'), 'მე-40', 'მე-40');
  16217. assert.equal(moment('2011 50', 'YYYY DDD').format('DDDo'), '50-ე', '50-ე');
  16218. assert.equal(moment('2011 60', 'YYYY DDD').format('DDDo'), 'მე-60', 'მე-60');
  16219. assert.equal(moment('2011 100', 'YYYY DDD').format('DDDo'), 'მე-100', 'მე-100');
  16220. assert.equal(moment('2011 101', 'YYYY DDD').format('DDDo'), '101-ე', '101-ე');
  16221. });
  16222. test('format month', function (assert) {
  16223. var i,
  16224. expected = 'იანვარი იან_თებერვალი თებ_მარტი მარ_აპრილი აპრ_მაისი მაი_ივნისი ივნ_ივლისი ივლ_აგვისტო აგვ_სექტემბერი სექ_ოქტომბერი ოქტ_ნოემბერი ნოე_დეკემბერი დეკ'.split('_');
  16225. for (i = 0; i < expected.length; i++) {
  16226. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  16227. }
  16228. });
  16229. test('format week', function (assert) {
  16230. var i,
  16231. expected = 'კვირა კვი კვ_ორშაბათი ორშ ორ_სამშაბათი სამ სა_ოთხშაბათი ოთხ ოთ_ხუთშაბათი ხუთ ხუ_პარასკევი პარ პა_შაბათი შაბ შა'.split('_');
  16232. for (i = 0; i < expected.length; i++) {
  16233. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  16234. }
  16235. });
  16236. test('from', function (assert) {
  16237. var start = moment([2007, 1, 28]);
  16238. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'რამდენიმე წამი', '44 წამი = რამდენიმე წამი');
  16239. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'წუთი', '45 წამი = წუთი');
  16240. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'წუთი', '89 წამი = წუთი');
  16241. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 წუთი', '90 წამი = 2 წუთი');
  16242. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 წუთი', '44 წამი = 44 წუთი');
  16243. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'საათი', '45 წამი = საათი');
  16244. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'საათი', '89 წამი = საათი');
  16245. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 საათი', '90 წამი = 2 საათი');
  16246. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 საათი', '5 საათი = 5 საათი');
  16247. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 საათი', '21 საათი = 21 საათი');
  16248. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'დღე', '22 საათი = დღე');
  16249. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'დღე', '35 საათი = დღე');
  16250. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 დღე', '36 საათი = 2 დღე');
  16251. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'დღე', '1 დღე = დღე');
  16252. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 დღე', '5 დღე = 5 დღე');
  16253. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 დღე', '25 დღე = 25 დღე');
  16254. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'თვე', '26 დღე = თვე');
  16255. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'თვე', '30 დღე = თვე');
  16256. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'თვე', '45 დღე = თვე');
  16257. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 თვე', '46 დღე = 2 თვე');
  16258. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 თვე', '75 დღე = 2 თვე');
  16259. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 თვე', '76 დღე = 3 თვე');
  16260. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'თვე', '1 თვე = თვე');
  16261. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 თვე', '5 თვე = 5 თვე');
  16262. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'წელი', '345 დღე = წელი');
  16263. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 წელი', '548 დღე = 2 წელი');
  16264. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'წელი', '1 წელი = წელი');
  16265. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 წელი', '5 წელი = 5 წელი');
  16266. });
  16267. test('suffix', function (assert) {
  16268. assert.equal(moment(30000).from(0), 'რამდენიმე წამში', 'ში სუფიქსი');
  16269. assert.equal(moment(0).from(30000), 'რამდენიმე წამის წინ', 'წინ სუფიქსი');
  16270. });
  16271. test('now from now', function (assert) {
  16272. assert.equal(moment().fromNow(), 'რამდენიმე წამის წინ', 'უნდა აჩვენოს როგორც წარსული');
  16273. });
  16274. test('fromNow', function (assert) {
  16275. assert.equal(moment().add({s: 30}).fromNow(), 'რამდენიმე წამში', 'რამდენიმე წამში');
  16276. assert.equal(moment().add({d: 5}).fromNow(), '5 დღეში', '5 დღეში');
  16277. });
  16278. test('calendar day', function (assert) {
  16279. var a = moment().hours(2).minutes(0).seconds(0);
  16280. assert.equal(moment(a).calendar(), 'დღეს 2:00 AM-ზე', 'დღეს ამავე დროს');
  16281. assert.equal(moment(a).add({m: 25}).calendar(), 'დღეს 2:25 AM-ზე', 'ახლანდელ დროს დამატებული 25 წუთი');
  16282. assert.equal(moment(a).add({h: 1}).calendar(), 'დღეს 3:00 AM-ზე', 'ახლანდელ დროს დამატებული 1 საათი');
  16283. assert.equal(moment(a).add({d: 1}).calendar(), 'ხვალ 2:00 AM-ზე', 'ხვალ ამავე დროს');
  16284. assert.equal(moment(a).subtract({h: 1}).calendar(), 'დღეს 1:00 AM-ზე', 'ახლანდელ დროს გამოკლებული 1 საათი');
  16285. assert.equal(moment(a).subtract({d: 1}).calendar(), 'გუშინ 2:00 AM-ზე', 'გუშინ ამავე დროს');
  16286. });
  16287. test('calendar next week', function (assert) {
  16288. var i, m;
  16289. for (i = 2; i < 7; i++) {
  16290. m = moment().add({d: i});
  16291. assert.equal(m.calendar(), m.format('[შემდეგ] dddd LT[-ზე]'), 'დღეს + ' + i + ' დღე ახლანდელ დროს');
  16292. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  16293. assert.equal(m.calendar(), m.format('[შემდეგ] dddd LT[-ზე]'), 'დღეს + ' + i + ' დღე დღის დასაწყისში');
  16294. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  16295. assert.equal(m.calendar(), m.format('[შემდეგ] dddd LT[-ზე]'), 'დღეს + ' + i + ' დღე დღის დასასრულს');
  16296. }
  16297. });
  16298. test('calendar last week', function (assert) {
  16299. var i, m;
  16300. for (i = 2; i < 7; i++) {
  16301. m = moment().subtract({d: i});
  16302. assert.equal(m.calendar(), m.format('[წინა] dddd LT[-ზე]'), 'დღეს - ' + i + ' დღე ახლანდელ დროს');
  16303. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  16304. assert.equal(m.calendar(), m.format('[წინა] dddd LT[-ზე]'), 'დღეს - ' + i + ' დღე დღის დასაწყისში');
  16305. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  16306. assert.equal(m.calendar(), m.format('[წინა] dddd LT[-ზე]'), 'დღეს - ' + i + ' დღე დღის დასასრულს');
  16307. }
  16308. });
  16309. test('calendar all else', function (assert) {
  16310. var weeksAgo = moment().subtract({w: 1}),
  16311. weeksFromNow = moment().add({w: 1});
  16312. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 კვირის წინ');
  16313. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), '1 კვირაში');
  16314. weeksAgo = moment().subtract({w: 2});
  16315. weeksFromNow = moment().add({w: 2});
  16316. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 კვირის წინ');
  16317. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), '2 კვირაში');
  16318. });
  16319. test('weeks year starting sunday', function (assert) {
  16320. assert.equal(moment([2011, 11, 26]).week(), 1, 'დეკ 26 2011 უნდა იყოს კვირა 1');
  16321. assert.equal(moment([2012, 0, 1]).week(), 1, 'იან 1 2012 უნდა იყოს კვირა 1');
  16322. assert.equal(moment([2012, 0, 2]).week(), 2, 'იან 2 2012 უნდა იყოს კვირა 2');
  16323. assert.equal(moment([2012, 0, 8]).week(), 2, 'იან 8 2012 უნდა იყოს კვირა 2');
  16324. assert.equal(moment([2012, 0, 9]).week(), 3, 'იან 9 2012 უნდა იყოს კვირა 3');
  16325. });
  16326. test('weeks year starting monday', function (assert) {
  16327. assert.equal(moment([2007, 0, 1]).week(), 1, 'იან 1 2007 უნდა იყოს კვირა 1');
  16328. assert.equal(moment([2007, 0, 7]).week(), 1, 'იან 7 2007 უნდა იყოს კვირა 1');
  16329. assert.equal(moment([2007, 0, 8]).week(), 2, 'იან 8 2007 უნდა იყოს კვირა 2');
  16330. assert.equal(moment([2007, 0, 14]).week(), 2, 'იან 14 2007 უნდა იყოს კვირა 2');
  16331. assert.equal(moment([2007, 0, 15]).week(), 3, 'იან 15 2007 უნდა იყოს კვირა 3');
  16332. });
  16333. test('weeks year starting tuesday', function (assert) {
  16334. assert.equal(moment([2007, 11, 31]).week(), 1, 'დეკ 31 2007 უნდა იყოს კვირა 1');
  16335. assert.equal(moment([2008, 0, 1]).week(), 1, 'იან 1 2008 უნდა იყოს კვირა 1');
  16336. assert.equal(moment([2008, 0, 6]).week(), 1, 'იან 6 2008 უნდა იყოს კვირა 1');
  16337. assert.equal(moment([2008, 0, 7]).week(), 2, 'იან 7 2008 უნდა იყოს კვირა 2');
  16338. assert.equal(moment([2008, 0, 13]).week(), 2, 'იან 13 2008 უნდა იყოს კვირა 2');
  16339. assert.equal(moment([2008, 0, 14]).week(), 3, 'იან 14 2008 უნდა იყოს კვირა 3');
  16340. });
  16341. test('weeks year starting wednesday', function (assert) {
  16342. assert.equal(moment([2002, 11, 30]).week(), 1, 'დეკ 30 2002 უნდა იყოს კვირა 1');
  16343. assert.equal(moment([2003, 0, 1]).week(), 1, 'იან 1 2003 უნდა იყოს კვირა 1');
  16344. assert.equal(moment([2003, 0, 5]).week(), 1, 'იან 5 2003 უნდა იყოს კვირა 1');
  16345. assert.equal(moment([2003, 0, 6]).week(), 2, 'იან 6 2003 უნდა იყოს კვირა 2');
  16346. assert.equal(moment([2003, 0, 12]).week(), 2, 'იან 12 2003 უნდა იყოს კვირა 2');
  16347. assert.equal(moment([2003, 0, 13]).week(), 3, 'იან 13 2003 უნდა იყოს კვირა 3');
  16348. });
  16349. test('weeks year starting thursday', function (assert) {
  16350. assert.equal(moment([2008, 11, 29]).week(), 1, 'დეკ 29 2008 უნდა იყოს კვირა 1');
  16351. assert.equal(moment([2009, 0, 1]).week(), 1, 'იან 1 2009 უნდა იყოს კვირა 1');
  16352. assert.equal(moment([2009, 0, 4]).week(), 1, 'იან 4 2009 უნდა იყოს კვირა 1');
  16353. assert.equal(moment([2009, 0, 5]).week(), 2, 'იან 5 2009 უნდა იყოს კვირა 2');
  16354. assert.equal(moment([2009, 0, 11]).week(), 2, 'იან 11 2009 უნდა იყოს კვირა 2');
  16355. assert.equal(moment([2009, 0, 12]).week(), 3, 'იან 12 2009 უნდა იყოს კვირა 3');
  16356. });
  16357. test('weeks year starting friday', function (assert) {
  16358. assert.equal(moment([2009, 11, 28]).week(), 1, 'დეკ 28 2009 უნდა იყოს კვირა 1');
  16359. assert.equal(moment([2010, 0, 1]).week(), 1, 'იან 1 2010 უნდა იყოს კვირა 1');
  16360. assert.equal(moment([2010, 0, 3]).week(), 1, 'იან 3 2010 უნდა იყოს კვირა 1');
  16361. assert.equal(moment([2010, 0, 4]).week(), 2, 'იან 4 2010 უნდა იყოს კვირა 2');
  16362. assert.equal(moment([2010, 0, 10]).week(), 2, 'იან 10 2010 უნდა იყოს კვირა 2');
  16363. assert.equal(moment([2010, 0, 11]).week(), 3, 'იან 11 2010 უნდა იყოს კვირა 3');
  16364. });
  16365. test('weeks year starting saturday', function (assert) {
  16366. assert.equal(moment([2010, 11, 27]).week(), 1, 'დეკ 27 2010 უნდა იყოს კვირა 1');
  16367. assert.equal(moment([2011, 0, 1]).week(), 1, 'იან 1 2011 უნდა იყოს კვირა 1');
  16368. assert.equal(moment([2011, 0, 2]).week(), 1, 'იან 2 2011 უნდა იყოს კვირა 1');
  16369. assert.equal(moment([2011, 0, 3]).week(), 2, 'იან 3 2011 უნდა იყოს კვირა 2');
  16370. assert.equal(moment([2011, 0, 9]).week(), 2, 'იან 9 2011 უნდა იყოს კვირა 2');
  16371. assert.equal(moment([2011, 0, 10]).week(), 3, 'იან 10 2011 უნდა იყოს კვირა 3');
  16372. });
  16373. test('weeks year starting sunday formatted', function (assert) {
  16374. assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1-ლი', 'დეკ 26 2011 უნდა იყოს კვირა 1');
  16375. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1-ლი', 'იან 1 2012 უნდა იყოს კვირა 1');
  16376. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 მე-2', 'იან 2 2012 უნდა იყოს კვირა 2');
  16377. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 მე-2', 'იან 8 2012 უნდა იყოს კვირა 2');
  16378. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 მე-3', 'იან 9 2012 უნდა იყოს კვირა 3');
  16379. });
  16380. test('lenient ordinal parsing', function (assert) {
  16381. var i, ordinalStr, testMoment;
  16382. for (i = 1; i <= 31; ++i) {
  16383. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  16384. testMoment = moment(ordinalStr, 'YYYY MM Do');
  16385. assert.equal(testMoment.year(), 2014,
  16386. 'lenient ordinal parsing ' + i + ' year check');
  16387. assert.equal(testMoment.month(), 0,
  16388. 'lenient ordinal parsing ' + i + ' month check');
  16389. assert.equal(testMoment.date(), i,
  16390. 'lenient ordinal parsing ' + i + ' date check');
  16391. }
  16392. });
  16393. test('lenient ordinal parsing of number', function (assert) {
  16394. var i, testMoment;
  16395. for (i = 1; i <= 31; ++i) {
  16396. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  16397. assert.equal(testMoment.year(), 2014,
  16398. 'lenient ordinal parsing of number ' + i + ' year check');
  16399. assert.equal(testMoment.month(), 0,
  16400. 'lenient ordinal parsing of number ' + i + ' month check');
  16401. assert.equal(testMoment.date(), i,
  16402. 'lenient ordinal parsing of number ' + i + ' date check');
  16403. }
  16404. });
  16405. test('strict ordinal parsing', function (assert) {
  16406. var i, ordinalStr, testMoment;
  16407. for (i = 1; i <= 31; ++i) {
  16408. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  16409. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  16410. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  16411. }
  16412. });
  16413. }));
  16414. ;(function (global, factory) {
  16415. typeof exports === 'object' && typeof module !== 'undefined'
  16416. && typeof require === 'function' ? factory(require('../../moment')) :
  16417. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  16418. factory(global.moment)
  16419. }(this, function (moment) { 'use strict';
  16420. /*global QUnit:false*/
  16421. var test = QUnit.test;
  16422. var expect = QUnit.expect;
  16423. function module (name, lifecycle) {
  16424. QUnit.module(name, {
  16425. setup : function () {
  16426. moment.locale('en');
  16427. moment.createFromInputFallback = function (config) {
  16428. throw new Error('input not handled by moment: ' + config._i);
  16429. };
  16430. if (lifecycle && lifecycle.setup) {
  16431. lifecycle.setup();
  16432. }
  16433. },
  16434. teardown : function () {
  16435. if (lifecycle && lifecycle.teardown) {
  16436. lifecycle.teardown();
  16437. }
  16438. }
  16439. });
  16440. }
  16441. function localeModule (name, lifecycle) {
  16442. QUnit.module('locale:' + name, {
  16443. setup : function () {
  16444. moment.locale(name);
  16445. moment.createFromInputFallback = function (config) {
  16446. throw new Error('input not handled by moment: ' + config._i);
  16447. };
  16448. if (lifecycle && lifecycle.setup) {
  16449. lifecycle.setup();
  16450. }
  16451. },
  16452. teardown : function () {
  16453. moment.locale('en');
  16454. if (lifecycle && lifecycle.teardown) {
  16455. lifecycle.teardown();
  16456. }
  16457. }
  16458. });
  16459. }
  16460. localeModule('kk');
  16461. test('parse', function (assert) {
  16462. var tests = 'Қаңтар Қаң_Ақпан Ақп_Наурыз Нау_Сәуір Сәу_Мамыр Мам_Маусым Мау_Шілде Шіл_Тамыз Там_Қыркүйек Қыр_Қазан Қаз_Қараша Қар_Желтоқсан Жел'.split('_'), i;
  16463. function equalTest(input, mmm, i) {
  16464. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  16465. }
  16466. for (i = 0; i < 12; i++) {
  16467. tests[i] = tests[i].split(' ');
  16468. equalTest(tests[i][0], 'MMM', i);
  16469. equalTest(tests[i][1], 'MMM', i);
  16470. equalTest(tests[i][0], 'MMMM', i);
  16471. equalTest(tests[i][1], 'MMMM', i);
  16472. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  16473. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  16474. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  16475. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  16476. }
  16477. });
  16478. test('format', function (assert) {
  16479. var a = [
  16480. ['dddd, Do MMMM YYYY, HH:mm:ss', 'Жексенбі, 14-ші Ақпан 2010, 15:25:50'],
  16481. ['ddd, hA', 'Жек, 3PM'],
  16482. ['M Mo MM MMMM MMM', '2 2-ші 02 Ақпан Ақп'],
  16483. ['YYYY YY', '2010 10'],
  16484. ['D Do DD', '14 14-ші 14'],
  16485. ['d do dddd ddd dd', '0 0-ші Жексенбі Жек Жк'],
  16486. ['DDD DDDo DDDD', '45 45-ші 045'],
  16487. ['w wo ww', '7 7-ші 07'],
  16488. ['h hh', '3 03'],
  16489. ['H HH', '15 15'],
  16490. ['m mm', '25 25'],
  16491. ['s ss', '50 50'],
  16492. ['a A', 'pm PM'],
  16493. ['[жылдың] DDDo [күні]', 'жылдың 45-ші күні'],
  16494. ['LTS', '15:25:50'],
  16495. ['L', '14.02.2010'],
  16496. ['LL', '14 Ақпан 2010'],
  16497. ['LLL', '14 Ақпан 2010 15:25'],
  16498. ['LLLL', 'Жексенбі, 14 Ақпан 2010 15:25'],
  16499. ['l', '14.2.2010'],
  16500. ['ll', '14 Ақп 2010'],
  16501. ['lll', '14 Ақп 2010 15:25'],
  16502. ['llll', 'Жек, 14 Ақп 2010 15:25']
  16503. ],
  16504. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  16505. i;
  16506. for (i = 0; i < a.length; i++) {
  16507. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  16508. }
  16509. });
  16510. test('format ordinal', function (assert) {
  16511. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1-ші', '1st');
  16512. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2-ші', '2nd');
  16513. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3-ші', '3rd');
  16514. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4-ші', '4th');
  16515. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5-ші', '5th');
  16516. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6-шы', '6th');
  16517. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7-ші', '7th');
  16518. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8-ші', '8th');
  16519. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9-шы', '9th');
  16520. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10-шы', '10th');
  16521. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11-ші', '11th');
  16522. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12-ші', '12th');
  16523. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13-ші', '13th');
  16524. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14-ші', '14th');
  16525. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15-ші', '15th');
  16526. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16-шы', '16th');
  16527. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17-ші', '17th');
  16528. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18-ші', '18th');
  16529. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19-шы', '19th');
  16530. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20-шы', '20th');
  16531. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21-ші', '21st');
  16532. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22-ші', '22nd');
  16533. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23-ші', '23rd');
  16534. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24-ші', '24th');
  16535. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25-ші', '25th');
  16536. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26-шы', '26th');
  16537. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27-ші', '27th');
  16538. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28-ші', '28th');
  16539. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29-шы', '29th');
  16540. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30-шы', '30th');
  16541. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31-ші', '31st');
  16542. });
  16543. test('format month', function (assert) {
  16544. var expected = 'Қаңтар Қаң_Ақпан Ақп_Наурыз Нау_Сәуір Сәу_Мамыр Мам_Маусым Мау_Шілде Шіл_Тамыз Там_Қыркүйек Қыр_Қазан Қаз_Қараша Қар_Желтоқсан Жел'.split('_'), i;
  16545. for (i = 0; i < expected.length; i++) {
  16546. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  16547. }
  16548. });
  16549. test('format week', function (assert) {
  16550. var expected = 'Жексенбі Жек Жк_Дүйсенбі Дүй Дй_Сейсенбі Сей Сй_Сәрсенбі Сәр Ср_Бейсенбі Бей Бй_Жұма Жұм Жм_Сенбі Сен Сн'.split('_'), i;
  16551. for (i = 0; i < expected.length; i++) {
  16552. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  16553. }
  16554. });
  16555. test('from', function (assert) {
  16556. var start = moment([2007, 1, 28]);
  16557. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'бірнеше секунд', '44 seconds = a few seconds');
  16558. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'бір минут', '45 seconds = a minute');
  16559. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'бір минут', '89 seconds = a minute');
  16560. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 минут', '90 seconds = 2 minutes');
  16561. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 минут', '44 minutes = 44 minutes');
  16562. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'бір сағат', '45 minutes = an hour');
  16563. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'бір сағат', '89 minutes = an hour');
  16564. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 сағат', '90 minutes = 2 hours');
  16565. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 сағат', '5 hours = 5 hours');
  16566. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 сағат', '21 hours = 21 hours');
  16567. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'бір күн', '22 hours = a day');
  16568. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'бір күн', '35 hours = a day');
  16569. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 күн', '36 hours = 2 days');
  16570. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'бір күн', '1 day = a day');
  16571. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 күн', '5 days = 5 days');
  16572. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 күн', '25 days = 25 days');
  16573. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'бір ай', '26 days = a month');
  16574. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'бір ай', '30 days = a month');
  16575. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'бір ай', '43 days = a month');
  16576. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 ай', '46 days = 2 months');
  16577. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 ай', '75 days = 2 months');
  16578. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 ай', '76 days = 3 months');
  16579. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'бір ай', '1 month = a month');
  16580. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 ай', '5 months = 5 months');
  16581. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'бір жыл', '345 days = a year');
  16582. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 жыл', '548 days = 2 years');
  16583. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'бір жыл', '1 year = a year');
  16584. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 жыл', '5 years = 5 years');
  16585. });
  16586. test('suffix', function (assert) {
  16587. assert.equal(moment(30000).from(0), 'бірнеше секунд ішінде', 'prefix');
  16588. assert.equal(moment(0).from(30000), 'бірнеше секунд бұрын', 'suffix');
  16589. });
  16590. test('now from now', function (assert) {
  16591. assert.equal(moment().fromNow(), 'бірнеше секунд бұрын', 'now from now should display as in the past');
  16592. });
  16593. test('fromNow', function (assert) {
  16594. assert.equal(moment().add({s: 30}).fromNow(), 'бірнеше секунд ішінде', 'in a few seconds');
  16595. assert.equal(moment().add({d: 5}).fromNow(), '5 күн ішінде', 'in 5 days');
  16596. });
  16597. test('calendar day', function (assert) {
  16598. var a = moment().hours(2).minutes(0).seconds(0);
  16599. assert.equal(moment(a).calendar(), 'Бүгін сағат 02:00', 'today at the same time');
  16600. assert.equal(moment(a).add({m: 25}).calendar(), 'Бүгін сағат 02:25', 'Now plus 25 min');
  16601. assert.equal(moment(a).add({h: 1}).calendar(), 'Бүгін сағат 03:00', 'Now plus 1 hour');
  16602. assert.equal(moment(a).add({d: 1}).calendar(), 'Ертең сағат 02:00', 'tomorrow at the same time');
  16603. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Бүгін сағат 01:00', 'Now minus 1 hour');
  16604. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Кеше сағат 02:00', 'yesterday at the same time');
  16605. });
  16606. test('calendar next week', function (assert) {
  16607. var i, m;
  16608. for (i = 2; i < 7; i++) {
  16609. m = moment().add({d: i});
  16610. assert.equal(m.calendar(), m.format('dddd [сағат] LT'), 'Today + ' + i + ' days current time');
  16611. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  16612. assert.equal(m.calendar(), m.format('dddd [сағат] LT'), 'Today + ' + i + ' days beginning of day');
  16613. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  16614. assert.equal(m.calendar(), m.format('dddd [сағат] LT'), 'Today + ' + i + ' days end of day');
  16615. }
  16616. });
  16617. test('calendar last week', function (assert) {
  16618. var i, m;
  16619. for (i = 2; i < 7; i++) {
  16620. m = moment().subtract({d: i});
  16621. assert.equal(m.calendar(), m.format('[Өткен аптаның] dddd [сағат] LT'), 'Today - ' + i + ' days current time');
  16622. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  16623. assert.equal(m.calendar(), m.format('[Өткен аптаның] dddd [сағат] LT'), 'Today - ' + i + ' days beginning of day');
  16624. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  16625. assert.equal(m.calendar(), m.format('[Өткен аптаның] dddd [сағат] LT'), 'Today - ' + i + ' days end of day');
  16626. }
  16627. });
  16628. test('calendar all else', function (assert) {
  16629. var weeksAgo = moment().subtract({w: 1}),
  16630. weeksFromNow = moment().add({w: 1});
  16631. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  16632. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  16633. weeksAgo = moment().subtract({w: 2});
  16634. weeksFromNow = moment().add({w: 2});
  16635. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  16636. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  16637. });
  16638. test('weeks year starting sunday', function (assert) {
  16639. assert.equal(moment([2011, 11, 25]).week(), 52, 'Dec 25 2011 should be week 52');
  16640. assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2');
  16641. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  16642. assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3');
  16643. assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 3');
  16644. });
  16645. test('weeks year starting monday', function (assert) {
  16646. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  16647. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  16648. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  16649. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  16650. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  16651. });
  16652. test('weeks year starting tuesday', function (assert) {
  16653. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  16654. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  16655. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  16656. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  16657. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  16658. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  16659. });
  16660. test('weeks year starting wednesday', function (assert) {
  16661. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  16662. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  16663. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  16664. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  16665. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  16666. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  16667. });
  16668. test('weeks year starting thursday', function (assert) {
  16669. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  16670. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  16671. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  16672. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  16673. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  16674. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  16675. });
  16676. test('weeks year starting friday', function (assert) {
  16677. assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1');
  16678. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  16679. assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1');
  16680. assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2');
  16681. assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2');
  16682. assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3');
  16683. });
  16684. test('weeks year starting saturday', function (assert) {
  16685. assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1');
  16686. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  16687. assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1');
  16688. assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2');
  16689. assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2');
  16690. assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3');
  16691. });
  16692. test('weeks year starting sunday formatted', function (assert) {
  16693. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1-ші', 'Jan 1 2012 should be week 1');
  16694. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2-ші', 'Jan 2 2012 should be week 2');
  16695. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2-ші', 'Jan 8 2012 should be week 2');
  16696. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3-ші', 'Jan 9 2012 should be week 3');
  16697. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3-ші', 'Jan 15 2012 should be week 3');
  16698. });
  16699. test('lenient ordinal parsing', function (assert) {
  16700. var i, ordinalStr, testMoment;
  16701. for (i = 1; i <= 31; ++i) {
  16702. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  16703. testMoment = moment(ordinalStr, 'YYYY MM Do');
  16704. assert.equal(testMoment.year(), 2014,
  16705. 'lenient ordinal parsing ' + i + ' year check');
  16706. assert.equal(testMoment.month(), 0,
  16707. 'lenient ordinal parsing ' + i + ' month check');
  16708. assert.equal(testMoment.date(), i,
  16709. 'lenient ordinal parsing ' + i + ' date check');
  16710. }
  16711. });
  16712. test('lenient ordinal parsing of number', function (assert) {
  16713. var i, testMoment;
  16714. for (i = 1; i <= 31; ++i) {
  16715. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  16716. assert.equal(testMoment.year(), 2014,
  16717. 'lenient ordinal parsing of number ' + i + ' year check');
  16718. assert.equal(testMoment.month(), 0,
  16719. 'lenient ordinal parsing of number ' + i + ' month check');
  16720. assert.equal(testMoment.date(), i,
  16721. 'lenient ordinal parsing of number ' + i + ' date check');
  16722. }
  16723. });
  16724. test('strict ordinal parsing', function (assert) {
  16725. var i, ordinalStr, testMoment;
  16726. for (i = 1; i <= 31; ++i) {
  16727. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  16728. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  16729. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  16730. }
  16731. });
  16732. }));
  16733. ;(function (global, factory) {
  16734. typeof exports === 'object' && typeof module !== 'undefined'
  16735. && typeof require === 'function' ? factory(require('../../moment')) :
  16736. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  16737. factory(global.moment)
  16738. }(this, function (moment) { 'use strict';
  16739. /*global QUnit:false*/
  16740. var test = QUnit.test;
  16741. var expect = QUnit.expect;
  16742. function module (name, lifecycle) {
  16743. QUnit.module(name, {
  16744. setup : function () {
  16745. moment.locale('en');
  16746. moment.createFromInputFallback = function (config) {
  16747. throw new Error('input not handled by moment: ' + config._i);
  16748. };
  16749. if (lifecycle && lifecycle.setup) {
  16750. lifecycle.setup();
  16751. }
  16752. },
  16753. teardown : function () {
  16754. if (lifecycle && lifecycle.teardown) {
  16755. lifecycle.teardown();
  16756. }
  16757. }
  16758. });
  16759. }
  16760. function localeModule (name, lifecycle) {
  16761. QUnit.module('locale:' + name, {
  16762. setup : function () {
  16763. moment.locale(name);
  16764. moment.createFromInputFallback = function (config) {
  16765. throw new Error('input not handled by moment: ' + config._i);
  16766. };
  16767. if (lifecycle && lifecycle.setup) {
  16768. lifecycle.setup();
  16769. }
  16770. },
  16771. teardown : function () {
  16772. moment.locale('en');
  16773. if (lifecycle && lifecycle.teardown) {
  16774. lifecycle.teardown();
  16775. }
  16776. }
  16777. });
  16778. }
  16779. localeModule('km');
  16780. test('parse', function (assert) {
  16781. var tests = 'មករា មករា_កុម្ភៈ កុម្ភៈ_មិនា មិនា_មេសា មេសា_ឧសភា ឧសភា_មិថុនា មិថុនា_កក្កដា កក្កដា_សីហា សីហា_កញ្ញា កញ្ញា_តុលា តុលា_វិច្ឆិកា វិច្ឆិកា_ធ្នូ ធ្នូ'.split('_'),
  16782. i;
  16783. function equalTest(input, mmm, i) {
  16784. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  16785. }
  16786. for (i = 0; i < 12; i++) {
  16787. tests[i] = tests[i].split(' ');
  16788. equalTest(tests[i][0], 'MMM', i);
  16789. equalTest(tests[i][1], 'MMM', i);
  16790. equalTest(tests[i][0], 'MMMM', i);
  16791. equalTest(tests[i][1], 'MMMM', i);
  16792. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  16793. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  16794. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  16795. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  16796. }
  16797. });
  16798. test('format', function (assert) {
  16799. var a = [
  16800. ['dddd, MMMM Do YYYY, h:mm:ss a', 'អាទិត្យ, កុម្ភៈ 14 2010, 3:25:50 pm'],
  16801. ['ddd, hA', 'អាទិត្យ, 3PM'],
  16802. ['M Mo MM MMMM MMM', '2 2 02 កុម្ភៈ កុម្ភៈ'],
  16803. ['YYYY YY', '2010 10'],
  16804. ['D Do DD', '14 14 14'],
  16805. ['d do dddd ddd dd', '0 0 អាទិត្យ អាទិត្យ អាទិត្យ'],
  16806. ['DDD DDDo DDDD', '45 45 045'],
  16807. ['w wo ww', '6 6 06'],
  16808. ['h hh', '3 03'],
  16809. ['H HH', '15 15'],
  16810. ['m mm', '25 25'],
  16811. ['s ss', '50 50'],
  16812. ['a A', 'pm PM'],
  16813. ['[the] DDDo [day of the year]', 'the 45 day of the year'],
  16814. ['LTS', '15:25:50'],
  16815. ['L', '14/02/2010'],
  16816. ['LL', '14 កុម្ភៈ 2010'],
  16817. ['LLL', '14 កុម្ភៈ 2010 15:25'],
  16818. ['LLLL', 'អាទិត្យ, 14 កុម្ភៈ 2010 15:25'],
  16819. ['l', '14/2/2010'],
  16820. ['ll', '14 កុម្ភៈ 2010'],
  16821. ['lll', '14 កុម្ភៈ 2010 15:25'],
  16822. ['llll', 'អាទិត្យ, 14 កុម្ភៈ 2010 15:25']
  16823. ],
  16824. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  16825. i;
  16826. for (i = 0; i < a.length; i++) {
  16827. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  16828. }
  16829. });
  16830. test('format ordinal', function (assert) {
  16831. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1st');
  16832. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2nd');
  16833. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3rd');
  16834. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4th');
  16835. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5th');
  16836. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6th');
  16837. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7th');
  16838. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8th');
  16839. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9th');
  16840. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10th');
  16841. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11th');
  16842. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12th');
  16843. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13th');
  16844. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14th');
  16845. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15th');
  16846. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16th');
  16847. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17th');
  16848. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18th');
  16849. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19th');
  16850. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20th');
  16851. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21st');
  16852. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22nd');
  16853. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23rd');
  16854. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24th');
  16855. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25th');
  16856. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26th');
  16857. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27th');
  16858. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28th');
  16859. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29th');
  16860. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30th');
  16861. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31st');
  16862. });
  16863. test('format month', function (assert) {
  16864. var expected = 'មករា មករា_កុម្ភៈ កុម្ភៈ_មិនា មិនា_មេសា មេសា_ឧសភា ឧសភា_មិថុនា មិថុនា_កក្កដា កក្កដា_សីហា សីហា_កញ្ញា កញ្ញា_តុលា តុលា_វិច្ឆិកា វិច្ឆិកា_ធ្នូ ធ្នូ'.split('_'),
  16865. i;
  16866. for (i = 0; i < expected.length; i++) {
  16867. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  16868. }
  16869. });
  16870. test('format week', function (assert) {
  16871. var expected = 'អាទិត្យ អាទិត្យ អាទិត្យ_ច័ន្ទ ច័ន្ទ ច័ន្ទ_អង្គារ អង្គារ អង្គារ_ពុធ ពុធ ពុធ_ព្រហស្បតិ៍ ព្រហស្បតិ៍ ព្រហស្បតិ៍_សុក្រ សុក្រ សុក្រ_សៅរ៍ សៅរ៍ សៅរ៍'.split('_'),
  16872. i;
  16873. for (i = 0; i < expected.length; i++) {
  16874. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  16875. }
  16876. });
  16877. test('from', function (assert) {
  16878. var start = moment([2007, 1, 28]);
  16879. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ប៉ុន្មានវិនាទី', '44 seconds = ប៉ុន្មានវិនាទី');
  16880. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'មួយនាទី', '45 seconds = មួយនាទី');
  16881. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'មួយនាទី', '89 seconds = មួយនាទី');
  16882. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 នាទី', '90 seconds = 2 នាទី');
  16883. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 នាទី', '44 minutes = 44 នាទី');
  16884. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'មួយម៉ោង', '45 minutes = មួយម៉ោង');
  16885. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'មួយម៉ោង', '89 minutes = មួយម៉ោង');
  16886. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 ម៉ោង', '90 minutes = 2 ម៉ោង');
  16887. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ម៉ោង', '5 hours = 5 ម៉ោង');
  16888. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 ម៉ោង', '21 hours = 21 ម៉ោង');
  16889. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'មួយថ្ងៃ', '22 hours = មួយថ្ងៃ');
  16890. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'មួយថ្ងៃ', '35 hours = មួយថ្ងៃ');
  16891. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 ថ្ងៃ', '36 hours = 2 ថ្ងៃ');
  16892. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'មួយថ្ងៃ', '1 day = មួយថ្ងៃ');
  16893. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 ថ្ងៃ', '5 days = 5 ថ្ងៃ');
  16894. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 ថ្ងៃ', '25 days = 25 ថ្ងៃ');
  16895. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'មួយខែ', '26 days = មួយខែ');
  16896. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'មួយខែ', '30 days = មួយខែ');
  16897. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'មួយខែ', '43 days = មួយខែ');
  16898. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 ខែ', '46 days = 2 ខែ');
  16899. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 ខែ', '75 days = 2 ខែ');
  16900. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 ខែ', '76 days = 3 ខែ');
  16901. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'មួយខែ', '1 month = មួយខែ');
  16902. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 ខែ', '5 months = 5 ខែ');
  16903. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'មួយឆ្នាំ', '345 days = មួយឆ្នាំ');
  16904. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 ឆ្នាំ', '548 days = 2 ឆ្នាំ');
  16905. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'មួយឆ្នាំ', '1 year = មួយឆ្នាំ');
  16906. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 ឆ្នាំ', '5 years = 5 ឆ្នាំ');
  16907. });
  16908. test('suffix', function (assert) {
  16909. assert.equal(moment(30000).from(0), 'ប៉ុន្មានវិនាទីទៀត', 'prefix');
  16910. assert.equal(moment(0).from(30000), 'ប៉ុន្មានវិនាទីមុន', 'suffix');
  16911. });
  16912. test('now from now', function (assert) {
  16913. assert.equal(moment().fromNow(), 'ប៉ុន្មានវិនាទីមុន', 'now from now should display as in the past');
  16914. });
  16915. test('fromNow', function (assert) {
  16916. assert.equal(moment().add({
  16917. s: 30
  16918. }).fromNow(), 'ប៉ុន្មានវិនាទីទៀត', 'in a few seconds');
  16919. assert.equal(moment().add({
  16920. d: 5
  16921. }).fromNow(), '5 ថ្ងៃទៀត', 'in 5 days');
  16922. });
  16923. test('calendar day', function (assert) {
  16924. var a = moment().hours(2).minutes(0).seconds(0);
  16925. assert.equal(moment(a).calendar(), 'ថ្ងៃនេះ ម៉ោង 02:00', 'today at the same time');
  16926. assert.equal(moment(a).add({
  16927. m: 25
  16928. }).calendar(), 'ថ្ងៃនេះ ម៉ោង 02:25', 'Now plus 25 min');
  16929. assert.equal(moment(a).add({
  16930. h: 1
  16931. }).calendar(), 'ថ្ងៃនេះ ម៉ោង 03:00', 'Now plus 1 hour');
  16932. assert.equal(moment(a).add({
  16933. d: 1
  16934. }).calendar(), 'ស្អែក ម៉ោង 02:00', 'tomorrow at the same time');
  16935. assert.equal(moment(a).subtract({
  16936. h: 1
  16937. }).calendar(), 'ថ្ងៃនេះ ម៉ោង 01:00', 'Now minus 1 hour');
  16938. assert.equal(moment(a).subtract({
  16939. d: 1
  16940. }).calendar(), 'ម្សិលមិញ ម៉ោង 02:00', 'yesterday at the same time');
  16941. });
  16942. test('calendar next week', function (assert) {
  16943. var i, m;
  16944. for (i = 2; i < 7; i++) {
  16945. m = moment().add({
  16946. d: i
  16947. });
  16948. assert.equal(m.calendar(), m.format('dddd [ម៉ោង] LT'), 'Today + ' + i + ' days current time');
  16949. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  16950. assert.equal(m.calendar(), m.format('dddd [ម៉ោង] LT'), 'Today + ' + i + ' days beginning of day');
  16951. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  16952. assert.equal(m.calendar(), m.format('dddd [ម៉ោង] LT'), 'Today + ' + i + ' days end of day');
  16953. }
  16954. });
  16955. test('calendar last week', function (assert) {
  16956. var i, m;
  16957. for (i = 2; i < 7; i++) {
  16958. m = moment().subtract({
  16959. d: i
  16960. });
  16961. assert.equal(m.calendar(), m.format('dddd [សប្តាហ៍មុន] [ម៉ោង] LT'), 'Today - ' + i + ' days current time');
  16962. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  16963. assert.equal(m.calendar(), m.format('dddd [សប្តាហ៍មុន] [ម៉ោង] LT'), 'Today - ' + i + ' days beginning of day');
  16964. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  16965. assert.equal(m.calendar(), m.format('dddd [សប្តាហ៍មុន] [ម៉ោង] LT'), 'Today - ' + i + ' days end of day');
  16966. }
  16967. });
  16968. test('calendar all else', function (assert) {
  16969. var weeksAgo = moment().subtract({
  16970. w: 1
  16971. }),
  16972. weeksFromNow = moment().add({
  16973. w: 1
  16974. });
  16975. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  16976. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  16977. weeksAgo = moment().subtract({
  16978. w: 2
  16979. });
  16980. weeksFromNow = moment().add({
  16981. w: 2
  16982. });
  16983. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  16984. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  16985. });
  16986. test('weeks year starting sunday', function (assert) {
  16987. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  16988. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  16989. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  16990. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  16991. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  16992. });
  16993. test('weeks year starting monday', function (assert) {
  16994. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  16995. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  16996. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  16997. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  16998. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  16999. });
  17000. test('weeks year starting tuesday', function (assert) {
  17001. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  17002. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  17003. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  17004. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  17005. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  17006. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  17007. });
  17008. test('weeks year starting wednesday', function (assert) {
  17009. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  17010. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  17011. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  17012. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  17013. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  17014. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  17015. });
  17016. test('weeks year starting thursday', function (assert) {
  17017. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  17018. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  17019. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  17020. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  17021. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  17022. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  17023. });
  17024. test('weeks year starting friday', function (assert) {
  17025. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  17026. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  17027. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  17028. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  17029. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  17030. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  17031. });
  17032. test('weeks year starting saturday', function (assert) {
  17033. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  17034. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  17035. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  17036. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  17037. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  17038. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  17039. });
  17040. test('weeks year starting sunday formatted', function (assert) {
  17041. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52', 'Jan 1 2012 should be week 52');
  17042. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1', 'Jan 2 2012 should be week 1');
  17043. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1', 'Jan 8 2012 should be week 1');
  17044. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2', 'Jan 9 2012 should be week 2');
  17045. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2', 'Jan 15 2012 should be week 2');
  17046. });
  17047. test('lenient ordinal parsing', function (assert) {
  17048. var i, ordinalStr, testMoment;
  17049. for (i = 1; i <= 31; ++i) {
  17050. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  17051. testMoment = moment(ordinalStr, 'YYYY MM Do');
  17052. assert.equal(testMoment.year(), 2014,
  17053. 'lenient ordinal parsing ' + i + ' year check');
  17054. assert.equal(testMoment.month(), 0,
  17055. 'lenient ordinal parsing ' + i + ' month check');
  17056. assert.equal(testMoment.date(), i,
  17057. 'lenient ordinal parsing ' + i + ' date check');
  17058. }
  17059. });
  17060. test('lenient ordinal parsing of number', function (assert) {
  17061. var i, testMoment;
  17062. for (i = 1; i <= 31; ++i) {
  17063. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  17064. assert.equal(testMoment.year(), 2014,
  17065. 'lenient ordinal parsing of number ' + i + ' year check');
  17066. assert.equal(testMoment.month(), 0,
  17067. 'lenient ordinal parsing of number ' + i + ' month check');
  17068. assert.equal(testMoment.date(), i,
  17069. 'lenient ordinal parsing of number ' + i + ' date check');
  17070. }
  17071. });
  17072. test('strict ordinal parsing', function (assert) {
  17073. var i, ordinalStr, testMoment;
  17074. for (i = 1; i <= 31; ++i) {
  17075. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  17076. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  17077. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  17078. }
  17079. });
  17080. }));
  17081. ;(function (global, factory) {
  17082. typeof exports === 'object' && typeof module !== 'undefined'
  17083. && typeof require === 'function' ? factory(require('../../moment')) :
  17084. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  17085. factory(global.moment)
  17086. }(this, function (moment) { 'use strict';
  17087. /*global QUnit:false*/
  17088. var test = QUnit.test;
  17089. var expect = QUnit.expect;
  17090. function module (name, lifecycle) {
  17091. QUnit.module(name, {
  17092. setup : function () {
  17093. moment.locale('en');
  17094. moment.createFromInputFallback = function (config) {
  17095. throw new Error('input not handled by moment: ' + config._i);
  17096. };
  17097. if (lifecycle && lifecycle.setup) {
  17098. lifecycle.setup();
  17099. }
  17100. },
  17101. teardown : function () {
  17102. if (lifecycle && lifecycle.teardown) {
  17103. lifecycle.teardown();
  17104. }
  17105. }
  17106. });
  17107. }
  17108. function localeModule (name, lifecycle) {
  17109. QUnit.module('locale:' + name, {
  17110. setup : function () {
  17111. moment.locale(name);
  17112. moment.createFromInputFallback = function (config) {
  17113. throw new Error('input not handled by moment: ' + config._i);
  17114. };
  17115. if (lifecycle && lifecycle.setup) {
  17116. lifecycle.setup();
  17117. }
  17118. },
  17119. teardown : function () {
  17120. moment.locale('en');
  17121. if (lifecycle && lifecycle.teardown) {
  17122. lifecycle.teardown();
  17123. }
  17124. }
  17125. });
  17126. }
  17127. localeModule('ko');
  17128. test('parse', function (assert) {
  17129. var tests = '1월 1월_2월 2월_3월 3월_4월 4월_5월 5월_6월 6월_7월 7월_8월 8월_9월 9월_10월 10월_11월 11월_12월 12월'.split('_'), i;
  17130. function equalTest(input, mmm, i) {
  17131. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  17132. }
  17133. for (i = 0; i < 12; i++) {
  17134. tests[i] = tests[i].split(' ');
  17135. equalTest(tests[i][0], 'MMM', i);
  17136. equalTest(tests[i][1], 'MMM', i);
  17137. equalTest(tests[i][0], 'MMMM', i);
  17138. equalTest(tests[i][1], 'MMMM', i);
  17139. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  17140. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  17141. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  17142. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  17143. }
  17144. });
  17145. test('parse meridiem', function (assert) {
  17146. var elements = [{
  17147. expression : '1981년 9월 8일 오후 2시 30분',
  17148. inputFormat : 'YYYY[년] M[월] D[일] A h[시] m[분]',
  17149. outputFormat : 'A',
  17150. expected : '오후'
  17151. }, {
  17152. expression : '1981년 9월 8일 오전 2시 30분',
  17153. inputFormat : 'YYYY[년] M[월] D[일] A h[시] m[분]',
  17154. outputFormat : 'A h시',
  17155. expected : '오전 2시'
  17156. }, {
  17157. expression : '14시 30분',
  17158. inputFormat : 'H[시] m[분]',
  17159. outputFormat : 'A',
  17160. expected : '오후'
  17161. }, {
  17162. expression : '오후 4시',
  17163. inputFormat : 'A h[시]',
  17164. outputFormat : 'H',
  17165. expected : '16'
  17166. }], i, l, it, actual;
  17167. for (i = 0, l = elements.length; i < l; ++i) {
  17168. it = elements[i];
  17169. actual = moment(it.expression, it.inputFormat).format(it.outputFormat);
  17170. assert.equal(
  17171. actual,
  17172. it.expected,
  17173. '\'' + it.outputFormat + '\' of \'' + it.expression + '\' must be \'' + it.expected + '\' but was \'' + actual + '\'.'
  17174. );
  17175. }
  17176. });
  17177. test('format', function (assert) {
  17178. var a = [
  17179. ['YYYY년 MMMM Do dddd a h:mm:ss', '2010년 2월 14일 일요일 오후 3:25:50'],
  17180. ['ddd A h', '일 오후 3'],
  17181. ['M Mo MM MMMM MMM', '2 2일 02 2월 2월'],
  17182. ['YYYY YY', '2010 10'],
  17183. ['D Do DD', '14 14일 14'],
  17184. ['d do dddd ddd dd', '0 0일 일요일 일 일'],
  17185. ['DDD DDDo DDDD', '45 45일 045'],
  17186. ['w wo ww', '8 8일 08'],
  17187. ['h hh', '3 03'],
  17188. ['H HH', '15 15'],
  17189. ['m mm', '25 25'],
  17190. ['s ss', '50 50'],
  17191. ['a A', '오후 오후'],
  17192. ['일년 중 DDDo째 되는 날', '일년 중 45일째 되는 날'],
  17193. ['LTS', '오후 3시 25분 50초'],
  17194. ['L', '2010.02.14'],
  17195. ['LL', '2010년 2월 14일'],
  17196. ['LLL', '2010년 2월 14일 오후 3시 25분'],
  17197. ['LLLL', '2010년 2월 14일 일요일 오후 3시 25분'],
  17198. ['l', '2010.2.14'],
  17199. ['ll', '2010년 2월 14일'],
  17200. ['lll', '2010년 2월 14일 오후 3시 25분'],
  17201. ['llll', '2010년 2월 14일 일 오후 3시 25분']
  17202. ],
  17203. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  17204. i;
  17205. for (i = 0; i < a.length; i++) {
  17206. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  17207. }
  17208. });
  17209. test('format ordinal', function (assert) {
  17210. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1일', '1일');
  17211. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2일', '2일');
  17212. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3일', '3일');
  17213. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4일', '4일');
  17214. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5일', '5일');
  17215. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6일', '6일');
  17216. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7일', '7일');
  17217. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8일', '8일');
  17218. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9일', '9일');
  17219. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10일', '10일');
  17220. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11일', '11일');
  17221. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12일', '12일');
  17222. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13일', '13일');
  17223. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14일', '14일');
  17224. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15일', '15일');
  17225. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16일', '16일');
  17226. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17일', '17일');
  17227. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18일', '18일');
  17228. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19일', '19일');
  17229. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20일', '20일');
  17230. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21일', '21일');
  17231. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22일', '22일');
  17232. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23일', '23일');
  17233. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24일', '24일');
  17234. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25일', '25일');
  17235. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26일', '26일');
  17236. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27일', '27일');
  17237. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28일', '28일');
  17238. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29일', '29일');
  17239. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30일', '30일');
  17240. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31일', '31일');
  17241. });
  17242. test('format month', function (assert) {
  17243. var expected = '1월 1월_2월 2월_3월 3월_4월 4월_5월 5월_6월 6월_7월 7월_8월 8월_9월 9월_10월 10월_11월 11월_12월 12월'.split('_'), i;
  17244. for (i = 0; i < expected.length; i++) {
  17245. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  17246. }
  17247. });
  17248. test('format week', function (assert) {
  17249. var expected = '일요일 일 일_월요일 월 월_화요일 화 화_수요일 수 수_목요일 목 목_금요일 금 금_토요일 토 토'.split('_'), i;
  17250. for (i = 0; i < expected.length; i++) {
  17251. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  17252. }
  17253. });
  17254. test('from', function (assert) {
  17255. var start = moment([2007, 1, 28]);
  17256. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), '몇초', '44초 = 몇초');
  17257. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), '일분', '45초 = 일분');
  17258. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), '일분', '89초 = 일분');
  17259. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2분', '90초 = 2분');
  17260. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44분', '44분 = 44분');
  17261. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), '한시간', '45분 = 한시간');
  17262. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), '한시간', '89분 = 한시간');
  17263. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2시간', '90분 = 2시간');
  17264. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5시간', '5시간 = 5시간');
  17265. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21시간', '21시간 = 21시간');
  17266. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), '하루', '22시간 = 하루');
  17267. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), '하루', '35시간 = 하루');
  17268. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2일', '36시간 = 2일');
  17269. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), '하루', '하루 = 하루');
  17270. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5일', '5일 = 5일');
  17271. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25일', '25일 = 25일');
  17272. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), '한달', '26일 = 한달');
  17273. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), '한달', '30일 = 한달');
  17274. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), '한달', '45일 = 한달');
  17275. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2달', '46일 = 2달');
  17276. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2달', '75일 = 2달');
  17277. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3달', '76일 = 3달');
  17278. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), '한달', '1달 = 한달');
  17279. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5달', '5달 = 5달');
  17280. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), '일년', '345일 = 일년');
  17281. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2년', '548일 = 2년');
  17282. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), '일년', '일년 = 일년');
  17283. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5년', '5년 = 5년');
  17284. });
  17285. test('suffix', function (assert) {
  17286. assert.equal(moment(30000).from(0), '몇초 후', 'prefix');
  17287. assert.equal(moment(0).from(30000), '몇초 전', 'suffix');
  17288. });
  17289. test('now from now', function (assert) {
  17290. assert.equal(moment().fromNow(), '몇초 전', 'now from now should display as in the past');
  17291. });
  17292. test('fromNow', function (assert) {
  17293. assert.equal(moment().add({s: 30}).fromNow(), '몇초 후', 'in a few seconds');
  17294. assert.equal(moment().add({d: 5}).fromNow(), '5일 후', 'in 5 days');
  17295. });
  17296. test('calendar day', function (assert) {
  17297. var a = moment().hours(2).minutes(0).seconds(0);
  17298. assert.equal(moment(a).calendar(), '오늘 오전 2시 0분', 'today at the same time');
  17299. assert.equal(moment(a).add({m: 25}).calendar(), '오늘 오전 2시 25분', 'Now plus 25 min');
  17300. assert.equal(moment(a).add({h: 1}).calendar(), '오늘 오전 3시 0분', 'Now plus 1 hour');
  17301. assert.equal(moment(a).add({d: 1}).calendar(), '내일 오전 2시 0분', 'tomorrow at the same time');
  17302. assert.equal(moment(a).subtract({h: 1}).calendar(), '오늘 오전 1시 0분', 'Now minus 1 hour');
  17303. assert.equal(moment(a).subtract({d: 1}).calendar(), '어제 오전 2시 0분', 'yesterday at the same time');
  17304. });
  17305. test('calendar next week', function (assert) {
  17306. var i, m;
  17307. for (i = 2; i < 7; i++) {
  17308. m = moment().add({d: i});
  17309. assert.equal(m.calendar(), m.format('dddd LT'), 'Today + ' + i + ' days current time');
  17310. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  17311. assert.equal(m.calendar(), m.format('dddd LT'), 'Today + ' + i + ' days beginning of day');
  17312. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  17313. assert.equal(m.calendar(), m.format('dddd LT'), 'Today + ' + i + ' days end of day');
  17314. }
  17315. });
  17316. test('calendar last week', function (assert) {
  17317. var i, m;
  17318. for (i = 2; i < 7; i++) {
  17319. m = moment().subtract({d: i});
  17320. assert.equal(m.calendar(), m.format('지난주 dddd LT'), 'Today - ' + i + ' days current time');
  17321. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  17322. assert.equal(m.calendar(), m.format('지난주 dddd LT'), 'Today - ' + i + ' days beginning of day');
  17323. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  17324. assert.equal(m.calendar(), m.format('지난주 dddd LT'), 'Today - ' + i + ' days end of day');
  17325. }
  17326. });
  17327. test('calendar all else', function (assert) {
  17328. var weeksAgo = moment().subtract({w: 1}),
  17329. weeksFromNow = moment().add({w: 1});
  17330. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  17331. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  17332. weeksAgo = moment().subtract({w: 2});
  17333. weeksFromNow = moment().add({w: 2});
  17334. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  17335. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  17336. });
  17337. test('weeks year starting sunday', function (assert) {
  17338. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  17339. assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1');
  17340. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  17341. assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2');
  17342. assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 3');
  17343. });
  17344. test('weeks year starting monday', function (assert) {
  17345. assert.equal(moment([2006, 11, 31]).week(), 1, 'Dec 31 2006 should be week 1');
  17346. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  17347. assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1');
  17348. assert.equal(moment([2007, 0, 7]).week(), 2, 'Jan 7 2007 should be week 2');
  17349. assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2');
  17350. assert.equal(moment([2007, 0, 14]).week(), 3, 'Jan 14 2007 should be week 3');
  17351. });
  17352. test('weeks year starting tuesday', function (assert) {
  17353. assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52');
  17354. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  17355. assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1');
  17356. assert.equal(moment([2008, 0, 6]).week(), 2, 'Jan 6 2008 should be week 2');
  17357. assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2');
  17358. assert.equal(moment([2008, 0, 13]).week(), 3, 'Jan 13 2008 should be week 3');
  17359. });
  17360. test('weeks year starting wednesday', function (assert) {
  17361. assert.equal(moment([2002, 11, 29]).week(), 1, 'Dec 29 2002 should be week 1');
  17362. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  17363. assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1');
  17364. assert.equal(moment([2003, 0, 5]).week(), 2, 'Jan 5 2003 should be week 2');
  17365. assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2');
  17366. assert.equal(moment([2003, 0, 12]).week(), 3, 'Jan 12 2003 should be week 3');
  17367. });
  17368. test('weeks year starting thursday', function (assert) {
  17369. assert.equal(moment([2008, 11, 28]).week(), 1, 'Dec 28 2008 should be week 1');
  17370. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  17371. assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1');
  17372. assert.equal(moment([2009, 0, 4]).week(), 2, 'Jan 4 2009 should be week 2');
  17373. assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2');
  17374. assert.equal(moment([2009, 0, 11]).week(), 3, 'Jan 11 2009 should be week 3');
  17375. });
  17376. test('weeks year starting friday', function (assert) {
  17377. assert.equal(moment([2009, 11, 27]).week(), 1, 'Dec 27 2009 should be week 1');
  17378. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  17379. assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 should be week 1');
  17380. assert.equal(moment([2010, 0, 3]).week(), 2, 'Jan 3 2010 should be week 2');
  17381. assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 should be week 2');
  17382. assert.equal(moment([2010, 0, 10]).week(), 3, 'Jan 10 2010 should be week 3');
  17383. });
  17384. test('weeks year starting saturday', function (assert) {
  17385. assert.equal(moment([2010, 11, 26]).week(), 1, 'Dec 26 2010 should be week 1');
  17386. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  17387. assert.equal(moment([2011, 0, 2]).week(), 2, 'Jan 2 2011 should be week 2');
  17388. assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2');
  17389. assert.equal(moment([2011, 0, 9]).week(), 3, 'Jan 9 2011 should be week 3');
  17390. });
  17391. test('weeks year starting sunday format', function (assert) {
  17392. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1일', 'Jan 1 2012 should be week 1');
  17393. assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1일', 'Jan 7 2012 should be week 1');
  17394. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2일', 'Jan 8 2012 should be week 2');
  17395. assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2일', 'Jan 14 2012 should be week 2');
  17396. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3일', 'Jan 15 2012 should be week 3');
  17397. });
  17398. test('lenient ordinal parsing', function (assert) {
  17399. var i, ordinalStr, testMoment;
  17400. for (i = 1; i <= 31; ++i) {
  17401. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  17402. testMoment = moment(ordinalStr, 'YYYY MM Do');
  17403. assert.equal(testMoment.year(), 2014,
  17404. 'lenient ordinal parsing ' + i + ' year check');
  17405. assert.equal(testMoment.month(), 0,
  17406. 'lenient ordinal parsing ' + i + ' month check');
  17407. assert.equal(testMoment.date(), i,
  17408. 'lenient ordinal parsing ' + i + ' date check');
  17409. }
  17410. });
  17411. test('lenient ordinal parsing of number', function (assert) {
  17412. var i, testMoment;
  17413. for (i = 1; i <= 31; ++i) {
  17414. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  17415. assert.equal(testMoment.year(), 2014,
  17416. 'lenient ordinal parsing of number ' + i + ' year check');
  17417. assert.equal(testMoment.month(), 0,
  17418. 'lenient ordinal parsing of number ' + i + ' month check');
  17419. assert.equal(testMoment.date(), i,
  17420. 'lenient ordinal parsing of number ' + i + ' date check');
  17421. }
  17422. });
  17423. test('strict ordinal parsing', function (assert) {
  17424. var i, ordinalStr, testMoment;
  17425. for (i = 1; i <= 31; ++i) {
  17426. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  17427. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  17428. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  17429. }
  17430. });
  17431. }));
  17432. ;(function (global, factory) {
  17433. typeof exports === 'object' && typeof module !== 'undefined'
  17434. && typeof require === 'function' ? factory(require('../../moment')) :
  17435. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  17436. factory(global.moment)
  17437. }(this, function (moment) { 'use strict';
  17438. /*global QUnit:false*/
  17439. var test = QUnit.test;
  17440. var expect = QUnit.expect;
  17441. function module (name, lifecycle) {
  17442. QUnit.module(name, {
  17443. setup : function () {
  17444. moment.locale('en');
  17445. moment.createFromInputFallback = function (config) {
  17446. throw new Error('input not handled by moment: ' + config._i);
  17447. };
  17448. if (lifecycle && lifecycle.setup) {
  17449. lifecycle.setup();
  17450. }
  17451. },
  17452. teardown : function () {
  17453. if (lifecycle && lifecycle.teardown) {
  17454. lifecycle.teardown();
  17455. }
  17456. }
  17457. });
  17458. }
  17459. function localeModule (name, lifecycle) {
  17460. QUnit.module('locale:' + name, {
  17461. setup : function () {
  17462. moment.locale(name);
  17463. moment.createFromInputFallback = function (config) {
  17464. throw new Error('input not handled by moment: ' + config._i);
  17465. };
  17466. if (lifecycle && lifecycle.setup) {
  17467. lifecycle.setup();
  17468. }
  17469. },
  17470. teardown : function () {
  17471. moment.locale('en');
  17472. if (lifecycle && lifecycle.teardown) {
  17473. lifecycle.teardown();
  17474. }
  17475. }
  17476. });
  17477. }
  17478. localeModule('lb');
  17479. test('parse', function (assert) {
  17480. var tests = 'Januar Jan._Februar Febr._Mäerz Mrz._Abrëll Abr._Mee Mee_Juni Jun._Juli Jul._August Aug._September Sept._Oktober Okt._November Nov._Dezember Dez.'.split('_'), i;
  17481. function equalTest(input, mmm, i) {
  17482. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  17483. }
  17484. for (i = 0; i < 12; i++) {
  17485. tests[i] = tests[i].split(' ');
  17486. equalTest(tests[i][0], 'MMM', i);
  17487. equalTest(tests[i][1], 'MMM', i);
  17488. equalTest(tests[i][0], 'MMMM', i);
  17489. equalTest(tests[i][1], 'MMMM', i);
  17490. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  17491. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  17492. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  17493. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  17494. }
  17495. });
  17496. test('format', function (assert) {
  17497. var a = [
  17498. ['dddd, Do MMMM YYYY, HH:mm:ss', 'Sonndeg, 14. Februar 2010, 15:25:50'],
  17499. ['ddd, HH:mm', 'So., 15:25'],
  17500. ['M Mo MM MMMM MMM', '2 2. 02 Februar Febr.'],
  17501. ['YYYY YY', '2010 10'],
  17502. ['D Do DD', '14 14. 14'],
  17503. ['d do dddd ddd dd', '0 0. Sonndeg So. So'],
  17504. ['DDD DDDo DDDD', '45 45. 045'],
  17505. ['w wo ww', '6 6. 06'],
  17506. ['h hh', '3 03'],
  17507. ['H HH', '15 15'],
  17508. ['m mm', '25 25'],
  17509. ['s ss', '50 50'],
  17510. ['a A', 'pm PM'],
  17511. ['[the] DDDo [day of the year]', 'the 45. day of the year'],
  17512. ['LTS', '15:25:50 Auer'],
  17513. ['L', '14.02.2010'],
  17514. ['LL', '14. Februar 2010'],
  17515. ['LLL', '14. Februar 2010 15:25 Auer'],
  17516. ['LLLL', 'Sonndeg, 14. Februar 2010 15:25 Auer'],
  17517. ['l', '14.2.2010'],
  17518. ['ll', '14. Febr. 2010'],
  17519. ['lll', '14. Febr. 2010 15:25 Auer'],
  17520. ['llll', 'So., 14. Febr. 2010 15:25 Auer']
  17521. ],
  17522. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  17523. i;
  17524. for (i = 0; i < a.length; i++) {
  17525. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  17526. }
  17527. });
  17528. test('format month', function (assert) {
  17529. var expected = 'Januar Jan._Februar Febr._Mäerz Mrz._Abrëll Abr._Mee Mee_Juni Jun._Juli Jul._August Aug._September Sept._Oktober Okt._November Nov._Dezember Dez.'.split('_'), i;
  17530. for (i = 0; i < expected.length; i++) {
  17531. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  17532. }
  17533. });
  17534. test('format week', function (assert) {
  17535. var expected = 'Sonndeg So. So_Méindeg Mé. Mé_Dënschdeg Dë. Dë_Mëttwoch Më. Më_Donneschdeg Do. Do_Freideg Fr. Fr_Samschdeg Sa. Sa'.split('_'), i;
  17536. for (i = 0; i < expected.length; i++) {
  17537. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  17538. }
  17539. });
  17540. test('from', function (assert) {
  17541. var start = moment([2007, 1, 28]);
  17542. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'e puer Sekonnen', '44 seconds = a few seconds');
  17543. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'eng Minutt', '45 seconds = a minute');
  17544. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'eng Minutt', '89 seconds = a minute');
  17545. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 Minutten', '90 seconds = 2 minutes');
  17546. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 Minutten', '44 minutes = 44 minutes');
  17547. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'eng Stonn', '45 minutes = an hour');
  17548. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'eng Stonn', '89 minutes = an hour');
  17549. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 Stonnen', '90 minutes = 2 hours');
  17550. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 Stonnen', '5 hours = 5 hours');
  17551. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 Stonnen', '21 hours = 21 hours');
  17552. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'een Dag', '22 hours = a day');
  17553. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'een Dag', '35 hours = a day');
  17554. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 Deeg', '36 hours = 2 days');
  17555. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'een Dag', '1 day = a day');
  17556. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 Deeg', '5 days = 5 days');
  17557. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 Deeg', '25 days = 25 days');
  17558. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ee Mount', '26 days = a month');
  17559. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ee Mount', '30 days = a month');
  17560. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ee Mount', '43 days = a month');
  17561. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 Méint', '46 days = 2 months');
  17562. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 Méint', '75 days = 2 months');
  17563. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 Méint', '76 days = 3 months');
  17564. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ee Mount', '1 month = a month');
  17565. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 Méint', '5 months = 5 months');
  17566. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ee Joer', '345 days = a year');
  17567. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 Joer', '548 days = 2 years');
  17568. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ee Joer', '1 year = a year');
  17569. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 Joer', '5 years = 5 years');
  17570. });
  17571. test('suffix', function (assert) {
  17572. assert.equal(moment(30000).from(0), 'an e puer Sekonnen', 'prefix');
  17573. assert.equal(moment(0).from(30000), 'virun e puer Sekonnen', 'suffix');
  17574. });
  17575. test('fromNow', function (assert) {
  17576. assert.equal(moment().add({s: 30}).fromNow(), 'an e puer Sekonnen', 'in a few seconds');
  17577. assert.equal(moment().add({d: 1}).fromNow(), 'an engem Dag', 'in one day');
  17578. assert.equal(moment().add({d: 2}).fromNow(), 'an 2 Deeg', 'in 2 days');
  17579. assert.equal(moment().add({d: 3}).fromNow(), 'an 3 Deeg', 'in 3 days');
  17580. assert.equal(moment().add({d: 4}).fromNow(), 'a 4 Deeg', 'in 4 days');
  17581. assert.equal(moment().add({d: 5}).fromNow(), 'a 5 Deeg', 'in 5 days');
  17582. assert.equal(moment().add({d: 6}).fromNow(), 'a 6 Deeg', 'in 6 days');
  17583. assert.equal(moment().add({d: 7}).fromNow(), 'a 7 Deeg', 'in 7 days');
  17584. assert.equal(moment().add({d: 8}).fromNow(), 'an 8 Deeg', 'in 8 days');
  17585. assert.equal(moment().add({d: 9}).fromNow(), 'an 9 Deeg', 'in 9 days');
  17586. assert.equal(moment().add({d: 10}).fromNow(), 'an 10 Deeg', 'in 10 days');
  17587. assert.equal(moment().add({y: 100}).fromNow(), 'an 100 Joer', 'in 100 years');
  17588. assert.equal(moment().add({y: 400}).fromNow(), 'a 400 Joer', 'in 400 years');
  17589. });
  17590. test('calendar last week', function (assert) {
  17591. var i, m, weekday, datestring;
  17592. for (i = 2; i < 7; i++) {
  17593. m = moment().subtract({d: i});
  17594. // Different date string for 'Dënschdeg' (Tuesday) and 'Donneschdeg' (Thursday)
  17595. weekday = parseInt(m.format('d'), 10);
  17596. datestring = (weekday === 2 || weekday === 4 ? '[Leschten] dddd [um] LT' : '[Leschte] dddd [um] LT');
  17597. assert.equal(m.calendar(), m.format(datestring), 'Today + ' + i + ' days current time');
  17598. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  17599. assert.equal(m.calendar(), m.format(datestring), 'Today + ' + i + ' days beginning of day');
  17600. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  17601. assert.equal(m.calendar(), m.format(datestring), 'Today + ' + i + ' days end of day');
  17602. }
  17603. });
  17604. test('lenient ordinal parsing', function (assert) {
  17605. var i, ordinalStr, testMoment;
  17606. for (i = 1; i <= 31; ++i) {
  17607. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  17608. testMoment = moment(ordinalStr, 'YYYY MM Do');
  17609. assert.equal(testMoment.year(), 2014,
  17610. 'lenient ordinal parsing ' + i + ' year check');
  17611. assert.equal(testMoment.month(), 0,
  17612. 'lenient ordinal parsing ' + i + ' month check');
  17613. assert.equal(testMoment.date(), i,
  17614. 'lenient ordinal parsing ' + i + ' date check');
  17615. }
  17616. });
  17617. test('lenient ordinal parsing of number', function (assert) {
  17618. var i, testMoment;
  17619. for (i = 1; i <= 31; ++i) {
  17620. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  17621. assert.equal(testMoment.year(), 2014,
  17622. 'lenient ordinal parsing of number ' + i + ' year check');
  17623. assert.equal(testMoment.month(), 0,
  17624. 'lenient ordinal parsing of number ' + i + ' month check');
  17625. assert.equal(testMoment.date(), i,
  17626. 'lenient ordinal parsing of number ' + i + ' date check');
  17627. }
  17628. });
  17629. test('strict ordinal parsing', function (assert) {
  17630. var i, ordinalStr, testMoment;
  17631. for (i = 1; i <= 31; ++i) {
  17632. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  17633. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  17634. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  17635. }
  17636. });
  17637. }));
  17638. ;(function (global, factory) {
  17639. typeof exports === 'object' && typeof module !== 'undefined'
  17640. && typeof require === 'function' ? factory(require('../../moment')) :
  17641. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  17642. factory(global.moment)
  17643. }(this, function (moment) { 'use strict';
  17644. /*global QUnit:false*/
  17645. var test = QUnit.test;
  17646. var expect = QUnit.expect;
  17647. function module (name, lifecycle) {
  17648. QUnit.module(name, {
  17649. setup : function () {
  17650. moment.locale('en');
  17651. moment.createFromInputFallback = function (config) {
  17652. throw new Error('input not handled by moment: ' + config._i);
  17653. };
  17654. if (lifecycle && lifecycle.setup) {
  17655. lifecycle.setup();
  17656. }
  17657. },
  17658. teardown : function () {
  17659. if (lifecycle && lifecycle.teardown) {
  17660. lifecycle.teardown();
  17661. }
  17662. }
  17663. });
  17664. }
  17665. function localeModule (name, lifecycle) {
  17666. QUnit.module('locale:' + name, {
  17667. setup : function () {
  17668. moment.locale(name);
  17669. moment.createFromInputFallback = function (config) {
  17670. throw new Error('input not handled by moment: ' + config._i);
  17671. };
  17672. if (lifecycle && lifecycle.setup) {
  17673. lifecycle.setup();
  17674. }
  17675. },
  17676. teardown : function () {
  17677. moment.locale('en');
  17678. if (lifecycle && lifecycle.teardown) {
  17679. lifecycle.teardown();
  17680. }
  17681. }
  17682. });
  17683. }
  17684. localeModule('lo');
  17685. test('parse', function (assert) {
  17686. var tests = 'ມັງກອນ ມັງກອນ_ກຸມພາ ກຸມພາ_ມີນາ ມີນາ_ເມສາ ເມສາ_ພຶດສະພາ ພຶດສະພາ_ມິຖຸນາ ມິຖຸນາ_ກໍລະກົດ ກໍລະກົດ_ສິງຫາ ສິງຫາ_ກັນຍາ ກັນຍາ_ຕຸລາ ຕຸລາ_ພະຈິກ ພະຈິກ_ທັນວາ ທັນວາ'.split('_'), i;
  17687. function equalTest(input, mmm, i) {
  17688. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  17689. }
  17690. for (i = 0; i < 12; i++) {
  17691. tests[i] = tests[i].split(' ');
  17692. equalTest(tests[i][0], 'MMM', i);
  17693. equalTest(tests[i][1], 'MMM', i);
  17694. equalTest(tests[i][0], 'MMMM', i);
  17695. equalTest(tests[i][1], 'MMMM', i);
  17696. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  17697. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  17698. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  17699. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  17700. }
  17701. });
  17702. test('format', function (assert) {
  17703. var a = [
  17704. ['dddd, MMMM Do YYYY, h:mm:ss a', 'ອາທິດ, ກຸມພາ ທີ່14 2010, 3:25:50 ຕອນແລງ'],
  17705. ['ddd, hA', 'ທິດ, 3ຕອນແລງ'],
  17706. ['M Mo MM MMMM MMM', '2 ທີ່2 02 ກຸມພາ ກຸມພາ'],
  17707. ['YYYY YY', '2010 10'],
  17708. ['D Do DD', '14 ທີ່14 14'],
  17709. ['d do dddd ddd dd', '0 ທີ່0 ອາທິດ ທິດ ທ'],
  17710. ['DDD DDDo DDDD', '45 ທີ່45 045'],
  17711. ['w wo ww', '8 ທີ່8 08'],
  17712. ['h hh', '3 03'],
  17713. ['H HH', '15 15'],
  17714. ['m mm', '25 25'],
  17715. ['s ss', '50 50'],
  17716. ['a A', 'ຕອນແລງ ຕອນແລງ'],
  17717. ['[ວັນ]DDDo [ຂອງປີ]', 'ວັນທີ່45 ຂອງປີ'],
  17718. ['LTS', '15:25:50'],
  17719. ['L', '14/02/2010'],
  17720. ['LL', '14 ກຸມພາ 2010'],
  17721. ['LLL', '14 ກຸມພາ 2010 15:25'],
  17722. ['LLLL', 'ວັນອາທິດ 14 ກຸມພາ 2010 15:25'],
  17723. ['l', '14/2/2010'],
  17724. ['ll', '14 ກຸມພາ 2010'],
  17725. ['lll', '14 ກຸມພາ 2010 15:25'],
  17726. ['llll', 'ວັນທິດ 14 ກຸມພາ 2010 15:25']
  17727. ],
  17728. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  17729. i;
  17730. for (i = 0; i < a.length; i++) {
  17731. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  17732. }
  17733. });
  17734. test('format ordinal', function (assert) {
  17735. assert.equal(moment([2011, 0, 1]).format('DDDo'), 'ທີ່1', 'ທີ່1');
  17736. assert.equal(moment([2011, 0, 2]).format('DDDo'), 'ທີ່2', 'ທີ່2');
  17737. assert.equal(moment([2011, 0, 3]).format('DDDo'), 'ທີ່3', 'ທີ່3');
  17738. assert.equal(moment([2011, 0, 4]).format('DDDo'), 'ທີ່4', 'ທີ່4');
  17739. assert.equal(moment([2011, 0, 5]).format('DDDo'), 'ທີ່5', 'ທີ່5');
  17740. assert.equal(moment([2011, 0, 6]).format('DDDo'), 'ທີ່6', 'ທີ່6');
  17741. assert.equal(moment([2011, 0, 7]).format('DDDo'), 'ທີ່7', 'ທີ່7');
  17742. assert.equal(moment([2011, 0, 8]).format('DDDo'), 'ທີ່8', 'ທີ່8');
  17743. assert.equal(moment([2011, 0, 9]).format('DDDo'), 'ທີ່9', 'ທີ່9');
  17744. assert.equal(moment([2011, 0, 10]).format('DDDo'), 'ທີ່10', 'ທີ່10');
  17745. assert.equal(moment([2011, 0, 11]).format('DDDo'), 'ທີ່11', 'ທີ່11');
  17746. assert.equal(moment([2011, 0, 12]).format('DDDo'), 'ທີ່12', 'ທີ່12');
  17747. assert.equal(moment([2011, 0, 13]).format('DDDo'), 'ທີ່13', 'ທີ່13');
  17748. assert.equal(moment([2011, 0, 14]).format('DDDo'), 'ທີ່14', 'ທີ່14');
  17749. assert.equal(moment([2011, 0, 15]).format('DDDo'), 'ທີ່15', 'ທີ່15');
  17750. assert.equal(moment([2011, 0, 16]).format('DDDo'), 'ທີ່16', 'ທີ່16');
  17751. assert.equal(moment([2011, 0, 17]).format('DDDo'), 'ທີ່17', 'ທີ່17');
  17752. assert.equal(moment([2011, 0, 18]).format('DDDo'), 'ທີ່18', 'ທີ່18');
  17753. assert.equal(moment([2011, 0, 19]).format('DDDo'), 'ທີ່19', 'ທີ່19');
  17754. assert.equal(moment([2011, 0, 20]).format('DDDo'), 'ທີ່20', 'ທີ່20');
  17755. assert.equal(moment([2011, 0, 21]).format('DDDo'), 'ທີ່21', 'ທີ່21');
  17756. assert.equal(moment([2011, 0, 22]).format('DDDo'), 'ທີ່22', 'ທີ່22');
  17757. assert.equal(moment([2011, 0, 23]).format('DDDo'), 'ທີ່23', 'ທີ່23');
  17758. assert.equal(moment([2011, 0, 24]).format('DDDo'), 'ທີ່24', 'ທີ່24');
  17759. assert.equal(moment([2011, 0, 25]).format('DDDo'), 'ທີ່25', 'ທີ່25');
  17760. assert.equal(moment([2011, 0, 26]).format('DDDo'), 'ທີ່26', 'ທີ່26');
  17761. assert.equal(moment([2011, 0, 27]).format('DDDo'), 'ທີ່27', 'ທີ່27');
  17762. assert.equal(moment([2011, 0, 28]).format('DDDo'), 'ທີ່28', 'ທີ່28');
  17763. assert.equal(moment([2011, 0, 29]).format('DDDo'), 'ທີ່29', 'ທີ່29');
  17764. assert.equal(moment([2011, 0, 30]).format('DDDo'), 'ທີ່30', 'ທີ່30');
  17765. assert.equal(moment([2011, 0, 31]).format('DDDo'), 'ທີ່31', 'ທີ່31');
  17766. });
  17767. test('format month', function (assert) {
  17768. var expected = 'ມັງກອນ ມັງກອນ_ກຸມພາ ກຸມພາ_ມີນາ ມີນາ_ເມສາ ເມສາ_ພຶດສະພາ ພຶດສະພາ_ມິຖຸນາ ມິຖຸນາ_ກໍລະກົດ ກໍລະກົດ_ສິງຫາ ສິງຫາ_ກັນຍາ ກັນຍາ_ຕຸລາ ຕຸລາ_ພະຈິກ ພະຈິກ_ທັນວາ ທັນວາ'.split('_'), i;
  17769. for (i = 0; i < expected.length; i++) {
  17770. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  17771. }
  17772. });
  17773. test('format week', function (assert) {
  17774. var expected = 'ອາທິດ ທິດ ທ_ຈັນ ຈັນ ຈ_ອັງຄານ ອັງຄານ ອຄ_ພຸດ ພຸດ ພ_ພະຫັດ ພະຫັດ ພຫ_ສຸກ ສຸກ ສກ_ເສົາ ເສົາ ສ'.split('_'), i;
  17775. for (i = 0; i < expected.length; i++) {
  17776. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  17777. }
  17778. });
  17779. test('from', function (assert) {
  17780. var start = moment([2007, 1, 28]);
  17781. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ບໍ່ເທົ່າໃດວິນາທີ', '44 seconds = a few seconds');
  17782. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), '1 ນາທີ', '45 seconds = a minute');
  17783. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), '1 ນາທີ', '89 seconds = a minute');
  17784. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 ນາທີ', '90 seconds = 2 minutes');
  17785. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 ນາທີ', '44 minutes = 44 minutes');
  17786. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), '1 ຊົ່ວໂມງ', '45 minutes = an hour');
  17787. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), '1 ຊົ່ວໂມງ', '89 minutes = an hour');
  17788. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 ຊົ່ວໂມງ', '90 minutes = 2 hours');
  17789. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ຊົ່ວໂມງ', '5 hours = 5 hours');
  17790. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 ຊົ່ວໂມງ', '21 hours = 21 hours');
  17791. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), '1 ມື້', '22 hours = a day');
  17792. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), '1 ມື້', '35 hours = a day');
  17793. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 ມື້', '36 hours = 2 days');
  17794. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), '1 ມື້', '1 day = a day');
  17795. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 ມື້', '5 days = 5 days');
  17796. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 ມື້', '25 days = 25 days');
  17797. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), '1 ເດືອນ', '26 days = a month');
  17798. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), '1 ເດືອນ', '30 days = a month');
  17799. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), '1 ເດືອນ', '43 days = a month');
  17800. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 ເດືອນ', '46 days = 2 months');
  17801. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 ເດືອນ', '75 days = 2 months');
  17802. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 ເດືອນ', '76 days = 3 months');
  17803. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), '1 ເດືອນ', '1 month = a month');
  17804. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 ເດືອນ', '5 months = 5 months');
  17805. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), '1 ປີ', '345 days = a year');
  17806. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 ປີ', '548 days = 2 years');
  17807. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), '1 ປີ', '1 year = a year');
  17808. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 ປີ', '5 years = 5 years');
  17809. });
  17810. test('suffix', function (assert) {
  17811. assert.equal(moment(30000).from(0), 'ອີກ ບໍ່ເທົ່າໃດວິນາທີ', 'prefix');
  17812. assert.equal(moment(0).from(30000), 'ບໍ່ເທົ່າໃດວິນາທີຜ່ານມາ', 'suffix');
  17813. });
  17814. test('now from now', function (assert) {
  17815. assert.equal(moment().fromNow(), 'ບໍ່ເທົ່າໃດວິນາທີຜ່ານມາ', 'now from now should display as in the past');
  17816. });
  17817. test('fromNow', function (assert) {
  17818. assert.equal(moment().add({s: 30}).fromNow(), 'ອີກ ບໍ່ເທົ່າໃດວິນາທີ', 'in a few seconds');
  17819. assert.equal(moment().add({d: 5}).fromNow(), 'ອີກ 5 ມື້', 'in 5 days');
  17820. });
  17821. test('calendar day', function (assert) {
  17822. var a = moment().hours(2).minutes(0).seconds(0);
  17823. assert.equal(moment(a).calendar(), 'ມື້ນີ້ເວລາ 02:00', 'today at the same time');
  17824. assert.equal(moment(a).add({m: 25}).calendar(), 'ມື້ນີ້ເວລາ 02:25', 'Now plus 25 min');
  17825. assert.equal(moment(a).add({h: 1}).calendar(), 'ມື້ນີ້ເວລາ 03:00', 'Now plus 1 hour');
  17826. assert.equal(moment(a).add({d: 1}).calendar(), 'ມື້ອື່ນເວລາ 02:00', 'tomorrow at the same time');
  17827. assert.equal(moment(a).subtract({h: 1}).calendar(), 'ມື້ນີ້ເວລາ 01:00', 'Now minus 1 hour');
  17828. assert.equal(moment(a).subtract({d: 1}).calendar(), 'ມື້ວານນີ້ເວລາ 02:00', 'yesterday at the same time');
  17829. });
  17830. test('calendar next week', function (assert) {
  17831. var i, m;
  17832. for (i = 2; i < 7; i++) {
  17833. m = moment().add({d: i});
  17834. assert.equal(m.calendar(), m.format('[ວັນ]dddd[ໜ້າເວລາ] LT'), 'Today + ' + i + ' days current time');
  17835. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  17836. assert.equal(m.calendar(), m.format('[ວັນ]dddd[ໜ້າເວລາ] LT'), 'Today + ' + i + ' days beginning of day');
  17837. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  17838. assert.equal(m.calendar(), m.format('[ວັນ]dddd[ໜ້າເວລາ] LT'), 'Today + ' + i + ' days end of day');
  17839. }
  17840. });
  17841. test('calendar last week', function (assert) {
  17842. var i, m;
  17843. for (i = 2; i < 7; i++) {
  17844. m = moment().subtract({d: i});
  17845. assert.equal(m.calendar(), m.format('[ວັນ]dddd[ແລ້ວນີ້ເວລາ] LT'), 'Today - ' + i + ' days current time');
  17846. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  17847. assert.equal(m.calendar(), m.format('[ວັນ]dddd[ແລ້ວນີ້ເວລາ] LT'), 'Today - ' + i + ' days beginning of day');
  17848. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  17849. assert.equal(m.calendar(), m.format('[ວັນ]dddd[ແລ້ວນີ້ເວລາ] LT'), 'Today - ' + i + ' days end of day');
  17850. }
  17851. });
  17852. test('calendar all else', function (assert) {
  17853. var weeksAgo = moment().subtract({w: 1}),
  17854. weeksFromNow = moment().add({w: 1});
  17855. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  17856. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  17857. weeksAgo = moment().subtract({w: 2});
  17858. weeksFromNow = moment().add({w: 2});
  17859. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  17860. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  17861. });
  17862. test('weeks year starting sunday', function (assert) {
  17863. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  17864. assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1');
  17865. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  17866. assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2');
  17867. assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 3');
  17868. });
  17869. test('weeks year starting monday', function (assert) {
  17870. assert.equal(moment([2006, 11, 31]).week(), 1, 'Dec 31 2006 should be week 1');
  17871. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  17872. assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1');
  17873. assert.equal(moment([2007, 0, 7]).week(), 2, 'Jan 7 2007 should be week 2');
  17874. assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2');
  17875. assert.equal(moment([2007, 0, 14]).week(), 3, 'Jan 14 2007 should be week 3');
  17876. });
  17877. test('weeks year starting tuesday', function (assert) {
  17878. assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52');
  17879. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  17880. assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1');
  17881. assert.equal(moment([2008, 0, 6]).week(), 2, 'Jan 6 2008 should be week 2');
  17882. assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2');
  17883. assert.equal(moment([2008, 0, 13]).week(), 3, 'Jan 13 2008 should be week 3');
  17884. });
  17885. test('weeks year starting wednesday', function (assert) {
  17886. assert.equal(moment([2002, 11, 29]).week(), 1, 'Dec 29 2002 should be week 1');
  17887. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  17888. assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1');
  17889. assert.equal(moment([2003, 0, 5]).week(), 2, 'Jan 5 2003 should be week 2');
  17890. assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2');
  17891. assert.equal(moment([2003, 0, 12]).week(), 3, 'Jan 12 2003 should be week 3');
  17892. });
  17893. test('weeks year starting thursday', function (assert) {
  17894. assert.equal(moment([2008, 11, 28]).week(), 1, 'Dec 28 2008 should be week 1');
  17895. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  17896. assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1');
  17897. assert.equal(moment([2009, 0, 4]).week(), 2, 'Jan 4 2009 should be week 2');
  17898. assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2');
  17899. assert.equal(moment([2009, 0, 11]).week(), 3, 'Jan 11 2009 should be week 3');
  17900. });
  17901. test('weeks year starting friday', function (assert) {
  17902. assert.equal(moment([2009, 11, 27]).week(), 1, 'Dec 27 2009 should be week 1');
  17903. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  17904. assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 should be week 1');
  17905. assert.equal(moment([2010, 0, 3]).week(), 2, 'Jan 3 2010 should be week 2');
  17906. assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 should be week 2');
  17907. assert.equal(moment([2010, 0, 10]).week(), 3, 'Jan 10 2010 should be week 3');
  17908. });
  17909. test('weeks year starting saturday', function (assert) {
  17910. assert.equal(moment([2010, 11, 26]).week(), 1, 'Dec 26 2010 should be week 1');
  17911. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  17912. assert.equal(moment([2011, 0, 2]).week(), 2, 'Jan 2 2011 should be week 2');
  17913. assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2');
  17914. assert.equal(moment([2011, 0, 9]).week(), 3, 'Jan 9 2011 should be week 3');
  17915. });
  17916. test('weeks year starting sunday format', function (assert) {
  17917. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 ທີ່1', 'Jan 1 2012 should be week 1');
  17918. assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 ທີ່1', 'Jan 7 2012 should be week 1');
  17919. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 ທີ່2', 'Jan 8 2012 should be week 2');
  17920. assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 ທີ່2', 'Jan 14 2012 should be week 2');
  17921. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 ທີ່3', 'Jan 15 2012 should be week 3');
  17922. });
  17923. test('lenient ordinal parsing', function (assert) {
  17924. var i, ordinalStr, testMoment;
  17925. for (i = 1; i <= 31; ++i) {
  17926. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  17927. testMoment = moment(ordinalStr, 'YYYY MM Do');
  17928. assert.equal(testMoment.year(), 2014,
  17929. 'lenient ordinal parsing ' + i + ' year check');
  17930. assert.equal(testMoment.month(), 0,
  17931. 'lenient ordinal parsing ' + i + ' month check');
  17932. assert.equal(testMoment.date(), i,
  17933. 'lenient ordinal parsing ' + i + ' date check');
  17934. }
  17935. });
  17936. test('lenient ordinal parsing of number', function (assert) {
  17937. var i, testMoment;
  17938. for (i = 1; i <= 31; ++i) {
  17939. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  17940. assert.equal(testMoment.year(), 2014,
  17941. 'lenient ordinal parsing of number ' + i + ' year check');
  17942. assert.equal(testMoment.month(), 0,
  17943. 'lenient ordinal parsing of number ' + i + ' month check');
  17944. assert.equal(testMoment.date(), i,
  17945. 'lenient ordinal parsing of number ' + i + ' date check');
  17946. }
  17947. });
  17948. test('strict ordinal parsing', function (assert) {
  17949. var i, ordinalStr, testMoment;
  17950. for (i = 1; i <= 31; ++i) {
  17951. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  17952. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  17953. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  17954. }
  17955. });
  17956. }));
  17957. ;(function (global, factory) {
  17958. typeof exports === 'object' && typeof module !== 'undefined'
  17959. && typeof require === 'function' ? factory(require('../../moment')) :
  17960. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  17961. factory(global.moment)
  17962. }(this, function (moment) { 'use strict';
  17963. /*global QUnit:false*/
  17964. var test = QUnit.test;
  17965. var expect = QUnit.expect;
  17966. function module (name, lifecycle) {
  17967. QUnit.module(name, {
  17968. setup : function () {
  17969. moment.locale('en');
  17970. moment.createFromInputFallback = function (config) {
  17971. throw new Error('input not handled by moment: ' + config._i);
  17972. };
  17973. if (lifecycle && lifecycle.setup) {
  17974. lifecycle.setup();
  17975. }
  17976. },
  17977. teardown : function () {
  17978. if (lifecycle && lifecycle.teardown) {
  17979. lifecycle.teardown();
  17980. }
  17981. }
  17982. });
  17983. }
  17984. function localeModule (name, lifecycle) {
  17985. QUnit.module('locale:' + name, {
  17986. setup : function () {
  17987. moment.locale(name);
  17988. moment.createFromInputFallback = function (config) {
  17989. throw new Error('input not handled by moment: ' + config._i);
  17990. };
  17991. if (lifecycle && lifecycle.setup) {
  17992. lifecycle.setup();
  17993. }
  17994. },
  17995. teardown : function () {
  17996. moment.locale('en');
  17997. if (lifecycle && lifecycle.teardown) {
  17998. lifecycle.teardown();
  17999. }
  18000. }
  18001. });
  18002. }
  18003. localeModule('lt');
  18004. test('parse', function (assert) {
  18005. var tests = 'sausis sau_vasaris vas_kovas kov_balandis bal_gegužė geg_birželis bir_liepa lie_rugpjūtis rgp_rugsėjis rgs_spalis spa_lapkritis lap_gruodis grd'.split('_'), i;
  18006. function equalTest(input, mmm, i) {
  18007. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  18008. }
  18009. for (i = 0; i < 12; i++) {
  18010. tests[i] = tests[i].split(' ');
  18011. equalTest(tests[i][0], 'MMM', i);
  18012. equalTest(tests[i][1], 'MMM', i);
  18013. equalTest(tests[i][0], 'MMMM', i);
  18014. equalTest(tests[i][1], 'MMMM', i);
  18015. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  18016. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  18017. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  18018. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  18019. }
  18020. });
  18021. test('format', function (assert) {
  18022. var a = [
  18023. ['dddd, Do MMMM YYYY, h:mm:ss a', 'sekmadienis, 14-oji vasario 2010, 3:25:50 pm'],
  18024. ['ddd, hA', 'Sek, 3PM'],
  18025. ['M Mo MM MMMM MMM', '2 2-oji 02 vasaris vas'],
  18026. ['YYYY YY', '2010 10'],
  18027. ['D Do DD', '14 14-oji 14'],
  18028. ['d do dddd ddd dd', '0 0-oji sekmadienis Sek S'],
  18029. ['DDD DDDo DDDD', '45 45-oji 045'],
  18030. ['w wo ww', '6 6-oji 06'],
  18031. ['h hh', '3 03'],
  18032. ['H HH', '15 15'],
  18033. ['m mm', '25 25'],
  18034. ['s ss', '50 50'],
  18035. ['a A', 'pm PM'],
  18036. ['DDDo [metų diena]', '45-oji metų diena'],
  18037. ['LTS', '15:25:50'],
  18038. ['L', '2010-02-14'],
  18039. ['LL', '2010 m. vasaris 14 d.'],
  18040. ['LLL', '2010 m. vasaris 14 d., 15:25 val.'],
  18041. ['LLLL', '2010 m. vasaris 14 d., sekmadienis, 15:25 val.'],
  18042. ['l', '2010-02-14'],
  18043. ['ll', '2010 m. vasaris 14 d.'],
  18044. ['lll', '2010 m. vasaris 14 d., 15:25 val.'],
  18045. ['llll', '2010 m. vasaris 14 d., Sek, 15:25 val.']
  18046. ],
  18047. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  18048. i;
  18049. for (i = 0; i < a.length; i++) {
  18050. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  18051. }
  18052. });
  18053. test('format ordinal', function (assert) {
  18054. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1-oji', '1-oji');
  18055. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2-oji', '2-oji');
  18056. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3-oji', '3-oji');
  18057. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4-oji', '4-oji');
  18058. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5-oji', '5-oji');
  18059. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6-oji', '6-oji');
  18060. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7-oji', '7-oji');
  18061. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8-oji', '8-oji');
  18062. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9-oji', '9-oji');
  18063. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10-oji', '10-oji');
  18064. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11-oji', '11-oji');
  18065. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12-oji', '12-oji');
  18066. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13-oji', '13-oji');
  18067. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14-oji', '14-oji');
  18068. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15-oji', '15-oji');
  18069. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16-oji', '16-oji');
  18070. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17-oji', '17-oji');
  18071. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18-oji', '18-oji');
  18072. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19-oji', '19-oji');
  18073. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20-oji', '20-oji');
  18074. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21-oji', '21-oji');
  18075. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22-oji', '22-oji');
  18076. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23-oji', '23-oji');
  18077. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24-oji', '24-oji');
  18078. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25-oji', '25-oji');
  18079. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26-oji', '26-oji');
  18080. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27-oji', '27-oji');
  18081. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28-oji', '28-oji');
  18082. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29-oji', '29-oji');
  18083. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30-oji', '30-oji');
  18084. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31-oji', '31-oji');
  18085. });
  18086. test('format month', function (assert) {
  18087. var expected = 'sausis sau_vasaris vas_kovas kov_balandis bal_gegužė geg_birželis bir_liepa lie_rugpjūtis rgp_rugsėjis rgs_spalis spa_lapkritis lap_gruodis grd'.split('_'), i;
  18088. for (i = 0; i < expected.length; i++) {
  18089. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  18090. }
  18091. });
  18092. test('format week', function (assert) {
  18093. var expected = 'sekmadienis Sek S_pirmadienis Pir P_antradienis Ant A_trečiadienis Tre T_ketvirtadienis Ket K_penktadienis Pen Pn_šeštadienis Šeš Š'.split('_'), i;
  18094. for (i = 0; i < expected.length; i++) {
  18095. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  18096. }
  18097. });
  18098. test('format week on US calendar', function (assert) {
  18099. // Tests, whether the weekday names are correct, even if the week does not start on Monday
  18100. moment.locale('lt', {week: {dow: 0, doy: 6}});
  18101. var expected = 'sekmadienis Sek S_pirmadienis Pir P_antradienis Ant A_trečiadienis Tre T_ketvirtadienis Ket K_penktadienis Pen Pn_šeštadienis Šeš Š'.split('_'), i;
  18102. for (i = 0; i < expected.length; i++) {
  18103. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  18104. }
  18105. moment.locale('lt', {week: {dow: 1, doy: 4}});
  18106. });
  18107. test('from', function (assert) {
  18108. var start = moment([2007, 1, 28]);
  18109. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'kelios sekundės', '44 seconds = seconds');
  18110. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'minutė', '45 seconds = a minute');
  18111. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'minutė', '89 seconds = a minute');
  18112. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutės', '90 seconds = 2 minutes');
  18113. assert.equal(start.from(moment([2007, 1, 28]).add({m: 10}), true), '10 minučių', '10 minutes = 10 minutes');
  18114. assert.equal(start.from(moment([2007, 1, 28]).add({m: 11}), true), '11 minučių', '11 minutes = 11 minutes');
  18115. assert.equal(start.from(moment([2007, 1, 28]).add({m: 19}), true), '19 minučių', '19 minutes = 19 minutes');
  18116. assert.equal(start.from(moment([2007, 1, 28]).add({m: 20}), true), '20 minučių', '20 minutes = 20 minutes');
  18117. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutės', '44 minutes = 44 minutes');
  18118. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'valanda', '45 minutes = an hour');
  18119. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'valanda', '89 minutes = an hour');
  18120. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 valandos', '90 minutes = 2 hours');
  18121. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 valandos', '5 hours = 5 hours');
  18122. assert.equal(start.from(moment([2007, 1, 28]).add({h: 10}), true), '10 valandų', '10 hours = 10 hours');
  18123. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 valandos', '21 hours = 21 hours');
  18124. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'diena', '22 hours = a day');
  18125. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'diena', '35 hours = a day');
  18126. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dienos', '36 hours = 2 days');
  18127. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'diena', '1 day = a day');
  18128. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dienos', '5 days = 5 days');
  18129. assert.equal(start.from(moment([2007, 1, 28]).add({d: 10}), true), '10 dienų', '10 days = 10 days');
  18130. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dienos', '25 days = 25 days');
  18131. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'mėnuo', '26 days = a month');
  18132. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'mėnuo', '30 days = a month');
  18133. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'mėnuo', '43 days = a month');
  18134. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mėnesiai', '46 days = 2 months');
  18135. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mėnesiai', '75 days = 2 months');
  18136. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mėnesiai', '76 days = 3 months');
  18137. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'mėnuo', '1 month = a month');
  18138. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mėnesiai', '5 months = 5 months');
  18139. assert.equal(start.from(moment([2007, 1, 28]).add({M: 10}), true), '10 mėnesių', '10 months = 10 months');
  18140. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'metai', '345 days = a year');
  18141. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 metai', '548 days = 2 years');
  18142. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'metai', '1 year = a year');
  18143. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 metai', '5 years = 5 years');
  18144. });
  18145. test('suffix', function (assert) {
  18146. assert.equal(moment(30000).from(0), 'po kelių sekundžių', 'prefix');
  18147. assert.equal(moment(0).from(30000), 'prieš kelias sekundes', 'suffix');
  18148. });
  18149. test('now from now', function (assert) {
  18150. assert.equal(moment().fromNow(), 'prieš kelias sekundes', 'now from now should display as in the past');
  18151. });
  18152. test('fromNow', function (assert) {
  18153. assert.equal(moment().add({s: 30}).fromNow(), 'po kelių sekundžių', 'in seconds');
  18154. assert.equal(moment().add({d: 5}).fromNow(), 'po 5 dienų', 'in 5 days');
  18155. });
  18156. test('calendar day', function (assert) {
  18157. var a = moment().hours(2).minutes(0).seconds(0);
  18158. assert.equal(moment(a).calendar(), 'Šiandien 02:00', 'today at the same time');
  18159. assert.equal(moment(a).add({m: 25}).calendar(), 'Šiandien 02:25', 'Now plus 25 min');
  18160. assert.equal(moment(a).add({h: 1}).calendar(), 'Šiandien 03:00', 'Now plus 1 hour');
  18161. assert.equal(moment(a).add({d: 1}).calendar(), 'Rytoj 02:00', 'tomorrow at the same time');
  18162. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Šiandien 01:00', 'Now minus 1 hour');
  18163. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Vakar 02:00', 'yesterday at the same time');
  18164. });
  18165. test('calendar next week', function (assert) {
  18166. var i, m;
  18167. for (i = 2; i < 7; i++) {
  18168. m = moment().add({d: i});
  18169. assert.equal(m.calendar(), m.format('dddd LT'), 'Today + ' + i + ' days current time');
  18170. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  18171. assert.equal(m.calendar(), m.format('dddd LT'), 'Today + ' + i + ' days beginning of day');
  18172. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  18173. assert.equal(m.calendar(), m.format('dddd LT'), 'Today + ' + i + ' days end of day');
  18174. }
  18175. });
  18176. test('calendar last week', function (assert) {
  18177. var i, m;
  18178. for (i = 2; i < 7; i++) {
  18179. m = moment().subtract({d: i});
  18180. assert.equal(m.calendar(), m.format('[Praėjusį] dddd LT'), 'Today - ' + i + ' days current time');
  18181. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  18182. assert.equal(m.calendar(), m.format('[Praėjusį] dddd LT'), 'Today - ' + i + ' days beginning of day');
  18183. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  18184. assert.equal(m.calendar(), m.format('[Praėjusį] dddd LT'), 'Today - ' + i + ' days end of day');
  18185. }
  18186. });
  18187. test('calendar all else', function (assert) {
  18188. var weeksAgo = moment().subtract({w: 1}),
  18189. weeksFromNow = moment().add({w: 1});
  18190. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  18191. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  18192. weeksAgo = moment().subtract({w: 2});
  18193. weeksFromNow = moment().add({w: 2});
  18194. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  18195. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  18196. });
  18197. test('weeks year starting sunday', function (assert) {
  18198. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  18199. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  18200. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  18201. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  18202. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  18203. });
  18204. test('weeks year starting monday', function (assert) {
  18205. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  18206. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  18207. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  18208. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  18209. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  18210. });
  18211. test('weeks year starting tuesday', function (assert) {
  18212. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  18213. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  18214. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  18215. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  18216. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  18217. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  18218. });
  18219. test('weeks year starting wednesday', function (assert) {
  18220. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  18221. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  18222. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  18223. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  18224. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  18225. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  18226. });
  18227. test('weeks year starting thursday', function (assert) {
  18228. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  18229. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  18230. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  18231. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  18232. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  18233. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  18234. });
  18235. test('weeks year starting friday', function (assert) {
  18236. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  18237. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  18238. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  18239. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  18240. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  18241. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  18242. });
  18243. test('weeks year starting saturday', function (assert) {
  18244. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  18245. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  18246. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  18247. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  18248. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  18249. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  18250. });
  18251. test('weeks year starting sunday formatted', function (assert) {
  18252. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52-oji', 'Jan 1 2012 should be week 52');
  18253. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1-oji', 'Jan 2 2012 should be week 1');
  18254. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1-oji', 'Jan 8 2012 should be week 1');
  18255. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2-oji', 'Jan 9 2012 should be week 2');
  18256. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2-oji', 'Jan 15 2012 should be week 2');
  18257. });
  18258. test('lenient ordinal parsing', function (assert) {
  18259. var i, ordinalStr, testMoment;
  18260. for (i = 1; i <= 31; ++i) {
  18261. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  18262. testMoment = moment(ordinalStr, 'YYYY MM Do');
  18263. assert.equal(testMoment.year(), 2014,
  18264. 'lenient ordinal parsing ' + i + ' year check');
  18265. assert.equal(testMoment.month(), 0,
  18266. 'lenient ordinal parsing ' + i + ' month check');
  18267. assert.equal(testMoment.date(), i,
  18268. 'lenient ordinal parsing ' + i + ' date check');
  18269. }
  18270. });
  18271. test('lenient ordinal parsing of number', function (assert) {
  18272. var i, testMoment;
  18273. for (i = 1; i <= 31; ++i) {
  18274. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  18275. assert.equal(testMoment.year(), 2014,
  18276. 'lenient ordinal parsing of number ' + i + ' year check');
  18277. assert.equal(testMoment.month(), 0,
  18278. 'lenient ordinal parsing of number ' + i + ' month check');
  18279. assert.equal(testMoment.date(), i,
  18280. 'lenient ordinal parsing of number ' + i + ' date check');
  18281. }
  18282. });
  18283. test('strict ordinal parsing', function (assert) {
  18284. var i, ordinalStr, testMoment;
  18285. for (i = 1; i <= 31; ++i) {
  18286. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  18287. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  18288. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  18289. }
  18290. });
  18291. }));
  18292. ;(function (global, factory) {
  18293. typeof exports === 'object' && typeof module !== 'undefined'
  18294. && typeof require === 'function' ? factory(require('../../moment')) :
  18295. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  18296. factory(global.moment)
  18297. }(this, function (moment) { 'use strict';
  18298. /*global QUnit:false*/
  18299. var test = QUnit.test;
  18300. var expect = QUnit.expect;
  18301. function module (name, lifecycle) {
  18302. QUnit.module(name, {
  18303. setup : function () {
  18304. moment.locale('en');
  18305. moment.createFromInputFallback = function (config) {
  18306. throw new Error('input not handled by moment: ' + config._i);
  18307. };
  18308. if (lifecycle && lifecycle.setup) {
  18309. lifecycle.setup();
  18310. }
  18311. },
  18312. teardown : function () {
  18313. if (lifecycle && lifecycle.teardown) {
  18314. lifecycle.teardown();
  18315. }
  18316. }
  18317. });
  18318. }
  18319. function localeModule (name, lifecycle) {
  18320. QUnit.module('locale:' + name, {
  18321. setup : function () {
  18322. moment.locale(name);
  18323. moment.createFromInputFallback = function (config) {
  18324. throw new Error('input not handled by moment: ' + config._i);
  18325. };
  18326. if (lifecycle && lifecycle.setup) {
  18327. lifecycle.setup();
  18328. }
  18329. },
  18330. teardown : function () {
  18331. moment.locale('en');
  18332. if (lifecycle && lifecycle.teardown) {
  18333. lifecycle.teardown();
  18334. }
  18335. }
  18336. });
  18337. }
  18338. localeModule('lv');
  18339. test('parse', function (assert) {
  18340. var tests = 'janvāris jan_februāris feb_marts mar_aprīlis apr_maijs mai_jūnijs jūn_jūlijs jūl_augusts aug_septembris sep_oktobris okt_novembris nov_decembris dec'.split('_'), i;
  18341. function equalTest(input, mmm, i) {
  18342. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  18343. }
  18344. for (i = 0; i < 12; i++) {
  18345. tests[i] = tests[i].split(' ');
  18346. equalTest(tests[i][0], 'MMM', i);
  18347. equalTest(tests[i][1], 'MMM', i);
  18348. equalTest(tests[i][0], 'MMMM', i);
  18349. equalTest(tests[i][1], 'MMMM', i);
  18350. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  18351. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  18352. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  18353. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  18354. }
  18355. });
  18356. test('format', function (assert) {
  18357. var a = [
  18358. ['dddd, Do MMMM YYYY, h:mm:ss a', 'svētdiena, 14. februāris 2010, 3:25:50 pm'],
  18359. ['ddd, hA', 'Sv, 3PM'],
  18360. ['M Mo MM MMMM MMM', '2 2. 02 februāris feb'],
  18361. ['YYYY YY', '2010 10'],
  18362. ['D Do DD', '14 14. 14'],
  18363. ['d do dddd ddd dd', '0 0. svētdiena Sv Sv'],
  18364. ['DDD DDDo DDDD', '45 45. 045'],
  18365. ['w wo ww', '6 6. 06'],
  18366. ['h hh', '3 03'],
  18367. ['H HH', '15 15'],
  18368. ['m mm', '25 25'],
  18369. ['s ss', '50 50'],
  18370. ['a A', 'pm PM'],
  18371. ['[the] DDDo [day of the year]', 'the 45. day of the year'],
  18372. ['LTS', '15:25:50'],
  18373. ['L', '14.02.2010.'],
  18374. ['LL', '2010. gada 14. februāris'],
  18375. ['LLL', '2010. gada 14. februāris, 15:25'],
  18376. ['LLLL', '2010. gada 14. februāris, svētdiena, 15:25'],
  18377. ['l', '14.2.2010.'],
  18378. ['ll', '2010. gada 14. feb'],
  18379. ['lll', '2010. gada 14. feb, 15:25'],
  18380. ['llll', '2010. gada 14. feb, Sv, 15:25']
  18381. ],
  18382. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  18383. i;
  18384. for (i = 0; i < a.length; i++) {
  18385. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  18386. }
  18387. });
  18388. test('format ordinal', function (assert) {
  18389. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
  18390. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
  18391. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
  18392. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
  18393. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
  18394. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
  18395. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
  18396. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
  18397. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
  18398. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
  18399. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
  18400. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
  18401. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
  18402. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
  18403. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
  18404. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
  18405. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
  18406. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
  18407. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
  18408. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
  18409. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
  18410. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
  18411. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
  18412. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
  18413. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
  18414. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
  18415. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
  18416. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
  18417. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
  18418. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
  18419. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
  18420. });
  18421. test('format month', function (assert) {
  18422. var expected = 'janvāris jan_februāris feb_marts mar_aprīlis apr_maijs mai_jūnijs jūn_jūlijs jūl_augusts aug_septembris sep_oktobris okt_novembris nov_decembris dec'.split('_'), i;
  18423. for (i = 0; i < expected.length; i++) {
  18424. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  18425. }
  18426. });
  18427. test('format week', function (assert) {
  18428. var expected = 'svētdiena Sv Sv_pirmdiena P P_otrdiena O O_trešdiena T T_ceturtdiena C C_piektdiena Pk Pk_sestdiena S S'.split('_'), i;
  18429. for (i = 0; i < expected.length; i++) {
  18430. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  18431. }
  18432. });
  18433. // Includes testing the cases of withoutSuffix = true and false.
  18434. test('from', function (assert) {
  18435. var start = moment([2007, 1, 28]);
  18436. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'dažas sekundes', '44 seconds = seconds');
  18437. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), false), 'pirms dažām sekundēm', '44 seconds with suffix = seconds ago');
  18438. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'minūte', '45 seconds = a minute');
  18439. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), false), 'pirms minūtes', '45 seconds with suffix = a minute ago');
  18440. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'minūte', '89 seconds = a minute');
  18441. assert.equal(start.from(moment([2007, 1, 28]).add({s: -89}), false), 'pēc minūtes', '89 seconds with suffix/prefix = in a minute');
  18442. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minūtes', '90 seconds = 2 minutes');
  18443. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), false), 'pirms 2 minūtēm', '90 seconds with suffix = 2 minutes ago');
  18444. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minūtes', '44 minutes = 44 minutes');
  18445. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), false), 'pirms 44 minūtēm', '44 minutes with suffix = 44 minutes ago');
  18446. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'stunda', '45 minutes = an hour');
  18447. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), false), 'pirms stundas', '45 minutes with suffix = an hour ago');
  18448. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'stunda', '89 minutes = an hour');
  18449. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 stundas', '90 minutes = 2 hours');
  18450. assert.equal(start.from(moment([2007, 1, 28]).add({m: -90}), false), 'pēc 2 stundām', '90 minutes with suffix = in 2 hours');
  18451. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 stundas', '5 hours = 5 hours');
  18452. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), false), 'pirms 5 stundām', '5 hours with suffix = 5 hours ago');
  18453. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 stunda', '21 hours = 21 hours');
  18454. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), false), 'pirms 21 stundas', '21 hours with suffix = 21 hours ago');
  18455. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'diena', '22 hours = a day');
  18456. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), false), 'pirms dienas', '22 hours with suffix = a day ago');
  18457. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'diena', '35 hours = a day');
  18458. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dienas', '36 hours = 2 days');
  18459. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), false), 'pirms 2 dienām', '36 hours with suffix = 2 days ago');
  18460. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'diena', '1 day = a day');
  18461. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dienas', '5 days = 5 days');
  18462. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), false), 'pirms 5 dienām', '5 days with suffix = 5 days ago');
  18463. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dienas', '25 days = 25 days');
  18464. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), false), 'pirms 25 dienām', '25 days with suffix = 25 days ago');
  18465. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'mēnesis', '26 days = a month');
  18466. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), false), 'pirms mēneša', '26 days with suffix = a month ago');
  18467. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'mēnesis', '30 days = a month');
  18468. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'mēnesis', '43 days = a month');
  18469. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mēneši', '46 days = 2 months');
  18470. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), false), 'pirms 2 mēnešiem', '46 days with suffix = 2 months ago');
  18471. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mēneši', '75 days = 2 months');
  18472. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mēneši', '76 days = 3 months');
  18473. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), false), 'pirms 3 mēnešiem', '76 days with suffix = 3 months ago');
  18474. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'mēnesis', '1 month = a month');
  18475. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mēneši', '5 months = 5 months');
  18476. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), false), 'pirms 5 mēnešiem', '5 months with suffix = 5 months ago');
  18477. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'gads', '345 days = a year');
  18478. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), false), 'pirms gada', '345 days with suffix = a year ago');
  18479. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 gadi', '548 days = 2 years');
  18480. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), false), 'pirms 2 gadiem', '548 days with suffix = 2 years ago');
  18481. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'gads', '1 year = a year');
  18482. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 gadi', '5 years = 5 years');
  18483. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), false), 'pirms 5 gadiem', '5 years with suffix = 5 years ago');
  18484. });
  18485. test('suffix', function (assert) {
  18486. assert.equal(moment(30000).from(0), 'pēc dažām sekundēm', 'prefix');
  18487. assert.equal(moment(0).from(30000), 'pirms dažām sekundēm', 'suffix');
  18488. });
  18489. test('now from now', function (assert) {
  18490. assert.equal(moment().fromNow(), 'pirms dažām sekundēm', 'now from now should display as in the past');
  18491. });
  18492. test('fromNow', function (assert) {
  18493. assert.equal(moment().add({s: 30}).fromNow(), 'pēc dažām sekundēm', 'in seconds');
  18494. assert.equal(moment().add({d: 5}).fromNow(), 'pēc 5 dienām', 'in 5 days');
  18495. });
  18496. test('calendar day', function (assert) {
  18497. var a = moment().hours(2).minutes(0).seconds(0);
  18498. assert.equal(moment(a).calendar(), 'Šodien pulksten 02:00', 'today at the same time');
  18499. assert.equal(moment(a).add({m: 25}).calendar(), 'Šodien pulksten 02:25', 'Now plus 25 min');
  18500. assert.equal(moment(a).add({h: 1}).calendar(), 'Šodien pulksten 03:00', 'Now plus 1 hour');
  18501. assert.equal(moment(a).add({d: 1}).calendar(), 'Rīt pulksten 02:00', 'tomorrow at the same time');
  18502. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Šodien pulksten 01:00', 'Now minus 1 hour');
  18503. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Vakar pulksten 02:00', 'yesterday at the same time');
  18504. });
  18505. test('calendar next week', function (assert) {
  18506. var i, m;
  18507. for (i = 2; i < 7; i++) {
  18508. m = moment().add({d: i});
  18509. assert.equal(m.calendar(), m.format('dddd [pulksten] LT'), 'Today + ' + i + ' days current time');
  18510. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  18511. assert.equal(m.calendar(), m.format('dddd [pulksten] LT'), 'Today + ' + i + ' days beginning of day');
  18512. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  18513. assert.equal(m.calendar(), m.format('dddd [pulksten] LT'), 'Today + ' + i + ' days end of day');
  18514. }
  18515. });
  18516. test('calendar last week', function (assert) {
  18517. var i, m;
  18518. for (i = 2; i < 7; i++) {
  18519. m = moment().subtract({d: i});
  18520. assert.equal(m.calendar(), m.format('[Pagājušā] dddd [pulksten] LT'), 'Today - ' + i + ' days current time');
  18521. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  18522. assert.equal(m.calendar(), m.format('[Pagājušā] dddd [pulksten] LT'), 'Today - ' + i + ' days beginning of day');
  18523. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  18524. assert.equal(m.calendar(), m.format('[Pagājušā] dddd [pulksten] LT'), 'Today - ' + i + ' days end of day');
  18525. }
  18526. });
  18527. test('calendar all else', function (assert) {
  18528. var weeksAgo = moment().subtract({w: 1}),
  18529. weeksFromNow = moment().add({w: 1});
  18530. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  18531. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  18532. weeksAgo = moment().subtract({w: 2});
  18533. weeksFromNow = moment().add({w: 2});
  18534. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  18535. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  18536. });
  18537. test('weeks year starting sunday', function (assert) {
  18538. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  18539. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  18540. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  18541. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  18542. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  18543. });
  18544. test('weeks year starting monday', function (assert) {
  18545. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  18546. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  18547. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  18548. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  18549. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  18550. });
  18551. test('weeks year starting tuesday', function (assert) {
  18552. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  18553. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  18554. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  18555. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  18556. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  18557. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  18558. });
  18559. test('weeks year starting wednesday', function (assert) {
  18560. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  18561. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  18562. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  18563. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  18564. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  18565. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  18566. });
  18567. test('weeks year starting thursday', function (assert) {
  18568. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  18569. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  18570. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  18571. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  18572. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  18573. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  18574. });
  18575. test('weeks year starting friday', function (assert) {
  18576. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  18577. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  18578. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  18579. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  18580. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  18581. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  18582. });
  18583. test('weeks year starting saturday', function (assert) {
  18584. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  18585. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  18586. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  18587. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  18588. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  18589. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  18590. });
  18591. test('weeks year starting sunday formatted', function (assert) {
  18592. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
  18593. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
  18594. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
  18595. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
  18596. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
  18597. });
  18598. test('lenient ordinal parsing', function (assert) {
  18599. var i, ordinalStr, testMoment;
  18600. for (i = 1; i <= 31; ++i) {
  18601. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  18602. testMoment = moment(ordinalStr, 'YYYY MM Do');
  18603. assert.equal(testMoment.year(), 2014,
  18604. 'lenient ordinal parsing ' + i + ' year check');
  18605. assert.equal(testMoment.month(), 0,
  18606. 'lenient ordinal parsing ' + i + ' month check');
  18607. assert.equal(testMoment.date(), i,
  18608. 'lenient ordinal parsing ' + i + ' date check');
  18609. }
  18610. });
  18611. test('lenient ordinal parsing of number', function (assert) {
  18612. var i, testMoment;
  18613. for (i = 1; i <= 31; ++i) {
  18614. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  18615. assert.equal(testMoment.year(), 2014,
  18616. 'lenient ordinal parsing of number ' + i + ' year check');
  18617. assert.equal(testMoment.month(), 0,
  18618. 'lenient ordinal parsing of number ' + i + ' month check');
  18619. assert.equal(testMoment.date(), i,
  18620. 'lenient ordinal parsing of number ' + i + ' date check');
  18621. }
  18622. });
  18623. test('strict ordinal parsing', function (assert) {
  18624. var i, ordinalStr, testMoment;
  18625. for (i = 1; i <= 31; ++i) {
  18626. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  18627. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  18628. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  18629. }
  18630. });
  18631. }));
  18632. ;(function (global, factory) {
  18633. typeof exports === 'object' && typeof module !== 'undefined'
  18634. && typeof require === 'function' ? factory(require('../../moment')) :
  18635. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  18636. factory(global.moment)
  18637. }(this, function (moment) { 'use strict';
  18638. /*global QUnit:false*/
  18639. var test = QUnit.test;
  18640. var expect = QUnit.expect;
  18641. function module (name, lifecycle) {
  18642. QUnit.module(name, {
  18643. setup : function () {
  18644. moment.locale('en');
  18645. moment.createFromInputFallback = function (config) {
  18646. throw new Error('input not handled by moment: ' + config._i);
  18647. };
  18648. if (lifecycle && lifecycle.setup) {
  18649. lifecycle.setup();
  18650. }
  18651. },
  18652. teardown : function () {
  18653. if (lifecycle && lifecycle.teardown) {
  18654. lifecycle.teardown();
  18655. }
  18656. }
  18657. });
  18658. }
  18659. function localeModule (name, lifecycle) {
  18660. QUnit.module('locale:' + name, {
  18661. setup : function () {
  18662. moment.locale(name);
  18663. moment.createFromInputFallback = function (config) {
  18664. throw new Error('input not handled by moment: ' + config._i);
  18665. };
  18666. if (lifecycle && lifecycle.setup) {
  18667. lifecycle.setup();
  18668. }
  18669. },
  18670. teardown : function () {
  18671. moment.locale('en');
  18672. if (lifecycle && lifecycle.teardown) {
  18673. lifecycle.teardown();
  18674. }
  18675. }
  18676. });
  18677. }
  18678. localeModule('me');
  18679. test('parse', function (assert) {
  18680. var tests = 'januar jan._februar feb._mart mar._april apr._maj maj_jun jun_jul jul_avgust avg._septembar sep._oktobar okt._novembar nov._decembar dec.'.split('_'),
  18681. i;
  18682. function equalTest(input, mmm, i) {
  18683. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  18684. }
  18685. for (i = 0; i < 12; i++) {
  18686. tests[i] = tests[i].split(' ');
  18687. equalTest(tests[i][0], 'MMM', i);
  18688. equalTest(tests[i][1], 'MMM', i);
  18689. equalTest(tests[i][0], 'MMMM', i);
  18690. equalTest(tests[i][1], 'MMMM', i);
  18691. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  18692. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  18693. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  18694. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  18695. }
  18696. });
  18697. test('format', function (assert) {
  18698. var a = [
  18699. ['dddd, Do MMMM YYYY, h:mm:ss a', 'nedjelja, 14. februar 2010, 3:25:50 pm'],
  18700. ['ddd, hA', 'ned., 3PM'],
  18701. ['M Mo MM MMMM MMM', '2 2. 02 februar feb.'],
  18702. ['YYYY YY', '2010 10'],
  18703. ['D Do DD', '14 14. 14'],
  18704. ['d do dddd ddd dd', '0 0. nedjelja ned. ne'],
  18705. ['DDD DDDo DDDD', '45 45. 045'],
  18706. ['w wo ww', '7 7. 07'],
  18707. ['h hh', '3 03'],
  18708. ['H HH', '15 15'],
  18709. ['m mm', '25 25'],
  18710. ['s ss', '50 50'],
  18711. ['a A', 'pm PM'],
  18712. ['[the] DDDo [day of the year]', 'the 45. day of the year'],
  18713. ['LTS', '15:25:50'],
  18714. ['L', '14. 02. 2010'],
  18715. ['LL', '14. februar 2010'],
  18716. ['LLL', '14. februar 2010 15:25'],
  18717. ['LLLL', 'nedjelja, 14. februar 2010 15:25'],
  18718. ['l', '14. 2. 2010'],
  18719. ['ll', '14. feb. 2010'],
  18720. ['lll', '14. feb. 2010 15:25'],
  18721. ['llll', 'ned., 14. feb. 2010 15:25']
  18722. ],
  18723. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  18724. i;
  18725. for (i = 0; i < a.length; i++) {
  18726. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  18727. }
  18728. });
  18729. test('format ordinal', function (assert) {
  18730. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
  18731. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
  18732. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
  18733. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
  18734. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
  18735. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
  18736. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
  18737. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
  18738. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
  18739. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
  18740. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
  18741. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
  18742. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
  18743. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
  18744. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
  18745. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
  18746. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
  18747. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
  18748. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
  18749. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
  18750. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
  18751. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
  18752. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
  18753. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
  18754. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
  18755. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
  18756. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
  18757. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
  18758. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
  18759. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
  18760. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
  18761. });
  18762. test('format month', function (assert) {
  18763. var expected = 'januar jan._februar feb._mart mar._april apr._maj maj_jun jun_jul jul_avgust avg._septembar sep._oktobar okt._novembar nov._decembar dec.'.split('_'),
  18764. i;
  18765. for (i = 0; i < expected.length; i++) {
  18766. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  18767. }
  18768. });
  18769. test('format week', function (assert) {
  18770. var expected = 'nedjelja ned. ne_ponedjeljak pon. po_utorak uto. ut_srijeda sri. sr_četvrtak čet. če_petak pet. pe_subota sub. su'.split('_'),
  18771. i;
  18772. for (i = 0; i < expected.length; i++) {
  18773. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  18774. }
  18775. });
  18776. test('from', function (assert) {
  18777. var start = moment([2007, 1, 28]);
  18778. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'nekoliko sekundi', '44 seconds = a few seconds');
  18779. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'jedan minut', '45 seconds = a minute');
  18780. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'jedan minut', '89 seconds = a minute');
  18781. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuta', '90 seconds = 2 minutes');
  18782. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuta', '44 minutes = 44 minutes');
  18783. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'jedan sat', '45 minutes = an hour');
  18784. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'jedan sat', '89 minutes = an hour');
  18785. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 sata', '90 minutes = 2 hours');
  18786. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 sati', '5 hours = 5 hours');
  18787. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 sati', '21 hours = 21 hours');
  18788. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'dan', '22 hours = a day');
  18789. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'dan', '35 hours = a day');
  18790. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dana', '36 hours = 2 days');
  18791. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'dan', '1 day = a day');
  18792. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dana', '5 days = 5 days');
  18793. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dana', '25 days = 25 days');
  18794. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'mjesec', '26 days = a month');
  18795. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'mjesec', '30 days = a month');
  18796. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'mjesec', '43 days = a month');
  18797. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mjeseca', '46 days = 2 months');
  18798. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mjeseca', '75 days = 2 months');
  18799. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mjeseca', '76 days = 3 months');
  18800. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'mjesec', '1 month = a month');
  18801. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mjeseci', '5 months = 5 months');
  18802. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'godinu', '345 days = a year');
  18803. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 godine', '548 days = 2 years');
  18804. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'godinu', '1 year = a year');
  18805. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 godina', '5 years = 5 years');
  18806. });
  18807. test('suffix', function (assert) {
  18808. assert.equal(moment(30000).from(0), 'za nekoliko sekundi', 'prefix');
  18809. assert.equal(moment(0).from(30000), 'prije nekoliko sekundi', 'prefix');
  18810. });
  18811. test('now from now', function (assert) {
  18812. assert.equal(moment().fromNow(), 'prije nekoliko sekundi', 'now from now should display as in the past');
  18813. });
  18814. test('fromNow', function (assert) {
  18815. assert.equal(moment().add({s: 30}).fromNow(), 'za nekoliko sekundi', 'in a few seconds');
  18816. assert.equal(moment().add({d: 5}).fromNow(), 'za 5 dana', 'in 5 days');
  18817. });
  18818. test('calendar day', function (assert) {
  18819. var a = moment().hours(2).minutes(0).seconds(0);
  18820. assert.equal(moment(a).calendar(), 'danas u 2:00', 'today at the same time');
  18821. assert.equal(moment(a).add({m: 25}).calendar(), 'danas u 2:25', 'Now plus 25 min');
  18822. assert.equal(moment(a).add({h: 1}).calendar(), 'danas u 3:00', 'Now plus 1 hour');
  18823. assert.equal(moment(a).add({d: 1}).calendar(), 'sjutra u 2:00', 'tomorrow at the same time');
  18824. assert.equal(moment(a).subtract({h: 1}).calendar(), 'danas u 1:00', 'Now minus 1 hour');
  18825. assert.equal(moment(a).subtract({d: 1}).calendar(), 'juče u 2:00', 'yesterday at the same time');
  18826. });
  18827. test('calendar next week', function (assert) {
  18828. var i, m;
  18829. function makeFormat(d) {
  18830. switch (d.day()) {
  18831. case 0:
  18832. return '[u] [nedjelju] [u] LT';
  18833. case 3:
  18834. return '[u] [srijedu] [u] LT';
  18835. case 6:
  18836. return '[u] [subotu] [u] LT';
  18837. case 1:
  18838. case 2:
  18839. case 4:
  18840. case 5:
  18841. return '[u] dddd [u] LT';
  18842. }
  18843. }
  18844. for (i = 2; i < 7; i++) {
  18845. m = moment().add({d: i});
  18846. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days current time');
  18847. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  18848. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days beginning of day');
  18849. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  18850. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days end of day');
  18851. }
  18852. });
  18853. test('calendar last week', function (assert) {
  18854. var i, m;
  18855. function makeFormat(d) {
  18856. var lastWeekDay = [
  18857. '[prošle] [nedjelje] [u] LT',
  18858. '[prošlog] [ponedjeljka] [u] LT',
  18859. '[prošlog] [utorka] [u] LT',
  18860. '[prošle] [srijede] [u] LT',
  18861. '[prošlog] [četvrtka] [u] LT',
  18862. '[prošlog] [petka] [u] LT',
  18863. '[prošle] [subote] [u] LT'
  18864. ];
  18865. return lastWeekDay[d.day()];
  18866. }
  18867. for (i = 2; i < 7; i++) {
  18868. m = moment().subtract({d: i});
  18869. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days current time');
  18870. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  18871. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days beginning of day');
  18872. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  18873. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days end of day');
  18874. }
  18875. });
  18876. test('calendar all else', function (assert) {
  18877. var weeksAgo = moment().subtract({w: 1}),
  18878. weeksFromNow = moment().add({w: 1});
  18879. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  18880. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  18881. weeksAgo = moment().subtract({w: 2});
  18882. weeksFromNow = moment().add({w: 2});
  18883. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  18884. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  18885. });
  18886. // Monday is the first day of the week.
  18887. // The week that contains Jan 1st is the first week of the year.
  18888. test('weeks year starting sunday', function (assert) {
  18889. assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1');
  18890. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  18891. assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2');
  18892. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  18893. assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3');
  18894. });
  18895. test('weeks year starting monday', function (assert) {
  18896. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  18897. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  18898. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  18899. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  18900. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  18901. });
  18902. test('weeks year starting tuesday', function (assert) {
  18903. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  18904. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  18905. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  18906. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  18907. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  18908. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  18909. });
  18910. test('weeks year starting wednesday', function (assert) {
  18911. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  18912. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  18913. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  18914. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  18915. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  18916. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  18917. });
  18918. test('weeks year starting thursday', function (assert) {
  18919. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  18920. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  18921. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  18922. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  18923. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  18924. assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3');
  18925. });
  18926. test('weeks year starting friday', function (assert) {
  18927. assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1');
  18928. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  18929. assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1');
  18930. assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2');
  18931. assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2');
  18932. assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3');
  18933. });
  18934. test('weeks year starting saturday', function (assert) {
  18935. assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1');
  18936. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  18937. assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1');
  18938. assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2');
  18939. assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2');
  18940. assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3');
  18941. });
  18942. test('weeks year starting sunday formatted', function (assert) {
  18943. assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1.', 'Dec 26 2011 should be week 1');
  18944. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1.', 'Jan 1 2012 should be week 1');
  18945. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2.', 'Jan 2 2012 should be week 2');
  18946. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2.', 'Jan 8 2012 should be week 2');
  18947. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3.', 'Jan 9 2012 should be week 3');
  18948. });
  18949. test('lenient ordinal parsing', function (assert) {
  18950. var i, ordinalStr, testMoment;
  18951. for (i = 1; i <= 31; ++i) {
  18952. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  18953. testMoment = moment(ordinalStr, 'YYYY MM Do');
  18954. assert.equal(testMoment.year(), 2014,
  18955. 'lenient ordinal parsing ' + i + ' year check');
  18956. assert.equal(testMoment.month(), 0,
  18957. 'lenient ordinal parsing ' + i + ' month check');
  18958. assert.equal(testMoment.date(), i,
  18959. 'lenient ordinal parsing ' + i + ' date check');
  18960. }
  18961. });
  18962. test('lenient ordinal parsing of number', function (assert) {
  18963. var i, testMoment;
  18964. for (i = 1; i <= 31; ++i) {
  18965. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  18966. assert.equal(testMoment.year(), 2014,
  18967. 'lenient ordinal parsing of number ' + i + ' year check');
  18968. assert.equal(testMoment.month(), 0,
  18969. 'lenient ordinal parsing of number ' + i + ' month check');
  18970. assert.equal(testMoment.date(), i,
  18971. 'lenient ordinal parsing of number ' + i + ' date check');
  18972. }
  18973. });
  18974. test('strict ordinal parsing', function (assert) {
  18975. var i, ordinalStr, testMoment;
  18976. for (i = 1; i <= 31; ++i) {
  18977. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  18978. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  18979. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  18980. }
  18981. });
  18982. }));
  18983. ;(function (global, factory) {
  18984. typeof exports === 'object' && typeof module !== 'undefined'
  18985. && typeof require === 'function' ? factory(require('../../moment')) :
  18986. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  18987. factory(global.moment)
  18988. }(this, function (moment) { 'use strict';
  18989. /*global QUnit:false*/
  18990. var test = QUnit.test;
  18991. var expect = QUnit.expect;
  18992. function module (name, lifecycle) {
  18993. QUnit.module(name, {
  18994. setup : function () {
  18995. moment.locale('en');
  18996. moment.createFromInputFallback = function (config) {
  18997. throw new Error('input not handled by moment: ' + config._i);
  18998. };
  18999. if (lifecycle && lifecycle.setup) {
  19000. lifecycle.setup();
  19001. }
  19002. },
  19003. teardown : function () {
  19004. if (lifecycle && lifecycle.teardown) {
  19005. lifecycle.teardown();
  19006. }
  19007. }
  19008. });
  19009. }
  19010. function localeModule (name, lifecycle) {
  19011. QUnit.module('locale:' + name, {
  19012. setup : function () {
  19013. moment.locale(name);
  19014. moment.createFromInputFallback = function (config) {
  19015. throw new Error('input not handled by moment: ' + config._i);
  19016. };
  19017. if (lifecycle && lifecycle.setup) {
  19018. lifecycle.setup();
  19019. }
  19020. },
  19021. teardown : function () {
  19022. moment.locale('en');
  19023. if (lifecycle && lifecycle.teardown) {
  19024. lifecycle.teardown();
  19025. }
  19026. }
  19027. });
  19028. }
  19029. localeModule('mk');
  19030. test('parse', function (assert) {
  19031. var tests = 'јануари јан_февруари фев_март мар_април апр_мај мај_јуни јун_јули јул_август авг_септември сеп_октомври окт_ноември ное_декември дек'.split('_'), i;
  19032. function equalTest(input, mmm, i) {
  19033. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  19034. }
  19035. for (i = 0; i < 12; i++) {
  19036. tests[i] = tests[i].split(' ');
  19037. equalTest(tests[i][0], 'MMM', i);
  19038. equalTest(tests[i][1], 'MMM', i);
  19039. equalTest(tests[i][0], 'MMMM', i);
  19040. equalTest(tests[i][1], 'MMMM', i);
  19041. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  19042. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  19043. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  19044. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  19045. }
  19046. });
  19047. test('format', function (assert) {
  19048. var a = [
  19049. ['dddd, MMMM Do YYYY, H:mm:ss', 'недела, февруари 14-ти 2010, 15:25:50'],
  19050. ['ddd, hA', 'нед, 3PM'],
  19051. ['M Mo MM MMMM MMM', '2 2-ри 02 февруари фев'],
  19052. ['YYYY YY', '2010 10'],
  19053. ['D Do DD', '14 14-ти 14'],
  19054. ['d do dddd ddd dd', '0 0-ев недела нед нe'],
  19055. ['DDD DDDo DDDD', '45 45-ти 045'],
  19056. ['w wo ww', '7 7-ми 07'],
  19057. ['h hh', '3 03'],
  19058. ['H HH', '15 15'],
  19059. ['m mm', '25 25'],
  19060. ['s ss', '50 50'],
  19061. ['a A', 'pm PM'],
  19062. ['[the] DDDo [day of the year]', 'the 45-ти day of the year'],
  19063. ['LTS', '15:25:50'],
  19064. ['L', '14.02.2010'],
  19065. ['LL', '14 февруари 2010'],
  19066. ['LLL', '14 февруари 2010 15:25'],
  19067. ['LLLL', 'недела, 14 февруари 2010 15:25'],
  19068. ['l', '14.2.2010'],
  19069. ['ll', '14 фев 2010'],
  19070. ['lll', '14 фев 2010 15:25'],
  19071. ['llll', 'нед, 14 фев 2010 15:25']
  19072. ],
  19073. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  19074. i;
  19075. for (i = 0; i < a.length; i++) {
  19076. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  19077. }
  19078. });
  19079. test('format ordinal', function (assert) {
  19080. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1-ви', '1-ви');
  19081. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2-ри', '2-ри');
  19082. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3-ти', '3-ти');
  19083. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4-ти', '4-ти');
  19084. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5-ти', '5-ти');
  19085. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6-ти', '6-ти');
  19086. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7-ми', '7-ми');
  19087. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8-ми', '8-ми');
  19088. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9-ти', '9-ти');
  19089. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10-ти', '10-ти');
  19090. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11-ти', '11-ти');
  19091. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12-ти', '12-ти');
  19092. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13-ти', '13-ти');
  19093. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14-ти', '14-ти');
  19094. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15-ти', '15-ти');
  19095. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16-ти', '16-ти');
  19096. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17-ти', '17-ти');
  19097. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18-ти', '18-ти');
  19098. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19-ти', '19-ти');
  19099. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20-ти', '20-ти');
  19100. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21-ви', '21-ви');
  19101. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22-ри', '22-ри');
  19102. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23-ти', '23-ти');
  19103. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24-ти', '24-ти');
  19104. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25-ти', '25-ти');
  19105. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26-ти', '26-ти');
  19106. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27-ми', '27-ми');
  19107. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28-ми', '28-ми');
  19108. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29-ти', '29-ти');
  19109. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30-ти', '30-ти');
  19110. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31-ви', '31-ви');
  19111. });
  19112. test('format month', function (assert) {
  19113. var expected = 'јануари јан_февруари фев_март мар_април апр_мај мај_јуни јун_јули јул_август авг_септември сеп_октомври окт_ноември ное_декември дек'.split('_'), i;
  19114. for (i = 0; i < expected.length; i++) {
  19115. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  19116. }
  19117. });
  19118. test('format week', function (assert) {
  19119. var expected = 'недела нед нe_понеделник пон пo_вторник вто вт_среда сре ср_четврток чет че_петок пет пе_сабота саб сa'.split('_'), i;
  19120. for (i = 0; i < expected.length; i++) {
  19121. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  19122. }
  19123. });
  19124. test('from', function (assert) {
  19125. var start = moment([2007, 1, 28]);
  19126. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'неколку секунди', '44 seconds = a few seconds');
  19127. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'минута', '45 seconds = a minute');
  19128. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'минута', '89 seconds = a minute');
  19129. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 минути', '90 seconds = 2 minutes');
  19130. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 минути', '44 minutes = 44 minutes');
  19131. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'час', '45 minutes = an hour');
  19132. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'час', '89 minutes = an hour');
  19133. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 часа', '90 minutes = 2 hours');
  19134. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 часа', '5 hours = 5 hours');
  19135. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 часа', '21 hours = 21 hours');
  19136. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ден', '22 hours = a day');
  19137. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ден', '35 hours = a day');
  19138. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 дена', '36 hours = 2 days');
  19139. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ден', '1 day = a day');
  19140. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 дена', '5 days = 5 days');
  19141. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 дена', '25 days = 25 days');
  19142. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'месец', '26 days = a month');
  19143. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'месец', '30 days = a month');
  19144. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'месец', '43 days = a month');
  19145. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 месеци', '46 days = 2 months');
  19146. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 месеци', '75 days = 2 months');
  19147. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 месеци', '76 days = 3 months');
  19148. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'месец', '1 month = a month');
  19149. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 месеци', '5 months = 5 months');
  19150. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'година', '345 days = a year');
  19151. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 години', '548 days = 2 years');
  19152. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'година', '1 year = a year');
  19153. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 години', '5 years = 5 years');
  19154. });
  19155. test('suffix', function (assert) {
  19156. assert.equal(moment(30000).from(0), 'после неколку секунди', 'prefix');
  19157. assert.equal(moment(0).from(30000), 'пред неколку секунди', 'suffix');
  19158. });
  19159. test('now from now', function (assert) {
  19160. assert.equal(moment().fromNow(), 'пред неколку секунди', 'now from now should display as in the past');
  19161. });
  19162. test('fromNow', function (assert) {
  19163. assert.equal(moment().add({s: 30}).fromNow(), 'после неколку секунди', 'in a few seconds');
  19164. assert.equal(moment().add({d: 5}).fromNow(), 'после 5 дена', 'in 5 days');
  19165. });
  19166. test('calendar day', function (assert) {
  19167. var a = moment().hours(2).minutes(0).seconds(0);
  19168. assert.equal(moment(a).calendar(), 'Денес во 2:00', 'today at the same time');
  19169. assert.equal(moment(a).add({m: 25}).calendar(), 'Денес во 2:25', 'Now plus 25 min');
  19170. assert.equal(moment(a).add({h: 1}).calendar(), 'Денес во 3:00', 'Now plus 1 hour');
  19171. assert.equal(moment(a).add({d: 1}).calendar(), 'Утре во 2:00', 'tomorrow at the same time');
  19172. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Денес во 1:00', 'Now minus 1 hour');
  19173. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Вчера во 2:00', 'yesterday at the same time');
  19174. });
  19175. test('calendar next week', function (assert) {
  19176. var i, m;
  19177. for (i = 2; i < 7; i++) {
  19178. m = moment().add({d: i});
  19179. assert.equal(m.calendar(), m.format('[Во] dddd [во] LT'), 'Today + ' + i + ' days current time');
  19180. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  19181. assert.equal(m.calendar(), m.format('[Во] dddd [во] LT'), 'Today + ' + i + ' days beginning of day');
  19182. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  19183. assert.equal(m.calendar(), m.format('[Во] dddd [во] LT'), 'Today + ' + i + ' days end of day');
  19184. }
  19185. });
  19186. test('calendar last week', function (assert) {
  19187. var i, m;
  19188. function makeFormat(d) {
  19189. switch (d.day()) {
  19190. case 0:
  19191. case 3:
  19192. case 6:
  19193. return '[Изминатата] dddd [во] LT';
  19194. case 1:
  19195. case 2:
  19196. case 4:
  19197. case 5:
  19198. return '[Изминатиот] dddd [во] LT';
  19199. }
  19200. }
  19201. for (i = 2; i < 7; i++) {
  19202. m = moment().subtract({d: i});
  19203. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days current time');
  19204. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  19205. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days beginning of day');
  19206. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  19207. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days end of day');
  19208. }
  19209. });
  19210. test('calendar all else', function (assert) {
  19211. var weeksAgo = moment().subtract({w: 1}),
  19212. weeksFromNow = moment().add({w: 1});
  19213. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  19214. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  19215. weeksAgo = moment().subtract({w: 2});
  19216. weeksFromNow = moment().add({w: 2});
  19217. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  19218. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  19219. });
  19220. test('weeks year starting sunday', function (assert) {
  19221. assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1');
  19222. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  19223. assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2');
  19224. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  19225. assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3');
  19226. });
  19227. test('weeks year starting monday', function (assert) {
  19228. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  19229. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  19230. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  19231. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  19232. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  19233. });
  19234. test('weeks year starting tuesday', function (assert) {
  19235. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  19236. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  19237. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  19238. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  19239. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  19240. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  19241. });
  19242. test('weeks year starting wednesday', function (assert) {
  19243. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  19244. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  19245. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  19246. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  19247. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  19248. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  19249. });
  19250. test('weeks year starting thursday', function (assert) {
  19251. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  19252. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  19253. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  19254. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  19255. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  19256. assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3');
  19257. });
  19258. test('weeks year starting friday', function (assert) {
  19259. assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1');
  19260. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  19261. assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1');
  19262. assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2');
  19263. assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2');
  19264. assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3');
  19265. });
  19266. test('weeks year starting saturday', function (assert) {
  19267. assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1');
  19268. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  19269. assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1');
  19270. assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2');
  19271. assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2');
  19272. assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3');
  19273. });
  19274. test('weeks year starting sunday formatted', function (assert) {
  19275. assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1-ви', 'Dec 26 2011 should be week 1');
  19276. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1-ви', 'Jan 1 2012 should be week 1');
  19277. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2-ри', 'Jan 2 2012 should be week 2');
  19278. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2-ри', 'Jan 8 2012 should be week 2');
  19279. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3-ти', 'Jan 9 2012 should be week 3');
  19280. });
  19281. test('lenient ordinal parsing', function (assert) {
  19282. var i, ordinalStr, testMoment;
  19283. for (i = 1; i <= 31; ++i) {
  19284. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  19285. testMoment = moment(ordinalStr, 'YYYY MM Do');
  19286. assert.equal(testMoment.year(), 2014,
  19287. 'lenient ordinal parsing ' + i + ' year check');
  19288. assert.equal(testMoment.month(), 0,
  19289. 'lenient ordinal parsing ' + i + ' month check');
  19290. assert.equal(testMoment.date(), i,
  19291. 'lenient ordinal parsing ' + i + ' date check');
  19292. }
  19293. });
  19294. test('lenient ordinal parsing of number', function (assert) {
  19295. var i, testMoment;
  19296. for (i = 1; i <= 31; ++i) {
  19297. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  19298. assert.equal(testMoment.year(), 2014,
  19299. 'lenient ordinal parsing of number ' + i + ' year check');
  19300. assert.equal(testMoment.month(), 0,
  19301. 'lenient ordinal parsing of number ' + i + ' month check');
  19302. assert.equal(testMoment.date(), i,
  19303. 'lenient ordinal parsing of number ' + i + ' date check');
  19304. }
  19305. });
  19306. test('strict ordinal parsing', function (assert) {
  19307. var i, ordinalStr, testMoment;
  19308. for (i = 1; i <= 31; ++i) {
  19309. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  19310. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  19311. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  19312. }
  19313. });
  19314. }));
  19315. ;(function (global, factory) {
  19316. typeof exports === 'object' && typeof module !== 'undefined'
  19317. && typeof require === 'function' ? factory(require('../../moment')) :
  19318. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  19319. factory(global.moment)
  19320. }(this, function (moment) { 'use strict';
  19321. /*global QUnit:false*/
  19322. var test = QUnit.test;
  19323. var expect = QUnit.expect;
  19324. function module (name, lifecycle) {
  19325. QUnit.module(name, {
  19326. setup : function () {
  19327. moment.locale('en');
  19328. moment.createFromInputFallback = function (config) {
  19329. throw new Error('input not handled by moment: ' + config._i);
  19330. };
  19331. if (lifecycle && lifecycle.setup) {
  19332. lifecycle.setup();
  19333. }
  19334. },
  19335. teardown : function () {
  19336. if (lifecycle && lifecycle.teardown) {
  19337. lifecycle.teardown();
  19338. }
  19339. }
  19340. });
  19341. }
  19342. function localeModule (name, lifecycle) {
  19343. QUnit.module('locale:' + name, {
  19344. setup : function () {
  19345. moment.locale(name);
  19346. moment.createFromInputFallback = function (config) {
  19347. throw new Error('input not handled by moment: ' + config._i);
  19348. };
  19349. if (lifecycle && lifecycle.setup) {
  19350. lifecycle.setup();
  19351. }
  19352. },
  19353. teardown : function () {
  19354. moment.locale('en');
  19355. if (lifecycle && lifecycle.teardown) {
  19356. lifecycle.teardown();
  19357. }
  19358. }
  19359. });
  19360. }
  19361. localeModule('ml');
  19362. test('parse', function (assert) {
  19363. var tests = 'ജനുവരി ജനു._ഫെബ്രുവരി ഫെബ്രു._മാർച്ച് മാർ._ഏപ്രിൽ ഏപ്രി._മേയ് മേയ്_ജൂൺ ജൂൺ_ജൂലൈ ജൂലൈ._ഓഗസ്റ്റ് ഓഗ._സെപ്റ്റംബർ സെപ്റ്റ._ഒക്ടോബർ ഒക്ടോ._നവംബർ നവം._ഡിസംബർ ഡിസം.'.split('_'), i;
  19364. function equalTest(input, mmm, i) {
  19365. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  19366. }
  19367. for (i = 0; i < 12; i++) {
  19368. tests[i] = tests[i].split(' ');
  19369. equalTest(tests[i][0], 'MMM', i);
  19370. equalTest(tests[i][1], 'MMM', i);
  19371. equalTest(tests[i][0], 'MMMM', i);
  19372. equalTest(tests[i][1], 'MMMM', i);
  19373. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  19374. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  19375. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  19376. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  19377. }
  19378. });
  19379. test('format', function (assert) {
  19380. var a = [
  19381. ['dddd, Do MMMM YYYY, a h:mm:ss -നു', 'ഞായറാഴ്ച, 14 ഫെബ്രുവരി 2010, ഉച്ച കഴിഞ്ഞ് 3:25:50 -നു'],
  19382. ['ddd, a h -നു', 'ഞായർ, ഉച്ച കഴിഞ്ഞ് 3 -നു'],
  19383. ['M Mo MM MMMM MMM', '2 2 02 ഫെബ്രുവരി ഫെബ്രു.'],
  19384. ['YYYY YY', '2010 10'],
  19385. ['D Do DD', '14 14 14'],
  19386. ['d do dddd ddd dd', '0 0 ഞായറാഴ്ച ഞായർ ഞാ'],
  19387. ['DDD DDDo DDDD', '45 45 045'],
  19388. ['w wo ww', '8 8 08'],
  19389. ['h hh', '3 03'],
  19390. ['H HH', '15 15'],
  19391. ['m mm', '25 25'],
  19392. ['s ss', '50 50'],
  19393. ['a A', 'ഉച്ച കഴിഞ്ഞ് ഉച്ച കഴിഞ്ഞ്'],
  19394. ['LTS', 'ഉച്ച കഴിഞ്ഞ് 3:25:50 -നു'],
  19395. ['L', '14/02/2010'],
  19396. ['LL', '14 ഫെബ്രുവരി 2010'],
  19397. ['LLL', '14 ഫെബ്രുവരി 2010, ഉച്ച കഴിഞ്ഞ് 3:25 -നു'],
  19398. ['LLLL', 'ഞായറാഴ്ച, 14 ഫെബ്രുവരി 2010, ഉച്ച കഴിഞ്ഞ് 3:25 -നു'],
  19399. ['l', '14/2/2010'],
  19400. ['ll', '14 ഫെബ്രു. 2010'],
  19401. ['lll', '14 ഫെബ്രു. 2010, ഉച്ച കഴിഞ്ഞ് 3:25 -നു'],
  19402. ['llll', 'ഞായർ, 14 ഫെബ്രു. 2010, ഉച്ച കഴിഞ്ഞ് 3:25 -നു']
  19403. ],
  19404. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  19405. i;
  19406. for (i = 0; i < a.length; i++) {
  19407. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  19408. }
  19409. });
  19410. test('format ordinal', function (assert) {
  19411. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1');
  19412. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2');
  19413. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3');
  19414. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4');
  19415. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5');
  19416. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6');
  19417. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7');
  19418. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8');
  19419. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9');
  19420. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10');
  19421. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11');
  19422. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12');
  19423. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13');
  19424. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14');
  19425. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15');
  19426. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16');
  19427. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17');
  19428. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18');
  19429. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19');
  19430. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20');
  19431. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21');
  19432. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22');
  19433. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23');
  19434. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24');
  19435. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25');
  19436. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26');
  19437. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27');
  19438. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28');
  19439. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29');
  19440. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30');
  19441. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31');
  19442. });
  19443. test('format month', function (assert) {
  19444. var expected = 'ജനുവരി ജനു._ഫെബ്രുവരി ഫെബ്രു._മാർച്ച് മാർ._ഏപ്രിൽ ഏപ്രി._മേയ് മേയ്_ജൂൺ ജൂൺ_ജൂലൈ ജൂലൈ._ഓഗസ്റ്റ് ഓഗ._സെപ്റ്റംബർ സെപ്റ്റ._ഒക്ടോബർ ഒക്ടോ._നവംബർ നവം._ഡിസംബർ ഡിസം.'.split('_'), i;
  19445. for (i = 0; i < expected.length; i++) {
  19446. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  19447. }
  19448. });
  19449. test('format week', function (assert) {
  19450. var expected = 'ഞായറാഴ്ച ഞായർ ഞാ_തിങ്കളാഴ്ച തിങ്കൾ തി_ചൊവ്വാഴ്ച ചൊവ്വ ചൊ_ബുധനാഴ്ച ബുധൻ ബു_വ്യാഴാഴ്ച വ്യാഴം വ്യാ_വെള്ളിയാഴ്ച വെള്ളി വെ_ശനിയാഴ്ച ശനി ശ'.split('_'), i;
  19451. for (i = 0; i < expected.length; i++) {
  19452. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  19453. }
  19454. });
  19455. test('from', function (assert) {
  19456. var start = moment([2007, 1, 28]);
  19457. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'അൽപ നിമിഷങ്ങൾ', '44 seconds = a few seconds');
  19458. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'ഒരു മിനിറ്റ്', '45 seconds = a minute');
  19459. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'ഒരു മിനിറ്റ്', '89 seconds = a minute');
  19460. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 മിനിറ്റ്', '90 seconds = 2 minutes');
  19461. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 മിനിറ്റ്', '44 minutes = 44 minutes');
  19462. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ഒരു മണിക്കൂർ', '45 minutes = an hour');
  19463. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ഒരു മണിക്കൂർ', '89 minutes = an hour');
  19464. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 മണിക്കൂർ', '90 minutes = 2 hours');
  19465. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 മണിക്കൂർ', '5 hours = 5 hours');
  19466. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 മണിക്കൂർ', '21 hours = 21 hours');
  19467. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ഒരു ദിവസം', '22 hours = a day');
  19468. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ഒരു ദിവസം', '35 hours = a day');
  19469. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 ദിവസം', '36 hours = 2 days');
  19470. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ഒരു ദിവസം', '1 day = a day');
  19471. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 ദിവസം', '5 days = 5 days');
  19472. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 ദിവസം', '25 days = 25 days');
  19473. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ഒരു മാസം', '26 days = a month');
  19474. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ഒരു മാസം', '30 days = a month');
  19475. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ഒരു മാസം', '43 days = a month');
  19476. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 മാസം', '46 days = 2 months');
  19477. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 മാസം', '75 days = 2 months');
  19478. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 മാസം', '76 days = 3 months');
  19479. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ഒരു മാസം', '1 month = a month');
  19480. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 മാസം', '5 months = 5 months');
  19481. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ഒരു വർഷം', '345 days = a year');
  19482. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 വർഷം', '548 days = 2 years');
  19483. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ഒരു വർഷം', '1 year = a year');
  19484. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 വർഷം', '5 years = 5 years');
  19485. });
  19486. test('suffix', function (assert) {
  19487. assert.equal(moment(30000).from(0), 'അൽപ നിമിഷങ്ങൾ കഴിഞ്ഞ്', 'prefix');
  19488. assert.equal(moment(0).from(30000), 'അൽപ നിമിഷങ്ങൾ മുൻപ്', 'suffix');
  19489. });
  19490. test('now from now', function (assert) {
  19491. assert.equal(moment().fromNow(), 'അൽപ നിമിഷങ്ങൾ മുൻപ്', 'now from now should display as in the past');
  19492. });
  19493. test('fromNow', function (assert) {
  19494. assert.equal(moment().add({s: 30}).fromNow(), 'അൽപ നിമിഷങ്ങൾ കഴിഞ്ഞ്', 'അൽപ നിമിഷങ്ങൾ കഴിഞ്ഞ്');
  19495. assert.equal(moment().add({d: 5}).fromNow(), '5 ദിവസം കഴിഞ്ഞ്', '5 ദിവസം കഴിഞ്ഞ്');
  19496. });
  19497. test('calendar day', function (assert) {
  19498. var a = moment().hours(2).minutes(0).seconds(0);
  19499. assert.equal(moment(a).calendar(), 'ഇന്ന് രാത്രി 2:00 -നു', 'today at the same time');
  19500. assert.equal(moment(a).add({m: 25}).calendar(), 'ഇന്ന് രാത്രി 2:25 -നു', 'Now plus 25 min');
  19501. assert.equal(moment(a).add({h: 3}).calendar(), 'ഇന്ന് രാവിലെ 5:00 -നു', 'Now plus 3 hour');
  19502. assert.equal(moment(a).add({d: 1}).calendar(), 'നാളെ രാത്രി 2:00 -നു', 'tomorrow at the same time');
  19503. assert.equal(moment(a).subtract({h: 1}).calendar(), 'ഇന്ന് രാത്രി 1:00 -നു', 'Now minus 1 hour');
  19504. assert.equal(moment(a).subtract({d: 1}).calendar(), 'ഇന്നലെ രാത്രി 2:00 -നു', 'yesterday at the same time');
  19505. });
  19506. test('calendar next week', function (assert) {
  19507. var i, m;
  19508. for (i = 2; i < 7; i++) {
  19509. m = moment().add({d: i});
  19510. assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days current time');
  19511. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  19512. assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days beginning of day');
  19513. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  19514. assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days end of day');
  19515. }
  19516. });
  19517. test('calendar last week', function (assert) {
  19518. var i, m;
  19519. for (i = 2; i < 7; i++) {
  19520. m = moment().subtract({d: i});
  19521. assert.equal(m.calendar(), m.format('[കഴിഞ്ഞ] dddd[,] LT'), 'Today - ' + i + ' days current time');
  19522. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  19523. assert.equal(m.calendar(), m.format('[കഴിഞ്ഞ] dddd[,] LT'), 'Today - ' + i + ' days beginning of day');
  19524. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  19525. assert.equal(m.calendar(), m.format('[കഴിഞ്ഞ] dddd[,] LT'), 'Today - ' + i + ' days end of day');
  19526. }
  19527. });
  19528. test('calendar all else', function (assert) {
  19529. var weeksAgo = moment().subtract({w: 1}),
  19530. weeksFromNow = moment().add({w: 1});
  19531. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  19532. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  19533. weeksAgo = moment().subtract({w: 2});
  19534. weeksFromNow = moment().add({w: 2});
  19535. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  19536. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  19537. });
  19538. test('meridiem', function (assert) {
  19539. assert.equal(moment([2011, 2, 23, 2, 30]).format('a'), 'രാത്രി', 'before dawn');
  19540. assert.equal(moment([2011, 2, 23, 9, 30]).format('a'), 'രാവിലെ', 'morning');
  19541. assert.equal(moment([2011, 2, 23, 14, 30]).format('a'), 'ഉച്ച കഴിഞ്ഞ്', 'during day');
  19542. assert.equal(moment([2011, 2, 23, 17, 30]).format('a'), 'വൈകുന്നേരം', 'evening');
  19543. assert.equal(moment([2011, 2, 23, 19, 30]).format('a'), 'വൈകുന്നേരം', 'late evening');
  19544. assert.equal(moment([2011, 2, 23, 21, 20]).format('a'), 'രാത്രി', 'night');
  19545. assert.equal(moment([2011, 2, 23, 2, 30]).format('A'), 'രാത്രി', 'before dawn');
  19546. assert.equal(moment([2011, 2, 23, 9, 30]).format('A'), 'രാവിലെ', 'morning');
  19547. assert.equal(moment([2011, 2, 23, 14, 30]).format('A'), 'ഉച്ച കഴിഞ്ഞ്', ' during day');
  19548. assert.equal(moment([2011, 2, 23, 17, 30]).format('A'), 'വൈകുന്നേരം', 'evening');
  19549. assert.equal(moment([2011, 2, 23, 19, 30]).format('A'), 'വൈകുന്നേരം', 'late evening');
  19550. assert.equal(moment([2011, 2, 23, 21, 20]).format('A'), 'രാത്രി', 'night');
  19551. });
  19552. test('weeks year starting sunday', function (assert) {
  19553. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  19554. assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1');
  19555. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  19556. assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2');
  19557. assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 3');
  19558. });
  19559. test('weeks year starting monday', function (assert) {
  19560. assert.equal(moment([2006, 11, 31]).week(), 1, 'Dec 31 2006 should be week 1');
  19561. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  19562. assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1');
  19563. assert.equal(moment([2007, 0, 7]).week(), 2, 'Jan 7 2007 should be week 2');
  19564. assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2');
  19565. assert.equal(moment([2007, 0, 14]).week(), 3, 'Jan 14 2007 should be week 3');
  19566. });
  19567. test('weeks year starting tuesday', function (assert) {
  19568. assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52');
  19569. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  19570. assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1');
  19571. assert.equal(moment([2008, 0, 6]).week(), 2, 'Jan 6 2008 should be week 2');
  19572. assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2');
  19573. assert.equal(moment([2008, 0, 13]).week(), 3, 'Jan 13 2008 should be week 3');
  19574. });
  19575. test('weeks year starting wednesday', function (assert) {
  19576. assert.equal(moment([2002, 11, 29]).week(), 1, 'Dec 29 2002 should be week 1');
  19577. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  19578. assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1');
  19579. assert.equal(moment([2003, 0, 5]).week(), 2, 'Jan 5 2003 should be week 2');
  19580. assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2');
  19581. assert.equal(moment([2003, 0, 12]).week(), 3, 'Jan 12 2003 should be week 3');
  19582. });
  19583. test('weeks year starting thursday', function (assert) {
  19584. assert.equal(moment([2008, 11, 28]).week(), 1, 'Dec 28 2008 should be week 1');
  19585. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  19586. assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1');
  19587. assert.equal(moment([2009, 0, 4]).week(), 2, 'Jan 4 2009 should be week 2');
  19588. assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2');
  19589. assert.equal(moment([2009, 0, 11]).week(), 3, 'Jan 11 2009 should be week 3');
  19590. });
  19591. test('weeks year starting friday', function (assert) {
  19592. assert.equal(moment([2009, 11, 27]).week(), 1, 'Dec 27 2009 should be week 1');
  19593. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  19594. assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 should be week 1');
  19595. assert.equal(moment([2010, 0, 3]).week(), 2, 'Jan 3 2010 should be week 2');
  19596. assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 should be week 2');
  19597. assert.equal(moment([2010, 0, 10]).week(), 3, 'Jan 10 2010 should be week 3');
  19598. });
  19599. test('weeks year starting saturday', function (assert) {
  19600. assert.equal(moment([2010, 11, 26]).week(), 1, 'Dec 26 2010 should be week 1');
  19601. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  19602. assert.equal(moment([2011, 0, 2]).week(), 2, 'Jan 2 2011 should be week 2');
  19603. assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2');
  19604. assert.equal(moment([2011, 0, 9]).week(), 3, 'Jan 9 2011 should be week 3');
  19605. });
  19606. test('weeks year starting sunday formatted', function (assert) {
  19607. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1', 'Jan 1 2012 should be week 1');
  19608. assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1', 'Jan 7 2012 should be week 1');
  19609. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2', 'Jan 8 2012 should be week 2');
  19610. assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2', 'Jan 14 2012 should be week 2');
  19611. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3', 'Jan 15 2012 should be week 3');
  19612. });
  19613. test('lenient ordinal parsing', function (assert) {
  19614. var i, ordinalStr, testMoment;
  19615. for (i = 1; i <= 31; ++i) {
  19616. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  19617. testMoment = moment(ordinalStr, 'YYYY MM Do');
  19618. assert.equal(testMoment.year(), 2014,
  19619. 'lenient ordinal parsing ' + i + ' year check');
  19620. assert.equal(testMoment.month(), 0,
  19621. 'lenient ordinal parsing ' + i + ' month check');
  19622. assert.equal(testMoment.date(), i,
  19623. 'lenient ordinal parsing ' + i + ' date check');
  19624. }
  19625. });
  19626. test('lenient ordinal parsing of number', function (assert) {
  19627. var i, testMoment;
  19628. for (i = 1; i <= 31; ++i) {
  19629. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  19630. assert.equal(testMoment.year(), 2014,
  19631. 'lenient ordinal parsing of number ' + i + ' year check');
  19632. assert.equal(testMoment.month(), 0,
  19633. 'lenient ordinal parsing of number ' + i + ' month check');
  19634. assert.equal(testMoment.date(), i,
  19635. 'lenient ordinal parsing of number ' + i + ' date check');
  19636. }
  19637. });
  19638. test('strict ordinal parsing', function (assert) {
  19639. var i, ordinalStr, testMoment;
  19640. for (i = 1; i <= 31; ++i) {
  19641. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  19642. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  19643. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  19644. }
  19645. });
  19646. }));
  19647. ;(function (global, factory) {
  19648. typeof exports === 'object' && typeof module !== 'undefined'
  19649. && typeof require === 'function' ? factory(require('../../moment')) :
  19650. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  19651. factory(global.moment)
  19652. }(this, function (moment) { 'use strict';
  19653. /*global QUnit:false*/
  19654. var test = QUnit.test;
  19655. var expect = QUnit.expect;
  19656. function module (name, lifecycle) {
  19657. QUnit.module(name, {
  19658. setup : function () {
  19659. moment.locale('en');
  19660. moment.createFromInputFallback = function (config) {
  19661. throw new Error('input not handled by moment: ' + config._i);
  19662. };
  19663. if (lifecycle && lifecycle.setup) {
  19664. lifecycle.setup();
  19665. }
  19666. },
  19667. teardown : function () {
  19668. if (lifecycle && lifecycle.teardown) {
  19669. lifecycle.teardown();
  19670. }
  19671. }
  19672. });
  19673. }
  19674. function localeModule (name, lifecycle) {
  19675. QUnit.module('locale:' + name, {
  19676. setup : function () {
  19677. moment.locale(name);
  19678. moment.createFromInputFallback = function (config) {
  19679. throw new Error('input not handled by moment: ' + config._i);
  19680. };
  19681. if (lifecycle && lifecycle.setup) {
  19682. lifecycle.setup();
  19683. }
  19684. },
  19685. teardown : function () {
  19686. moment.locale('en');
  19687. if (lifecycle && lifecycle.teardown) {
  19688. lifecycle.teardown();
  19689. }
  19690. }
  19691. });
  19692. }
  19693. localeModule('mr');
  19694. test('parse', function (assert) {
  19695. var tests = 'जानेवारी जाने._फेब्रुवारी फेब्रु._मार्च मार्च._एप्रिल एप्रि._मे मे._जून जून._जुलै जुलै._ऑगस्ट ऑग._सप्टेंबर सप्टें._ऑक्टोबर ऑक्टो._नोव्हेंबर नोव्हें._डिसेंबर डिसें.'.split('_'), i;
  19696. function equalTest(input, mmm, i) {
  19697. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  19698. }
  19699. for (i = 0; i < 12; i++) {
  19700. tests[i] = tests[i].split(' ');
  19701. equalTest(tests[i][0], 'MMM', i);
  19702. equalTest(tests[i][1], 'MMM', i);
  19703. equalTest(tests[i][0], 'MMMM', i);
  19704. equalTest(tests[i][1], 'MMMM', i);
  19705. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  19706. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  19707. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  19708. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  19709. }
  19710. });
  19711. test('format', function (assert) {
  19712. var a = [
  19713. ['dddd, Do MMMM YYYY, a h:mm:ss वाजता', 'रविवार, १४ फेब्रुवारी २०१०, दुपारी ३:२५:५० वाजता'],
  19714. ['ddd, a h वाजता', 'रवि, दुपारी ३ वाजता'],
  19715. ['M Mo MM MMMM MMM', '२ २ ०२ फेब्रुवारी फेब्रु.'],
  19716. ['YYYY YY', '२०१० १०'],
  19717. ['D Do DD', '१४ १४ १४'],
  19718. ['d do dddd ddd dd', '० ० रविवार रवि र'],
  19719. ['DDD DDDo DDDD', '४५ ४५ ०४५'],
  19720. ['w wo ww', '८ ८ ०८'],
  19721. ['h hh', '३ ०३'],
  19722. ['H HH', '१५ १५'],
  19723. ['m mm', '२५ २५'],
  19724. ['s ss', '५० ५०'],
  19725. ['a A', 'दुपारी दुपारी'],
  19726. ['LTS', 'दुपारी ३:२५:५० वाजता'],
  19727. ['L', '१४/०२/२०१०'],
  19728. ['LL', '१४ फेब्रुवारी २०१०'],
  19729. ['LLL', '१४ फेब्रुवारी २०१०, दुपारी ३:२५ वाजता'],
  19730. ['LLLL', 'रविवार, १४ फेब्रुवारी २०१०, दुपारी ३:२५ वाजता'],
  19731. ['l', '१४/२/२०१०'],
  19732. ['ll', '१४ फेब्रु. २०१०'],
  19733. ['lll', '१४ फेब्रु. २०१०, दुपारी ३:२५ वाजता'],
  19734. ['llll', 'रवि, १४ फेब्रु. २०१०, दुपारी ३:२५ वाजता']
  19735. ],
  19736. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  19737. i;
  19738. for (i = 0; i < a.length; i++) {
  19739. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  19740. }
  19741. });
  19742. test('format ordinal', function (assert) {
  19743. assert.equal(moment([2011, 0, 1]).format('DDDo'), '१', '१');
  19744. assert.equal(moment([2011, 0, 2]).format('DDDo'), '२', '२');
  19745. assert.equal(moment([2011, 0, 3]).format('DDDo'), '३', '३');
  19746. assert.equal(moment([2011, 0, 4]).format('DDDo'), '४', '४');
  19747. assert.equal(moment([2011, 0, 5]).format('DDDo'), '५', '५');
  19748. assert.equal(moment([2011, 0, 6]).format('DDDo'), '६', '६');
  19749. assert.equal(moment([2011, 0, 7]).format('DDDo'), '७', '७');
  19750. assert.equal(moment([2011, 0, 8]).format('DDDo'), '८', '८');
  19751. assert.equal(moment([2011, 0, 9]).format('DDDo'), '९', '९');
  19752. assert.equal(moment([2011, 0, 10]).format('DDDo'), '१०', '१०');
  19753. assert.equal(moment([2011, 0, 11]).format('DDDo'), '११', '११');
  19754. assert.equal(moment([2011, 0, 12]).format('DDDo'), '१२', '१२');
  19755. assert.equal(moment([2011, 0, 13]).format('DDDo'), '१३', '१३');
  19756. assert.equal(moment([2011, 0, 14]).format('DDDo'), '१४', '१४');
  19757. assert.equal(moment([2011, 0, 15]).format('DDDo'), '१५', '१५');
  19758. assert.equal(moment([2011, 0, 16]).format('DDDo'), '१६', '१६');
  19759. assert.equal(moment([2011, 0, 17]).format('DDDo'), '१७', '१७');
  19760. assert.equal(moment([2011, 0, 18]).format('DDDo'), '१८', '१८');
  19761. assert.equal(moment([2011, 0, 19]).format('DDDo'), '१९', '१९');
  19762. assert.equal(moment([2011, 0, 20]).format('DDDo'), '२०', '२०');
  19763. assert.equal(moment([2011, 0, 21]).format('DDDo'), '२१', '२१');
  19764. assert.equal(moment([2011, 0, 22]).format('DDDo'), '२२', '२२');
  19765. assert.equal(moment([2011, 0, 23]).format('DDDo'), '२३', '२३');
  19766. assert.equal(moment([2011, 0, 24]).format('DDDo'), '२४', '२४');
  19767. assert.equal(moment([2011, 0, 25]).format('DDDo'), '२५', '२५');
  19768. assert.equal(moment([2011, 0, 26]).format('DDDo'), '२६', '२६');
  19769. assert.equal(moment([2011, 0, 27]).format('DDDo'), '२७', '२७');
  19770. assert.equal(moment([2011, 0, 28]).format('DDDo'), '२८', '२८');
  19771. assert.equal(moment([2011, 0, 29]).format('DDDo'), '२९', '२९');
  19772. assert.equal(moment([2011, 0, 30]).format('DDDo'), '३०', '३०');
  19773. assert.equal(moment([2011, 0, 31]).format('DDDo'), '३१', '३१');
  19774. });
  19775. test('format month', function (assert) {
  19776. var expected = 'जानेवारी जाने._फेब्रुवारी फेब्रु._मार्च मार्च._एप्रिल एप्रि._मे मे._जून जून._जुलै जुलै._ऑगस्ट ऑग._सप्टेंबर सप्टें._ऑक्टोबर ऑक्टो._नोव्हेंबर नोव्हें._डिसेंबर डिसें.'.split('_'), i;
  19777. for (i = 0; i < expected.length; i++) {
  19778. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  19779. }
  19780. });
  19781. test('format week', function (assert) {
  19782. var expected = 'रविवार रवि र_सोमवार सोम सो_मंगळवार मंगळ मं_बुधवार बुध बु_गुरूवार गुरू गु_शुक्रवार शुक्र शु_शनिवार शनि श'.split('_'), i;
  19783. for (i = 0; i < expected.length; i++) {
  19784. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  19785. }
  19786. });
  19787. test('from', function (assert) {
  19788. var start = moment([2007, 1, 28]);
  19789. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'काही सेकंद', '44 seconds = a few seconds');
  19790. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'एक मिनिट', '45 seconds = a minute');
  19791. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'एक मिनिट', '89 seconds = a minute');
  19792. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '२ मिनिटे', '90 seconds = 2 minutes');
  19793. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '४४ मिनिटे', '44 minutes = 44 minutes');
  19794. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'एक तास', '45 minutes = an hour');
  19795. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'एक तास', '89 minutes = an hour');
  19796. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '२ तास', '90 minutes = 2 hours');
  19797. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '५ तास', '5 hours = 5 hours');
  19798. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '२१ तास', '21 hours = 21 hours');
  19799. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'एक दिवस', '22 hours = a day');
  19800. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'एक दिवस', '35 hours = a day');
  19801. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '२ दिवस', '36 hours = 2 days');
  19802. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'एक दिवस', '1 day = a day');
  19803. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '५ दिवस', '5 days = 5 days');
  19804. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '२५ दिवस', '25 days = 25 days');
  19805. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'एक महिना', '26 days = a month');
  19806. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'एक महिना', '30 days = a month');
  19807. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'एक महिना', '43 days = a month');
  19808. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '२ महिने', '46 days = 2 months');
  19809. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '२ महिने', '75 days = 2 months');
  19810. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '३ महिने', '76 days = 3 months');
  19811. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'एक महिना', '1 month = a month');
  19812. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '५ महिने', '5 months = 5 months');
  19813. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'एक वर्ष', '345 days = a year');
  19814. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '२ वर्षे', '548 days = 2 years');
  19815. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'एक वर्ष', '1 year = a year');
  19816. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '५ वर्षे', '5 years = 5 years');
  19817. });
  19818. test('suffix', function (assert) {
  19819. assert.equal(moment(30000).from(0), 'काही सेकंदांमध्ये', 'prefix');
  19820. assert.equal(moment(0).from(30000), 'काही सेकंदांपूर्वी', 'suffix');
  19821. });
  19822. test('now from now', function (assert) {
  19823. assert.equal(moment().fromNow(), 'काही सेकंदांपूर्वी', 'now from now should display as in the past');
  19824. });
  19825. test('fromNow', function (assert) {
  19826. assert.equal(moment().add({s: 30}).fromNow(), 'काही सेकंदांमध्ये', 'in a few seconds');
  19827. assert.equal(moment().add({d: 5}).fromNow(), '५ दिवसांमध्ये', 'in 5 days');
  19828. });
  19829. test('calendar day', function (assert) {
  19830. var a = moment().hours(2).minutes(0).seconds(0);
  19831. assert.equal(moment(a).calendar(), 'आज रात्री २:०० वाजता', 'today at the same time');
  19832. assert.equal(moment(a).add({m: 25}).calendar(), 'आज रात्री २:२५ वाजता', 'Now plus 25 min');
  19833. assert.equal(moment(a).add({h: 3}).calendar(), 'आज सकाळी ५:०० वाजता', 'Now plus 3 hour');
  19834. assert.equal(moment(a).add({d: 1}).calendar(), 'उद्या रात्री २:०० वाजता', 'tomorrow at the same time');
  19835. assert.equal(moment(a).subtract({h: 1}).calendar(), 'आज रात्री १:०० वाजता', 'Now minus 1 hour');
  19836. assert.equal(moment(a).subtract({d: 1}).calendar(), 'काल रात्री २:०० वाजता', 'yesterday at the same time');
  19837. });
  19838. test('calendar next week', function (assert) {
  19839. var i, m;
  19840. for (i = 2; i < 7; i++) {
  19841. m = moment().add({d: i});
  19842. assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days current time');
  19843. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  19844. assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days beginning of day');
  19845. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  19846. assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days end of day');
  19847. }
  19848. });
  19849. test('calendar last week', function (assert) {
  19850. var i, m;
  19851. for (i = 2; i < 7; i++) {
  19852. m = moment().subtract({d: i});
  19853. assert.equal(m.calendar(), m.format('[मागील] dddd[,] LT'), 'Today - ' + i + ' days current time');
  19854. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  19855. assert.equal(m.calendar(), m.format('[मागील] dddd[,] LT'), 'Today - ' + i + ' days beginning of day');
  19856. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  19857. assert.equal(m.calendar(), m.format('[मागील] dddd[,] LT'), 'Today - ' + i + ' days end of day');
  19858. }
  19859. });
  19860. test('calendar all else', function (assert) {
  19861. var weeksAgo = moment().subtract({w: 1}),
  19862. weeksFromNow = moment().add({w: 1});
  19863. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  19864. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  19865. weeksAgo = moment().subtract({w: 2});
  19866. weeksFromNow = moment().add({w: 2});
  19867. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  19868. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  19869. });
  19870. test('meridiem', function (assert) {
  19871. assert.equal(moment([2011, 2, 23, 2, 30]).format('a'), 'रात्री', 'before dawn');
  19872. assert.equal(moment([2011, 2, 23, 9, 30]).format('a'), 'सकाळी', 'morning');
  19873. assert.equal(moment([2011, 2, 23, 14, 30]).format('a'), 'दुपारी', 'during day');
  19874. assert.equal(moment([2011, 2, 23, 17, 30]).format('a'), 'सायंकाळी', 'evening');
  19875. assert.equal(moment([2011, 2, 23, 19, 30]).format('a'), 'सायंकाळी', 'late evening');
  19876. assert.equal(moment([2011, 2, 23, 21, 20]).format('a'), 'रात्री', 'night');
  19877. assert.equal(moment([2011, 2, 23, 2, 30]).format('A'), 'रात्री', 'before dawn');
  19878. assert.equal(moment([2011, 2, 23, 9, 30]).format('A'), 'सकाळी', 'morning');
  19879. assert.equal(moment([2011, 2, 23, 14, 30]).format('A'), 'दुपारी', ' during day');
  19880. assert.equal(moment([2011, 2, 23, 17, 30]).format('A'), 'सायंकाळी', 'evening');
  19881. assert.equal(moment([2011, 2, 23, 19, 30]).format('A'), 'सायंकाळी', 'late evening');
  19882. assert.equal(moment([2011, 2, 23, 21, 20]).format('A'), 'रात्री', 'night');
  19883. });
  19884. test('weeks year starting sunday', function (assert) {
  19885. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  19886. assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1');
  19887. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  19888. assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2');
  19889. assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 3');
  19890. });
  19891. test('weeks year starting monday', function (assert) {
  19892. assert.equal(moment([2006, 11, 31]).week(), 1, 'Dec 31 2006 should be week 1');
  19893. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  19894. assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1');
  19895. assert.equal(moment([2007, 0, 7]).week(), 2, 'Jan 7 2007 should be week 2');
  19896. assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2');
  19897. assert.equal(moment([2007, 0, 14]).week(), 3, 'Jan 14 2007 should be week 3');
  19898. });
  19899. test('weeks year starting tuesday', function (assert) {
  19900. assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52');
  19901. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  19902. assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1');
  19903. assert.equal(moment([2008, 0, 6]).week(), 2, 'Jan 6 2008 should be week 2');
  19904. assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2');
  19905. assert.equal(moment([2008, 0, 13]).week(), 3, 'Jan 13 2008 should be week 3');
  19906. });
  19907. test('weeks year starting wednesday', function (assert) {
  19908. assert.equal(moment([2002, 11, 29]).week(), 1, 'Dec 29 2002 should be week 1');
  19909. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  19910. assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1');
  19911. assert.equal(moment([2003, 0, 5]).week(), 2, 'Jan 5 2003 should be week 2');
  19912. assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2');
  19913. assert.equal(moment([2003, 0, 12]).week(), 3, 'Jan 12 2003 should be week 3');
  19914. });
  19915. test('weeks year starting thursday', function (assert) {
  19916. assert.equal(moment([2008, 11, 28]).week(), 1, 'Dec 28 2008 should be week 1');
  19917. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  19918. assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1');
  19919. assert.equal(moment([2009, 0, 4]).week(), 2, 'Jan 4 2009 should be week 2');
  19920. assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2');
  19921. assert.equal(moment([2009, 0, 11]).week(), 3, 'Jan 11 2009 should be week 3');
  19922. });
  19923. test('weeks year starting friday', function (assert) {
  19924. assert.equal(moment([2009, 11, 27]).week(), 1, 'Dec 27 2009 should be week 1');
  19925. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  19926. assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 should be week 1');
  19927. assert.equal(moment([2010, 0, 3]).week(), 2, 'Jan 3 2010 should be week 2');
  19928. assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 should be week 2');
  19929. assert.equal(moment([2010, 0, 10]).week(), 3, 'Jan 10 2010 should be week 3');
  19930. });
  19931. test('weeks year starting saturday', function (assert) {
  19932. assert.equal(moment([2010, 11, 26]).week(), 1, 'Dec 26 2010 should be week 1');
  19933. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  19934. assert.equal(moment([2011, 0, 2]).week(), 2, 'Jan 2 2011 should be week 2');
  19935. assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2');
  19936. assert.equal(moment([2011, 0, 9]).week(), 3, 'Jan 9 2011 should be week 3');
  19937. });
  19938. test('weeks year starting sunday formatted', function (assert) {
  19939. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '१ ०१ १', 'Jan 1 2012 should be week 1');
  19940. assert.equal(moment([2012, 0, 7]).format('w ww wo'), '१ ०१ १', 'Jan 7 2012 should be week 1');
  19941. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '२ ०२ २', 'Jan 8 2012 should be week 2');
  19942. assert.equal(moment([2012, 0, 14]).format('w ww wo'), '२ ०२ २', 'Jan 14 2012 should be week 2');
  19943. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '३ ०३ ३', 'Jan 15 2012 should be week 3');
  19944. });
  19945. test('lenient ordinal parsing', function (assert) {
  19946. var i, ordinalStr, testMoment;
  19947. for (i = 1; i <= 31; ++i) {
  19948. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  19949. testMoment = moment(ordinalStr, 'YYYY MM Do');
  19950. assert.equal(testMoment.year(), 2014,
  19951. 'lenient ordinal parsing ' + i + ' year check');
  19952. assert.equal(testMoment.month(), 0,
  19953. 'lenient ordinal parsing ' + i + ' month check');
  19954. assert.equal(testMoment.date(), i,
  19955. 'lenient ordinal parsing ' + i + ' date check');
  19956. }
  19957. });
  19958. test('lenient ordinal parsing of number', function (assert) {
  19959. var i, testMoment;
  19960. for (i = 1; i <= 31; ++i) {
  19961. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  19962. assert.equal(testMoment.year(), 2014,
  19963. 'lenient ordinal parsing of number ' + i + ' year check');
  19964. assert.equal(testMoment.month(), 0,
  19965. 'lenient ordinal parsing of number ' + i + ' month check');
  19966. assert.equal(testMoment.date(), i,
  19967. 'lenient ordinal parsing of number ' + i + ' date check');
  19968. }
  19969. });
  19970. test('meridiem invariant', function (assert) {
  19971. var h, m, t1, t2;
  19972. for (h = 0; h < 24; ++h) {
  19973. for (m = 0; m < 60; m += 15) {
  19974. t1 = moment.utc([2000, 0, 1, h, m]);
  19975. t2 = moment(t1.format('A h:mm'), 'A h:mm');
  19976. assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
  19977. 'meridiem at ' + t1.format('HH:mm'));
  19978. }
  19979. }
  19980. });
  19981. test('strict ordinal parsing', function (assert) {
  19982. var i, ordinalStr, testMoment;
  19983. for (i = 1; i <= 31; ++i) {
  19984. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  19985. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  19986. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  19987. }
  19988. });
  19989. }));
  19990. ;(function (global, factory) {
  19991. typeof exports === 'object' && typeof module !== 'undefined'
  19992. && typeof require === 'function' ? factory(require('../../moment')) :
  19993. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  19994. factory(global.moment)
  19995. }(this, function (moment) { 'use strict';
  19996. /*global QUnit:false*/
  19997. var test = QUnit.test;
  19998. var expect = QUnit.expect;
  19999. function module (name, lifecycle) {
  20000. QUnit.module(name, {
  20001. setup : function () {
  20002. moment.locale('en');
  20003. moment.createFromInputFallback = function (config) {
  20004. throw new Error('input not handled by moment: ' + config._i);
  20005. };
  20006. if (lifecycle && lifecycle.setup) {
  20007. lifecycle.setup();
  20008. }
  20009. },
  20010. teardown : function () {
  20011. if (lifecycle && lifecycle.teardown) {
  20012. lifecycle.teardown();
  20013. }
  20014. }
  20015. });
  20016. }
  20017. function localeModule (name, lifecycle) {
  20018. QUnit.module('locale:' + name, {
  20019. setup : function () {
  20020. moment.locale(name);
  20021. moment.createFromInputFallback = function (config) {
  20022. throw new Error('input not handled by moment: ' + config._i);
  20023. };
  20024. if (lifecycle && lifecycle.setup) {
  20025. lifecycle.setup();
  20026. }
  20027. },
  20028. teardown : function () {
  20029. moment.locale('en');
  20030. if (lifecycle && lifecycle.teardown) {
  20031. lifecycle.teardown();
  20032. }
  20033. }
  20034. });
  20035. }
  20036. localeModule('ms-my');
  20037. test('parse', function (assert) {
  20038. var i,
  20039. tests = 'Januari Jan_Februari Feb_Mac Mac_April Apr_Mei Mei_Jun Jun_Julai Jul_Ogos Ogs_September Sep_Oktober Okt_November Nov_Disember Dis'.split('_');
  20040. function equalTest(input, mmm, i) {
  20041. assert.equal(moment(input, mmm).month(), i, input + ' sepatutnya bulan ' + (i + 1));
  20042. }
  20043. for (i = 0; i < 12; i++) {
  20044. tests[i] = tests[i].split(' ');
  20045. equalTest(tests[i][0], 'MMM', i);
  20046. equalTest(tests[i][1], 'MMM', i);
  20047. equalTest(tests[i][0], 'MMMM', i);
  20048. equalTest(tests[i][1], 'MMMM', i);
  20049. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  20050. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  20051. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  20052. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  20053. }
  20054. });
  20055. test('format', function (assert) {
  20056. var a = [
  20057. ['dddd, MMMM Do YYYY, h:mm:ss a', 'Ahad, Februari 14 2010, 3:25:50 petang'],
  20058. ['ddd, hA', 'Ahd, 3petang'],
  20059. ['M Mo MM MMMM MMM', '2 2 02 Februari Feb'],
  20060. ['YYYY YY', '2010 10'],
  20061. ['D Do DD', '14 14 14'],
  20062. ['d do dddd ddd dd', '0 0 Ahad Ahd Ah'],
  20063. ['DDD DDDo DDDD', '45 45 045'],
  20064. ['w wo ww', '7 7 07'],
  20065. ['h hh', '3 03'],
  20066. ['H HH', '15 15'],
  20067. ['m mm', '25 25'],
  20068. ['s ss', '50 50'],
  20069. ['a A', 'petang petang'],
  20070. ['[hari] [ke] DDDo [tahun] ini', 'hari ke 45 tahun ini'],
  20071. ['LTS', '15.25.50'],
  20072. ['L', '14/02/2010'],
  20073. ['LL', '14 Februari 2010'],
  20074. ['LLL', '14 Februari 2010 pukul 15.25'],
  20075. ['LLLL', 'Ahad, 14 Februari 2010 pukul 15.25'],
  20076. ['l', '14/2/2010'],
  20077. ['ll', '14 Feb 2010'],
  20078. ['lll', '14 Feb 2010 pukul 15.25'],
  20079. ['llll', 'Ahd, 14 Feb 2010 pukul 15.25']
  20080. ],
  20081. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  20082. i;
  20083. for (i = 0; i < a.length; i++) {
  20084. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  20085. }
  20086. });
  20087. test('format ordinal', function (assert) {
  20088. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1');
  20089. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2');
  20090. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3');
  20091. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4');
  20092. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5');
  20093. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6');
  20094. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7');
  20095. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8');
  20096. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9');
  20097. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10');
  20098. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11');
  20099. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12');
  20100. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13');
  20101. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14');
  20102. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15');
  20103. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16');
  20104. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17');
  20105. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18');
  20106. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19');
  20107. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20');
  20108. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21');
  20109. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22');
  20110. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23');
  20111. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24');
  20112. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25');
  20113. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26');
  20114. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27');
  20115. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28');
  20116. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29');
  20117. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30');
  20118. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31');
  20119. });
  20120. test('format month', function (assert) {
  20121. var i,
  20122. expected = 'Januari Jan_Februari Feb_Mac Mac_April Apr_Mei Mei_Jun Jun_Julai Jul_Ogos Ogs_September Sep_Oktober Okt_November Nov_Disember Dis'.split('_');
  20123. for (i = 0; i < expected.length; i++) {
  20124. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  20125. }
  20126. });
  20127. test('format week', function (assert) {
  20128. var i,
  20129. expected = 'Ahad Ahd Ah_Isnin Isn Is_Selasa Sel Sl_Rabu Rab Rb_Khamis Kha Km_Jumaat Jum Jm_Sabtu Sab Sb'.split('_');
  20130. for (i = 0; i < expected.length; i++) {
  20131. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  20132. }
  20133. });
  20134. test('from', function (assert) {
  20135. var start = moment([2007, 1, 28]);
  20136. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'beberapa saat', '44 saat = beberapa saat');
  20137. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'seminit', '45 saat = seminit');
  20138. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'seminit', '89 saat = seminit');
  20139. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minit', '90 saat = 2 minit');
  20140. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minit', '44 minit = 44 minit');
  20141. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'sejam', '45 minit = sejam');
  20142. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'sejam', '89 minit = sejam');
  20143. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 jam', '90 minit = 2 jam');
  20144. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 jam', '5 jam = 5 jam');
  20145. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 jam', '21 jam = 21 jam');
  20146. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'sehari', '22 jam = sehari');
  20147. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'sehari', '35 jam = sehari');
  20148. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 hari', '36 jam = 2 hari');
  20149. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'sehari', '1 hari = sehari');
  20150. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 hari', '5 hari = 5 hari');
  20151. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 hari', '25 hari = 25 hari');
  20152. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'sebulan', '26 hari = sebulan');
  20153. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'sebulan', '30 hari = sebulan');
  20154. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'sebulan', '45 hari = sebulan');
  20155. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 bulan', '46 hari = 2 bulan');
  20156. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 bulan', '75 hari = 2 bulan');
  20157. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 bulan', '76 hari = 3 bulan');
  20158. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'sebulan', '1 bulan = sebulan');
  20159. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 bulan', '5 bulan = 5 bulan');
  20160. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'setahun', '345 hari = setahun');
  20161. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 tahun', '548 hari = 2 tahun');
  20162. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'setahun', '1 tahun = setahun');
  20163. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 tahun', '5 tahun = 5 tahun');
  20164. });
  20165. test('suffix', function (assert) {
  20166. assert.equal(moment(30000).from(0), 'dalam beberapa saat', 'prefix');
  20167. assert.equal(moment(0).from(30000), 'beberapa saat yang lepas', 'suffix');
  20168. });
  20169. test('now from now', function (assert) {
  20170. assert.equal(moment().fromNow(), 'beberapa saat yang lepas', 'waktu sekarang dari sekarang sepatutnya menunjukkan sebagai telah lepas');
  20171. });
  20172. test('fromNow', function (assert) {
  20173. assert.equal(moment().add({s: 30}).fromNow(), 'dalam beberapa saat', 'dalam beberapa saat');
  20174. assert.equal(moment().add({d: 5}).fromNow(), 'dalam 5 hari', 'dalam 5 hari');
  20175. });
  20176. test('calendar day', function (assert) {
  20177. var a = moment().hours(2).minutes(0).seconds(0);
  20178. assert.equal(moment(a).calendar(), 'Hari ini pukul 02.00', 'hari ini pada waktu yang sama');
  20179. assert.equal(moment(a).add({m: 25}).calendar(), 'Hari ini pukul 02.25', 'Sekarang tambah 25 minit');
  20180. assert.equal(moment(a).add({h: 1}).calendar(), 'Hari ini pukul 03.00', 'Sekarang tambah 1 jam');
  20181. assert.equal(moment(a).add({d: 1}).calendar(), 'Esok pukul 02.00', 'esok pada waktu yang sama');
  20182. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Hari ini pukul 01.00', 'Sekarang tolak 1 jam');
  20183. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Kelmarin pukul 02.00', 'kelmarin pada waktu yang sama');
  20184. });
  20185. test('calendar next week', function (assert) {
  20186. var i, m;
  20187. for (i = 2; i < 7; i++) {
  20188. m = moment().add({d: i});
  20189. assert.equal(m.calendar(), m.format('dddd [pukul] LT'), 'Hari ini + ' + i + ' hari waktu sekarang');
  20190. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  20191. assert.equal(m.calendar(), m.format('dddd [pukul] LT'), 'Hari ini + ' + i + ' hari permulaan hari');
  20192. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  20193. assert.equal(m.calendar(), m.format('dddd [pukul] LT'), 'Hari ini + ' + i + ' hari tamat hari');
  20194. }
  20195. });
  20196. test('calendar last week', function (assert) {
  20197. var i, m;
  20198. for (i = 2; i < 7; i++) {
  20199. m = moment().subtract({d: i});
  20200. assert.equal(m.calendar(), m.format('dddd [lepas] [pukul] LT'), 'Hari ini - ' + i + ' hari waktu sekarang');
  20201. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  20202. assert.equal(m.calendar(), m.format('dddd [lepas] [pukul] LT'), 'Hari ini - ' + i + ' hari permulaan hari');
  20203. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  20204. assert.equal(m.calendar(), m.format('dddd [lepas] [pukul] LT'), 'Hari ini - ' + i + ' hari tamat hari');
  20205. }
  20206. });
  20207. test('calendar all else', function (assert) {
  20208. var weeksAgo = moment().subtract({w: 1}),
  20209. weeksFromNow = moment().add({w: 1});
  20210. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 minggu lepas');
  20211. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'dalam 1 minggu');
  20212. weeksAgo = moment().subtract({w: 2});
  20213. weeksFromNow = moment().add({w: 2});
  20214. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 minggu lepas');
  20215. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'dalam 2 minggu');
  20216. });
  20217. test('weeks year starting sunday', function (assert) {
  20218. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 sepatutnya minggu 1');
  20219. assert.equal(moment([2012, 0, 7]).week(), 2, 'Jan 7 2012 sepatutnya minggu 2');
  20220. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 sepatutnya minggu 2');
  20221. assert.equal(moment([2012, 0, 14]).week(), 3, 'Jan 14 2012 sepatutnya minggu 3');
  20222. assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 sepatutnya minggu 3');
  20223. });
  20224. test('weeks year starting monday', function (assert) {
  20225. assert.equal(moment([2006, 11, 31]).week(), 53, 'Dec 31 2006 sepatutnya minggu 53');
  20226. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 sepatutnya minggu 1');
  20227. assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 sepatutnya minggu 1');
  20228. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 sepatutnya minggu 1');
  20229. assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 sepatutnya minggu 2');
  20230. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 sepatutnya minggu 2');
  20231. });
  20232. test('weeks year starting tuesday', function (assert) {
  20233. assert.equal(moment([2007, 11, 30]).week(), 52, 'Dec 30 2007 sepatutnya minggu 52');
  20234. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 sepatutnya minggu 1');
  20235. assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 sepatutnya minggu 1');
  20236. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 sepatutnya minggu 1');
  20237. assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 sepatutnya minggu 2');
  20238. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 sepatutnya minggu 2');
  20239. });
  20240. test('weeks year starting wednesday', function (assert) {
  20241. assert.equal(moment([2002, 11, 29]).week(), 52, 'Dec 29 2002 sepatutnya minggu 52');
  20242. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 sepatutnya minggu 1');
  20243. assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 sepatutnya minggu 1');
  20244. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 sepatutnya minggu 1');
  20245. assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 sepatutnya minggu 2');
  20246. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 sepatutnya minggu 2');
  20247. });
  20248. test('weeks year starting thursday', function (assert) {
  20249. assert.equal(moment([2008, 11, 28]).week(), 52, 'Dec 28 2008 sepatutnya minggu 52');
  20250. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 sepatutnya minggu 1');
  20251. assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 sepatutnya minggu 1');
  20252. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 sepatutnya minggu 1');
  20253. assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 sepatutnya minggu 2');
  20254. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 sepatutnya minggu 2');
  20255. });
  20256. test('weeks year starting friday', function (assert) {
  20257. assert.equal(moment([2009, 11, 27]).week(), 52, 'Dec 27 2009 sepatutnya minggu 52');
  20258. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 sepatutnya minggu 1');
  20259. assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 sepatutnya minggu 1');
  20260. assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 sepatutnya minggu 1');
  20261. assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 sepatutnya minggu 2');
  20262. assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 sepatutnya minggu 2');
  20263. });
  20264. test('weeks year starting saturday', function (assert) {
  20265. assert.equal(moment([2010, 11, 26]).week(), 52, 'Dec 26 2010 sepatutnya minggu 52');
  20266. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 sepatutnya minggu 1');
  20267. assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 sepatutnya minggu 1');
  20268. assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 sepatutnya minggu 2');
  20269. assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 sepatutnya minggu 2');
  20270. });
  20271. test('weeks year starting sunday format', function (assert) {
  20272. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1', 'Jan 1 2012 sepatutnya minggu 1');
  20273. assert.equal(moment([2012, 0, 7]).format('w ww wo'), '2 02 2', 'Jan 7 2012 sepatutnya minggu 2');
  20274. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2', 'Jan 8 2012 sepatutnya minggu 2');
  20275. assert.equal(moment([2012, 0, 14]).format('w ww wo'), '3 03 3', 'Jan 14 2012 sepatutnya minggu 3');
  20276. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3', 'Jan 15 2012 sepatutnya minggu 3');
  20277. });
  20278. test('lenient ordinal parsing', function (assert) {
  20279. var i, ordinalStr, testMoment;
  20280. for (i = 1; i <= 31; ++i) {
  20281. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  20282. testMoment = moment(ordinalStr, 'YYYY MM Do');
  20283. assert.equal(testMoment.year(), 2014,
  20284. 'lenient ordinal parsing ' + i + ' year check');
  20285. assert.equal(testMoment.month(), 0,
  20286. 'lenient ordinal parsing ' + i + ' month check');
  20287. assert.equal(testMoment.date(), i,
  20288. 'lenient ordinal parsing ' + i + ' date check');
  20289. }
  20290. });
  20291. test('meridiem invariant', function (assert) {
  20292. var h, m, t1, t2;
  20293. for (h = 0; h < 24; ++h) {
  20294. for (m = 0; m < 60; m += 15) {
  20295. t1 = moment.utc([2000, 0, 1, h, m]);
  20296. t2 = moment(t1.format('A h:mm'), 'A h:mm');
  20297. assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
  20298. 'meridiem at ' + t1.format('HH:mm'));
  20299. }
  20300. }
  20301. });
  20302. test('lenient ordinal parsing of number', function (assert) {
  20303. var i, testMoment;
  20304. for (i = 1; i <= 31; ++i) {
  20305. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  20306. assert.equal(testMoment.year(), 2014,
  20307. 'lenient ordinal parsing of number ' + i + ' year check');
  20308. assert.equal(testMoment.month(), 0,
  20309. 'lenient ordinal parsing of number ' + i + ' month check');
  20310. assert.equal(testMoment.date(), i,
  20311. 'lenient ordinal parsing of number ' + i + ' date check');
  20312. }
  20313. });
  20314. test('strict ordinal parsing', function (assert) {
  20315. var i, ordinalStr, testMoment;
  20316. for (i = 1; i <= 31; ++i) {
  20317. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  20318. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  20319. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  20320. }
  20321. });
  20322. }));
  20323. ;(function (global, factory) {
  20324. typeof exports === 'object' && typeof module !== 'undefined'
  20325. && typeof require === 'function' ? factory(require('../../moment')) :
  20326. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  20327. factory(global.moment)
  20328. }(this, function (moment) { 'use strict';
  20329. /*global QUnit:false*/
  20330. var test = QUnit.test;
  20331. var expect = QUnit.expect;
  20332. function module (name, lifecycle) {
  20333. QUnit.module(name, {
  20334. setup : function () {
  20335. moment.locale('en');
  20336. moment.createFromInputFallback = function (config) {
  20337. throw new Error('input not handled by moment: ' + config._i);
  20338. };
  20339. if (lifecycle && lifecycle.setup) {
  20340. lifecycle.setup();
  20341. }
  20342. },
  20343. teardown : function () {
  20344. if (lifecycle && lifecycle.teardown) {
  20345. lifecycle.teardown();
  20346. }
  20347. }
  20348. });
  20349. }
  20350. function localeModule (name, lifecycle) {
  20351. QUnit.module('locale:' + name, {
  20352. setup : function () {
  20353. moment.locale(name);
  20354. moment.createFromInputFallback = function (config) {
  20355. throw new Error('input not handled by moment: ' + config._i);
  20356. };
  20357. if (lifecycle && lifecycle.setup) {
  20358. lifecycle.setup();
  20359. }
  20360. },
  20361. teardown : function () {
  20362. moment.locale('en');
  20363. if (lifecycle && lifecycle.teardown) {
  20364. lifecycle.teardown();
  20365. }
  20366. }
  20367. });
  20368. }
  20369. localeModule('ms');
  20370. test('parse', function (assert) {
  20371. var i,
  20372. tests = 'Januari Jan_Februari Feb_Mac Mac_April Apr_Mei Mei_Jun Jun_Julai Jul_Ogos Ogs_September Sep_Oktober Okt_November Nov_Disember Dis'.split('_');
  20373. function equalTest(input, mmm, i) {
  20374. assert.equal(moment(input, mmm).month(), i, input + ' sepatutnya bulan ' + (i + 1));
  20375. }
  20376. for (i = 0; i < 12; i++) {
  20377. tests[i] = tests[i].split(' ');
  20378. equalTest(tests[i][0], 'MMM', i);
  20379. equalTest(tests[i][1], 'MMM', i);
  20380. equalTest(tests[i][0], 'MMMM', i);
  20381. equalTest(tests[i][1], 'MMMM', i);
  20382. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  20383. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  20384. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  20385. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  20386. }
  20387. });
  20388. test('format', function (assert) {
  20389. var a = [
  20390. ['dddd, MMMM Do YYYY, h:mm:ss a', 'Ahad, Februari 14 2010, 3:25:50 petang'],
  20391. ['ddd, hA', 'Ahd, 3petang'],
  20392. ['M Mo MM MMMM MMM', '2 2 02 Februari Feb'],
  20393. ['YYYY YY', '2010 10'],
  20394. ['D Do DD', '14 14 14'],
  20395. ['d do dddd ddd dd', '0 0 Ahad Ahd Ah'],
  20396. ['DDD DDDo DDDD', '45 45 045'],
  20397. ['w wo ww', '7 7 07'],
  20398. ['h hh', '3 03'],
  20399. ['H HH', '15 15'],
  20400. ['m mm', '25 25'],
  20401. ['s ss', '50 50'],
  20402. ['a A', 'petang petang'],
  20403. ['[hari] [ke] DDDo [tahun] ini', 'hari ke 45 tahun ini'],
  20404. ['LTS', '15.25.50'],
  20405. ['L', '14/02/2010'],
  20406. ['LL', '14 Februari 2010'],
  20407. ['LLL', '14 Februari 2010 pukul 15.25'],
  20408. ['LLLL', 'Ahad, 14 Februari 2010 pukul 15.25'],
  20409. ['l', '14/2/2010'],
  20410. ['ll', '14 Feb 2010'],
  20411. ['lll', '14 Feb 2010 pukul 15.25'],
  20412. ['llll', 'Ahd, 14 Feb 2010 pukul 15.25']
  20413. ],
  20414. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  20415. i;
  20416. for (i = 0; i < a.length; i++) {
  20417. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  20418. }
  20419. });
  20420. test('format ordinal', function (assert) {
  20421. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1');
  20422. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2');
  20423. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3');
  20424. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4');
  20425. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5');
  20426. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6');
  20427. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7');
  20428. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8');
  20429. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9');
  20430. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10');
  20431. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11');
  20432. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12');
  20433. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13');
  20434. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14');
  20435. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15');
  20436. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16');
  20437. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17');
  20438. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18');
  20439. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19');
  20440. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20');
  20441. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21');
  20442. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22');
  20443. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23');
  20444. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24');
  20445. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25');
  20446. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26');
  20447. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27');
  20448. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28');
  20449. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29');
  20450. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30');
  20451. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31');
  20452. });
  20453. test('format month', function (assert) {
  20454. var i,
  20455. expected = 'Januari Jan_Februari Feb_Mac Mac_April Apr_Mei Mei_Jun Jun_Julai Jul_Ogos Ogs_September Sep_Oktober Okt_November Nov_Disember Dis'.split('_');
  20456. for (i = 0; i < expected.length; i++) {
  20457. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  20458. }
  20459. });
  20460. test('format week', function (assert) {
  20461. var i,
  20462. expected = 'Ahad Ahd Ah_Isnin Isn Is_Selasa Sel Sl_Rabu Rab Rb_Khamis Kha Km_Jumaat Jum Jm_Sabtu Sab Sb'.split('_');
  20463. for (i = 0; i < expected.length; i++) {
  20464. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  20465. }
  20466. });
  20467. test('from', function (assert) {
  20468. var start = moment([2007, 1, 28]);
  20469. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'beberapa saat', '44 saat = beberapa saat');
  20470. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'seminit', '45 saat = seminit');
  20471. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'seminit', '89 saat = seminit');
  20472. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minit', '90 saat = 2 minit');
  20473. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minit', '44 minit = 44 minit');
  20474. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'sejam', '45 minit = sejam');
  20475. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'sejam', '89 minit = sejam');
  20476. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 jam', '90 minit = 2 jam');
  20477. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 jam', '5 jam = 5 jam');
  20478. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 jam', '21 jam = 21 jam');
  20479. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'sehari', '22 jam = sehari');
  20480. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'sehari', '35 jam = sehari');
  20481. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 hari', '36 jam = 2 hari');
  20482. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'sehari', '1 hari = sehari');
  20483. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 hari', '5 hari = 5 hari');
  20484. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 hari', '25 hari = 25 hari');
  20485. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'sebulan', '26 hari = sebulan');
  20486. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'sebulan', '30 hari = sebulan');
  20487. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'sebulan', '45 hari = sebulan');
  20488. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 bulan', '46 hari = 2 bulan');
  20489. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 bulan', '75 hari = 2 bulan');
  20490. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 bulan', '76 hari = 3 bulan');
  20491. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'sebulan', '1 bulan = sebulan');
  20492. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 bulan', '5 bulan = 5 bulan');
  20493. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'setahun', '345 hari = setahun');
  20494. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 tahun', '548 hari = 2 tahun');
  20495. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'setahun', '1 tahun = setahun');
  20496. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 tahun', '5 tahun = 5 tahun');
  20497. });
  20498. test('suffix', function (assert) {
  20499. assert.equal(moment(30000).from(0), 'dalam beberapa saat', 'prefix');
  20500. assert.equal(moment(0).from(30000), 'beberapa saat yang lepas', 'suffix');
  20501. });
  20502. test('now from now', function (assert) {
  20503. assert.equal(moment().fromNow(), 'beberapa saat yang lepas', 'waktu sekarang dari sekarang sepatutnya menunjukkan sebagai telah lepas');
  20504. });
  20505. test('fromNow', function (assert) {
  20506. assert.equal(moment().add({s: 30}).fromNow(), 'dalam beberapa saat', 'dalam beberapa saat');
  20507. assert.equal(moment().add({d: 5}).fromNow(), 'dalam 5 hari', 'dalam 5 hari');
  20508. });
  20509. test('calendar day', function (assert) {
  20510. var a = moment().hours(2).minutes(0).seconds(0);
  20511. assert.equal(moment(a).calendar(), 'Hari ini pukul 02.00', 'hari ini pada waktu yang sama');
  20512. assert.equal(moment(a).add({m: 25}).calendar(), 'Hari ini pukul 02.25', 'Sekarang tambah 25 minit');
  20513. assert.equal(moment(a).add({h: 1}).calendar(), 'Hari ini pukul 03.00', 'Sekarang tambah 1 jam');
  20514. assert.equal(moment(a).add({d: 1}).calendar(), 'Esok pukul 02.00', 'esok pada waktu yang sama');
  20515. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Hari ini pukul 01.00', 'Sekarang tolak 1 jam');
  20516. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Kelmarin pukul 02.00', 'kelmarin pada waktu yang sama');
  20517. });
  20518. test('calendar next week', function (assert) {
  20519. var i, m;
  20520. for (i = 2; i < 7; i++) {
  20521. m = moment().add({d: i});
  20522. assert.equal(m.calendar(), m.format('dddd [pukul] LT'), 'Hari ini + ' + i + ' hari waktu sekarang');
  20523. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  20524. assert.equal(m.calendar(), m.format('dddd [pukul] LT'), 'Hari ini + ' + i + ' hari permulaan hari');
  20525. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  20526. assert.equal(m.calendar(), m.format('dddd [pukul] LT'), 'Hari ini + ' + i + ' hari tamat hari');
  20527. }
  20528. });
  20529. test('calendar last week', function (assert) {
  20530. var i, m;
  20531. for (i = 2; i < 7; i++) {
  20532. m = moment().subtract({d: i});
  20533. assert.equal(m.calendar(), m.format('dddd [lepas] [pukul] LT'), 'Hari ini - ' + i + ' hari waktu sekarang');
  20534. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  20535. assert.equal(m.calendar(), m.format('dddd [lepas] [pukul] LT'), 'Hari ini - ' + i + ' hari permulaan hari');
  20536. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  20537. assert.equal(m.calendar(), m.format('dddd [lepas] [pukul] LT'), 'Hari ini - ' + i + ' hari tamat hari');
  20538. }
  20539. });
  20540. test('calendar all else', function (assert) {
  20541. var weeksAgo = moment().subtract({w: 1}),
  20542. weeksFromNow = moment().add({w: 1});
  20543. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 minggu lepas');
  20544. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'dalam 1 minggu');
  20545. weeksAgo = moment().subtract({w: 2});
  20546. weeksFromNow = moment().add({w: 2});
  20547. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 minggu lepas');
  20548. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'dalam 2 minggu');
  20549. });
  20550. test('weeks year starting sunday', function (assert) {
  20551. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 sepatutnya minggu 1');
  20552. assert.equal(moment([2012, 0, 7]).week(), 2, 'Jan 7 2012 sepatutnya minggu 2');
  20553. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 sepatutnya minggu 2');
  20554. assert.equal(moment([2012, 0, 14]).week(), 3, 'Jan 14 2012 sepatutnya minggu 3');
  20555. assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 sepatutnya minggu 3');
  20556. });
  20557. test('weeks year starting monday', function (assert) {
  20558. assert.equal(moment([2006, 11, 31]).week(), 53, 'Dec 31 2006 sepatutnya minggu 53');
  20559. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 sepatutnya minggu 1');
  20560. assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 sepatutnya minggu 1');
  20561. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 sepatutnya minggu 1');
  20562. assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 sepatutnya minggu 2');
  20563. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 sepatutnya minggu 2');
  20564. });
  20565. test('weeks year starting tuesday', function (assert) {
  20566. assert.equal(moment([2007, 11, 30]).week(), 52, 'Dec 30 2007 sepatutnya minggu 52');
  20567. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 sepatutnya minggu 1');
  20568. assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 sepatutnya minggu 1');
  20569. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 sepatutnya minggu 1');
  20570. assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 sepatutnya minggu 2');
  20571. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 sepatutnya minggu 2');
  20572. });
  20573. test('weeks year starting wednesday', function (assert) {
  20574. assert.equal(moment([2002, 11, 29]).week(), 52, 'Dec 29 2002 sepatutnya minggu 52');
  20575. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 sepatutnya minggu 1');
  20576. assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 sepatutnya minggu 1');
  20577. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 sepatutnya minggu 1');
  20578. assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 sepatutnya minggu 2');
  20579. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 sepatutnya minggu 2');
  20580. });
  20581. test('weeks year starting thursday', function (assert) {
  20582. assert.equal(moment([2008, 11, 28]).week(), 52, 'Dec 28 2008 sepatutnya minggu 52');
  20583. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 sepatutnya minggu 1');
  20584. assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 sepatutnya minggu 1');
  20585. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 sepatutnya minggu 1');
  20586. assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 sepatutnya minggu 2');
  20587. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 sepatutnya minggu 2');
  20588. });
  20589. test('weeks year starting friday', function (assert) {
  20590. assert.equal(moment([2009, 11, 27]).week(), 52, 'Dec 27 2009 sepatutnya minggu 52');
  20591. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 sepatutnya minggu 1');
  20592. assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 sepatutnya minggu 1');
  20593. assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 sepatutnya minggu 1');
  20594. assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 sepatutnya minggu 2');
  20595. assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 sepatutnya minggu 2');
  20596. });
  20597. test('weeks year starting saturday', function (assert) {
  20598. assert.equal(moment([2010, 11, 26]).week(), 52, 'Dec 26 2010 sepatutnya minggu 52');
  20599. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 sepatutnya minggu 1');
  20600. assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 sepatutnya minggu 1');
  20601. assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 sepatutnya minggu 2');
  20602. assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 sepatutnya minggu 2');
  20603. });
  20604. test('weeks year starting sunday format', function (assert) {
  20605. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1', 'Jan 1 2012 sepatutnya minggu 1');
  20606. assert.equal(moment([2012, 0, 7]).format('w ww wo'), '2 02 2', 'Jan 7 2012 sepatutnya minggu 2');
  20607. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2', 'Jan 8 2012 sepatutnya minggu 2');
  20608. assert.equal(moment([2012, 0, 14]).format('w ww wo'), '3 03 3', 'Jan 14 2012 sepatutnya minggu 3');
  20609. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3', 'Jan 15 2012 sepatutnya minggu 3');
  20610. });
  20611. test('lenient ordinal parsing', function (assert) {
  20612. var i, ordinalStr, testMoment;
  20613. for (i = 1; i <= 31; ++i) {
  20614. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  20615. testMoment = moment(ordinalStr, 'YYYY MM Do');
  20616. assert.equal(testMoment.year(), 2014,
  20617. 'lenient ordinal parsing ' + i + ' year check');
  20618. assert.equal(testMoment.month(), 0,
  20619. 'lenient ordinal parsing ' + i + ' month check');
  20620. assert.equal(testMoment.date(), i,
  20621. 'lenient ordinal parsing ' + i + ' date check');
  20622. }
  20623. });
  20624. test('meridiem invariant', function (assert) {
  20625. var h, m, t1, t2;
  20626. for (h = 0; h < 24; ++h) {
  20627. for (m = 0; m < 60; m += 15) {
  20628. t1 = moment.utc([2000, 0, 1, h, m]);
  20629. t2 = moment(t1.format('A h:mm'), 'A h:mm');
  20630. assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
  20631. 'meridiem at ' + t1.format('HH:mm'));
  20632. }
  20633. }
  20634. });
  20635. test('lenient ordinal parsing of number', function (assert) {
  20636. var i, testMoment;
  20637. for (i = 1; i <= 31; ++i) {
  20638. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  20639. assert.equal(testMoment.year(), 2014,
  20640. 'lenient ordinal parsing of number ' + i + ' year check');
  20641. assert.equal(testMoment.month(), 0,
  20642. 'lenient ordinal parsing of number ' + i + ' month check');
  20643. assert.equal(testMoment.date(), i,
  20644. 'lenient ordinal parsing of number ' + i + ' date check');
  20645. }
  20646. });
  20647. test('strict ordinal parsing', function (assert) {
  20648. var i, ordinalStr, testMoment;
  20649. for (i = 1; i <= 31; ++i) {
  20650. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  20651. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  20652. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  20653. }
  20654. });
  20655. }));
  20656. ;(function (global, factory) {
  20657. typeof exports === 'object' && typeof module !== 'undefined'
  20658. && typeof require === 'function' ? factory(require('../../moment')) :
  20659. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  20660. factory(global.moment)
  20661. }(this, function (moment) { 'use strict';
  20662. /*global QUnit:false*/
  20663. var test = QUnit.test;
  20664. var expect = QUnit.expect;
  20665. function module (name, lifecycle) {
  20666. QUnit.module(name, {
  20667. setup : function () {
  20668. moment.locale('en');
  20669. moment.createFromInputFallback = function (config) {
  20670. throw new Error('input not handled by moment: ' + config._i);
  20671. };
  20672. if (lifecycle && lifecycle.setup) {
  20673. lifecycle.setup();
  20674. }
  20675. },
  20676. teardown : function () {
  20677. if (lifecycle && lifecycle.teardown) {
  20678. lifecycle.teardown();
  20679. }
  20680. }
  20681. });
  20682. }
  20683. function localeModule (name, lifecycle) {
  20684. QUnit.module('locale:' + name, {
  20685. setup : function () {
  20686. moment.locale(name);
  20687. moment.createFromInputFallback = function (config) {
  20688. throw new Error('input not handled by moment: ' + config._i);
  20689. };
  20690. if (lifecycle && lifecycle.setup) {
  20691. lifecycle.setup();
  20692. }
  20693. },
  20694. teardown : function () {
  20695. moment.locale('en');
  20696. if (lifecycle && lifecycle.teardown) {
  20697. lifecycle.teardown();
  20698. }
  20699. }
  20700. });
  20701. }
  20702. localeModule('my');
  20703. test('parse', function (assert) {
  20704. var tests = 'ဇန်နဝါရီ ဇန်_ဖေဖော်ဝါရီ ဖေ_မတ် မတ်_ဧပြီ ပြီ_မေ မေ_ဇွန် ဇွန်_ဇူလိုင် လိုင်_သြဂုတ် သြ_စက်တင်ဘာ စက်_အောက်တိုဘာ အောက်_နိုဝင်ဘာ နို_ဒီဇင်ဘာ ဒီ'.split('_'),
  20705. i;
  20706. function equalTest (input, mmm, i) {
  20707. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  20708. }
  20709. for (i = 0; i < 12; i++) {
  20710. tests[i] = tests[i].split(' ');
  20711. equalTest(tests[i][0], 'MMM', i);
  20712. equalTest(tests[i][1], 'MMM', i);
  20713. equalTest(tests[i][0], 'MMMM', i);
  20714. equalTest(tests[i][1], 'MMMM', i);
  20715. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  20716. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  20717. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  20718. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  20719. }
  20720. });
  20721. test('format', function (assert) {
  20722. var a = [
  20723. ['dddd, MMMM Do YYYY, h:mm:ss a', 'တနင်္ဂနွေ, ဖေဖော်ဝါရီ ၁၄ ၂၀၁၀, ၃:၂၅:၅၀ pm'],
  20724. ['ddd, hA', 'နွေ, ၃PM'],
  20725. ['M Mo MM MMMM MMM', '၂ ၂ ၀၂ ဖေဖော်ဝါရီ ဖေ'],
  20726. ['YYYY YY', '၂၀၁၀ ၁၀'],
  20727. ['D Do DD', '၁၄ ၁၄ ၁၄'],
  20728. ['d do dddd ddd dd', '၀ ၀ တနင်္ဂနွေ နွေ နွေ'],
  20729. ['DDD DDDo DDDD', '၄၅ ၄၅ ၀၄၅'],
  20730. ['w wo ww', '၆ ၆ ၀၆'],
  20731. ['h hh', '၃ ၀၃'],
  20732. ['H HH', '၁၅ ၁၅'],
  20733. ['m mm', '၂၅ ၂၅'],
  20734. ['s ss', '၅၀ ၅၀'],
  20735. ['a A', 'pm PM'],
  20736. ['[နှစ်၏] DDDo [ရက်မြောက်]', 'နှစ်၏ ၄၅ ရက်မြောက်'],
  20737. ['LTS', '၁၅:၂၅:၅၀'],
  20738. ['L', '၁၄/၀၂/၂၀၁၀'],
  20739. ['LL', '၁၄ ဖေဖော်ဝါရီ ၂၀၁၀'],
  20740. ['LLL', '၁၄ ဖေဖော်ဝါရီ ၂၀၁၀ ၁၅:၂၅'],
  20741. ['LLLL', 'တနင်္ဂနွေ ၁၄ ဖေဖော်ဝါရီ ၂၀၁၀ ၁၅:၂၅'],
  20742. ['l', '၁၄/၂/၂၀၁၀'],
  20743. ['ll', '၁၄ ဖေ ၂၀၁၀'],
  20744. ['lll', '၁၄ ဖေ ၂၀၁၀ ၁၅:၂၅'],
  20745. ['llll', 'နွေ ၁၄ ဖေ ၂၀၁၀ ၁၅:၂၅']
  20746. ],
  20747. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  20748. i;
  20749. for (i = 0; i < a.length; i++) {
  20750. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  20751. }
  20752. });
  20753. test('format ordinal', function (assert) {
  20754. assert.equal(moment([2011, 0, 1]).format('DDDo'), '၁', '၁');
  20755. assert.equal(moment([2011, 0, 2]).format('DDDo'), '၂', '၂');
  20756. assert.equal(moment([2011, 0, 3]).format('DDDo'), '၃', '၃');
  20757. assert.equal(moment([2011, 0, 4]).format('DDDo'), '၄', '၄');
  20758. assert.equal(moment([2011, 0, 5]).format('DDDo'), '၅', '၅');
  20759. assert.equal(moment([2011, 0, 6]).format('DDDo'), '၆', '၆');
  20760. assert.equal(moment([2011, 0, 7]).format('DDDo'), '၇', '၇');
  20761. assert.equal(moment([2011, 0, 8]).format('DDDo'), '၈', '၈');
  20762. assert.equal(moment([2011, 0, 9]).format('DDDo'), '၉', '၉');
  20763. assert.equal(moment([2011, 0, 10]).format('DDDo'), '၁၀', '၁၀');
  20764. assert.equal(moment([2011, 0, 11]).format('DDDo'), '၁၁', '၁၁');
  20765. assert.equal(moment([2011, 0, 12]).format('DDDo'), '၁၂', '၁၂');
  20766. assert.equal(moment([2011, 0, 13]).format('DDDo'), '၁၃', '၁၃');
  20767. assert.equal(moment([2011, 0, 14]).format('DDDo'), '၁၄', '၁၄');
  20768. assert.equal(moment([2011, 0, 15]).format('DDDo'), '၁၅', '၁၅');
  20769. assert.equal(moment([2011, 0, 16]).format('DDDo'), '၁၆', '၁၆');
  20770. assert.equal(moment([2011, 0, 17]).format('DDDo'), '၁၇', '၁၇');
  20771. assert.equal(moment([2011, 0, 18]).format('DDDo'), '၁၈', '၁၈');
  20772. assert.equal(moment([2011, 0, 19]).format('DDDo'), '၁၉', '၁၉');
  20773. assert.equal(moment([2011, 0, 20]).format('DDDo'), '၂၀', '၂၀');
  20774. assert.equal(moment([2011, 0, 21]).format('DDDo'), '၂၁', '၂၁');
  20775. assert.equal(moment([2011, 0, 22]).format('DDDo'), '၂၂', '၂၂');
  20776. assert.equal(moment([2011, 0, 23]).format('DDDo'), '၂၃', '၂၃');
  20777. assert.equal(moment([2011, 0, 24]).format('DDDo'), '၂၄', '၂၄');
  20778. assert.equal(moment([2011, 0, 25]).format('DDDo'), '၂၅', '၂၅');
  20779. assert.equal(moment([2011, 0, 26]).format('DDDo'), '၂၆', '၂၆');
  20780. assert.equal(moment([2011, 0, 27]).format('DDDo'), '၂၇', '၂၇');
  20781. assert.equal(moment([2011, 0, 28]).format('DDDo'), '၂၈', '၂၈');
  20782. assert.equal(moment([2011, 0, 29]).format('DDDo'), '၂၉', '၂၉');
  20783. assert.equal(moment([2011, 0, 30]).format('DDDo'), '၃၀', '၃၀');
  20784. assert.equal(moment([2011, 0, 31]).format('DDDo'), '၃၁', '၃၁');
  20785. });
  20786. test('format month', function (assert) {
  20787. var expected = 'ဇန်နဝါရီ ဇန်_ဖေဖော်ဝါရီ ဖေ_မတ် မတ်_ဧပြီ ပြီ_မေ မေ_ဇွန် ဇွန်_ဇူလိုင် လိုင်_သြဂုတ် သြ_စက်တင်ဘာ စက်_အောက်တိုဘာ အောက်_နိုဝင်ဘာ နို_ဒီဇင်ဘာ ဒီ'.split('_'),
  20788. i;
  20789. for (i = 0; i < expected.length; i++) {
  20790. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  20791. }
  20792. });
  20793. test('format week', function (assert) {
  20794. var expected = 'တနင်္ဂနွေ နွေ နွေ_တနင်္လာ လာ လာ_အင်္ဂါ ဂါ ဂါ_ဗုဒ္ဓဟူး ဟူး ဟူး_ကြာသပတေး ကြာ ကြာ_သောကြာ သော သော_စနေ နေ နေ'.split('_'),
  20795. i;
  20796. for (i = 0; i < expected.length; i++) {
  20797. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  20798. }
  20799. });
  20800. test('from', function (assert) {
  20801. var start = moment([2007, 1, 28]);
  20802. assert.equal(start.from(moment([2007, 1, 28]).add({
  20803. s: 44
  20804. }), true), 'စက္ကန်.အနည်းငယ်', '၄၄ စက္ကန်. = စက္ကန်.အနည်းငယ်');
  20805. assert.equal(start.from(moment([2007, 1, 28]).add({
  20806. s: 45
  20807. }), true), 'တစ်မိနစ်', '၄၅ စက္ကန်. = တစ်မိနစ်');
  20808. assert.equal(start.from(moment([2007, 1, 28]).add({
  20809. s: 89
  20810. }), true), 'တစ်မိနစ်', '၈၉ စက္ကန်. = တစ်မိနစ်');
  20811. assert.equal(start.from(moment([2007, 1, 28]).add({
  20812. s: 90
  20813. }), true), '၂ မိနစ်', '၉၀ စက္ကန်. = ၂ မိနစ်');
  20814. assert.equal(start.from(moment([2007, 1, 28]).add({
  20815. m: 44
  20816. }), true), '၄၄ မိနစ်', '၄၄ မိနစ် = ၄၄ မိနစ်');
  20817. assert.equal(start.from(moment([2007, 1, 28]).add({
  20818. m: 45
  20819. }), true), 'တစ်နာရီ', '၄၅ မိနစ် = ၁ နာရီ');
  20820. assert.equal(start.from(moment([2007, 1, 28]).add({
  20821. m: 89
  20822. }), true), 'တစ်နာရီ', '၈၉ မိနစ် = တစ်နာရီ');
  20823. assert.equal(start.from(moment([2007, 1, 28]).add({
  20824. m: 90
  20825. }), true), '၂ နာရီ', 'မိနစ် ၉၀= ၂ နာရီ');
  20826. assert.equal(start.from(moment([2007, 1, 28]).add({
  20827. h: 5
  20828. }), true), '၅ နာရီ', '၅ နာရီ= ၅ နာရီ');
  20829. assert.equal(start.from(moment([2007, 1, 28]).add({
  20830. h: 21
  20831. }), true), '၂၁ နာရီ', '၂၁ နာရီ =၂၁ နာရီ');
  20832. assert.equal(start.from(moment([2007, 1, 28]).add({
  20833. h: 22
  20834. }), true), 'တစ်ရက်', '၂၂ နာရီ =တစ်ရက်');
  20835. assert.equal(start.from(moment([2007, 1, 28]).add({
  20836. h: 35
  20837. }), true), 'တစ်ရက်', '၃၅ နာရီ =တစ်ရက်');
  20838. assert.equal(start.from(moment([2007, 1, 28]).add({
  20839. h: 36
  20840. }), true), '၂ ရက်', '၃၆ နာရီ = ၂ ရက်');
  20841. assert.equal(start.from(moment([2007, 1, 28]).add({
  20842. d: 1
  20843. }), true), 'တစ်ရက်', '၁ ရက်= တစ်ရက်');
  20844. assert.equal(start.from(moment([2007, 1, 28]).add({
  20845. d: 5
  20846. }), true), '၅ ရက်', '၅ ရက် = ၅ ရက်');
  20847. assert.equal(start.from(moment([2007, 1, 28]).add({
  20848. d: 25
  20849. }), true), '၂၅ ရက်', '၂၅ ရက်= ၂၅ ရက်');
  20850. assert.equal(start.from(moment([2007, 1, 28]).add({
  20851. d: 26
  20852. }), true), 'တစ်လ', '၂၆ ရက် = တစ်လ');
  20853. assert.equal(start.from(moment([2007, 1, 28]).add({
  20854. d: 30
  20855. }), true), 'တစ်လ', 'ရက် ၃၀ = တစ်လ');
  20856. assert.equal(start.from(moment([2007, 1, 28]).add({
  20857. d: 43
  20858. }), true), 'တစ်လ', '၄၃ ရက် = တစ်လ');
  20859. assert.equal(start.from(moment([2007, 1, 28]).add({
  20860. d: 46
  20861. }), true), '၂ လ', '၄၆ ရက် = ၂ လ');
  20862. assert.equal(start.from(moment([2007, 1, 28]).add({
  20863. d: 74
  20864. }), true), '၂ လ', '၇၅ ရက်= ၂ လ');
  20865. assert.equal(start.from(moment([2007, 1, 28]).add({
  20866. d: 76
  20867. }), true), '၃ လ', '၇၆ ရက် = ၃ လ');
  20868. assert.equal(start.from(moment([2007, 1, 28]).add({
  20869. M: 1
  20870. }), true), 'တစ်လ', '၁ လ = တစ်လ');
  20871. assert.equal(start.from(moment([2007, 1, 28]).add({
  20872. M: 5
  20873. }), true), '၅ လ', '၅ လ = ၅ လ');
  20874. assert.equal(start.from(moment([2007, 1, 28]).add({
  20875. d: 345
  20876. }), true), 'တစ်နှစ်', '၃၄၅ ရက် = တစ်နှစ်');
  20877. assert.equal(start.from(moment([2007, 1, 28]).add({
  20878. d: 548
  20879. }), true), '၂ နှစ်', '၅၄၈ ရက် = ၂ နှစ်');
  20880. assert.equal(start.from(moment([2007, 1, 28]).add({
  20881. y: 1
  20882. }), true), 'တစ်နှစ်', '၁ နှစ် = တစ်နှစ်');
  20883. assert.equal(start.from(moment([2007, 1, 28]).add({
  20884. y: 5
  20885. }), true), '၅ နှစ်', '၅ နှစ် = ၅ နှစ်');
  20886. });
  20887. test('suffix', function (assert) {
  20888. assert.equal(moment(30000).from(0), 'လာမည့် စက္ကန်.အနည်းငယ် မှာ', 'prefix');
  20889. assert.equal(moment(0).from(30000), 'လွန်ခဲ့သော စက္ကန်.အနည်းငယ် က', 'suffix');
  20890. });
  20891. test('now from now', function (assert) {
  20892. assert.equal(moment().fromNow(), 'လွန်ခဲ့သော စက္ကန်.အနည်းငယ် က', 'ယခုမှစပြီး အတိတ်တွင်ဖော်ပြသလိုဖော်ပြမည်');
  20893. });
  20894. test('fromNow', function (assert) {
  20895. assert.equal(moment().add({
  20896. s: 30
  20897. }).fromNow(), 'လာမည့် စက္ကန်.အနည်းငယ် မှာ', 'လာမည့် စက္ကန်.အနည်းငယ် မှာ');
  20898. assert.equal(moment().add({
  20899. d: 5
  20900. }).fromNow(), 'လာမည့် ၅ ရက် မှာ', 'လာမည့် ၅ ရက် မှာ');
  20901. });
  20902. test('calendar day', function (assert) {
  20903. var a = moment().hours(2).minutes(0).seconds(0);
  20904. assert.equal(moment(a).calendar(), 'ယနေ. ၀၂:၀၀ မှာ', 'ယနေ. ဒီအချိန်');
  20905. assert.equal(moment(a).add({
  20906. m: 25
  20907. }).calendar(), 'ယနေ. ၀၂:၂၅ မှာ', 'ယခုမှ ၂၅ မိနစ်ပေါင်းထည့်');
  20908. assert.equal(moment(a).add({
  20909. h: 1
  20910. }).calendar(), 'ယနေ. ၀၃:၀၀ မှာ', 'ယခုမှ ၁ နာရီပေါင်းထည့်');
  20911. assert.equal(moment(a).add({
  20912. d: 1
  20913. }).calendar(), 'မနက်ဖြန် ၀၂:၀၀ မှာ', 'မနက်ဖြန် ဒီအချိန်');
  20914. assert.equal(moment(a).subtract({
  20915. h: 1
  20916. }).calendar(), 'ယနေ. ၀၁:၀၀ မှာ', 'ယခုမှ ၁ နာရီနှုတ်');
  20917. assert.equal(moment(a).subtract({
  20918. d: 1
  20919. }).calendar(), 'မနေ.က ၀၂:၀၀ မှာ', 'မနေ.က ဒီအချိန်');
  20920. });
  20921. test('calendar next week', function (assert) {
  20922. var i, m;
  20923. for (i = 2; i < 7; i++) {
  20924. m = moment().add({
  20925. d: i
  20926. });
  20927. assert.equal(m.calendar(), m.format('dddd LT [မှာ]'), 'Today + ' + i + ' days current time');
  20928. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  20929. assert.equal(m.calendar(), m.format('dddd LT [မှာ]'), 'Today + ' + i + ' days beginning of day');
  20930. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  20931. assert.equal(m.calendar(), m.format('dddd LT [မှာ]'), 'Today + ' + i + ' days end of day');
  20932. }
  20933. });
  20934. test('calendar last week', function (assert) {
  20935. var i, m;
  20936. for (i = 2; i < 7; i++) {
  20937. m = moment().subtract({
  20938. d: i
  20939. });
  20940. assert.equal(m.calendar(), m.format('[ပြီးခဲ့သော] dddd LT [မှာ]'), 'Today - ' + i + ' days current time');
  20941. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  20942. assert.equal(m.calendar(), m.format('[ပြီးခဲ့သော] dddd LT [မှာ]'), 'Today - ' + i + ' days beginning of day');
  20943. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  20944. assert.equal(m.calendar(), m.format('[ပြီးခဲ့သော] dddd LT [မှာ]'), 'Today - ' + i + ' days end of day');
  20945. }
  20946. });
  20947. test('calendar all else', function (assert) {
  20948. var weeksAgo = moment().subtract({
  20949. w: 1
  20950. }),
  20951. weeksFromNow = moment().add({
  20952. w: 1
  20953. });
  20954. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), 'လွန်ခဲ့သော ၁ ပတ်က');
  20955. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), '၁ ပတ်အတွင်း');
  20956. weeksAgo = moment().subtract({
  20957. w: 2
  20958. });
  20959. weeksFromNow = moment().add({
  20960. w: 2
  20961. });
  20962. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '၂ ပတ် အရင်က');
  20963. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), '၂ ပတ် အတွင်း');
  20964. });
  20965. test('weeks year starting sunday', function (assert) {
  20966. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  20967. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  20968. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  20969. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  20970. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  20971. });
  20972. test('weeks year starting monday', function (assert) {
  20973. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  20974. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  20975. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  20976. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  20977. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  20978. });
  20979. test('weeks year starting tuesday', function (assert) {
  20980. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  20981. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  20982. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  20983. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  20984. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  20985. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  20986. });
  20987. test('weeks year starting wednesday', function (assert) {
  20988. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  20989. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  20990. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  20991. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  20992. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  20993. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  20994. });
  20995. test('weeks year starting thursday', function (assert) {
  20996. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  20997. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  20998. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  20999. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  21000. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  21001. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  21002. });
  21003. test('weeks year starting friday', function (assert) {
  21004. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  21005. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  21006. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  21007. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  21008. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  21009. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  21010. });
  21011. test('weeks year starting saturday', function (assert) {
  21012. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  21013. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  21014. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  21015. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  21016. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  21017. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  21018. });
  21019. test('weeks year starting sunday formatted', function (assert) {
  21020. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '၅၂ ၅၂ ၅၂', 'Jan 1 2012 should be week 52');
  21021. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '၁ ၀၁ ၁', 'Jan 2 2012 should be week 1');
  21022. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '၁ ၀၁ ၁', 'Jan 8 2012 should be week 1');
  21023. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '၂ ၀၂ ၂', 'Jan 9 2012 should be week 2');
  21024. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '၂ ၀၂ ၂', 'Jan 15 2012 should be week 2');
  21025. });
  21026. test('lenient ordinal parsing', function (assert) {
  21027. var i, ordinalStr, testMoment;
  21028. for (i = 1; i <= 31; ++i) {
  21029. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  21030. testMoment = moment(ordinalStr, 'YYYY MM Do');
  21031. assert.equal(testMoment.year(), 2014,
  21032. 'lenient ordinal parsing ' + i + ' year check');
  21033. assert.equal(testMoment.month(), 0,
  21034. 'lenient ordinal parsing ' + i + ' month check');
  21035. assert.equal(testMoment.date(), i,
  21036. 'lenient ordinal parsing ' + i + ' date check');
  21037. }
  21038. });
  21039. test('lenient ordinal parsing of number', function (assert) {
  21040. var i, testMoment;
  21041. for (i = 1; i <= 31; ++i) {
  21042. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  21043. assert.equal(testMoment.year(), 2014,
  21044. 'lenient ordinal parsing of number ' + i + ' year check');
  21045. assert.equal(testMoment.month(), 0,
  21046. 'lenient ordinal parsing of number ' + i + ' month check');
  21047. assert.equal(testMoment.date(), i,
  21048. 'lenient ordinal parsing of number ' + i + ' date check');
  21049. }
  21050. });
  21051. test('strict ordinal parsing', function (assert) {
  21052. var i, ordinalStr, testMoment;
  21053. for (i = 1; i <= 31; ++i) {
  21054. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  21055. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  21056. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  21057. }
  21058. });
  21059. }));
  21060. ;(function (global, factory) {
  21061. typeof exports === 'object' && typeof module !== 'undefined'
  21062. && typeof require === 'function' ? factory(require('../../moment')) :
  21063. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  21064. factory(global.moment)
  21065. }(this, function (moment) { 'use strict';
  21066. /*global QUnit:false*/
  21067. var test = QUnit.test;
  21068. var expect = QUnit.expect;
  21069. function module (name, lifecycle) {
  21070. QUnit.module(name, {
  21071. setup : function () {
  21072. moment.locale('en');
  21073. moment.createFromInputFallback = function (config) {
  21074. throw new Error('input not handled by moment: ' + config._i);
  21075. };
  21076. if (lifecycle && lifecycle.setup) {
  21077. lifecycle.setup();
  21078. }
  21079. },
  21080. teardown : function () {
  21081. if (lifecycle && lifecycle.teardown) {
  21082. lifecycle.teardown();
  21083. }
  21084. }
  21085. });
  21086. }
  21087. function localeModule (name, lifecycle) {
  21088. QUnit.module('locale:' + name, {
  21089. setup : function () {
  21090. moment.locale(name);
  21091. moment.createFromInputFallback = function (config) {
  21092. throw new Error('input not handled by moment: ' + config._i);
  21093. };
  21094. if (lifecycle && lifecycle.setup) {
  21095. lifecycle.setup();
  21096. }
  21097. },
  21098. teardown : function () {
  21099. moment.locale('en');
  21100. if (lifecycle && lifecycle.teardown) {
  21101. lifecycle.teardown();
  21102. }
  21103. }
  21104. });
  21105. }
  21106. localeModule('nb');
  21107. test('parse', function (assert) {
  21108. var tests = 'januar jan._februar feb._mars mars_april april_mai mai_juni juni_juli juli_august aug._september sep._oktober okt._november nov._desember des.'.split('_'),
  21109. i;
  21110. function equalTest(input, mmm, i) {
  21111. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  21112. }
  21113. for (i = 0; i < 12; i++) {
  21114. tests[i] = tests[i].split(' ');
  21115. equalTest(tests[i][0], 'MMM', i);
  21116. equalTest(tests[i][1], 'MMM', i);
  21117. equalTest(tests[i][0], 'MMMM', i);
  21118. equalTest(tests[i][1], 'MMMM', i);
  21119. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  21120. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  21121. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  21122. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  21123. }
  21124. });
  21125. test('format', function (assert) {
  21126. var a = [
  21127. ['dddd, MMMM Do YYYY, h:mm:ss a', 'søndag, februar 14. 2010, 3:25:50 pm'],
  21128. ['ddd, hA', 'sø., 3PM'],
  21129. ['M Mo MM MMMM MMM', '2 2. 02 februar feb.'],
  21130. ['YYYY YY', '2010 10'],
  21131. ['D Do DD', '14 14. 14'],
  21132. ['d do dddd ddd dd', '0 0. søndag sø. sø'],
  21133. ['DDD DDDo DDDD', '45 45. 045'],
  21134. ['w wo ww', '6 6. 06'],
  21135. ['h hh', '3 03'],
  21136. ['H HH', '15 15'],
  21137. ['m mm', '25 25'],
  21138. ['s ss', '50 50'],
  21139. ['a A', 'pm PM'],
  21140. ['[den] DDDo [dagen i året]', 'den 45. dagen i året'],
  21141. ['LTS', '15:25:50'],
  21142. ['L', '14.02.2010'],
  21143. ['LL', '14. februar 2010'],
  21144. ['LLL', '14. februar 2010 kl. 15:25'],
  21145. ['LLLL', 'søndag 14. februar 2010 kl. 15:25'],
  21146. ['l', '14.2.2010'],
  21147. ['ll', '14. feb. 2010'],
  21148. ['lll', '14. feb. 2010 kl. 15:25'],
  21149. ['llll', 'sø. 14. feb. 2010 kl. 15:25']
  21150. ],
  21151. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  21152. i;
  21153. for (i = 0; i < a.length; i++) {
  21154. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  21155. }
  21156. });
  21157. test('format ordinal', function (assert) {
  21158. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
  21159. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
  21160. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
  21161. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
  21162. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
  21163. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
  21164. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
  21165. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
  21166. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
  21167. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
  21168. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
  21169. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
  21170. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
  21171. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
  21172. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
  21173. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
  21174. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
  21175. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
  21176. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
  21177. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
  21178. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
  21179. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
  21180. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
  21181. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
  21182. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
  21183. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
  21184. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
  21185. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
  21186. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
  21187. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
  21188. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
  21189. });
  21190. test('format month', function (assert) {
  21191. var expected = 'januar jan._februar feb._mars mars_april april_mai mai_juni juni_juli juli_august aug._september sep._oktober okt._november nov._desember des.'.split('_'), i;
  21192. for (i = 0; i < expected.length; i++) {
  21193. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  21194. }
  21195. });
  21196. test('format week', function (assert) {
  21197. var expected = 'søndag sø. sø_mandag ma. ma_tirsdag ti. ti_onsdag on. on_torsdag to. to_fredag fr. fr_lørdag lø. lø'.split('_'), i;
  21198. for (i = 0; i < expected.length; i++) {
  21199. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  21200. }
  21201. });
  21202. test('from', function (assert) {
  21203. var start = moment([2007, 1, 28]);
  21204. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'noen sekunder', '44 sekunder = a few seconds');
  21205. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'ett minutt', '45 seconds = a minute');
  21206. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'ett minutt', '89 seconds = a minute');
  21207. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutter', '90 seconds = 2 minutes');
  21208. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutter', '44 minutes = 44 minutes');
  21209. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'en time', '45 minutes = an hour');
  21210. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'en time', '89 minutes = an hour');
  21211. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 timer', '90 minutes = 2 hours');
  21212. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 timer', '5 hours = 5 hours');
  21213. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 timer', '21 hours = 21 hours');
  21214. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'en dag', '22 hours = a day');
  21215. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'en dag', '35 hours = a day');
  21216. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dager', '36 hours = 2 days');
  21217. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'en dag', '1 day = a day');
  21218. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dager', '5 days = 5 days');
  21219. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dager', '25 days = 25 days');
  21220. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'en måned', '26 days = a month');
  21221. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'en måned', '30 days = a month');
  21222. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'en måned', '43 days = a month');
  21223. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 måneder', '46 days = 2 months');
  21224. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 måneder', '75 days = 2 months');
  21225. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 måneder', '76 days = 3 months');
  21226. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'en måned', '1 month = a month');
  21227. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 måneder', '5 months = 5 months');
  21228. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ett år', '345 days = a year');
  21229. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 år', '548 days = 2 years');
  21230. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ett år', '1 year = a year');
  21231. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 år', '5 years = 5 years');
  21232. });
  21233. test('suffix', function (assert) {
  21234. assert.equal(moment(30000).from(0), 'om noen sekunder', 'prefix');
  21235. assert.equal(moment(0).from(30000), 'for noen sekunder siden', 'suffix');
  21236. });
  21237. test('now from now', function (assert) {
  21238. assert.equal(moment().fromNow(), 'for noen sekunder siden', 'now from now should display as in the past');
  21239. });
  21240. test('fromNow', function (assert) {
  21241. assert.equal(moment().add({s: 30}).fromNow(), 'om noen sekunder', 'in a few seconds');
  21242. assert.equal(moment().add({d: 5}).fromNow(), 'om 5 dager', 'in 5 days');
  21243. });
  21244. test('calendar day', function (assert) {
  21245. var a = moment().hours(2).minutes(0).seconds(0);
  21246. assert.equal(moment(a).calendar(), 'i dag kl. 02:00', 'today at the same time');
  21247. assert.equal(moment(a).add({m: 25}).calendar(), 'i dag kl. 02:25', 'Now plus 25 min');
  21248. assert.equal(moment(a).add({h: 1}).calendar(), 'i dag kl. 03:00', 'Now plus 1 hour');
  21249. assert.equal(moment(a).add({d: 1}).calendar(), 'i morgen kl. 02:00', 'tomorrow at the same time');
  21250. assert.equal(moment(a).subtract({h: 1}).calendar(), 'i dag kl. 01:00', 'Now minus 1 hour');
  21251. assert.equal(moment(a).subtract({d: 1}).calendar(), 'i går kl. 02:00', 'yesterday at the same time');
  21252. });
  21253. test('calendar next week', function (assert) {
  21254. var i, m;
  21255. for (i = 2; i < 7; i++) {
  21256. m = moment().add({d: i});
  21257. assert.equal(m.calendar(), m.format('dddd [kl.] LT'), 'Today + ' + i + ' days current time');
  21258. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  21259. assert.equal(m.calendar(), m.format('dddd [kl.] LT'), 'Today + ' + i + ' days beginning of day');
  21260. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  21261. assert.equal(m.calendar(), m.format('dddd [kl.] LT'), 'Today + ' + i + ' days end of day');
  21262. }
  21263. });
  21264. test('calendar last week', function (assert) {
  21265. var i, m;
  21266. for (i = 2; i < 7; i++) {
  21267. m = moment().subtract({d: i});
  21268. assert.equal(m.calendar(), m.format('[forrige] dddd [kl.] LT'), 'Today - ' + i + ' days current time');
  21269. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  21270. assert.equal(m.calendar(), m.format('[forrige] dddd [kl.] LT'), 'Today - ' + i + ' days beginning of day');
  21271. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  21272. assert.equal(m.calendar(), m.format('[forrige] dddd [kl.] LT'), 'Today - ' + i + ' days end of day');
  21273. }
  21274. });
  21275. test('calendar all else', function (assert) {
  21276. var weeksAgo = moment().subtract({w: 1}),
  21277. weeksFromNow = moment().add({w: 1});
  21278. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  21279. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  21280. weeksAgo = moment().subtract({w: 2});
  21281. weeksFromNow = moment().add({w: 2});
  21282. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  21283. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  21284. });
  21285. test('weeks year starting sunday', function (assert) {
  21286. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  21287. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  21288. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  21289. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  21290. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  21291. });
  21292. test('weeks year starting monday', function (assert) {
  21293. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  21294. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  21295. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  21296. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  21297. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  21298. });
  21299. test('weeks year starting tuesday', function (assert) {
  21300. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  21301. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  21302. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  21303. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  21304. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  21305. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  21306. });
  21307. test('weeks year starting wednesday', function (assert) {
  21308. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  21309. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  21310. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  21311. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  21312. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  21313. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  21314. });
  21315. test('weeks year starting thursday', function (assert) {
  21316. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  21317. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  21318. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  21319. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  21320. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  21321. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  21322. });
  21323. test('weeks year starting friday', function (assert) {
  21324. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  21325. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  21326. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  21327. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  21328. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  21329. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  21330. });
  21331. test('weeks year starting saturday', function (assert) {
  21332. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  21333. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  21334. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  21335. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  21336. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  21337. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  21338. });
  21339. test('weeks year starting sunday formatted', function (assert) {
  21340. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
  21341. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
  21342. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
  21343. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
  21344. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
  21345. });
  21346. test('lenient ordinal parsing', function (assert) {
  21347. var i, ordinalStr, testMoment;
  21348. for (i = 1; i <= 31; ++i) {
  21349. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  21350. testMoment = moment(ordinalStr, 'YYYY MM Do');
  21351. assert.equal(testMoment.year(), 2014,
  21352. 'lenient ordinal parsing ' + i + ' year check');
  21353. assert.equal(testMoment.month(), 0,
  21354. 'lenient ordinal parsing ' + i + ' month check');
  21355. assert.equal(testMoment.date(), i,
  21356. 'lenient ordinal parsing ' + i + ' date check');
  21357. }
  21358. });
  21359. test('lenient ordinal parsing of number', function (assert) {
  21360. var i, testMoment;
  21361. for (i = 1; i <= 31; ++i) {
  21362. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  21363. assert.equal(testMoment.year(), 2014,
  21364. 'lenient ordinal parsing of number ' + i + ' year check');
  21365. assert.equal(testMoment.month(), 0,
  21366. 'lenient ordinal parsing of number ' + i + ' month check');
  21367. assert.equal(testMoment.date(), i,
  21368. 'lenient ordinal parsing of number ' + i + ' date check');
  21369. }
  21370. });
  21371. test('strict ordinal parsing', function (assert) {
  21372. var i, ordinalStr, testMoment;
  21373. for (i = 1; i <= 31; ++i) {
  21374. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  21375. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  21376. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  21377. }
  21378. });
  21379. }));
  21380. ;(function (global, factory) {
  21381. typeof exports === 'object' && typeof module !== 'undefined'
  21382. && typeof require === 'function' ? factory(require('../../moment')) :
  21383. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  21384. factory(global.moment)
  21385. }(this, function (moment) { 'use strict';
  21386. /*global QUnit:false*/
  21387. var test = QUnit.test;
  21388. var expect = QUnit.expect;
  21389. function module (name, lifecycle) {
  21390. QUnit.module(name, {
  21391. setup : function () {
  21392. moment.locale('en');
  21393. moment.createFromInputFallback = function (config) {
  21394. throw new Error('input not handled by moment: ' + config._i);
  21395. };
  21396. if (lifecycle && lifecycle.setup) {
  21397. lifecycle.setup();
  21398. }
  21399. },
  21400. teardown : function () {
  21401. if (lifecycle && lifecycle.teardown) {
  21402. lifecycle.teardown();
  21403. }
  21404. }
  21405. });
  21406. }
  21407. function localeModule (name, lifecycle) {
  21408. QUnit.module('locale:' + name, {
  21409. setup : function () {
  21410. moment.locale(name);
  21411. moment.createFromInputFallback = function (config) {
  21412. throw new Error('input not handled by moment: ' + config._i);
  21413. };
  21414. if (lifecycle && lifecycle.setup) {
  21415. lifecycle.setup();
  21416. }
  21417. },
  21418. teardown : function () {
  21419. moment.locale('en');
  21420. if (lifecycle && lifecycle.teardown) {
  21421. lifecycle.teardown();
  21422. }
  21423. }
  21424. });
  21425. }
  21426. localeModule('ne');
  21427. test('parse', function (assert) {
  21428. var tests = 'जनवरी जन._फेब्रुवरी फेब्रु._मार्च मार्च_अप्रिल अप्रि._मई मई_जुन जुन_जुलाई जुलाई._अगष्ट अग._सेप्टेम्बर सेप्ट._अक्टोबर अक्टो._नोभेम्बर नोभे._डिसेम्बर डिसे.'.split('_'), i;
  21429. function equalTest(input, mmm, i) {
  21430. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  21431. }
  21432. for (i = 0; i < 12; i++) {
  21433. tests[i] = tests[i].split(' ');
  21434. equalTest(tests[i][0], 'MMM', i);
  21435. equalTest(tests[i][1], 'MMM', i);
  21436. equalTest(tests[i][0], 'MMMM', i);
  21437. equalTest(tests[i][1], 'MMMM', i);
  21438. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  21439. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  21440. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  21441. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  21442. }
  21443. });
  21444. test('format', function (assert) {
  21445. var a = [
  21446. ['dddd, Do MMMM YYYY, aको h:mm:ss बजे', 'आइतबार, १४ फेब्रुवरी २०१०, दिउँसोको ३:२५:५० बजे'],
  21447. ['ddd, aको h बजे', 'आइत., दिउँसोको ३ बजे'],
  21448. ['M Mo MM MMMM MMM', '२ २ ०२ फेब्रुवरी फेब्रु.'],
  21449. ['YYYY YY', '२०१० १०'],
  21450. ['D Do DD', '१४ १४ १४'],
  21451. ['d do dddd ddd dd', '० ० आइतबार आइत. आ.'],
  21452. ['DDD DDDo DDDD', '४५ ४५ ०४५'],
  21453. ['w wo ww', '८ ८ ०८'],
  21454. ['h hh', '३ ०३'],
  21455. ['H HH', '१५ १५'],
  21456. ['m mm', '२५ २५'],
  21457. ['s ss', '५० ५०'],
  21458. ['a A', 'दिउँसो दिउँसो'],
  21459. ['LTS', 'दिउँसोको ३:२५:५० बजे'],
  21460. ['L', '१४/०२/२०१०'],
  21461. ['LL', '१४ फेब्रुवरी २०१०'],
  21462. ['LLL', '१४ फेब्रुवरी २०१०, दिउँसोको ३:२५ बजे'],
  21463. ['LLLL', 'आइतबार, १४ फेब्रुवरी २०१०, दिउँसोको ३:२५ बजे'],
  21464. ['l', '१४/२/२०१०'],
  21465. ['ll', '१४ फेब्रु. २०१०'],
  21466. ['lll', '१४ फेब्रु. २०१०, दिउँसोको ३:२५ बजे'],
  21467. ['llll', 'आइत., १४ फेब्रु. २०१०, दिउँसोको ३:२५ बजे']
  21468. ],
  21469. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  21470. i;
  21471. for (i = 0; i < a.length; i++) {
  21472. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  21473. }
  21474. });
  21475. test('format ordinal', function (assert) {
  21476. assert.equal(moment([2011, 0, 1]).format('DDDo'), '१', '१');
  21477. assert.equal(moment([2011, 0, 2]).format('DDDo'), '२', '२');
  21478. assert.equal(moment([2011, 0, 3]).format('DDDo'), '३', '३');
  21479. assert.equal(moment([2011, 0, 4]).format('DDDo'), '४', '४');
  21480. assert.equal(moment([2011, 0, 5]).format('DDDo'), '५', '५');
  21481. assert.equal(moment([2011, 0, 6]).format('DDDo'), '६', '६');
  21482. assert.equal(moment([2011, 0, 7]).format('DDDo'), '७', '७');
  21483. assert.equal(moment([2011, 0, 8]).format('DDDo'), '८', '८');
  21484. assert.equal(moment([2011, 0, 9]).format('DDDo'), '९', '९');
  21485. assert.equal(moment([2011, 0, 10]).format('DDDo'), '१०', '१०');
  21486. assert.equal(moment([2011, 0, 11]).format('DDDo'), '११', '११');
  21487. assert.equal(moment([2011, 0, 12]).format('DDDo'), '१२', '१२');
  21488. assert.equal(moment([2011, 0, 13]).format('DDDo'), '१३', '१३');
  21489. assert.equal(moment([2011, 0, 14]).format('DDDo'), '१४', '१४');
  21490. assert.equal(moment([2011, 0, 15]).format('DDDo'), '१५', '१५');
  21491. assert.equal(moment([2011, 0, 16]).format('DDDo'), '१६', '१६');
  21492. assert.equal(moment([2011, 0, 17]).format('DDDo'), '१७', '१७');
  21493. assert.equal(moment([2011, 0, 18]).format('DDDo'), '१८', '१८');
  21494. assert.equal(moment([2011, 0, 19]).format('DDDo'), '१९', '१९');
  21495. assert.equal(moment([2011, 0, 20]).format('DDDo'), '२०', '२०');
  21496. assert.equal(moment([2011, 0, 21]).format('DDDo'), '२१', '२१');
  21497. assert.equal(moment([2011, 0, 22]).format('DDDo'), '२२', '२२');
  21498. assert.equal(moment([2011, 0, 23]).format('DDDo'), '२३', '२३');
  21499. assert.equal(moment([2011, 0, 24]).format('DDDo'), '२४', '२४');
  21500. assert.equal(moment([2011, 0, 25]).format('DDDo'), '२५', '२५');
  21501. assert.equal(moment([2011, 0, 26]).format('DDDo'), '२६', '२६');
  21502. assert.equal(moment([2011, 0, 27]).format('DDDo'), '२७', '२७');
  21503. assert.equal(moment([2011, 0, 28]).format('DDDo'), '२८', '२८');
  21504. assert.equal(moment([2011, 0, 29]).format('DDDo'), '२९', '२९');
  21505. assert.equal(moment([2011, 0, 30]).format('DDDo'), '३०', '३०');
  21506. assert.equal(moment([2011, 0, 31]).format('DDDo'), '३१', '३१');
  21507. });
  21508. test('format month', function (assert) {
  21509. var expected = 'जनवरी जन._फेब्रुवरी फेब्रु._मार्च मार्च_अप्रिल अप्रि._मई मई_जुन जुन_जुलाई जुलाई._अगष्ट अग._सेप्टेम्बर सेप्ट._अक्टोबर अक्टो._नोभेम्बर नोभे._डिसेम्बर डिसे.'.split('_'), i;
  21510. for (i = 0; i < expected.length; i++) {
  21511. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  21512. }
  21513. });
  21514. test('format week', function (assert) {
  21515. var expected = 'आइतबार आइत. आ._सोमबार सोम. सो._मङ्गलबार मङ्गल. मं._बुधबार बुध. बु._बिहिबार बिहि. बि._शुक्रबार शुक्र. शु._शनिबार शनि. श.'.split('_'), i;
  21516. for (i = 0; i < expected.length; i++) {
  21517. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  21518. }
  21519. });
  21520. test('from', function (assert) {
  21521. var start = moment([2007, 1, 28]);
  21522. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'केही क्षण', '44 seconds = a few seconds');
  21523. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'एक मिनेट', '45 seconds = a minute');
  21524. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'एक मिनेट', '89 seconds = a minute');
  21525. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '२ मिनेट', '90 seconds = 2 minutes');
  21526. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '४४ मिनेट', '44 minutes = 44 minutes');
  21527. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'एक घण्टा', '45 minutes = an hour');
  21528. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'एक घण्टा', '89 minutes = an hour');
  21529. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '२ घण्टा', '90 minutes = 2 hours');
  21530. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '५ घण्टा', '5 hours = 5 hours');
  21531. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '२१ घण्टा', '21 hours = 21 hours');
  21532. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'एक दिन', '22 hours = a day');
  21533. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'एक दिन', '35 hours = a day');
  21534. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '२ दिन', '36 hours = 2 days');
  21535. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'एक दिन', '1 day = a day');
  21536. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '५ दिन', '5 days = 5 days');
  21537. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '२५ दिन', '25 days = 25 days');
  21538. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'एक महिना', '26 days = a month');
  21539. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'एक महिना', '30 days = a month');
  21540. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'एक महिना', '43 days = a month');
  21541. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '२ महिना', '46 days = 2 months');
  21542. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '२ महिना', '75 days = 2 months');
  21543. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '३ महिना', '76 days = 3 months');
  21544. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'एक महिना', '1 month = a month');
  21545. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '५ महिना', '5 months = 5 months');
  21546. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'एक बर्ष', '345 days = a year');
  21547. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '२ बर्ष', '548 days = 2 years');
  21548. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'एक बर्ष', '1 year = a year');
  21549. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '५ बर्ष', '5 years = 5 years');
  21550. });
  21551. test('suffix', function (assert) {
  21552. assert.equal(moment(30000).from(0), 'केही क्षणमा', 'prefix');
  21553. assert.equal(moment(0).from(30000), 'केही क्षण अगाडि', 'suffix');
  21554. });
  21555. test('now from now', function (assert) {
  21556. assert.equal(moment().fromNow(), 'केही क्षण अगाडि', 'now from now should display as in the past');
  21557. });
  21558. test('fromNow', function (assert) {
  21559. assert.equal(moment().add({s: 30}).fromNow(), 'केही क्षणमा', 'केही क्षणमा');
  21560. assert.equal(moment().add({d: 5}).fromNow(), '५ दिनमा', '५ दिनमा');
  21561. });
  21562. test('calendar day', function (assert) {
  21563. var a = moment().hours(2).minutes(0).seconds(0);
  21564. assert.equal(moment(a).calendar(), 'आज रातिको २:०० बजे', 'today at the same time');
  21565. assert.equal(moment(a).add({m: 25}).calendar(), 'आज रातिको २:२५ बजे', 'Now plus 25 min');
  21566. assert.equal(moment(a).add({h: 1}).calendar(), 'आज बिहानको ३:०० बजे', 'Now plus 1 hour');
  21567. assert.equal(moment(a).add({d: 1}).calendar(), 'भोलि रातिको २:०० बजे', 'tomorrow at the same time');
  21568. assert.equal(moment(a).subtract({h: 1}).calendar(), 'आज रातिको १:०० बजे', 'Now minus 1 hour');
  21569. assert.equal(moment(a).subtract({d: 1}).calendar(), 'हिजो रातिको २:०० बजे', 'yesterday at the same time');
  21570. });
  21571. test('calendar next week', function (assert) {
  21572. var i, m;
  21573. for (i = 2; i < 7; i++) {
  21574. m = moment().add({d: i});
  21575. assert.equal(m.calendar(), m.format('[आउँदो] dddd[,] LT'), 'Today + ' + i + ' days current time');
  21576. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  21577. assert.equal(m.calendar(), m.format('[आउँदो] dddd[,] LT'), 'Today + ' + i + ' days beginning of day');
  21578. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  21579. assert.equal(m.calendar(), m.format('[आउँदो] dddd[,] LT'), 'Today + ' + i + ' days end of day');
  21580. }
  21581. });
  21582. test('calendar last week', function (assert) {
  21583. var i, m;
  21584. for (i = 2; i < 7; i++) {
  21585. m = moment().subtract({d: i});
  21586. assert.equal(m.calendar(), m.format('[गएको] dddd[,] LT'), 'Today - ' + i + ' days current time');
  21587. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  21588. assert.equal(m.calendar(), m.format('[गएको] dddd[,] LT'), 'Today - ' + i + ' days beginning of day');
  21589. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  21590. assert.equal(m.calendar(), m.format('[गएको] dddd[,] LT'), 'Today - ' + i + ' days end of day');
  21591. }
  21592. });
  21593. test('calendar all else', function (assert) {
  21594. var weeksAgo = moment().subtract({w: 1}),
  21595. weeksFromNow = moment().add({w: 1});
  21596. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  21597. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  21598. weeksAgo = moment().subtract({w: 2});
  21599. weeksFromNow = moment().add({w: 2});
  21600. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  21601. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  21602. });
  21603. test('meridiem', function (assert) {
  21604. assert.equal(moment([2011, 2, 23, 2, 30]).format('a'), 'राति', 'before dawn');
  21605. assert.equal(moment([2011, 2, 23, 9, 30]).format('a'), 'बिहान', 'morning');
  21606. assert.equal(moment([2011, 2, 23, 14, 30]).format('a'), 'दिउँसो', 'during day');
  21607. assert.equal(moment([2011, 2, 23, 17, 30]).format('a'), 'साँझ', 'evening');
  21608. assert.equal(moment([2011, 2, 23, 19, 30]).format('a'), 'साँझ', 'late evening');
  21609. assert.equal(moment([2011, 2, 23, 21, 20]).format('a'), 'राति', 'night');
  21610. assert.equal(moment([2011, 2, 23, 2, 30]).format('A'), 'राति', 'before dawn');
  21611. assert.equal(moment([2011, 2, 23, 9, 30]).format('A'), 'बिहान', 'morning');
  21612. assert.equal(moment([2011, 2, 23, 14, 30]).format('A'), 'दिउँसो', 'during day');
  21613. assert.equal(moment([2011, 2, 23, 17, 30]).format('A'), 'साँझ', 'evening');
  21614. assert.equal(moment([2011, 2, 23, 19, 30]).format('A'), 'साँझ', 'late evening');
  21615. assert.equal(moment([2011, 2, 23, 21, 20]).format('A'), 'राति', 'night');
  21616. });
  21617. test('weeks year starting sunday', function (assert) {
  21618. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  21619. assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1');
  21620. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  21621. assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2');
  21622. assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 3');
  21623. });
  21624. test('weeks year starting monday', function (assert) {
  21625. assert.equal(moment([2006, 11, 31]).week(), 1, 'Dec 31 2006 should be week 1');
  21626. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  21627. assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1');
  21628. assert.equal(moment([2007, 0, 7]).week(), 2, 'Jan 7 2007 should be week 2');
  21629. assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2');
  21630. assert.equal(moment([2007, 0, 14]).week(), 3, 'Jan 14 2007 should be week 3');
  21631. });
  21632. test('weeks year starting tuesday', function (assert) {
  21633. assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52');
  21634. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  21635. assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1');
  21636. assert.equal(moment([2008, 0, 6]).week(), 2, 'Jan 6 2008 should be week 2');
  21637. assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2');
  21638. assert.equal(moment([2008, 0, 13]).week(), 3, 'Jan 13 2008 should be week 3');
  21639. });
  21640. test('weeks year starting wednesday', function (assert) {
  21641. assert.equal(moment([2002, 11, 29]).week(), 1, 'Dec 29 2002 should be week 1');
  21642. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  21643. assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1');
  21644. assert.equal(moment([2003, 0, 5]).week(), 2, 'Jan 5 2003 should be week 2');
  21645. assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2');
  21646. assert.equal(moment([2003, 0, 12]).week(), 3, 'Jan 12 2003 should be week 3');
  21647. });
  21648. test('weeks year starting thursday', function (assert) {
  21649. assert.equal(moment([2008, 11, 28]).week(), 1, 'Dec 28 2008 should be week 1');
  21650. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  21651. assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1');
  21652. assert.equal(moment([2009, 0, 4]).week(), 2, 'Jan 4 2009 should be week 2');
  21653. assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2');
  21654. assert.equal(moment([2009, 0, 11]).week(), 3, 'Jan 11 2009 should be week 3');
  21655. });
  21656. test('weeks year starting friday', function (assert) {
  21657. assert.equal(moment([2009, 11, 27]).week(), 1, 'Dec 27 2009 should be week 1');
  21658. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  21659. assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 should be week 1');
  21660. assert.equal(moment([2010, 0, 3]).week(), 2, 'Jan 3 2010 should be week 2');
  21661. assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 should be week 2');
  21662. assert.equal(moment([2010, 0, 10]).week(), 3, 'Jan 10 2010 should be week 3');
  21663. });
  21664. test('weeks year starting saturday', function (assert) {
  21665. assert.equal(moment([2010, 11, 26]).week(), 1, 'Dec 26 2010 should be week 1');
  21666. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  21667. assert.equal(moment([2011, 0, 2]).week(), 2, 'Jan 2 2011 should be week 2');
  21668. assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2');
  21669. assert.equal(moment([2011, 0, 9]).week(), 3, 'Jan 9 2011 should be week 3');
  21670. });
  21671. test('weeks year starting sunday formatted', function (assert) {
  21672. assert.equal(moment([2011, 11, 26]).format('w ww wo'), '५३ ५३ ५३', 'Dec 26 2011 should be week 53');
  21673. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '१ ०१ १', 'Jan 1 2012 should be week 1');
  21674. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '१ ०१ १', 'Jan 2 2012 should be week 1');
  21675. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '२ ०२ २', 'Jan 8 2012 should be week 2');
  21676. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '२ ०२ २', 'Jan 9 2012 should be week 2');
  21677. });
  21678. test('lenient ordinal parsing', function (assert) {
  21679. var i, ordinalStr, testMoment;
  21680. for (i = 1; i <= 31; ++i) {
  21681. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  21682. testMoment = moment(ordinalStr, 'YYYY MM Do');
  21683. assert.equal(testMoment.year(), 2014,
  21684. 'lenient ordinal parsing ' + i + ' year check');
  21685. assert.equal(testMoment.month(), 0,
  21686. 'lenient ordinal parsing ' + i + ' month check');
  21687. assert.equal(testMoment.date(), i,
  21688. 'lenient ordinal parsing ' + i + ' date check');
  21689. }
  21690. });
  21691. test('lenient ordinal parsing of number', function (assert) {
  21692. var i, testMoment;
  21693. for (i = 1; i <= 31; ++i) {
  21694. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  21695. assert.equal(testMoment.year(), 2014,
  21696. 'lenient ordinal parsing of number ' + i + ' year check');
  21697. assert.equal(testMoment.month(), 0,
  21698. 'lenient ordinal parsing of number ' + i + ' month check');
  21699. assert.equal(testMoment.date(), i,
  21700. 'lenient ordinal parsing of number ' + i + ' date check');
  21701. }
  21702. });
  21703. test('meridiem invariant', function (assert) {
  21704. var h, m, t1, t2;
  21705. for (h = 0; h < 24; ++h) {
  21706. for (m = 0; m < 60; m += 15) {
  21707. t1 = moment.utc([2000, 0, 1, h, m]);
  21708. t2 = moment(t1.format('A h:mm'), 'A h:mm');
  21709. assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
  21710. 'meridiem at ' + t1.format('HH:mm'));
  21711. }
  21712. }
  21713. });
  21714. test('strict ordinal parsing', function (assert) {
  21715. var i, ordinalStr, testMoment;
  21716. for (i = 1; i <= 31; ++i) {
  21717. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  21718. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  21719. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  21720. }
  21721. });
  21722. }));
  21723. ;(function (global, factory) {
  21724. typeof exports === 'object' && typeof module !== 'undefined'
  21725. && typeof require === 'function' ? factory(require('../../moment')) :
  21726. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  21727. factory(global.moment)
  21728. }(this, function (moment) { 'use strict';
  21729. /*global QUnit:false*/
  21730. var test = QUnit.test;
  21731. var expect = QUnit.expect;
  21732. function module (name, lifecycle) {
  21733. QUnit.module(name, {
  21734. setup : function () {
  21735. moment.locale('en');
  21736. moment.createFromInputFallback = function (config) {
  21737. throw new Error('input not handled by moment: ' + config._i);
  21738. };
  21739. if (lifecycle && lifecycle.setup) {
  21740. lifecycle.setup();
  21741. }
  21742. },
  21743. teardown : function () {
  21744. if (lifecycle && lifecycle.teardown) {
  21745. lifecycle.teardown();
  21746. }
  21747. }
  21748. });
  21749. }
  21750. function localeModule (name, lifecycle) {
  21751. QUnit.module('locale:' + name, {
  21752. setup : function () {
  21753. moment.locale(name);
  21754. moment.createFromInputFallback = function (config) {
  21755. throw new Error('input not handled by moment: ' + config._i);
  21756. };
  21757. if (lifecycle && lifecycle.setup) {
  21758. lifecycle.setup();
  21759. }
  21760. },
  21761. teardown : function () {
  21762. moment.locale('en');
  21763. if (lifecycle && lifecycle.teardown) {
  21764. lifecycle.teardown();
  21765. }
  21766. }
  21767. });
  21768. }
  21769. localeModule('nl');
  21770. test('parse', function (assert) {
  21771. var tests = 'januari jan._februari feb._maart mrt._april apr._mei mei._juni jun._juli jul._augustus aug._september sep._oktober okt._november nov._december dec.'.split('_'), i;
  21772. function equalTest(input, mmm, i) {
  21773. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  21774. }
  21775. for (i = 0; i < 12; i++) {
  21776. tests[i] = tests[i].split(' ');
  21777. equalTest(tests[i][0], 'MMM', i);
  21778. equalTest(tests[i][1], 'MMM', i);
  21779. equalTest(tests[i][0], 'MMMM', i);
  21780. equalTest(tests[i][1], 'MMMM', i);
  21781. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  21782. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  21783. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  21784. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  21785. }
  21786. });
  21787. test('format', function (assert) {
  21788. var a = [
  21789. ['dddd, MMMM Do YYYY, HH:mm:ss', 'zondag, februari 14de 2010, 15:25:50'],
  21790. ['ddd, HH', 'zo., 15'],
  21791. ['M Mo MM MMMM MMM', '2 2de 02 februari feb.'],
  21792. ['YYYY YY', '2010 10'],
  21793. ['D Do DD', '14 14de 14'],
  21794. ['d do dddd ddd dd', '0 0de zondag zo. Zo'],
  21795. ['DDD DDDo DDDD', '45 45ste 045'],
  21796. ['w wo ww', '6 6de 06'],
  21797. ['h hh', '3 03'],
  21798. ['H HH', '15 15'],
  21799. ['m mm', '25 25'],
  21800. ['s ss', '50 50'],
  21801. ['a A', 'pm PM'],
  21802. ['[the] DDDo [day of the year]', 'the 45ste day of the year'],
  21803. ['LTS', '15:25:50'],
  21804. ['L', '14-02-2010'],
  21805. ['LL', '14 februari 2010'],
  21806. ['LLL', '14 februari 2010 15:25'],
  21807. ['LLLL', 'zondag 14 februari 2010 15:25'],
  21808. ['l', '14-2-2010'],
  21809. ['ll', '14 feb. 2010'],
  21810. ['lll', '14 feb. 2010 15:25'],
  21811. ['llll', 'zo. 14 feb. 2010 15:25']
  21812. ],
  21813. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  21814. i;
  21815. for (i = 0; i < a.length; i++) {
  21816. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  21817. }
  21818. });
  21819. test('format ordinal', function (assert) {
  21820. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1ste', '1ste');
  21821. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2de', '2de');
  21822. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3de', '3de');
  21823. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4de', '4de');
  21824. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5de', '5de');
  21825. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6de', '6de');
  21826. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7de', '7de');
  21827. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8ste', '8ste');
  21828. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9de', '9de');
  21829. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10de', '10de');
  21830. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11de', '11de');
  21831. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12de', '12de');
  21832. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13de', '13de');
  21833. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14de', '14de');
  21834. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15de', '15de');
  21835. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16de', '16de');
  21836. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17de', '17de');
  21837. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18de', '18de');
  21838. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19de', '19de');
  21839. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20ste', '20ste');
  21840. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21ste', '21ste');
  21841. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22ste', '22ste');
  21842. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23ste', '23ste');
  21843. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24ste', '24ste');
  21844. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25ste', '25ste');
  21845. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26ste', '26ste');
  21846. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27ste', '27ste');
  21847. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28ste', '28ste');
  21848. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29ste', '29ste');
  21849. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30ste', '30ste');
  21850. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31ste', '31ste');
  21851. });
  21852. test('format month', function (assert) {
  21853. var expected = 'januari jan._februari feb._maart mrt._april apr._mei mei_juni jun._juli jul._augustus aug._september sep._oktober okt._november nov._december dec.'.split('_'), i;
  21854. for (i = 0; i < expected.length; i++) {
  21855. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  21856. }
  21857. });
  21858. test('format week', function (assert) {
  21859. var expected = 'zondag zo. Zo_maandag ma. Ma_dinsdag di. Di_woensdag wo. Wo_donderdag do. Do_vrijdag vr. Vr_zaterdag za. Za'.split('_'), i;
  21860. for (i = 0; i < expected.length; i++) {
  21861. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  21862. }
  21863. });
  21864. test('from', function (assert) {
  21865. var start = moment([2007, 1, 28]);
  21866. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'een paar seconden', '44 seconds = a few seconds');
  21867. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'één minuut', '45 seconds = a minute');
  21868. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'één minuut', '89 seconds = a minute');
  21869. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuten', '90 seconds = 2 minutes');
  21870. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuten', '44 minutes = 44 minutes');
  21871. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'één uur', '45 minutes = an hour');
  21872. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'één uur', '89 minutes = an hour');
  21873. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 uur', '90 minutes = 2 hours');
  21874. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 uur', '5 hours = 5 hours');
  21875. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 uur', '21 hours = 21 hours');
  21876. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'één dag', '22 hours = a day');
  21877. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'één dag', '35 hours = a day');
  21878. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dagen', '36 hours = 2 days');
  21879. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'één dag', '1 day = a day');
  21880. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dagen', '5 days = 5 days');
  21881. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dagen', '25 days = 25 days');
  21882. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'één maand', '26 days = a month');
  21883. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'één maand', '30 days = a month');
  21884. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'één maand', '43 days = a month');
  21885. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 maanden', '46 days = 2 months');
  21886. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 maanden', '75 days = 2 months');
  21887. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 maanden', '76 days = 3 months');
  21888. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'één maand', '1 month = a month');
  21889. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 maanden', '5 months = 5 months');
  21890. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'één jaar', '345 days = a year');
  21891. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 jaar', '548 days = 2 years');
  21892. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'één jaar', '1 year = a year');
  21893. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 jaar', '5 years = 5 years');
  21894. });
  21895. test('suffix', function (assert) {
  21896. assert.equal(moment(30000).from(0), 'over een paar seconden', 'prefix');
  21897. assert.equal(moment(0).from(30000), 'een paar seconden geleden', 'suffix');
  21898. });
  21899. test('now from now', function (assert) {
  21900. assert.equal(moment().fromNow(), 'een paar seconden geleden', 'now from now should display as in the past');
  21901. });
  21902. test('fromNow', function (assert) {
  21903. assert.equal(moment().add({s: 30}).fromNow(), 'over een paar seconden', 'in a few seconds');
  21904. assert.equal(moment().add({d: 5}).fromNow(), 'over 5 dagen', 'in 5 days');
  21905. });
  21906. test('calendar day', function (assert) {
  21907. var a = moment().hours(2).minutes(0).seconds(0);
  21908. assert.equal(moment(a).calendar(), 'vandaag om 02:00', 'today at the same time');
  21909. assert.equal(moment(a).add({m: 25}).calendar(), 'vandaag om 02:25', 'Now plus 25 min');
  21910. assert.equal(moment(a).add({h: 1}).calendar(), 'vandaag om 03:00', 'Now plus 1 hour');
  21911. assert.equal(moment(a).add({d: 1}).calendar(), 'morgen om 02:00', 'tomorrow at the same time');
  21912. assert.equal(moment(a).subtract({h: 1}).calendar(), 'vandaag om 01:00', 'Now minus 1 hour');
  21913. assert.equal(moment(a).subtract({d: 1}).calendar(), 'gisteren om 02:00', 'yesterday at the same time');
  21914. });
  21915. test('calendar next week', function (assert) {
  21916. var i, m;
  21917. for (i = 2; i < 7; i++) {
  21918. m = moment().add({d: i});
  21919. assert.equal(m.calendar(), m.format('dddd [om] LT'), 'Today + ' + i + ' days current time');
  21920. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  21921. assert.equal(m.calendar(), m.format('dddd [om] LT'), 'Today + ' + i + ' days beginning of day');
  21922. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  21923. assert.equal(m.calendar(), m.format('dddd [om] LT'), 'Today + ' + i + ' days end of day');
  21924. }
  21925. });
  21926. test('calendar last week', function (assert) {
  21927. var i, m;
  21928. for (i = 2; i < 7; i++) {
  21929. m = moment().subtract({d: i});
  21930. assert.equal(m.calendar(), m.format('[afgelopen] dddd [om] LT'), 'Today - ' + i + ' days current time');
  21931. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  21932. assert.equal(m.calendar(), m.format('[afgelopen] dddd [om] LT'), 'Today - ' + i + ' days beginning of day');
  21933. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  21934. assert.equal(m.calendar(), m.format('[afgelopen] dddd [om] LT'), 'Today - ' + i + ' days end of day');
  21935. }
  21936. });
  21937. test('calendar all else', function (assert) {
  21938. var weeksAgo = moment().subtract({w: 1}),
  21939. weeksFromNow = moment().add({w: 1});
  21940. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  21941. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  21942. weeksAgo = moment().subtract({w: 2});
  21943. weeksFromNow = moment().add({w: 2});
  21944. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  21945. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  21946. });
  21947. test('month abbreviation', function (assert) {
  21948. assert.equal(moment([2012, 5, 23]).format('D-MMM-YYYY'), '23-jun-2012', 'format month abbreviation surrounded by dashes should not include a dot');
  21949. assert.equal(moment([2012, 5, 23]).format('D MMM YYYY'), '23 jun. 2012', 'format month abbreviation not surrounded by dashes should include a dot');
  21950. });
  21951. test('weeks year starting sunday', function (assert) {
  21952. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  21953. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  21954. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  21955. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  21956. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  21957. });
  21958. test('weeks year starting monday', function (assert) {
  21959. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  21960. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  21961. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  21962. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  21963. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  21964. });
  21965. test('weeks year starting tuesday', function (assert) {
  21966. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  21967. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  21968. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  21969. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  21970. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  21971. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  21972. });
  21973. test('weeks year starting wednesday', function (assert) {
  21974. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  21975. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  21976. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  21977. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  21978. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  21979. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  21980. });
  21981. test('weeks year starting thursday', function (assert) {
  21982. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  21983. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  21984. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  21985. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  21986. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  21987. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  21988. });
  21989. test('weeks year starting friday', function (assert) {
  21990. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  21991. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  21992. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  21993. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  21994. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  21995. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  21996. });
  21997. test('weeks year starting saturday', function (assert) {
  21998. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  21999. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  22000. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  22001. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  22002. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  22003. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  22004. });
  22005. test('weeks year starting sunday formatted', function (assert) {
  22006. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52ste', 'Jan 1 2012 should be week 52');
  22007. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1ste', 'Jan 2 2012 should be week 1');
  22008. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1ste', 'Jan 8 2012 should be week 1');
  22009. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2de', 'Jan 9 2012 should be week 2');
  22010. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2de', 'Jan 15 2012 should be week 2');
  22011. });
  22012. test('lenient ordinal parsing', function (assert) {
  22013. var i, ordinalStr, testMoment;
  22014. for (i = 1; i <= 31; ++i) {
  22015. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  22016. testMoment = moment(ordinalStr, 'YYYY MM Do');
  22017. assert.equal(testMoment.year(), 2014,
  22018. 'lenient ordinal parsing ' + i + ' year check');
  22019. assert.equal(testMoment.month(), 0,
  22020. 'lenient ordinal parsing ' + i + ' month check');
  22021. assert.equal(testMoment.date(), i,
  22022. 'lenient ordinal parsing ' + i + ' date check');
  22023. }
  22024. });
  22025. test('lenient ordinal parsing of number', function (assert) {
  22026. var i, testMoment;
  22027. for (i = 1; i <= 31; ++i) {
  22028. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  22029. assert.equal(testMoment.year(), 2014,
  22030. 'lenient ordinal parsing of number ' + i + ' year check');
  22031. assert.equal(testMoment.month(), 0,
  22032. 'lenient ordinal parsing of number ' + i + ' month check');
  22033. assert.equal(testMoment.date(), i,
  22034. 'lenient ordinal parsing of number ' + i + ' date check');
  22035. }
  22036. });
  22037. test('strict ordinal parsing', function (assert) {
  22038. var i, ordinalStr, testMoment;
  22039. for (i = 1; i <= 31; ++i) {
  22040. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  22041. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  22042. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  22043. }
  22044. });
  22045. }));
  22046. ;(function (global, factory) {
  22047. typeof exports === 'object' && typeof module !== 'undefined'
  22048. && typeof require === 'function' ? factory(require('../../moment')) :
  22049. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  22050. factory(global.moment)
  22051. }(this, function (moment) { 'use strict';
  22052. /*global QUnit:false*/
  22053. var test = QUnit.test;
  22054. var expect = QUnit.expect;
  22055. function module (name, lifecycle) {
  22056. QUnit.module(name, {
  22057. setup : function () {
  22058. moment.locale('en');
  22059. moment.createFromInputFallback = function (config) {
  22060. throw new Error('input not handled by moment: ' + config._i);
  22061. };
  22062. if (lifecycle && lifecycle.setup) {
  22063. lifecycle.setup();
  22064. }
  22065. },
  22066. teardown : function () {
  22067. if (lifecycle && lifecycle.teardown) {
  22068. lifecycle.teardown();
  22069. }
  22070. }
  22071. });
  22072. }
  22073. function localeModule (name, lifecycle) {
  22074. QUnit.module('locale:' + name, {
  22075. setup : function () {
  22076. moment.locale(name);
  22077. moment.createFromInputFallback = function (config) {
  22078. throw new Error('input not handled by moment: ' + config._i);
  22079. };
  22080. if (lifecycle && lifecycle.setup) {
  22081. lifecycle.setup();
  22082. }
  22083. },
  22084. teardown : function () {
  22085. moment.locale('en');
  22086. if (lifecycle && lifecycle.teardown) {
  22087. lifecycle.teardown();
  22088. }
  22089. }
  22090. });
  22091. }
  22092. localeModule('nn');
  22093. test('parse', function (assert) {
  22094. var tests = 'januar jan_februar feb_mars mar_april apr_mai mai_juni jun_juli jul_august aug_september sep_oktober okt_november nov_desember des'.split('_'), i;
  22095. function equalTest(input, mmm, i) {
  22096. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  22097. }
  22098. for (i = 0; i < 12; i++) {
  22099. tests[i] = tests[i].split(' ');
  22100. equalTest(tests[i][0], 'MMM', i);
  22101. equalTest(tests[i][1], 'MMM', i);
  22102. equalTest(tests[i][0], 'MMMM', i);
  22103. equalTest(tests[i][1], 'MMMM', i);
  22104. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  22105. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  22106. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  22107. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  22108. }
  22109. });
  22110. test('format', function (assert) {
  22111. var a = [
  22112. ['dddd, MMMM Do YYYY, h:mm:ss a', 'sundag, februar 14. 2010, 3:25:50 pm'],
  22113. ['ddd, hA', 'sun, 3PM'],
  22114. ['M Mo MM MMMM MMM', '2 2. 02 februar feb'],
  22115. ['YYYY YY', '2010 10'],
  22116. ['D Do DD', '14 14. 14'],
  22117. ['d do dddd ddd dd', '0 0. sundag sun su'],
  22118. ['DDD DDDo DDDD', '45 45. 045'],
  22119. ['w wo ww', '6 6. 06'],
  22120. ['h hh', '3 03'],
  22121. ['H HH', '15 15'],
  22122. ['m mm', '25 25'],
  22123. ['s ss', '50 50'],
  22124. ['a A', 'pm PM'],
  22125. ['[the] DDDo [day of the year]', 'the 45. day of the year'],
  22126. ['LTS', '15:25:50'],
  22127. ['L', '14.02.2010'],
  22128. ['LL', '14. februar 2010'],
  22129. ['LLL', '14. februar 2010 kl. 15:25'],
  22130. ['LLLL', 'sundag 14. februar 2010 kl. 15:25'],
  22131. ['l', '14.2.2010'],
  22132. ['ll', '14. feb 2010'],
  22133. ['lll', '14. feb 2010 kl. 15:25'],
  22134. ['llll', 'sun 14. feb 2010 kl. 15:25']
  22135. ],
  22136. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  22137. i;
  22138. for (i = 0; i < a.length; i++) {
  22139. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  22140. }
  22141. });
  22142. test('format ordinal', function (assert) {
  22143. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
  22144. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
  22145. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
  22146. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
  22147. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
  22148. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
  22149. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
  22150. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
  22151. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
  22152. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
  22153. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
  22154. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
  22155. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
  22156. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
  22157. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
  22158. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
  22159. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
  22160. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
  22161. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
  22162. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
  22163. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
  22164. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
  22165. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
  22166. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
  22167. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
  22168. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
  22169. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
  22170. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
  22171. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
  22172. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
  22173. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
  22174. });
  22175. test('format month', function (assert) {
  22176. var expected = 'januar jan_februar feb_mars mar_april apr_mai mai_juni jun_juli jul_august aug_september sep_oktober okt_november nov_desember des'.split('_'), i;
  22177. for (i = 0; i < expected.length; i++) {
  22178. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  22179. }
  22180. });
  22181. test('format week', function (assert) {
  22182. var expected = 'sundag sun su_måndag mån må_tysdag tys ty_onsdag ons on_torsdag tor to_fredag fre fr_laurdag lau lø'.split('_'), i;
  22183. for (i = 0; i < expected.length; i++) {
  22184. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  22185. }
  22186. });
  22187. test('from', function (assert) {
  22188. var start = moment([2007, 1, 28]);
  22189. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'nokre sekund', '44 sekunder = a few seconds');
  22190. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'eit minutt', '45 seconds = a minute');
  22191. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'eit minutt', '89 seconds = a minute');
  22192. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutt', '90 seconds = 2 minutes');
  22193. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutt', '44 minutes = 44 minutes');
  22194. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ein time', '45 minutes = an hour');
  22195. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ein time', '89 minutes = an hour');
  22196. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 timar', '90 minutes = 2 hours');
  22197. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 timar', '5 hours = 5 hours');
  22198. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 timar', '21 hours = 21 hours');
  22199. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ein dag', '22 hours = a day');
  22200. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ein dag', '35 hours = a day');
  22201. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dagar', '36 hours = 2 days');
  22202. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ein dag', '1 day = a day');
  22203. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dagar', '5 days = 5 days');
  22204. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dagar', '25 days = 25 days');
  22205. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ein månad', '26 days = a month');
  22206. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ein månad', '30 days = a month');
  22207. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ein månad', '43 days = a month');
  22208. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 månader', '46 days = 2 months');
  22209. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 månader', '75 days = 2 months');
  22210. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 månader', '76 days = 3 months');
  22211. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ein månad', '1 month = a month');
  22212. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 månader', '5 months = 5 months');
  22213. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'eit år', '345 days = a year');
  22214. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 år', '548 days = 2 years');
  22215. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'eit år', '1 year = a year');
  22216. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 år', '5 years = 5 years');
  22217. });
  22218. test('suffix', function (assert) {
  22219. assert.equal(moment(30000).from(0), 'om nokre sekund', 'prefix');
  22220. assert.equal(moment(0).from(30000), 'for nokre sekund sidan', 'suffix');
  22221. });
  22222. test('now from now', function (assert) {
  22223. assert.equal(moment().fromNow(), 'for nokre sekund sidan', 'now from now should display as in the past');
  22224. });
  22225. test('fromNow', function (assert) {
  22226. assert.equal(moment().add({s: 30}).fromNow(), 'om nokre sekund', 'in a few seconds');
  22227. assert.equal(moment().add({d: 5}).fromNow(), 'om 5 dagar', 'in 5 days');
  22228. });
  22229. test('calendar day', function (assert) {
  22230. var a = moment().hours(2).minutes(0).seconds(0);
  22231. assert.equal(moment(a).calendar(), 'I dag klokka 02:00', 'today at the same time');
  22232. assert.equal(moment(a).add({m: 25}).calendar(), 'I dag klokka 02:25', 'Now plus 25 min');
  22233. assert.equal(moment(a).add({h: 1}).calendar(), 'I dag klokka 03:00', 'Now plus 1 hour');
  22234. assert.equal(moment(a).add({d: 1}).calendar(), 'I morgon klokka 02:00', 'tomorrow at the same time');
  22235. assert.equal(moment(a).subtract({h: 1}).calendar(), 'I dag klokka 01:00', 'Now minus 1 hour');
  22236. assert.equal(moment(a).subtract({d: 1}).calendar(), 'I går klokka 02:00', 'yesterday at the same time');
  22237. });
  22238. test('calendar next week', function (assert) {
  22239. var i, m;
  22240. for (i = 2; i < 7; i++) {
  22241. m = moment().add({d: i});
  22242. assert.equal(m.calendar(), m.format('dddd [klokka] LT'), 'Today + ' + i + ' days current time');
  22243. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  22244. assert.equal(m.calendar(), m.format('dddd [klokka] LT'), 'Today + ' + i + ' days beginning of day');
  22245. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  22246. assert.equal(m.calendar(), m.format('dddd [klokka] LT'), 'Today + ' + i + ' days end of day');
  22247. }
  22248. });
  22249. test('calendar last week', function (assert) {
  22250. var i, m;
  22251. for (i = 2; i < 7; i++) {
  22252. m = moment().subtract({d: i});
  22253. assert.equal(m.calendar(), m.format('[Føregåande] dddd [klokka] LT'), 'Today - ' + i + ' days current time');
  22254. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  22255. assert.equal(m.calendar(), m.format('[Føregåande] dddd [klokka] LT'), 'Today - ' + i + ' days beginning of day');
  22256. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  22257. assert.equal(m.calendar(), m.format('[Føregåande] dddd [klokka] LT'), 'Today - ' + i + ' days end of day');
  22258. }
  22259. });
  22260. test('calendar all else', function (assert) {
  22261. var weeksAgo = moment().subtract({w: 1}),
  22262. weeksFromNow = moment().add({w: 1});
  22263. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  22264. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  22265. weeksAgo = moment().subtract({w: 2});
  22266. weeksFromNow = moment().add({w: 2});
  22267. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  22268. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  22269. });
  22270. test('weeks year starting sunday', function (assert) {
  22271. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  22272. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  22273. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  22274. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  22275. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  22276. });
  22277. test('weeks year starting monday', function (assert) {
  22278. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  22279. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  22280. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  22281. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  22282. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  22283. });
  22284. test('weeks year starting tuesday', function (assert) {
  22285. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  22286. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  22287. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  22288. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  22289. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  22290. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  22291. });
  22292. test('weeks year starting wednesday', function (assert) {
  22293. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  22294. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  22295. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  22296. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  22297. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  22298. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  22299. });
  22300. test('weeks year starting thursday', function (assert) {
  22301. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  22302. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  22303. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  22304. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  22305. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  22306. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  22307. });
  22308. test('weeks year starting friday', function (assert) {
  22309. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  22310. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  22311. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  22312. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  22313. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  22314. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  22315. });
  22316. test('weeks year starting saturday', function (assert) {
  22317. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  22318. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  22319. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  22320. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  22321. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  22322. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  22323. });
  22324. test('weeks year starting sunday formatted', function (assert) {
  22325. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
  22326. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
  22327. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
  22328. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
  22329. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
  22330. });
  22331. test('lenient ordinal parsing', function (assert) {
  22332. var i, ordinalStr, testMoment;
  22333. for (i = 1; i <= 31; ++i) {
  22334. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  22335. testMoment = moment(ordinalStr, 'YYYY MM Do');
  22336. assert.equal(testMoment.year(), 2014,
  22337. 'lenient ordinal parsing ' + i + ' year check');
  22338. assert.equal(testMoment.month(), 0,
  22339. 'lenient ordinal parsing ' + i + ' month check');
  22340. assert.equal(testMoment.date(), i,
  22341. 'lenient ordinal parsing ' + i + ' date check');
  22342. }
  22343. });
  22344. test('lenient ordinal parsing of number', function (assert) {
  22345. var i, testMoment;
  22346. for (i = 1; i <= 31; ++i) {
  22347. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  22348. assert.equal(testMoment.year(), 2014,
  22349. 'lenient ordinal parsing of number ' + i + ' year check');
  22350. assert.equal(testMoment.month(), 0,
  22351. 'lenient ordinal parsing of number ' + i + ' month check');
  22352. assert.equal(testMoment.date(), i,
  22353. 'lenient ordinal parsing of number ' + i + ' date check');
  22354. }
  22355. });
  22356. test('strict ordinal parsing', function (assert) {
  22357. var i, ordinalStr, testMoment;
  22358. for (i = 1; i <= 31; ++i) {
  22359. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  22360. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  22361. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  22362. }
  22363. });
  22364. }));
  22365. ;(function (global, factory) {
  22366. typeof exports === 'object' && typeof module !== 'undefined'
  22367. && typeof require === 'function' ? factory(require('../../moment')) :
  22368. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  22369. factory(global.moment)
  22370. }(this, function (moment) { 'use strict';
  22371. /*global QUnit:false*/
  22372. var test = QUnit.test;
  22373. var expect = QUnit.expect;
  22374. function module (name, lifecycle) {
  22375. QUnit.module(name, {
  22376. setup : function () {
  22377. moment.locale('en');
  22378. moment.createFromInputFallback = function (config) {
  22379. throw new Error('input not handled by moment: ' + config._i);
  22380. };
  22381. if (lifecycle && lifecycle.setup) {
  22382. lifecycle.setup();
  22383. }
  22384. },
  22385. teardown : function () {
  22386. if (lifecycle && lifecycle.teardown) {
  22387. lifecycle.teardown();
  22388. }
  22389. }
  22390. });
  22391. }
  22392. function localeModule (name, lifecycle) {
  22393. QUnit.module('locale:' + name, {
  22394. setup : function () {
  22395. moment.locale(name);
  22396. moment.createFromInputFallback = function (config) {
  22397. throw new Error('input not handled by moment: ' + config._i);
  22398. };
  22399. if (lifecycle && lifecycle.setup) {
  22400. lifecycle.setup();
  22401. }
  22402. },
  22403. teardown : function () {
  22404. moment.locale('en');
  22405. if (lifecycle && lifecycle.teardown) {
  22406. lifecycle.teardown();
  22407. }
  22408. }
  22409. });
  22410. }
  22411. localeModule('pl');
  22412. test('parse', function (assert) {
  22413. var tests = 'styczeń stycznia sty_luty lutego lut_marzec marca mar_kwiecień kwietnia kwi_maj maja maj_czerwiec czerwca cze_lipiec lipca lip_sierpień sierpnia sie_wrzesień września wrz_październik października paź_listopad listopada lis_grudzień grudnia gru'.split('_'), i;
  22414. function equalTest(input, mmm, i) {
  22415. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  22416. }
  22417. for (i = 0; i < 12; i++) {
  22418. tests[i] = tests[i].split(' ');
  22419. equalTest(tests[i][0], 'MMM', i);
  22420. equalTest(tests[i][1], 'MMM', i);
  22421. equalTest(tests[i][2], 'MMM', i);
  22422. equalTest(tests[i][0], 'MMMM', i);
  22423. equalTest(tests[i][1], 'MMMM', i);
  22424. equalTest(tests[i][2], 'MMMM', i);
  22425. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  22426. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  22427. equalTest(tests[i][2].toLocaleLowerCase(), 'MMMM', i);
  22428. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  22429. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  22430. equalTest(tests[i][2].toLocaleUpperCase(), 'MMMM', i);
  22431. }
  22432. });
  22433. test('parse strict', function (assert) {
  22434. var tests = 'styczeń stycznia sty_luty lutego lut_marzec marca mar_kwiecień kwietnia kwi_maj maja maj_czerwiec czerwca cze_lipiec lipca lip_sierpień sierpnia sie_wrzesień września wrz_październik października paź_listopad listopada lis_grudzień grudnia gru'.split('_'), i;
  22435. function equalTest(input, mmm, i) {
  22436. assert.equal(moment(input, mmm, true).month(), i, input + ' should be month ' + (i + 1));
  22437. }
  22438. for (i = 0; i < 12; i++) {
  22439. tests[i] = tests[i].split(' ');
  22440. equalTest(tests[i][0], 'MMMM', i);
  22441. equalTest(tests[i][1], 'MMMM', i);
  22442. equalTest(tests[i][2], 'MMM', i);
  22443. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  22444. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  22445. equalTest(tests[i][2].toLocaleLowerCase(), 'MMM', i);
  22446. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  22447. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  22448. equalTest(tests[i][2].toLocaleUpperCase(), 'MMM', i);
  22449. }
  22450. });
  22451. test('format', function (assert) {
  22452. var a = [
  22453. ['dddd, MMMM Do YYYY, h:mm:ss a', 'niedziela, luty 14. 2010, 3:25:50 pm'],
  22454. ['ddd, hA', 'nie, 3PM'],
  22455. ['M Mo MM MMMM MMM', '2 2. 02 luty lut'],
  22456. ['YYYY YY', '2010 10'],
  22457. ['D Do DD', '14 14. 14'],
  22458. ['d do dddd ddd dd', '0 0. niedziela nie Nd'],
  22459. ['DDD DDDo DDDD', '45 45. 045'],
  22460. ['w wo ww', '6 6. 06'],
  22461. ['h hh', '3 03'],
  22462. ['H HH', '15 15'],
  22463. ['m mm', '25 25'],
  22464. ['s ss', '50 50'],
  22465. ['a A', 'pm PM'],
  22466. ['[the] DDDo [day of the year]', 'the 45. day of the year'],
  22467. ['LTS', '15:25:50'],
  22468. ['L', '14.02.2010'],
  22469. ['LL', '14 lutego 2010'],
  22470. ['LLL', '14 lutego 2010 15:25'],
  22471. ['LLLL', 'niedziela, 14 lutego 2010 15:25'],
  22472. ['l', '14.2.2010'],
  22473. ['ll', '14 lut 2010'],
  22474. ['lll', '14 lut 2010 15:25'],
  22475. ['llll', 'nie, 14 lut 2010 15:25']
  22476. ],
  22477. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  22478. i;
  22479. for (i = 0; i < a.length; i++) {
  22480. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  22481. }
  22482. });
  22483. test('format ordinal', function (assert) {
  22484. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
  22485. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
  22486. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
  22487. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
  22488. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
  22489. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
  22490. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
  22491. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
  22492. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
  22493. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
  22494. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
  22495. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
  22496. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
  22497. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
  22498. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
  22499. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
  22500. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
  22501. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
  22502. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
  22503. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
  22504. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
  22505. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
  22506. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
  22507. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
  22508. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
  22509. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
  22510. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
  22511. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
  22512. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
  22513. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
  22514. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
  22515. });
  22516. test('format month', function (assert) {
  22517. var expected = 'styczeń sty_luty lut_marzec mar_kwiecień kwi_maj maj_czerwiec cze_lipiec lip_sierpień sie_wrzesień wrz_październik paź_listopad lis_grudzień gru'.split('_'), i;
  22518. for (i = 0; i < expected.length; i++) {
  22519. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  22520. }
  22521. });
  22522. test('format week', function (assert) {
  22523. var expected = 'niedziela nie Nd_poniedziałek pon Pn_wtorek wt Wt_środa śr Śr_czwartek czw Cz_piątek pt Pt_sobota sb So'.split('_'), i;
  22524. for (i = 0; i < expected.length; i++) {
  22525. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  22526. }
  22527. });
  22528. test('from', function (assert) {
  22529. var start = moment([2007, 1, 28]);
  22530. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'kilka sekund', '44 seconds = a few seconds');
  22531. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'minuta', '45 seconds = a minute');
  22532. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'minuta', '89 seconds = a minute');
  22533. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuty', '90 seconds = 2 minutes');
  22534. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuty', '44 minutes = 44 minutes');
  22535. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'godzina', '45 minutes = an hour');
  22536. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'godzina', '89 minutes = an hour');
  22537. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 godziny', '90 minutes = 2 hours');
  22538. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 godzin', '5 hours = 5 hours');
  22539. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 godzin', '21 hours = 21 hours');
  22540. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), '1 dzień', '22 hours = a day');
  22541. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), '1 dzień', '35 hours = a day');
  22542. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dni', '36 hours = 2 days');
  22543. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), '1 dzień', '1 day = a day');
  22544. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dni', '5 days = 5 days');
  22545. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dni', '25 days = 25 days');
  22546. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'miesiąc', '26 days = a month');
  22547. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'miesiąc', '30 days = a month');
  22548. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'miesiąc', '43 days = a month');
  22549. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 miesiące', '46 days = 2 months');
  22550. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 miesiące', '75 days = 2 months');
  22551. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 miesiące', '76 days = 3 months');
  22552. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'miesiąc', '1 month = a month');
  22553. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 miesięcy', '5 months = 5 months');
  22554. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'rok', '345 days = a year');
  22555. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 lata', '548 days = 2 years');
  22556. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'rok', '1 year = a year');
  22557. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 lat', '5 years = 5 years');
  22558. assert.equal(start.from(moment([2007, 1, 28]).add({y: 112}), true), '112 lat', '112 years = 112 years');
  22559. assert.equal(start.from(moment([2007, 1, 28]).add({y: 122}), true), '122 lata', '122 years = 122 years');
  22560. assert.equal(start.from(moment([2007, 1, 28]).add({y: 213}), true), '213 lat', '213 years = 213 years');
  22561. assert.equal(start.from(moment([2007, 1, 28]).add({y: 223}), true), '223 lata', '223 years = 223 years');
  22562. });
  22563. test('suffix', function (assert) {
  22564. assert.equal(moment(30000).from(0), 'za kilka sekund', 'prefix');
  22565. assert.equal(moment(0).from(30000), 'kilka sekund temu', 'suffix');
  22566. });
  22567. test('now from now', function (assert) {
  22568. assert.equal(moment().fromNow(), 'kilka sekund temu', 'now from now should display as in the past');
  22569. });
  22570. test('fromNow', function (assert) {
  22571. assert.equal(moment().add({s: 30}).fromNow(), 'za kilka sekund', 'in a few seconds');
  22572. assert.equal(moment().add({h: 1}).fromNow(), 'za godzinę', 'in an hour');
  22573. assert.equal(moment().add({d: 5}).fromNow(), 'za 5 dni', 'in 5 days');
  22574. });
  22575. test('calendar day', function (assert) {
  22576. var a = moment().hours(2).minutes(0).seconds(0);
  22577. assert.equal(moment(a).calendar(), 'Dziś o 02:00', 'today at the same time');
  22578. assert.equal(moment(a).add({m: 25}).calendar(), 'Dziś o 02:25', 'Now plus 25 min');
  22579. assert.equal(moment(a).add({h: 1}).calendar(), 'Dziś o 03:00', 'Now plus 1 hour');
  22580. assert.equal(moment(a).add({d: 1}).calendar(), 'Jutro o 02:00', 'tomorrow at the same time');
  22581. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Dziś o 01:00', 'Now minus 1 hour');
  22582. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Wczoraj o 02:00', 'yesterday at the same time');
  22583. });
  22584. test('calendar next week', function (assert) {
  22585. var i, m;
  22586. for (i = 2; i < 7; i++) {
  22587. m = moment().add({d: i});
  22588. assert.equal(m.calendar(), m.format('[W] dddd [o] LT'), 'Today + ' + i + ' days current time');
  22589. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  22590. assert.equal(m.calendar(), m.format('[W] dddd [o] LT'), 'Today + ' + i + ' days beginning of day');
  22591. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  22592. assert.equal(m.calendar(), m.format('[W] dddd [o] LT'), 'Today + ' + i + ' days end of day');
  22593. }
  22594. });
  22595. test('calendar last week', function (assert) {
  22596. var i, m;
  22597. function makeFormat(d) {
  22598. switch (d.day()) {
  22599. case 0:
  22600. return '[W zeszłą niedzielę o] LT';
  22601. case 3:
  22602. return '[W zeszłą środę o] LT';
  22603. case 6:
  22604. return '[W zeszłą sobotę o] LT';
  22605. default:
  22606. return '[W zeszły] dddd [o] LT';
  22607. }
  22608. }
  22609. for (i = 2; i < 7; i++) {
  22610. m = moment().subtract({d: i});
  22611. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days current time');
  22612. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  22613. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days beginning of day');
  22614. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  22615. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days end of day');
  22616. }
  22617. });
  22618. test('calendar all else', function (assert) {
  22619. var weeksAgo = moment().subtract({w: 1}),
  22620. weeksFromNow = moment().add({w: 1});
  22621. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  22622. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  22623. weeksAgo = moment().subtract({w: 2});
  22624. weeksFromNow = moment().add({w: 2});
  22625. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  22626. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  22627. });
  22628. test('weeks year starting sunday', function (assert) {
  22629. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  22630. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  22631. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  22632. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  22633. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  22634. });
  22635. test('weeks year starting monday', function (assert) {
  22636. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  22637. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  22638. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  22639. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  22640. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  22641. });
  22642. test('weeks year starting tuesday', function (assert) {
  22643. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  22644. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  22645. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  22646. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  22647. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  22648. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  22649. });
  22650. test('weeks year starting wednesday', function (assert) {
  22651. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  22652. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  22653. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  22654. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  22655. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  22656. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  22657. });
  22658. test('weeks year starting thursday', function (assert) {
  22659. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  22660. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  22661. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  22662. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  22663. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  22664. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  22665. });
  22666. test('weeks year starting friday', function (assert) {
  22667. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  22668. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  22669. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  22670. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  22671. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  22672. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  22673. });
  22674. test('weeks year starting saturday', function (assert) {
  22675. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  22676. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  22677. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  22678. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  22679. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  22680. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  22681. });
  22682. test('weeks year starting sunday formatted', function (assert) {
  22683. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
  22684. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
  22685. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
  22686. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
  22687. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
  22688. });
  22689. test('lenient ordinal parsing', function (assert) {
  22690. var i, ordinalStr, testMoment;
  22691. for (i = 1; i <= 31; ++i) {
  22692. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  22693. testMoment = moment(ordinalStr, 'YYYY MM Do');
  22694. assert.equal(testMoment.year(), 2014,
  22695. 'lenient ordinal parsing ' + i + ' year check');
  22696. assert.equal(testMoment.month(), 0,
  22697. 'lenient ordinal parsing ' + i + ' month check');
  22698. assert.equal(testMoment.date(), i,
  22699. 'lenient ordinal parsing ' + i + ' date check');
  22700. }
  22701. });
  22702. test('lenient ordinal parsing of number', function (assert) {
  22703. var i, testMoment;
  22704. for (i = 1; i <= 31; ++i) {
  22705. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  22706. assert.equal(testMoment.year(), 2014,
  22707. 'lenient ordinal parsing of number ' + i + ' year check');
  22708. assert.equal(testMoment.month(), 0,
  22709. 'lenient ordinal parsing of number ' + i + ' month check');
  22710. assert.equal(testMoment.date(), i,
  22711. 'lenient ordinal parsing of number ' + i + ' date check');
  22712. }
  22713. });
  22714. test('strict ordinal parsing', function (assert) {
  22715. var i, ordinalStr, testMoment;
  22716. for (i = 1; i <= 31; ++i) {
  22717. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  22718. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  22719. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  22720. }
  22721. });
  22722. }));
  22723. ;(function (global, factory) {
  22724. typeof exports === 'object' && typeof module !== 'undefined'
  22725. && typeof require === 'function' ? factory(require('../../moment')) :
  22726. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  22727. factory(global.moment)
  22728. }(this, function (moment) { 'use strict';
  22729. /*global QUnit:false*/
  22730. var test = QUnit.test;
  22731. var expect = QUnit.expect;
  22732. function module (name, lifecycle) {
  22733. QUnit.module(name, {
  22734. setup : function () {
  22735. moment.locale('en');
  22736. moment.createFromInputFallback = function (config) {
  22737. throw new Error('input not handled by moment: ' + config._i);
  22738. };
  22739. if (lifecycle && lifecycle.setup) {
  22740. lifecycle.setup();
  22741. }
  22742. },
  22743. teardown : function () {
  22744. if (lifecycle && lifecycle.teardown) {
  22745. lifecycle.teardown();
  22746. }
  22747. }
  22748. });
  22749. }
  22750. function localeModule (name, lifecycle) {
  22751. QUnit.module('locale:' + name, {
  22752. setup : function () {
  22753. moment.locale(name);
  22754. moment.createFromInputFallback = function (config) {
  22755. throw new Error('input not handled by moment: ' + config._i);
  22756. };
  22757. if (lifecycle && lifecycle.setup) {
  22758. lifecycle.setup();
  22759. }
  22760. },
  22761. teardown : function () {
  22762. moment.locale('en');
  22763. if (lifecycle && lifecycle.teardown) {
  22764. lifecycle.teardown();
  22765. }
  22766. }
  22767. });
  22768. }
  22769. localeModule('pt-br');
  22770. test('parse', function (assert) {
  22771. var tests = 'janeiro jan_fevereiro fev_março mar_abril abr_maio mai_junho jun_julho jul_agosto ago_setembro set_outubro out_novembro nov_dezembro dez'.split('_'), i;
  22772. function equalTest(input, mmm, i) {
  22773. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  22774. }
  22775. for (i = 0; i < 12; i++) {
  22776. tests[i] = tests[i].split(' ');
  22777. equalTest(tests[i][0], 'MMM', i);
  22778. equalTest(tests[i][1], 'MMM', i);
  22779. equalTest(tests[i][0], 'MMMM', i);
  22780. equalTest(tests[i][1], 'MMMM', i);
  22781. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  22782. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  22783. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  22784. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  22785. }
  22786. });
  22787. test('format', function (assert) {
  22788. var a = [
  22789. ['dddd, MMMM Do YYYY, h:mm:ss a', 'Domingo, Fevereiro 14º 2010, 3:25:50 pm'],
  22790. ['ddd, hA', 'Dom, 3PM'],
  22791. ['M Mo MM MMMM MMM', '2 2º 02 Fevereiro Fev'],
  22792. ['YYYY YY', '2010 10'],
  22793. ['D Do DD', '14 14º 14'],
  22794. ['d do dddd ddd', '0 0º Domingo Dom'],
  22795. ['DDD DDDo DDDD', '45 45º 045'],
  22796. ['w wo ww', '8 8º 08'],
  22797. ['h hh', '3 03'],
  22798. ['H HH', '15 15'],
  22799. ['m mm', '25 25'],
  22800. ['s ss', '50 50'],
  22801. ['a A', 'pm PM'],
  22802. ['[the] DDDo [day of the year]', 'the 45º day of the year'],
  22803. ['LTS', '15:25:50'],
  22804. ['L', '14/02/2010'],
  22805. ['LL', '14 de Fevereiro de 2010'],
  22806. ['LLL', '14 de Fevereiro de 2010 às 15:25'],
  22807. ['LLLL', 'Domingo, 14 de Fevereiro de 2010 às 15:25'],
  22808. ['l', '14/2/2010'],
  22809. ['ll', '14 de Fev de 2010'],
  22810. ['lll', '14 de Fev de 2010 às 15:25'],
  22811. ['llll', 'Dom, 14 de Fev de 2010 às 15:25']
  22812. ],
  22813. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  22814. i;
  22815. for (i = 0; i < a.length; i++) {
  22816. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  22817. }
  22818. });
  22819. test('format ordinal', function (assert) {
  22820. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1º', '1º');
  22821. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2º', '2º');
  22822. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3º', '3º');
  22823. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4º', '4º');
  22824. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5º', '5º');
  22825. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6º', '6º');
  22826. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7º', '7º');
  22827. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8º', '8º');
  22828. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9º', '9º');
  22829. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10º', '10º');
  22830. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11º', '11º');
  22831. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12º', '12º');
  22832. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13º', '13º');
  22833. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14º', '14º');
  22834. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15º', '15º');
  22835. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16º', '16º');
  22836. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17º', '17º');
  22837. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18º', '18º');
  22838. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19º', '19º');
  22839. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20º', '20º');
  22840. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21º', '21º');
  22841. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22º', '22º');
  22842. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23º', '23º');
  22843. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24º', '24º');
  22844. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25º', '25º');
  22845. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26º', '26º');
  22846. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27º', '27º');
  22847. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28º', '28º');
  22848. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29º', '29º');
  22849. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30º', '30º');
  22850. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31º', '31º');
  22851. });
  22852. test('format month', function (assert) {
  22853. var expected = 'Janeiro Jan_Fevereiro Fev_Março Mar_Abril Abr_Maio Mai_Junho Jun_Julho Jul_Agosto Ago_Setembro Set_Outubro Out_Novembro Nov_Dezembro Dez'.split('_'), i;
  22854. for (i = 0; i < expected.length; i++) {
  22855. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  22856. }
  22857. });
  22858. test('format week', function (assert) {
  22859. var expected = 'Domingo Dom_Segunda-Feira Seg_Terça-Feira Ter_Quarta-Feira Qua_Quinta-Feira Qui_Sexta-Feira Sex_Sábado Sáb'.split('_'), i;
  22860. for (i = 0; i < expected.length; i++) {
  22861. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd'), expected[i], expected[i]);
  22862. }
  22863. });
  22864. test('from', function (assert) {
  22865. var start = moment([2007, 1, 28]);
  22866. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'poucos segundos', '44 seconds = seconds');
  22867. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'um minuto', '45 seconds = a minute');
  22868. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'um minuto', '89 seconds = a minute');
  22869. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutos', '90 seconds = 2 minutes');
  22870. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutos', '44 minutes = 44 minutes');
  22871. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'uma hora', '45 minutes = an hour');
  22872. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'uma hora', '89 minutes = an hour');
  22873. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 horas', '90 minutes = 2 hours');
  22874. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 horas', '5 hours = 5 hours');
  22875. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 horas', '21 hours = 21 hours');
  22876. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'um dia', '22 hours = a day');
  22877. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'um dia', '35 hours = a day');
  22878. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dias', '36 hours = 2 days');
  22879. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'um dia', '1 day = a day');
  22880. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dias', '5 days = 5 days');
  22881. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dias', '25 days = 25 days');
  22882. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'um mês', '26 days = a month');
  22883. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'um mês', '30 days = a month');
  22884. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'um mês', '43 days = a month');
  22885. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 meses', '46 days = 2 months');
  22886. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 meses', '75 days = 2 months');
  22887. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 meses', '76 days = 3 months');
  22888. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'um mês', '1 month = a month');
  22889. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 meses', '5 months = 5 months');
  22890. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'um ano', '345 days = a year');
  22891. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 anos', '548 days = 2 years');
  22892. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'um ano', '1 year = a year');
  22893. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 anos', '5 years = 5 years');
  22894. });
  22895. test('suffix', function (assert) {
  22896. assert.equal(moment(30000).from(0), 'em poucos segundos', 'prefix');
  22897. assert.equal(moment(0).from(30000), 'poucos segundos atrás', 'suffix');
  22898. });
  22899. test('fromNow', function (assert) {
  22900. assert.equal(moment().add({s: 30}).fromNow(), 'em poucos segundos', 'in seconds');
  22901. assert.equal(moment().add({d: 5}).fromNow(), 'em 5 dias', 'in 5 days');
  22902. });
  22903. test('calendar day', function (assert) {
  22904. var a = moment().hours(2).minutes(0).seconds(0);
  22905. assert.equal(moment(a).calendar(), 'Hoje às 02:00', 'today at the same time');
  22906. assert.equal(moment(a).add({m: 25}).calendar(), 'Hoje às 02:25', 'Now plus 25 min');
  22907. assert.equal(moment(a).add({h: 1}).calendar(), 'Hoje às 03:00', 'Now plus 1 hour');
  22908. assert.equal(moment(a).add({d: 1}).calendar(), 'Amanhã às 02:00', 'tomorrow at the same time');
  22909. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Hoje às 01:00', 'Now minus 1 hour');
  22910. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Ontem às 02:00', 'yesterday at the same time');
  22911. });
  22912. test('calendar next week', function (assert) {
  22913. var i, m;
  22914. for (i = 2; i < 7; i++) {
  22915. m = moment().add({d: i});
  22916. assert.equal(m.calendar(), m.format('dddd [às] LT'), 'Today + ' + i + ' days current time');
  22917. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  22918. assert.equal(m.calendar(), m.format('dddd [às] LT'), 'Today + ' + i + ' days beginning of day');
  22919. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  22920. assert.equal(m.calendar(), m.format('dddd [às] LT'), 'Today + ' + i + ' days end of day');
  22921. }
  22922. });
  22923. test('calendar last week', function (assert) {
  22924. var i, m;
  22925. for (i = 2; i < 7; i++) {
  22926. m = moment().subtract({d: i});
  22927. assert.equal(m.calendar(), m.format((m.day() === 0 || m.day() === 6) ? '[Último] dddd [às] LT' : '[Última] dddd [às] LT'), 'Today - ' + i + ' days current time');
  22928. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  22929. assert.equal(m.calendar(), m.format((m.day() === 0 || m.day() === 6) ? '[Último] dddd [às] LT' : '[Última] dddd [às] LT'), 'Today - ' + i + ' days beginning of day');
  22930. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  22931. assert.equal(m.calendar(), m.format((m.day() === 0 || m.day() === 6) ? '[Último] dddd [às] LT' : '[Última] dddd [às] LT'), 'Today - ' + i + ' days end of day');
  22932. }
  22933. });
  22934. test('calendar all else', function (assert) {
  22935. var weeksAgo = moment().subtract({w: 1}),
  22936. weeksFromNow = moment().add({w: 1});
  22937. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  22938. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  22939. weeksAgo = moment().subtract({w: 2});
  22940. weeksFromNow = moment().add({w: 2});
  22941. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  22942. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  22943. });
  22944. test('weeks year starting sunday', function (assert) {
  22945. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  22946. assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1');
  22947. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  22948. assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2');
  22949. assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 3');
  22950. });
  22951. test('weeks year starting monday', function (assert) {
  22952. assert.equal(moment([2006, 11, 31]).week(), 1, 'Dec 31 2006 should be week 1');
  22953. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  22954. assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1');
  22955. assert.equal(moment([2007, 0, 7]).week(), 2, 'Jan 7 2007 should be week 2');
  22956. assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2');
  22957. assert.equal(moment([2007, 0, 14]).week(), 3, 'Jan 14 2007 should be week 3');
  22958. });
  22959. test('weeks year starting tuesday', function (assert) {
  22960. assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52');
  22961. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  22962. assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1');
  22963. assert.equal(moment([2008, 0, 6]).week(), 2, 'Jan 6 2008 should be week 2');
  22964. assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2');
  22965. assert.equal(moment([2008, 0, 13]).week(), 3, 'Jan 13 2008 should be week 3');
  22966. });
  22967. test('weeks year starting wednesday', function (assert) {
  22968. assert.equal(moment([2002, 11, 29]).week(), 1, 'Dec 29 2002 should be week 1');
  22969. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  22970. assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1');
  22971. assert.equal(moment([2003, 0, 5]).week(), 2, 'Jan 5 2003 should be week 2');
  22972. assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2');
  22973. assert.equal(moment([2003, 0, 12]).week(), 3, 'Jan 12 2003 should be week 3');
  22974. });
  22975. test('weeks year starting thursday', function (assert) {
  22976. assert.equal(moment([2008, 11, 28]).week(), 1, 'Dec 28 2008 should be week 1');
  22977. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  22978. assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1');
  22979. assert.equal(moment([2009, 0, 4]).week(), 2, 'Jan 4 2009 should be week 2');
  22980. assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2');
  22981. assert.equal(moment([2009, 0, 11]).week(), 3, 'Jan 11 2009 should be week 3');
  22982. });
  22983. test('weeks year starting friday', function (assert) {
  22984. assert.equal(moment([2009, 11, 27]).week(), 1, 'Dec 27 2009 should be week 1');
  22985. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  22986. assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 should be week 1');
  22987. assert.equal(moment([2010, 0, 3]).week(), 2, 'Jan 3 2010 should be week 2');
  22988. assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 should be week 2');
  22989. assert.equal(moment([2010, 0, 10]).week(), 3, 'Jan 10 2010 should be week 3');
  22990. });
  22991. test('weeks year starting saturday', function (assert) {
  22992. assert.equal(moment([2010, 11, 26]).week(), 1, 'Dec 26 2010 should be week 1');
  22993. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  22994. assert.equal(moment([2011, 0, 2]).week(), 2, 'Jan 2 2011 should be week 2');
  22995. assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2');
  22996. assert.equal(moment([2011, 0, 9]).week(), 3, 'Jan 9 2011 should be week 3');
  22997. });
  22998. test('weeks year starting sunday format', function (assert) {
  22999. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1º', 'Jan 1 2012 should be week 1');
  23000. assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1º', 'Jan 7 2012 should be week 1');
  23001. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2º', 'Jan 8 2012 should be week 2');
  23002. assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2º', 'Jan 14 2012 should be week 2');
  23003. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3º', 'Jan 15 2012 should be week 3');
  23004. });
  23005. test('lenient ordinal parsing', function (assert) {
  23006. var i, ordinalStr, testMoment;
  23007. for (i = 1; i <= 31; ++i) {
  23008. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  23009. testMoment = moment(ordinalStr, 'YYYY MM Do');
  23010. assert.equal(testMoment.year(), 2014,
  23011. 'lenient ordinal parsing ' + i + ' year check');
  23012. assert.equal(testMoment.month(), 0,
  23013. 'lenient ordinal parsing ' + i + ' month check');
  23014. assert.equal(testMoment.date(), i,
  23015. 'lenient ordinal parsing ' + i + ' date check');
  23016. }
  23017. });
  23018. test('lenient ordinal parsing of number', function (assert) {
  23019. var i, testMoment;
  23020. for (i = 1; i <= 31; ++i) {
  23021. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  23022. assert.equal(testMoment.year(), 2014,
  23023. 'lenient ordinal parsing of number ' + i + ' year check');
  23024. assert.equal(testMoment.month(), 0,
  23025. 'lenient ordinal parsing of number ' + i + ' month check');
  23026. assert.equal(testMoment.date(), i,
  23027. 'lenient ordinal parsing of number ' + i + ' date check');
  23028. }
  23029. });
  23030. test('strict ordinal parsing', function (assert) {
  23031. var i, ordinalStr, testMoment;
  23032. for (i = 1; i <= 31; ++i) {
  23033. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  23034. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  23035. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  23036. }
  23037. });
  23038. }));
  23039. ;(function (global, factory) {
  23040. typeof exports === 'object' && typeof module !== 'undefined'
  23041. && typeof require === 'function' ? factory(require('../../moment')) :
  23042. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  23043. factory(global.moment)
  23044. }(this, function (moment) { 'use strict';
  23045. /*global QUnit:false*/
  23046. var test = QUnit.test;
  23047. var expect = QUnit.expect;
  23048. function module (name, lifecycle) {
  23049. QUnit.module(name, {
  23050. setup : function () {
  23051. moment.locale('en');
  23052. moment.createFromInputFallback = function (config) {
  23053. throw new Error('input not handled by moment: ' + config._i);
  23054. };
  23055. if (lifecycle && lifecycle.setup) {
  23056. lifecycle.setup();
  23057. }
  23058. },
  23059. teardown : function () {
  23060. if (lifecycle && lifecycle.teardown) {
  23061. lifecycle.teardown();
  23062. }
  23063. }
  23064. });
  23065. }
  23066. function localeModule (name, lifecycle) {
  23067. QUnit.module('locale:' + name, {
  23068. setup : function () {
  23069. moment.locale(name);
  23070. moment.createFromInputFallback = function (config) {
  23071. throw new Error('input not handled by moment: ' + config._i);
  23072. };
  23073. if (lifecycle && lifecycle.setup) {
  23074. lifecycle.setup();
  23075. }
  23076. },
  23077. teardown : function () {
  23078. moment.locale('en');
  23079. if (lifecycle && lifecycle.teardown) {
  23080. lifecycle.teardown();
  23081. }
  23082. }
  23083. });
  23084. }
  23085. localeModule('pt');
  23086. test('parse', function (assert) {
  23087. var tests = 'Janeiro Jan_Fevereiro Fev_Março Mar_Abril Abr_Maio Mai_Junho Jun_Julho Jul_Agosto Ago_Setembro Set_Outubro Out_Novembro Nov_Dezembro Dez'.split('_'), i;
  23088. function equalTest(input, mmm, i) {
  23089. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  23090. }
  23091. for (i = 0; i < 12; i++) {
  23092. tests[i] = tests[i].split(' ');
  23093. equalTest(tests[i][0], 'MMM', i);
  23094. equalTest(tests[i][1], 'MMM', i);
  23095. equalTest(tests[i][0], 'MMMM', i);
  23096. equalTest(tests[i][1], 'MMMM', i);
  23097. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  23098. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  23099. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  23100. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  23101. }
  23102. });
  23103. test('format', function (assert) {
  23104. var a = [
  23105. ['dddd, MMMM Do YYYY, h:mm:ss a', 'Domingo, Fevereiro 14º 2010, 3:25:50 pm'],
  23106. ['ddd, hA', 'Dom, 3PM'],
  23107. ['M Mo MM MMMM MMM', '2 2º 02 Fevereiro Fev'],
  23108. ['YYYY YY', '2010 10'],
  23109. ['D Do DD', '14 14º 14'],
  23110. ['d do dddd ddd', '0 0º Domingo Dom'],
  23111. ['DDD DDDo DDDD', '45 45º 045'],
  23112. ['w wo ww', '6 6º 06'],
  23113. ['h hh', '3 03'],
  23114. ['H HH', '15 15'],
  23115. ['m mm', '25 25'],
  23116. ['s ss', '50 50'],
  23117. ['a A', 'pm PM'],
  23118. ['[the] DDDo [day of the year]', 'the 45º day of the year'],
  23119. ['LTS', '15:25:50'],
  23120. ['L', '14/02/2010'],
  23121. ['LL', '14 de Fevereiro de 2010'],
  23122. ['LLL', '14 de Fevereiro de 2010 15:25'],
  23123. ['LLLL', 'Domingo, 14 de Fevereiro de 2010 15:25'],
  23124. ['l', '14/2/2010'],
  23125. ['ll', '14 de Fev de 2010'],
  23126. ['lll', '14 de Fev de 2010 15:25'],
  23127. ['llll', 'Dom, 14 de Fev de 2010 15:25']
  23128. ],
  23129. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  23130. i;
  23131. for (i = 0; i < a.length; i++) {
  23132. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  23133. }
  23134. });
  23135. test('format ordinal', function (assert) {
  23136. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1º', '1º');
  23137. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2º', '2º');
  23138. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3º', '3º');
  23139. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4º', '4º');
  23140. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5º', '5º');
  23141. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6º', '6º');
  23142. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7º', '7º');
  23143. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8º', '8º');
  23144. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9º', '9º');
  23145. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10º', '10º');
  23146. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11º', '11º');
  23147. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12º', '12º');
  23148. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13º', '13º');
  23149. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14º', '14º');
  23150. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15º', '15º');
  23151. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16º', '16º');
  23152. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17º', '17º');
  23153. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18º', '18º');
  23154. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19º', '19º');
  23155. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20º', '20º');
  23156. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21º', '21º');
  23157. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22º', '22º');
  23158. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23º', '23º');
  23159. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24º', '24º');
  23160. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25º', '25º');
  23161. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26º', '26º');
  23162. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27º', '27º');
  23163. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28º', '28º');
  23164. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29º', '29º');
  23165. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30º', '30º');
  23166. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31º', '31º');
  23167. });
  23168. test('format month', function (assert) {
  23169. var expected = 'Janeiro Jan_Fevereiro Fev_Março Mar_Abril Abr_Maio Mai_Junho Jun_Julho Jul_Agosto Ago_Setembro Set_Outubro Out_Novembro Nov_Dezembro Dez'.split('_'), i;
  23170. for (i = 0; i < expected.length; i++) {
  23171. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  23172. }
  23173. });
  23174. test('format week', function (assert) {
  23175. var expected = 'Domingo Dom Dom_Segunda-Feira Seg 2ª_Terça-Feira Ter 3ª_Quarta-Feira Qua 4ª_Quinta-Feira Qui 5ª_Sexta-Feira Sex 6ª_Sábado Sáb Sáb'.split('_'), i;
  23176. for (i = 0; i < expected.length; i++) {
  23177. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  23178. }
  23179. });
  23180. test('from', function (assert) {
  23181. var start = moment([2007, 1, 28]);
  23182. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'segundos', '44 seconds = seconds');
  23183. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'um minuto', '45 seconds = a minute');
  23184. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'um minuto', '89 seconds = a minute');
  23185. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutos', '90 seconds = 2 minutes');
  23186. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutos', '44 minutes = 44 minutes');
  23187. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'uma hora', '45 minutes = an hour');
  23188. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'uma hora', '89 minutes = an hour');
  23189. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 horas', '90 minutes = 2 hours');
  23190. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 horas', '5 hours = 5 hours');
  23191. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 horas', '21 hours = 21 hours');
  23192. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'um dia', '22 hours = a day');
  23193. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'um dia', '35 hours = a day');
  23194. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dias', '36 hours = 2 days');
  23195. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'um dia', '1 day = a day');
  23196. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dias', '5 days = 5 days');
  23197. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dias', '25 days = 25 days');
  23198. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'um mês', '26 days = a month');
  23199. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'um mês', '30 days = a month');
  23200. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'um mês', '43 days = a month');
  23201. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 meses', '46 days = 2 months');
  23202. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 meses', '75 days = 2 months');
  23203. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 meses', '76 days = 3 months');
  23204. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'um mês', '1 month = a month');
  23205. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 meses', '5 months = 5 months');
  23206. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'um ano', '345 days = a year');
  23207. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 anos', '548 days = 2 years');
  23208. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'um ano', '1 year = a year');
  23209. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 anos', '5 years = 5 years');
  23210. });
  23211. test('suffix', function (assert) {
  23212. assert.equal(moment(30000).from(0), 'em segundos', 'prefix');
  23213. assert.equal(moment(0).from(30000), 'há segundos', 'suffix');
  23214. });
  23215. test('fromNow', function (assert) {
  23216. assert.equal(moment().add({s: 30}).fromNow(), 'em segundos', 'in seconds');
  23217. assert.equal(moment().add({d: 5}).fromNow(), 'em 5 dias', 'in 5 days');
  23218. });
  23219. test('calendar day', function (assert) {
  23220. var a = moment().hours(2).minutes(0).seconds(0);
  23221. assert.equal(moment(a).calendar(), 'Hoje às 02:00', 'today at the same time');
  23222. assert.equal(moment(a).add({m: 25}).calendar(), 'Hoje às 02:25', 'Now plus 25 min');
  23223. assert.equal(moment(a).add({h: 1}).calendar(), 'Hoje às 03:00', 'Now plus 1 hour');
  23224. assert.equal(moment(a).add({d: 1}).calendar(), 'Amanhã às 02:00', 'tomorrow at the same time');
  23225. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Hoje às 01:00', 'Now minus 1 hour');
  23226. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Ontem às 02:00', 'yesterday at the same time');
  23227. });
  23228. test('calendar next week', function (assert) {
  23229. var i, m;
  23230. for (i = 2; i < 7; i++) {
  23231. m = moment().add({d: i});
  23232. assert.equal(m.calendar(), m.format('dddd [às] LT'), 'Today + ' + i + ' days current time');
  23233. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  23234. assert.equal(m.calendar(), m.format('dddd [às] LT'), 'Today + ' + i + ' days beginning of day');
  23235. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  23236. assert.equal(m.calendar(), m.format('dddd [às] LT'), 'Today + ' + i + ' days end of day');
  23237. }
  23238. });
  23239. test('calendar last week', function (assert) {
  23240. var i, m;
  23241. for (i = 2; i < 7; i++) {
  23242. m = moment().subtract({d: i});
  23243. assert.equal(m.calendar(), m.format((m.day() === 0 || m.day() === 6) ? '[Último] dddd [às] LT' : '[Última] dddd [às] LT'), 'Today - ' + i + ' days current time');
  23244. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  23245. assert.equal(m.calendar(), m.format((m.day() === 0 || m.day() === 6) ? '[Último] dddd [às] LT' : '[Última] dddd [às] LT'), 'Today - ' + i + ' days beginning of day');
  23246. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  23247. assert.equal(m.calendar(), m.format((m.day() === 0 || m.day() === 6) ? '[Último] dddd [às] LT' : '[Última] dddd [às] LT'), 'Today - ' + i + ' days end of day');
  23248. }
  23249. });
  23250. test('calendar all else', function (assert) {
  23251. var weeksAgo = moment().subtract({w: 1}),
  23252. weeksFromNow = moment().add({w: 1});
  23253. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  23254. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  23255. weeksAgo = moment().subtract({w: 2});
  23256. weeksFromNow = moment().add({w: 2});
  23257. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  23258. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  23259. });
  23260. test('weeks year starting sunday', function (assert) {
  23261. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  23262. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  23263. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  23264. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  23265. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  23266. });
  23267. test('weeks year starting monday', function (assert) {
  23268. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  23269. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  23270. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  23271. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  23272. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  23273. });
  23274. test('weeks year starting tuesday', function (assert) {
  23275. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  23276. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  23277. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  23278. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  23279. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  23280. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  23281. });
  23282. test('weeks year starting wednesday', function (assert) {
  23283. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  23284. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  23285. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  23286. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  23287. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  23288. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  23289. });
  23290. test('weeks year starting thursday', function (assert) {
  23291. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  23292. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  23293. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  23294. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  23295. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  23296. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  23297. });
  23298. test('weeks year starting friday', function (assert) {
  23299. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  23300. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  23301. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  23302. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  23303. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  23304. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  23305. });
  23306. test('weeks year starting saturday', function (assert) {
  23307. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  23308. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  23309. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  23310. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  23311. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  23312. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  23313. });
  23314. test('weeks year starting sunday formatted', function (assert) {
  23315. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52º', 'Jan 1 2012 should be week 52');
  23316. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1º', 'Jan 2 2012 should be week 1');
  23317. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1º', 'Jan 8 2012 should be week 1');
  23318. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2º', 'Jan 9 2012 should be week 2');
  23319. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2º', 'Jan 15 2012 should be week 2');
  23320. });
  23321. test('lenient ordinal parsing', function (assert) {
  23322. var i, ordinalStr, testMoment;
  23323. for (i = 1; i <= 31; ++i) {
  23324. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  23325. testMoment = moment(ordinalStr, 'YYYY MM Do');
  23326. assert.equal(testMoment.year(), 2014,
  23327. 'lenient ordinal parsing ' + i + ' year check');
  23328. assert.equal(testMoment.month(), 0,
  23329. 'lenient ordinal parsing ' + i + ' month check');
  23330. assert.equal(testMoment.date(), i,
  23331. 'lenient ordinal parsing ' + i + ' date check');
  23332. }
  23333. });
  23334. test('lenient ordinal parsing of number', function (assert) {
  23335. var i, testMoment;
  23336. for (i = 1; i <= 31; ++i) {
  23337. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  23338. assert.equal(testMoment.year(), 2014,
  23339. 'lenient ordinal parsing of number ' + i + ' year check');
  23340. assert.equal(testMoment.month(), 0,
  23341. 'lenient ordinal parsing of number ' + i + ' month check');
  23342. assert.equal(testMoment.date(), i,
  23343. 'lenient ordinal parsing of number ' + i + ' date check');
  23344. }
  23345. });
  23346. test('strict ordinal parsing', function (assert) {
  23347. var i, ordinalStr, testMoment;
  23348. for (i = 1; i <= 31; ++i) {
  23349. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  23350. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  23351. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  23352. }
  23353. });
  23354. }));
  23355. ;(function (global, factory) {
  23356. typeof exports === 'object' && typeof module !== 'undefined'
  23357. && typeof require === 'function' ? factory(require('../../moment')) :
  23358. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  23359. factory(global.moment)
  23360. }(this, function (moment) { 'use strict';
  23361. /*global QUnit:false*/
  23362. var test = QUnit.test;
  23363. var expect = QUnit.expect;
  23364. function module (name, lifecycle) {
  23365. QUnit.module(name, {
  23366. setup : function () {
  23367. moment.locale('en');
  23368. moment.createFromInputFallback = function (config) {
  23369. throw new Error('input not handled by moment: ' + config._i);
  23370. };
  23371. if (lifecycle && lifecycle.setup) {
  23372. lifecycle.setup();
  23373. }
  23374. },
  23375. teardown : function () {
  23376. if (lifecycle && lifecycle.teardown) {
  23377. lifecycle.teardown();
  23378. }
  23379. }
  23380. });
  23381. }
  23382. function localeModule (name, lifecycle) {
  23383. QUnit.module('locale:' + name, {
  23384. setup : function () {
  23385. moment.locale(name);
  23386. moment.createFromInputFallback = function (config) {
  23387. throw new Error('input not handled by moment: ' + config._i);
  23388. };
  23389. if (lifecycle && lifecycle.setup) {
  23390. lifecycle.setup();
  23391. }
  23392. },
  23393. teardown : function () {
  23394. moment.locale('en');
  23395. if (lifecycle && lifecycle.teardown) {
  23396. lifecycle.teardown();
  23397. }
  23398. }
  23399. });
  23400. }
  23401. localeModule('ro');
  23402. test('parse', function (assert) {
  23403. var tests = 'ianuarie ian._februarie febr._martie mart._aprilie apr._mai mai_iunie iun._iulie iul._august aug._septembrie sept._octombrie oct._noiembrie nov._decembrie dec.'.split('_'), i;
  23404. function equalTest(input, mmm, i) {
  23405. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  23406. }
  23407. for (i = 0; i < 12; i++) {
  23408. tests[i] = tests[i].split(' ');
  23409. equalTest(tests[i][0], 'MMM', i);
  23410. equalTest(tests[i][1], 'MMM', i);
  23411. equalTest(tests[i][0], 'MMMM', i);
  23412. equalTest(tests[i][1], 'MMMM', i);
  23413. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  23414. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  23415. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  23416. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  23417. }
  23418. });
  23419. test('format', function (assert) {
  23420. var a = [
  23421. ['dddd, MMMM Do YYYY, h:mm:ss A', 'duminică, februarie 14 2010, 3:25:50 PM'],
  23422. ['ddd, hA', 'Dum, 3PM'],
  23423. ['M Mo MM MMMM MMM', '2 2 02 februarie febr.'],
  23424. ['YYYY YY', '2010 10'],
  23425. ['D Do DD', '14 14 14'],
  23426. ['d do dddd ddd dd', '0 0 duminică Dum Du'],
  23427. ['DDD DDDo DDDD', '45 45 045'],
  23428. ['w wo ww', '7 7 07'],
  23429. ['h hh', '3 03'],
  23430. ['H HH', '15 15'],
  23431. ['m mm', '25 25'],
  23432. ['s ss', '50 50'],
  23433. ['a A', 'pm PM'],
  23434. ['[a] DDDo[a zi a anului]', 'a 45a zi a anului'],
  23435. ['LTS', '15:25:50'],
  23436. ['L', '14.02.2010'],
  23437. ['LL', '14 februarie 2010'],
  23438. ['LLL', '14 februarie 2010 15:25'],
  23439. ['LLLL', 'duminică, 14 februarie 2010 15:25'],
  23440. ['l', '14.2.2010'],
  23441. ['ll', '14 febr. 2010'],
  23442. ['lll', '14 febr. 2010 15:25'],
  23443. ['llll', 'Dum, 14 febr. 2010 15:25']
  23444. ],
  23445. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  23446. i;
  23447. for (i = 0; i < a.length; i++) {
  23448. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  23449. }
  23450. });
  23451. test('format ordinal', function (assert) {
  23452. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1');
  23453. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2');
  23454. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3');
  23455. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4');
  23456. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5');
  23457. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6');
  23458. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7');
  23459. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8');
  23460. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9');
  23461. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10');
  23462. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11');
  23463. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12');
  23464. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13');
  23465. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14');
  23466. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15');
  23467. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16');
  23468. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17');
  23469. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18');
  23470. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19');
  23471. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20');
  23472. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21');
  23473. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22');
  23474. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23');
  23475. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24');
  23476. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25');
  23477. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26');
  23478. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27');
  23479. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28');
  23480. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29');
  23481. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30');
  23482. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31');
  23483. });
  23484. test('format month', function (assert) {
  23485. var expected = 'ianuarie ian._februarie febr._martie mart._aprilie apr._mai mai_iunie iun._iulie iul._august aug._septembrie sept._octombrie oct._noiembrie nov._decembrie dec.'.split('_'), i;
  23486. for (i = 0; i < expected.length; i++) {
  23487. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  23488. }
  23489. });
  23490. test('format week', function (assert) {
  23491. var expected = 'duminică Dum Du_luni Lun Lu_marți Mar Ma_miercuri Mie Mi_joi Joi Jo_vineri Vin Vi_sâmbătă Sâm Sâ'.split('_'), i;
  23492. for (i = 0; i < expected.length; i++) {
  23493. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  23494. }
  23495. });
  23496. test('from', function (assert) {
  23497. var start = moment([2007, 1, 28]);
  23498. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'câteva secunde', '44 seconds = a few seconds');
  23499. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'un minut', '45 seconds = a minute');
  23500. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'un minut', '89 seconds = a minute');
  23501. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minute', '90 seconds = 2 minutes');
  23502. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 de minute', '44 minutes = 44 minutes');
  23503. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'o oră', '45 minutes = an hour');
  23504. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'o oră', '89 minutes = an hour');
  23505. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 ore', '90 minutes = 2 hours');
  23506. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ore', '5 hours = 5 hours');
  23507. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 de ore', '21 hours = 21 hours');
  23508. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'o zi', '22 hours = a day');
  23509. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'o zi', '35 hours = a day');
  23510. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 zile', '36 hours = 2 days');
  23511. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'o zi', '1 day = a day');
  23512. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 zile', '5 days = 5 days');
  23513. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 de zile', '25 days = 25 days');
  23514. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'o lună', '26 days = a month');
  23515. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'o lună', '30 days = a month');
  23516. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'o lună', '43 days = a month');
  23517. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 luni', '46 days = 2 months');
  23518. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 luni', '75 days = 2 months');
  23519. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 luni', '76 days = 3 months');
  23520. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'o lună', '1 month = a month');
  23521. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 luni', '5 months = 5 months');
  23522. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'un an', '345 days = a year');
  23523. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 ani', '548 days = 2 years');
  23524. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'un an', '1 year = a year');
  23525. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 ani', '5 years = 5 years');
  23526. assert.equal(start.from(moment([2007, 1, 28]).add({y: 19}), true), '19 ani', '19 years = 19 years');
  23527. assert.equal(start.from(moment([2007, 1, 28]).add({y: 20}), true), '20 de ani', '20 years = 20 years');
  23528. assert.equal(start.from(moment([2007, 1, 28]).add({y: 100}), true), '100 de ani', '100 years = 100 years');
  23529. assert.equal(start.from(moment([2007, 1, 28]).add({y: 101}), true), '101 ani', '101 years = 101 years');
  23530. assert.equal(start.from(moment([2007, 1, 28]).add({y: 119}), true), '119 ani', '119 years = 119 years');
  23531. assert.equal(start.from(moment([2007, 1, 28]).add({y: 120}), true), '120 de ani', '120 years = 120 years');
  23532. assert.equal(start.from(moment([2007, 1, 28]).add({y: 219}), true), '219 ani', '219 years = 219 years');
  23533. assert.equal(start.from(moment([2007, 1, 28]).add({y: 220}), true), '220 de ani', '220 years = 220 years');
  23534. });
  23535. test('suffix', function (assert) {
  23536. assert.equal(moment(30000).from(0), 'peste câteva secunde', 'prefix');
  23537. assert.equal(moment(0).from(30000), 'câteva secunde în urmă', 'suffix');
  23538. });
  23539. test('now from now', function (assert) {
  23540. assert.equal(moment().fromNow(), 'câteva secunde în urmă', 'now from now should display as in the past');
  23541. });
  23542. test('fromNow', function (assert) {
  23543. assert.equal(moment().add({s: 30}).fromNow(), 'peste câteva secunde', 'in a few seconds');
  23544. assert.equal(moment().add({d: 5}).fromNow(), 'peste 5 zile', 'in 5 days');
  23545. });
  23546. test('calendar day', function (assert) {
  23547. var a = moment().hours(2).minutes(0).seconds(0);
  23548. assert.equal(moment(a).calendar(), 'azi la 2:00', 'today at the same time');
  23549. assert.equal(moment(a).add({m: 25}).calendar(), 'azi la 2:25', 'Now plus 25 min');
  23550. assert.equal(moment(a).add({h: 1}).calendar(), 'azi la 3:00', 'Now plus 1 hour');
  23551. assert.equal(moment(a).add({d: 1}).calendar(), 'mâine la 2:00', 'tomorrow at the same time');
  23552. assert.equal(moment(a).subtract({h: 1}).calendar(), 'azi la 1:00', 'Now minus 1 hour');
  23553. assert.equal(moment(a).subtract({d: 1}).calendar(), 'ieri la 2:00', 'yesterday at the same time');
  23554. });
  23555. test('calendar next week', function (assert) {
  23556. var i, m;
  23557. for (i = 2; i < 7; i++) {
  23558. m = moment().add({d: i});
  23559. assert.equal(m.calendar(), m.format('dddd [la] LT'), 'Today + ' + i + ' days current time');
  23560. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  23561. assert.equal(m.calendar(), m.format('dddd [la] LT'), 'Today + ' + i + ' days beginning of day');
  23562. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  23563. assert.equal(m.calendar(), m.format('dddd [la] LT'), 'Today + ' + i + ' days end of day');
  23564. }
  23565. });
  23566. test('calendar last week', function (assert) {
  23567. var i, m;
  23568. for (i = 2; i < 7; i++) {
  23569. m = moment().subtract({d: i});
  23570. assert.equal(m.calendar(), m.format('[fosta] dddd [la] LT'), 'Today - ' + i + ' days current time');
  23571. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  23572. assert.equal(m.calendar(), m.format('[fosta] dddd [la] LT'), 'Today - ' + i + ' days beginning of day');
  23573. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  23574. assert.equal(m.calendar(), m.format('[fosta] dddd [la] LT'), 'Today - ' + i + ' days end of day');
  23575. }
  23576. });
  23577. test('calendar all else', function (assert) {
  23578. var weeksAgo = moment().subtract({w: 1}),
  23579. weeksFromNow = moment().add({w: 1});
  23580. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  23581. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  23582. weeksAgo = moment().subtract({w: 2});
  23583. weeksFromNow = moment().add({w: 2});
  23584. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  23585. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  23586. });
  23587. test('weeks year starting sunday', function (assert) {
  23588. assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1');
  23589. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  23590. assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2');
  23591. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  23592. assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3');
  23593. });
  23594. test('weeks year starting monday', function (assert) {
  23595. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  23596. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  23597. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  23598. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  23599. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  23600. });
  23601. test('weeks year starting tuesday', function (assert) {
  23602. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  23603. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  23604. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  23605. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  23606. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  23607. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  23608. });
  23609. test('weeks year starting wednesday', function (assert) {
  23610. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  23611. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  23612. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  23613. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  23614. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  23615. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  23616. });
  23617. test('weeks year starting thursday', function (assert) {
  23618. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  23619. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  23620. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  23621. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  23622. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  23623. assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3');
  23624. });
  23625. test('weeks year starting friday', function (assert) {
  23626. assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1');
  23627. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  23628. assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1');
  23629. assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2');
  23630. assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2');
  23631. assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3');
  23632. });
  23633. test('weeks year starting saturday', function (assert) {
  23634. assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1');
  23635. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  23636. assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1');
  23637. assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2');
  23638. assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2');
  23639. assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3');
  23640. });
  23641. test('weeks year starting sunday formatted', function (assert) {
  23642. assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1', 'Dec 26 2011 should be week 1');
  23643. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1', 'Jan 1 2012 should be week 1');
  23644. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2', 'Jan 2 2012 should be week 2');
  23645. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2', 'Jan 8 2012 should be week 2');
  23646. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3', 'Jan 9 2012 should be week 3');
  23647. });
  23648. test('lenient ordinal parsing', function (assert) {
  23649. var i, ordinalStr, testMoment;
  23650. for (i = 1; i <= 31; ++i) {
  23651. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  23652. testMoment = moment(ordinalStr, 'YYYY MM Do');
  23653. assert.equal(testMoment.year(), 2014,
  23654. 'lenient ordinal parsing ' + i + ' year check');
  23655. assert.equal(testMoment.month(), 0,
  23656. 'lenient ordinal parsing ' + i + ' month check');
  23657. assert.equal(testMoment.date(), i,
  23658. 'lenient ordinal parsing ' + i + ' date check');
  23659. }
  23660. });
  23661. test('lenient ordinal parsing of number', function (assert) {
  23662. var i, testMoment;
  23663. for (i = 1; i <= 31; ++i) {
  23664. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  23665. assert.equal(testMoment.year(), 2014,
  23666. 'lenient ordinal parsing of number ' + i + ' year check');
  23667. assert.equal(testMoment.month(), 0,
  23668. 'lenient ordinal parsing of number ' + i + ' month check');
  23669. assert.equal(testMoment.date(), i,
  23670. 'lenient ordinal parsing of number ' + i + ' date check');
  23671. }
  23672. });
  23673. test('strict ordinal parsing', function (assert) {
  23674. var i, ordinalStr, testMoment;
  23675. for (i = 1; i <= 31; ++i) {
  23676. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  23677. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  23678. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  23679. }
  23680. });
  23681. }));
  23682. ;(function (global, factory) {
  23683. typeof exports === 'object' && typeof module !== 'undefined'
  23684. && typeof require === 'function' ? factory(require('../../moment')) :
  23685. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  23686. factory(global.moment)
  23687. }(this, function (moment) { 'use strict';
  23688. /*global QUnit:false*/
  23689. var test = QUnit.test;
  23690. var expect = QUnit.expect;
  23691. function module (name, lifecycle) {
  23692. QUnit.module(name, {
  23693. setup : function () {
  23694. moment.locale('en');
  23695. moment.createFromInputFallback = function (config) {
  23696. throw new Error('input not handled by moment: ' + config._i);
  23697. };
  23698. if (lifecycle && lifecycle.setup) {
  23699. lifecycle.setup();
  23700. }
  23701. },
  23702. teardown : function () {
  23703. if (lifecycle && lifecycle.teardown) {
  23704. lifecycle.teardown();
  23705. }
  23706. }
  23707. });
  23708. }
  23709. function localeModule (name, lifecycle) {
  23710. QUnit.module('locale:' + name, {
  23711. setup : function () {
  23712. moment.locale(name);
  23713. moment.createFromInputFallback = function (config) {
  23714. throw new Error('input not handled by moment: ' + config._i);
  23715. };
  23716. if (lifecycle && lifecycle.setup) {
  23717. lifecycle.setup();
  23718. }
  23719. },
  23720. teardown : function () {
  23721. moment.locale('en');
  23722. if (lifecycle && lifecycle.teardown) {
  23723. lifecycle.teardown();
  23724. }
  23725. }
  23726. });
  23727. }
  23728. localeModule('ru');
  23729. test('parse', function (assert) {
  23730. var tests = 'Январь янв_Февраль фев_Март март_Апрель апр_Май май_Июнь июнь_Июль июль_Август авг_Сентябрь сен_Октябрь окт_Ноябрь ноя_Декабрь дек'.split('_'), i;
  23731. function equalTest(input, mmm, i) {
  23732. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  23733. }
  23734. function equalTestStrict(input, mmm, monthIndex) {
  23735. assert.equal(moment(input, mmm, true).month(), monthIndex, input + ' ' + mmm + ' should be strict month ' + (monthIndex + 1));
  23736. }
  23737. for (i = 0; i < 12; i++) {
  23738. tests[i] = tests[i].split(' ');
  23739. equalTest(tests[i][0], 'MMM', i);
  23740. equalTest(tests[i][1], 'MMM', i);
  23741. equalTest(tests[i][0], 'MMMM', i);
  23742. equalTest(tests[i][1], 'MMMM', i);
  23743. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  23744. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  23745. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  23746. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  23747. equalTestStrict(tests[i][1], 'MMM', i);
  23748. equalTestStrict(tests[i][0], 'MMMM', i);
  23749. equalTestStrict(tests[i][1].toLocaleLowerCase(), 'MMM', i);
  23750. equalTestStrict(tests[i][1].toLocaleUpperCase(), 'MMM', i);
  23751. equalTestStrict(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  23752. equalTestStrict(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  23753. }
  23754. });
  23755. test('parse exceptional case', function (assert) {
  23756. assert.equal(moment('11 Мая 1989', ['DD MMMM YYYY']).format('DD-MM-YYYY'), '11-05-1989');
  23757. });
  23758. test('format', function (assert) {
  23759. var a = [
  23760. ['dddd, Do MMMM YYYY, HH:mm:ss', 'Воскресенье, 14-го Февраля 2010, 15:25:50'],
  23761. ['ddd, h A', 'Вс, 3 дня'],
  23762. ['M Mo MM MMMM MMM', '2 2-й 02 Февраль фев'],
  23763. ['YYYY YY', '2010 10'],
  23764. ['D Do DD', '14 14-го 14'],
  23765. ['d do dddd ddd dd', '0 0-й Воскресенье Вс Вс'],
  23766. ['DDD DDDo DDDD', '45 45-й 045'],
  23767. ['w wo ww', '7 7-я 07'],
  23768. ['h hh', '3 03'],
  23769. ['H HH', '15 15'],
  23770. ['m mm', '25 25'],
  23771. ['s ss', '50 50'],
  23772. ['a A', 'дня дня'],
  23773. ['DDDo [день года]', '45-й день года'],
  23774. ['LTS', '15:25:50'],
  23775. ['L', '14.02.2010'],
  23776. ['LL', '14 Февраля 2010 г.'],
  23777. ['LLL', '14 Февраля 2010 г., 15:25'],
  23778. ['LLLL', 'Воскресенье, 14 Февраля 2010 г., 15:25'],
  23779. ['l', '14.2.2010'],
  23780. ['ll', '14 фев 2010 г.'],
  23781. ['lll', '14 фев 2010 г., 15:25'],
  23782. ['llll', 'Вс, 14 фев 2010 г., 15:25']
  23783. ],
  23784. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  23785. i;
  23786. for (i = 0; i < a.length; i++) {
  23787. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  23788. }
  23789. });
  23790. test('format meridiem', function (assert) {
  23791. assert.equal(moment([2012, 11, 28, 0, 0]).format('A'), 'ночи', 'night');
  23792. assert.equal(moment([2012, 11, 28, 3, 59]).format('A'), 'ночи', 'night');
  23793. assert.equal(moment([2012, 11, 28, 4, 0]).format('A'), 'утра', 'morning');
  23794. assert.equal(moment([2012, 11, 28, 11, 59]).format('A'), 'утра', 'morning');
  23795. assert.equal(moment([2012, 11, 28, 12, 0]).format('A'), 'дня', 'afternoon');
  23796. assert.equal(moment([2012, 11, 28, 16, 59]).format('A'), 'дня', 'afternoon');
  23797. assert.equal(moment([2012, 11, 28, 17, 0]).format('A'), 'вечера', 'evening');
  23798. assert.equal(moment([2012, 11, 28, 23, 59]).format('A'), 'вечера', 'evening');
  23799. });
  23800. test('format ordinal', function (assert) {
  23801. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1-й', '1-й');
  23802. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2-й', '2-й');
  23803. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3-й', '3-й');
  23804. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4-й', '4-й');
  23805. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5-й', '5-й');
  23806. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6-й', '6-й');
  23807. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7-й', '7-й');
  23808. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8-й', '8-й');
  23809. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9-й', '9-й');
  23810. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10-й', '10-й');
  23811. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11-й', '11-й');
  23812. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12-й', '12-й');
  23813. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13-й', '13-й');
  23814. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14-й', '14-й');
  23815. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15-й', '15-й');
  23816. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16-й', '16-й');
  23817. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17-й', '17-й');
  23818. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18-й', '18-й');
  23819. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19-й', '19-й');
  23820. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20-й', '20-й');
  23821. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21-й', '21-й');
  23822. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22-й', '22-й');
  23823. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23-й', '23-й');
  23824. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24-й', '24-й');
  23825. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25-й', '25-й');
  23826. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26-й', '26-й');
  23827. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27-й', '27-й');
  23828. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28-й', '28-й');
  23829. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29-й', '29-й');
  23830. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30-й', '30-й');
  23831. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31-й', '31-й');
  23832. });
  23833. test('format month', function (assert) {
  23834. var expected = 'Январь янв_Февраль фев_Март март_Апрель апр_Май май_Июнь июнь_Июль июль_Август авг_Сентябрь сен_Октябрь окт_Ноябрь ноя_Декабрь дек'.split('_'), i;
  23835. for (i = 0; i < expected.length; i++) {
  23836. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  23837. }
  23838. });
  23839. test('format month case', function (assert) {
  23840. var months = {
  23841. 'nominative': 'Январь_Февраль_Март_Апрель_Май_Июнь_Июль_Август_Сентябрь_Октябрь_Ноябрь_Декабрь'.split('_'),
  23842. 'accusative': 'Января_Февраля_Марта_Апреля_Мая_Июня_Июля_Августа_Сентября_Октября_Ноября_Декабря'.split('_')
  23843. }, i;
  23844. for (i = 0; i < 12; i++) {
  23845. assert.equal(moment([2011, i, 1]).format('D MMMM'), '1 ' + months.accusative[i], '1 ' + months.accusative[i]);
  23846. assert.equal(moment([2011, i, 1]).format('MMMM'), months.nominative[i], '1 ' + months.nominative[i]);
  23847. }
  23848. });
  23849. test('format month short case', function (assert) {
  23850. var monthsShort = {
  23851. 'nominative': 'янв_фев_март_апр_май_июнь_июль_авг_сен_окт_ноя_дек'.split('_'),
  23852. 'accusative': 'янв_фев_мар_апр_мая_июня_июля_авг_сен_окт_ноя_дек'.split('_')
  23853. }, i;
  23854. for (i = 0; i < 12; i++) {
  23855. assert.equal(moment([2011, i, 1]).format('D MMM'), '1 ' + monthsShort.accusative[i], '1 ' + monthsShort.accusative[i]);
  23856. assert.equal(moment([2011, i, 1]).format('MMM'), monthsShort.nominative[i], '1 ' + monthsShort.nominative[i]);
  23857. }
  23858. });
  23859. test('format month case with escaped symbols', function (assert) {
  23860. var months = {
  23861. 'nominative': 'Январь_Февраль_Март_Апрель_Май_Июнь_Июль_Август_Сентябрь_Октябрь_Ноябрь_Декабрь'.split('_'),
  23862. 'accusative': 'Января_Февраля_Марта_Апреля_Мая_Июня_Июля_Августа_Сентября_Октября_Ноября_Декабря'.split('_')
  23863. }, i;
  23864. for (i = 0; i < 12; i++) {
  23865. assert.equal(moment([2013, i, 1]).format('D[] MMMM'), '1 ' + months.accusative[i], '1 ' + months.accusative[i]);
  23866. assert.equal(moment([2013, i, 1]).format('[<i>]D[</i>] [<b>]MMMM[</b>]'), '<i>1</i> <b>' + months.accusative[i] + '</b>', '1 <b>' + months.accusative[i] + '</b>');
  23867. assert.equal(moment([2013, i, 1]).format('D[-й день] MMMM'), '1-й день ' + months.accusative[i], '1-й день ' + months.accusative[i]);
  23868. assert.equal(moment([2013, i, 1]).format('D, MMMM'), '1, ' + months.nominative[i], '1, ' + months.nominative[i]);
  23869. }
  23870. });
  23871. test('format month short case with escaped symbols', function (assert) {
  23872. var monthsShort = {
  23873. 'nominative': 'янв_фев_март_апр_май_июнь_июль_авг_сен_окт_ноя_дек'.split('_'),
  23874. 'accusative': 'янв_фев_мар_апр_мая_июня_июля_авг_сен_окт_ноя_дек'.split('_')
  23875. }, i;
  23876. for (i = 0; i < 12; i++) {
  23877. assert.equal(moment([2013, i, 1]).format('D[] MMM'), '1 ' + monthsShort.accusative[i], '1 ' + monthsShort.accusative[i]);
  23878. assert.equal(moment([2013, i, 1]).format('[<i>]D[</i>] [<b>]MMM[</b>]'), '<i>1</i> <b>' + monthsShort.accusative[i] + '</b>', '1 <b>' + monthsShort.accusative[i] + '</b>');
  23879. assert.equal(moment([2013, i, 1]).format('D[-й день] MMM'), '1-й день ' + monthsShort.accusative[i], '1-й день ' + monthsShort.accusative[i]);
  23880. assert.equal(moment([2013, i, 1]).format('D, MMM'), '1, ' + monthsShort.nominative[i], '1, ' + monthsShort.nominative[i]);
  23881. }
  23882. });
  23883. test('format week', function (assert) {
  23884. var expected = 'Воскресенье Вс Вс_Понедельник Пн Пн_Вторник Вт Вт_Среда Ср Ср_Четверг Чт Чт_Пятница Пт Пт_Суббота Сб Сб'.split('_'), i;
  23885. for (i = 0; i < expected.length; i++) {
  23886. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  23887. }
  23888. });
  23889. test('from', function (assert) {
  23890. var start = moment([2007, 1, 28]);
  23891. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'несколько секунд', '44 seconds = seconds');
  23892. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'минута', '45 seconds = a minute');
  23893. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'минута', '89 seconds = a minute');
  23894. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 минуты', '90 seconds = 2 minutes');
  23895. assert.equal(start.from(moment([2007, 1, 28]).add({m: 31}), true), '31 минута', '31 minutes = 31 minutes');
  23896. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 минуты', '44 minutes = 44 minutes');
  23897. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'час', '45 minutes = an hour');
  23898. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'час', '89 minutes = an hour');
  23899. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 часа', '90 minutes = 2 hours');
  23900. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 часов', '5 hours = 5 hours');
  23901. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 час', '21 hours = 21 hours');
  23902. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'день', '22 hours = a day');
  23903. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'день', '35 hours = a day');
  23904. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 дня', '36 hours = 2 days');
  23905. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'день', '1 day = a day');
  23906. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 дней', '5 days = 5 days');
  23907. assert.equal(start.from(moment([2007, 1, 28]).add({d: 11}), true), '11 дней', '11 days = 11 days');
  23908. assert.equal(start.from(moment([2007, 1, 28]).add({d: 21}), true), '21 день', '21 days = 21 days');
  23909. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 дней', '25 days = 25 days');
  23910. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'месяц', '26 days = a month');
  23911. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'месяц', '30 days = a month');
  23912. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'месяц', '43 days = a month');
  23913. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 месяца', '46 days = 2 months');
  23914. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 месяца', '75 days = 2 months');
  23915. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 месяца', '76 days = 3 months');
  23916. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'месяц', '1 month = a month');
  23917. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 месяцев', '5 months = 5 months');
  23918. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'год', '345 days = a year');
  23919. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 года', '548 days = 2 years');
  23920. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'год', '1 year = a year');
  23921. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 лет', '5 years = 5 years');
  23922. });
  23923. test('suffix', function (assert) {
  23924. assert.equal(moment(30000).from(0), 'через несколько секунд', 'prefix');
  23925. assert.equal(moment(0).from(30000), 'несколько секунд назад', 'suffix');
  23926. });
  23927. test('fromNow', function (assert) {
  23928. assert.equal(moment().add({s: 30}).fromNow(), 'через несколько секунд', 'in seconds');
  23929. assert.equal(moment().add({d: 5}).fromNow(), 'через 5 дней', 'in 5 days');
  23930. assert.equal(moment().add({m: 31}).fromNow(), 'через 31 минуту', 'in 31 minutes = in 31 minutes');
  23931. assert.equal(moment().subtract({m: 31}).fromNow(), '31 минуту назад', '31 minutes ago = 31 minutes ago');
  23932. });
  23933. test('calendar day', function (assert) {
  23934. var a = moment().hours(2).minutes(0).seconds(0);
  23935. assert.equal(moment(a).calendar(), 'Сегодня в 02:00', 'today at the same time');
  23936. assert.equal(moment(a).add({m: 25}).calendar(), 'Сегодня в 02:25', 'Now plus 25 min');
  23937. assert.equal(moment(a).add({h: 1}).calendar(), 'Сегодня в 03:00', 'Now plus 1 hour');
  23938. assert.equal(moment(a).add({d: 1}).calendar(), 'Завтра в 02:00', 'tomorrow at the same time');
  23939. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Сегодня в 01:00', 'Now minus 1 hour');
  23940. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Вчера в 02:00', 'yesterday at the same time');
  23941. });
  23942. test('calendar next week', function (assert) {
  23943. var i, m, now;
  23944. function makeFormatNext(d) {
  23945. switch (d.day()) {
  23946. case 0:
  23947. return '[В следующее] dddd [в] LT';
  23948. case 1:
  23949. case 2:
  23950. case 4:
  23951. return '[В следующий] dddd [в] LT';
  23952. case 3:
  23953. case 5:
  23954. case 6:
  23955. return '[В следующую] dddd [в] LT';
  23956. }
  23957. }
  23958. function makeFormatThis(d) {
  23959. if (d.day() === 2) {
  23960. return '[Во] dddd [в] LT';
  23961. }
  23962. else {
  23963. return '[В] dddd [в] LT';
  23964. }
  23965. }
  23966. now = moment().startOf('week');
  23967. for (i = 2; i < 7; i++) {
  23968. m = moment(now).add({d: i});
  23969. assert.equal(m.calendar(now), m.format(makeFormatThis(m)), 'Today + ' + i + ' days current time');
  23970. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  23971. assert.equal(m.calendar(now), m.format(makeFormatThis(m)), 'Today + ' + i + ' days beginning of day');
  23972. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  23973. assert.equal(m.calendar(now), m.format(makeFormatThis(m)), 'Today + ' + i + ' days end of day');
  23974. }
  23975. now = moment().endOf('week');
  23976. for (i = 2; i < 7; i++) {
  23977. m = moment(now).add({d: i});
  23978. assert.equal(m.calendar(now), m.format(makeFormatNext(m)), 'Today + ' + i + ' days current time');
  23979. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  23980. assert.equal(m.calendar(now), m.format(makeFormatNext(m)), 'Today + ' + i + ' days beginning of day');
  23981. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  23982. assert.equal(m.calendar(now), m.format(makeFormatNext(m)), 'Today + ' + i + ' days end of day');
  23983. }
  23984. });
  23985. test('calendar last week', function (assert) {
  23986. var i, m, now;
  23987. function makeFormatLast(d) {
  23988. switch (d.day()) {
  23989. case 0:
  23990. return '[В прошлое] dddd [в] LT';
  23991. case 1:
  23992. case 2:
  23993. case 4:
  23994. return '[В прошлый] dddd [в] LT';
  23995. case 3:
  23996. case 5:
  23997. case 6:
  23998. return '[В прошлую] dddd [в] LT';
  23999. }
  24000. }
  24001. function makeFormatThis(d) {
  24002. if (d.day() === 2) {
  24003. return '[Во] dddd [в] LT';
  24004. }
  24005. else {
  24006. return '[В] dddd [в] LT';
  24007. }
  24008. }
  24009. now = moment().startOf('week');
  24010. for (i = 2; i < 7; i++) {
  24011. m = moment(now).subtract({d: i});
  24012. assert.equal(m.calendar(now), m.format(makeFormatLast(m)), 'Today - ' + i + ' days current time');
  24013. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  24014. assert.equal(m.calendar(now), m.format(makeFormatLast(m)), 'Today - ' + i + ' days beginning of day');
  24015. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  24016. assert.equal(m.calendar(now), m.format(makeFormatLast(m)), 'Today - ' + i + ' days end of day');
  24017. }
  24018. now = moment().endOf('week');
  24019. for (i = 2; i < 7; i++) {
  24020. m = moment(now).subtract({d: i});
  24021. assert.equal(m.calendar(now), m.format(makeFormatThis(m)), 'Today - ' + i + ' days current time');
  24022. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  24023. assert.equal(m.calendar(now), m.format(makeFormatThis(m)), 'Today - ' + i + ' days beginning of day');
  24024. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  24025. assert.equal(m.calendar(now), m.format(makeFormatThis(m)), 'Today - ' + i + ' days end of day');
  24026. }
  24027. });
  24028. test('calendar all else', function (assert) {
  24029. var weeksAgo = moment().subtract({w: 1}),
  24030. weeksFromNow = moment().add({w: 1});
  24031. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  24032. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  24033. weeksAgo = moment().subtract({w: 2});
  24034. weeksFromNow = moment().add({w: 2});
  24035. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  24036. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  24037. });
  24038. test('weeks year starting sunday', function (assert) {
  24039. assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1');
  24040. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  24041. assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2');
  24042. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  24043. assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3');
  24044. });
  24045. test('weeks year starting monday', function (assert) {
  24046. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  24047. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  24048. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  24049. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  24050. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  24051. });
  24052. test('weeks year starting tuesday', function (assert) {
  24053. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  24054. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  24055. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  24056. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  24057. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  24058. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  24059. });
  24060. test('weeks year starting wednesday', function (assert) {
  24061. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  24062. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  24063. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  24064. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  24065. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  24066. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  24067. });
  24068. test('weeks year starting thursday', function (assert) {
  24069. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  24070. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  24071. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  24072. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  24073. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  24074. assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3');
  24075. });
  24076. test('weeks year starting friday', function (assert) {
  24077. assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1');
  24078. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  24079. assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1');
  24080. assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2');
  24081. assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2');
  24082. assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3');
  24083. });
  24084. test('weeks year starting saturday', function (assert) {
  24085. assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1');
  24086. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  24087. assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1');
  24088. assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2');
  24089. assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2');
  24090. assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3');
  24091. });
  24092. test('weeks year starting sunday formatted', function (assert) {
  24093. assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1-я', 'Dec 26 2011 should be week 1');
  24094. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1-я', 'Jan 1 2012 should be week 1');
  24095. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2-я', 'Jan 2 2012 should be week 2');
  24096. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2-я', 'Jan 8 2012 should be week 2');
  24097. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3-я', 'Jan 9 2012 should be week 3');
  24098. });
  24099. test('lenient ordinal parsing', function (assert) {
  24100. var i, ordinalStr, testMoment;
  24101. for (i = 1; i <= 31; ++i) {
  24102. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  24103. testMoment = moment(ordinalStr, 'YYYY MM Do');
  24104. assert.equal(testMoment.year(), 2014,
  24105. 'lenient ordinal parsing ' + i + ' year check');
  24106. assert.equal(testMoment.month(), 0,
  24107. 'lenient ordinal parsing ' + i + ' month check');
  24108. assert.equal(testMoment.date(), i,
  24109. 'lenient ordinal parsing ' + i + ' date check');
  24110. }
  24111. });
  24112. test('lenient ordinal parsing of number', function (assert) {
  24113. var i, testMoment;
  24114. for (i = 1; i <= 31; ++i) {
  24115. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  24116. assert.equal(testMoment.year(), 2014,
  24117. 'lenient ordinal parsing of number ' + i + ' year check');
  24118. assert.equal(testMoment.month(), 0,
  24119. 'lenient ordinal parsing of number ' + i + ' month check');
  24120. assert.equal(testMoment.date(), i,
  24121. 'lenient ordinal parsing of number ' + i + ' date check');
  24122. }
  24123. });
  24124. test('strict ordinal parsing', function (assert) {
  24125. var i, ordinalStr, testMoment;
  24126. for (i = 1; i <= 31; ++i) {
  24127. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  24128. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  24129. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  24130. }
  24131. });
  24132. }));
  24133. ;(function (global, factory) {
  24134. typeof exports === 'object' && typeof module !== 'undefined'
  24135. && typeof require === 'function' ? factory(require('../../moment')) :
  24136. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  24137. factory(global.moment)
  24138. }(this, function (moment) { 'use strict';
  24139. /*global QUnit:false*/
  24140. var test = QUnit.test;
  24141. var expect = QUnit.expect;
  24142. function module (name, lifecycle) {
  24143. QUnit.module(name, {
  24144. setup : function () {
  24145. moment.locale('en');
  24146. moment.createFromInputFallback = function (config) {
  24147. throw new Error('input not handled by moment: ' + config._i);
  24148. };
  24149. if (lifecycle && lifecycle.setup) {
  24150. lifecycle.setup();
  24151. }
  24152. },
  24153. teardown : function () {
  24154. if (lifecycle && lifecycle.teardown) {
  24155. lifecycle.teardown();
  24156. }
  24157. }
  24158. });
  24159. }
  24160. function localeModule (name, lifecycle) {
  24161. QUnit.module('locale:' + name, {
  24162. setup : function () {
  24163. moment.locale(name);
  24164. moment.createFromInputFallback = function (config) {
  24165. throw new Error('input not handled by moment: ' + config._i);
  24166. };
  24167. if (lifecycle && lifecycle.setup) {
  24168. lifecycle.setup();
  24169. }
  24170. },
  24171. teardown : function () {
  24172. moment.locale('en');
  24173. if (lifecycle && lifecycle.teardown) {
  24174. lifecycle.teardown();
  24175. }
  24176. }
  24177. });
  24178. }
  24179. localeModule('se');
  24180. test('parse', function (assert) {
  24181. var i,
  24182. tests = 'ođđajagemánnu ođđj_guovvamánnu guov_njukčamánnu njuk_cuoŋománnu cuo_miessemánnu mies_geassemánnu geas_suoidnemánnu suoi_borgemánnu borg_čakčamánnu čakč_golggotmánnu golg_skábmamánnu skáb_juovlamánnu juov'.split('_');
  24183. function equalTest(input, mmm, i) {
  24184. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  24185. }
  24186. for (i = 0; i < 12; i++) {
  24187. tests[i] = tests[i].split(' ');
  24188. equalTest(tests[i][0], 'MMM', i);
  24189. equalTest(tests[i][1], 'MMM', i);
  24190. equalTest(tests[i][0], 'MMMM', i);
  24191. equalTest(tests[i][1], 'MMMM', i);
  24192. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  24193. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  24194. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  24195. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  24196. }
  24197. });
  24198. test('format', function (assert) {
  24199. var a = [
  24200. ['dddd, MMMM Do YYYY, h:mm:ss a', 'sotnabeaivi, guovvamánnu 14. 2010, 3:25:50 pm'],
  24201. ['ddd, hA', 'sotn, 3PM'],
  24202. ['M Mo MM MMMM MMM', '2 2. 02 guovvamánnu guov'],
  24203. ['YYYY YY', '2010 10'],
  24204. ['D Do DD', '14 14. 14'],
  24205. ['d do dddd ddd dd', '0 0. sotnabeaivi sotn s'],
  24206. ['DDD DDDo DDDD', '45 45. 045'],
  24207. ['w wo ww', '6 6. 06'],
  24208. ['h hh', '3 03'],
  24209. ['H HH', '15 15'],
  24210. ['m mm', '25 25'],
  24211. ['s ss', '50 50'],
  24212. ['a A', 'pm PM'],
  24213. ['[jagi] DDDo [beaivi]', 'jagi 45. beaivi'],
  24214. ['LTS', '15:25:50'],
  24215. ['L', '14.02.2010'],
  24216. ['LL', 'guovvamánnu 14. b. 2010'],
  24217. ['LLL', 'guovvamánnu 14. b. 2010 ti. 15:25'],
  24218. ['LLLL', 'sotnabeaivi, guovvamánnu 14. b. 2010 ti. 15:25'],
  24219. ['l', '14.2.2010'],
  24220. ['ll', 'guov 14. b. 2010'],
  24221. ['lll', 'guov 14. b. 2010 ti. 15:25'],
  24222. ['llll', 'sotn, guov 14. b. 2010 ti. 15:25']
  24223. ],
  24224. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  24225. i;
  24226. for (i = 0; i < a.length; i++) {
  24227. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  24228. }
  24229. });
  24230. test('format ordinal', function (assert) {
  24231. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
  24232. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
  24233. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
  24234. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
  24235. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
  24236. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
  24237. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
  24238. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
  24239. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
  24240. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
  24241. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
  24242. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
  24243. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
  24244. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
  24245. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
  24246. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
  24247. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
  24248. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
  24249. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
  24250. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
  24251. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
  24252. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
  24253. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
  24254. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
  24255. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
  24256. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
  24257. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
  24258. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
  24259. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
  24260. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
  24261. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
  24262. });
  24263. test('format month', function (assert) {
  24264. var i,
  24265. expected = 'ođđajagemánnu ođđj_guovvamánnu guov_njukčamánnu njuk_cuoŋománnu cuo_miessemánnu mies_geassemánnu geas_suoidnemánnu suoi_borgemánnu borg_čakčamánnu čakč_golggotmánnu golg_skábmamánnu skáb_juovlamánnu juov'.split('_');
  24266. for (i = 0; i < expected.length; i++) {
  24267. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  24268. }
  24269. });
  24270. test('format week', function (assert) {
  24271. var i,
  24272. expected = 'sotnabeaivi sotn s_vuossárga vuos v_maŋŋebárga maŋ m_gaskavahkku gask g_duorastat duor d_bearjadat bear b_lávvardat láv L'.split('_');
  24273. for (i = 0; i < expected.length; i++) {
  24274. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  24275. }
  24276. });
  24277. test('from', function (assert) {
  24278. var start = moment([2007, 1, 28]);
  24279. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'moadde sekunddat', '44 seconds = a few seconds');
  24280. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'okta minuhta', '45 seconds = a minute');
  24281. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'okta minuhta', '89 seconds = a minute');
  24282. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuhtat', '90 seconds = 2 minutes');
  24283. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuhtat', '44 minutes = 44 minutes');
  24284. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'okta diimmu', '45 minutes = an hour');
  24285. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'okta diimmu', '89 minutes = an hour');
  24286. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 diimmut', '90 minutes = 2 hours');
  24287. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 diimmut', '5 hours = 5 hours');
  24288. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 diimmut', '21 hours = 21 hours');
  24289. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'okta beaivi', '22 hours = a day');
  24290. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'okta beaivi', '35 hours = a day');
  24291. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 beaivvit', '36 hours = 2 days');
  24292. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'okta beaivi', '1 day = a day');
  24293. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 beaivvit', '5 days = 5 days');
  24294. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 beaivvit', '25 days = 25 days');
  24295. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'okta mánnu', '26 days = a month');
  24296. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'okta mánnu', '30 days = a month');
  24297. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'okta mánnu', '43 days = a month');
  24298. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mánut', '46 days = 2 months');
  24299. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mánut', '75 days = 2 months');
  24300. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mánut', '76 days = 3 months');
  24301. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'okta mánnu', '1 month = a month');
  24302. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mánut', '5 months = 5 months');
  24303. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'okta jahki', '345 days = a year');
  24304. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 jagit', '548 days = 2 years');
  24305. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'okta jahki', '1 year = a year');
  24306. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 jagit', '5 years = 5 years');
  24307. });
  24308. test('suffix', function (assert) {
  24309. assert.equal(moment(30000).from(0), 'moadde sekunddat geažes', 'prefix');
  24310. assert.equal(moment(0).from(30000), 'maŋit moadde sekunddat', 'suffix');
  24311. });
  24312. test('now from now', function (assert) {
  24313. assert.equal(moment().fromNow(), 'maŋit moadde sekunddat', 'now from now should display as in the past');
  24314. });
  24315. test('fromNow', function (assert) {
  24316. assert.equal(moment().add({s: 30}).fromNow(), 'moadde sekunddat geažes', 'in a few seconds');
  24317. assert.equal(moment().add({d: 5}).fromNow(), '5 beaivvit geažes', 'in 5 days');
  24318. });
  24319. test('calendar day', function (assert) {
  24320. var a = moment().hours(2).minutes(0).seconds(0);
  24321. assert.equal(moment(a).calendar(), 'otne ti 02:00', 'Today at the same time');
  24322. assert.equal(moment(a).add({m: 25}).calendar(), 'otne ti 02:25', 'Now plus 25 min');
  24323. assert.equal(moment(a).add({h: 1}).calendar(), 'otne ti 03:00', 'Now plus 1 hour');
  24324. assert.equal(moment(a).add({d: 1}).calendar(), 'ihttin ti 02:00', 'Tomorrow at the same time');
  24325. assert.equal(moment(a).subtract({h: 1}).calendar(), 'otne ti 01:00', 'Now minus 1 hour');
  24326. assert.equal(moment(a).subtract({d: 1}).calendar(), 'ikte ti 02:00', 'yesterday at the same time');
  24327. });
  24328. test('calendar next week', function (assert) {
  24329. var i, m;
  24330. for (i = 2; i < 7; i++) {
  24331. m = moment().add({d: i});
  24332. assert.equal(m.calendar(), m.format('dddd [ti] LT'), 'Today + ' + i + ' days current time');
  24333. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  24334. assert.equal(m.calendar(), m.format('dddd [ti] LT'), 'Today + ' + i + ' days beginning of day');
  24335. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  24336. assert.equal(m.calendar(), m.format('dddd [ti] LT'), 'Today + ' + i + ' days end of day');
  24337. }
  24338. });
  24339. test('calendar last week', function (assert) {
  24340. var i, m;
  24341. for (i = 2; i < 7; i++) {
  24342. m = moment().subtract({d: i});
  24343. assert.equal(m.calendar(), m.format('[ovddit] dddd [ti] LT'), 'Today - ' + i + ' days current time');
  24344. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  24345. assert.equal(m.calendar(), m.format('[ovddit] dddd [ti] LT'), 'Today - ' + i + ' days beginning of day');
  24346. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  24347. assert.equal(m.calendar(), m.format('[ovddit] dddd [ti] LT'), 'Today - ' + i + ' days end of day');
  24348. }
  24349. });
  24350. test('calendar all else', function (assert) {
  24351. var weeksAgo = moment().subtract({w: 1}),
  24352. weeksFromNow = moment().add({w: 1});
  24353. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  24354. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  24355. weeksAgo = moment().subtract({w: 2});
  24356. weeksFromNow = moment().add({w: 2});
  24357. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  24358. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  24359. });
  24360. test('weeks year starting sunday', function (assert) {
  24361. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  24362. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  24363. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  24364. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  24365. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  24366. });
  24367. test('weeks year starting monday', function (assert) {
  24368. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  24369. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  24370. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  24371. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  24372. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  24373. });
  24374. test('weeks year starting tuesday', function (assert) {
  24375. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  24376. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  24377. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  24378. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  24379. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  24380. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  24381. });
  24382. test('weeks year starting wednesday', function (assert) {
  24383. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  24384. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  24385. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  24386. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  24387. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  24388. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  24389. });
  24390. test('weeks year starting thursday', function (assert) {
  24391. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  24392. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  24393. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  24394. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  24395. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  24396. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  24397. });
  24398. test('weeks year starting friday', function (assert) {
  24399. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  24400. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  24401. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  24402. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  24403. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  24404. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  24405. });
  24406. test('weeks year starting saturday', function (assert) {
  24407. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  24408. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  24409. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  24410. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  24411. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  24412. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  24413. });
  24414. test('weeks year starting sunday formatted', function (assert) {
  24415. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
  24416. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
  24417. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
  24418. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
  24419. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
  24420. });
  24421. test('lenient ordinal parsing', function (assert) {
  24422. var i, ordinalStr, testMoment;
  24423. for (i = 1; i <= 31; ++i) {
  24424. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  24425. testMoment = moment(ordinalStr, 'YYYY MM Do');
  24426. assert.equal(testMoment.year(), 2014,
  24427. 'lenient ordinal parsing ' + i + ' year check');
  24428. assert.equal(testMoment.month(), 0,
  24429. 'lenient ordinal parsing ' + i + ' month check');
  24430. assert.equal(testMoment.date(), i,
  24431. 'lenient ordinal parsing ' + i + ' date check');
  24432. }
  24433. });
  24434. test('lenient ordinal parsing of number', function (assert) {
  24435. var i, testMoment;
  24436. for (i = 1; i <= 31; ++i) {
  24437. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  24438. assert.equal(testMoment.year(), 2014,
  24439. 'lenient ordinal parsing of number ' + i + ' year check');
  24440. assert.equal(testMoment.month(), 0,
  24441. 'lenient ordinal parsing of number ' + i + ' month check');
  24442. assert.equal(testMoment.date(), i,
  24443. 'lenient ordinal parsing of number ' + i + ' date check');
  24444. }
  24445. });
  24446. test('strict ordinal parsing', function (assert) {
  24447. var i, ordinalStr, testMoment;
  24448. for (i = 1; i <= 31; ++i) {
  24449. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  24450. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  24451. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  24452. }
  24453. });
  24454. }));
  24455. ;(function (global, factory) {
  24456. typeof exports === 'object' && typeof module !== 'undefined'
  24457. && typeof require === 'function' ? factory(require('../../moment')) :
  24458. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  24459. factory(global.moment)
  24460. }(this, function (moment) { 'use strict';
  24461. /*global QUnit:false*/
  24462. var test = QUnit.test;
  24463. var expect = QUnit.expect;
  24464. function module (name, lifecycle) {
  24465. QUnit.module(name, {
  24466. setup : function () {
  24467. moment.locale('en');
  24468. moment.createFromInputFallback = function (config) {
  24469. throw new Error('input not handled by moment: ' + config._i);
  24470. };
  24471. if (lifecycle && lifecycle.setup) {
  24472. lifecycle.setup();
  24473. }
  24474. },
  24475. teardown : function () {
  24476. if (lifecycle && lifecycle.teardown) {
  24477. lifecycle.teardown();
  24478. }
  24479. }
  24480. });
  24481. }
  24482. function localeModule (name, lifecycle) {
  24483. QUnit.module('locale:' + name, {
  24484. setup : function () {
  24485. moment.locale(name);
  24486. moment.createFromInputFallback = function (config) {
  24487. throw new Error('input not handled by moment: ' + config._i);
  24488. };
  24489. if (lifecycle && lifecycle.setup) {
  24490. lifecycle.setup();
  24491. }
  24492. },
  24493. teardown : function () {
  24494. moment.locale('en');
  24495. if (lifecycle && lifecycle.teardown) {
  24496. lifecycle.teardown();
  24497. }
  24498. }
  24499. });
  24500. }
  24501. localeModule('si');
  24502. /*jshint -W100*/
  24503. test('parse', function (assert) {
  24504. var tests = 'ජනවාරි ජන_පෙබරවාරි පෙබ_මාර්තු මාර්_අප්‍රේල් අප්_මැයි මැයි_ජූනි ජූනි_ජූලි ජූලි_අගෝස්තු අගෝ_සැප්තැම්බර් සැප්_ඔක්තෝබර් ඔක්_නොවැම්බර් නොවැ_දෙසැම්බර් දෙසැ'.split('_'), i;
  24505. function equalTest(input, mmm, i) {
  24506. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  24507. }
  24508. for (i = 0; i < 12; i++) {
  24509. tests[i] = tests[i].split(' ');
  24510. equalTest(tests[i][0], 'MMM', i);
  24511. equalTest(tests[i][1], 'MMM', i);
  24512. equalTest(tests[i][0], 'MMMM', i);
  24513. equalTest(tests[i][1], 'MMMM', i);
  24514. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  24515. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  24516. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  24517. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  24518. }
  24519. });
  24520. test('format', function (assert) {
  24521. var a = [
  24522. ['YYYY MMMM Do dddd, a h:mm:ss', '2010 පෙබරවාරි 14 වැනි ඉරිදා, ප.ව. 3:25:50'],
  24523. ['YYYY MMMM Do dddd, a h:mm:ss', '2010 පෙබරවාරි 14 වැනි ඉරිදා, ප.ව. 3:25:50'],
  24524. ['ddd, A h', 'ඉරි, පස් වරු 3'],
  24525. ['M Mo MM MMMM MMM', '2 2 වැනි 02 පෙබරවාරි පෙබ'],
  24526. ['YYYY YY', '2010 10'],
  24527. ['D Do DD', '14 14 වැනි 14'],
  24528. ['d do dddd ddd dd', '0 0 වැනි ඉරිදා ඉරි ඉ'],
  24529. ['DDD DDDo DDDD', '45 45 වැනි 045'],
  24530. ['h hh', '3 03'],
  24531. ['H HH', '15 15'],
  24532. ['m mm', '25 25'],
  24533. ['s ss', '50 50'],
  24534. ['a A', 'ප.ව. පස් වරු'],
  24535. ['[වසරේ] DDDo [දිනය]', 'වසරේ 45 වැනි දිනය'],
  24536. ['LTS', 'ප.ව. 3:25:50'],
  24537. ['LT', 'ප.ව. 3:25'],
  24538. ['L', '2010/02/14'],
  24539. ['LL', '2010 පෙබරවාරි 14'],
  24540. ['LLL', '2010 පෙබරවාරි 14, ප.ව. 3:25'],
  24541. ['LLLL', '2010 පෙබරවාරි 14 වැනි ඉරිදා, ප.ව. 3:25:50'],
  24542. ['l', '2010/2/14'],
  24543. ['ll', '2010 පෙබ 14'],
  24544. ['lll', '2010 පෙබ 14, ප.ව. 3:25'],
  24545. ['llll', '2010 පෙබ 14 වැනි ඉරි, ප.ව. 3:25:50']
  24546. ],
  24547. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  24548. i;
  24549. for (i = 0; i < a.length; i++) {
  24550. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  24551. }
  24552. });
  24553. test('format ordinal', function (assert) {
  24554. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1 වැනි', '1 වැනි');
  24555. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2 වැනි', '2 වැනි');
  24556. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3 වැනි', '3 වැනි');
  24557. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4 වැනි', '4 වැනි');
  24558. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5 වැනි', '5 වැනි');
  24559. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6 වැනි', '6 වැනි');
  24560. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7 වැනි', '7 වැනි');
  24561. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8 වැනි', '8 වැනි');
  24562. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9 වැනි', '9 වැනි');
  24563. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10 වැනි', '10 වැනි');
  24564. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11 වැනි', '11 වැනි');
  24565. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12 වැනි', '12 වැනි');
  24566. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13 වැනි', '13 වැනි');
  24567. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14 වැනි', '14 වැනි');
  24568. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15 වැනි', '15 වැනි');
  24569. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16 වැනි', '16 වැනි');
  24570. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17 වැනි', '17 වැනි');
  24571. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18 වැනි', '18 වැනි');
  24572. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19 වැනි', '19 වැනි');
  24573. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20 වැනි', '20 වැනි');
  24574. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21 වැනි', '21 වැනි');
  24575. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22 වැනි', '22 වැනි');
  24576. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23 වැනි', '23 වැනි');
  24577. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24 වැනි', '24 වැනි');
  24578. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25 වැනි', '25 වැනි');
  24579. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26 වැනි', '26 වැනි');
  24580. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27 වැනි', '27 වැනි');
  24581. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28 වැනි', '28 වැනි');
  24582. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29 වැනි', '29 වැනි');
  24583. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30 වැනි', '30 වැනි');
  24584. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31 වැනි', '31 වැනි');
  24585. });
  24586. test('format month', function (assert) {
  24587. var expected = 'ජනවාරි ජන_පෙබරවාරි පෙබ_මාර්තු මාර්_අප්‍රේල් අප්_මැයි මැයි_ජූනි ජූනි_ජූලි ජූලි_අගෝස්තු අගෝ_සැප්තැම්බර් සැප්_ඔක්තෝබර් ඔක්_නොවැම්බර් නොවැ_දෙසැම්බර් දෙසැ'.split('_'), i;
  24588. for (i = 0; i < expected.length; i++) {
  24589. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  24590. }
  24591. });
  24592. test('format week', function (assert) {
  24593. var expected = 'ඉරිදා ඉරි ඉ_සඳුදා සඳු ස_අඟහරුවාදා අඟ අ_බදාදා බදා බ_බ්‍රහස්පතින්දා බ්‍රහ බ්‍ර_සිකුරාදා සිකු සි_සෙනසුරාදා සෙන සෙ'.split('_'), i;
  24594. for (i = 0; i < expected.length; i++) {
  24595. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  24596. }
  24597. });
  24598. test('from', function (assert) {
  24599. var start = moment([2007, 1, 28]);
  24600. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'තත්පර කිහිපය', '44 seconds = a few seconds');
  24601. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'මිනිත්තුව', '45 seconds = a minute');
  24602. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'මිනිත්තුව', '89 seconds = a minute');
  24603. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), 'මිනිත්තු 2', '90 seconds = 2 minutes');
  24604. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), 'මිනිත්තු 44', '44 minutes = 44 minutes');
  24605. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'පැය', '45 minutes = an hour');
  24606. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'පැය', '89 minutes = an hour');
  24607. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), 'පැය 2', '90 minutes = 2 hours');
  24608. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), 'පැය 5', '5 hours = 5 hours');
  24609. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), 'පැය 21', '21 hours = 21 hours');
  24610. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'දිනය', '22 hours = a day');
  24611. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'දිනය', '35 hours = a day');
  24612. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), 'දින 2', '36 hours = 2 days');
  24613. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'දිනය', '1 day = a day');
  24614. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), 'දින 5', '5 days = 5 days');
  24615. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), 'දින 25', '25 days = 25 days');
  24616. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'මාසය', '26 days = a month');
  24617. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'මාසය', '30 days = a month');
  24618. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'මාසය', '43 days = a month');
  24619. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), 'මාස 2', '46 days = 2 months');
  24620. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), 'මාස 2', '75 days = 2 months');
  24621. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), 'මාස 3', '76 days = 3 months');
  24622. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'මාසය', '1 month = a month');
  24623. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), 'මාස 5', '5 months = 5 months');
  24624. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'වසර', '345 days = a year');
  24625. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), 'වසර 2', '548 days = 2 years');
  24626. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'වසර', '1 year = a year');
  24627. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), 'වසර 5', '5 years = 5 years');
  24628. });
  24629. test('suffix', function (assert) {
  24630. assert.equal(moment(30000).from(0), 'තත්පර කිහිපයකින්', 'prefix');
  24631. assert.equal(moment(0).from(30000), 'තත්පර කිහිපයකට පෙර', 'suffix');
  24632. });
  24633. test('now from now', function (assert) {
  24634. assert.equal(moment().fromNow(), 'තත්පර කිහිපයකට පෙර', 'now from now should display as in the past');
  24635. });
  24636. test('fromNow', function (assert) {
  24637. assert.equal(moment().add({s: 30}).fromNow(), 'තත්පර කිහිපයකින්', 'in a few seconds');
  24638. assert.equal(moment().add({d: 5}).fromNow(), 'දින 5කින්', 'in 5 days');
  24639. });
  24640. test('calendar day', function (assert) {
  24641. var a = moment().hours(2).minutes(0).seconds(0);
  24642. assert.equal(moment(a).calendar(), 'අද පෙ.ව. 2:00ට', 'today at the same time');
  24643. assert.equal(moment(a).add({m: 25}).calendar(), 'අද පෙ.ව. 2:25ට', 'Now plus 25 min');
  24644. assert.equal(moment(a).add({h: 1}).calendar(), 'අද පෙ.ව. 3:00ට', 'Now plus 1 hour');
  24645. assert.equal(moment(a).add({d: 1}).calendar(), 'හෙට පෙ.ව. 2:00ට', 'tomorrow at the same time');
  24646. assert.equal(moment(a).subtract({h: 1}).calendar(), 'අද පෙ.ව. 1:00ට', 'Now minus 1 hour');
  24647. assert.equal(moment(a).subtract({d: 1}).calendar(), 'ඊයේ පෙ.ව. 2:00ට', 'yesterday at the same time');
  24648. });
  24649. test('calendar next week', function (assert) {
  24650. var i, m;
  24651. for (i = 2; i < 7; i++) {
  24652. m = moment().add({d: i});
  24653. assert.equal(m.calendar(), m.format('dddd LT[ට]'), 'Today + ' + i + ' days current time');
  24654. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  24655. assert.equal(m.calendar(), m.format('dddd LT[ට]'), 'Today + ' + i + ' days beginning of day');
  24656. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  24657. assert.equal(m.calendar(), m.format('dddd LT[ට]'), 'Today + ' + i + ' days end of day');
  24658. }
  24659. });
  24660. test('calendar last week', function (assert) {
  24661. var i, m;
  24662. for (i = 2; i < 7; i++) {
  24663. m = moment().subtract({d: i});
  24664. assert.equal(m.calendar(), m.format('[පසුගිය] dddd LT[ට]'), 'Today - ' + i + ' days current time');
  24665. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  24666. assert.equal(m.calendar(), m.format('[පසුගිය] dddd LT[ට]'), 'Today - ' + i + ' days beginning of day');
  24667. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  24668. assert.equal(m.calendar(), m.format('[පසුගිය] dddd LT[ට]'), 'Today - ' + i + ' days end of day');
  24669. }
  24670. });
  24671. test('calendar all else', function (assert) {
  24672. var weeksAgo = moment().subtract({w: 1}),
  24673. weeksFromNow = moment().add({w: 1});
  24674. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  24675. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  24676. weeksAgo = moment().subtract({w: 2});
  24677. weeksFromNow = moment().add({w: 2});
  24678. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  24679. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  24680. });
  24681. test('lenient ordinal parsing', function (assert) {
  24682. var i, ordinalStr, testMoment;
  24683. for (i = 1; i <= 31; ++i) {
  24684. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  24685. testMoment = moment(ordinalStr, 'YYYY MM Do');
  24686. assert.equal(testMoment.year(), 2014,
  24687. 'lenient ordinal parsing ' + i + ' year check');
  24688. assert.equal(testMoment.month(), 0,
  24689. 'lenient ordinal parsing ' + i + ' month check');
  24690. assert.equal(testMoment.date(), i,
  24691. 'lenient ordinal parsing ' + i + ' date check');
  24692. }
  24693. });
  24694. test('lenient ordinal parsing of number', function (assert) {
  24695. var i, testMoment;
  24696. for (i = 1; i <= 31; ++i) {
  24697. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  24698. assert.equal(testMoment.year(), 2014,
  24699. 'lenient ordinal parsing of number ' + i + ' year check');
  24700. assert.equal(testMoment.month(), 0,
  24701. 'lenient ordinal parsing of number ' + i + ' month check');
  24702. assert.equal(testMoment.date(), i,
  24703. 'lenient ordinal parsing of number ' + i + ' date check');
  24704. }
  24705. });
  24706. test('strict ordinal parsing', function (assert) {
  24707. var i, ordinalStr, testMoment;
  24708. for (i = 1; i <= 31; ++i) {
  24709. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  24710. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  24711. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  24712. }
  24713. });
  24714. }));
  24715. ;(function (global, factory) {
  24716. typeof exports === 'object' && typeof module !== 'undefined'
  24717. && typeof require === 'function' ? factory(require('../../moment')) :
  24718. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  24719. factory(global.moment)
  24720. }(this, function (moment) { 'use strict';
  24721. /*global QUnit:false*/
  24722. var test = QUnit.test;
  24723. var expect = QUnit.expect;
  24724. function module (name, lifecycle) {
  24725. QUnit.module(name, {
  24726. setup : function () {
  24727. moment.locale('en');
  24728. moment.createFromInputFallback = function (config) {
  24729. throw new Error('input not handled by moment: ' + config._i);
  24730. };
  24731. if (lifecycle && lifecycle.setup) {
  24732. lifecycle.setup();
  24733. }
  24734. },
  24735. teardown : function () {
  24736. if (lifecycle && lifecycle.teardown) {
  24737. lifecycle.teardown();
  24738. }
  24739. }
  24740. });
  24741. }
  24742. function localeModule (name, lifecycle) {
  24743. QUnit.module('locale:' + name, {
  24744. setup : function () {
  24745. moment.locale(name);
  24746. moment.createFromInputFallback = function (config) {
  24747. throw new Error('input not handled by moment: ' + config._i);
  24748. };
  24749. if (lifecycle && lifecycle.setup) {
  24750. lifecycle.setup();
  24751. }
  24752. },
  24753. teardown : function () {
  24754. moment.locale('en');
  24755. if (lifecycle && lifecycle.teardown) {
  24756. lifecycle.teardown();
  24757. }
  24758. }
  24759. });
  24760. }
  24761. localeModule('sk');
  24762. test('parse', function (assert) {
  24763. var tests = 'január jan._február feb._marec mar._apríl apr._máj máj_jún jún._júl júl._august aug._september sep._október okt._november nov._december dec.'.split('_'), i;
  24764. function equalTest(input, mmm, monthIndex) {
  24765. assert.equal(moment(input, mmm).month(), monthIndex, input + ' should be month ' + (monthIndex + 1));
  24766. }
  24767. for (i = 0; i < 12; i++) {
  24768. tests[i] = tests[i].split(' ');
  24769. equalTest(tests[i][0], 'MMM', i);
  24770. equalTest(tests[i][1], 'MMM', i);
  24771. equalTest(tests[i][0], 'MMMM', i);
  24772. equalTest(tests[i][1], 'MMMM', i);
  24773. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  24774. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  24775. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  24776. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  24777. }
  24778. });
  24779. test('format', function (assert) {
  24780. var a = [
  24781. ['dddd, MMMM Do YYYY, h:mm:ss', 'nedeľa, február 14. 2010, 3:25:50'],
  24782. ['ddd, h', 'ne, 3'],
  24783. ['M Mo MM MMMM MMM', '2 2. 02 február feb'],
  24784. ['YYYY YY', '2010 10'],
  24785. ['D Do DD', '14 14. 14'],
  24786. ['d do dddd ddd dd', '0 0. nedeľa ne ne'],
  24787. ['DDD DDDo DDDD', '45 45. 045'],
  24788. ['w wo ww', '6 6. 06'],
  24789. ['h hh', '3 03'],
  24790. ['H HH', '15 15'],
  24791. ['m mm', '25 25'],
  24792. ['s ss', '50 50'],
  24793. ['a A', 'pm PM'],
  24794. ['DDDo [deň v roku]', '45. deň v roku'],
  24795. ['LTS', '15:25:50'],
  24796. ['L', '14.02.2010'],
  24797. ['LL', '14. február 2010'],
  24798. ['LLL', '14. február 2010 15:25'],
  24799. ['LLLL', 'nedeľa 14. február 2010 15:25'],
  24800. ['l', '14.2.2010'],
  24801. ['ll', '14. feb 2010'],
  24802. ['lll', '14. feb 2010 15:25'],
  24803. ['llll', 'ne 14. feb 2010 15:25']
  24804. ],
  24805. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  24806. i;
  24807. for (i = 0; i < a.length; i++) {
  24808. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  24809. }
  24810. });
  24811. test('format ordinal', function (assert) {
  24812. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
  24813. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
  24814. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
  24815. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
  24816. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
  24817. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
  24818. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
  24819. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
  24820. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
  24821. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
  24822. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
  24823. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
  24824. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
  24825. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
  24826. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
  24827. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
  24828. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
  24829. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
  24830. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
  24831. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
  24832. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
  24833. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
  24834. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
  24835. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
  24836. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
  24837. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
  24838. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
  24839. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
  24840. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
  24841. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
  24842. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
  24843. });
  24844. test('format month', function (assert) {
  24845. var expected = 'január jan_február feb_marec mar_apríl apr_máj máj_jún jún_júl júl_august aug_september sep_október okt_november nov_december dec'.split('_'), i;
  24846. for (i = 0; i < expected.length; i++) {
  24847. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  24848. }
  24849. });
  24850. test('format week', function (assert) {
  24851. var expected = 'nedeľa ne ne_pondelok po po_utorok ut ut_streda st st_štvrtok št št_piatok pi pi_sobota so so'.split('_'), i;
  24852. for (i = 0; i < expected.length; i++) {
  24853. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  24854. }
  24855. });
  24856. test('from', function (assert) {
  24857. var start = moment([2007, 1, 28]);
  24858. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'pár sekúnd', '44 seconds = a few seconds');
  24859. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'minúta', '45 seconds = a minute');
  24860. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'minúta', '89 seconds = a minute');
  24861. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minúty', '90 seconds = 2 minutes');
  24862. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minút', '44 minutes = 44 minutes');
  24863. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'hodina', '45 minutes = an hour');
  24864. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'hodina', '89 minutes = an hour');
  24865. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 hodiny', '90 minutes = 2 hours');
  24866. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 hodín', '5 hours = 5 hours');
  24867. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 hodín', '21 hours = 21 hours');
  24868. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'deň', '22 hours = a day');
  24869. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'deň', '35 hours = a day');
  24870. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dni', '36 hours = 2 days');
  24871. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'deň', '1 day = a day');
  24872. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dní', '5 days = 5 days');
  24873. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dní', '25 days = 25 days');
  24874. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'mesiac', '26 days = a month');
  24875. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'mesiac', '30 days = a month');
  24876. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'mesiac', '43 days = a month');
  24877. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mesiace', '46 days = 2 months');
  24878. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mesiace', '75 days = 2 months');
  24879. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mesiace', '76 days = 3 months');
  24880. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'mesiac', '1 month = a month');
  24881. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mesiacov', '5 months = 5 months');
  24882. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'rok', '345 days = a year');
  24883. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 roky', '548 days = 2 years');
  24884. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'rok', '1 year = a year');
  24885. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 rokov', '5 years = 5 years');
  24886. });
  24887. test('suffix', function (assert) {
  24888. assert.equal(moment(30000).from(0), 'za pár sekúnd', 'prefix');
  24889. assert.equal(moment(0).from(30000), 'pred pár sekundami', 'suffix');
  24890. });
  24891. test('now from now', function (assert) {
  24892. assert.equal(moment().fromNow(), 'pred pár sekundami', 'now from now should display as in the past');
  24893. });
  24894. test('fromNow (future)', function (assert) {
  24895. assert.equal(moment().add({s: 30}).fromNow(), 'za pár sekúnd', 'in a few seconds');
  24896. assert.equal(moment().add({m: 1}).fromNow(), 'za minútu', 'in a minute');
  24897. assert.equal(moment().add({m: 3}).fromNow(), 'za 3 minúty', 'in 3 minutes');
  24898. assert.equal(moment().add({m: 10}).fromNow(), 'za 10 minút', 'in 10 minutes');
  24899. assert.equal(moment().add({h: 1}).fromNow(), 'za hodinu', 'in an hour');
  24900. assert.equal(moment().add({h: 3}).fromNow(), 'za 3 hodiny', 'in 3 hours');
  24901. assert.equal(moment().add({h: 10}).fromNow(), 'za 10 hodín', 'in 10 hours');
  24902. assert.equal(moment().add({d: 1}).fromNow(), 'za deň', 'in a day');
  24903. assert.equal(moment().add({d: 3}).fromNow(), 'za 3 dni', 'in 3 days');
  24904. assert.equal(moment().add({d: 10}).fromNow(), 'za 10 dní', 'in 10 days');
  24905. assert.equal(moment().add({M: 1}).fromNow(), 'za mesiac', 'in a month');
  24906. assert.equal(moment().add({M: 3}).fromNow(), 'za 3 mesiace', 'in 3 months');
  24907. assert.equal(moment().add({M: 10}).fromNow(), 'za 10 mesiacov', 'in 10 months');
  24908. assert.equal(moment().add({y: 1}).fromNow(), 'za rok', 'in a year');
  24909. assert.equal(moment().add({y: 3}).fromNow(), 'za 3 roky', 'in 3 years');
  24910. assert.equal(moment().add({y: 10}).fromNow(), 'za 10 rokov', 'in 10 years');
  24911. });
  24912. test('fromNow (past)', function (assert) {
  24913. assert.equal(moment().subtract({s: 30}).fromNow(), 'pred pár sekundami', 'a few seconds ago');
  24914. assert.equal(moment().subtract({m: 1}).fromNow(), 'pred minútou', 'a minute ago');
  24915. assert.equal(moment().subtract({m: 3}).fromNow(), 'pred 3 minútami', '3 minutes ago');
  24916. assert.equal(moment().subtract({m: 10}).fromNow(), 'pred 10 minútami', '10 minutes ago');
  24917. assert.equal(moment().subtract({h: 1}).fromNow(), 'pred hodinou', 'an hour ago');
  24918. assert.equal(moment().subtract({h: 3}).fromNow(), 'pred 3 hodinami', '3 hours ago');
  24919. assert.equal(moment().subtract({h: 10}).fromNow(), 'pred 10 hodinami', '10 hours ago');
  24920. assert.equal(moment().subtract({d: 1}).fromNow(), 'pred dňom', 'a day ago');
  24921. assert.equal(moment().subtract({d: 3}).fromNow(), 'pred 3 dňami', '3 days ago');
  24922. assert.equal(moment().subtract({d: 10}).fromNow(), 'pred 10 dňami', '10 days ago');
  24923. assert.equal(moment().subtract({M: 1}).fromNow(), 'pred mesiacom', 'a month ago');
  24924. assert.equal(moment().subtract({M: 3}).fromNow(), 'pred 3 mesiacmi', '3 months ago');
  24925. assert.equal(moment().subtract({M: 10}).fromNow(), 'pred 10 mesiacmi', '10 months ago');
  24926. assert.equal(moment().subtract({y: 1}).fromNow(), 'pred rokom', 'a year ago');
  24927. assert.equal(moment().subtract({y: 3}).fromNow(), 'pred 3 rokmi', '3 years ago');
  24928. assert.equal(moment().subtract({y: 10}).fromNow(), 'pred 10 rokmi', '10 years ago');
  24929. });
  24930. test('calendar day', function (assert) {
  24931. var a = moment().hours(2).minutes(0).seconds(0);
  24932. assert.equal(moment(a).calendar(), 'dnes o 2:00', 'today at the same time');
  24933. assert.equal(moment(a).add({m: 25}).calendar(), 'dnes o 2:25', 'Now plus 25 min');
  24934. assert.equal(moment(a).add({h: 1}).calendar(), 'dnes o 3:00', 'Now plus 1 hour');
  24935. assert.equal(moment(a).add({d: 1}).calendar(), 'zajtra o 2:00', 'tomorrow at the same time');
  24936. assert.equal(moment(a).subtract({h: 1}).calendar(), 'dnes o 1:00', 'Now minus 1 hour');
  24937. assert.equal(moment(a).subtract({d: 1}).calendar(), 'včera o 2:00', 'yesterday at the same time');
  24938. });
  24939. test('calendar next week', function (assert) {
  24940. var i, m, nextDay;
  24941. for (i = 2; i < 7; i++) {
  24942. m = moment().add({d: i});
  24943. nextDay = '';
  24944. switch (m.day()) {
  24945. case 0:
  24946. nextDay = 'v nedeľu';
  24947. break;
  24948. case 1:
  24949. nextDay = 'v pondelok';
  24950. break;
  24951. case 2:
  24952. nextDay = 'v utorok';
  24953. break;
  24954. case 3:
  24955. nextDay = 'v stredu';
  24956. break;
  24957. case 4:
  24958. nextDay = 'vo štvrtok';
  24959. break;
  24960. case 5:
  24961. nextDay = 'v piatok';
  24962. break;
  24963. case 6:
  24964. nextDay = 'v sobotu';
  24965. break;
  24966. }
  24967. assert.equal(m.calendar(), m.format('[' + nextDay + '] [o] LT'), 'Today + ' + i + ' days current time');
  24968. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  24969. assert.equal(m.calendar(), m.format('[' + nextDay + '] [o] LT'), 'Today + ' + i + ' days beginning of day');
  24970. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  24971. assert.equal(m.calendar(), m.format('[' + nextDay + '] [o] LT'), 'Today + ' + i + ' days end of day');
  24972. }
  24973. });
  24974. test('calendar last week', function (assert) {
  24975. var i, m, lastDay;
  24976. for (i = 2; i < 7; i++) {
  24977. m = moment().subtract({d: i});
  24978. lastDay = '';
  24979. switch (m.day()) {
  24980. case 0:
  24981. lastDay = 'minulú nedeľu';
  24982. break;
  24983. case 1:
  24984. lastDay = 'minulý pondelok';
  24985. break;
  24986. case 2:
  24987. lastDay = 'minulý utorok';
  24988. break;
  24989. case 3:
  24990. lastDay = 'minulú stredu';
  24991. break;
  24992. case 4:
  24993. lastDay = 'minulý štvrtok';
  24994. break;
  24995. case 5:
  24996. lastDay = 'minulý piatok';
  24997. break;
  24998. case 6:
  24999. lastDay = 'minulú sobotu';
  25000. break;
  25001. }
  25002. assert.equal(m.calendar(), m.format('[' + lastDay + '] [o] LT'), 'Today - ' + i + ' days current time');
  25003. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  25004. assert.equal(m.calendar(), m.format('[' + lastDay + '] [o] LT'), 'Today - ' + i + ' days beginning of day');
  25005. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  25006. assert.equal(m.calendar(), m.format('[' + lastDay + '] [o] LT'), 'Today - ' + i + ' days end of day');
  25007. }
  25008. });
  25009. test('calendar all else', function (assert) {
  25010. var weeksAgo = moment().subtract({w: 1}),
  25011. weeksFromNow = moment().add({w: 1});
  25012. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  25013. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  25014. weeksAgo = moment().subtract({w: 2});
  25015. weeksFromNow = moment().add({w: 2});
  25016. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  25017. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  25018. });
  25019. test('humanize duration', function (assert) {
  25020. assert.equal(moment.duration(1, 'minutes').humanize(), 'minúta', 'a minute (future)');
  25021. assert.equal(moment.duration(1, 'minutes').humanize(true), 'za minútu', 'in a minute');
  25022. assert.equal(moment.duration(-1, 'minutes').humanize(), 'minúta', 'a minute (past)');
  25023. assert.equal(moment.duration(-1, 'minutes').humanize(true), 'pred minútou', 'a minute ago');
  25024. });
  25025. test('weeks year starting sunday', function (assert) {
  25026. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  25027. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  25028. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  25029. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  25030. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  25031. });
  25032. test('weeks year starting monday', function (assert) {
  25033. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  25034. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  25035. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  25036. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  25037. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  25038. });
  25039. test('weeks year starting tuesday', function (assert) {
  25040. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  25041. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  25042. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  25043. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  25044. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  25045. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  25046. });
  25047. test('weeks year starting wednesday', function (assert) {
  25048. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  25049. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  25050. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  25051. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  25052. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  25053. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  25054. });
  25055. test('weeks year starting thursday', function (assert) {
  25056. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  25057. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  25058. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  25059. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  25060. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  25061. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  25062. });
  25063. test('weeks year starting friday', function (assert) {
  25064. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  25065. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  25066. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  25067. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  25068. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  25069. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  25070. });
  25071. test('weeks year starting saturday', function (assert) {
  25072. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  25073. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  25074. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  25075. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  25076. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  25077. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  25078. });
  25079. test('weeks year starting sunday formatted', function (assert) {
  25080. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
  25081. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
  25082. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
  25083. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
  25084. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
  25085. });
  25086. test('lenient ordinal parsing', function (assert) {
  25087. var i, ordinalStr, testMoment;
  25088. for (i = 1; i <= 31; ++i) {
  25089. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  25090. testMoment = moment(ordinalStr, 'YYYY MM Do');
  25091. assert.equal(testMoment.year(), 2014,
  25092. 'lenient ordinal parsing ' + i + ' year check');
  25093. assert.equal(testMoment.month(), 0,
  25094. 'lenient ordinal parsing ' + i + ' month check');
  25095. assert.equal(testMoment.date(), i,
  25096. 'lenient ordinal parsing ' + i + ' date check');
  25097. }
  25098. });
  25099. test('lenient ordinal parsing of number', function (assert) {
  25100. var i, testMoment;
  25101. for (i = 1; i <= 31; ++i) {
  25102. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  25103. assert.equal(testMoment.year(), 2014,
  25104. 'lenient ordinal parsing of number ' + i + ' year check');
  25105. assert.equal(testMoment.month(), 0,
  25106. 'lenient ordinal parsing of number ' + i + ' month check');
  25107. assert.equal(testMoment.date(), i,
  25108. 'lenient ordinal parsing of number ' + i + ' date check');
  25109. }
  25110. });
  25111. test('strict ordinal parsing', function (assert) {
  25112. var i, ordinalStr, testMoment;
  25113. for (i = 1; i <= 31; ++i) {
  25114. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  25115. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  25116. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  25117. }
  25118. });
  25119. }));
  25120. ;(function (global, factory) {
  25121. typeof exports === 'object' && typeof module !== 'undefined'
  25122. && typeof require === 'function' ? factory(require('../../moment')) :
  25123. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  25124. factory(global.moment)
  25125. }(this, function (moment) { 'use strict';
  25126. /*global QUnit:false*/
  25127. var test = QUnit.test;
  25128. var expect = QUnit.expect;
  25129. function module (name, lifecycle) {
  25130. QUnit.module(name, {
  25131. setup : function () {
  25132. moment.locale('en');
  25133. moment.createFromInputFallback = function (config) {
  25134. throw new Error('input not handled by moment: ' + config._i);
  25135. };
  25136. if (lifecycle && lifecycle.setup) {
  25137. lifecycle.setup();
  25138. }
  25139. },
  25140. teardown : function () {
  25141. if (lifecycle && lifecycle.teardown) {
  25142. lifecycle.teardown();
  25143. }
  25144. }
  25145. });
  25146. }
  25147. function localeModule (name, lifecycle) {
  25148. QUnit.module('locale:' + name, {
  25149. setup : function () {
  25150. moment.locale(name);
  25151. moment.createFromInputFallback = function (config) {
  25152. throw new Error('input not handled by moment: ' + config._i);
  25153. };
  25154. if (lifecycle && lifecycle.setup) {
  25155. lifecycle.setup();
  25156. }
  25157. },
  25158. teardown : function () {
  25159. moment.locale('en');
  25160. if (lifecycle && lifecycle.teardown) {
  25161. lifecycle.teardown();
  25162. }
  25163. }
  25164. });
  25165. }
  25166. localeModule('sl');
  25167. test('parse', function (assert) {
  25168. var tests = 'januar jan._februar feb._marec mar._april apr._maj maj_junij jun._julij jul._avgust avg._september sep._oktober okt._november nov._december dec.'.split('_'), i;
  25169. function equalTest(input, mmm, i) {
  25170. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  25171. }
  25172. for (i = 0; i < 12; i++) {
  25173. tests[i] = tests[i].split(' ');
  25174. equalTest(tests[i][0], 'MMM', i);
  25175. equalTest(tests[i][1], 'MMM', i);
  25176. equalTest(tests[i][0], 'MMMM', i);
  25177. equalTest(tests[i][1], 'MMMM', i);
  25178. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  25179. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  25180. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  25181. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  25182. }
  25183. });
  25184. test('format', function (assert) {
  25185. var a = [
  25186. ['dddd, Do MMMM YYYY, h:mm:ss a', 'nedelja, 14. februar 2010, 3:25:50 pm'],
  25187. ['ddd, hA', 'ned., 3PM'],
  25188. ['M Mo MM MMMM MMM', '2 2. 02 februar feb.'],
  25189. ['YYYY YY', '2010 10'],
  25190. ['D Do DD', '14 14. 14'],
  25191. ['d do dddd ddd dd', '0 0. nedelja ned. ne'],
  25192. ['DDD DDDo DDDD', '45 45. 045'],
  25193. ['w wo ww', '7 7. 07'],
  25194. ['h hh', '3 03'],
  25195. ['H HH', '15 15'],
  25196. ['m mm', '25 25'],
  25197. ['s ss', '50 50'],
  25198. ['a A', 'pm PM'],
  25199. ['[the] DDDo [day of the year]', 'the 45. day of the year'],
  25200. ['LTS', '15:25:50'],
  25201. ['L', '14. 02. 2010'],
  25202. ['LL', '14. februar 2010'],
  25203. ['LLL', '14. februar 2010 15:25'],
  25204. ['LLLL', 'nedelja, 14. februar 2010 15:25'],
  25205. ['l', '14. 2. 2010'],
  25206. ['ll', '14. feb. 2010'],
  25207. ['lll', '14. feb. 2010 15:25'],
  25208. ['llll', 'ned., 14. feb. 2010 15:25']
  25209. ],
  25210. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  25211. i;
  25212. for (i = 0; i < a.length; i++) {
  25213. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  25214. }
  25215. });
  25216. test('format ordinal', function (assert) {
  25217. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
  25218. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
  25219. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
  25220. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
  25221. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
  25222. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
  25223. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
  25224. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
  25225. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
  25226. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
  25227. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
  25228. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
  25229. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
  25230. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
  25231. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
  25232. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
  25233. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
  25234. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
  25235. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
  25236. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
  25237. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
  25238. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
  25239. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
  25240. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
  25241. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
  25242. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
  25243. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
  25244. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
  25245. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
  25246. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
  25247. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
  25248. });
  25249. test('format month', function (assert) {
  25250. var expected = 'januar jan._februar feb._marec mar._april apr._maj maj._junij jun._julij jul._avgust avg._september sep._oktober okt._november nov._december dec.'.split('_'), i;
  25251. for (i = 0; i < expected.length; i++) {
  25252. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  25253. }
  25254. });
  25255. test('format week', function (assert) {
  25256. var expected = 'nedelja ned. ne_ponedeljek pon. po_torek tor. to_sreda sre. sr_četrtek čet. če_petek pet. pe_sobota sob. so'.split('_'), i;
  25257. for (i = 0; i < expected.length; i++) {
  25258. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  25259. }
  25260. });
  25261. test('from', function (assert) {
  25262. var start = moment([2007, 1, 28]);
  25263. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'nekaj sekund', '44 seconds = a few seconds');
  25264. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'ena minuta', '45 seconds = a minute');
  25265. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'ena minuta', '89 seconds = a minute');
  25266. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuti', '90 seconds = 2 minutes');
  25267. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minut', '44 minutes = 44 minutes');
  25268. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ena ura', '45 minutes = an hour');
  25269. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ena ura', '89 minutes = an hour');
  25270. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 uri', '90 minutes = 2 hours');
  25271. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ur', '5 hours = 5 hours');
  25272. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 ur', '21 hours = 21 hours');
  25273. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'en dan', '22 hours = a day');
  25274. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'en dan', '35 hours = a day');
  25275. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dni', '36 hours = 2 days');
  25276. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'en dan', '1 day = a day');
  25277. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dni', '5 days = 5 days');
  25278. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dni', '25 days = 25 days');
  25279. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'en mesec', '26 days = a month');
  25280. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'en mesec', '30 days = a month');
  25281. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'en mesec', '43 days = a month');
  25282. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 meseca', '46 days = 2 months');
  25283. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 meseca', '75 days = 2 months');
  25284. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mesece', '76 days = 3 months');
  25285. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'en mesec', '1 month = a month');
  25286. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mesecev', '5 months = 5 months');
  25287. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'eno leto', '345 days = a year');
  25288. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 leti', '548 days = 2 years');
  25289. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'eno leto', '1 year = a year');
  25290. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 let', '5 years = 5 years');
  25291. assert.equal(start.from(moment([2007, 1, 28]).add({m: 1}), true), 'ena minuta', 'a minute');
  25292. assert.equal(start.from(moment([2007, 1, 28]).add({m: 2}), true), '2 minuti', '2 minutes');
  25293. assert.equal(start.from(moment([2007, 1, 28]).add({m: 3}), true), '3 minute', '3 minutes');
  25294. assert.equal(start.from(moment([2007, 1, 28]).add({m: 4}), true), '4 minute', '4 minutes');
  25295. assert.equal(start.from(moment([2007, 1, 28]).add({m: 5}), true), '5 minut', '5 minutes');
  25296. assert.equal(start.from(moment([2007, 1, 28]).add({h: 1}), true), 'ena ura', 'an hour');
  25297. assert.equal(start.from(moment([2007, 1, 28]).add({h: 2}), true), '2 uri', '2 hours');
  25298. assert.equal(start.from(moment([2007, 1, 28]).add({h: 3}), true), '3 ure', '3 hours');
  25299. assert.equal(start.from(moment([2007, 1, 28]).add({h: 4}), true), '4 ure', '4 hours');
  25300. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ur', '5 hours');
  25301. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'en dan', 'a day');
  25302. assert.equal(start.from(moment([2007, 1, 28]).add({d: 2}), true), '2 dni', '2 days');
  25303. assert.equal(start.from(moment([2007, 1, 28]).add({d: 3}), true), '3 dni', '3 days');
  25304. assert.equal(start.from(moment([2007, 1, 28]).add({d: 4}), true), '4 dni', '4 days');
  25305. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dni', '5 days');
  25306. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'en mesec', 'a month');
  25307. assert.equal(start.from(moment([2007, 1, 28]).add({M: 2}), true), '2 meseca', '2 months');
  25308. assert.equal(start.from(moment([2007, 1, 28]).add({M: 3}), true), '3 mesece', '3 months');
  25309. assert.equal(start.from(moment([2007, 1, 28]).add({M: 4}), true), '4 mesece', '4 months');
  25310. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mesecev', '5 months');
  25311. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'eno leto', 'a year');
  25312. assert.equal(start.from(moment([2007, 1, 28]).add({y: 2}), true), '2 leti', '2 years');
  25313. assert.equal(start.from(moment([2007, 1, 28]).add({y: 3}), true), '3 leta', '3 years');
  25314. assert.equal(start.from(moment([2007, 1, 28]).add({y: 4}), true), '4 leta', '4 years');
  25315. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 let', '5 years');
  25316. });
  25317. test('suffix', function (assert) {
  25318. assert.equal(moment(30000).from(0), 'čez nekaj sekund', 'prefix');
  25319. assert.equal(moment(0).from(30000), 'pred nekaj sekundami', 'suffix');
  25320. });
  25321. test('now from now', function (assert) {
  25322. assert.equal(moment().fromNow(), 'pred nekaj sekundami', 'now from now should display as in the past');
  25323. });
  25324. test('fromNow (future)', function (assert) {
  25325. assert.equal(moment().add({s: 30}).fromNow(), 'čez nekaj sekund', 'in a few seconds');
  25326. assert.equal(moment().add({m: 1}).fromNow(), 'čez eno minuto', 'in a minute');
  25327. assert.equal(moment().add({m: 2}).fromNow(), 'čez 2 minuti', 'in 2 minutes');
  25328. assert.equal(moment().add({m: 3}).fromNow(), 'čez 3 minute', 'in 3 minutes');
  25329. assert.equal(moment().add({m: 4}).fromNow(), 'čez 4 minute', 'in 4 minutes');
  25330. assert.equal(moment().add({m: 5}).fromNow(), 'čez 5 minut', 'in 5 minutes');
  25331. assert.equal(moment().add({h: 1}).fromNow(), 'čez eno uro', 'in an hour');
  25332. assert.equal(moment().add({h: 2}).fromNow(), 'čez 2 uri', 'in 2 hours');
  25333. assert.equal(moment().add({h: 3}).fromNow(), 'čez 3 ure', 'in 3 hours');
  25334. assert.equal(moment().add({h: 4}).fromNow(), 'čez 4 ure', 'in 4 hours');
  25335. assert.equal(moment().add({h: 5}).fromNow(), 'čez 5 ur', 'in 5 hours');
  25336. assert.equal(moment().add({d: 1}).fromNow(), 'čez en dan', 'in a day');
  25337. assert.equal(moment().add({d: 2}).fromNow(), 'čez 2 dni', 'in 2 days');
  25338. assert.equal(moment().add({d: 3}).fromNow(), 'čez 3 dni', 'in 3 days');
  25339. assert.equal(moment().add({d: 4}).fromNow(), 'čez 4 dni', 'in 4 days');
  25340. assert.equal(moment().add({d: 5}).fromNow(), 'čez 5 dni', 'in 5 days');
  25341. assert.equal(moment().add({M: 1}).fromNow(), 'čez en mesec', 'in a month');
  25342. assert.equal(moment().add({M: 2}).fromNow(), 'čez 2 meseca', 'in 2 months');
  25343. assert.equal(moment().add({M: 3}).fromNow(), 'čez 3 mesece', 'in 3 months');
  25344. assert.equal(moment().add({M: 4}).fromNow(), 'čez 4 mesece', 'in 4 months');
  25345. assert.equal(moment().add({M: 5}).fromNow(), 'čez 5 mesecev', 'in 5 months');
  25346. assert.equal(moment().add({y: 1}).fromNow(), 'čez eno leto', 'in a year');
  25347. assert.equal(moment().add({y: 2}).fromNow(), 'čez 2 leti', 'in 2 years');
  25348. assert.equal(moment().add({y: 3}).fromNow(), 'čez 3 leta', 'in 3 years');
  25349. assert.equal(moment().add({y: 4}).fromNow(), 'čez 4 leta', 'in 4 years');
  25350. assert.equal(moment().add({y: 5}).fromNow(), 'čez 5 let', 'in 5 years');
  25351. assert.equal(moment().subtract({s: 30}).fromNow(), 'pred nekaj sekundami', 'a few seconds ago');
  25352. assert.equal(moment().subtract({m: 1}).fromNow(), 'pred eno minuto', 'a minute ago');
  25353. assert.equal(moment().subtract({m: 2}).fromNow(), 'pred 2 minutama', '2 minutes ago');
  25354. assert.equal(moment().subtract({m: 3}).fromNow(), 'pred 3 minutami', '3 minutes ago');
  25355. assert.equal(moment().subtract({m: 4}).fromNow(), 'pred 4 minutami', '4 minutes ago');
  25356. assert.equal(moment().subtract({m: 5}).fromNow(), 'pred 5 minutami', '5 minutes ago');
  25357. assert.equal(moment().subtract({h: 1}).fromNow(), 'pred eno uro', 'an hour ago');
  25358. assert.equal(moment().subtract({h: 2}).fromNow(), 'pred 2 urama', '2 hours ago');
  25359. assert.equal(moment().subtract({h: 3}).fromNow(), 'pred 3 urami', '3 hours ago');
  25360. assert.equal(moment().subtract({h: 4}).fromNow(), 'pred 4 urami', '4 hours ago');
  25361. assert.equal(moment().subtract({h: 5}).fromNow(), 'pred 5 urami', '5 hours ago');
  25362. assert.equal(moment().subtract({d: 1}).fromNow(), 'pred enim dnem', 'a day ago');
  25363. assert.equal(moment().subtract({d: 2}).fromNow(), 'pred 2 dnevoma', '2 days ago');
  25364. assert.equal(moment().subtract({d: 3}).fromNow(), 'pred 3 dnevi', '3 days ago');
  25365. assert.equal(moment().subtract({d: 4}).fromNow(), 'pred 4 dnevi', '4 days ago');
  25366. assert.equal(moment().subtract({d: 5}).fromNow(), 'pred 5 dnevi', '5 days ago');
  25367. assert.equal(moment().subtract({M: 1}).fromNow(), 'pred enim mesecem', 'a month ago');
  25368. assert.equal(moment().subtract({M: 2}).fromNow(), 'pred 2 mesecema', '2 months ago');
  25369. assert.equal(moment().subtract({M: 3}).fromNow(), 'pred 3 meseci', '3 months ago');
  25370. assert.equal(moment().subtract({M: 4}).fromNow(), 'pred 4 meseci', '4 months ago');
  25371. assert.equal(moment().subtract({M: 5}).fromNow(), 'pred 5 meseci', '5 months ago');
  25372. assert.equal(moment().subtract({y: 1}).fromNow(), 'pred enim letom', 'a year ago');
  25373. assert.equal(moment().subtract({y: 2}).fromNow(), 'pred 2 letoma', '2 years ago');
  25374. assert.equal(moment().subtract({y: 3}).fromNow(), 'pred 3 leti', '3 years ago');
  25375. assert.equal(moment().subtract({y: 4}).fromNow(), 'pred 4 leti', '4 years ago');
  25376. assert.equal(moment().subtract({y: 5}).fromNow(), 'pred 5 leti', '5 years ago');
  25377. });
  25378. test('calendar day', function (assert) {
  25379. var a = moment().hours(2).minutes(0).seconds(0);
  25380. assert.equal(moment(a).calendar(), 'danes ob 2:00', 'today at the same time');
  25381. assert.equal(moment(a).add({m: 25}).calendar(), 'danes ob 2:25', 'Now plus 25 min');
  25382. assert.equal(moment(a).add({h: 1}).calendar(), 'danes ob 3:00', 'Now plus 1 hour');
  25383. assert.equal(moment(a).add({d: 1}).calendar(), 'jutri ob 2:00', 'tomorrow at the same time');
  25384. assert.equal(moment(a).subtract({h: 1}).calendar(), 'danes ob 1:00', 'Now minus 1 hour');
  25385. assert.equal(moment(a).subtract({d: 1}).calendar(), 'včeraj ob 2:00', 'yesterday at the same time');
  25386. });
  25387. test('calendar next week', function (assert) {
  25388. var i, m;
  25389. function makeFormat(d) {
  25390. switch (d.day()) {
  25391. case 0:
  25392. return '[v] [nedeljo] [ob] LT';
  25393. case 3:
  25394. return '[v] [sredo] [ob] LT';
  25395. case 6:
  25396. return '[v] [soboto] [ob] LT';
  25397. case 1:
  25398. case 2:
  25399. case 4:
  25400. case 5:
  25401. return '[v] dddd [ob] LT';
  25402. }
  25403. }
  25404. for (i = 2; i < 7; i++) {
  25405. m = moment().add({d: i});
  25406. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days current time');
  25407. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  25408. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days beginning of day');
  25409. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  25410. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days end of day');
  25411. }
  25412. });
  25413. test('calendar last week', function (assert) {
  25414. var i, m;
  25415. function makeFormat(d) {
  25416. switch (d.day()) {
  25417. case 0:
  25418. return '[prejšnjo] [nedeljo] [ob] LT';
  25419. case 3:
  25420. return '[prejšnjo] [sredo] [ob] LT';
  25421. case 6:
  25422. return '[prejšnjo] [soboto] [ob] LT';
  25423. case 1:
  25424. case 2:
  25425. case 4:
  25426. case 5:
  25427. return '[prejšnji] dddd [ob] LT';
  25428. }
  25429. }
  25430. for (i = 2; i < 7; i++) {
  25431. m = moment().subtract({d: i});
  25432. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days current time');
  25433. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  25434. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days beginning of day');
  25435. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  25436. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days end of day');
  25437. }
  25438. });
  25439. test('calendar all else', function (assert) {
  25440. var weeksAgo = moment().subtract({w: 1}),
  25441. weeksFromNow = moment().add({w: 1});
  25442. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  25443. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  25444. weeksAgo = moment().subtract({w: 2});
  25445. weeksFromNow = moment().add({w: 2});
  25446. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  25447. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  25448. });
  25449. test('weeks year starting sunday', function (assert) {
  25450. assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1');
  25451. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  25452. assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2');
  25453. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  25454. assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3');
  25455. });
  25456. test('weeks year starting monday', function (assert) {
  25457. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  25458. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  25459. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  25460. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  25461. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  25462. });
  25463. test('weeks year starting tuesday', function (assert) {
  25464. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  25465. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  25466. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  25467. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  25468. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  25469. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  25470. });
  25471. test('weeks year starting wednesday', function (assert) {
  25472. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  25473. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  25474. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  25475. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  25476. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  25477. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  25478. });
  25479. test('weeks year starting thursday', function (assert) {
  25480. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  25481. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  25482. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  25483. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  25484. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  25485. assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3');
  25486. });
  25487. test('weeks year starting friday', function (assert) {
  25488. assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1');
  25489. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  25490. assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1');
  25491. assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2');
  25492. assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2');
  25493. assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3');
  25494. });
  25495. test('weeks year starting saturday', function (assert) {
  25496. assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1');
  25497. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  25498. assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1');
  25499. assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2');
  25500. assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2');
  25501. assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3');
  25502. });
  25503. test('weeks year starting sunday formatted', function (assert) {
  25504. assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1.', 'Dec 26 2011 should be week 1');
  25505. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1.', 'Jan 1 2012 should be week 1');
  25506. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2.', 'Jan 2 2012 should be week 2');
  25507. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2.', 'Jan 8 2012 should be week 2');
  25508. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3.', 'Jan 9 2012 should be week 3');
  25509. });
  25510. test('lenient ordinal parsing', function (assert) {
  25511. var i, ordinalStr, testMoment;
  25512. for (i = 1; i <= 31; ++i) {
  25513. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  25514. testMoment = moment(ordinalStr, 'YYYY MM Do');
  25515. assert.equal(testMoment.year(), 2014,
  25516. 'lenient ordinal parsing ' + i + ' year check');
  25517. assert.equal(testMoment.month(), 0,
  25518. 'lenient ordinal parsing ' + i + ' month check');
  25519. assert.equal(testMoment.date(), i,
  25520. 'lenient ordinal parsing ' + i + ' date check');
  25521. }
  25522. });
  25523. test('lenient ordinal parsing of number', function (assert) {
  25524. var i, testMoment;
  25525. for (i = 1; i <= 31; ++i) {
  25526. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  25527. assert.equal(testMoment.year(), 2014,
  25528. 'lenient ordinal parsing of number ' + i + ' year check');
  25529. assert.equal(testMoment.month(), 0,
  25530. 'lenient ordinal parsing of number ' + i + ' month check');
  25531. assert.equal(testMoment.date(), i,
  25532. 'lenient ordinal parsing of number ' + i + ' date check');
  25533. }
  25534. });
  25535. test('strict ordinal parsing', function (assert) {
  25536. var i, ordinalStr, testMoment;
  25537. for (i = 1; i <= 31; ++i) {
  25538. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  25539. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  25540. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  25541. }
  25542. });
  25543. }));
  25544. ;(function (global, factory) {
  25545. typeof exports === 'object' && typeof module !== 'undefined'
  25546. && typeof require === 'function' ? factory(require('../../moment')) :
  25547. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  25548. factory(global.moment)
  25549. }(this, function (moment) { 'use strict';
  25550. /*global QUnit:false*/
  25551. var test = QUnit.test;
  25552. var expect = QUnit.expect;
  25553. function module (name, lifecycle) {
  25554. QUnit.module(name, {
  25555. setup : function () {
  25556. moment.locale('en');
  25557. moment.createFromInputFallback = function (config) {
  25558. throw new Error('input not handled by moment: ' + config._i);
  25559. };
  25560. if (lifecycle && lifecycle.setup) {
  25561. lifecycle.setup();
  25562. }
  25563. },
  25564. teardown : function () {
  25565. if (lifecycle && lifecycle.teardown) {
  25566. lifecycle.teardown();
  25567. }
  25568. }
  25569. });
  25570. }
  25571. function localeModule (name, lifecycle) {
  25572. QUnit.module('locale:' + name, {
  25573. setup : function () {
  25574. moment.locale(name);
  25575. moment.createFromInputFallback = function (config) {
  25576. throw new Error('input not handled by moment: ' + config._i);
  25577. };
  25578. if (lifecycle && lifecycle.setup) {
  25579. lifecycle.setup();
  25580. }
  25581. },
  25582. teardown : function () {
  25583. moment.locale('en');
  25584. if (lifecycle && lifecycle.teardown) {
  25585. lifecycle.teardown();
  25586. }
  25587. }
  25588. });
  25589. }
  25590. localeModule('sq');
  25591. test('parse', function (assert) {
  25592. var i,
  25593. tests = 'Janar Jan_Shkurt Shk_Mars Mar_Prill Pri_Maj Maj_Qershor Qer_Korrik Kor_Gusht Gus_Shtator Sht_Tetor Tet_Nëntor Nën_Dhjetor Dhj'.split('_');
  25594. function equalTest(input, mmm, i) {
  25595. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  25596. }
  25597. for (i = 0; i < 12; i++) {
  25598. tests[i] = tests[i].split(' ');
  25599. equalTest(tests[i][0], 'MMM', i);
  25600. equalTest(tests[i][1], 'MMM', i);
  25601. equalTest(tests[i][0], 'MMMM', i);
  25602. equalTest(tests[i][1], 'MMMM', i);
  25603. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  25604. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  25605. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  25606. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  25607. }
  25608. });
  25609. test('format', function (assert) {
  25610. var a = [
  25611. ['dddd, MMMM Do YYYY, HH:mm:ss', 'E Diel, Shkurt 14. 2010, 15:25:50'],
  25612. ['ddd, HH', 'Die, 15'],
  25613. ['M Mo MM MMMM MMM', '2 2. 02 Shkurt Shk'],
  25614. ['YYYY YY', '2010 10'],
  25615. ['D Do DD', '14 14. 14'],
  25616. ['d do dddd ddd dd', '0 0. E Diel Die D'],
  25617. ['DDD DDDo DDDD', '45 45. 045'],
  25618. ['w wo ww', '6 6. 06'],
  25619. ['h hh', '3 03'],
  25620. ['H HH', '15 15'],
  25621. ['m mm', '25 25'],
  25622. ['s ss', '50 50'],
  25623. ['a A', 'MD MD'],
  25624. ['[the] DDDo [day of the year]', 'the 45. day of the year'],
  25625. ['LTS', '15:25:50'],
  25626. ['L', '14/02/2010'],
  25627. ['LL', '14 Shkurt 2010'],
  25628. ['LLL', '14 Shkurt 2010 15:25'],
  25629. ['LLLL', 'E Diel, 14 Shkurt 2010 15:25'],
  25630. ['l', '14/2/2010'],
  25631. ['ll', '14 Shk 2010'],
  25632. ['lll', '14 Shk 2010 15:25'],
  25633. ['llll', 'Die, 14 Shk 2010 15:25']
  25634. ],
  25635. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  25636. i;
  25637. for (i = 0; i < a.length; i++) {
  25638. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  25639. }
  25640. });
  25641. test('meridiem', function (assert) {
  25642. assert.equal(moment([2011, 2, 23, 0, 0]).format('A'), 'PD', 'before dawn');
  25643. assert.equal(moment([2011, 2, 23, 12, 0]).format('A'), 'MD', 'noon');
  25644. });
  25645. test('format ordinal', function (assert) {
  25646. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
  25647. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
  25648. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
  25649. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
  25650. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
  25651. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
  25652. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
  25653. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
  25654. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
  25655. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
  25656. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
  25657. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
  25658. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
  25659. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
  25660. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
  25661. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
  25662. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
  25663. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
  25664. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
  25665. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
  25666. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
  25667. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
  25668. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
  25669. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
  25670. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
  25671. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
  25672. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
  25673. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
  25674. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
  25675. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
  25676. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
  25677. });
  25678. test('format month', function (assert) {
  25679. var i,
  25680. expected = 'Janar Jan_Shkurt Shk_Mars Mar_Prill Pri_Maj Maj_Qershor Qer_Korrik Kor_Gusht Gus_Shtator Sht_Tetor Tet_Nëntor Nën_Dhjetor Dhj'.split('_');
  25681. for (i = 0; i < expected.length; i++) {
  25682. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  25683. }
  25684. });
  25685. test('format week', function (assert) {
  25686. var i,
  25687. expected = 'E Diel Die D_E Hënë Hën H_E Martë Mar Ma_E Mërkurë Mër Më_E Enjte Enj E_E Premte Pre P_E Shtunë Sht Sh'.split('_');
  25688. for (i = 0; i < expected.length; i++) {
  25689. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  25690. }
  25691. });
  25692. test('from', function (assert) {
  25693. var start = moment([2007, 1, 28]);
  25694. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'disa sekonda', '44 seconds = a few seconds');
  25695. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'një minutë', '45 seconds = a minute');
  25696. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'një minutë', '89 seconds = a minute');
  25697. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuta', '90 seconds = 2 minutes');
  25698. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuta', '44 minutes = 44 minutes');
  25699. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'një orë', '45 minutes = an hour');
  25700. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'një orë', '89 minutes = an hour');
  25701. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 orë', '90 minutes = 2 hours');
  25702. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 orë', '5 hours = 5 hours');
  25703. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 orë', '21 hours = 21 hours');
  25704. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'një ditë', '22 hours = a day');
  25705. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'një ditë', '35 hours = a day');
  25706. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 ditë', '36 hours = 2 days');
  25707. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'një ditë', '1 day = a day');
  25708. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 ditë', '5 days = 5 days');
  25709. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 ditë', '25 days = 25 days');
  25710. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'një muaj', '26 days = a month');
  25711. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'një muaj', '30 days = a month');
  25712. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'një muaj', '43 days = a month');
  25713. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 muaj', '46 days = 2 months');
  25714. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 muaj', '75 days = 2 months');
  25715. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 muaj', '76 days = 3 months');
  25716. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'një muaj', '1 month = a month');
  25717. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 muaj', '5 months = 5 months');
  25718. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'një vit', '345 days = a year');
  25719. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 vite', '548 days = 2 years');
  25720. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'një vit', '1 year = a year');
  25721. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 vite', '5 years = 5 years');
  25722. });
  25723. test('suffix', function (assert) {
  25724. assert.equal(moment(30000).from(0), 'në disa sekonda', 'prefix');
  25725. assert.equal(moment(0).from(30000), 'disa sekonda më parë', 'suffix');
  25726. });
  25727. test('now from now', function (assert) {
  25728. assert.equal(moment().fromNow(), 'disa sekonda më parë', 'now from now should display as in the past');
  25729. });
  25730. test('fromNow', function (assert) {
  25731. assert.equal(moment().add({s: 30}).fromNow(), 'në disa sekonda', 'in a few seconds');
  25732. assert.equal(moment().add({d: 5}).fromNow(), 'në 5 ditë', 'in 5 days');
  25733. });
  25734. test('calendar day', function (assert) {
  25735. var a = moment().hours(2).minutes(0).seconds(0);
  25736. assert.equal(moment(a).calendar(), 'Sot në 02:00', 'today at the same time');
  25737. assert.equal(moment(a).add({m: 25}).calendar(), 'Sot në 02:25', 'Now plus 25 min');
  25738. assert.equal(moment(a).add({h: 1}).calendar(), 'Sot në 03:00', 'Now plus 1 hour');
  25739. assert.equal(moment(a).add({d: 1}).calendar(), 'Nesër në 02:00', 'tomorrow at the same time');
  25740. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Sot në 01:00', 'Now minus 1 hour');
  25741. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Dje në 02:00', 'yesterday at the same time');
  25742. });
  25743. test('calendar next week', function (assert) {
  25744. var i, m;
  25745. for (i = 2; i < 7; i++) {
  25746. m = moment().add({d: i});
  25747. assert.equal(m.calendar(), m.format('dddd [në] LT'), 'Today + ' + i + ' days current time');
  25748. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  25749. assert.equal(m.calendar(), m.format('dddd [në] LT'), 'Today + ' + i + ' days beginning of day');
  25750. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  25751. assert.equal(m.calendar(), m.format('dddd [në] LT'), 'Today + ' + i + ' days end of day');
  25752. }
  25753. });
  25754. test('calendar last week', function (assert) {
  25755. var i, m;
  25756. for (i = 2; i < 7; i++) {
  25757. m = moment().subtract({d: i});
  25758. assert.equal(m.calendar(), m.format('dddd [e kaluar në] LT'), 'Today - ' + i + ' days current time');
  25759. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  25760. assert.equal(m.calendar(), m.format('dddd [e kaluar në] LT'), 'Today - ' + i + ' days beginning of day');
  25761. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  25762. assert.equal(m.calendar(), m.format('dddd [e kaluar në] LT'), 'Today - ' + i + ' days end of day');
  25763. }
  25764. });
  25765. test('calendar all else', function (assert) {
  25766. var weeksAgo = moment().subtract({w: 1}),
  25767. weeksFromNow = moment().add({w: 1});
  25768. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  25769. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  25770. weeksAgo = moment().subtract({w: 2});
  25771. weeksFromNow = moment().add({w: 2});
  25772. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  25773. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  25774. });
  25775. test('weeks year starting sunday', function (assert) {
  25776. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  25777. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  25778. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  25779. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  25780. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  25781. });
  25782. test('weeks year starting monday', function (assert) {
  25783. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  25784. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  25785. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  25786. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  25787. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  25788. });
  25789. test('weeks year starting tuesday', function (assert) {
  25790. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  25791. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  25792. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  25793. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  25794. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  25795. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  25796. });
  25797. test('weeks year starting wednesday', function (assert) {
  25798. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  25799. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  25800. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  25801. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  25802. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  25803. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  25804. });
  25805. test('weeks year starting thursday', function (assert) {
  25806. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  25807. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  25808. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  25809. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  25810. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  25811. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  25812. });
  25813. test('weeks year starting friday', function (assert) {
  25814. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  25815. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  25816. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  25817. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  25818. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  25819. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  25820. });
  25821. test('weeks year starting saturday', function (assert) {
  25822. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  25823. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  25824. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  25825. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  25826. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  25827. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  25828. });
  25829. test('weeks year starting sunday formatted', function (assert) {
  25830. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
  25831. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
  25832. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
  25833. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
  25834. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
  25835. });
  25836. test('lenient ordinal parsing', function (assert) {
  25837. var i, ordinalStr, testMoment;
  25838. for (i = 1; i <= 31; ++i) {
  25839. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  25840. testMoment = moment(ordinalStr, 'YYYY MM Do');
  25841. assert.equal(testMoment.year(), 2014,
  25842. 'lenient ordinal parsing ' + i + ' year check');
  25843. assert.equal(testMoment.month(), 0,
  25844. 'lenient ordinal parsing ' + i + ' month check');
  25845. assert.equal(testMoment.date(), i,
  25846. 'lenient ordinal parsing ' + i + ' date check');
  25847. }
  25848. });
  25849. test('lenient ordinal parsing of number', function (assert) {
  25850. var i, testMoment;
  25851. for (i = 1; i <= 31; ++i) {
  25852. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  25853. assert.equal(testMoment.year(), 2014,
  25854. 'lenient ordinal parsing of number ' + i + ' year check');
  25855. assert.equal(testMoment.month(), 0,
  25856. 'lenient ordinal parsing of number ' + i + ' month check');
  25857. assert.equal(testMoment.date(), i,
  25858. 'lenient ordinal parsing of number ' + i + ' date check');
  25859. }
  25860. });
  25861. test('strict ordinal parsing', function (assert) {
  25862. var i, ordinalStr, testMoment;
  25863. for (i = 1; i <= 31; ++i) {
  25864. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  25865. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  25866. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  25867. }
  25868. });
  25869. }));
  25870. ;(function (global, factory) {
  25871. typeof exports === 'object' && typeof module !== 'undefined'
  25872. && typeof require === 'function' ? factory(require('../../moment')) :
  25873. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  25874. factory(global.moment)
  25875. }(this, function (moment) { 'use strict';
  25876. /*global QUnit:false*/
  25877. var test = QUnit.test;
  25878. var expect = QUnit.expect;
  25879. function module (name, lifecycle) {
  25880. QUnit.module(name, {
  25881. setup : function () {
  25882. moment.locale('en');
  25883. moment.createFromInputFallback = function (config) {
  25884. throw new Error('input not handled by moment: ' + config._i);
  25885. };
  25886. if (lifecycle && lifecycle.setup) {
  25887. lifecycle.setup();
  25888. }
  25889. },
  25890. teardown : function () {
  25891. if (lifecycle && lifecycle.teardown) {
  25892. lifecycle.teardown();
  25893. }
  25894. }
  25895. });
  25896. }
  25897. function localeModule (name, lifecycle) {
  25898. QUnit.module('locale:' + name, {
  25899. setup : function () {
  25900. moment.locale(name);
  25901. moment.createFromInputFallback = function (config) {
  25902. throw new Error('input not handled by moment: ' + config._i);
  25903. };
  25904. if (lifecycle && lifecycle.setup) {
  25905. lifecycle.setup();
  25906. }
  25907. },
  25908. teardown : function () {
  25909. moment.locale('en');
  25910. if (lifecycle && lifecycle.teardown) {
  25911. lifecycle.teardown();
  25912. }
  25913. }
  25914. });
  25915. }
  25916. localeModule('sr-cyrl');
  25917. test('parse', function (assert) {
  25918. var tests = 'јануар јан._фебруар феб._март мар._април апр._мај мај_јун јун_јул јул_август авг._септембар сеп._октобар окт._новембар нов._децембар дец.'.split('_'),
  25919. i;
  25920. function equalTest(input, mmm, i) {
  25921. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  25922. }
  25923. for (i = 0; i < 12; i++) {
  25924. tests[i] = tests[i].split(' ');
  25925. equalTest(tests[i][0], 'MMM', i);
  25926. equalTest(tests[i][1], 'MMM', i);
  25927. equalTest(tests[i][0], 'MMMM', i);
  25928. equalTest(tests[i][1], 'MMMM', i);
  25929. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  25930. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  25931. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  25932. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  25933. }
  25934. });
  25935. test('format', function (assert) {
  25936. var a = [
  25937. ['dddd, Do MMMM YYYY, h:mm:ss a', 'недеља, 14. фебруар 2010, 3:25:50 pm'],
  25938. ['ddd, hA', 'нед., 3PM'],
  25939. ['M Mo MM MMMM MMM', '2 2. 02 фебруар феб.'],
  25940. ['YYYY YY', '2010 10'],
  25941. ['D Do DD', '14 14. 14'],
  25942. ['d do dddd ddd dd', '0 0. недеља нед. не'],
  25943. ['DDD DDDo DDDD', '45 45. 045'],
  25944. ['w wo ww', '7 7. 07'],
  25945. ['h hh', '3 03'],
  25946. ['H HH', '15 15'],
  25947. ['m mm', '25 25'],
  25948. ['s ss', '50 50'],
  25949. ['a A', 'pm PM'],
  25950. ['[the] DDDo [day of the year]', 'the 45. day of the year'],
  25951. ['LTS', '15:25:50'],
  25952. ['L', '14. 02. 2010'],
  25953. ['LL', '14. фебруар 2010'],
  25954. ['LLL', '14. фебруар 2010 15:25'],
  25955. ['LLLL', 'недеља, 14. фебруар 2010 15:25'],
  25956. ['l', '14. 2. 2010'],
  25957. ['ll', '14. феб. 2010'],
  25958. ['lll', '14. феб. 2010 15:25'],
  25959. ['llll', 'нед., 14. феб. 2010 15:25']
  25960. ],
  25961. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  25962. i;
  25963. for (i = 0; i < a.length; i++) {
  25964. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  25965. }
  25966. });
  25967. test('format ordinal', function (assert) {
  25968. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
  25969. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
  25970. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
  25971. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
  25972. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
  25973. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
  25974. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
  25975. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
  25976. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
  25977. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
  25978. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
  25979. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
  25980. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
  25981. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
  25982. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
  25983. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
  25984. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
  25985. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
  25986. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
  25987. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
  25988. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
  25989. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
  25990. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
  25991. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
  25992. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
  25993. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
  25994. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
  25995. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
  25996. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
  25997. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
  25998. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
  25999. });
  26000. test('format month', function (assert) {
  26001. var expected = 'јануар јан._фебруар феб._март мар._април апр._мај мај_јун јун_јул јул_август авг._септембар сеп._октобар окт._новембар нов._децембар дец.'.split('_'),
  26002. i;
  26003. for (i = 0; i < expected.length; i++) {
  26004. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  26005. }
  26006. });
  26007. test('format week', function (assert) {
  26008. var expected = 'недеља нед. не_понедељак пон. по_уторак уто. ут_среда сре. ср_четвртак чет. че_петак пет. пе_субота суб. су'.split('_'),
  26009. i;
  26010. for (i = 0; i < expected.length; i++) {
  26011. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  26012. }
  26013. });
  26014. test('from', function (assert) {
  26015. var start = moment([2007, 1, 28]);
  26016. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'неколико секунди', '44 seconds = a few seconds');
  26017. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'један минут', '45 seconds = a minute');
  26018. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'један минут', '89 seconds = a minute');
  26019. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 минуте', '90 seconds = 2 minutes');
  26020. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 минута', '44 minutes = 44 minutes');
  26021. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'један сат', '45 minutes = an hour');
  26022. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'један сат', '89 minutes = an hour');
  26023. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 сата', '90 minutes = 2 hours');
  26024. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 сати', '5 hours = 5 hours');
  26025. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 сати', '21 hours = 21 hours');
  26026. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'дан', '22 hours = a day');
  26027. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'дан', '35 hours = a day');
  26028. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 дана', '36 hours = 2 days');
  26029. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'дан', '1 day = a day');
  26030. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 дана', '5 days = 5 days');
  26031. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 дана', '25 days = 25 days');
  26032. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'месец', '26 days = a month');
  26033. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'месец', '30 days = a month');
  26034. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'месец', '43 days = a month');
  26035. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 месеца', '46 days = 2 months');
  26036. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 месеца', '75 days = 2 months');
  26037. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 месеца', '76 days = 3 months');
  26038. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'месец', '1 month = a month');
  26039. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 месеци', '5 months = 5 months');
  26040. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'годину', '345 days = a year');
  26041. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 године', '548 days = 2 years');
  26042. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'годину', '1 year = a year');
  26043. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 година', '5 years = 5 years');
  26044. });
  26045. test('suffix', function (assert) {
  26046. assert.equal(moment(30000).from(0), 'за неколико секунди', 'prefix');
  26047. assert.equal(moment(0).from(30000), 'пре неколико секунди', 'prefix');
  26048. });
  26049. test('now from now', function (assert) {
  26050. assert.equal(moment().fromNow(), 'пре неколико секунди', 'now from now should display as in the past');
  26051. });
  26052. test('fromNow', function (assert) {
  26053. assert.equal(moment().add({s: 30}).fromNow(), 'за неколико секунди', 'in a few seconds');
  26054. assert.equal(moment().add({d: 5}).fromNow(), 'за 5 дана', 'in 5 days');
  26055. });
  26056. test('calendar day', function (assert) {
  26057. var a = moment().hours(2).minutes(0).seconds(0);
  26058. assert.equal(moment(a).calendar(), 'данас у 2:00', 'today at the same time');
  26059. assert.equal(moment(a).add({m: 25}).calendar(), 'данас у 2:25', 'Now plus 25 min');
  26060. assert.equal(moment(a).add({h: 1}).calendar(), 'данас у 3:00', 'Now plus 1 hour');
  26061. assert.equal(moment(a).add({d: 1}).calendar(), 'сутра у 2:00', 'tomorrow at the same time');
  26062. assert.equal(moment(a).subtract({h: 1}).calendar(), 'данас у 1:00', 'Now minus 1 hour');
  26063. assert.equal(moment(a).subtract({d: 1}).calendar(), 'јуче у 2:00', 'yesterday at the same time');
  26064. });
  26065. test('calendar next week', function (assert) {
  26066. var i, m;
  26067. function makeFormat(d) {
  26068. switch (d.day()) {
  26069. case 0:
  26070. return '[у] [недељу] [у] LT';
  26071. case 3:
  26072. return '[у] [среду] [у] LT';
  26073. case 6:
  26074. return '[у] [суботу] [у] LT';
  26075. case 1:
  26076. case 2:
  26077. case 4:
  26078. case 5:
  26079. return '[у] dddd [у] LT';
  26080. }
  26081. }
  26082. for (i = 2; i < 7; i++) {
  26083. m = moment().add({d: i});
  26084. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days current time');
  26085. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  26086. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days beginning of day');
  26087. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  26088. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days end of day');
  26089. }
  26090. });
  26091. test('calendar last week', function (assert) {
  26092. var i, m;
  26093. function makeFormat(d) {
  26094. var lastWeekDay = [
  26095. '[прошле] [недеље] [у] LT',
  26096. '[прошлог] [понедељка] [у] LT',
  26097. '[прошлог] [уторка] [у] LT',
  26098. '[прошле] [среде] [у] LT',
  26099. '[прошлог] [четвртка] [у] LT',
  26100. '[прошлог] [петка] [у] LT',
  26101. '[прошле] [суботе] [у] LT'
  26102. ];
  26103. return lastWeekDay[d.day()];
  26104. }
  26105. for (i = 2; i < 7; i++) {
  26106. m = moment().subtract({d: i});
  26107. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days current time');
  26108. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  26109. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days beginning of day');
  26110. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  26111. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days end of day');
  26112. }
  26113. });
  26114. test('calendar all else', function (assert) {
  26115. var weeksAgo = moment().subtract({w: 1}),
  26116. weeksFromNow = moment().add({w: 1});
  26117. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  26118. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  26119. weeksAgo = moment().subtract({w: 2});
  26120. weeksFromNow = moment().add({w: 2});
  26121. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  26122. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  26123. });
  26124. test('weeks year starting sunday', function (assert) {
  26125. assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1');
  26126. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  26127. assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2');
  26128. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  26129. assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3');
  26130. });
  26131. test('weeks year starting monday', function (assert) {
  26132. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  26133. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  26134. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  26135. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  26136. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  26137. });
  26138. test('weeks year starting tuesday', function (assert) {
  26139. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  26140. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  26141. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  26142. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  26143. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  26144. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  26145. });
  26146. test('weeks year starting wednesday', function (assert) {
  26147. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  26148. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  26149. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  26150. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  26151. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  26152. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  26153. });
  26154. test('weeks year starting thursday', function (assert) {
  26155. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  26156. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  26157. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  26158. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  26159. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  26160. assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3');
  26161. });
  26162. test('weeks year starting friday', function (assert) {
  26163. assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1');
  26164. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  26165. assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1');
  26166. assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2');
  26167. assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2');
  26168. assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3');
  26169. });
  26170. test('weeks year starting saturday', function (assert) {
  26171. assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1');
  26172. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  26173. assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1');
  26174. assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2');
  26175. assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2');
  26176. assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3');
  26177. });
  26178. test('weeks year starting sunday formatted', function (assert) {
  26179. assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1.', 'Dec 26 2011 should be week 1');
  26180. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1.', 'Jan 1 2012 should be week 1');
  26181. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2.', 'Jan 2 2012 should be week 2');
  26182. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2.', 'Jan 8 2012 should be week 2');
  26183. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3.', 'Jan 9 2012 should be week 3');
  26184. });
  26185. test('lenient ordinal parsing', function (assert) {
  26186. var i, ordinalStr, testMoment;
  26187. for (i = 1; i <= 31; ++i) {
  26188. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  26189. testMoment = moment(ordinalStr, 'YYYY MM Do');
  26190. assert.equal(testMoment.year(), 2014,
  26191. 'lenient ordinal parsing ' + i + ' year check');
  26192. assert.equal(testMoment.month(), 0,
  26193. 'lenient ordinal parsing ' + i + ' month check');
  26194. assert.equal(testMoment.date(), i,
  26195. 'lenient ordinal parsing ' + i + ' date check');
  26196. }
  26197. });
  26198. test('lenient ordinal parsing of number', function (assert) {
  26199. var i, testMoment;
  26200. for (i = 1; i <= 31; ++i) {
  26201. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  26202. assert.equal(testMoment.year(), 2014,
  26203. 'lenient ordinal parsing of number ' + i + ' year check');
  26204. assert.equal(testMoment.month(), 0,
  26205. 'lenient ordinal parsing of number ' + i + ' month check');
  26206. assert.equal(testMoment.date(), i,
  26207. 'lenient ordinal parsing of number ' + i + ' date check');
  26208. }
  26209. });
  26210. test('strict ordinal parsing', function (assert) {
  26211. var i, ordinalStr, testMoment;
  26212. for (i = 1; i <= 31; ++i) {
  26213. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  26214. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  26215. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  26216. }
  26217. });
  26218. }));
  26219. ;(function (global, factory) {
  26220. typeof exports === 'object' && typeof module !== 'undefined'
  26221. && typeof require === 'function' ? factory(require('../../moment')) :
  26222. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  26223. factory(global.moment)
  26224. }(this, function (moment) { 'use strict';
  26225. /*global QUnit:false*/
  26226. var test = QUnit.test;
  26227. var expect = QUnit.expect;
  26228. function module (name, lifecycle) {
  26229. QUnit.module(name, {
  26230. setup : function () {
  26231. moment.locale('en');
  26232. moment.createFromInputFallback = function (config) {
  26233. throw new Error('input not handled by moment: ' + config._i);
  26234. };
  26235. if (lifecycle && lifecycle.setup) {
  26236. lifecycle.setup();
  26237. }
  26238. },
  26239. teardown : function () {
  26240. if (lifecycle && lifecycle.teardown) {
  26241. lifecycle.teardown();
  26242. }
  26243. }
  26244. });
  26245. }
  26246. function localeModule (name, lifecycle) {
  26247. QUnit.module('locale:' + name, {
  26248. setup : function () {
  26249. moment.locale(name);
  26250. moment.createFromInputFallback = function (config) {
  26251. throw new Error('input not handled by moment: ' + config._i);
  26252. };
  26253. if (lifecycle && lifecycle.setup) {
  26254. lifecycle.setup();
  26255. }
  26256. },
  26257. teardown : function () {
  26258. moment.locale('en');
  26259. if (lifecycle && lifecycle.teardown) {
  26260. lifecycle.teardown();
  26261. }
  26262. }
  26263. });
  26264. }
  26265. localeModule('sr');
  26266. test('parse', function (assert) {
  26267. var tests = 'januar jan._februar feb._mart mar._april apr._maj maj_jun jun_jul jul_avgust avg._septembar sep._oktobar okt._novembar nov._decembar dec.'.split('_'),
  26268. i;
  26269. function equalTest(input, mmm, i) {
  26270. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  26271. }
  26272. for (i = 0; i < 12; i++) {
  26273. tests[i] = tests[i].split(' ');
  26274. equalTest(tests[i][0], 'MMM', i);
  26275. equalTest(tests[i][1], 'MMM', i);
  26276. equalTest(tests[i][0], 'MMMM', i);
  26277. equalTest(tests[i][1], 'MMMM', i);
  26278. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  26279. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  26280. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  26281. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  26282. }
  26283. });
  26284. test('format', function (assert) {
  26285. var a = [
  26286. ['dddd, Do MMMM YYYY, h:mm:ss a', 'nedelja, 14. februar 2010, 3:25:50 pm'],
  26287. ['ddd, hA', 'ned., 3PM'],
  26288. ['M Mo MM MMMM MMM', '2 2. 02 februar feb.'],
  26289. ['YYYY YY', '2010 10'],
  26290. ['D Do DD', '14 14. 14'],
  26291. ['d do dddd ddd dd', '0 0. nedelja ned. ne'],
  26292. ['DDD DDDo DDDD', '45 45. 045'],
  26293. ['w wo ww', '7 7. 07'],
  26294. ['h hh', '3 03'],
  26295. ['H HH', '15 15'],
  26296. ['m mm', '25 25'],
  26297. ['s ss', '50 50'],
  26298. ['a A', 'pm PM'],
  26299. ['[the] DDDo [day of the year]', 'the 45. day of the year'],
  26300. ['LTS', '15:25:50'],
  26301. ['L', '14. 02. 2010'],
  26302. ['LL', '14. februar 2010'],
  26303. ['LLL', '14. februar 2010 15:25'],
  26304. ['LLLL', 'nedelja, 14. februar 2010 15:25'],
  26305. ['l', '14. 2. 2010'],
  26306. ['ll', '14. feb. 2010'],
  26307. ['lll', '14. feb. 2010 15:25'],
  26308. ['llll', 'ned., 14. feb. 2010 15:25']
  26309. ],
  26310. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  26311. i;
  26312. for (i = 0; i < a.length; i++) {
  26313. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  26314. }
  26315. });
  26316. test('format ordinal', function (assert) {
  26317. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
  26318. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
  26319. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
  26320. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
  26321. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
  26322. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
  26323. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
  26324. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
  26325. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
  26326. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
  26327. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
  26328. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
  26329. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
  26330. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
  26331. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
  26332. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
  26333. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
  26334. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
  26335. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
  26336. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
  26337. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
  26338. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
  26339. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
  26340. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
  26341. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
  26342. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
  26343. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
  26344. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
  26345. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
  26346. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
  26347. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
  26348. });
  26349. test('format month', function (assert) {
  26350. var expected = 'januar jan._februar feb._mart mar._april apr._maj maj_jun jun_jul jul_avgust avg._septembar sep._oktobar okt._novembar nov._decembar dec.'.split('_'),
  26351. i;
  26352. for (i = 0; i < expected.length; i++) {
  26353. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  26354. }
  26355. });
  26356. test('format week', function (assert) {
  26357. var expected = 'nedelja ned. ne_ponedeljak pon. po_utorak uto. ut_sreda sre. sr_četvrtak čet. če_petak pet. pe_subota sub. su'.split('_'),
  26358. i;
  26359. for (i = 0; i < expected.length; i++) {
  26360. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  26361. }
  26362. });
  26363. test('from', function (assert) {
  26364. var start = moment([2007, 1, 28]);
  26365. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'nekoliko sekundi', '44 seconds = a few seconds');
  26366. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'jedan minut', '45 seconds = a minute');
  26367. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'jedan minut', '89 seconds = a minute');
  26368. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minute', '90 seconds = 2 minutes');
  26369. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuta', '44 minutes = 44 minutes');
  26370. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'jedan sat', '45 minutes = an hour');
  26371. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'jedan sat', '89 minutes = an hour');
  26372. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 sata', '90 minutes = 2 hours');
  26373. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 sati', '5 hours = 5 hours');
  26374. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 sati', '21 hours = 21 hours');
  26375. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'dan', '22 hours = a day');
  26376. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'dan', '35 hours = a day');
  26377. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dana', '36 hours = 2 days');
  26378. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'dan', '1 day = a day');
  26379. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dana', '5 days = 5 days');
  26380. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dana', '25 days = 25 days');
  26381. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'mesec', '26 days = a month');
  26382. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'mesec', '30 days = a month');
  26383. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'mesec', '43 days = a month');
  26384. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 meseca', '46 days = 2 months');
  26385. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 meseca', '75 days = 2 months');
  26386. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 meseca', '76 days = 3 months');
  26387. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'mesec', '1 month = a month');
  26388. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 meseci', '5 months = 5 months');
  26389. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'godinu', '345 days = a year');
  26390. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 godine', '548 days = 2 years');
  26391. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'godinu', '1 year = a year');
  26392. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 godina', '5 years = 5 years');
  26393. });
  26394. test('suffix', function (assert) {
  26395. assert.equal(moment(30000).from(0), 'za nekoliko sekundi', 'prefix');
  26396. assert.equal(moment(0).from(30000), 'pre nekoliko sekundi', 'prefix');
  26397. });
  26398. test('now from now', function (assert) {
  26399. assert.equal(moment().fromNow(), 'pre nekoliko sekundi', 'now from now should display as in the past');
  26400. });
  26401. test('fromNow', function (assert) {
  26402. assert.equal(moment().add({s: 30}).fromNow(), 'za nekoliko sekundi', 'in a few seconds');
  26403. assert.equal(moment().add({d: 5}).fromNow(), 'za 5 dana', 'in 5 days');
  26404. });
  26405. test('calendar day', function (assert) {
  26406. var a = moment().hours(2).minutes(0).seconds(0);
  26407. assert.equal(moment(a).calendar(), 'danas u 2:00', 'today at the same time');
  26408. assert.equal(moment(a).add({m: 25}).calendar(), 'danas u 2:25', 'Now plus 25 min');
  26409. assert.equal(moment(a).add({h: 1}).calendar(), 'danas u 3:00', 'Now plus 1 hour');
  26410. assert.equal(moment(a).add({d: 1}).calendar(), 'sutra u 2:00', 'tomorrow at the same time');
  26411. assert.equal(moment(a).subtract({h: 1}).calendar(), 'danas u 1:00', 'Now minus 1 hour');
  26412. assert.equal(moment(a).subtract({d: 1}).calendar(), 'juče u 2:00', 'yesterday at the same time');
  26413. });
  26414. test('calendar next week', function (assert) {
  26415. var i, m;
  26416. function makeFormat(d) {
  26417. switch (d.day()) {
  26418. case 0:
  26419. return '[u] [nedelju] [u] LT';
  26420. case 3:
  26421. return '[u] [sredu] [u] LT';
  26422. case 6:
  26423. return '[u] [subotu] [u] LT';
  26424. case 1:
  26425. case 2:
  26426. case 4:
  26427. case 5:
  26428. return '[u] dddd [u] LT';
  26429. }
  26430. }
  26431. for (i = 2; i < 7; i++) {
  26432. m = moment().add({d: i});
  26433. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days current time');
  26434. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  26435. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days beginning of day');
  26436. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  26437. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days end of day');
  26438. }
  26439. });
  26440. test('calendar last week', function (assert) {
  26441. var i, m;
  26442. function makeFormat(d) {
  26443. var lastWeekDay = [
  26444. '[prošle] [nedelje] [u] LT',
  26445. '[prošlog] [ponedeljka] [u] LT',
  26446. '[prošlog] [utorka] [u] LT',
  26447. '[prošle] [srede] [u] LT',
  26448. '[prošlog] [četvrtka] [u] LT',
  26449. '[prošlog] [petka] [u] LT',
  26450. '[prošle] [subote] [u] LT'
  26451. ];
  26452. return lastWeekDay[d.day()];
  26453. }
  26454. for (i = 2; i < 7; i++) {
  26455. m = moment().subtract({d: i});
  26456. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days current time');
  26457. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  26458. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days beginning of day');
  26459. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  26460. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days end of day');
  26461. }
  26462. });
  26463. test('calendar all else', function (assert) {
  26464. var weeksAgo = moment().subtract({w: 1}),
  26465. weeksFromNow = moment().add({w: 1});
  26466. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  26467. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  26468. weeksAgo = moment().subtract({w: 2});
  26469. weeksFromNow = moment().add({w: 2});
  26470. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  26471. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  26472. });
  26473. test('weeks year starting sunday', function (assert) {
  26474. assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1');
  26475. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  26476. assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2');
  26477. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  26478. assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3');
  26479. });
  26480. test('weeks year starting monday', function (assert) {
  26481. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  26482. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  26483. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  26484. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  26485. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  26486. });
  26487. test('weeks year starting tuesday', function (assert) {
  26488. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  26489. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  26490. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  26491. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  26492. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  26493. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  26494. });
  26495. test('weeks year starting wednesday', function (assert) {
  26496. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  26497. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  26498. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  26499. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  26500. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  26501. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  26502. });
  26503. test('weeks year starting thursday', function (assert) {
  26504. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  26505. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  26506. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  26507. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  26508. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  26509. assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3');
  26510. });
  26511. test('weeks year starting friday', function (assert) {
  26512. assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1');
  26513. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  26514. assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1');
  26515. assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2');
  26516. assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2');
  26517. assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3');
  26518. });
  26519. test('weeks year starting saturday', function (assert) {
  26520. assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1');
  26521. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  26522. assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1');
  26523. assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2');
  26524. assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2');
  26525. assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3');
  26526. });
  26527. test('weeks year starting sunday formatted', function (assert) {
  26528. assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1.', 'Dec 26 2011 should be week 1');
  26529. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1.', 'Jan 1 2012 should be week 1');
  26530. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2.', 'Jan 2 2012 should be week 2');
  26531. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2.', 'Jan 8 2012 should be week 2');
  26532. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3.', 'Jan 9 2012 should be week 3');
  26533. });
  26534. test('lenient ordinal parsing', function (assert) {
  26535. var i, ordinalStr, testMoment;
  26536. for (i = 1; i <= 31; ++i) {
  26537. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  26538. testMoment = moment(ordinalStr, 'YYYY MM Do');
  26539. assert.equal(testMoment.year(), 2014,
  26540. 'lenient ordinal parsing ' + i + ' year check');
  26541. assert.equal(testMoment.month(), 0,
  26542. 'lenient ordinal parsing ' + i + ' month check');
  26543. assert.equal(testMoment.date(), i,
  26544. 'lenient ordinal parsing ' + i + ' date check');
  26545. }
  26546. });
  26547. test('lenient ordinal parsing of number', function (assert) {
  26548. var i, testMoment;
  26549. for (i = 1; i <= 31; ++i) {
  26550. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  26551. assert.equal(testMoment.year(), 2014,
  26552. 'lenient ordinal parsing of number ' + i + ' year check');
  26553. assert.equal(testMoment.month(), 0,
  26554. 'lenient ordinal parsing of number ' + i + ' month check');
  26555. assert.equal(testMoment.date(), i,
  26556. 'lenient ordinal parsing of number ' + i + ' date check');
  26557. }
  26558. });
  26559. test('strict ordinal parsing', function (assert) {
  26560. var i, ordinalStr, testMoment;
  26561. for (i = 1; i <= 31; ++i) {
  26562. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  26563. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  26564. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  26565. }
  26566. });
  26567. }));
  26568. ;(function (global, factory) {
  26569. typeof exports === 'object' && typeof module !== 'undefined'
  26570. && typeof require === 'function' ? factory(require('../../moment')) :
  26571. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  26572. factory(global.moment)
  26573. }(this, function (moment) { 'use strict';
  26574. /*global QUnit:false*/
  26575. var test = QUnit.test;
  26576. var expect = QUnit.expect;
  26577. function module (name, lifecycle) {
  26578. QUnit.module(name, {
  26579. setup : function () {
  26580. moment.locale('en');
  26581. moment.createFromInputFallback = function (config) {
  26582. throw new Error('input not handled by moment: ' + config._i);
  26583. };
  26584. if (lifecycle && lifecycle.setup) {
  26585. lifecycle.setup();
  26586. }
  26587. },
  26588. teardown : function () {
  26589. if (lifecycle && lifecycle.teardown) {
  26590. lifecycle.teardown();
  26591. }
  26592. }
  26593. });
  26594. }
  26595. function localeModule (name, lifecycle) {
  26596. QUnit.module('locale:' + name, {
  26597. setup : function () {
  26598. moment.locale(name);
  26599. moment.createFromInputFallback = function (config) {
  26600. throw new Error('input not handled by moment: ' + config._i);
  26601. };
  26602. if (lifecycle && lifecycle.setup) {
  26603. lifecycle.setup();
  26604. }
  26605. },
  26606. teardown : function () {
  26607. moment.locale('en');
  26608. if (lifecycle && lifecycle.teardown) {
  26609. lifecycle.teardown();
  26610. }
  26611. }
  26612. });
  26613. }
  26614. localeModule('sv');
  26615. test('parse', function (assert) {
  26616. var tests = 'januari jan_februari feb_mars mar_april apr_maj maj_juni jun_juli jul_augusti aug_september sep_oktober okt_november nov_december dec'.split('_'), i;
  26617. function equalTest(input, mmm, i) {
  26618. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  26619. }
  26620. for (i = 0; i < 12; i++) {
  26621. tests[i] = tests[i].split(' ');
  26622. equalTest(tests[i][0], 'MMM', i);
  26623. equalTest(tests[i][1], 'MMM', i);
  26624. equalTest(tests[i][0], 'MMMM', i);
  26625. equalTest(tests[i][1], 'MMMM', i);
  26626. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  26627. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  26628. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  26629. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  26630. }
  26631. });
  26632. test('format', function (assert) {
  26633. var a = [
  26634. ['dddd, MMMM Do YYYY, h:mm:ss a', 'söndag, februari 14e 2010, 3:25:50 pm'],
  26635. ['ddd, hA', 'sön, 3PM'],
  26636. ['M Mo MM MMMM MMM', '2 2a 02 februari feb'],
  26637. ['YYYY YY', '2010 10'],
  26638. ['D Do DD', '14 14e 14'],
  26639. ['d do dddd ddd dd', '0 0e söndag sön sö'],
  26640. ['DDD DDDo DDDD', '45 45e 045'],
  26641. ['w wo ww', '6 6e 06'],
  26642. ['h hh', '3 03'],
  26643. ['H HH', '15 15'],
  26644. ['m mm', '25 25'],
  26645. ['s ss', '50 50'],
  26646. ['a A', 'pm PM'],
  26647. ['[the] DDDo [day of the year]', 'the 45e day of the year'],
  26648. ['LTS', '15:25:50'],
  26649. ['L', '2010-02-14'],
  26650. ['LL', '14 februari 2010'],
  26651. ['LLL', '14 februari 2010 15:25'],
  26652. ['LLLL', 'söndag 14 februari 2010 15:25'],
  26653. ['l', '2010-2-14'],
  26654. ['ll', '14 feb 2010'],
  26655. ['lll', '14 feb 2010 15:25'],
  26656. ['llll', 'sön 14 feb 2010 15:25']
  26657. ],
  26658. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  26659. i;
  26660. for (i = 0; i < a.length; i++) {
  26661. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  26662. }
  26663. });
  26664. test('format ordinal', function (assert) {
  26665. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1a', '1a');
  26666. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2a', '2a');
  26667. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3e', '3e');
  26668. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4e', '4e');
  26669. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5e', '5e');
  26670. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6e', '6e');
  26671. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7e', '7e');
  26672. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8e', '8e');
  26673. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9e', '9e');
  26674. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10e', '10e');
  26675. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11e', '11e');
  26676. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12e', '12e');
  26677. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13e', '13e');
  26678. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14e', '14e');
  26679. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15e', '15e');
  26680. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16e', '16e');
  26681. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17e', '17e');
  26682. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18e', '18e');
  26683. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19e', '19e');
  26684. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20e', '20e');
  26685. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21a', '21a');
  26686. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22a', '22a');
  26687. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23e', '23e');
  26688. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24e', '24e');
  26689. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25e', '25e');
  26690. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26e', '26e');
  26691. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27e', '27e');
  26692. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28e', '28e');
  26693. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29e', '29e');
  26694. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30e', '30e');
  26695. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31a', '31a');
  26696. });
  26697. test('format month', function (assert) {
  26698. var expected = 'januari jan_februari feb_mars mar_april apr_maj maj_juni jun_juli jul_augusti aug_september sep_oktober okt_november nov_december dec'.split('_'), i;
  26699. for (i = 0; i < expected.length; i++) {
  26700. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  26701. }
  26702. });
  26703. test('format week', function (assert) {
  26704. var expected = 'söndag sön sö_måndag mån må_tisdag tis ti_onsdag ons on_torsdag tor to_fredag fre fr_lördag lör lö'.split('_'), i;
  26705. for (i = 0; i < expected.length; i++) {
  26706. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  26707. }
  26708. });
  26709. test('from', function (assert) {
  26710. var start = moment([2007, 1, 28]);
  26711. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'några sekunder', '44 seconds = a few seconds');
  26712. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'en minut', '45 seconds = a minute');
  26713. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'en minut', '89 seconds = a minute');
  26714. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuter', '90 seconds = 2 minutes');
  26715. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuter', '44 minutes = 44 minutes');
  26716. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'en timme', '45 minutes = an hour');
  26717. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'en timme', '89 minutes = an hour');
  26718. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 timmar', '90 minutes = 2 hours');
  26719. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 timmar', '5 hours = 5 hours');
  26720. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 timmar', '21 hours = 21 hours');
  26721. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'en dag', '22 hours = a day');
  26722. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'en dag', '35 hours = a day');
  26723. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dagar', '36 hours = 2 days');
  26724. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'en dag', '1 day = a day');
  26725. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dagar', '5 days = 5 days');
  26726. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dagar', '25 days = 25 days');
  26727. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'en månad', '26 days = a month');
  26728. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'en månad', '30 days = a month');
  26729. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'en månad', '43 days = a month');
  26730. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 månader', '46 days = 2 months');
  26731. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 månader', '75 days = 2 months');
  26732. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 månader', '76 days = 3 months');
  26733. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'en månad', '1 month = a month');
  26734. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 månader', '5 months = 5 months');
  26735. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ett år', '345 days = a year');
  26736. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 år', '548 days = 2 years');
  26737. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ett år', '1 year = a year');
  26738. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 år', '5 years = 5 years');
  26739. });
  26740. test('suffix', function (assert) {
  26741. assert.equal(moment(30000).from(0), 'om några sekunder', 'prefix');
  26742. assert.equal(moment(0).from(30000), 'för några sekunder sedan', 'suffix');
  26743. });
  26744. test('now from now', function (assert) {
  26745. assert.equal(moment().fromNow(), 'för några sekunder sedan', 'now from now should display as in the past');
  26746. });
  26747. test('fromNow', function (assert) {
  26748. assert.equal(moment().add({s: 30}).fromNow(), 'om några sekunder', 'in a few seconds');
  26749. assert.equal(moment().add({d: 5}).fromNow(), 'om 5 dagar', 'in 5 days');
  26750. });
  26751. test('calendar day', function (assert) {
  26752. var a = moment().hours(2).minutes(0).seconds(0);
  26753. assert.equal(moment(a).calendar(), 'Idag 02:00', 'today at the same time');
  26754. assert.equal(moment(a).add({m: 25}).calendar(), 'Idag 02:25', 'Now plus 25 min');
  26755. assert.equal(moment(a).add({h: 1}).calendar(), 'Idag 03:00', 'Now plus 1 hour');
  26756. assert.equal(moment(a).add({d: 1}).calendar(), 'Imorgon 02:00', 'tomorrow at the same time');
  26757. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Idag 01:00', 'Now minus 1 hour');
  26758. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Igår 02:00', 'yesterday at the same time');
  26759. });
  26760. test('calendar next week', function (assert) {
  26761. var i, m;
  26762. for (i = 2; i < 7; i++) {
  26763. m = moment().add({d: i});
  26764. assert.equal(m.calendar(), m.format('[På] dddd LT'), 'Today + ' + i + ' days current time');
  26765. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  26766. assert.equal(m.calendar(), m.format('[På] dddd LT'), 'Today + ' + i + ' days beginning of day');
  26767. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  26768. assert.equal(m.calendar(), m.format('[På] dddd LT'), 'Today + ' + i + ' days end of day');
  26769. }
  26770. });
  26771. test('calendar last week', function (assert) {
  26772. var i, m;
  26773. for (i = 2; i < 7; i++) {
  26774. m = moment().subtract({d: i});
  26775. assert.equal(m.calendar(), m.format('[I] dddd[s] LT'), 'Today - ' + i + ' days current time');
  26776. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  26777. assert.equal(m.calendar(), m.format('[I] dddd[s] LT'), 'Today - ' + i + ' days beginning of day');
  26778. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  26779. assert.equal(m.calendar(), m.format('[I] dddd[s] LT'), 'Today - ' + i + ' days end of day');
  26780. }
  26781. });
  26782. test('calendar all else', function (assert) {
  26783. var weeksAgo = moment().subtract({w: 1}),
  26784. weeksFromNow = moment().add({w: 1});
  26785. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  26786. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  26787. weeksAgo = moment().subtract({w: 2});
  26788. weeksFromNow = moment().add({w: 2});
  26789. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  26790. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  26791. });
  26792. test('weeks year starting sunday', function (assert) {
  26793. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  26794. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  26795. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  26796. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  26797. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  26798. });
  26799. test('weeks year starting monday', function (assert) {
  26800. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  26801. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  26802. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  26803. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  26804. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  26805. });
  26806. test('weeks year starting tuesday', function (assert) {
  26807. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  26808. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  26809. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  26810. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  26811. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  26812. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  26813. });
  26814. test('weeks year starting wednesday', function (assert) {
  26815. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  26816. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  26817. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  26818. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  26819. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  26820. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  26821. });
  26822. test('weeks year starting thursday', function (assert) {
  26823. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  26824. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  26825. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  26826. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  26827. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  26828. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  26829. });
  26830. test('weeks year starting friday', function (assert) {
  26831. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  26832. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  26833. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  26834. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  26835. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  26836. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  26837. });
  26838. test('weeks year starting saturday', function (assert) {
  26839. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  26840. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  26841. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  26842. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  26843. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  26844. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  26845. });
  26846. test('weeks year starting sunday formatted', function (assert) {
  26847. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52a', 'Jan 1 2012 should be week 52');
  26848. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1a', 'Jan 2 2012 should be week 1');
  26849. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1a', 'Jan 8 2012 should be week 1');
  26850. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2a', 'Jan 9 2012 should be week 2');
  26851. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2a', 'Jan 15 2012 should be week 2');
  26852. });
  26853. test('lenient ordinal parsing', function (assert) {
  26854. var i, ordinalStr, testMoment;
  26855. for (i = 1; i <= 31; ++i) {
  26856. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  26857. testMoment = moment(ordinalStr, 'YYYY MM Do');
  26858. assert.equal(testMoment.year(), 2014,
  26859. 'lenient ordinal parsing ' + i + ' year check');
  26860. assert.equal(testMoment.month(), 0,
  26861. 'lenient ordinal parsing ' + i + ' month check');
  26862. assert.equal(testMoment.date(), i,
  26863. 'lenient ordinal parsing ' + i + ' date check');
  26864. }
  26865. });
  26866. test('lenient ordinal parsing of number', function (assert) {
  26867. var i, testMoment;
  26868. for (i = 1; i <= 31; ++i) {
  26869. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  26870. assert.equal(testMoment.year(), 2014,
  26871. 'lenient ordinal parsing of number ' + i + ' year check');
  26872. assert.equal(testMoment.month(), 0,
  26873. 'lenient ordinal parsing of number ' + i + ' month check');
  26874. assert.equal(testMoment.date(), i,
  26875. 'lenient ordinal parsing of number ' + i + ' date check');
  26876. }
  26877. });
  26878. test('strict ordinal parsing', function (assert) {
  26879. var i, ordinalStr, testMoment;
  26880. for (i = 1; i <= 31; ++i) {
  26881. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  26882. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  26883. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  26884. }
  26885. });
  26886. }));
  26887. ;(function (global, factory) {
  26888. typeof exports === 'object' && typeof module !== 'undefined'
  26889. && typeof require === 'function' ? factory(require('../../moment')) :
  26890. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  26891. factory(global.moment)
  26892. }(this, function (moment) { 'use strict';
  26893. /*global QUnit:false*/
  26894. var test = QUnit.test;
  26895. var expect = QUnit.expect;
  26896. function module (name, lifecycle) {
  26897. QUnit.module(name, {
  26898. setup : function () {
  26899. moment.locale('en');
  26900. moment.createFromInputFallback = function (config) {
  26901. throw new Error('input not handled by moment: ' + config._i);
  26902. };
  26903. if (lifecycle && lifecycle.setup) {
  26904. lifecycle.setup();
  26905. }
  26906. },
  26907. teardown : function () {
  26908. if (lifecycle && lifecycle.teardown) {
  26909. lifecycle.teardown();
  26910. }
  26911. }
  26912. });
  26913. }
  26914. function localeModule (name, lifecycle) {
  26915. QUnit.module('locale:' + name, {
  26916. setup : function () {
  26917. moment.locale(name);
  26918. moment.createFromInputFallback = function (config) {
  26919. throw new Error('input not handled by moment: ' + config._i);
  26920. };
  26921. if (lifecycle && lifecycle.setup) {
  26922. lifecycle.setup();
  26923. }
  26924. },
  26925. teardown : function () {
  26926. moment.locale('en');
  26927. if (lifecycle && lifecycle.teardown) {
  26928. lifecycle.teardown();
  26929. }
  26930. }
  26931. });
  26932. }
  26933. localeModule('sw');
  26934. test('parse', function (assert) {
  26935. var tests = 'Januari Jan_Februari Feb_Machi Mac_Aprili Apr_Mei Mei_Juni Jun_Julai Jul_Agosti Ago_Septemba Sep_Oktoba Okt_Novemba Nov_Desemba Des'.split('_'), i;
  26936. function equalTest(input, mmm, i) {
  26937. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  26938. }
  26939. for (i = 0; i < 12; i++) {
  26940. tests[i] = tests[i].split(' ');
  26941. equalTest(tests[i][0], 'MMM', i);
  26942. equalTest(tests[i][1], 'MMM', i);
  26943. equalTest(tests[i][0], 'MMMM', i);
  26944. equalTest(tests[i][1], 'MMMM', i);
  26945. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  26946. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  26947. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  26948. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  26949. }
  26950. });
  26951. test('format', function (assert) {
  26952. var a = [
  26953. ['dddd, MMMM Do YYYY, h:mm:ss a', 'Jumapili, Februari 14 2010, 3:25:50 pm'],
  26954. ['ddd, hA', 'Jpl, 3PM'],
  26955. ['M Mo MM MMMM MMM', '2 2 02 Februari Feb'],
  26956. ['YYYY YY', '2010 10'],
  26957. ['D Do DD', '14 14 14'],
  26958. ['d do dddd ddd dd', '0 0 Jumapili Jpl J2'],
  26959. ['DDD DDDo DDDD', '45 45 045'],
  26960. ['w wo ww', '7 7 07'],
  26961. ['h hh', '3 03'],
  26962. ['H HH', '15 15'],
  26963. ['m mm', '25 25'],
  26964. ['s ss', '50 50'],
  26965. ['a A', 'pm PM'],
  26966. ['[siku] DDDo [ya mwaka]', 'siku 45 ya mwaka'],
  26967. ['LTS', '15:25:50'],
  26968. ['L', '14.02.2010'],
  26969. ['LL', '14 Februari 2010'],
  26970. ['LLL', '14 Februari 2010 15:25'],
  26971. ['LLLL', 'Jumapili, 14 Februari 2010 15:25'],
  26972. ['l', '14.2.2010'],
  26973. ['ll', '14 Feb 2010'],
  26974. ['lll', '14 Feb 2010 15:25'],
  26975. ['llll', 'Jpl, 14 Feb 2010 15:25']
  26976. ],
  26977. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  26978. i;
  26979. for (i = 0; i < a.length; i++) {
  26980. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  26981. }
  26982. });
  26983. test('format ordinal', function (assert) {
  26984. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1');
  26985. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2');
  26986. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3');
  26987. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4');
  26988. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5');
  26989. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6');
  26990. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7');
  26991. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8');
  26992. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9');
  26993. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10');
  26994. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11');
  26995. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12');
  26996. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13');
  26997. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14');
  26998. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15');
  26999. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16');
  27000. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17');
  27001. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18');
  27002. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19');
  27003. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20');
  27004. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21');
  27005. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22');
  27006. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23');
  27007. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24');
  27008. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25');
  27009. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26');
  27010. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27');
  27011. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28');
  27012. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29');
  27013. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30');
  27014. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31');
  27015. });
  27016. test('format month', function (assert) {
  27017. var expected = 'Januari Jan_Februari Feb_Machi Mac_Aprili Apr_Mei Mei_Juni Jun_Julai Jul_Agosti Ago_Septemba Sep_Oktoba Okt_Novemba Nov_Desemba Des'.split('_'), i;
  27018. for (i = 0; i < expected.length; i++) {
  27019. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  27020. }
  27021. });
  27022. test('format week', function (assert) {
  27023. var expected = 'Jumapili Jpl J2_Jumatatu Jtat J3_Jumanne Jnne J4_Jumatano Jtan J5_Alhamisi Alh Al_Ijumaa Ijm Ij_Jumamosi Jmos J1'.split('_'), i;
  27024. for (i = 0; i < expected.length; i++) {
  27025. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  27026. }
  27027. });
  27028. test('from', function (assert) {
  27029. var start = moment([2007, 1, 28]);
  27030. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'hivi punde', '44 seconds = a few seconds');
  27031. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'dakika moja', '45 seconds = a minute');
  27032. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'dakika moja', '89 seconds = a minute');
  27033. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), 'dakika 2', '90 seconds = 2 minutes');
  27034. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), 'dakika 44', '44 minutes = 44 minutes');
  27035. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'saa limoja', '45 minutes = an hour');
  27036. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'saa limoja', '89 minutes = an hour');
  27037. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), 'masaa 2', '90 minutes = 2 hours');
  27038. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), 'masaa 5', '5 hours = 5 hours');
  27039. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), 'masaa 21', '21 hours = 21 hours');
  27040. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'siku moja', '22 hours = a day');
  27041. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'siku moja', '35 hours = a day');
  27042. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), 'masiku 2', '36 hours = 2 days');
  27043. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'siku moja', '1 day = a day');
  27044. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), 'masiku 5', '5 days = 5 days');
  27045. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), 'masiku 25', '25 days = 25 days');
  27046. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'mwezi mmoja', '26 days = a month');
  27047. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'mwezi mmoja', '30 days = a month');
  27048. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'mwezi mmoja', '43 days = a month');
  27049. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), 'miezi 2', '46 days = 2 months');
  27050. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), 'miezi 2', '75 days = 2 months');
  27051. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), 'miezi 3', '76 days = 3 months');
  27052. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'mwezi mmoja', '1 month = a month');
  27053. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), 'miezi 5', '5 months = 5 months');
  27054. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'mwaka mmoja', '345 days = a year');
  27055. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), 'miaka 2', '548 days = 2 years');
  27056. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'mwaka mmoja', '1 year = a year');
  27057. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), 'miaka 5', '5 years = 5 years');
  27058. });
  27059. test('suffix', function (assert) {
  27060. assert.equal(moment(30000).from(0), 'hivi punde baadaye', 'prefix');
  27061. assert.equal(moment(0).from(30000), 'tokea hivi punde', 'suffix');
  27062. });
  27063. test('now from now', function (assert) {
  27064. assert.equal(moment().fromNow(), 'tokea hivi punde', 'now from now should display as in the past');
  27065. });
  27066. test('fromNow', function (assert) {
  27067. assert.equal(moment().add({s: 30}).fromNow(), 'hivi punde baadaye', 'in a few seconds');
  27068. assert.equal(moment().add({d: 5}).fromNow(), 'masiku 5 baadaye', 'in 5 days');
  27069. });
  27070. test('calendar day', function (assert) {
  27071. var a = moment().hours(2).minutes(0).seconds(0);
  27072. assert.equal(moment(a).calendar(), 'leo saa 02:00', 'today at the same time');
  27073. assert.equal(moment(a).add({m: 25}).calendar(), 'leo saa 02:25', 'Now plus 25 min');
  27074. assert.equal(moment(a).add({h: 1}).calendar(), 'leo saa 03:00', 'Now plus 1 hour');
  27075. assert.equal(moment(a).add({d: 1}).calendar(), 'kesho saa 02:00', 'tomorrow at the same time');
  27076. assert.equal(moment(a).subtract({h: 1}).calendar(), 'leo saa 01:00', 'Now minus 1 hour');
  27077. assert.equal(moment(a).subtract({d: 1}).calendar(), 'jana 02:00', 'yesterday at the same time');
  27078. });
  27079. test('calendar next week', function (assert) {
  27080. var i, m;
  27081. for (i = 2; i < 7; i++) {
  27082. m = moment().add({d: i});
  27083. assert.equal(m.calendar(), m.format('[wiki ijayo] dddd [saat] LT'), 'Today + ' + i + ' days current time');
  27084. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  27085. assert.equal(m.calendar(), m.format('[wiki ijayo] dddd [saat] LT'), 'Today + ' + i + ' days beginning of day');
  27086. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  27087. assert.equal(m.calendar(), m.format('[wiki ijayo] dddd [saat] LT'), 'Today + ' + i + ' days end of day');
  27088. }
  27089. });
  27090. test('calendar last week', function (assert) {
  27091. var i, m;
  27092. for (i = 2; i < 7; i++) {
  27093. m = moment().subtract({d: i});
  27094. assert.equal(m.calendar(), m.format('[wiki iliyopita] dddd [saat] LT'), 'Today - ' + i + ' days current time');
  27095. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  27096. assert.equal(m.calendar(), m.format('[wiki iliyopita] dddd [saat] LT'), 'Today - ' + i + ' days beginning of day');
  27097. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  27098. assert.equal(m.calendar(), m.format('[wiki iliyopita] dddd [saat] LT'), 'Today - ' + i + ' days end of day');
  27099. }
  27100. });
  27101. test('calendar all else', function (assert) {
  27102. var weeksAgo = moment().subtract({w: 1}),
  27103. weeksFromNow = moment().add({w: 1});
  27104. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  27105. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  27106. weeksAgo = moment().subtract({w: 2});
  27107. weeksFromNow = moment().add({w: 2});
  27108. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  27109. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  27110. });
  27111. test('weeks year starting sunday', function (assert) {
  27112. assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1');
  27113. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  27114. assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2');
  27115. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  27116. assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3');
  27117. });
  27118. test('weeks year starting monday', function (assert) {
  27119. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  27120. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  27121. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  27122. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  27123. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  27124. });
  27125. test('weeks year starting tuesday', function (assert) {
  27126. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  27127. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  27128. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  27129. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  27130. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  27131. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  27132. });
  27133. test('weeks year starting wednesday', function (assert) {
  27134. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  27135. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  27136. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  27137. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  27138. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  27139. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  27140. });
  27141. test('weeks year starting thursday', function (assert) {
  27142. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  27143. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  27144. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  27145. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  27146. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  27147. assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3');
  27148. });
  27149. test('weeks year starting friday', function (assert) {
  27150. assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1');
  27151. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  27152. assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1');
  27153. assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2');
  27154. assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2');
  27155. assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3');
  27156. });
  27157. test('weeks year starting saturday', function (assert) {
  27158. assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1');
  27159. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  27160. assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1');
  27161. assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2');
  27162. assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2');
  27163. assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3');
  27164. });
  27165. test('weeks year starting sunday format', function (assert) {
  27166. assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1', 'Dec 26 2011 should be week 1');
  27167. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1', 'Jan 1 2012 should be week 1');
  27168. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2', 'Jan 2 2012 should be week 2');
  27169. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2', 'Jan 8 2012 should be week 2');
  27170. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3', 'Jan 9 2012 should be week 3');
  27171. });
  27172. test('lenient ordinal parsing', function (assert) {
  27173. var i, ordinalStr, testMoment;
  27174. for (i = 1; i <= 31; ++i) {
  27175. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  27176. testMoment = moment(ordinalStr, 'YYYY MM Do');
  27177. assert.equal(testMoment.year(), 2014,
  27178. 'lenient ordinal parsing ' + i + ' year check');
  27179. assert.equal(testMoment.month(), 0,
  27180. 'lenient ordinal parsing ' + i + ' month check');
  27181. assert.equal(testMoment.date(), i,
  27182. 'lenient ordinal parsing ' + i + ' date check');
  27183. }
  27184. });
  27185. test('lenient ordinal parsing of number', function (assert) {
  27186. var i, testMoment;
  27187. for (i = 1; i <= 31; ++i) {
  27188. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  27189. assert.equal(testMoment.year(), 2014,
  27190. 'lenient ordinal parsing of number ' + i + ' year check');
  27191. assert.equal(testMoment.month(), 0,
  27192. 'lenient ordinal parsing of number ' + i + ' month check');
  27193. assert.equal(testMoment.date(), i,
  27194. 'lenient ordinal parsing of number ' + i + ' date check');
  27195. }
  27196. });
  27197. test('strict ordinal parsing', function (assert) {
  27198. var i, ordinalStr, testMoment;
  27199. for (i = 1; i <= 31; ++i) {
  27200. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  27201. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  27202. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  27203. }
  27204. });
  27205. }));
  27206. ;(function (global, factory) {
  27207. typeof exports === 'object' && typeof module !== 'undefined'
  27208. && typeof require === 'function' ? factory(require('../../moment')) :
  27209. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  27210. factory(global.moment)
  27211. }(this, function (moment) { 'use strict';
  27212. /*global QUnit:false*/
  27213. var test = QUnit.test;
  27214. var expect = QUnit.expect;
  27215. function module (name, lifecycle) {
  27216. QUnit.module(name, {
  27217. setup : function () {
  27218. moment.locale('en');
  27219. moment.createFromInputFallback = function (config) {
  27220. throw new Error('input not handled by moment: ' + config._i);
  27221. };
  27222. if (lifecycle && lifecycle.setup) {
  27223. lifecycle.setup();
  27224. }
  27225. },
  27226. teardown : function () {
  27227. if (lifecycle && lifecycle.teardown) {
  27228. lifecycle.teardown();
  27229. }
  27230. }
  27231. });
  27232. }
  27233. function localeModule (name, lifecycle) {
  27234. QUnit.module('locale:' + name, {
  27235. setup : function () {
  27236. moment.locale(name);
  27237. moment.createFromInputFallback = function (config) {
  27238. throw new Error('input not handled by moment: ' + config._i);
  27239. };
  27240. if (lifecycle && lifecycle.setup) {
  27241. lifecycle.setup();
  27242. }
  27243. },
  27244. teardown : function () {
  27245. moment.locale('en');
  27246. if (lifecycle && lifecycle.teardown) {
  27247. lifecycle.teardown();
  27248. }
  27249. }
  27250. });
  27251. }
  27252. localeModule('ta');
  27253. test('parse', function (assert) {
  27254. var tests = 'ஜனவரி ஜனவரி_பிப்ரவரி பிப்ரவரி_மார்ச் மார்ச்_ஏப்ரல் ஏப்ரல்_மே மே_ஜூன் ஜூன்_ஜூலை ஜூலை_ஆகஸ்ட் ஆகஸ்ட்_செப்டெம்பர் செப்டெம்பர்_அக்டோபர் அக்டோபர்_நவம்பர் நவம்பர்_டிசம்பர் டிசம்பர்'.split('_'), i;
  27255. function equalTest(input, mmm, i) {
  27256. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  27257. }
  27258. for (i = 0; i < 12; i++) {
  27259. tests[i] = tests[i].split(' ');
  27260. equalTest(tests[i][0], 'MMM', i);
  27261. equalTest(tests[i][1], 'MMM', i);
  27262. equalTest(tests[i][0], 'MMMM', i);
  27263. equalTest(tests[i][1], 'MMMM', i);
  27264. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  27265. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  27266. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  27267. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  27268. }
  27269. });
  27270. test('format', function (assert) {
  27271. var a = [
  27272. ['dddd, MMMM Do YYYY, h:mm:ss a', 'ஞாயிற்றுக்கிழமை, பிப்ரவரி ௧௪வது ௨௦௧௦, ௩:௨௫:௫௦ எற்பாடு'],
  27273. ['ddd, hA', 'ஞாயிறு, ௩ எற்பாடு'],
  27274. ['M Mo MM MMMM MMM', '௨ ௨வது ௦௨ பிப்ரவரி பிப்ரவரி'],
  27275. ['YYYY YY', '௨௦௧௦ ௧௦'],
  27276. ['D Do DD', '௧௪ ௧௪வது ௧௪'],
  27277. ['d do dddd ddd dd', '௦ ௦வது ஞாயிற்றுக்கிழமை ஞாயிறு ஞா'],
  27278. ['DDD DDDo DDDD', '௪௫ ௪௫வது ௦௪௫'],
  27279. ['w wo ww', '௮ ௮வது ௦௮'],
  27280. ['h hh', '௩ ௦௩'],
  27281. ['H HH', '௧௫ ௧௫'],
  27282. ['m mm', '௨௫ ௨௫'],
  27283. ['s ss', '௫௦ ௫௦'],
  27284. ['a A', ' எற்பாடு எற்பாடு'],
  27285. ['[ஆண்டின்] DDDo [நாள்]', 'ஆண்டின் ௪௫வது நாள்'],
  27286. ['LTS', '௧௫:௨௫:௫௦'],
  27287. ['L', '௧௪/௦௨/௨௦௧௦'],
  27288. ['LL', '௧௪ பிப்ரவரி ௨௦௧௦'],
  27289. ['LLL', '௧௪ பிப்ரவரி ௨௦௧௦, ௧௫:௨௫'],
  27290. ['LLLL', 'ஞாயிற்றுக்கிழமை, ௧௪ பிப்ரவரி ௨௦௧௦, ௧௫:௨௫'],
  27291. ['l', '௧௪/௨/௨௦௧௦'],
  27292. ['ll', '௧௪ பிப்ரவரி ௨௦௧௦'],
  27293. ['lll', '௧௪ பிப்ரவரி ௨௦௧௦, ௧௫:௨௫'],
  27294. ['llll', 'ஞாயிறு, ௧௪ பிப்ரவரி ௨௦௧௦, ௧௫:௨௫']
  27295. ],
  27296. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  27297. i;
  27298. for (i = 0; i < a.length; i++) {
  27299. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  27300. }
  27301. });
  27302. test('format ordinal', function (assert) {
  27303. assert.equal(moment([2011, 0, 1]).format('DDDo'), '௧வது', '௧வது');
  27304. assert.equal(moment([2011, 0, 2]).format('DDDo'), '௨வது', '௨வது');
  27305. assert.equal(moment([2011, 0, 3]).format('DDDo'), '௩வது', '௩வது');
  27306. assert.equal(moment([2011, 0, 4]).format('DDDo'), '௪வது', '௪வது');
  27307. assert.equal(moment([2011, 0, 5]).format('DDDo'), '௫வது', '௫வது');
  27308. assert.equal(moment([2011, 0, 6]).format('DDDo'), '௬வது', '௬வது');
  27309. assert.equal(moment([2011, 0, 7]).format('DDDo'), '௭வது', '௭வது');
  27310. assert.equal(moment([2011, 0, 8]).format('DDDo'), '௮வது', '௮வது');
  27311. assert.equal(moment([2011, 0, 9]).format('DDDo'), '௯வது', '௯வது');
  27312. assert.equal(moment([2011, 0, 10]).format('DDDo'), '௧௦வது', '௧௦வது');
  27313. assert.equal(moment([2011, 0, 11]).format('DDDo'), '௧௧வது', '௧௧வது');
  27314. assert.equal(moment([2011, 0, 12]).format('DDDo'), '௧௨வது', '௧௨வது');
  27315. assert.equal(moment([2011, 0, 13]).format('DDDo'), '௧௩வது', '௧௩வது');
  27316. assert.equal(moment([2011, 0, 14]).format('DDDo'), '௧௪வது', '௧௪வது');
  27317. assert.equal(moment([2011, 0, 15]).format('DDDo'), '௧௫வது', '௧௫வது');
  27318. assert.equal(moment([2011, 0, 16]).format('DDDo'), '௧௬வது', '௧௬வது');
  27319. assert.equal(moment([2011, 0, 17]).format('DDDo'), '௧௭வது', '௧௭வது');
  27320. assert.equal(moment([2011, 0, 18]).format('DDDo'), '௧௮வது', '௧௮வது');
  27321. assert.equal(moment([2011, 0, 19]).format('DDDo'), '௧௯வது', '௧௯வது');
  27322. assert.equal(moment([2011, 0, 20]).format('DDDo'), '௨௦வது', '௨௦வது');
  27323. assert.equal(moment([2011, 0, 21]).format('DDDo'), '௨௧வது', '௨௧வது');
  27324. assert.equal(moment([2011, 0, 22]).format('DDDo'), '௨௨வது', '௨௨வது');
  27325. assert.equal(moment([2011, 0, 23]).format('DDDo'), '௨௩வது', '௨௩வது');
  27326. assert.equal(moment([2011, 0, 24]).format('DDDo'), '௨௪வது', '௨௪வது');
  27327. assert.equal(moment([2011, 0, 25]).format('DDDo'), '௨௫வது', '௨௫வது');
  27328. assert.equal(moment([2011, 0, 26]).format('DDDo'), '௨௬வது', '௨௬வது');
  27329. assert.equal(moment([2011, 0, 27]).format('DDDo'), '௨௭வது', '௨௭வது');
  27330. assert.equal(moment([2011, 0, 28]).format('DDDo'), '௨௮வது', '௨௮வது');
  27331. assert.equal(moment([2011, 0, 29]).format('DDDo'), '௨௯வது', '௨௯வது');
  27332. assert.equal(moment([2011, 0, 30]).format('DDDo'), '௩௦வது', '௩௦வது');
  27333. assert.equal(moment([2011, 0, 31]).format('DDDo'), '௩௧வது', '௩௧வது');
  27334. });
  27335. test('format month', function (assert) {
  27336. var expected = 'ஜனவரி ஜனவரி_பிப்ரவரி பிப்ரவரி_மார்ச் மார்ச்_ஏப்ரல் ஏப்ரல்_மே மே_ஜூன் ஜூன்_ஜூலை ஜூலை_ஆகஸ்ட் ஆகஸ்ட்_செப்டெம்பர் செப்டெம்பர்_அக்டோபர் அக்டோபர்_நவம்பர் நவம்பர்_டிசம்பர் டிசம்பர்'.split('_'), i;
  27337. for (i = 0; i < expected.length; i++) {
  27338. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  27339. }
  27340. });
  27341. test('format week', function (assert) {
  27342. var expected = 'ஞாயிற்றுக்கிழமை ஞாயிறு ஞா_திங்கட்கிழமை திங்கள் தி_செவ்வாய்கிழமை செவ்வாய் செ_புதன்கிழமை புதன் பு_வியாழக்கிழமை வியாழன் வி_வெள்ளிக்கிழமை வெள்ளி வெ_சனிக்கிழமை சனி ச'.split('_'), i;
  27343. for (i = 0; i < expected.length; i++) {
  27344. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  27345. }
  27346. });
  27347. test('from', function (assert) {
  27348. var start = moment([2007, 1, 28]);
  27349. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ஒரு சில விநாடிகள்', '44 விநாடிகள் = ஒரு சில விநாடிகள்');
  27350. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'ஒரு நிமிடம்', '45 விநாடிகள் = ஒரு நிமிடம்');
  27351. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'ஒரு நிமிடம்', '89 விநாடிகள் = ஒரு நிமிடம்');
  27352. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '௨ நிமிடங்கள்', '90 விநாடிகள் = ௨ நிமிடங்கள்');
  27353. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '௪௪ நிமிடங்கள்', '44 நிமிடங்கள் = 44 நிமிடங்கள்');
  27354. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ஒரு மணி நேரம்', '45 நிமிடங்கள் = ஒரு மணி நேரம்');
  27355. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ஒரு மணி நேரம்', '89 நிமிடங்கள் = ஒரு மணி நேரம்');
  27356. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '௨ மணி நேரம்', '90 நிமிடங்கள் = ௨ மணி நேரம்');
  27357. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '௫ மணி நேரம்', '5 மணி நேரம் = 5 மணி நேரம்');
  27358. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '௨௧ மணி நேரம்', '௨௧ மணி நேரம் = ௨௧ மணி நேரம்');
  27359. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ஒரு நாள்', '௨௨ மணி நேரம் = ஒரு நாள்');
  27360. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ஒரு நாள்', '௩5 மணி நேரம் = ஒரு நாள்');
  27361. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '௨ நாட்கள்', '௩6 மணி நேரம் = ௨ days');
  27362. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ஒரு நாள்', '௧ நாள் = ஒரு நாள்');
  27363. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '௫ நாட்கள்', '5 நாட்கள் = 5 நாட்கள்');
  27364. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '௨௫ நாட்கள்', '௨5 நாட்கள் = ௨5 நாட்கள்');
  27365. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ஒரு மாதம்', '௨6 நாட்கள் = ஒரு மாதம்');
  27366. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ஒரு மாதம்', '௩0 நாட்கள் = ஒரு மாதம்');
  27367. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ஒரு மாதம்', '45 நாட்கள் = ஒரு மாதம்');
  27368. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '௨ மாதங்கள்', '46 நாட்கள் = ௨ மாதங்கள்');
  27369. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '௨ மாதங்கள்', '75 நாட்கள் = ௨ மாதங்கள்');
  27370. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '௩ மாதங்கள்', '76 நாட்கள் = ௩ மாதங்கள்');
  27371. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ஒரு மாதம்', '௧ மாதம் = ஒரு மாதம்');
  27372. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '௫ மாதங்கள்', '5 மாதங்கள் = 5 மாதங்கள்');
  27373. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ஒரு வருடம்', '௩45 நாட்கள் = ஒரு வருடம்');
  27374. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '௨ ஆண்டுகள்', '548 நாட்கள் = ௨ ஆண்டுகள்');
  27375. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ஒரு வருடம்', '௧ வருடம் = ஒரு வருடம்');
  27376. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '௫ ஆண்டுகள்', '5 ஆண்டுகள் = 5 ஆண்டுகள்');
  27377. });
  27378. test('suffix', function (assert) {
  27379. assert.equal(moment(30000).from(0), 'ஒரு சில விநாடிகள் இல்', 'prefix');
  27380. assert.equal(moment(0).from(30000), 'ஒரு சில விநாடிகள் முன்', 'suffix');
  27381. });
  27382. test('now from now', function (assert) {
  27383. assert.equal(moment().fromNow(), 'ஒரு சில விநாடிகள் முன்', 'இப்போது இருந்து கடந்த காலத்தில் காட்ட வேண்டும்');
  27384. });
  27385. test('fromNow', function (assert) {
  27386. assert.equal(moment().add({s: 30}).fromNow(), 'ஒரு சில விநாடிகள் இல்', 'ஒரு சில விநாடிகள் இல்');
  27387. assert.equal(moment().add({d: 5}).fromNow(), '௫ நாட்கள் இல்', '5 நாட்கள் இல்');
  27388. });
  27389. test('calendar day', function (assert) {
  27390. var a = moment().hours(2).minutes(0).seconds(0);
  27391. assert.equal(moment(a).calendar(), 'இன்று ௦௨:௦௦', 'இன்று 02:00');
  27392. assert.equal(moment(a).add({m: 25}).calendar(), 'இன்று ௦௨:௨௫', 'இன்று 02:25');
  27393. assert.equal(moment(a).add({h: 1}).calendar(), 'இன்று ௦௩:௦௦', 'இன்று 03:00');
  27394. assert.equal(moment(a).add({d: 1}).calendar(), 'நாளை ௦௨:௦௦', 'நாளை 02:00');
  27395. assert.equal(moment(a).subtract({h: 1}).calendar(), 'இன்று ௦௧:௦௦', 'இன்று 0௧:00');
  27396. assert.equal(moment(a).subtract({d: 1}).calendar(), 'நேற்று ௦௨:௦௦', 'நேற்று 02:00');
  27397. });
  27398. test('calendar next week', function (assert) {
  27399. var i, m;
  27400. for (i = 2; i < 7; i++) {
  27401. m = moment().add({d: i});
  27402. assert.equal(m.calendar(), m.format('dddd, LT'), 'Today + ' + i + ' days current time');
  27403. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  27404. assert.equal(m.calendar(), m.format('dddd, LT'), 'Today + ' + i + ' days beginning of day');
  27405. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  27406. assert.equal(m.calendar(), m.format('dddd, LT'), 'Today + ' + i + ' days end of day');
  27407. }
  27408. });
  27409. test('calendar last week', function (assert) {
  27410. var i, m;
  27411. for (i = 2; i < 7; i++) {
  27412. m = moment().subtract({d: i});
  27413. assert.equal(m.calendar(), m.format('[கடந்த வாரம்] dddd, LT'), 'Today - ' + i + ' days current time');
  27414. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  27415. assert.equal(m.calendar(), m.format('[கடந்த வாரம்] dddd, LT'), 'Today - ' + i + ' days beginning of day');
  27416. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  27417. assert.equal(m.calendar(), m.format('[கடந்த வாரம்] dddd, LT'), 'Today - ' + i + ' days end of day');
  27418. }
  27419. });
  27420. test('calendar all else', function (assert) {
  27421. var weeksAgo = moment().subtract({w: 1}),
  27422. weeksFromNow = moment().add({w: 1});
  27423. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  27424. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  27425. weeksAgo = moment().subtract({w: 2});
  27426. weeksFromNow = moment().add({w: 2});
  27427. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  27428. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  27429. });
  27430. test('weeks year starting sunday', function (assert) {
  27431. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  27432. assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1');
  27433. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  27434. assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2');
  27435. assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 3');
  27436. });
  27437. test('weeks year starting monday', function (assert) {
  27438. assert.equal(moment([2006, 11, 31]).week(), 1, 'Dec 31 2006 should be week 1');
  27439. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  27440. assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1');
  27441. assert.equal(moment([2007, 0, 7]).week(), 2, 'Jan 7 2007 should be week 2');
  27442. assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2');
  27443. assert.equal(moment([2007, 0, 14]).week(), 3, 'Jan 14 2007 should be week 3');
  27444. });
  27445. test('weeks year starting tuesday', function (assert) {
  27446. assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52');
  27447. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  27448. assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1');
  27449. assert.equal(moment([2008, 0, 6]).week(), 2, 'Jan 6 2008 should be week 2');
  27450. assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2');
  27451. assert.equal(moment([2008, 0, 13]).week(), 3, 'Jan 13 2008 should be week 3');
  27452. });
  27453. test('weeks year starting wednesday', function (assert) {
  27454. assert.equal(moment([2002, 11, 29]).week(), 1, 'Dec 29 2002 should be week 1');
  27455. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  27456. assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1');
  27457. assert.equal(moment([2003, 0, 5]).week(), 2, 'Jan 5 2003 should be week 2');
  27458. assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2');
  27459. assert.equal(moment([2003, 0, 12]).week(), 3, 'Jan 12 2003 should be week 3');
  27460. });
  27461. test('weeks year starting thursday', function (assert) {
  27462. assert.equal(moment([2008, 11, 28]).week(), 1, 'Dec 28 2008 should be week 1');
  27463. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  27464. assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1');
  27465. assert.equal(moment([2009, 0, 4]).week(), 2, 'Jan 4 2009 should be week 2');
  27466. assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2');
  27467. assert.equal(moment([2009, 0, 11]).week(), 3, 'Jan 11 2009 should be week 3');
  27468. });
  27469. test('weeks year starting friday', function (assert) {
  27470. assert.equal(moment([2009, 11, 27]).week(), 1, 'Dec 27 2009 should be week 1');
  27471. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  27472. assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 should be week 1');
  27473. assert.equal(moment([2010, 0, 3]).week(), 2, 'Jan 3 2010 should be week 2');
  27474. assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 should be week 2');
  27475. assert.equal(moment([2010, 0, 10]).week(), 3, 'Jan 10 2010 should be week 3');
  27476. });
  27477. test('weeks year starting saturday', function (assert) {
  27478. assert.equal(moment([2010, 11, 26]).week(), 1, 'Dec 26 2010 should be week 1');
  27479. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  27480. assert.equal(moment([2011, 0, 2]).week(), 2, 'Jan 2 2011 should be week 2');
  27481. assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2');
  27482. assert.equal(moment([2011, 0, 9]).week(), 3, 'Jan 9 2011 should be week 3');
  27483. });
  27484. test('meridiem', function (assert) {
  27485. assert.equal(moment([2011, 2, 23, 0, 30]).format('a'), ' யாமம்', '(after) midnight');
  27486. assert.equal(moment([2011, 2, 23, 2, 30]).format('a'), ' வைகறை', 'before dawn');
  27487. assert.equal(moment([2011, 2, 23, 9, 30]).format('a'), ' காலை', 'morning');
  27488. assert.equal(moment([2011, 2, 23, 14, 30]).format('a'), ' எற்பாடு', 'during day');
  27489. assert.equal(moment([2011, 2, 23, 17, 30]).format('a'), ' எற்பாடு', 'evening');
  27490. assert.equal(moment([2011, 2, 23, 19, 30]).format('a'), ' மாலை', 'late evening');
  27491. assert.equal(moment([2011, 2, 23, 23, 30]).format('a'), ' யாமம்', '(before) midnight');
  27492. });
  27493. test('lenient ordinal parsing', function (assert) {
  27494. var i, ordinalStr, testMoment;
  27495. for (i = 1; i <= 31; ++i) {
  27496. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  27497. testMoment = moment(ordinalStr, 'YYYY MM Do');
  27498. assert.equal(testMoment.year(), 2014,
  27499. 'lenient ordinal parsing ' + i + ' year check');
  27500. assert.equal(testMoment.month(), 0,
  27501. 'lenient ordinal parsing ' + i + ' month check');
  27502. assert.equal(testMoment.date(), i,
  27503. 'lenient ordinal parsing ' + i + ' date check');
  27504. }
  27505. });
  27506. test('lenient ordinal parsing of number', function (assert) {
  27507. var i, testMoment;
  27508. for (i = 1; i <= 31; ++i) {
  27509. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  27510. assert.equal(testMoment.year(), 2014,
  27511. 'lenient ordinal parsing of number ' + i + ' year check');
  27512. assert.equal(testMoment.month(), 0,
  27513. 'lenient ordinal parsing of number ' + i + ' month check');
  27514. assert.equal(testMoment.date(), i,
  27515. 'lenient ordinal parsing of number ' + i + ' date check');
  27516. }
  27517. });
  27518. test('meridiem invariant', function (assert) {
  27519. var h, m, t1, t2;
  27520. for (h = 0; h < 24; ++h) {
  27521. for (m = 0; m < 60; m += 15) {
  27522. t1 = moment.utc([2000, 0, 1, h, m]);
  27523. t2 = moment(t1.format('A h:mm'), 'A h:mm');
  27524. assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
  27525. 'meridiem at ' + t1.format('HH:mm'));
  27526. }
  27527. }
  27528. });
  27529. test('strict ordinal parsing', function (assert) {
  27530. var i, ordinalStr, testMoment;
  27531. for (i = 1; i <= 31; ++i) {
  27532. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  27533. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  27534. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  27535. }
  27536. });
  27537. }));
  27538. ;(function (global, factory) {
  27539. typeof exports === 'object' && typeof module !== 'undefined'
  27540. && typeof require === 'function' ? factory(require('../../moment')) :
  27541. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  27542. factory(global.moment)
  27543. }(this, function (moment) { 'use strict';
  27544. /*global QUnit:false*/
  27545. var test = QUnit.test;
  27546. var expect = QUnit.expect;
  27547. function module (name, lifecycle) {
  27548. QUnit.module(name, {
  27549. setup : function () {
  27550. moment.locale('en');
  27551. moment.createFromInputFallback = function (config) {
  27552. throw new Error('input not handled by moment: ' + config._i);
  27553. };
  27554. if (lifecycle && lifecycle.setup) {
  27555. lifecycle.setup();
  27556. }
  27557. },
  27558. teardown : function () {
  27559. if (lifecycle && lifecycle.teardown) {
  27560. lifecycle.teardown();
  27561. }
  27562. }
  27563. });
  27564. }
  27565. function localeModule (name, lifecycle) {
  27566. QUnit.module('locale:' + name, {
  27567. setup : function () {
  27568. moment.locale(name);
  27569. moment.createFromInputFallback = function (config) {
  27570. throw new Error('input not handled by moment: ' + config._i);
  27571. };
  27572. if (lifecycle && lifecycle.setup) {
  27573. lifecycle.setup();
  27574. }
  27575. },
  27576. teardown : function () {
  27577. moment.locale('en');
  27578. if (lifecycle && lifecycle.teardown) {
  27579. lifecycle.teardown();
  27580. }
  27581. }
  27582. });
  27583. }
  27584. localeModule('te');
  27585. test('parse', function (assert) {
  27586. var tests = 'జనవరి జన._ఫిబ్రవరి ఫిబ్ర._మార్చి మార్చి_ఏప్రిల్ ఏప్రి._మే మే_జూన్ జూన్_జూలై జూలై_ఆగస్టు ఆగ._సెప్టెంబర్ సెప్._అక్టోబర్ అక్టో._నవంబర్ నవ._డిసెంబర్ డిసె.'.split('_'), i;
  27587. function equalTest(input, mmm, i) {
  27588. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  27589. }
  27590. for (i = 0; i < 12; i++) {
  27591. tests[i] = tests[i].split(' ');
  27592. equalTest(tests[i][0], 'MMM', i);
  27593. equalTest(tests[i][1], 'MMM', i);
  27594. equalTest(tests[i][0], 'MMMM', i);
  27595. equalTest(tests[i][1], 'MMMM', i);
  27596. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  27597. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  27598. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  27599. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  27600. }
  27601. });
  27602. test('format', function (assert) {
  27603. var a = [
  27604. ['dddd, Do తేదీ MMMM YYYY, a h:mm:ss', 'ఆదివారం, 14వ తేదీ ఫిబ్రవరి 2010, మధ్యాహ్నం 3:25:50'],
  27605. ['ddd, a h గంటలు', 'ఆది, మధ్యాహ్నం 3 గంటలు'],
  27606. ['M Mo నెల MM MMMM MMM', '2 2వ నెల 02 ఫిబ్రవరి ఫిబ్ర.'],
  27607. ['YYYY YY', '2010 10'],
  27608. ['D Do DD', '14 14వ 14'],
  27609. ['d do dddd ddd dd', '0 0వ ఆదివారం ఆది ఆ'],
  27610. ['DDD DDDo DDDD', '45 45వ 045'],
  27611. ['w wo ww', '8 8వ 08'],
  27612. ['h hh', '3 03'],
  27613. ['H HH', '15 15'],
  27614. ['m mm', '25 25'],
  27615. ['s ss', '50 50'],
  27616. ['a A', 'మధ్యాహ్నం మధ్యాహ్నం'],
  27617. ['LTS', 'మధ్యాహ్నం 3:25:50'],
  27618. ['L', '14/02/2010'],
  27619. ['LL', '14 ఫిబ్రవరి 2010'],
  27620. ['LLL', '14 ఫిబ్రవరి 2010, మధ్యాహ్నం 3:25'],
  27621. ['LLLL', 'ఆదివారం, 14 ఫిబ్రవరి 2010, మధ్యాహ్నం 3:25'],
  27622. ['l', '14/2/2010'],
  27623. ['ll', '14 ఫిబ్ర. 2010'],
  27624. ['lll', '14 ఫిబ్ర. 2010, మధ్యాహ్నం 3:25'],
  27625. ['llll', 'ఆది, 14 ఫిబ్ర. 2010, మధ్యాహ్నం 3:25']
  27626. ],
  27627. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  27628. i;
  27629. for (i = 0; i < a.length; i++) {
  27630. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  27631. }
  27632. });
  27633. test('format ordinal', function (assert) {
  27634. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1వ', '1వ');
  27635. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2వ', '2వ');
  27636. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3వ', '3వ');
  27637. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4వ', '4వ');
  27638. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5వ', '5వ');
  27639. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6వ', '6వ');
  27640. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7వ', '7వ');
  27641. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8వ', '8వ');
  27642. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9వ', '9వ');
  27643. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10వ', '10వ');
  27644. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11వ', '11వ');
  27645. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12వ', '12వ');
  27646. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13వ', '13వ');
  27647. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14వ', '14వ');
  27648. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15వ', '15వ');
  27649. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16వ', '16వ');
  27650. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17వ', '17వ');
  27651. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18వ', '18వ');
  27652. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19వ', '19వ');
  27653. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20వ', '20వ');
  27654. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21వ', '21వ');
  27655. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22వ', '22వ');
  27656. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23వ', '23వ');
  27657. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24వ', '24వ');
  27658. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25వ', '25వ');
  27659. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26వ', '26వ');
  27660. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27వ', '27వ');
  27661. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28వ', '28వ');
  27662. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29వ', '29వ');
  27663. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30వ', '30వ');
  27664. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31వ', '31వ');
  27665. });
  27666. test('format month', function (assert) {
  27667. var expected = 'జనవరి జన._ఫిబ్రవరి ఫిబ్ర._మార్చి మార్చి_ఏప్రిల్ ఏప్రి._మే మే_జూన్ జూన్_జూలై జూలై_ఆగస్టు ఆగ._సెప్టెంబర్ సెప్._అక్టోబర్ అక్టో._నవంబర్ నవ._డిసెంబర్ డిసె.'.split('_'), i;
  27668. for (i = 0; i < expected.length; i++) {
  27669. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  27670. }
  27671. });
  27672. test('format week', function (assert) {
  27673. var expected = 'ఆదివారం ఆది ఆ_సోమవారం సోమ సో_మంగళవారం మంగళ మం_బుధవారం బుధ బు_గురువారం గురు గు_శుక్రవారం శుక్ర శు_శనివారం శని శ'.split('_'), i;
  27674. for (i = 0; i < expected.length; i++) {
  27675. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  27676. }
  27677. });
  27678. test('from', function (assert) {
  27679. var start = moment([2007, 1, 28]);
  27680. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'కొన్ని క్షణాలు', '44 seconds = a few seconds');
  27681. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'ఒక నిమిషం', '45 seconds = a minute');
  27682. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'ఒక నిమిషం', '89 seconds = a minute');
  27683. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 నిమిషాలు', '90 seconds = 2 minutes');
  27684. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 నిమిషాలు', '44 minutes = 44 minutes');
  27685. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ఒక గంట', '45 minutes = an hour');
  27686. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ఒక గంట', '89 minutes = an hour');
  27687. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 గంటలు', '90 minutes = 2 hours');
  27688. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 గంటలు', '5 hours = 5 hours');
  27689. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 గంటలు', '21 hours = 21 hours');
  27690. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ఒక రోజు', '22 hours = a day');
  27691. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ఒక రోజు', '35 hours = a day');
  27692. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 రోజులు', '36 hours = 2 days');
  27693. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ఒక రోజు', '1 day = a day');
  27694. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 రోజులు', '5 days = 5 days');
  27695. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 రోజులు', '25 days = 25 days');
  27696. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ఒక నెల', '26 days = a month');
  27697. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ఒక నెల', '30 days = a month');
  27698. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ఒక నెల', '43 days = a month');
  27699. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 నెలలు', '46 days = 2 months');
  27700. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 నెలలు', '75 days = 2 months');
  27701. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 నెలలు', '76 days = 3 months');
  27702. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ఒక నెల', '1 month = a month');
  27703. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 నెలలు', '5 months = 5 months');
  27704. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ఒక సంవత్సరం', '345 days = a year');
  27705. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 సంవత్సరాలు', '548 days = 2 years');
  27706. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ఒక సంవత్సరం', '1 year = a year');
  27707. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 సంవత్సరాలు', '5 years = 5 years');
  27708. });
  27709. test('suffix', function (assert) {
  27710. assert.equal(moment(30000).from(0), 'కొన్ని క్షణాలు లో', 'prefix');
  27711. assert.equal(moment(0).from(30000), 'కొన్ని క్షణాలు క్రితం', 'suffix');
  27712. });
  27713. test('now from now', function (assert) {
  27714. assert.equal(moment().fromNow(), 'కొన్ని క్షణాలు క్రితం', 'now from now should display as in the past');
  27715. });
  27716. test('fromNow', function (assert) {
  27717. assert.equal(moment().add({s: 30}).fromNow(), 'కొన్ని క్షణాలు లో', 'కొన్ని క్షణాలు లో');
  27718. assert.equal(moment().add({d: 5}).fromNow(), '5 రోజులు లో', '5 రోజులు లో');
  27719. });
  27720. test('calendar day', function (assert) {
  27721. var a = moment().hours(2).minutes(0).seconds(0);
  27722. assert.equal(moment(a).calendar(), 'నేడు రాత్రి 2:00', 'today at the same time');
  27723. assert.equal(moment(a).add({m: 25}).calendar(), 'నేడు రాత్రి 2:25', 'Now plus 25 min');
  27724. assert.equal(moment(a).add({h: 3}).calendar(), 'నేడు ఉదయం 5:00', 'Now plus 3 hour');
  27725. assert.equal(moment(a).add({d: 1}).calendar(), 'రేపు రాత్రి 2:00', 'tomorrow at the same time');
  27726. assert.equal(moment(a).subtract({h: 1}).calendar(), 'నేడు రాత్రి 1:00', 'Now minus 1 hour');
  27727. assert.equal(moment(a).subtract({d: 1}).calendar(), 'నిన్న రాత్రి 2:00', 'yesterday at the same time');
  27728. });
  27729. test('calendar next week', function (assert) {
  27730. var i, m;
  27731. for (i = 2; i < 7; i++) {
  27732. m = moment().add({d: i});
  27733. assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days current time');
  27734. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  27735. assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days beginning of day');
  27736. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  27737. assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days end of day');
  27738. }
  27739. });
  27740. test('calendar last week', function (assert) {
  27741. var i, m;
  27742. for (i = 2; i < 7; i++) {
  27743. m = moment().subtract({d: i});
  27744. assert.equal(m.calendar(), m.format('[గత] dddd[,] LT'), 'Today - ' + i + ' days current time');
  27745. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  27746. assert.equal(m.calendar(), m.format('[గత] dddd[,] LT'), 'Today - ' + i + ' days beginning of day');
  27747. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  27748. assert.equal(m.calendar(), m.format('[గత] dddd[,] LT'), 'Today - ' + i + ' days end of day');
  27749. }
  27750. });
  27751. test('calendar all else', function (assert) {
  27752. var weeksAgo = moment().subtract({w: 1}),
  27753. weeksFromNow = moment().add({w: 1});
  27754. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  27755. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  27756. weeksAgo = moment().subtract({w: 2});
  27757. weeksFromNow = moment().add({w: 2});
  27758. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  27759. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  27760. });
  27761. test('meridiem invariant', function (assert) {
  27762. assert.equal(moment([2011, 2, 23, 2, 30]).format('a'), 'రాత్రి', 'before dawn');
  27763. assert.equal(moment([2011, 2, 23, 9, 30]).format('a'), 'ఉదయం', 'morning');
  27764. assert.equal(moment([2011, 2, 23, 14, 30]).format('a'), 'మధ్యాహ్నం', 'during day');
  27765. assert.equal(moment([2011, 2, 23, 17, 30]).format('a'), 'సాయంత్రం', 'evening');
  27766. assert.equal(moment([2011, 2, 23, 19, 30]).format('a'), 'సాయంత్రం', 'late evening');
  27767. assert.equal(moment([2011, 2, 23, 21, 20]).format('a'), 'రాత్రి', 'night');
  27768. assert.equal(moment([2011, 2, 23, 2, 30]).format('A'), 'రాత్రి', 'before dawn');
  27769. assert.equal(moment([2011, 2, 23, 9, 30]).format('A'), 'ఉదయం', 'morning');
  27770. assert.equal(moment([2011, 2, 23, 14, 30]).format('A'), 'మధ్యాహ్నం', ' during day');
  27771. assert.equal(moment([2011, 2, 23, 17, 30]).format('A'), 'సాయంత్రం', 'evening');
  27772. assert.equal(moment([2011, 2, 23, 19, 30]).format('A'), 'సాయంత్రం', 'late evening');
  27773. assert.equal(moment([2011, 2, 23, 21, 20]).format('A'), 'రాత్రి', 'night');
  27774. });
  27775. test('weeks year starting sunday', function (assert) {
  27776. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  27777. assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1');
  27778. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  27779. assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2');
  27780. assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 3');
  27781. });
  27782. test('weeks year starting monday', function (assert) {
  27783. assert.equal(moment([2006, 11, 31]).week(), 1, 'Dec 31 2006 should be week 1');
  27784. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  27785. assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1');
  27786. assert.equal(moment([2007, 0, 7]).week(), 2, 'Jan 7 2007 should be week 2');
  27787. assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2');
  27788. assert.equal(moment([2007, 0, 14]).week(), 3, 'Jan 14 2007 should be week 3');
  27789. });
  27790. test('weeks year starting tuesday', function (assert) {
  27791. assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52');
  27792. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  27793. assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1');
  27794. assert.equal(moment([2008, 0, 6]).week(), 2, 'Jan 6 2008 should be week 2');
  27795. assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2');
  27796. assert.equal(moment([2008, 0, 13]).week(), 3, 'Jan 13 2008 should be week 3');
  27797. });
  27798. test('weeks year starting wednesday', function (assert) {
  27799. assert.equal(moment([2002, 11, 29]).week(), 1, 'Dec 29 2002 should be week 1');
  27800. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  27801. assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1');
  27802. assert.equal(moment([2003, 0, 5]).week(), 2, 'Jan 5 2003 should be week 2');
  27803. assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2');
  27804. assert.equal(moment([2003, 0, 12]).week(), 3, 'Jan 12 2003 should be week 3');
  27805. });
  27806. test('weeks year starting thursday', function (assert) {
  27807. assert.equal(moment([2008, 11, 28]).week(), 1, 'Dec 28 2008 should be week 1');
  27808. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  27809. assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1');
  27810. assert.equal(moment([2009, 0, 4]).week(), 2, 'Jan 4 2009 should be week 2');
  27811. assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2');
  27812. assert.equal(moment([2009, 0, 11]).week(), 3, 'Jan 11 2009 should be week 3');
  27813. });
  27814. test('weeks year starting friday', function (assert) {
  27815. assert.equal(moment([2009, 11, 27]).week(), 1, 'Dec 27 2009 should be week 1');
  27816. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  27817. assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 should be week 1');
  27818. assert.equal(moment([2010, 0, 3]).week(), 2, 'Jan 3 2010 should be week 2');
  27819. assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 should be week 2');
  27820. assert.equal(moment([2010, 0, 10]).week(), 3, 'Jan 10 2010 should be week 3');
  27821. });
  27822. test('weeks year starting saturday', function (assert) {
  27823. assert.equal(moment([2010, 11, 26]).week(), 1, 'Dec 26 2010 should be week 1');
  27824. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  27825. assert.equal(moment([2011, 0, 2]).week(), 2, 'Jan 2 2011 should be week 2');
  27826. assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2');
  27827. assert.equal(moment([2011, 0, 9]).week(), 3, 'Jan 9 2011 should be week 3');
  27828. });
  27829. test('weeks year starting sunday formatted', function (assert) {
  27830. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1వ', 'Jan 1 2012 should be week 1');
  27831. assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1వ', 'Jan 7 2012 should be week 1');
  27832. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2వ', 'Jan 8 2012 should be week 2');
  27833. assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2వ', 'Jan 14 2012 should be week 2');
  27834. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3వ', 'Jan 15 2012 should be week 3');
  27835. });
  27836. test('lenient ordinal parsing', function (assert) {
  27837. var i, ordinalStr, testMoment;
  27838. for (i = 1; i <= 31; ++i) {
  27839. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  27840. testMoment = moment(ordinalStr, 'YYYY MM Do');
  27841. assert.equal(testMoment.year(), 2014,
  27842. 'lenient ordinal parsing ' + i + ' year check');
  27843. assert.equal(testMoment.month(), 0,
  27844. 'lenient ordinal parsing ' + i + ' month check');
  27845. assert.equal(testMoment.date(), i,
  27846. 'lenient ordinal parsing ' + i + ' date check');
  27847. }
  27848. });
  27849. test('lenient ordinal parsing of number', function (assert) {
  27850. var i, testMoment;
  27851. for (i = 1; i <= 31; ++i) {
  27852. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  27853. assert.equal(testMoment.year(), 2014,
  27854. 'lenient ordinal parsing of number ' + i + ' year check');
  27855. assert.equal(testMoment.month(), 0,
  27856. 'lenient ordinal parsing of number ' + i + ' month check');
  27857. assert.equal(testMoment.date(), i,
  27858. 'lenient ordinal parsing of number ' + i + ' date check');
  27859. }
  27860. });
  27861. test('meridiem', function (assert) {
  27862. var h, m, t1, t2;
  27863. for (h = 0; h < 24; ++h) {
  27864. for (m = 0; m < 60; m += 15) {
  27865. t1 = moment.utc([2000, 0, 1, h, m]);
  27866. t2 = moment(t1.format('A h:mm'), 'A h:mm');
  27867. assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
  27868. 'meridiem at ' + t1.format('HH:mm'));
  27869. }
  27870. }
  27871. });
  27872. test('strict ordinal parsing', function (assert) {
  27873. var i, ordinalStr, testMoment;
  27874. for (i = 1; i <= 31; ++i) {
  27875. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  27876. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  27877. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  27878. }
  27879. });
  27880. }));
  27881. ;(function (global, factory) {
  27882. typeof exports === 'object' && typeof module !== 'undefined'
  27883. && typeof require === 'function' ? factory(require('../../moment')) :
  27884. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  27885. factory(global.moment)
  27886. }(this, function (moment) { 'use strict';
  27887. /*global QUnit:false*/
  27888. var test = QUnit.test;
  27889. var expect = QUnit.expect;
  27890. function module (name, lifecycle) {
  27891. QUnit.module(name, {
  27892. setup : function () {
  27893. moment.locale('en');
  27894. moment.createFromInputFallback = function (config) {
  27895. throw new Error('input not handled by moment: ' + config._i);
  27896. };
  27897. if (lifecycle && lifecycle.setup) {
  27898. lifecycle.setup();
  27899. }
  27900. },
  27901. teardown : function () {
  27902. if (lifecycle && lifecycle.teardown) {
  27903. lifecycle.teardown();
  27904. }
  27905. }
  27906. });
  27907. }
  27908. function localeModule (name, lifecycle) {
  27909. QUnit.module('locale:' + name, {
  27910. setup : function () {
  27911. moment.locale(name);
  27912. moment.createFromInputFallback = function (config) {
  27913. throw new Error('input not handled by moment: ' + config._i);
  27914. };
  27915. if (lifecycle && lifecycle.setup) {
  27916. lifecycle.setup();
  27917. }
  27918. },
  27919. teardown : function () {
  27920. moment.locale('en');
  27921. if (lifecycle && lifecycle.teardown) {
  27922. lifecycle.teardown();
  27923. }
  27924. }
  27925. });
  27926. }
  27927. localeModule('th');
  27928. test('parse', function (assert) {
  27929. var tests = 'มกราคม มกรา_กุมภาพันธ์ กุมภา_มีนาคม มีนา_เมษายน เมษา_พฤษภาคม พฤษภา_มิถุนายน มิถุนา_กรกฎาคม กรกฎา_สิงหาคม สิงหา_กันยายน กันยา_ตุลาคม ตุลา_พฤศจิกายน พฤศจิกา_ธันวาคม ธันวา'.split('_'), i;
  27930. function equalTest(input, mmm, i) {
  27931. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  27932. }
  27933. for (i = 0; i < 12; i++) {
  27934. tests[i] = tests[i].split(' ');
  27935. equalTest(tests[i][0], 'MMM', i);
  27936. equalTest(tests[i][1], 'MMM', i);
  27937. equalTest(tests[i][0], 'MMMM', i);
  27938. equalTest(tests[i][1], 'MMMM', i);
  27939. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  27940. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  27941. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  27942. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  27943. }
  27944. });
  27945. test('format', function (assert) {
  27946. var a = [
  27947. ['dddd, Do MMMM YYYY, h:mm:ss a', 'อาทิตย์, 14 กุมภาพันธ์ 2010, 3:25:50 หลังเที่ยง'],
  27948. ['ddd, h A', 'อาทิตย์, 3 หลังเที่ยง'],
  27949. ['M Mo MM MMMM MMM', '2 2 02 กุมภาพันธ์ กุมภา'],
  27950. ['YYYY YY', '2010 10'],
  27951. ['D Do DD', '14 14 14'],
  27952. ['d do dddd ddd dd', '0 0 อาทิตย์ อาทิตย์ อา.'],
  27953. ['DDD DDDo DDDD', '45 45 045'],
  27954. ['w wo ww', '8 8 08'],
  27955. ['h hh', '3 03'],
  27956. ['H HH', '15 15'],
  27957. ['m mm', '25 25'],
  27958. ['s ss', '50 50'],
  27959. ['a A', 'หลังเที่ยง หลังเที่ยง'],
  27960. ['[the] DDDo [day of the year]', 'the 45 day of the year'],
  27961. ['LTS', '15 นาฬิกา 25 นาที 50 วินาที'],
  27962. ['L', '2010/02/14'],
  27963. ['LL', '14 กุมภาพันธ์ 2010'],
  27964. ['LLL', '14 กุมภาพันธ์ 2010 เวลา 15 นาฬิกา 25 นาที'],
  27965. ['LLLL', 'วันอาทิตย์ที่ 14 กุมภาพันธ์ 2010 เวลา 15 นาฬิกา 25 นาที'],
  27966. ['l', '2010/2/14'],
  27967. ['ll', '14 กุมภา 2010'],
  27968. ['lll', '14 กุมภา 2010 เวลา 15 นาฬิกา 25 นาที'],
  27969. ['llll', 'วันอาทิตย์ที่ 14 กุมภา 2010 เวลา 15 นาฬิกา 25 นาที']
  27970. ],
  27971. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  27972. i;
  27973. for (i = 0; i < a.length; i++) {
  27974. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  27975. }
  27976. });
  27977. test('format month', function (assert) {
  27978. var expected = 'มกราคม มกรา_กุมภาพันธ์ กุมภา_มีนาคม มีนา_เมษายน เมษา_พฤษภาคม พฤษภา_มิถุนายน มิถุนา_กรกฎาคม กรกฎา_สิงหาคม สิงหา_กันยายน กันยา_ตุลาคม ตุลา_พฤศจิกายน พฤศจิกา_ธันวาคม ธันวา'.split('_'), i;
  27979. for (i = 0; i < expected.length; i++) {
  27980. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  27981. }
  27982. });
  27983. test('format week', function (assert) {
  27984. var expected = 'อาทิตย์ อาทิตย์ อา._จันทร์ จันทร์ จ._อังคาร อังคาร อ._พุธ พุธ พ._พฤหัสบดี พฤหัส พฤ._ศุกร์ ศุกร์ ศ._เสาร์ เสาร์ ส.'.split('_'), i;
  27985. for (i = 0; i < expected.length; i++) {
  27986. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  27987. }
  27988. });
  27989. test('from', function (assert) {
  27990. var start = moment([2007, 1, 28]);
  27991. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ไม่กี่วินาที', '44 seconds = a few seconds');
  27992. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), '1 นาที', '45 seconds = a minute');
  27993. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), '1 นาที', '89 seconds = a minute');
  27994. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 นาที', '90 seconds = 2 minutes');
  27995. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 นาที', '44 minutes = 44 minutes');
  27996. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), '1 ชั่วโมง', '45 minutes = an hour');
  27997. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), '1 ชั่วโมง', '89 minutes = an hour');
  27998. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 ชั่วโมง', '90 minutes = 2 hours');
  27999. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ชั่วโมง', '5 hours = 5 hours');
  28000. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 ชั่วโมง', '21 hours = 21 hours');
  28001. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), '1 วัน', '22 hours = a day');
  28002. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), '1 วัน', '35 hours = a day');
  28003. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 วัน', '36 hours = 2 days');
  28004. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), '1 วัน', '1 day = a day');
  28005. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 วัน', '5 days = 5 days');
  28006. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 วัน', '25 days = 25 days');
  28007. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), '1 เดือน', '26 days = a month');
  28008. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), '1 เดือน', '30 days = a month');
  28009. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), '1 เดือน', '43 days = a month');
  28010. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 เดือน', '46 days = 2 months');
  28011. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 เดือน', '75 days = 2 months');
  28012. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 เดือน', '76 days = 3 months');
  28013. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), '1 เดือน', '1 month = a month');
  28014. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 เดือน', '5 months = 5 months');
  28015. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), '1 ปี', '345 days = a year');
  28016. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 ปี', '548 days = 2 years');
  28017. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), '1 ปี', '1 year = a year');
  28018. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 ปี', '5 years = 5 years');
  28019. });
  28020. test('suffix', function (assert) {
  28021. assert.equal(moment(30000).from(0), 'อีก ไม่กี่วินาที', 'prefix');
  28022. assert.equal(moment(0).from(30000), 'ไม่กี่วินาทีที่แล้ว', 'suffix');
  28023. });
  28024. test('now from now', function (assert) {
  28025. assert.equal(moment().fromNow(), 'ไม่กี่วินาทีที่แล้ว', 'now from now should display as in the past');
  28026. });
  28027. test('fromNow', function (assert) {
  28028. assert.equal(moment().add({s: 30}).fromNow(), 'อีก ไม่กี่วินาที', 'in a few seconds');
  28029. assert.equal(moment().add({d: 5}).fromNow(), 'อีก 5 วัน', 'in 5 days');
  28030. });
  28031. test('calendar day', function (assert) {
  28032. var a = moment().hours(2).minutes(0).seconds(0);
  28033. assert.equal(moment(a).calendar(), 'วันนี้ เวลา 2 นาฬิกา 0 นาที', 'today at the same time');
  28034. assert.equal(moment(a).add({m: 25}).calendar(), 'วันนี้ เวลา 2 นาฬิกา 25 นาที', 'Now plus 25 min');
  28035. assert.equal(moment(a).add({h: 1}).calendar(), 'วันนี้ เวลา 3 นาฬิกา 0 นาที', 'Now plus 1 hour');
  28036. assert.equal(moment(a).add({d: 1}).calendar(), 'พรุ่งนี้ เวลา 2 นาฬิกา 0 นาที', 'tomorrow at the same time');
  28037. assert.equal(moment(a).subtract({h: 1}).calendar(), 'วันนี้ เวลา 1 นาฬิกา 0 นาที', 'Now minus 1 hour');
  28038. assert.equal(moment(a).subtract({d: 1}).calendar(), 'เมื่อวานนี้ เวลา 2 นาฬิกา 0 นาที', 'yesterday at the same time');
  28039. });
  28040. test('calendar next week', function (assert) {
  28041. var i, m;
  28042. for (i = 2; i < 7; i++) {
  28043. m = moment().add({d: i});
  28044. assert.equal(m.calendar(), m.format('dddd[หน้า เวลา] LT'), 'Today + ' + i + ' days current time');
  28045. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  28046. assert.equal(m.calendar(), m.format('dddd[หน้า เวลา] LT'), 'Today + ' + i + ' days beginning of day');
  28047. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  28048. assert.equal(m.calendar(), m.format('dddd[หน้า เวลา] LT'), 'Today + ' + i + ' days end of day');
  28049. }
  28050. });
  28051. test('calendar last week', function (assert) {
  28052. var i, m;
  28053. for (i = 2; i < 7; i++) {
  28054. m = moment().subtract({d: i});
  28055. assert.equal(m.calendar(), m.format('[วัน]dddd[ที่แล้ว เวลา] LT'), 'Today - ' + i + ' days current time');
  28056. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  28057. assert.equal(m.calendar(), m.format('[วัน]dddd[ที่แล้ว เวลา] LT'), 'Today - ' + i + ' days beginning of day');
  28058. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  28059. assert.equal(m.calendar(), m.format('[วัน]dddd[ที่แล้ว เวลา] LT'), 'Today - ' + i + ' days end of day');
  28060. }
  28061. });
  28062. test('calendar all else', function (assert) {
  28063. var weeksAgo = moment().subtract({w: 1}),
  28064. weeksFromNow = moment().add({w: 1});
  28065. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  28066. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  28067. weeksAgo = moment().subtract({w: 2});
  28068. weeksFromNow = moment().add({w: 2});
  28069. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  28070. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  28071. });
  28072. test('weeks year starting sunday', function (assert) {
  28073. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  28074. assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1');
  28075. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  28076. assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2');
  28077. assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 3');
  28078. });
  28079. test('weeks year starting monday', function (assert) {
  28080. assert.equal(moment([2006, 11, 31]).week(), 1, 'Dec 31 2006 should be week 1');
  28081. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  28082. assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1');
  28083. assert.equal(moment([2007, 0, 7]).week(), 2, 'Jan 7 2007 should be week 2');
  28084. assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2');
  28085. assert.equal(moment([2007, 0, 14]).week(), 3, 'Jan 14 2007 should be week 3');
  28086. });
  28087. test('weeks year starting tuesday', function (assert) {
  28088. assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52');
  28089. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  28090. assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1');
  28091. assert.equal(moment([2008, 0, 6]).week(), 2, 'Jan 6 2008 should be week 2');
  28092. assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2');
  28093. assert.equal(moment([2008, 0, 13]).week(), 3, 'Jan 13 2008 should be week 3');
  28094. });
  28095. test('weeks year starting wednesday', function (assert) {
  28096. assert.equal(moment([2002, 11, 29]).week(), 1, 'Dec 29 2002 should be week 1');
  28097. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  28098. assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1');
  28099. assert.equal(moment([2003, 0, 5]).week(), 2, 'Jan 5 2003 should be week 2');
  28100. assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2');
  28101. assert.equal(moment([2003, 0, 12]).week(), 3, 'Jan 12 2003 should be week 3');
  28102. });
  28103. test('weeks year starting thursday', function (assert) {
  28104. assert.equal(moment([2008, 11, 28]).week(), 1, 'Dec 28 2008 should be week 1');
  28105. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  28106. assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1');
  28107. assert.equal(moment([2009, 0, 4]).week(), 2, 'Jan 4 2009 should be week 2');
  28108. assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2');
  28109. assert.equal(moment([2009, 0, 11]).week(), 3, 'Jan 11 2009 should be week 3');
  28110. });
  28111. test('weeks year starting friday', function (assert) {
  28112. assert.equal(moment([2009, 11, 27]).week(), 1, 'Dec 27 2009 should be week 1');
  28113. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  28114. assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 should be week 1');
  28115. assert.equal(moment([2010, 0, 3]).week(), 2, 'Jan 3 2010 should be week 2');
  28116. assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 should be week 2');
  28117. assert.equal(moment([2010, 0, 10]).week(), 3, 'Jan 10 2010 should be week 3');
  28118. });
  28119. test('weeks year starting saturday', function (assert) {
  28120. assert.equal(moment([2010, 11, 26]).week(), 1, 'Dec 26 2010 should be week 1');
  28121. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  28122. assert.equal(moment([2011, 0, 2]).week(), 2, 'Jan 2 2011 should be week 2');
  28123. assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2');
  28124. assert.equal(moment([2011, 0, 9]).week(), 3, 'Jan 9 2011 should be week 3');
  28125. });
  28126. test('weeks year starting sunday format', function (assert) {
  28127. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1', 'Jan 1 2012 should be week 1');
  28128. assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1', 'Jan 7 2012 should be week 1');
  28129. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2', 'Jan 8 2012 should be week 2');
  28130. assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2', 'Jan 14 2012 should be week 2');
  28131. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3', 'Jan 15 2012 should be week 3');
  28132. });
  28133. test('lenient ordinal parsing', function (assert) {
  28134. var i, ordinalStr, testMoment;
  28135. for (i = 1; i <= 31; ++i) {
  28136. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  28137. testMoment = moment(ordinalStr, 'YYYY MM Do');
  28138. assert.equal(testMoment.year(), 2014,
  28139. 'lenient ordinal parsing ' + i + ' year check');
  28140. assert.equal(testMoment.month(), 0,
  28141. 'lenient ordinal parsing ' + i + ' month check');
  28142. assert.equal(testMoment.date(), i,
  28143. 'lenient ordinal parsing ' + i + ' date check');
  28144. }
  28145. });
  28146. test('lenient ordinal parsing of number', function (assert) {
  28147. var i, testMoment;
  28148. for (i = 1; i <= 31; ++i) {
  28149. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  28150. assert.equal(testMoment.year(), 2014,
  28151. 'lenient ordinal parsing of number ' + i + ' year check');
  28152. assert.equal(testMoment.month(), 0,
  28153. 'lenient ordinal parsing of number ' + i + ' month check');
  28154. assert.equal(testMoment.date(), i,
  28155. 'lenient ordinal parsing of number ' + i + ' date check');
  28156. }
  28157. });
  28158. test('strict ordinal parsing', function (assert) {
  28159. var i, ordinalStr, testMoment;
  28160. for (i = 1; i <= 31; ++i) {
  28161. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  28162. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  28163. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  28164. }
  28165. });
  28166. }));
  28167. ;(function (global, factory) {
  28168. typeof exports === 'object' && typeof module !== 'undefined'
  28169. && typeof require === 'function' ? factory(require('../../moment')) :
  28170. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  28171. factory(global.moment)
  28172. }(this, function (moment) { 'use strict';
  28173. /*global QUnit:false*/
  28174. var test = QUnit.test;
  28175. var expect = QUnit.expect;
  28176. function module (name, lifecycle) {
  28177. QUnit.module(name, {
  28178. setup : function () {
  28179. moment.locale('en');
  28180. moment.createFromInputFallback = function (config) {
  28181. throw new Error('input not handled by moment: ' + config._i);
  28182. };
  28183. if (lifecycle && lifecycle.setup) {
  28184. lifecycle.setup();
  28185. }
  28186. },
  28187. teardown : function () {
  28188. if (lifecycle && lifecycle.teardown) {
  28189. lifecycle.teardown();
  28190. }
  28191. }
  28192. });
  28193. }
  28194. function localeModule (name, lifecycle) {
  28195. QUnit.module('locale:' + name, {
  28196. setup : function () {
  28197. moment.locale(name);
  28198. moment.createFromInputFallback = function (config) {
  28199. throw new Error('input not handled by moment: ' + config._i);
  28200. };
  28201. if (lifecycle && lifecycle.setup) {
  28202. lifecycle.setup();
  28203. }
  28204. },
  28205. teardown : function () {
  28206. moment.locale('en');
  28207. if (lifecycle && lifecycle.teardown) {
  28208. lifecycle.teardown();
  28209. }
  28210. }
  28211. });
  28212. }
  28213. localeModule('tl-ph');
  28214. test('parse', function (assert) {
  28215. var tests = 'Enero Ene_Pebrero Peb_Marso Mar_Abril Abr_Mayo May_Hunyo Hun_Hulyo Hul_Agosto Ago_Setyembre Set_Oktubre Okt_Nobyembre Nob_Disyembre Dis'.split('_'),
  28216. i;
  28217. function equalTest(input, mmm, i) {
  28218. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  28219. }
  28220. for (i = 0; i < 12; i++) {
  28221. tests[i] = tests[i].split(' ');
  28222. equalTest(tests[i][0], 'MMM', i);
  28223. equalTest(tests[i][1], 'MMM', i);
  28224. equalTest(tests[i][0], 'MMMM', i);
  28225. equalTest(tests[i][1], 'MMMM', i);
  28226. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  28227. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  28228. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  28229. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  28230. }
  28231. });
  28232. test('format', function (assert) {
  28233. var a = [
  28234. ['dddd, MMMM Do YYYY, h:mm:ss a', 'Linggo, Pebrero 14 2010, 3:25:50 pm'],
  28235. ['ddd, hA', 'Lin, 3PM'],
  28236. ['M Mo MM MMMM MMM', '2 2 02 Pebrero Peb'],
  28237. ['YYYY YY', '2010 10'],
  28238. ['D Do DD', '14 14 14'],
  28239. ['d do dddd ddd dd', '0 0 Linggo Lin Li'],
  28240. ['DDD DDDo DDDD', '45 45 045'],
  28241. ['w wo ww', '6 6 06'],
  28242. ['h hh', '3 03'],
  28243. ['H HH', '15 15'],
  28244. ['m mm', '25 25'],
  28245. ['s ss', '50 50'],
  28246. ['a A', 'pm PM'],
  28247. ['[the] DDDo [day of the year]', 'the 45 day of the year'],
  28248. ['LTS', '15:25:50'],
  28249. ['L', '02/14/2010'],
  28250. ['LL', 'Pebrero 14, 2010'],
  28251. ['LLL', 'Pebrero 14, 2010 15:25'],
  28252. ['LLLL', 'Linggo, Pebrero 14, 2010 15:25'],
  28253. ['l', '2/14/2010'],
  28254. ['ll', 'Peb 14, 2010'],
  28255. ['lll', 'Peb 14, 2010 15:25'],
  28256. ['llll', 'Lin, Peb 14, 2010 15:25']
  28257. ],
  28258. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  28259. i;
  28260. for (i = 0; i < a.length; i++) {
  28261. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  28262. }
  28263. });
  28264. test('format ordinal', function (assert) {
  28265. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1');
  28266. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2');
  28267. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3');
  28268. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4');
  28269. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5');
  28270. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6');
  28271. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7');
  28272. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8');
  28273. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9');
  28274. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10');
  28275. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11');
  28276. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12');
  28277. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13');
  28278. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14');
  28279. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15');
  28280. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16');
  28281. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17');
  28282. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18');
  28283. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19');
  28284. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20');
  28285. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21');
  28286. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22');
  28287. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23');
  28288. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24');
  28289. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25');
  28290. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26');
  28291. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27');
  28292. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28');
  28293. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29');
  28294. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30');
  28295. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31');
  28296. });
  28297. test('format month', function (assert) {
  28298. var expected = 'Enero Ene_Pebrero Peb_Marso Mar_Abril Abr_Mayo May_Hunyo Hun_Hulyo Hul_Agosto Ago_Setyembre Set_Oktubre Okt_Nobyembre Nob_Disyembre Dis'.split('_'), i;
  28299. for (i = 0; i < expected.length; i++) {
  28300. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  28301. }
  28302. });
  28303. test('format week', function (assert) {
  28304. var expected = 'Linggo Lin Li_Lunes Lun Lu_Martes Mar Ma_Miyerkules Miy Mi_Huwebes Huw Hu_Biyernes Biy Bi_Sabado Sab Sab'.split('_'), i;
  28305. for (i = 0; i < expected.length; i++) {
  28306. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  28307. }
  28308. });
  28309. test('from', function (assert) {
  28310. var start = moment([2007, 1, 28]);
  28311. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ilang segundo', '44 seconds = a few seconds');
  28312. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'isang minuto', '45 seconds = a minute');
  28313. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'isang minuto', '89 seconds = a minute');
  28314. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuto', '90 seconds = 2 minutes');
  28315. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuto', '44 minutes = 44 minutes');
  28316. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'isang oras', '45 minutes = an hour');
  28317. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'isang oras', '89 minutes = an hour');
  28318. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 oras', '90 minutes = 2 hours');
  28319. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 oras', '5 hours = 5 hours');
  28320. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 oras', '21 hours = 21 hours');
  28321. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'isang araw', '22 hours = a day');
  28322. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'isang araw', '35 hours = a day');
  28323. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 araw', '36 hours = 2 days');
  28324. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'isang araw', '1 day = a day');
  28325. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 araw', '5 days = 5 days');
  28326. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 araw', '25 days = 25 days');
  28327. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'isang buwan', '26 days = a month');
  28328. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'isang buwan', '30 days = a month');
  28329. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'isang buwan', '43 days = a month');
  28330. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 buwan', '46 days = 2 months');
  28331. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 buwan', '75 days = 2 months');
  28332. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 buwan', '76 days = 3 months');
  28333. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'isang buwan', '1 month = a month');
  28334. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 buwan', '5 months = 5 months');
  28335. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'isang taon', '345 days = a year');
  28336. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 taon', '548 days = 2 years');
  28337. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'isang taon', '1 year = a year');
  28338. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 taon', '5 years = 5 years');
  28339. });
  28340. test('suffix', function (assert) {
  28341. assert.equal(moment(30000).from(0), 'sa loob ng ilang segundo', 'prefix');
  28342. assert.equal(moment(0).from(30000), 'ilang segundo ang nakalipas', 'suffix');
  28343. });
  28344. test('fromNow', function (assert) {
  28345. assert.equal(moment().add({s: 30}).fromNow(), 'sa loob ng ilang segundo', 'in a few seconds');
  28346. assert.equal(moment().add({d: 5}).fromNow(), 'sa loob ng 5 araw', 'in 5 days');
  28347. });
  28348. test('same day', function (assert) {
  28349. var a = moment().hours(2).minutes(0).seconds(0);
  28350. assert.equal(moment(a).calendar(), 'Ngayon sa 02:00', 'today at the same time');
  28351. assert.equal(moment(a).add({m: 25}).calendar(), 'Ngayon sa 02:25', 'Now plus 25 min');
  28352. assert.equal(moment(a).add({h: 1}).calendar(), 'Ngayon sa 03:00', 'Now plus 1 hour');
  28353. assert.equal(moment(a).add({d: 1}).calendar(), 'Bukas sa 02:00', 'tomorrow at the same time');
  28354. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Ngayon sa 01:00', 'Now minus 1 hour');
  28355. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Kahapon sa 02:00', 'yesterday at the same time');
  28356. });
  28357. test('same next week', function (assert) {
  28358. var i, m;
  28359. for (i = 2; i < 7; i++) {
  28360. m = moment().add({d: i});
  28361. assert.equal(m.calendar(), m.format('dddd [sa] LT'), 'Today + ' + i + ' days current time');
  28362. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  28363. assert.equal(m.calendar(), m.format('dddd [sa] LT'), 'Today + ' + i + ' days beginning of day');
  28364. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  28365. assert.equal(m.calendar(), m.format('dddd [sa] LT'), 'Today + ' + i + ' days end of day');
  28366. }
  28367. });
  28368. test('same last week', function (assert) {
  28369. var i, m;
  28370. for (i = 2; i < 7; i++) {
  28371. m = moment().subtract({d: i});
  28372. assert.equal(m.calendar(), m.format('dddd [huling linggo] LT'), 'Today - ' + i + ' days current time');
  28373. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  28374. assert.equal(m.calendar(), m.format('dddd [huling linggo] LT'), 'Today - ' + i + ' days beginning of day');
  28375. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  28376. assert.equal(m.calendar(), m.format('dddd [huling linggo] LT'), 'Today - ' + i + ' days end of day');
  28377. }
  28378. });
  28379. test('same all else', function (assert) {
  28380. var weeksAgo = moment().subtract({w: 1}),
  28381. weeksFromNow = moment().add({w: 1});
  28382. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  28383. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  28384. weeksAgo = moment().subtract({w: 2});
  28385. weeksFromNow = moment().add({w: 2});
  28386. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  28387. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  28388. });
  28389. test('weeks year starting sunday', function (assert) {
  28390. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  28391. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  28392. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  28393. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  28394. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  28395. });
  28396. test('weeks year starting monday', function (assert) {
  28397. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  28398. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  28399. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  28400. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  28401. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  28402. });
  28403. test('weeks year starting tuesday', function (assert) {
  28404. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  28405. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  28406. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  28407. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  28408. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  28409. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  28410. });
  28411. test('weeks year starting wednesday', function (assert) {
  28412. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  28413. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  28414. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  28415. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  28416. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  28417. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  28418. });
  28419. test('weeks year starting thursday', function (assert) {
  28420. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  28421. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  28422. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  28423. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  28424. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  28425. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  28426. });
  28427. test('weeks year starting friday', function (assert) {
  28428. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  28429. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  28430. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  28431. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  28432. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  28433. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  28434. });
  28435. test('weeks year starting saturday', function (assert) {
  28436. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  28437. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  28438. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  28439. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  28440. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  28441. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  28442. });
  28443. test('weeks year starting sunday formatted', function (assert) {
  28444. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52', 'Jan 1 2012 should be week 52');
  28445. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1', 'Jan 2 2012 should be week 1');
  28446. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1', 'Jan 8 2012 should be week 1');
  28447. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2', 'Jan 9 2012 should be week 2');
  28448. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2', 'Jan 15 2012 should be week 2');
  28449. });
  28450. test('lenient ordinal parsing', function (assert) {
  28451. var i, ordinalStr, testMoment;
  28452. for (i = 1; i <= 31; ++i) {
  28453. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  28454. testMoment = moment(ordinalStr, 'YYYY MM Do');
  28455. assert.equal(testMoment.year(), 2014,
  28456. 'lenient ordinal parsing ' + i + ' year check');
  28457. assert.equal(testMoment.month(), 0,
  28458. 'lenient ordinal parsing ' + i + ' month check');
  28459. assert.equal(testMoment.date(), i,
  28460. 'lenient ordinal parsing ' + i + ' date check');
  28461. }
  28462. });
  28463. test('lenient ordinal parsing of number', function (assert) {
  28464. var i, testMoment;
  28465. for (i = 1; i <= 31; ++i) {
  28466. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  28467. assert.equal(testMoment.year(), 2014,
  28468. 'lenient ordinal parsing of number ' + i + ' year check');
  28469. assert.equal(testMoment.month(), 0,
  28470. 'lenient ordinal parsing of number ' + i + ' month check');
  28471. assert.equal(testMoment.date(), i,
  28472. 'lenient ordinal parsing of number ' + i + ' date check');
  28473. }
  28474. });
  28475. test('strict ordinal parsing', function (assert) {
  28476. var i, ordinalStr, testMoment;
  28477. for (i = 1; i <= 31; ++i) {
  28478. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  28479. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  28480. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  28481. }
  28482. });
  28483. }));
  28484. ;(function (global, factory) {
  28485. typeof exports === 'object' && typeof module !== 'undefined'
  28486. && typeof require === 'function' ? factory(require('../../moment')) :
  28487. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  28488. factory(global.moment)
  28489. }(this, function (moment) { 'use strict';
  28490. /*global QUnit:false*/
  28491. var test = QUnit.test;
  28492. var expect = QUnit.expect;
  28493. function module (name, lifecycle) {
  28494. QUnit.module(name, {
  28495. setup : function () {
  28496. moment.locale('en');
  28497. moment.createFromInputFallback = function (config) {
  28498. throw new Error('input not handled by moment: ' + config._i);
  28499. };
  28500. if (lifecycle && lifecycle.setup) {
  28501. lifecycle.setup();
  28502. }
  28503. },
  28504. teardown : function () {
  28505. if (lifecycle && lifecycle.teardown) {
  28506. lifecycle.teardown();
  28507. }
  28508. }
  28509. });
  28510. }
  28511. function localeModule (name, lifecycle) {
  28512. QUnit.module('locale:' + name, {
  28513. setup : function () {
  28514. moment.locale(name);
  28515. moment.createFromInputFallback = function (config) {
  28516. throw new Error('input not handled by moment: ' + config._i);
  28517. };
  28518. if (lifecycle && lifecycle.setup) {
  28519. lifecycle.setup();
  28520. }
  28521. },
  28522. teardown : function () {
  28523. moment.locale('en');
  28524. if (lifecycle && lifecycle.teardown) {
  28525. lifecycle.teardown();
  28526. }
  28527. }
  28528. });
  28529. }
  28530. localeModule('tlh');
  28531. //Current parsing method doesn't allow parsing correctly months 10, 11 and 12.
  28532. /*
  28533. * test('parse', function (assert) {
  28534. var tests = 'tera’ jar wa’.jar wa’_tera’ jar cha’.jar cha’_tera’ jar wej.jar wej_tera’ jar loS.jar loS_tera’ jar vagh.jar vagh_tera’ jar jav.jar jav_tera’ jar Soch.jar Soch_tera’ jar chorgh.jar chorgh_tera’ jar Hut.jar Hut_tera’ jar wa’maH.jar wa’maH_tera’ jar wa’maH wa’.jar wa’maH wa’_tera’ jar wa’maH cha’.jar wa’maH cha’'.split('_'), i;
  28535. function equalTest(input, mmm, i) {
  28536. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  28537. }
  28538. for (i = 0; i < 12; i++) {
  28539. tests[i] = tests[i].split('.');
  28540. equalTest(tests[i][0], 'MMM', i);
  28541. equalTest(tests[i][1], 'MMM', i);
  28542. equalTest(tests[i][0], 'MMMM', i);
  28543. equalTest(tests[i][1], 'MMMM', i);
  28544. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  28545. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  28546. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  28547. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  28548. }
  28549. });
  28550. */
  28551. test('format', function (assert) {
  28552. var a = [
  28553. ['dddd, MMMM Do YYYY, h:mm:ss a', 'lojmItjaj, tera’ jar cha’ 14. 2010, 3:25:50 pm'],
  28554. ['ddd, hA', 'lojmItjaj, 3PM'],
  28555. ['M Mo MM MMMM MMM', '2 2. 02 tera’ jar cha’ jar cha’'],
  28556. ['YYYY YY', '2010 10'],
  28557. ['D Do DD', '14 14. 14'],
  28558. ['d do dddd ddd dd', '0 0. lojmItjaj lojmItjaj lojmItjaj'],
  28559. ['DDD DDDo DDDD', '45 45. 045'],
  28560. ['w wo ww', '6 6. 06'],
  28561. ['h hh', '3 03'],
  28562. ['H HH', '15 15'],
  28563. ['m mm', '25 25'],
  28564. ['s ss', '50 50'],
  28565. ['a A', 'pm PM'],
  28566. ['[DIS jaj] DDDo', 'DIS jaj 45.'],
  28567. ['LTS', '15:25:50'],
  28568. ['L', '14.02.2010'],
  28569. ['LL', '14 tera’ jar cha’ 2010'],
  28570. ['LLL', '14 tera’ jar cha’ 2010 15:25'],
  28571. ['LLLL', 'lojmItjaj, 14 tera’ jar cha’ 2010 15:25'],
  28572. ['l', '14.2.2010'],
  28573. ['ll', '14 jar cha’ 2010'],
  28574. ['lll', '14 jar cha’ 2010 15:25'],
  28575. ['llll', 'lojmItjaj, 14 jar cha’ 2010 15:25']
  28576. ],
  28577. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  28578. i;
  28579. for (i = 0; i < a.length; i++) {
  28580. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  28581. }
  28582. });
  28583. test('format ordinal', function (assert) {
  28584. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
  28585. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
  28586. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
  28587. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
  28588. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
  28589. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
  28590. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
  28591. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
  28592. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
  28593. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
  28594. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
  28595. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
  28596. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
  28597. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
  28598. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
  28599. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
  28600. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
  28601. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
  28602. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
  28603. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
  28604. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
  28605. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
  28606. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
  28607. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
  28608. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
  28609. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
  28610. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
  28611. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
  28612. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
  28613. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
  28614. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
  28615. });
  28616. test('format month', function (assert) {
  28617. var expected = 'tera’ jar wa’ jar wa’_tera’ jar cha’ jar cha’_tera’ jar wej jar wej_tera’ jar loS jar loS_tera’ jar vagh jar vagh_tera’ jar jav jar jav_tera’ jar Soch jar Soch_tera’ jar chorgh jar chorgh_tera’ jar Hut jar Hut_tera’ jar wa’maH jar wa’maH_tera’ jar wa’maH wa’ jar wa’maH wa’_tera’ jar wa’maH cha’ jar wa’maH cha’'.split('_'), i;
  28618. for (i = 0; i < expected.length; i++) {
  28619. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  28620. }
  28621. });
  28622. test('format week', function (assert) {
  28623. var expected = 'lojmItjaj lojmItjaj lojmItjaj_DaSjaj DaSjaj DaSjaj_povjaj povjaj povjaj_ghItlhjaj ghItlhjaj ghItlhjaj_loghjaj loghjaj loghjaj_buqjaj buqjaj buqjaj_ghInjaj ghInjaj ghInjaj'.split('_'), i;
  28624. for (i = 0; i < expected.length; i++) {
  28625. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  28626. }
  28627. });
  28628. test('from', function (assert) {
  28629. var start = moment([2007, 1, 28]);
  28630. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'puS lup', '44 seconds = a few seconds');
  28631. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'wa’ tup', '45 seconds = a minute');
  28632. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'wa’ tup', '89 seconds = a minute');
  28633. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), 'cha’ tup', '90 seconds = 2 minutes');
  28634. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), 'loSmaH loS tup', '44 minutes = 44 minutes');
  28635. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'wa’ rep', '45 minutes = an hour');
  28636. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'wa’ rep', '89 minutes = an hour');
  28637. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), 'cha’ rep', '90 minutes = 2 hours');
  28638. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), 'vagh rep', '5 hours = 5 hours');
  28639. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), 'cha’maH wa’ rep', '21 hours = 21 hours');
  28640. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'wa’ jaj', '22 hours = a day');
  28641. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'wa’ jaj', '35 hours = a day');
  28642. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), 'cha’ jaj', '36 hours = 2 days');
  28643. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'wa’ jaj', '1 day = a day');
  28644. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), 'vagh jaj', '5 days = 5 days');
  28645. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), 'cha’maH vagh jaj', '25 days = 25 days');
  28646. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'wa’ jar', '26 days = a month');
  28647. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'wa’ jar', '30 days = a month');
  28648. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'wa’ jar', '43 days = a month');
  28649. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), 'cha’ jar', '46 days = 2 months');
  28650. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), 'cha’ jar', '75 days = 2 months');
  28651. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), 'wej jar', '76 days = 3 months');
  28652. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'wa’ jar', '1 month = a month');
  28653. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), 'vagh jar', '5 months = 5 months');
  28654. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'wa’ DIS', '345 days = a year');
  28655. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), 'cha’ DIS', '548 days = 2 years');
  28656. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'wa’ DIS', '1 year = a year');
  28657. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), 'vagh DIS', '5 years = 5 years');
  28658. assert.equal(start.from(moment([2007, 1, 28]).add({y: 112}), true), 'wa’vatlh wa’maH cha’ DIS', '112 years = 112 years');
  28659. assert.equal(start.from(moment([2007, 1, 28]).add({y: 122}), true), 'wa’vatlh cha’maH cha’ DIS', '122 years = 122 years');
  28660. assert.equal(start.from(moment([2007, 1, 28]).add({y: 213}), true), 'cha’vatlh wa’maH wej DIS', '213 years = 213 years');
  28661. assert.equal(start.from(moment([2007, 1, 28]).add({y: 223}), true), 'cha’vatlh cha’maH wej DIS', '223 years = 223 years');
  28662. });
  28663. test('suffix', function (assert) {
  28664. assert.equal(moment(30000).from(0), 'puS lup pIq', 'suffix');
  28665. assert.equal(moment(0).from(30000), 'puS lup ret', 'suffix');
  28666. });
  28667. test('now from now', function (assert) {
  28668. assert.equal(moment().fromNow(), 'puS lup ret', 'now from now should display as in the past');
  28669. });
  28670. test('fromNow', function (assert) {
  28671. assert.equal(moment().add({s: 30}).fromNow(), 'puS lup pIq', 'in a few seconds');
  28672. assert.equal(moment().add({h: 1}).fromNow(), 'wa’ rep pIq', 'in an hour');
  28673. assert.equal(moment().add({d: 5}).fromNow(), 'vagh leS', 'in 5 days');
  28674. assert.equal(moment().add({M: 2}).fromNow(), 'cha’ waQ', 'in 2 months');
  28675. assert.equal(moment().add({y: 1}).fromNow(), 'wa’ nem', 'in a year');
  28676. assert.equal(moment().add({s: -30}).fromNow(), 'puS lup ret', 'a few seconds ago');
  28677. assert.equal(moment().add({h: -1}).fromNow(), 'wa’ rep ret', 'an hour ago');
  28678. assert.equal(moment().add({d: -5}).fromNow(), 'vagh Hu’', '5 days ago');
  28679. assert.equal(moment().add({M: -2}).fromNow(), 'cha’ wen', '2 months ago');
  28680. assert.equal(moment().add({y: -1}).fromNow(), 'wa’ ben', 'a year ago');
  28681. });
  28682. test('calendar day', function (assert) {
  28683. var a = moment().hours(2).minutes(0).seconds(0);
  28684. assert.equal(moment(a).calendar(), 'DaHjaj 02:00', 'today at the same time');
  28685. assert.equal(moment(a).add({m: 25}).calendar(), 'DaHjaj 02:25', 'Now plus 25 min');
  28686. assert.equal(moment(a).add({h: 1}).calendar(), 'DaHjaj 03:00', 'Now plus 1 hour');
  28687. assert.equal(moment(a).add({d: 1}).calendar(), 'wa’leS 02:00', 'tomorrow at the same time');
  28688. assert.equal(moment(a).subtract({h: 1}).calendar(), 'DaHjaj 01:00', 'Now minus 1 hour');
  28689. assert.equal(moment(a).subtract({d: 1}).calendar(), 'wa’Hu’ 02:00', 'yesterday at the same time');
  28690. });
  28691. test('calendar next week', function (assert) {
  28692. var i, m;
  28693. for (i = 2; i < 7; i++) {
  28694. m = moment().add({d: i});
  28695. assert.equal(m.calendar(), m.format('LLL'), 'Today + ' + i + ' days current time');
  28696. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  28697. assert.equal(m.calendar(), m.format('LLL'), 'Today + ' + i + ' days beginning of day');
  28698. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  28699. assert.equal(m.calendar(), m.format('LLL'), 'Today + ' + i + ' days end of day');
  28700. }
  28701. });
  28702. test('calendar last week', function (assert) {
  28703. var i, m;
  28704. for (i = 2; i < 7; i++) {
  28705. m = moment().subtract({d: i});
  28706. assert.equal(m.calendar(), m.format('LLL'), 'Today - ' + i + ' days current time');
  28707. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  28708. assert.equal(m.calendar(), m.format('LLL'), 'Today - ' + i + ' days beginning of day');
  28709. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  28710. assert.equal(m.calendar(), m.format('LLL'), 'Today - ' + i + ' days end of day');
  28711. }
  28712. });
  28713. test('calendar all else', function (assert) {
  28714. var weeksAgo = moment().subtract({w: 1}),
  28715. weeksFromNow = moment().add({w: 1});
  28716. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  28717. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  28718. weeksAgo = moment().subtract({w: 2});
  28719. weeksFromNow = moment().add({w: 2});
  28720. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  28721. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  28722. });
  28723. test('weeks year starting sunday', function (assert) {
  28724. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  28725. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  28726. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  28727. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  28728. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  28729. });
  28730. test('weeks year starting monday', function (assert) {
  28731. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  28732. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  28733. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  28734. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  28735. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  28736. });
  28737. test('weeks year starting tuesday', function (assert) {
  28738. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  28739. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  28740. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  28741. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  28742. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  28743. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  28744. });
  28745. test('weeks year starting wednesday', function (assert) {
  28746. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  28747. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  28748. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  28749. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  28750. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  28751. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  28752. });
  28753. test('weeks year starting thursday', function (assert) {
  28754. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  28755. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  28756. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  28757. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  28758. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  28759. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  28760. });
  28761. test('weeks year starting friday', function (assert) {
  28762. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  28763. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  28764. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  28765. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  28766. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  28767. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  28768. });
  28769. test('weeks year starting saturday', function (assert) {
  28770. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  28771. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  28772. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  28773. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  28774. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  28775. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  28776. });
  28777. test('weeks year starting sunday formatted', function (assert) {
  28778. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
  28779. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
  28780. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
  28781. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
  28782. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
  28783. });
  28784. test('lenient ordinal parsing', function (assert) {
  28785. var i, ordinalStr, testMoment;
  28786. for (i = 1; i <= 31; ++i) {
  28787. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  28788. testMoment = moment(ordinalStr, 'YYYY MM Do');
  28789. assert.equal(testMoment.year(), 2014,
  28790. 'lenient ordinal parsing ' + i + ' year check');
  28791. assert.equal(testMoment.month(), 0,
  28792. 'lenient ordinal parsing ' + i + ' month check');
  28793. assert.equal(testMoment.date(), i,
  28794. 'lenient ordinal parsing ' + i + ' date check');
  28795. }
  28796. });
  28797. test('lenient ordinal parsing of number', function (assert) {
  28798. var i, testMoment;
  28799. for (i = 1; i <= 31; ++i) {
  28800. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  28801. assert.equal(testMoment.year(), 2014,
  28802. 'lenient ordinal parsing of number ' + i + ' year check');
  28803. assert.equal(testMoment.month(), 0,
  28804. 'lenient ordinal parsing of number ' + i + ' month check');
  28805. assert.equal(testMoment.date(), i,
  28806. 'lenient ordinal parsing of number ' + i + ' date check');
  28807. }
  28808. });
  28809. test('strict ordinal parsing', function (assert) {
  28810. var i, ordinalStr, testMoment;
  28811. for (i = 1; i <= 31; ++i) {
  28812. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  28813. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  28814. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  28815. }
  28816. });
  28817. }));
  28818. ;(function (global, factory) {
  28819. typeof exports === 'object' && typeof module !== 'undefined'
  28820. && typeof require === 'function' ? factory(require('../../moment')) :
  28821. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  28822. factory(global.moment)
  28823. }(this, function (moment) { 'use strict';
  28824. /*global QUnit:false*/
  28825. var test = QUnit.test;
  28826. var expect = QUnit.expect;
  28827. function module (name, lifecycle) {
  28828. QUnit.module(name, {
  28829. setup : function () {
  28830. moment.locale('en');
  28831. moment.createFromInputFallback = function (config) {
  28832. throw new Error('input not handled by moment: ' + config._i);
  28833. };
  28834. if (lifecycle && lifecycle.setup) {
  28835. lifecycle.setup();
  28836. }
  28837. },
  28838. teardown : function () {
  28839. if (lifecycle && lifecycle.teardown) {
  28840. lifecycle.teardown();
  28841. }
  28842. }
  28843. });
  28844. }
  28845. function localeModule (name, lifecycle) {
  28846. QUnit.module('locale:' + name, {
  28847. setup : function () {
  28848. moment.locale(name);
  28849. moment.createFromInputFallback = function (config) {
  28850. throw new Error('input not handled by moment: ' + config._i);
  28851. };
  28852. if (lifecycle && lifecycle.setup) {
  28853. lifecycle.setup();
  28854. }
  28855. },
  28856. teardown : function () {
  28857. moment.locale('en');
  28858. if (lifecycle && lifecycle.teardown) {
  28859. lifecycle.teardown();
  28860. }
  28861. }
  28862. });
  28863. }
  28864. localeModule('tr');
  28865. test('parse', function (assert) {
  28866. var tests = 'Ocak Oca_Şubat Şub_Mart Mar_Nisan Nis_Mayıs May_Haziran Haz_Temmuz Tem_Ağustos Ağu_Eylül Eyl_Ekim Eki_Kasım Kas_Aralık Ara'.split('_'), i;
  28867. function equalTest(input, mmm, i) {
  28868. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  28869. }
  28870. for (i = 0; i < 12; i++) {
  28871. tests[i] = tests[i].split(' ');
  28872. equalTest(tests[i][0], 'MMM', i);
  28873. equalTest(tests[i][1], 'MMM', i);
  28874. equalTest(tests[i][0], 'MMMM', i);
  28875. equalTest(tests[i][1], 'MMMM', i);
  28876. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  28877. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  28878. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  28879. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  28880. }
  28881. });
  28882. test('format', function (assert) {
  28883. var a = [
  28884. ['dddd, MMMM Do YYYY, h:mm:ss a', 'Pazar, Şubat 14\'üncü 2010, 3:25:50 pm'],
  28885. ['ddd, hA', 'Paz, 3PM'],
  28886. ['M Mo MM MMMM MMM', '2 2\'nci 02 Şubat Şub'],
  28887. ['YYYY YY', '2010 10'],
  28888. ['D Do DD', '14 14\'üncü 14'],
  28889. ['d do dddd ddd dd', '0 0\'ıncı Pazar Paz Pz'],
  28890. ['DDD DDDo DDDD', '45 45\'inci 045'],
  28891. ['w wo ww', '7 7\'nci 07'],
  28892. ['h hh', '3 03'],
  28893. ['H HH', '15 15'],
  28894. ['m mm', '25 25'],
  28895. ['s ss', '50 50'],
  28896. ['a A', 'pm PM'],
  28897. ['[yılın] DDDo [günü]', 'yılın 45\'inci günü'],
  28898. ['LTS', '15:25:50'],
  28899. ['L', '14.02.2010'],
  28900. ['LL', '14 Şubat 2010'],
  28901. ['LLL', '14 Şubat 2010 15:25'],
  28902. ['LLLL', 'Pazar, 14 Şubat 2010 15:25'],
  28903. ['l', '14.2.2010'],
  28904. ['ll', '14 Şub 2010'],
  28905. ['lll', '14 Şub 2010 15:25'],
  28906. ['llll', 'Paz, 14 Şub 2010 15:25']
  28907. ],
  28908. DDDo = [
  28909. [359, '360\'ıncı'],
  28910. [199, '200\'üncü'],
  28911. [149, '150\'nci']
  28912. ],
  28913. dt = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  28914. DDDoDt,
  28915. i;
  28916. for (i = 0; i < a.length; i++) {
  28917. assert.equal(dt.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  28918. }
  28919. for (i = 0; i < DDDo.length; i++) {
  28920. DDDoDt = moment([2010]);
  28921. assert.equal(DDDoDt.add(DDDo[i][0], 'days').format('DDDo'), DDDo[i][1], DDDo[i][0] + ' ---> ' + DDDo[i][1]);
  28922. }
  28923. });
  28924. test('format ordinal', function (assert) {
  28925. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1\'inci', '1st');
  28926. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2\'nci', '2nd');
  28927. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3\'üncü', '3rd');
  28928. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4\'üncü', '4th');
  28929. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5\'inci', '5th');
  28930. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6\'ncı', '6th');
  28931. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7\'nci', '7th');
  28932. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8\'inci', '8th');
  28933. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9\'uncu', '9th');
  28934. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10\'uncu', '10th');
  28935. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11\'inci', '11th');
  28936. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12\'nci', '12th');
  28937. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13\'üncü', '13th');
  28938. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14\'üncü', '14th');
  28939. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15\'inci', '15th');
  28940. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16\'ncı', '16th');
  28941. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17\'nci', '17th');
  28942. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18\'inci', '18th');
  28943. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19\'uncu', '19th');
  28944. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20\'nci', '20th');
  28945. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21\'inci', '21th');
  28946. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22\'nci', '22th');
  28947. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23\'üncü', '23th');
  28948. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24\'üncü', '24th');
  28949. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25\'inci', '25th');
  28950. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26\'ncı', '26th');
  28951. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27\'nci', '27th');
  28952. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28\'inci', '28th');
  28953. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29\'uncu', '29th');
  28954. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30\'uncu', '30th');
  28955. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31\'inci', '31st');
  28956. });
  28957. test('format month', function (assert) {
  28958. var expected = 'Ocak Oca_Şubat Şub_Mart Mar_Nisan Nis_Mayıs May_Haziran Haz_Temmuz Tem_Ağustos Ağu_Eylül Eyl_Ekim Eki_Kasım Kas_Aralık Ara'.split('_'), i;
  28959. for (i = 0; i < expected.length; i++) {
  28960. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  28961. }
  28962. });
  28963. test('format week', function (assert) {
  28964. var expected = 'Pazar Paz Pz_Pazartesi Pts Pt_Salı Sal Sa_Çarşamba Çar Ça_Perşembe Per Pe_Cuma Cum Cu_Cumartesi Cts Ct'.split('_'), i;
  28965. for (i = 0; i < expected.length; i++) {
  28966. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  28967. }
  28968. });
  28969. test('from', function (assert) {
  28970. var start = moment([2007, 1, 28]);
  28971. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'birkaç saniye', '44 seconds = a few seconds');
  28972. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'bir dakika', '45 seconds = a minute');
  28973. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'bir dakika', '89 seconds = a minute');
  28974. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 dakika', '90 seconds = 2 minutes');
  28975. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 dakika', '44 minutes = 44 minutes');
  28976. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'bir saat', '45 minutes = an hour');
  28977. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'bir saat', '89 minutes = an hour');
  28978. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 saat', '90 minutes = 2 hours');
  28979. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 saat', '5 hours = 5 hours');
  28980. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 saat', '21 hours = 21 hours');
  28981. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'bir gün', '22 hours = a day');
  28982. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'bir gün', '35 hours = a day');
  28983. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 gün', '36 hours = 2 days');
  28984. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'bir gün', '1 day = a day');
  28985. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 gün', '5 days = 5 days');
  28986. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 gün', '25 days = 25 days');
  28987. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'bir ay', '26 days = a month');
  28988. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'bir ay', '30 days = a month');
  28989. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'bir ay', '43 days = a month');
  28990. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 ay', '46 days = 2 months');
  28991. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 ay', '75 days = 2 months');
  28992. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 ay', '76 days = 3 months');
  28993. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'bir ay', '1 month = a month');
  28994. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 ay', '5 months = 5 months');
  28995. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'bir yıl', '345 days = a year');
  28996. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 yıl', '548 days = 2 years');
  28997. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'bir yıl', '1 year = a year');
  28998. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 yıl', '5 years = 5 years');
  28999. });
  29000. test('suffix', function (assert) {
  29001. assert.equal(moment(30000).from(0), 'birkaç saniye sonra', 'prefix');
  29002. assert.equal(moment(0).from(30000), 'birkaç saniye önce', 'suffix');
  29003. });
  29004. test('now from now', function (assert) {
  29005. assert.equal(moment().fromNow(), 'birkaç saniye önce', 'now from now should display as in the past');
  29006. });
  29007. test('fromNow', function (assert) {
  29008. assert.equal(moment().add({s: 30}).fromNow(), 'birkaç saniye sonra', 'in a few seconds');
  29009. assert.equal(moment().add({d: 5}).fromNow(), '5 gün sonra', 'in 5 days');
  29010. });
  29011. test('calendar day', function (assert) {
  29012. var a = moment().hours(2).minutes(0).seconds(0);
  29013. assert.equal(moment(a).calendar(), 'bugün saat 02:00', 'today at the same time');
  29014. assert.equal(moment(a).add({m: 25}).calendar(), 'bugün saat 02:25', 'Now plus 25 min');
  29015. assert.equal(moment(a).add({h: 1}).calendar(), 'bugün saat 03:00', 'Now plus 1 hour');
  29016. assert.equal(moment(a).add({d: 1}).calendar(), 'yarın saat 02:00', 'tomorrow at the same time');
  29017. assert.equal(moment(a).subtract({h: 1}).calendar(), 'bugün saat 01:00', 'Now minus 1 hour');
  29018. assert.equal(moment(a).subtract({d: 1}).calendar(), 'dün 02:00', 'yesterday at the same time');
  29019. });
  29020. test('calendar next week', function (assert) {
  29021. var i, m;
  29022. for (i = 2; i < 7; i++) {
  29023. m = moment().add({d: i});
  29024. assert.equal(m.calendar(), m.format('[haftaya] dddd [saat] LT'), 'Today + ' + i + ' days current time');
  29025. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  29026. assert.equal(m.calendar(), m.format('[haftaya] dddd [saat] LT'), 'Today + ' + i + ' days beginning of day');
  29027. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  29028. assert.equal(m.calendar(), m.format('[haftaya] dddd [saat] LT'), 'Today + ' + i + ' days end of day');
  29029. }
  29030. });
  29031. test('calendar last week', function (assert) {
  29032. var i, m;
  29033. for (i = 2; i < 7; i++) {
  29034. m = moment().subtract({d: i});
  29035. assert.equal(m.calendar(), m.format('[geçen hafta] dddd [saat] LT'), 'Today - ' + i + ' days current time');
  29036. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  29037. assert.equal(m.calendar(), m.format('[geçen hafta] dddd [saat] LT'), 'Today - ' + i + ' days beginning of day');
  29038. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  29039. assert.equal(m.calendar(), m.format('[geçen hafta] dddd [saat] LT'), 'Today - ' + i + ' days end of day');
  29040. }
  29041. });
  29042. test('calendar all else', function (assert) {
  29043. var weeksAgo = moment().subtract({w: 1}),
  29044. weeksFromNow = moment().add({w: 1});
  29045. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  29046. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  29047. weeksAgo = moment().subtract({w: 2});
  29048. weeksFromNow = moment().add({w: 2});
  29049. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  29050. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  29051. });
  29052. test('weeks year starting sunday', function (assert) {
  29053. assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1');
  29054. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  29055. assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2');
  29056. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  29057. assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3');
  29058. });
  29059. test('weeks year starting monday', function (assert) {
  29060. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  29061. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  29062. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  29063. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  29064. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  29065. });
  29066. test('weeks year starting tuesday', function (assert) {
  29067. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  29068. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  29069. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  29070. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  29071. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  29072. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  29073. });
  29074. test('weeks year starting wednesday', function (assert) {
  29075. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  29076. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  29077. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  29078. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  29079. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  29080. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  29081. });
  29082. test('weeks year starting thursday', function (assert) {
  29083. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  29084. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  29085. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  29086. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  29087. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  29088. assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3');
  29089. });
  29090. test('weeks year starting friday', function (assert) {
  29091. assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1');
  29092. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  29093. assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1');
  29094. assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2');
  29095. assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2');
  29096. assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3');
  29097. });
  29098. test('weeks year starting saturday', function (assert) {
  29099. assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1');
  29100. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  29101. assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1');
  29102. assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2');
  29103. assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2');
  29104. assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3');
  29105. });
  29106. test('weeks year starting sunday formatted', function (assert) {
  29107. assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1\'inci', 'Dec 26 2011 should be week 1');
  29108. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1\'inci', 'Jan 1 2012 should be week 1');
  29109. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2\'nci', 'Jan 2 2012 should be week 2');
  29110. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2\'nci', 'Jan 8 2012 should be week 2');
  29111. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3\'üncü', 'Jan 9 2012 should be week 3');
  29112. });
  29113. test('lenient ordinal parsing', function (assert) {
  29114. var i, ordinalStr, testMoment;
  29115. for (i = 1; i <= 31; ++i) {
  29116. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  29117. testMoment = moment(ordinalStr, 'YYYY MM Do');
  29118. assert.equal(testMoment.year(), 2014,
  29119. 'lenient ordinal parsing ' + i + ' year check');
  29120. assert.equal(testMoment.month(), 0,
  29121. 'lenient ordinal parsing ' + i + ' month check');
  29122. assert.equal(testMoment.date(), i,
  29123. 'lenient ordinal parsing ' + i + ' date check');
  29124. }
  29125. });
  29126. test('lenient ordinal parsing of number', function (assert) {
  29127. var i, testMoment;
  29128. for (i = 1; i <= 31; ++i) {
  29129. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  29130. assert.equal(testMoment.year(), 2014,
  29131. 'lenient ordinal parsing of number ' + i + ' year check');
  29132. assert.equal(testMoment.month(), 0,
  29133. 'lenient ordinal parsing of number ' + i + ' month check');
  29134. assert.equal(testMoment.date(), i,
  29135. 'lenient ordinal parsing of number ' + i + ' date check');
  29136. }
  29137. });
  29138. test('strict ordinal parsing', function (assert) {
  29139. var i, ordinalStr, testMoment;
  29140. for (i = 1; i <= 31; ++i) {
  29141. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  29142. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  29143. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  29144. }
  29145. });
  29146. }));
  29147. ;(function (global, factory) {
  29148. typeof exports === 'object' && typeof module !== 'undefined'
  29149. && typeof require === 'function' ? factory(require('../../moment')) :
  29150. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  29151. factory(global.moment)
  29152. }(this, function (moment) { 'use strict';
  29153. /*global QUnit:false*/
  29154. var test = QUnit.test;
  29155. var expect = QUnit.expect;
  29156. function module (name, lifecycle) {
  29157. QUnit.module(name, {
  29158. setup : function () {
  29159. moment.locale('en');
  29160. moment.createFromInputFallback = function (config) {
  29161. throw new Error('input not handled by moment: ' + config._i);
  29162. };
  29163. if (lifecycle && lifecycle.setup) {
  29164. lifecycle.setup();
  29165. }
  29166. },
  29167. teardown : function () {
  29168. if (lifecycle && lifecycle.teardown) {
  29169. lifecycle.teardown();
  29170. }
  29171. }
  29172. });
  29173. }
  29174. function localeModule (name, lifecycle) {
  29175. QUnit.module('locale:' + name, {
  29176. setup : function () {
  29177. moment.locale(name);
  29178. moment.createFromInputFallback = function (config) {
  29179. throw new Error('input not handled by moment: ' + config._i);
  29180. };
  29181. if (lifecycle && lifecycle.setup) {
  29182. lifecycle.setup();
  29183. }
  29184. },
  29185. teardown : function () {
  29186. moment.locale('en');
  29187. if (lifecycle && lifecycle.teardown) {
  29188. lifecycle.teardown();
  29189. }
  29190. }
  29191. });
  29192. }
  29193. localeModule('tzl');
  29194. test('parse', function (assert) {
  29195. var tests = 'Januar Jan_Fevraglh Fev_Març Mar_Avrïu Avr_Mai Mai_Gün Gün_Julia Jul_Guscht Gus_Setemvar Set_Listopäts Lis_Noemvar Noe_Zecemvar Zec'.split('_'), i;
  29196. function equalTest(input, mmm, i) {
  29197. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  29198. }
  29199. for (i = 0; i < 12; i++) {
  29200. tests[i] = tests[i].split(' ');
  29201. equalTest(tests[i][0], 'MMM', i);
  29202. equalTest(tests[i][1], 'MMM', i);
  29203. equalTest(tests[i][0], 'MMMM', i);
  29204. equalTest(tests[i][1], 'MMMM', i);
  29205. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  29206. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  29207. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  29208. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  29209. }
  29210. });
  29211. test('format', function (assert) {
  29212. var a = [
  29213. ['dddd, MMMM Do YYYY, h.mm.ss a', 'Súladi, Fevraglh 14. 2010, 3.25.50 d\'o'],
  29214. ['ddd, hA', 'Súl, 3D\'O'],
  29215. ['M Mo MM MMMM MMM', '2 2. 02 Fevraglh Fev'],
  29216. ['YYYY YY', '2010 10'],
  29217. ['D Do DD', '14 14. 14'],
  29218. ['d do dddd ddd dd', '0 0. Súladi Súl Sú'],
  29219. ['DDD DDDo DDDD', '45 45. 045'],
  29220. ['w wo ww', '6 6. 06'],
  29221. ['h hh', '3 03'],
  29222. ['H HH', '15 15'],
  29223. ['m mm', '25 25'],
  29224. ['s ss', '50 50'],
  29225. ['a A', 'd\'o D\'O'],
  29226. ['[the] DDDo [day of the year]', 'the 45. day of the year'],
  29227. ['LTS', '15.25.50'],
  29228. ['L', '14.02.2010'],
  29229. ['LL', '14. Fevraglh dallas 2010'],
  29230. ['LLL', '14. Fevraglh dallas 2010 15.25'],
  29231. ['LLLL', 'Súladi, li 14. Fevraglh dallas 2010 15.25'],
  29232. ['l', '14.2.2010'],
  29233. ['ll', '14. Fev dallas 2010'],
  29234. ['lll', '14. Fev dallas 2010 15.25'],
  29235. ['llll', 'Súl, li 14. Fev dallas 2010 15.25']
  29236. ],
  29237. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  29238. i;
  29239. for (i = 0; i < a.length; i++) {
  29240. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  29241. }
  29242. });
  29243. test('format ordinal', function (assert) {
  29244. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
  29245. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
  29246. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
  29247. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
  29248. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
  29249. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
  29250. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
  29251. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
  29252. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
  29253. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
  29254. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
  29255. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
  29256. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
  29257. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
  29258. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
  29259. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
  29260. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
  29261. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
  29262. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
  29263. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
  29264. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
  29265. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
  29266. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
  29267. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
  29268. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
  29269. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
  29270. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
  29271. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
  29272. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
  29273. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
  29274. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
  29275. });
  29276. test('format month', function (assert) {
  29277. var expected = 'Januar Jan_Fevraglh Fev_Març Mar_Avrïu Avr_Mai Mai_Gün Gün_Julia Jul_Guscht Gus_Setemvar Set_Listopäts Lis_Noemvar Noe_Zecemvar Zec'.split('_'), i;
  29278. for (i = 0; i < expected.length; i++) {
  29279. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  29280. }
  29281. });
  29282. test('format week', function (assert) {
  29283. var expected = 'Súladi Súl Sú_Lúneçi Lún Lú_Maitzi Mai Ma_Márcuri Már Má_Xhúadi Xhú Xh_Viénerçi Vié Vi_Sáturi Sát Sá'.split('_'), i;
  29284. for (i = 0; i < expected.length; i++) {
  29285. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  29286. }
  29287. });
  29288. test('from', function (assert) {
  29289. var start = moment([2007, 1, 28]);
  29290. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'viensas secunds', '44 seconds = a few seconds');
  29291. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), '\'n míut', '45 seconds = a minute');
  29292. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), '\'n míut', '89 seconds = a minute');
  29293. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 míuts', '90 seconds = 2 minutes');
  29294. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 míuts', '44 minutes = 44 minutes');
  29295. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), '\'n þora', '45 minutes = an hour');
  29296. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), '\'n þora', '89 minutes = an hour');
  29297. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 þoras', '90 minutes = 2 hours');
  29298. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 þoras', '5 hours = 5 hours');
  29299. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 þoras', '21 hours = 21 hours');
  29300. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), '\'n ziua', '22 hours = a day');
  29301. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), '\'n ziua', '35 hours = a day');
  29302. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 ziuas', '36 hours = 2 days');
  29303. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), '\'n ziua', '1 day = a day');
  29304. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 ziuas', '5 days = 5 days');
  29305. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 ziuas', '25 days = 25 days');
  29306. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), '\'n mes', '26 days = a month');
  29307. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), '\'n mes', '30 days = a month');
  29308. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), '\'n mes', '43 days = a month');
  29309. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mesen', '46 days = 2 months');
  29310. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mesen', '75 days = 2 months');
  29311. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mesen', '76 days = 3 months');
  29312. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), '\'n mes', '1 month = a month');
  29313. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mesen', '5 months = 5 months');
  29314. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), '\'n ar', '345 days = a year');
  29315. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 ars', '548 days = 2 years');
  29316. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), '\'n ar', '1 year = a year');
  29317. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 ars', '5 years = 5 years');
  29318. });
  29319. test('suffix', function (assert) {
  29320. assert.equal(moment(30000).from(0), 'osprei viensas secunds', 'prefix');
  29321. assert.equal(moment(0).from(30000), 'ja\'iensas secunds', 'suffix');
  29322. });
  29323. test('now from now', function (assert) {
  29324. assert.equal(moment().fromNow(), 'ja\'iensas secunds', 'now from now should display as in the past');
  29325. });
  29326. test('fromNow', function (assert) {
  29327. assert.equal(moment().add({s: 30}).fromNow(), 'osprei viensas secunds', 'in a few seconds');
  29328. assert.equal(moment().add({d: 5}).fromNow(), 'osprei 5 ziuas', 'in 5 days');
  29329. });
  29330. test('calendar day', function (assert) {
  29331. var a = moment().hours(2).minutes(0).seconds(0);
  29332. assert.equal(moment(a).calendar(), 'oxhi à 02.00', 'today at the same time');
  29333. assert.equal(moment(a).add({m: 25}).calendar(), 'oxhi à 02.25', 'Now plus 25 min');
  29334. assert.equal(moment(a).add({h: 1}).calendar(), 'oxhi à 03.00', 'Now plus 1 hour');
  29335. assert.equal(moment(a).add({d: 1}).calendar(), 'demà à 02.00', 'tomorrow at the same time');
  29336. assert.equal(moment(a).subtract({h: 1}).calendar(), 'oxhi à 01.00', 'Now minus 1 hour');
  29337. assert.equal(moment(a).subtract({d: 1}).calendar(), 'ieiri à 02.00', 'yesterday at the same time');
  29338. });
  29339. test('calendar next week', function (assert) {
  29340. var i, m;
  29341. for (i = 2; i < 7; i++) {
  29342. m = moment().add({d: i});
  29343. assert.equal(m.calendar(), m.format('dddd [à] LT'), 'Today + ' + i + ' days current time');
  29344. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  29345. assert.equal(m.calendar(), m.format('dddd [à] LT'), 'Today + ' + i + ' days beginning of day');
  29346. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  29347. assert.equal(m.calendar(), m.format('dddd [à] LT'), 'Today + ' + i + ' days end of day');
  29348. }
  29349. });
  29350. test('calendar last week', function (assert) {
  29351. var i, m;
  29352. for (i = 2; i < 7; i++) {
  29353. m = moment().subtract({d: i});
  29354. assert.equal(m.calendar(), m.format('[sür el] dddd [lasteu à] LT'), 'Today - ' + i + ' days current time');
  29355. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  29356. assert.equal(m.calendar(), m.format('[sür el] dddd [lasteu à] LT'), 'Today - ' + i + ' days beginning of day');
  29357. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  29358. assert.equal(m.calendar(), m.format('[sür el] dddd [lasteu à] LT'), 'Today - ' + i + ' days end of day');
  29359. }
  29360. });
  29361. test('calendar all else', function (assert) {
  29362. var weeksAgo = moment().subtract({w: 1}),
  29363. weeksFromNow = moment().add({w: 1});
  29364. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  29365. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  29366. weeksAgo = moment().subtract({w: 2});
  29367. weeksFromNow = moment().add({w: 2});
  29368. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  29369. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  29370. });
  29371. // Monday is the first day of the week.
  29372. // The week that contains Jan 4th is the first week of the year.
  29373. test('weeks year starting sunday', function (assert) {
  29374. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  29375. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  29376. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  29377. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  29378. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  29379. });
  29380. test('weeks year starting monday', function (assert) {
  29381. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  29382. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  29383. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  29384. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  29385. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  29386. });
  29387. test('weeks year starting tuesday', function (assert) {
  29388. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  29389. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  29390. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  29391. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  29392. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  29393. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  29394. });
  29395. test('weeks year starting wednesday', function (assert) {
  29396. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  29397. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  29398. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  29399. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  29400. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  29401. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  29402. });
  29403. test('weeks year starting thursday', function (assert) {
  29404. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  29405. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  29406. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  29407. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  29408. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  29409. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  29410. });
  29411. test('weeks year starting friday', function (assert) {
  29412. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  29413. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  29414. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  29415. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  29416. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  29417. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  29418. });
  29419. test('weeks year starting saturday', function (assert) {
  29420. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  29421. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  29422. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  29423. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  29424. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  29425. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  29426. });
  29427. test('weeks year starting sunday formatted', function (assert) {
  29428. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
  29429. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
  29430. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
  29431. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
  29432. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
  29433. });
  29434. test('lenient ordinal parsing', function (assert) {
  29435. var i, ordinalStr, testMoment;
  29436. for (i = 1; i <= 31; ++i) {
  29437. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  29438. testMoment = moment(ordinalStr, 'YYYY MM Do');
  29439. assert.equal(testMoment.year(), 2014,
  29440. 'lenient ordinal parsing ' + i + ' year check');
  29441. assert.equal(testMoment.month(), 0,
  29442. 'lenient ordinal parsing ' + i + ' month check');
  29443. assert.equal(testMoment.date(), i,
  29444. 'lenient ordinal parsing ' + i + ' date check');
  29445. }
  29446. });
  29447. test('lenient ordinal parsing of number', function (assert) {
  29448. var i, testMoment;
  29449. for (i = 1; i <= 31; ++i) {
  29450. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  29451. assert.equal(testMoment.year(), 2014,
  29452. 'lenient ordinal parsing of number ' + i + ' year check');
  29453. assert.equal(testMoment.month(), 0,
  29454. 'lenient ordinal parsing of number ' + i + ' month check');
  29455. assert.equal(testMoment.date(), i,
  29456. 'lenient ordinal parsing of number ' + i + ' date check');
  29457. }
  29458. });
  29459. test('strict ordinal parsing', function (assert) {
  29460. var i, ordinalStr, testMoment;
  29461. for (i = 1; i <= 31; ++i) {
  29462. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  29463. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  29464. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  29465. }
  29466. });
  29467. }));
  29468. ;(function (global, factory) {
  29469. typeof exports === 'object' && typeof module !== 'undefined'
  29470. && typeof require === 'function' ? factory(require('../../moment')) :
  29471. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  29472. factory(global.moment)
  29473. }(this, function (moment) { 'use strict';
  29474. /*global QUnit:false*/
  29475. var test = QUnit.test;
  29476. var expect = QUnit.expect;
  29477. function module (name, lifecycle) {
  29478. QUnit.module(name, {
  29479. setup : function () {
  29480. moment.locale('en');
  29481. moment.createFromInputFallback = function (config) {
  29482. throw new Error('input not handled by moment: ' + config._i);
  29483. };
  29484. if (lifecycle && lifecycle.setup) {
  29485. lifecycle.setup();
  29486. }
  29487. },
  29488. teardown : function () {
  29489. if (lifecycle && lifecycle.teardown) {
  29490. lifecycle.teardown();
  29491. }
  29492. }
  29493. });
  29494. }
  29495. function localeModule (name, lifecycle) {
  29496. QUnit.module('locale:' + name, {
  29497. setup : function () {
  29498. moment.locale(name);
  29499. moment.createFromInputFallback = function (config) {
  29500. throw new Error('input not handled by moment: ' + config._i);
  29501. };
  29502. if (lifecycle && lifecycle.setup) {
  29503. lifecycle.setup();
  29504. }
  29505. },
  29506. teardown : function () {
  29507. moment.locale('en');
  29508. if (lifecycle && lifecycle.teardown) {
  29509. lifecycle.teardown();
  29510. }
  29511. }
  29512. });
  29513. }
  29514. localeModule('tzm-latn');
  29515. test('parse', function (assert) {
  29516. var tests = 'innayr innayr_brˤayrˤ brˤayrˤ_marˤsˤ marˤsˤ_ibrir ibrir_mayyw mayyw_ywnyw ywnyw_ywlywz ywlywz_ɣwšt ɣwšt_šwtanbir šwtanbir_ktˤwbrˤ ktˤwbrˤ_nwwanbir nwwanbir_dwjnbir dwjnbir'.split('_'), i;
  29517. function equalTest(input, mmm, i) {
  29518. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  29519. }
  29520. for (i = 0; i < 12; i++) {
  29521. tests[i] = tests[i].split(' ');
  29522. equalTest(tests[i][0], 'MMM', i);
  29523. equalTest(tests[i][1], 'MMM', i);
  29524. equalTest(tests[i][0], 'MMMM', i);
  29525. equalTest(tests[i][1], 'MMMM', i);
  29526. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  29527. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  29528. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  29529. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  29530. }
  29531. });
  29532. test('format', function (assert) {
  29533. var a = [
  29534. ['dddd, MMMM Do YYYY, h:mm:ss a', 'asamas, brˤayrˤ 14 2010, 3:25:50 pm'],
  29535. ['ddd, hA', 'asamas, 3PM'],
  29536. ['M Mo MM MMMM MMM', '2 2 02 brˤayrˤ brˤayrˤ'],
  29537. ['YYYY YY', '2010 10'],
  29538. ['D Do DD', '14 14 14'],
  29539. ['d do dddd ddd dd', '0 0 asamas asamas asamas'],
  29540. ['DDD DDDo DDDD', '45 45 045'],
  29541. ['w wo ww', '8 8 08'],
  29542. ['h hh', '3 03'],
  29543. ['H HH', '15 15'],
  29544. ['m mm', '25 25'],
  29545. ['s ss', '50 50'],
  29546. ['a A', 'pm PM'],
  29547. ['[the] DDDo [day of the year]', 'the 45 day of the year'],
  29548. ['LTS', '15:25:50'],
  29549. ['L', '14/02/2010'],
  29550. ['LL', '14 brˤayrˤ 2010'],
  29551. ['LLL', '14 brˤayrˤ 2010 15:25'],
  29552. ['LLLL', 'asamas 14 brˤayrˤ 2010 15:25'],
  29553. ['l', '14/2/2010'],
  29554. ['ll', '14 brˤayrˤ 2010'],
  29555. ['lll', '14 brˤayrˤ 2010 15:25'],
  29556. ['llll', 'asamas 14 brˤayrˤ 2010 15:25']
  29557. ],
  29558. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  29559. i;
  29560. for (i = 0; i < a.length; i++) {
  29561. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  29562. }
  29563. });
  29564. test('format ordinal', function (assert) {
  29565. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1');
  29566. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2');
  29567. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3');
  29568. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4');
  29569. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5');
  29570. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6');
  29571. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7');
  29572. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8');
  29573. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9');
  29574. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10');
  29575. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11');
  29576. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12');
  29577. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13');
  29578. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14');
  29579. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15');
  29580. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16');
  29581. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17');
  29582. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18');
  29583. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19');
  29584. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20');
  29585. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21');
  29586. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22');
  29587. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23');
  29588. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24');
  29589. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25');
  29590. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26');
  29591. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27');
  29592. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28');
  29593. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29');
  29594. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30');
  29595. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31');
  29596. });
  29597. test('format month', function (assert) {
  29598. var expected = 'innayr innayr_brˤayrˤ brˤayrˤ_marˤsˤ marˤsˤ_ibrir ibrir_mayyw mayyw_ywnyw ywnyw_ywlywz ywlywz_ɣwšt ɣwšt_šwtanbir šwtanbir_ktˤwbrˤ ktˤwbrˤ_nwwanbir nwwanbir_dwjnbir dwjnbir'.split('_'), i;
  29599. for (i = 0; i < expected.length; i++) {
  29600. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  29601. }
  29602. });
  29603. test('format week', function (assert) {
  29604. var expected = 'asamas asamas asamas_aynas aynas aynas_asinas asinas asinas_akras akras akras_akwas akwas akwas_asimwas asimwas asimwas_asiḍyas asiḍyas asiḍyas'.split('_'), i;
  29605. for (i = 0; i < expected.length; i++) {
  29606. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  29607. }
  29608. });
  29609. test('from', function (assert) {
  29610. var start = moment([2007, 1, 28]);
  29611. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'imik', '44 seconds = a few seconds');
  29612. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'minuḍ', '45 seconds = a minute');
  29613. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'minuḍ', '89 seconds = a minute');
  29614. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuḍ', '90 seconds = 2 minutes');
  29615. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuḍ', '44 minutes = 44 minutes');
  29616. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'saɛa', '45 minutes = an hour');
  29617. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'saɛa', '89 minutes = an hour');
  29618. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 tassaɛin', '90 minutes = 2 hours');
  29619. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 tassaɛin', '5 hours = 5 hours');
  29620. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 tassaɛin', '21 hours = 21 hours');
  29621. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ass', '22 hours = a day');
  29622. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ass', '35 hours = a day');
  29623. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 ossan', '36 hours = 2 days');
  29624. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ass', '1 day = a day');
  29625. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 ossan', '5 days = 5 days');
  29626. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 ossan', '25 days = 25 days');
  29627. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ayowr', '26 days = a month');
  29628. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ayowr', '30 days = a month');
  29629. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ayowr', '43 days = a month');
  29630. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 iyyirn', '46 days = 2 months');
  29631. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 iyyirn', '75 days = 2 months');
  29632. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 iyyirn', '76 days = 3 months');
  29633. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ayowr', '1 month = a month');
  29634. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 iyyirn', '5 months = 5 months');
  29635. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'asgas', '345 days = a year');
  29636. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 isgasn', '548 days = 2 years');
  29637. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'asgas', '1 year = a year');
  29638. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 isgasn', '5 years = 5 years');
  29639. });
  29640. test('suffix', function (assert) {
  29641. assert.equal(moment(30000).from(0), 'dadkh s yan imik', 'prefix');
  29642. assert.equal(moment(0).from(30000), 'yan imik', 'suffix');
  29643. });
  29644. test('now from now', function (assert) {
  29645. assert.equal(moment().fromNow(), 'yan imik', 'now from now should display as in the past');
  29646. });
  29647. test('fromNow', function (assert) {
  29648. assert.equal(moment().add({s: 30}).fromNow(), 'dadkh s yan imik', 'in a few seconds');
  29649. assert.equal(moment().add({d: 5}).fromNow(), 'dadkh s yan 5 ossan', 'in 5 days');
  29650. });
  29651. test('calendar day', function (assert) {
  29652. var a = moment().hours(2).minutes(0).seconds(0);
  29653. assert.equal(moment(a).calendar(), 'asdkh g 02:00', 'today at the same time');
  29654. assert.equal(moment(a).add({m: 25}).calendar(), 'asdkh g 02:25', 'Now plus 25 min');
  29655. assert.equal(moment(a).add({h: 1}).calendar(), 'asdkh g 03:00', 'Now plus 1 hour');
  29656. assert.equal(moment(a).add({d: 1}).calendar(), 'aska g 02:00', 'tomorrow at the same time');
  29657. assert.equal(moment(a).subtract({h: 1}).calendar(), 'asdkh g 01:00', 'Now minus 1 hour');
  29658. assert.equal(moment(a).subtract({d: 1}).calendar(), 'assant g 02:00', 'yesterday at the same time');
  29659. });
  29660. test('calendar next week', function (assert) {
  29661. var i, m;
  29662. for (i = 2; i < 7; i++) {
  29663. m = moment().add({d: i});
  29664. assert.equal(m.calendar(), m.format('dddd [g] LT'), 'Today + ' + i + ' days current time');
  29665. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  29666. assert.equal(m.calendar(), m.format('dddd [g] LT'), 'Today + ' + i + ' days beginning of day');
  29667. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  29668. assert.equal(m.calendar(), m.format('dddd [g] LT'), 'Today + ' + i + ' days end of day');
  29669. }
  29670. });
  29671. test('calendar last week', function (assert) {
  29672. var i, m;
  29673. for (i = 2; i < 7; i++) {
  29674. m = moment().subtract({d: i});
  29675. assert.equal(m.calendar(), m.format('dddd [g] LT'), 'Today - ' + i + ' days current time');
  29676. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  29677. assert.equal(m.calendar(), m.format('dddd [g] LT'), 'Today - ' + i + ' days beginning of day');
  29678. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  29679. assert.equal(m.calendar(), m.format('dddd [g] LT'), 'Today - ' + i + ' days end of day');
  29680. }
  29681. });
  29682. test('calendar all else', function (assert) {
  29683. var weeksAgo = moment().subtract({w: 1}),
  29684. weeksFromNow = moment().add({w: 1});
  29685. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  29686. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  29687. weeksAgo = moment().subtract({w: 2});
  29688. weeksFromNow = moment().add({w: 2});
  29689. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  29690. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  29691. });
  29692. test('weeks year starting sunday', function (assert) {
  29693. assert.equal(moment([2011, 11, 31]).week(), 1, 'Dec 31 2011 should be week 1');
  29694. assert.equal(moment([2012, 0, 6]).week(), 1, 'Jan 6 2012 should be week 1');
  29695. assert.equal(moment([2012, 0, 7]).week(), 2, 'Jan 7 2012 should be week 2');
  29696. assert.equal(moment([2012, 0, 13]).week(), 2, 'Jan 13 2012 should be week 2');
  29697. assert.equal(moment([2012, 0, 14]).week(), 3, 'Jan 14 2012 should be week 3');
  29698. });
  29699. test('weeks year starting monday', function (assert) {
  29700. assert.equal(moment([2006, 11, 30]).week(), 1, 'Dec 30 2006 should be week 1');
  29701. assert.equal(moment([2007, 0, 5]).week(), 1, 'Jan 5 2007 should be week 1');
  29702. assert.equal(moment([2007, 0, 6]).week(), 2, 'Jan 6 2007 should be week 2');
  29703. assert.equal(moment([2007, 0, 12]).week(), 2, 'Jan 12 2007 should be week 2');
  29704. assert.equal(moment([2007, 0, 13]).week(), 3, 'Jan 13 2007 should be week 3');
  29705. });
  29706. test('weeks year starting tuesday', function (assert) {
  29707. assert.equal(moment([2007, 11, 29]).week(), 1, 'Dec 29 2007 should be week 1');
  29708. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  29709. assert.equal(moment([2008, 0, 4]).week(), 1, 'Jan 4 2008 should be week 1');
  29710. assert.equal(moment([2008, 0, 5]).week(), 2, 'Jan 5 2008 should be week 2');
  29711. assert.equal(moment([2008, 0, 11]).week(), 2, 'Jan 11 2008 should be week 2');
  29712. assert.equal(moment([2008, 0, 12]).week(), 3, 'Jan 12 2008 should be week 3');
  29713. });
  29714. test('weeks year starting wednesday', function (assert) {
  29715. assert.equal(moment([2002, 11, 28]).week(), 1, 'Dec 28 2002 should be week 1');
  29716. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  29717. assert.equal(moment([2003, 0, 3]).week(), 1, 'Jan 3 2003 should be week 1');
  29718. assert.equal(moment([2003, 0, 4]).week(), 2, 'Jan 4 2003 should be week 2');
  29719. assert.equal(moment([2003, 0, 10]).week(), 2, 'Jan 10 2003 should be week 2');
  29720. assert.equal(moment([2003, 0, 11]).week(), 3, 'Jan 11 2003 should be week 3');
  29721. });
  29722. test('weeks year starting thursday', function (assert) {
  29723. assert.equal(moment([2008, 11, 27]).week(), 1, 'Dec 27 2008 should be week 1');
  29724. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  29725. assert.equal(moment([2009, 0, 2]).week(), 1, 'Jan 2 2009 should be week 1');
  29726. assert.equal(moment([2009, 0, 3]).week(), 2, 'Jan 3 2009 should be week 2');
  29727. assert.equal(moment([2009, 0, 9]).week(), 2, 'Jan 9 2009 should be week 2');
  29728. assert.equal(moment([2009, 0, 10]).week(), 3, 'Jan 10 2009 should be week 3');
  29729. });
  29730. test('weeks year starting friday', function (assert) {
  29731. assert.equal(moment([2009, 11, 26]).week(), 1, 'Dec 26 2009 should be week 1');
  29732. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  29733. assert.equal(moment([2010, 0, 2]).week(), 2, 'Jan 2 2010 should be week 2');
  29734. assert.equal(moment([2010, 0, 8]).week(), 2, 'Jan 8 2010 should be week 2');
  29735. assert.equal(moment([2010, 0, 9]).week(), 3, 'Jan 9 2010 should be week 3');
  29736. });
  29737. test('weeks year starting saturday', function (assert) {
  29738. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  29739. assert.equal(moment([2011, 0, 7]).week(), 1, 'Jan 7 2011 should be week 1');
  29740. assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2');
  29741. assert.equal(moment([2011, 0, 14]).week(), 2, 'Jan 14 2011 should be week 2');
  29742. assert.equal(moment([2011, 0, 15]).week(), 3, 'Jan 15 2011 should be week 3');
  29743. });
  29744. test('weeks year starting sunday formatted', function (assert) {
  29745. assert.equal(moment([2011, 11, 31]).format('w ww wo'), '1 01 1', 'Dec 31 2011 should be week 1');
  29746. assert.equal(moment([2012, 0, 6]).format('w ww wo'), '1 01 1', 'Jan 6 2012 should be week 1');
  29747. assert.equal(moment([2012, 0, 7]).format('w ww wo'), '2 02 2', 'Jan 7 2012 should be week 2');
  29748. assert.equal(moment([2012, 0, 13]).format('w ww wo'), '2 02 2', 'Jan 13 2012 should be week 2');
  29749. assert.equal(moment([2012, 0, 14]).format('w ww wo'), '3 03 3', 'Jan 14 2012 should be week 3');
  29750. });
  29751. test('lenient ordinal parsing', function (assert) {
  29752. var i, ordinalStr, testMoment;
  29753. for (i = 1; i <= 31; ++i) {
  29754. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  29755. testMoment = moment(ordinalStr, 'YYYY MM Do');
  29756. assert.equal(testMoment.year(), 2014,
  29757. 'lenient ordinal parsing ' + i + ' year check');
  29758. assert.equal(testMoment.month(), 0,
  29759. 'lenient ordinal parsing ' + i + ' month check');
  29760. assert.equal(testMoment.date(), i,
  29761. 'lenient ordinal parsing ' + i + ' date check');
  29762. }
  29763. });
  29764. test('lenient ordinal parsing of number', function (assert) {
  29765. var i, testMoment;
  29766. for (i = 1; i <= 31; ++i) {
  29767. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  29768. assert.equal(testMoment.year(), 2014,
  29769. 'lenient ordinal parsing of number ' + i + ' year check');
  29770. assert.equal(testMoment.month(), 0,
  29771. 'lenient ordinal parsing of number ' + i + ' month check');
  29772. assert.equal(testMoment.date(), i,
  29773. 'lenient ordinal parsing of number ' + i + ' date check');
  29774. }
  29775. });
  29776. test('strict ordinal parsing', function (assert) {
  29777. var i, ordinalStr, testMoment;
  29778. for (i = 1; i <= 31; ++i) {
  29779. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  29780. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  29781. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  29782. }
  29783. });
  29784. }));
  29785. ;(function (global, factory) {
  29786. typeof exports === 'object' && typeof module !== 'undefined'
  29787. && typeof require === 'function' ? factory(require('../../moment')) :
  29788. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  29789. factory(global.moment)
  29790. }(this, function (moment) { 'use strict';
  29791. /*global QUnit:false*/
  29792. var test = QUnit.test;
  29793. var expect = QUnit.expect;
  29794. function module (name, lifecycle) {
  29795. QUnit.module(name, {
  29796. setup : function () {
  29797. moment.locale('en');
  29798. moment.createFromInputFallback = function (config) {
  29799. throw new Error('input not handled by moment: ' + config._i);
  29800. };
  29801. if (lifecycle && lifecycle.setup) {
  29802. lifecycle.setup();
  29803. }
  29804. },
  29805. teardown : function () {
  29806. if (lifecycle && lifecycle.teardown) {
  29807. lifecycle.teardown();
  29808. }
  29809. }
  29810. });
  29811. }
  29812. function localeModule (name, lifecycle) {
  29813. QUnit.module('locale:' + name, {
  29814. setup : function () {
  29815. moment.locale(name);
  29816. moment.createFromInputFallback = function (config) {
  29817. throw new Error('input not handled by moment: ' + config._i);
  29818. };
  29819. if (lifecycle && lifecycle.setup) {
  29820. lifecycle.setup();
  29821. }
  29822. },
  29823. teardown : function () {
  29824. moment.locale('en');
  29825. if (lifecycle && lifecycle.teardown) {
  29826. lifecycle.teardown();
  29827. }
  29828. }
  29829. });
  29830. }
  29831. localeModule('tzm');
  29832. test('parse', function (assert) {
  29833. var tests = 'ⵉⵏⵏⴰⵢⵔ ⵉⵏⵏⴰⵢⵔ_ⴱⵕⴰⵢⵕ ⴱⵕⴰⵢⵕ_ⵎⴰⵕⵚ ⵎⴰⵕⵚ_ⵉⴱⵔⵉⵔ ⵉⴱⵔⵉⵔ_ⵎⴰⵢⵢⵓ ⵎⴰⵢⵢⵓ_ⵢⵓⵏⵢⵓ ⵢⵓⵏⵢⵓ_ⵢⵓⵍⵢⵓⵣ ⵢⵓⵍⵢⵓⵣ_ⵖⵓⵛⵜ ⵖⵓⵛⵜ_ⵛⵓⵜⴰⵏⴱⵉⵔ ⵛⵓⵜⴰⵏⴱⵉⵔ_ⴽⵟⵓⴱⵕ ⴽⵟⵓⴱⵕ_ⵏⵓⵡⴰⵏⴱⵉⵔ ⵏⵓⵡⴰⵏⴱⵉⵔ_ⴷⵓⵊⵏⴱⵉⵔ ⴷⵓⵊⵏⴱⵉⵔ'.split('_'), i;
  29834. function equalTest(input, mmm, i) {
  29835. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  29836. }
  29837. for (i = 0; i < 12; i++) {
  29838. tests[i] = tests[i].split(' ');
  29839. equalTest(tests[i][0], 'MMM', i);
  29840. equalTest(tests[i][1], 'MMM', i);
  29841. equalTest(tests[i][0], 'MMMM', i);
  29842. equalTest(tests[i][1], 'MMMM', i);
  29843. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  29844. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  29845. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  29846. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  29847. }
  29848. });
  29849. test('format', function (assert) {
  29850. var a = [
  29851. ['dddd, MMMM Do YYYY, h:mm:ss a', 'ⴰⵙⴰⵎⴰⵙ, ⴱⵕⴰⵢⵕ 14 2010, 3:25:50 pm'],
  29852. ['ddd, hA', 'ⴰⵙⴰⵎⴰⵙ, 3PM'],
  29853. ['M Mo MM MMMM MMM', '2 2 02 ⴱⵕⴰⵢⵕ ⴱⵕⴰⵢⵕ'],
  29854. ['YYYY YY', '2010 10'],
  29855. ['D Do DD', '14 14 14'],
  29856. ['d do dddd ddd dd', '0 0 ⴰⵙⴰⵎⴰⵙ ⴰⵙⴰⵎⴰⵙ ⴰⵙⴰⵎⴰⵙ'],
  29857. ['DDD DDDo DDDD', '45 45 045'],
  29858. ['w wo ww', '8 8 08'],
  29859. ['h hh', '3 03'],
  29860. ['H HH', '15 15'],
  29861. ['m mm', '25 25'],
  29862. ['s ss', '50 50'],
  29863. ['a A', 'pm PM'],
  29864. ['[the] DDDo [day of the year]', 'the 45 day of the year'],
  29865. ['LTS', '15:25:50'],
  29866. ['L', '14/02/2010'],
  29867. ['LL', '14 ⴱⵕⴰⵢⵕ 2010'],
  29868. ['LLL', '14 ⴱⵕⴰⵢⵕ 2010 15:25'],
  29869. ['LLLL', 'ⴰⵙⴰⵎⴰⵙ 14 ⴱⵕⴰⵢⵕ 2010 15:25'],
  29870. ['l', '14/2/2010'],
  29871. ['ll', '14 ⴱⵕⴰⵢⵕ 2010'],
  29872. ['lll', '14 ⴱⵕⴰⵢⵕ 2010 15:25'],
  29873. ['llll', 'ⴰⵙⴰⵎⴰⵙ 14 ⴱⵕⴰⵢⵕ 2010 15:25']
  29874. ],
  29875. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  29876. i;
  29877. for (i = 0; i < a.length; i++) {
  29878. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  29879. }
  29880. });
  29881. test('format ordinal', function (assert) {
  29882. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1');
  29883. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2');
  29884. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3');
  29885. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4');
  29886. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5');
  29887. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6');
  29888. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7');
  29889. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8');
  29890. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9');
  29891. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10');
  29892. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11');
  29893. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12');
  29894. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13');
  29895. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14');
  29896. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15');
  29897. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16');
  29898. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17');
  29899. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18');
  29900. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19');
  29901. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20');
  29902. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21');
  29903. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22');
  29904. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23');
  29905. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24');
  29906. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25');
  29907. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26');
  29908. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27');
  29909. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28');
  29910. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29');
  29911. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30');
  29912. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31');
  29913. });
  29914. test('format month', function (assert) {
  29915. var expected = 'ⵉⵏⵏⴰⵢⵔ ⵉⵏⵏⴰⵢⵔ_ⴱⵕⴰⵢⵕ ⴱⵕⴰⵢⵕ_ⵎⴰⵕⵚ ⵎⴰⵕⵚ_ⵉⴱⵔⵉⵔ ⵉⴱⵔⵉⵔ_ⵎⴰⵢⵢⵓ ⵎⴰⵢⵢⵓ_ⵢⵓⵏⵢⵓ ⵢⵓⵏⵢⵓ_ⵢⵓⵍⵢⵓⵣ ⵢⵓⵍⵢⵓⵣ_ⵖⵓⵛⵜ ⵖⵓⵛⵜ_ⵛⵓⵜⴰⵏⴱⵉⵔ ⵛⵓⵜⴰⵏⴱⵉⵔ_ⴽⵟⵓⴱⵕ ⴽⵟⵓⴱⵕ_ⵏⵓⵡⴰⵏⴱⵉⵔ ⵏⵓⵡⴰⵏⴱⵉⵔ_ⴷⵓⵊⵏⴱⵉⵔ ⴷⵓⵊⵏⴱⵉⵔ'.split('_'), i;
  29916. for (i = 0; i < expected.length; i++) {
  29917. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  29918. }
  29919. });
  29920. test('format week', function (assert) {
  29921. var expected = 'ⴰⵙⴰⵎⴰⵙ ⴰⵙⴰⵎⴰⵙ ⴰⵙⴰⵎⴰⵙ_ⴰⵢⵏⴰⵙ ⴰⵢⵏⴰⵙ ⴰⵢⵏⴰⵙ_ⴰⵙⵉⵏⴰⵙ ⴰⵙⵉⵏⴰⵙ ⴰⵙⵉⵏⴰⵙ_ⴰⴽⵔⴰⵙ ⴰⴽⵔⴰⵙ ⴰⴽⵔⴰⵙ_ⴰⴽⵡⴰⵙ ⴰⴽⵡⴰⵙ ⴰⴽⵡⴰⵙ_ⴰⵙⵉⵎⵡⴰⵙ ⴰⵙⵉⵎⵡⴰⵙ ⴰⵙⵉⵎⵡⴰⵙ_ⴰⵙⵉⴹⵢⴰⵙ ⴰⵙⵉⴹⵢⴰⵙ ⴰⵙⵉⴹⵢⴰⵙ'.split('_'), i;
  29922. for (i = 0; i < expected.length; i++) {
  29923. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  29924. }
  29925. });
  29926. test('from', function (assert) {
  29927. var start = moment([2007, 1, 28]);
  29928. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ⵉⵎⵉⴽ', '44 seconds = a few seconds');
  29929. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'ⵎⵉⵏⵓⴺ', '45 seconds = a minute');
  29930. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'ⵎⵉⵏⵓⴺ', '89 seconds = a minute');
  29931. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 ⵎⵉⵏⵓⴺ', '90 seconds = 2 minutes');
  29932. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 ⵎⵉⵏⵓⴺ', '44 minutes = 44 minutes');
  29933. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ⵙⴰⵄⴰ', '45 minutes = an hour');
  29934. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ⵙⴰⵄⴰ', '89 minutes = an hour');
  29935. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 ⵜⴰⵙⵙⴰⵄⵉⵏ', '90 minutes = 2 hours');
  29936. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ⵜⴰⵙⵙⴰⵄⵉⵏ', '5 hours = 5 hours');
  29937. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 ⵜⴰⵙⵙⴰⵄⵉⵏ', '21 hours = 21 hours');
  29938. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ⴰⵙⵙ', '22 hours = a day');
  29939. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ⴰⵙⵙ', '35 hours = a day');
  29940. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 oⵙⵙⴰⵏ', '36 hours = 2 days');
  29941. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ⴰⵙⵙ', '1 day = a day');
  29942. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 oⵙⵙⴰⵏ', '5 days = 5 days');
  29943. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 oⵙⵙⴰⵏ', '25 days = 25 days');
  29944. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ⴰⵢoⵓⵔ', '26 days = a month');
  29945. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ⴰⵢoⵓⵔ', '30 days = a month');
  29946. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ⴰⵢoⵓⵔ', '43 days = a month');
  29947. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 ⵉⵢⵢⵉⵔⵏ', '46 days = 2 months');
  29948. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 ⵉⵢⵢⵉⵔⵏ', '75 days = 2 months');
  29949. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 ⵉⵢⵢⵉⵔⵏ', '76 days = 3 months');
  29950. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ⴰⵢoⵓⵔ', '1 month = a month');
  29951. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 ⵉⵢⵢⵉⵔⵏ', '5 months = 5 months');
  29952. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ⴰⵙⴳⴰⵙ', '345 days = a year');
  29953. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 ⵉⵙⴳⴰⵙⵏ', '548 days = 2 years');
  29954. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ⴰⵙⴳⴰⵙ', '1 year = a year');
  29955. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 ⵉⵙⴳⴰⵙⵏ', '5 years = 5 years');
  29956. });
  29957. test('suffix', function (assert) {
  29958. assert.equal(moment(30000).from(0), 'ⴷⴰⴷⵅ ⵙ ⵢⴰⵏ ⵉⵎⵉⴽ', 'prefix');
  29959. assert.equal(moment(0).from(30000), 'ⵢⴰⵏ ⵉⵎⵉⴽ', 'suffix');
  29960. });
  29961. test('now from now', function (assert) {
  29962. assert.equal(moment().fromNow(), 'ⵢⴰⵏ ⵉⵎⵉⴽ', 'now from now should display as in the past');
  29963. });
  29964. test('fromNow', function (assert) {
  29965. assert.equal(moment().add({s: 30}).fromNow(), 'ⴷⴰⴷⵅ ⵙ ⵢⴰⵏ ⵉⵎⵉⴽ', 'in a few seconds');
  29966. assert.equal(moment().add({d: 5}).fromNow(), 'ⴷⴰⴷⵅ ⵙ ⵢⴰⵏ 5 oⵙⵙⴰⵏ', 'in 5 days');
  29967. });
  29968. test('calendar day', function (assert) {
  29969. var a = moment().hours(2).minutes(0).seconds(0);
  29970. assert.equal(moment(a).calendar(), 'ⴰⵙⴷⵅ ⴴ 02:00', 'today at the same time');
  29971. assert.equal(moment(a).add({m: 25}).calendar(), 'ⴰⵙⴷⵅ ⴴ 02:25', 'Now plus 25 min');
  29972. assert.equal(moment(a).add({h: 1}).calendar(), 'ⴰⵙⴷⵅ ⴴ 03:00', 'Now plus 1 hour');
  29973. assert.equal(moment(a).add({d: 1}).calendar(), 'ⴰⵙⴽⴰ ⴴ 02:00', 'tomorrow at the same time');
  29974. assert.equal(moment(a).subtract({h: 1}).calendar(), 'ⴰⵙⴷⵅ ⴴ 01:00', 'Now minus 1 hour');
  29975. assert.equal(moment(a).subtract({d: 1}).calendar(), 'ⴰⵚⴰⵏⵜ ⴴ 02:00', 'yesterday at the same time');
  29976. });
  29977. test('calendar next week', function (assert) {
  29978. var i, m;
  29979. for (i = 2; i < 7; i++) {
  29980. m = moment().add({d: i});
  29981. assert.equal(m.calendar(), m.format('dddd [ⴴ] LT'), 'Today + ' + i + ' days current time');
  29982. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  29983. assert.equal(m.calendar(), m.format('dddd [ⴴ] LT'), 'Today + ' + i + ' days beginning of day');
  29984. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  29985. assert.equal(m.calendar(), m.format('dddd [ⴴ] LT'), 'Today + ' + i + ' days end of day');
  29986. }
  29987. });
  29988. test('calendar last week', function (assert) {
  29989. var i, m;
  29990. for (i = 2; i < 7; i++) {
  29991. m = moment().subtract({d: i});
  29992. assert.equal(m.calendar(), m.format('dddd [ⴴ] LT'), 'Today - ' + i + ' days current time');
  29993. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  29994. assert.equal(m.calendar(), m.format('dddd [ⴴ] LT'), 'Today - ' + i + ' days beginning of day');
  29995. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  29996. assert.equal(m.calendar(), m.format('dddd [ⴴ] LT'), 'Today - ' + i + ' days end of day');
  29997. }
  29998. });
  29999. test('calendar all else', function (assert) {
  30000. var weeksAgo = moment().subtract({w: 1}),
  30001. weeksFromNow = moment().add({w: 1});
  30002. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  30003. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  30004. weeksAgo = moment().subtract({w: 2});
  30005. weeksFromNow = moment().add({w: 2});
  30006. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  30007. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  30008. });
  30009. test('weeks year starting sunday', function (assert) {
  30010. assert.equal(moment([2011, 11, 31]).week(), 1, 'Dec 31 2011 should be week 1');
  30011. assert.equal(moment([2012, 0, 6]).week(), 1, 'Jan 6 2012 should be week 1');
  30012. assert.equal(moment([2012, 0, 7]).week(), 2, 'Jan 7 2012 should be week 2');
  30013. assert.equal(moment([2012, 0, 13]).week(), 2, 'Jan 13 2012 should be week 2');
  30014. assert.equal(moment([2012, 0, 14]).week(), 3, 'Jan 14 2012 should be week 3');
  30015. });
  30016. test('weeks year starting monday', function (assert) {
  30017. assert.equal(moment([2006, 11, 30]).week(), 1, 'Dec 30 2006 should be week 1');
  30018. assert.equal(moment([2007, 0, 5]).week(), 1, 'Jan 5 2007 should be week 1');
  30019. assert.equal(moment([2007, 0, 6]).week(), 2, 'Jan 6 2007 should be week 2');
  30020. assert.equal(moment([2007, 0, 12]).week(), 2, 'Jan 12 2007 should be week 2');
  30021. assert.equal(moment([2007, 0, 13]).week(), 3, 'Jan 13 2007 should be week 3');
  30022. });
  30023. test('weeks year starting tuesday', function (assert) {
  30024. assert.equal(moment([2007, 11, 29]).week(), 1, 'Dec 29 2007 should be week 1');
  30025. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  30026. assert.equal(moment([2008, 0, 4]).week(), 1, 'Jan 4 2008 should be week 1');
  30027. assert.equal(moment([2008, 0, 5]).week(), 2, 'Jan 5 2008 should be week 2');
  30028. assert.equal(moment([2008, 0, 11]).week(), 2, 'Jan 11 2008 should be week 2');
  30029. assert.equal(moment([2008, 0, 12]).week(), 3, 'Jan 12 2008 should be week 3');
  30030. });
  30031. test('weeks year starting wednesday', function (assert) {
  30032. assert.equal(moment([2002, 11, 28]).week(), 1, 'Dec 28 2002 should be week 1');
  30033. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  30034. assert.equal(moment([2003, 0, 3]).week(), 1, 'Jan 3 2003 should be week 1');
  30035. assert.equal(moment([2003, 0, 4]).week(), 2, 'Jan 4 2003 should be week 2');
  30036. assert.equal(moment([2003, 0, 10]).week(), 2, 'Jan 10 2003 should be week 2');
  30037. assert.equal(moment([2003, 0, 11]).week(), 3, 'Jan 11 2003 should be week 3');
  30038. });
  30039. test('weeks year starting thursday', function (assert) {
  30040. assert.equal(moment([2008, 11, 27]).week(), 1, 'Dec 27 2008 should be week 1');
  30041. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  30042. assert.equal(moment([2009, 0, 2]).week(), 1, 'Jan 2 2009 should be week 1');
  30043. assert.equal(moment([2009, 0, 3]).week(), 2, 'Jan 3 2009 should be week 2');
  30044. assert.equal(moment([2009, 0, 9]).week(), 2, 'Jan 9 2009 should be week 2');
  30045. assert.equal(moment([2009, 0, 10]).week(), 3, 'Jan 10 2009 should be week 3');
  30046. });
  30047. test('weeks year starting friday', function (assert) {
  30048. assert.equal(moment([2009, 11, 26]).week(), 1, 'Dec 26 2009 should be week 1');
  30049. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  30050. assert.equal(moment([2010, 0, 2]).week(), 2, 'Jan 2 2010 should be week 2');
  30051. assert.equal(moment([2010, 0, 8]).week(), 2, 'Jan 8 2010 should be week 2');
  30052. assert.equal(moment([2010, 0, 9]).week(), 3, 'Jan 9 2010 should be week 3');
  30053. });
  30054. test('weeks year starting saturday', function (assert) {
  30055. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  30056. assert.equal(moment([2011, 0, 7]).week(), 1, 'Jan 7 2011 should be week 1');
  30057. assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2');
  30058. assert.equal(moment([2011, 0, 14]).week(), 2, 'Jan 14 2011 should be week 2');
  30059. assert.equal(moment([2011, 0, 15]).week(), 3, 'Jan 15 2011 should be week 3');
  30060. });
  30061. test('weeks year starting sunday formatted', function (assert) {
  30062. assert.equal(moment([2011, 11, 31]).format('w ww wo'), '1 01 1', 'Dec 31 2011 should be week 1');
  30063. assert.equal(moment([2012, 0, 6]).format('w ww wo'), '1 01 1', 'Jan 6 2012 should be week 1');
  30064. assert.equal(moment([2012, 0, 7]).format('w ww wo'), '2 02 2', 'Jan 7 2012 should be week 2');
  30065. assert.equal(moment([2012, 0, 13]).format('w ww wo'), '2 02 2', 'Jan 13 2012 should be week 2');
  30066. assert.equal(moment([2012, 0, 14]).format('w ww wo'), '3 03 3', 'Jan 14 2012 should be week 3');
  30067. });
  30068. test('lenient ordinal parsing', function (assert) {
  30069. var i, ordinalStr, testMoment;
  30070. for (i = 1; i <= 31; ++i) {
  30071. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  30072. testMoment = moment(ordinalStr, 'YYYY MM Do');
  30073. assert.equal(testMoment.year(), 2014,
  30074. 'lenient ordinal parsing ' + i + ' year check');
  30075. assert.equal(testMoment.month(), 0,
  30076. 'lenient ordinal parsing ' + i + ' month check');
  30077. assert.equal(testMoment.date(), i,
  30078. 'lenient ordinal parsing ' + i + ' date check');
  30079. }
  30080. });
  30081. test('lenient ordinal parsing of number', function (assert) {
  30082. var i, testMoment;
  30083. for (i = 1; i <= 31; ++i) {
  30084. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  30085. assert.equal(testMoment.year(), 2014,
  30086. 'lenient ordinal parsing of number ' + i + ' year check');
  30087. assert.equal(testMoment.month(), 0,
  30088. 'lenient ordinal parsing of number ' + i + ' month check');
  30089. assert.equal(testMoment.date(), i,
  30090. 'lenient ordinal parsing of number ' + i + ' date check');
  30091. }
  30092. });
  30093. test('strict ordinal parsing', function (assert) {
  30094. var i, ordinalStr, testMoment;
  30095. for (i = 1; i <= 31; ++i) {
  30096. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  30097. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  30098. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  30099. }
  30100. });
  30101. }));
  30102. ;(function (global, factory) {
  30103. typeof exports === 'object' && typeof module !== 'undefined'
  30104. && typeof require === 'function' ? factory(require('../../moment')) :
  30105. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  30106. factory(global.moment)
  30107. }(this, function (moment) { 'use strict';
  30108. /*global QUnit:false*/
  30109. var test = QUnit.test;
  30110. var expect = QUnit.expect;
  30111. function module (name, lifecycle) {
  30112. QUnit.module(name, {
  30113. setup : function () {
  30114. moment.locale('en');
  30115. moment.createFromInputFallback = function (config) {
  30116. throw new Error('input not handled by moment: ' + config._i);
  30117. };
  30118. if (lifecycle && lifecycle.setup) {
  30119. lifecycle.setup();
  30120. }
  30121. },
  30122. teardown : function () {
  30123. if (lifecycle && lifecycle.teardown) {
  30124. lifecycle.teardown();
  30125. }
  30126. }
  30127. });
  30128. }
  30129. function localeModule (name, lifecycle) {
  30130. QUnit.module('locale:' + name, {
  30131. setup : function () {
  30132. moment.locale(name);
  30133. moment.createFromInputFallback = function (config) {
  30134. throw new Error('input not handled by moment: ' + config._i);
  30135. };
  30136. if (lifecycle && lifecycle.setup) {
  30137. lifecycle.setup();
  30138. }
  30139. },
  30140. teardown : function () {
  30141. moment.locale('en');
  30142. if (lifecycle && lifecycle.teardown) {
  30143. lifecycle.teardown();
  30144. }
  30145. }
  30146. });
  30147. }
  30148. localeModule('uk');
  30149. test('parse', function (assert) {
  30150. var tests = 'січень січ_лютий лют_березень бер_квітень квіт_травень трав_червень черв_липень лип_серпень серп_вересень вер_жовтень жовт_листопад лист_грудень груд'.split('_'), i;
  30151. function equalTest(input, mmm, i) {
  30152. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  30153. }
  30154. for (i = 0; i < 12; i++) {
  30155. tests[i] = tests[i].split(' ');
  30156. equalTest(tests[i][0], 'MMM', i);
  30157. equalTest(tests[i][1], 'MMM', i);
  30158. equalTest(tests[i][0], 'MMMM', i);
  30159. equalTest(tests[i][1], 'MMMM', i);
  30160. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  30161. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  30162. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  30163. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  30164. }
  30165. });
  30166. test('format', function (assert) {
  30167. var a = [
  30168. ['dddd, Do MMMM YYYY, HH:mm:ss', 'неділя, 14-го лютого 2010, 15:25:50'],
  30169. ['ddd, h A', 'нд, 3 дня'],
  30170. ['M Mo MM MMMM MMM', '2 2-й 02 лютий лют'],
  30171. ['YYYY YY', '2010 10'],
  30172. ['D Do DD', '14 14-го 14'],
  30173. ['d do dddd ddd dd', '0 0-й неділя нд нд'],
  30174. ['DDD DDDo DDDD', '45 45-й 045'],
  30175. ['w wo ww', '7 7-й 07'],
  30176. ['h hh', '3 03'],
  30177. ['H HH', '15 15'],
  30178. ['m mm', '25 25'],
  30179. ['s ss', '50 50'],
  30180. ['a A', 'дня дня'],
  30181. ['DDDo [день року]', '45-й день року'],
  30182. ['LTS', '15:25:50'],
  30183. ['L', '14.02.2010'],
  30184. ['LL', '14 лютого 2010 р.'],
  30185. ['LLL', '14 лютого 2010 р., 15:25'],
  30186. ['LLLL', 'неділя, 14 лютого 2010 р., 15:25']
  30187. ],
  30188. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  30189. i;
  30190. for (i = 0; i < a.length; i++) {
  30191. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  30192. }
  30193. });
  30194. test('format meridiem', function (assert) {
  30195. assert.equal(moment([2012, 11, 28, 0, 0]).format('A'), 'ночі', 'night');
  30196. assert.equal(moment([2012, 11, 28, 3, 59]).format('A'), 'ночі', 'night');
  30197. assert.equal(moment([2012, 11, 28, 4, 0]).format('A'), 'ранку', 'morning');
  30198. assert.equal(moment([2012, 11, 28, 11, 59]).format('A'), 'ранку', 'morning');
  30199. assert.equal(moment([2012, 11, 28, 12, 0]).format('A'), 'дня', 'afternoon');
  30200. assert.equal(moment([2012, 11, 28, 16, 59]).format('A'), 'дня', 'afternoon');
  30201. assert.equal(moment([2012, 11, 28, 17, 0]).format('A'), 'вечора', 'evening');
  30202. assert.equal(moment([2012, 11, 28, 23, 59]).format('A'), 'вечора', 'evening');
  30203. });
  30204. test('format ordinal', function (assert) {
  30205. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1-й', '1-й');
  30206. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2-й', '2-й');
  30207. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3-й', '3-й');
  30208. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4-й', '4-й');
  30209. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5-й', '5-й');
  30210. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6-й', '6-й');
  30211. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7-й', '7-й');
  30212. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8-й', '8-й');
  30213. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9-й', '9-й');
  30214. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10-й', '10-й');
  30215. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11-й', '11-й');
  30216. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12-й', '12-й');
  30217. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13-й', '13-й');
  30218. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14-й', '14-й');
  30219. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15-й', '15-й');
  30220. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16-й', '16-й');
  30221. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17-й', '17-й');
  30222. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18-й', '18-й');
  30223. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19-й', '19-й');
  30224. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20-й', '20-й');
  30225. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21-й', '21-й');
  30226. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22-й', '22-й');
  30227. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23-й', '23-й');
  30228. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24-й', '24-й');
  30229. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25-й', '25-й');
  30230. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26-й', '26-й');
  30231. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27-й', '27-й');
  30232. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28-й', '28-й');
  30233. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29-й', '29-й');
  30234. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30-й', '30-й');
  30235. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31-й', '31-й');
  30236. });
  30237. test('format month', function (assert) {
  30238. var expected = 'січень січ_лютий лют_березень бер_квітень квіт_травень трав_червень черв_липень лип_серпень серп_вересень вер_жовтень жовт_листопад лист_грудень груд'.split('_'), i;
  30239. for (i = 0; i < expected.length; i++) {
  30240. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  30241. }
  30242. });
  30243. test('format month case', function (assert) {
  30244. var months = {
  30245. 'nominative': 'січень_лютий_березень_квітень_травень_червень_липень_серпень_вересень_жовтень_листопад_грудень'.split('_'),
  30246. 'accusative': 'січня_лютого_березня_квітня_травня_червня_липня_серпня_вересня_жовтня_листопада_грудня'.split('_')
  30247. }, i;
  30248. for (i = 0; i < 12; i++) {
  30249. assert.equal(moment([2011, i, 1]).format('D MMMM'), '1 ' + months.accusative[i], '1 ' + months.accusative[i]);
  30250. assert.equal(moment([2011, i, 1]).format('MMMM'), months.nominative[i], '1 ' + months.nominative[i]);
  30251. }
  30252. });
  30253. test('format week', function (assert) {
  30254. var expected = 'неділя нд нд_понеділок пн пн_вівторок вт вт_середа ср ср_четвер чт чт_п’ятниця пт пт_субота сб сб'.split('_'), i;
  30255. for (i = 0; i < expected.length; i++) {
  30256. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  30257. }
  30258. });
  30259. test('from', function (assert) {
  30260. var start = moment([2007, 1, 28]);
  30261. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'декілька секунд', '44 seconds = seconds');
  30262. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'хвилина', '45 seconds = a minute');
  30263. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'хвилина', '89 seconds = a minute');
  30264. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 хвилини', '90 seconds = 2 minutes');
  30265. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 хвилини', '44 minutes = 44 minutes');
  30266. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'годину', '45 minutes = an hour');
  30267. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'годину', '89 minutes = an hour');
  30268. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 години', '90 minutes = 2 hours');
  30269. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 годин', '5 hours = 5 hours');
  30270. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 година', '21 hours = 21 hours');
  30271. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'день', '22 hours = a day');
  30272. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'день', '35 hours = a day');
  30273. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 дні', '36 hours = 2 days');
  30274. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'день', '1 day = a day');
  30275. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 днів', '5 days = 5 days');
  30276. assert.equal(start.from(moment([2007, 1, 28]).add({d: 11}), true), '11 днів', '11 days = 11 days');
  30277. assert.equal(start.from(moment([2007, 1, 28]).add({d: 21}), true), '21 день', '21 days = 21 days');
  30278. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 днів', '25 days = 25 days');
  30279. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'місяць', '26 days = a month');
  30280. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'місяць', '30 days = a month');
  30281. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'місяць', '43 days = a month');
  30282. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 місяці', '46 days = 2 months');
  30283. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 місяці', '75 days = 2 months');
  30284. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 місяці', '76 days = 3 months');
  30285. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'місяць', '1 month = a month');
  30286. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 місяців', '5 months = 5 months');
  30287. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'рік', '345 days = a year');
  30288. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 роки', '548 days = 2 years');
  30289. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'рік', '1 year = a year');
  30290. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 років', '5 years = 5 years');
  30291. });
  30292. test('suffix', function (assert) {
  30293. assert.equal(moment(30000).from(0), 'за декілька секунд', 'prefix');
  30294. assert.equal(moment(0).from(30000), 'декілька секунд тому', 'suffix');
  30295. });
  30296. test('fromNow', function (assert) {
  30297. assert.equal(moment().add({s: 30}).fromNow(), 'за декілька секунд', 'in seconds');
  30298. assert.equal(moment().add({d: 5}).fromNow(), 'за 5 днів', 'in 5 days');
  30299. });
  30300. test('calendar day', function (assert) {
  30301. var a = moment().hours(2).minutes(0).seconds(0);
  30302. assert.equal(moment(a).calendar(), 'Сьогодні о 02:00', 'today at the same time');
  30303. assert.equal(moment(a).add({m: 25}).calendar(), 'Сьогодні о 02:25', 'Now plus 25 min');
  30304. assert.equal(moment(a).add({h: 1}).calendar(), 'Сьогодні о 03:00', 'Now plus 1 hour');
  30305. assert.equal(moment(a).add({d: 1}).calendar(), 'Завтра о 02:00', 'tomorrow at the same time');
  30306. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Сьогодні о 01:00', 'Now minus 1 hour');
  30307. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Вчора о 02:00', 'yesterday at the same time');
  30308. // A special case for Ukrainian since 11 hours have different preposition
  30309. assert.equal(moment(a).add({h: 9}).calendar(), 'Сьогодні об 11:00', 'same day at 11 o\'clock');
  30310. });
  30311. test('calendar next week', function (assert) {
  30312. var i, m;
  30313. for (i = 2; i < 7; i++) {
  30314. m = moment().add({d: i});
  30315. assert.equal(m.calendar(), m.format('[У] dddd [о' + (m.hours() === 11 ? 'б' : '') + '] LT'), 'Today + ' + i + ' days current time');
  30316. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  30317. assert.equal(m.calendar(), m.format('[У] dddd [о] LT'), 'Today + ' + i + ' days beginning of day');
  30318. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  30319. assert.equal(m.calendar(), m.format('[У] dddd [о] LT'), 'Today + ' + i + ' days end of day');
  30320. }
  30321. });
  30322. test('calendar last week', function (assert) {
  30323. var i, m;
  30324. function makeFormat(d) {
  30325. switch (d.day()) {
  30326. case 0:
  30327. case 3:
  30328. case 5:
  30329. case 6:
  30330. return '[Минулої] dddd [о' + (d.hours() === 11 ? 'б' : '') + '] LT';
  30331. case 1:
  30332. case 2:
  30333. case 4:
  30334. return '[Минулого] dddd [о' + (d.hours() === 11 ? 'б' : '') + '] LT';
  30335. }
  30336. }
  30337. for (i = 2; i < 7; i++) {
  30338. m = moment().subtract({d: i});
  30339. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days current time');
  30340. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  30341. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days beginning of day');
  30342. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  30343. assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days end of day');
  30344. }
  30345. });
  30346. test('calendar all else', function (assert) {
  30347. var weeksAgo = moment().subtract({w: 1}),
  30348. weeksFromNow = moment().add({w: 1});
  30349. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  30350. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  30351. weeksAgo = moment().subtract({w: 2});
  30352. weeksFromNow = moment().add({w: 2});
  30353. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  30354. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  30355. });
  30356. test('weeks year starting sunday', function (assert) {
  30357. assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1');
  30358. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  30359. assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2');
  30360. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  30361. assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3');
  30362. });
  30363. test('weeks year starting monday', function (assert) {
  30364. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  30365. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  30366. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  30367. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  30368. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  30369. });
  30370. test('weeks year starting tuesday', function (assert) {
  30371. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  30372. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  30373. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  30374. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  30375. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  30376. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  30377. });
  30378. test('weeks year starting wednesday', function (assert) {
  30379. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  30380. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  30381. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  30382. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  30383. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  30384. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  30385. });
  30386. test('weeks year starting thursday', function (assert) {
  30387. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  30388. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  30389. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  30390. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  30391. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  30392. assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3');
  30393. });
  30394. test('weeks year starting friday', function (assert) {
  30395. assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1');
  30396. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  30397. assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1');
  30398. assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2');
  30399. assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2');
  30400. assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3');
  30401. });
  30402. test('weeks year starting saturday', function (assert) {
  30403. assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1');
  30404. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  30405. assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1');
  30406. assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2');
  30407. assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2');
  30408. assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3');
  30409. });
  30410. test('weeks year starting sunday formatted', function (assert) {
  30411. assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1-й', 'Dec 26 2011 should be week 1');
  30412. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1-й', 'Jan 1 2012 should be week 1');
  30413. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2-й', 'Jan 2 2012 should be week 2');
  30414. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2-й', 'Jan 8 2012 should be week 2');
  30415. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3-й', 'Jan 9 2012 should be week 3');
  30416. });
  30417. test('lenient ordinal parsing', function (assert) {
  30418. var i, ordinalStr, testMoment;
  30419. for (i = 1; i <= 31; ++i) {
  30420. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  30421. testMoment = moment(ordinalStr, 'YYYY MM Do');
  30422. assert.equal(testMoment.year(), 2014,
  30423. 'lenient ordinal parsing ' + i + ' year check');
  30424. assert.equal(testMoment.month(), 0,
  30425. 'lenient ordinal parsing ' + i + ' month check');
  30426. assert.equal(testMoment.date(), i,
  30427. 'lenient ordinal parsing ' + i + ' date check');
  30428. }
  30429. });
  30430. test('lenient ordinal parsing of number', function (assert) {
  30431. var i, testMoment;
  30432. for (i = 1; i <= 31; ++i) {
  30433. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  30434. assert.equal(testMoment.year(), 2014,
  30435. 'lenient ordinal parsing of number ' + i + ' year check');
  30436. assert.equal(testMoment.month(), 0,
  30437. 'lenient ordinal parsing of number ' + i + ' month check');
  30438. assert.equal(testMoment.date(), i,
  30439. 'lenient ordinal parsing of number ' + i + ' date check');
  30440. }
  30441. });
  30442. test('strict ordinal parsing', function (assert) {
  30443. var i, ordinalStr, testMoment;
  30444. for (i = 1; i <= 31; ++i) {
  30445. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  30446. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  30447. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  30448. }
  30449. });
  30450. }));
  30451. ;(function (global, factory) {
  30452. typeof exports === 'object' && typeof module !== 'undefined'
  30453. && typeof require === 'function' ? factory(require('../../moment')) :
  30454. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  30455. factory(global.moment)
  30456. }(this, function (moment) { 'use strict';
  30457. /*global QUnit:false*/
  30458. var test = QUnit.test;
  30459. var expect = QUnit.expect;
  30460. function module (name, lifecycle) {
  30461. QUnit.module(name, {
  30462. setup : function () {
  30463. moment.locale('en');
  30464. moment.createFromInputFallback = function (config) {
  30465. throw new Error('input not handled by moment: ' + config._i);
  30466. };
  30467. if (lifecycle && lifecycle.setup) {
  30468. lifecycle.setup();
  30469. }
  30470. },
  30471. teardown : function () {
  30472. if (lifecycle && lifecycle.teardown) {
  30473. lifecycle.teardown();
  30474. }
  30475. }
  30476. });
  30477. }
  30478. function localeModule (name, lifecycle) {
  30479. QUnit.module('locale:' + name, {
  30480. setup : function () {
  30481. moment.locale(name);
  30482. moment.createFromInputFallback = function (config) {
  30483. throw new Error('input not handled by moment: ' + config._i);
  30484. };
  30485. if (lifecycle && lifecycle.setup) {
  30486. lifecycle.setup();
  30487. }
  30488. },
  30489. teardown : function () {
  30490. moment.locale('en');
  30491. if (lifecycle && lifecycle.teardown) {
  30492. lifecycle.teardown();
  30493. }
  30494. }
  30495. });
  30496. }
  30497. localeModule('uz');
  30498. test('parse', function (assert) {
  30499. var tests = 'январ янв_феврал фев_март мар_апрел апр_май май_июн июн_июл июл_август авг_сентябр сен_октябр окт_ноябр ноя_декабр дек'.split('_'), i;
  30500. function equalTest(input, mmm, i) {
  30501. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  30502. }
  30503. for (i = 0; i < 12; i++) {
  30504. tests[i] = tests[i].split(' ');
  30505. equalTest(tests[i][0], 'MMM', i);
  30506. equalTest(tests[i][1], 'MMM', i);
  30507. equalTest(tests[i][0], 'MMMM', i);
  30508. equalTest(tests[i][1], 'MMMM', i);
  30509. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  30510. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  30511. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  30512. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  30513. }
  30514. });
  30515. test('format', function (assert) {
  30516. var a = [
  30517. ['dddd, Do-MMMM YYYY, h:mm:ss', 'Якшанба, 14-феврал 2010, 3:25:50'],
  30518. ['ddd, h:mm', 'Якш, 3:25'],
  30519. ['M Mo MM MMMM MMM', '2 2 02 феврал фев'],
  30520. ['YYYY YY', '2010 10'],
  30521. ['D Do DD', '14 14 14'],
  30522. ['d do dddd ddd dd', '0 0 Якшанба Якш Як'],
  30523. ['DDD DDDo DDDD', '45 45 045'],
  30524. ['w wo ww', '7 7 07'],
  30525. ['h hh', '3 03'],
  30526. ['H HH', '15 15'],
  30527. ['m mm', '25 25'],
  30528. ['s ss', '50 50'],
  30529. ['a A', 'pm PM'],
  30530. ['[йилнинг] DDDo-[куни]', 'йилнинг 45-куни'],
  30531. ['LTS', '15:25:50'],
  30532. ['L', '14/02/2010'],
  30533. ['LL', '14 феврал 2010'],
  30534. ['LLL', '14 феврал 2010 15:25'],
  30535. ['LLLL', '14 феврал 2010, Якшанба 15:25'],
  30536. ['l', '14/2/2010'],
  30537. ['ll', '14 фев 2010'],
  30538. ['lll', '14 фев 2010 15:25'],
  30539. ['llll', '14 фев 2010, Якш 15:25']
  30540. ],
  30541. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  30542. i;
  30543. for (i = 0; i < a.length; i++) {
  30544. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  30545. }
  30546. });
  30547. test('format ordinal', function (assert) {
  30548. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1');
  30549. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2');
  30550. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3');
  30551. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4');
  30552. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5');
  30553. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6');
  30554. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7');
  30555. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8');
  30556. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9');
  30557. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10');
  30558. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11');
  30559. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12');
  30560. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13');
  30561. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14');
  30562. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15');
  30563. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16');
  30564. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17');
  30565. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18');
  30566. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19');
  30567. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20');
  30568. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21');
  30569. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22');
  30570. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23');
  30571. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24');
  30572. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25');
  30573. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26');
  30574. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27');
  30575. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28');
  30576. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29');
  30577. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30');
  30578. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31');
  30579. });
  30580. test('format month', function (assert) {
  30581. var expected = 'январ янв_феврал фев_март мар_апрел апр_май май_июн июн_июл июл_август авг_сентябр сен_октябр окт_ноябр ноя_декабр дек'.split('_'), i;
  30582. for (i = 0; i < expected.length; i++) {
  30583. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  30584. }
  30585. });
  30586. test('format week', function (assert) {
  30587. var expected = 'Якшанба Якш Як_Душанба Душ Ду_Сешанба Сеш Се_Чоршанба Чор Чо_Пайшанба Пай Па_Жума Жум Жу_Шанба Шан Ша'.split('_'), i;
  30588. for (i = 0; i < expected.length; i++) {
  30589. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  30590. }
  30591. });
  30592. test('from', function (assert) {
  30593. var start = moment([2007, 1, 28]);
  30594. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'фурсат', '44 секунд = фурсат');
  30595. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'бир дакика', '45 секунд = бир дакика');
  30596. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'бир дакика', '89 секунд = бир дакика');
  30597. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 дакика', '90 секунд = 2 дакика');
  30598. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 дакика', '44 дакика = 44 дакика');
  30599. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'бир соат', '45 минут = бир соат');
  30600. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'бир соат', '89 minutes = an hour');
  30601. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 соат', '90 минут = 2 соат');
  30602. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 соат', '5 соат = 5 соат');
  30603. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 соат', '21 соат = 21 соат');
  30604. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'бир кун', '22 соат = бир кун');
  30605. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'бир кун', '35 соат = бир кун');
  30606. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 кун', '36 соат = 2 кун');
  30607. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'бир кун', '1 кун = 1 кун');
  30608. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 кун', '5 кун = 5 кун');
  30609. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 кун', '25 кун = 25 кун');
  30610. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'бир ой', '26 кун = бир ой');
  30611. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'бир ой', '30 кун = бир ой');
  30612. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'бир ой', '45 кун = бир ой');
  30613. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 ой', '46 кун = 2 ой');
  30614. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 ой', '75 кун = 2 ой');
  30615. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 ой', '76 кун = 3 ой');
  30616. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'бир ой', 'бир ой = бир ой');
  30617. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 ой', '5 ой = 5 ой');
  30618. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'бир йил', '345 кун = бир йил');
  30619. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 йил', '548 кун = 2 йил');
  30620. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'бир йил', '1 йил = бир йил');
  30621. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 йил', '5 йил = 5 йил');
  30622. });
  30623. test('suffix', function (assert) {
  30624. assert.equal(moment(30000).from(0), 'Якин фурсат ичида', 'prefix');
  30625. assert.equal(moment(0).from(30000), 'Бир неча фурсат олдин', 'suffix');
  30626. });
  30627. test('now from now', function (assert) {
  30628. assert.equal(moment().fromNow(), 'Бир неча фурсат олдин', 'now from now should display as in the past');
  30629. });
  30630. test('fromNow', function (assert) {
  30631. assert.equal(moment().add({s: 30}).fromNow(), 'Якин фурсат ичида', 'in a few seconds');
  30632. assert.equal(moment().add({d: 5}).fromNow(), 'Якин 5 кун ичида', 'in 5 days');
  30633. });
  30634. test('calendar day', function (assert) {
  30635. var a = moment().hours(2).minutes(0).seconds(0);
  30636. assert.equal(moment(a).calendar(), 'Бугун соат 02:00 да', 'today at the same time');
  30637. assert.equal(moment(a).add({m: 25}).calendar(), 'Бугун соат 02:25 да', 'Now plus 25 min');
  30638. assert.equal(moment(a).add({h: 1}).calendar(), 'Бугун соат 03:00 да', 'Now plus 1 hour');
  30639. assert.equal(moment(a).add({d: 1}).calendar(), 'Эртага 02:00 да', 'tomorrow at the same time');
  30640. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Бугун соат 01:00 да', 'Now minus 1 hour');
  30641. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Кеча соат 02:00 да', 'yesterday at the same time');
  30642. });
  30643. test('calendar next week', function (assert) {
  30644. var i, m;
  30645. for (i = 2; i < 7; i++) {
  30646. m = moment().add({d: i});
  30647. assert.equal(m.calendar(), m.format('dddd [куни соат] LT [да]'), 'Today + ' + i + ' days current time');
  30648. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  30649. assert.equal(m.calendar(), m.format('dddd [куни соат] LT [да]'), 'Today + ' + i + ' days beginning of day');
  30650. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  30651. assert.equal(m.calendar(), m.format('dddd [куни соат] LT [да]'), 'Today + ' + i + ' days end of day');
  30652. }
  30653. });
  30654. test('calendar last week', function (assert) {
  30655. var i, m;
  30656. for (i = 2; i < 7; i++) {
  30657. m = moment().subtract({d: i});
  30658. assert.equal(m.calendar(), m.format('[Утган] dddd [куни соат] LT [да]'), 'Today - ' + i + ' days current time');
  30659. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  30660. assert.equal(m.calendar(), m.format('[Утган] dddd [куни соат] LT [да]'), 'Today - ' + i + ' days beginning of day');
  30661. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  30662. assert.equal(m.calendar(), m.format('[Утган] dddd [куни соат] LT [да]'), 'Today - ' + i + ' days end of day');
  30663. }
  30664. });
  30665. test('calendar all else', function (assert) {
  30666. var weeksAgo = moment().subtract({w: 1}),
  30667. weeksFromNow = moment().add({w: 1});
  30668. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  30669. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  30670. weeksAgo = moment().subtract({w: 2});
  30671. weeksFromNow = moment().add({w: 2});
  30672. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  30673. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  30674. });
  30675. test('weeks year starting sunday', function (assert) {
  30676. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 52');
  30677. assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 1');
  30678. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 1');
  30679. assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 2');
  30680. assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 2');
  30681. });
  30682. test('weeks year starting monday', function (assert) {
  30683. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  30684. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  30685. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  30686. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  30687. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  30688. });
  30689. test('weeks year starting tuesday', function (assert) {
  30690. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  30691. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  30692. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  30693. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  30694. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  30695. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  30696. });
  30697. test('weeks year starting wednesday', function (assert) {
  30698. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  30699. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  30700. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  30701. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  30702. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  30703. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  30704. });
  30705. test('weeks year starting thursday', function (assert) {
  30706. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  30707. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  30708. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  30709. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  30710. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  30711. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  30712. });
  30713. test('weeks year starting friday', function (assert) {
  30714. assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 53');
  30715. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 53');
  30716. assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 53');
  30717. assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 1');
  30718. assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 1');
  30719. assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 2');
  30720. });
  30721. test('weeks year starting saturday', function (assert) {
  30722. assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 52');
  30723. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 52');
  30724. assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 52');
  30725. assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 1');
  30726. assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 1');
  30727. assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 2');
  30728. });
  30729. test('weeks year starting sunday formatted', function (assert) {
  30730. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1', 'Jan 1 2012 should be week 52');
  30731. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2', 'Jan 2 2012 should be week 1');
  30732. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2', 'Jan 8 2012 should be week 1');
  30733. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3', 'Jan 9 2012 should be week 2');
  30734. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3', 'Jan 15 2012 should be week 2');
  30735. });
  30736. test('lenient ordinal parsing', function (assert) {
  30737. var i, ordinalStr, testMoment;
  30738. for (i = 1; i <= 31; ++i) {
  30739. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  30740. testMoment = moment(ordinalStr, 'YYYY MM Do');
  30741. assert.equal(testMoment.year(), 2014,
  30742. 'lenient ordinal parsing ' + i + ' year check');
  30743. assert.equal(testMoment.month(), 0,
  30744. 'lenient ordinal parsing ' + i + ' month check');
  30745. assert.equal(testMoment.date(), i,
  30746. 'lenient ordinal parsing ' + i + ' date check');
  30747. }
  30748. });
  30749. test('lenient ordinal parsing of number', function (assert) {
  30750. var i, testMoment;
  30751. for (i = 1; i <= 31; ++i) {
  30752. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  30753. assert.equal(testMoment.year(), 2014,
  30754. 'lenient ordinal parsing of number ' + i + ' year check');
  30755. assert.equal(testMoment.month(), 0,
  30756. 'lenient ordinal parsing of number ' + i + ' month check');
  30757. assert.equal(testMoment.date(), i,
  30758. 'lenient ordinal parsing of number ' + i + ' date check');
  30759. }
  30760. });
  30761. test('strict ordinal parsing', function (assert) {
  30762. var i, ordinalStr, testMoment;
  30763. for (i = 1; i <= 31; ++i) {
  30764. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  30765. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  30766. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  30767. }
  30768. });
  30769. }));
  30770. ;(function (global, factory) {
  30771. typeof exports === 'object' && typeof module !== 'undefined'
  30772. && typeof require === 'function' ? factory(require('../../moment')) :
  30773. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  30774. factory(global.moment)
  30775. }(this, function (moment) { 'use strict';
  30776. /*global QUnit:false*/
  30777. var test = QUnit.test;
  30778. var expect = QUnit.expect;
  30779. function module (name, lifecycle) {
  30780. QUnit.module(name, {
  30781. setup : function () {
  30782. moment.locale('en');
  30783. moment.createFromInputFallback = function (config) {
  30784. throw new Error('input not handled by moment: ' + config._i);
  30785. };
  30786. if (lifecycle && lifecycle.setup) {
  30787. lifecycle.setup();
  30788. }
  30789. },
  30790. teardown : function () {
  30791. if (lifecycle && lifecycle.teardown) {
  30792. lifecycle.teardown();
  30793. }
  30794. }
  30795. });
  30796. }
  30797. function localeModule (name, lifecycle) {
  30798. QUnit.module('locale:' + name, {
  30799. setup : function () {
  30800. moment.locale(name);
  30801. moment.createFromInputFallback = function (config) {
  30802. throw new Error('input not handled by moment: ' + config._i);
  30803. };
  30804. if (lifecycle && lifecycle.setup) {
  30805. lifecycle.setup();
  30806. }
  30807. },
  30808. teardown : function () {
  30809. moment.locale('en');
  30810. if (lifecycle && lifecycle.teardown) {
  30811. lifecycle.teardown();
  30812. }
  30813. }
  30814. });
  30815. }
  30816. localeModule('vi');
  30817. test('parse', function (assert) {
  30818. var i,
  30819. tests = 'tháng 1,Th01_tháng 2,Th02_tháng 3,Th03_tháng 4,Th04_tháng 5,Th05_tháng 6,Th06_tháng 7,Th07_tháng 8,Th08_tháng 9,Th09_tháng 10,Th10_tháng 11,Th11_tháng 12,Th12'.split('_');
  30820. function equalTest(input, mmm, i) {
  30821. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + i);
  30822. }
  30823. for (i = 0; i < 12; i++) {
  30824. tests[i] = tests[i].split(',');
  30825. equalTest(tests[i][0], '[tháng] M', i);
  30826. equalTest(tests[i][1], '[Th]M', i);
  30827. equalTest(tests[i][0], '[tháng] MM', i);
  30828. equalTest(tests[i][1], '[Th]MM', i);
  30829. equalTest(tests[i][0].toLocaleLowerCase(), '[THÁNG] M', i);
  30830. equalTest(tests[i][1].toLocaleLowerCase(), '[TH]M', i);
  30831. equalTest(tests[i][0].toLocaleUpperCase(), '[THÁNG] MM', i);
  30832. equalTest(tests[i][1].toLocaleUpperCase(), '[TH]MM', i);
  30833. }
  30834. });
  30835. test('format', function (assert) {
  30836. var a = [
  30837. ['dddd, MMMM Do YYYY, h:mm:ss a', 'chủ nhật, tháng 2 14 2010, 3:25:50 pm'],
  30838. ['ddd, hA', 'CN, 3PM'],
  30839. ['M Mo MM MMMM MMM', '2 2 02 tháng 2 Th02'],
  30840. ['YYYY YY', '2010 10'],
  30841. ['D Do DD', '14 14 14'],
  30842. ['d do dddd ddd dd', '0 0 chủ nhật CN CN'],
  30843. ['DDD DDDo DDDD', '45 45 045'],
  30844. ['w wo ww', '6 6 06'],
  30845. ['h hh', '3 03'],
  30846. ['H HH', '15 15'],
  30847. ['m mm', '25 25'],
  30848. ['s ss', '50 50'],
  30849. ['a A', 'pm PM'],
  30850. ['[ngày thứ] DDDo [của năm]', 'ngày thứ 45 của năm'],
  30851. ['LTS', '15:25:50'],
  30852. ['L', '14/02/2010'],
  30853. ['LL', '14 tháng 2 năm 2010'],
  30854. ['LLL', '14 tháng 2 năm 2010 15:25'],
  30855. ['LLLL', 'chủ nhật, 14 tháng 2 năm 2010 15:25'],
  30856. ['l', '14/2/2010'],
  30857. ['ll', '14 Th02 2010'],
  30858. ['lll', '14 Th02 2010 15:25'],
  30859. ['llll', 'CN, 14 Th02 2010 15:25']
  30860. ],
  30861. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  30862. i;
  30863. for (i = 0; i < a.length; i++) {
  30864. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  30865. }
  30866. });
  30867. test('format ordinal', function (assert) {
  30868. assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1');
  30869. assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2');
  30870. assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3');
  30871. assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4');
  30872. assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5');
  30873. assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6');
  30874. assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7');
  30875. assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8');
  30876. assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9');
  30877. assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10');
  30878. assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11');
  30879. assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12');
  30880. assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13');
  30881. assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14');
  30882. assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15');
  30883. assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16');
  30884. assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17');
  30885. assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18');
  30886. assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19');
  30887. assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20');
  30888. assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21');
  30889. assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22');
  30890. assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23');
  30891. assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24');
  30892. assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25');
  30893. assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26');
  30894. assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27');
  30895. assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28');
  30896. assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29');
  30897. assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30');
  30898. assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31');
  30899. });
  30900. test('format month', function (assert) {
  30901. var i,
  30902. expected = 'tháng 1,Th01_tháng 2,Th02_tháng 3,Th03_tháng 4,Th04_tháng 5,Th05_tháng 6,Th06_tháng 7,Th07_tháng 8,Th08_tháng 9,Th09_tháng 10,Th10_tháng 11,Th11_tháng 12,Th12'.split('_');
  30903. for (i = 0; i < expected.length; i++) {
  30904. assert.equal(moment([2011, i, 1]).format('MMMM,MMM'), expected[i], expected[i]);
  30905. }
  30906. });
  30907. test('format week', function (assert) {
  30908. var i,
  30909. expected = 'chủ nhật CN CN_thứ hai T2 T2_thứ ba T3 T3_thứ tư T4 T4_thứ năm T5 T5_thứ sáu T6 T6_thứ bảy T7 T7'.split('_');
  30910. for (i = 0; i < expected.length; i++) {
  30911. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  30912. }
  30913. });
  30914. test('from', function (assert) {
  30915. var start = moment([2007, 1, 28]);
  30916. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'vài giây', '44 seconds = a few seconds');
  30917. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'một phút', '45 seconds = a minute');
  30918. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'một phút', '89 seconds = a minute');
  30919. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 phút', '90 seconds = 2 minutes');
  30920. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 phút', '44 minutes = 44 minutes');
  30921. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'một giờ', '45 minutes = an hour');
  30922. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'một giờ', '89 minutes = an hour');
  30923. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 giờ', '90 minutes = 2 hours');
  30924. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 giờ', '5 hours = 5 hours');
  30925. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 giờ', '21 hours = 21 hours');
  30926. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'một ngày', '22 hours = a day');
  30927. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'một ngày', '35 hours = a day');
  30928. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 ngày', '36 hours = 2 days');
  30929. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'một ngày', '1 day = a day');
  30930. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 ngày', '5 days = 5 days');
  30931. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 ngày', '25 days = 25 days');
  30932. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'một tháng', '26 days = a month');
  30933. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'một tháng', '30 days = a month');
  30934. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'một tháng', '43 days = a month');
  30935. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 tháng', '46 days = 2 months');
  30936. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 tháng', '75 days = 2 months');
  30937. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 tháng', '76 days = 3 months');
  30938. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'một tháng', '1 month = a month');
  30939. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 tháng', '5 months = 5 months');
  30940. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'một năm', '345 days = a year');
  30941. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 năm', '548 days = 2 years');
  30942. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'một năm', '1 year = a year');
  30943. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 năm', '5 years = 5 years');
  30944. });
  30945. test('suffix', function (assert) {
  30946. assert.equal(moment(30000).from(0), 'vài giây tới', 'prefix');
  30947. assert.equal(moment(0).from(30000), 'vài giây trước', 'suffix');
  30948. });
  30949. test('now from now', function (assert) {
  30950. assert.equal(moment().fromNow(), 'vài giây trước', 'now from now should display as in the past');
  30951. });
  30952. test('fromNow', function (assert) {
  30953. assert.equal(moment().add({s: 30}).fromNow(), 'vài giây tới', 'in a few seconds');
  30954. assert.equal(moment().add({d: 5}).fromNow(), '5 ngày tới', 'in 5 days');
  30955. });
  30956. test('calendar day', function (assert) {
  30957. var a = moment().hours(2).minutes(0).seconds(0);
  30958. assert.equal(moment(a).calendar(), 'Hôm nay lúc 02:00', 'today at the same time');
  30959. assert.equal(moment(a).add({m: 25}).calendar(), 'Hôm nay lúc 02:25', 'Now plus 25 min');
  30960. assert.equal(moment(a).add({h: 1}).calendar(), 'Hôm nay lúc 03:00', 'Now plus 1 hour');
  30961. assert.equal(moment(a).add({d: 1}).calendar(), 'Ngày mai lúc 02:00', 'tomorrow at the same time');
  30962. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Hôm nay lúc 01:00', 'Now minus 1 hour');
  30963. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Hôm qua lúc 02:00', 'yesterday at the same time');
  30964. });
  30965. test('calendar next week', function (assert) {
  30966. var i, m;
  30967. for (i = 2; i < 7; i++) {
  30968. m = moment().add({d: i});
  30969. assert.equal(m.calendar(), m.format('dddd [tuần tới lúc] LT'), 'Today + ' + i + ' days current time');
  30970. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  30971. assert.equal(m.calendar(), m.format('dddd [tuần tới lúc] LT'), 'Today + ' + i + ' days beginning of day');
  30972. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  30973. assert.equal(m.calendar(), m.format('dddd [tuần tới lúc] LT'), 'Today + ' + i + ' days end of day');
  30974. }
  30975. });
  30976. test('calendar last week', function (assert) {
  30977. var i, m;
  30978. for (i = 2; i < 7; i++) {
  30979. m = moment().subtract({d: i});
  30980. assert.equal(m.calendar(), m.format('dddd [tuần rồi lúc] LT'), 'Today - ' + i + ' days current time');
  30981. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  30982. assert.equal(m.calendar(), m.format('dddd [tuần rồi lúc] LT'), 'Today - ' + i + ' days beginning of day');
  30983. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  30984. assert.equal(m.calendar(), m.format('dddd [tuần rồi lúc] LT'), 'Today - ' + i + ' days end of day');
  30985. }
  30986. });
  30987. test('calendar all else', function (assert) {
  30988. var weeksAgo = moment().subtract({w: 1}),
  30989. weeksFromNow = moment().add({w: 1});
  30990. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  30991. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  30992. weeksAgo = moment().subtract({w: 2});
  30993. weeksFromNow = moment().add({w: 2});
  30994. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  30995. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  30996. });
  30997. test('weeks year starting sunday', function (assert) {
  30998. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  30999. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
  31000. assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
  31001. assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
  31002. assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
  31003. });
  31004. test('weeks year starting monday', function (assert) {
  31005. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  31006. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  31007. assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
  31008. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  31009. assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
  31010. });
  31011. test('weeks year starting tuesday', function (assert) {
  31012. assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
  31013. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  31014. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  31015. assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
  31016. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  31017. assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
  31018. });
  31019. test('weeks year starting wednesday', function (assert) {
  31020. assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
  31021. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  31022. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  31023. assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
  31024. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  31025. assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
  31026. });
  31027. test('weeks year starting thursday', function (assert) {
  31028. assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
  31029. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  31030. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  31031. assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
  31032. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  31033. assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
  31034. });
  31035. test('weeks year starting friday', function (assert) {
  31036. assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
  31037. assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
  31038. assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
  31039. assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
  31040. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  31041. assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
  31042. });
  31043. test('weeks year starting saturday', function (assert) {
  31044. assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
  31045. assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
  31046. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  31047. assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
  31048. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  31049. assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
  31050. });
  31051. test('weeks year starting sunday formatted', function (assert) {
  31052. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52', 'Jan 1 2012 should be week 52');
  31053. assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1', 'Jan 2 2012 should be week 1');
  31054. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1', 'Jan 8 2012 should be week 1');
  31055. assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2', 'Jan 9 2012 should be week 2');
  31056. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2', 'Jan 15 2012 should be week 2');
  31057. });
  31058. test('lenient ordinal parsing', function (assert) {
  31059. var i, ordinalStr, testMoment;
  31060. for (i = 1; i <= 31; ++i) {
  31061. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  31062. testMoment = moment(ordinalStr, 'YYYY MM Do');
  31063. assert.equal(testMoment.year(), 2014,
  31064. 'lenient ordinal parsing ' + i + ' year check');
  31065. assert.equal(testMoment.month(), 0,
  31066. 'lenient ordinal parsing ' + i + ' month check');
  31067. assert.equal(testMoment.date(), i,
  31068. 'lenient ordinal parsing ' + i + ' date check');
  31069. }
  31070. });
  31071. test('lenient ordinal parsing of number', function (assert) {
  31072. var i, testMoment;
  31073. for (i = 1; i <= 31; ++i) {
  31074. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  31075. assert.equal(testMoment.year(), 2014,
  31076. 'lenient ordinal parsing of number ' + i + ' year check');
  31077. assert.equal(testMoment.month(), 0,
  31078. 'lenient ordinal parsing of number ' + i + ' month check');
  31079. assert.equal(testMoment.date(), i,
  31080. 'lenient ordinal parsing of number ' + i + ' date check');
  31081. }
  31082. });
  31083. test('strict ordinal parsing', function (assert) {
  31084. var i, ordinalStr, testMoment;
  31085. for (i = 1; i <= 31; ++i) {
  31086. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  31087. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  31088. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  31089. }
  31090. });
  31091. }));
  31092. ;(function (global, factory) {
  31093. typeof exports === 'object' && typeof module !== 'undefined'
  31094. && typeof require === 'function' ? factory(require('../../moment')) :
  31095. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  31096. factory(global.moment)
  31097. }(this, function (moment) { 'use strict';
  31098. /*global QUnit:false*/
  31099. var test = QUnit.test;
  31100. var expect = QUnit.expect;
  31101. function module (name, lifecycle) {
  31102. QUnit.module(name, {
  31103. setup : function () {
  31104. moment.locale('en');
  31105. moment.createFromInputFallback = function (config) {
  31106. throw new Error('input not handled by moment: ' + config._i);
  31107. };
  31108. if (lifecycle && lifecycle.setup) {
  31109. lifecycle.setup();
  31110. }
  31111. },
  31112. teardown : function () {
  31113. if (lifecycle && lifecycle.teardown) {
  31114. lifecycle.teardown();
  31115. }
  31116. }
  31117. });
  31118. }
  31119. function localeModule (name, lifecycle) {
  31120. QUnit.module('locale:' + name, {
  31121. setup : function () {
  31122. moment.locale(name);
  31123. moment.createFromInputFallback = function (config) {
  31124. throw new Error('input not handled by moment: ' + config._i);
  31125. };
  31126. if (lifecycle && lifecycle.setup) {
  31127. lifecycle.setup();
  31128. }
  31129. },
  31130. teardown : function () {
  31131. moment.locale('en');
  31132. if (lifecycle && lifecycle.teardown) {
  31133. lifecycle.teardown();
  31134. }
  31135. }
  31136. });
  31137. }
  31138. localeModule('zh-cn');
  31139. test('parse', function (assert) {
  31140. var tests = '一月 1月_二月 2月_三月 3月_四月 4月_五月 5月_六月 6月_七月 7月_八月 8月_九月 9月_十月 10月_十一月 11月_十二月 12月'.split('_'), i;
  31141. function equalTest(input, mmm, i) {
  31142. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  31143. }
  31144. for (i = 0; i < 12; i++) {
  31145. tests[i] = tests[i].split(' ');
  31146. equalTest(tests[i][0], 'MMM', i);
  31147. equalTest(tests[i][1], 'MMM', i);
  31148. equalTest(tests[i][0], 'MMMM', i);
  31149. equalTest(tests[i][1], 'MMMM', i);
  31150. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  31151. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  31152. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  31153. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  31154. }
  31155. });
  31156. test('format', function (assert) {
  31157. var a = [
  31158. ['dddd, MMMM Do YYYY, a h:mm:ss', '星期日, 二月 14日 2010, 下午 3:25:50'],
  31159. ['ddd, Ah', '周日, 下午3'],
  31160. ['M Mo MM MMMM MMM', '2 2月 02 二月 2月'],
  31161. ['YYYY YY', '2010 10'],
  31162. ['D Do DD', '14 14日 14'],
  31163. ['d do dddd ddd dd', '0 0日 星期日 周日 日'],
  31164. ['DDD DDDo DDDD', '45 45日 045'],
  31165. ['w wo ww', '6 6周 06'],
  31166. ['h hh', '3 03'],
  31167. ['H HH', '15 15'],
  31168. ['m mm', '25 25'],
  31169. ['s ss', '50 50'],
  31170. ['a A', '下午 下午'],
  31171. ['[这年的第] DDDo', '这年的第 45日'],
  31172. ['LTS', '下午3点25分50秒'],
  31173. ['L', '2010-02-14'],
  31174. ['LL', '2010年2月14日'],
  31175. ['LLL', '2010年2月14日下午3点25分'],
  31176. ['LLLL', '2010年2月14日星期日下午3点25分'],
  31177. ['l', '2010-02-14'],
  31178. ['ll', '2010年2月14日'],
  31179. ['lll', '2010年2月14日下午3点25分'],
  31180. ['llll', '2010年2月14日星期日下午3点25分']
  31181. ],
  31182. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  31183. i;
  31184. for (i = 0; i < a.length; i++) {
  31185. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  31186. }
  31187. });
  31188. test('format month', function (assert) {
  31189. var expected = '一月 1月_二月 2月_三月 3月_四月 4月_五月 5月_六月 6月_七月 7月_八月 8月_九月 9月_十月 10月_十一月 11月_十二月 12月'.split('_'), i;
  31190. for (i = 0; i < expected.length; i++) {
  31191. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  31192. }
  31193. });
  31194. test('format week', function (assert) {
  31195. var expected = '星期日 周日 日_星期一 周一 一_星期二 周二 二_星期三 周三 三_星期四 周四 四_星期五 周五 五_星期六 周六 六'.split('_'), i;
  31196. for (i = 0; i < expected.length; i++) {
  31197. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  31198. }
  31199. });
  31200. test('from', function (assert) {
  31201. var start = moment([2007, 1, 28]);
  31202. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), '几秒', '44 seconds = a few seconds');
  31203. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), '1 分钟', '45 seconds = a minute');
  31204. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), '1 分钟', '89 seconds = a minute');
  31205. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 分钟', '90 seconds = 2 minutes');
  31206. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 分钟', '44 minutes = 44 minutes');
  31207. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), '1 小时', '45 minutes = an hour');
  31208. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), '1 小时', '89 minutes = an hour');
  31209. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 小时', '90 minutes = 2 hours');
  31210. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 小时', '5 hours = 5 hours');
  31211. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 小时', '21 hours = 21 hours');
  31212. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), '1 天', '22 hours = a day');
  31213. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), '1 天', '35 hours = a day');
  31214. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 天', '36 hours = 2 days');
  31215. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), '1 天', '1 day = a day');
  31216. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 天', '5 days = 5 days');
  31217. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 天', '25 days = 25 days');
  31218. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), '1 个月', '26 days = a month');
  31219. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), '1 个月', '30 days = a month');
  31220. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), '1 个月', '43 days = a month');
  31221. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 个月', '46 days = 2 months');
  31222. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 个月', '75 days = 2 months');
  31223. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 个月', '76 days = 3 months');
  31224. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), '1 个月', '1 month = a month');
  31225. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 个月', '5 months = 5 months');
  31226. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), '1 年', '345 days = a year');
  31227. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 年', '548 days = 2 years');
  31228. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), '1 年', '1 year = a year');
  31229. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 年', '5 years = 5 years');
  31230. });
  31231. test('suffix', function (assert) {
  31232. assert.equal(moment(30000).from(0), '几秒内', 'prefix');
  31233. assert.equal(moment(0).from(30000), '几秒前', 'suffix');
  31234. });
  31235. test('now from now', function (assert) {
  31236. assert.equal(moment().fromNow(), '几秒前', 'now from now should display as in the past');
  31237. });
  31238. test('fromNow', function (assert) {
  31239. assert.equal(moment().add({s: 30}).fromNow(), '几秒内', 'in a few seconds');
  31240. assert.equal(moment().add({d: 5}).fromNow(), '5 天内', 'in 5 days');
  31241. });
  31242. test('calendar day', function (assert) {
  31243. var a = moment().hours(2).minutes(0).seconds(0);
  31244. assert.equal(moment(a).calendar(), '今天凌晨2点整', 'today at the same time');
  31245. assert.equal(moment(a).add({m: 25}).calendar(), '今天凌晨2点25分', 'Now plus 25 min');
  31246. assert.equal(moment(a).add({h: 1}).calendar(), '今天凌晨3点整', 'Now plus 1 hour');
  31247. assert.equal(moment(a).add({d: 1}).calendar(), '明天凌晨2点整', 'tomorrow at the same time');
  31248. assert.equal(moment(a).subtract({h: 1}).calendar(), '今天凌晨1点整', 'Now minus 1 hour');
  31249. assert.equal(moment(a).subtract({d: 1}).calendar(), '昨天凌晨2点整', 'yesterday at the same time');
  31250. });
  31251. test('calendar current week', function (assert) {
  31252. var i, m,
  31253. today = moment().startOf('day');
  31254. for (i = 0; i < 7; i++) {
  31255. m = moment().startOf('week').add({d: i});
  31256. if (Math.abs(m.diff(today, 'days')) <= 1) {
  31257. continue; // skip today, yesterday, tomorrow
  31258. }
  31259. assert.equal(m.calendar(), m.format('[本]ddd凌晨12点整'), 'Monday + ' + i + ' days current time');
  31260. }
  31261. });
  31262. test('calendar next week', function (assert) {
  31263. var i, m,
  31264. today = moment().startOf('day');
  31265. for (i = 7; i < 14; i++) {
  31266. m = moment().startOf('week').add({d: i});
  31267. if (Math.abs(m.diff(today, 'days')) >= 7) {
  31268. continue;
  31269. }
  31270. if (Math.abs(m.diff(today, 'days')) <= 1) {
  31271. continue; // skip today, yesterday, tomorrow
  31272. }
  31273. assert.equal(m.calendar(), m.format('[下]ddd凌晨12点整'), 'Today + ' + i + ' days beginning of day');
  31274. }
  31275. assert.equal(42, 42, 'at least one assert');
  31276. });
  31277. test('calendar last week', function (assert) {
  31278. var i, m,
  31279. today = moment().startOf('day');
  31280. for (i = 1; i < 8; i++) {
  31281. m = moment().startOf('week').subtract({d: i});
  31282. if ((Math.abs(m.diff(today, 'days')) >= 7) || (Math.abs(m.diff(today, 'days')) <= 1)) {
  31283. continue;
  31284. }
  31285. assert.equal(m.calendar(), m.format('[上]ddd凌晨12点整'), 'Monday - ' + i + ' days next week');
  31286. }
  31287. assert.equal(42, 42, 'at least one assert');
  31288. });
  31289. test('calendar all else', function (assert) {
  31290. var weeksAgo = moment().subtract({w: 1}),
  31291. weeksFromNow = moment().add({w: 1});
  31292. assert.equal(weeksAgo.calendar(), weeksAgo.format('LL'), '1 week ago');
  31293. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('LL'), 'in 1 week');
  31294. weeksAgo = moment().subtract({w: 2});
  31295. weeksFromNow = moment().add({w: 2});
  31296. assert.equal(weeksAgo.calendar(), weeksAgo.format('LL'), '2 weeks ago');
  31297. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('LL'), 'in 2 weeks');
  31298. });
  31299. test('meridiem', function (assert) {
  31300. assert.equal(moment([2011, 2, 23, 0, 0]).format('A'), '凌晨', 'before dawn');
  31301. assert.equal(moment([2011, 2, 23, 6, 0]).format('A'), '早上', 'morning');
  31302. assert.equal(moment([2011, 2, 23, 9, 0]).format('A'), '上午', 'before noon');
  31303. assert.equal(moment([2011, 2, 23, 12, 0]).format('A'), '中午', 'noon');
  31304. assert.equal(moment([2011, 2, 23, 13, 0]).format('A'), '下午', 'afternoon');
  31305. assert.equal(moment([2011, 2, 23, 18, 0]).format('A'), '晚上', 'night');
  31306. });
  31307. test('weeks year starting sunday', function (assert) {
  31308. assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
  31309. assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 52');
  31310. assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1');
  31311. assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2');
  31312. });
  31313. test('weeks year starting monday', function (assert) {
  31314. assert.equal(moment([2006, 11, 31]).week(), 52, 'Dec 31 2006 should be week 52');
  31315. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  31316. assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1');
  31317. assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
  31318. assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2');
  31319. assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
  31320. });
  31321. test('weeks year starting tuesday', function (assert) {
  31322. assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52');
  31323. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  31324. assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1');
  31325. assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
  31326. assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2');
  31327. assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
  31328. });
  31329. test('weeks year starting wednesday', function (assert) {
  31330. assert.equal(moment([2002, 11, 29]).week(), 52, 'Dec 29 2002 should be week 52');
  31331. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  31332. assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1');
  31333. assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
  31334. assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2');
  31335. assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
  31336. });
  31337. test('weeks year starting thursday', function (assert) {
  31338. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  31339. assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1');
  31340. assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
  31341. assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2');
  31342. assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
  31343. });
  31344. test('weeks year starting friday', function (assert) {
  31345. assert.equal(moment([2010, 0, 2]).week(), 53, 'Jan 2 2010 should be week 53');
  31346. assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
  31347. });
  31348. test('weeks year starting saturday', function (assert) {
  31349. assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
  31350. assert.equal(moment([2011, 0, 8]).week(), 1, 'Jan 8 2011 should be week 1');
  31351. assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
  31352. });
  31353. test('weeks year starting sunday format', function (assert) {
  31354. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52周', 'Jan 1 2012 应该是第52周');
  31355. assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1周', 'Jan 7 2012 应该是第 1周');
  31356. assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2周', 'Jan 14 2012 应该是第 2周');
  31357. });
  31358. test('lenient ordinal parsing', function (assert) {
  31359. var i, ordinalStr, testMoment;
  31360. for (i = 1; i <= 31; ++i) {
  31361. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  31362. testMoment = moment(ordinalStr, 'YYYY MM Do');
  31363. assert.equal(testMoment.year(), 2014,
  31364. 'lenient ordinal parsing ' + i + ' year check');
  31365. assert.equal(testMoment.month(), 0,
  31366. 'lenient ordinal parsing ' + i + ' month check');
  31367. assert.equal(testMoment.date(), i,
  31368. 'lenient ordinal parsing ' + i + ' date check');
  31369. }
  31370. });
  31371. test('lenient ordinal parsing of number', function (assert) {
  31372. var i, testMoment;
  31373. for (i = 1; i <= 31; ++i) {
  31374. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  31375. assert.equal(testMoment.year(), 2014,
  31376. 'lenient ordinal parsing of number ' + i + ' year check');
  31377. assert.equal(testMoment.month(), 0,
  31378. 'lenient ordinal parsing of number ' + i + ' month check');
  31379. assert.equal(testMoment.date(), i,
  31380. 'lenient ordinal parsing of number ' + i + ' date check');
  31381. }
  31382. });
  31383. test('meridiem invariant', function (assert) {
  31384. var h, m, t1, t2;
  31385. for (h = 0; h < 24; ++h) {
  31386. for (m = 0; m < 60; m += 15) {
  31387. t1 = moment.utc([2000, 0, 1, h, m]);
  31388. t2 = moment(t1.format('A h:mm'), 'A h:mm');
  31389. assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
  31390. 'meridiem at ' + t1.format('HH:mm'));
  31391. }
  31392. }
  31393. });
  31394. test('strict ordinal parsing', function (assert) {
  31395. var i, ordinalStr, testMoment;
  31396. for (i = 1; i <= 31; ++i) {
  31397. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  31398. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  31399. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  31400. }
  31401. });
  31402. }));
  31403. ;(function (global, factory) {
  31404. typeof exports === 'object' && typeof module !== 'undefined'
  31405. && typeof require === 'function' ? factory(require('../../moment')) :
  31406. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  31407. factory(global.moment)
  31408. }(this, function (moment) { 'use strict';
  31409. /*global QUnit:false*/
  31410. var test = QUnit.test;
  31411. var expect = QUnit.expect;
  31412. function module (name, lifecycle) {
  31413. QUnit.module(name, {
  31414. setup : function () {
  31415. moment.locale('en');
  31416. moment.createFromInputFallback = function (config) {
  31417. throw new Error('input not handled by moment: ' + config._i);
  31418. };
  31419. if (lifecycle && lifecycle.setup) {
  31420. lifecycle.setup();
  31421. }
  31422. },
  31423. teardown : function () {
  31424. if (lifecycle && lifecycle.teardown) {
  31425. lifecycle.teardown();
  31426. }
  31427. }
  31428. });
  31429. }
  31430. function localeModule (name, lifecycle) {
  31431. QUnit.module('locale:' + name, {
  31432. setup : function () {
  31433. moment.locale(name);
  31434. moment.createFromInputFallback = function (config) {
  31435. throw new Error('input not handled by moment: ' + config._i);
  31436. };
  31437. if (lifecycle && lifecycle.setup) {
  31438. lifecycle.setup();
  31439. }
  31440. },
  31441. teardown : function () {
  31442. moment.locale('en');
  31443. if (lifecycle && lifecycle.teardown) {
  31444. lifecycle.teardown();
  31445. }
  31446. }
  31447. });
  31448. }
  31449. localeModule('zh-tw');
  31450. test('parse', function (assert) {
  31451. var tests = '一月 1月_二月 2月_三月 3月_四月 4月_五月 5月_六月 6月_七月 7月_八月 8月_九月 9月_十月 10月_十一月 11月_十二月 12月'.split('_'), i;
  31452. function equalTest(input, mmm, i) {
  31453. assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
  31454. }
  31455. for (i = 0; i < 12; i++) {
  31456. tests[i] = tests[i].split(' ');
  31457. equalTest(tests[i][0], 'MMM', i);
  31458. equalTest(tests[i][1], 'MMM', i);
  31459. equalTest(tests[i][0], 'MMMM', i);
  31460. equalTest(tests[i][1], 'MMMM', i);
  31461. equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
  31462. equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
  31463. equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
  31464. equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
  31465. }
  31466. });
  31467. test('format', function (assert) {
  31468. var a = [
  31469. ['dddd, MMMM Do YYYY, a h:mm:ss', '星期日, 二月 14日 2010, 下午 3:25:50'],
  31470. ['ddd, Ah', '週日, 下午3'],
  31471. ['M Mo MM MMMM MMM', '2 2月 02 二月 2月'],
  31472. ['YYYY YY', '2010 10'],
  31473. ['D Do DD', '14 14日 14'],
  31474. ['d do dddd ddd dd', '0 0日 星期日 週日 日'],
  31475. ['DDD DDDo DDDD', '45 45日 045'],
  31476. ['w wo ww', '8 8週 08'],
  31477. ['h hh', '3 03'],
  31478. ['H HH', '15 15'],
  31479. ['m mm', '25 25'],
  31480. ['s ss', '50 50'],
  31481. ['a A', '下午 下午'],
  31482. ['[這年的第] DDDo', '這年的第 45日'],
  31483. ['LTS', '下午3點25分50秒'],
  31484. ['L', '2010年2月14日'],
  31485. ['LL', '2010年2月14日'],
  31486. ['LLL', '2010年2月14日下午3點25分'],
  31487. ['LLLL', '2010年2月14日星期日下午3點25分'],
  31488. ['l', '2010年2月14日'],
  31489. ['ll', '2010年2月14日'],
  31490. ['lll', '2010年2月14日下午3點25分'],
  31491. ['llll', '2010年2月14日星期日下午3點25分']
  31492. ],
  31493. b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
  31494. i;
  31495. for (i = 0; i < a.length; i++) {
  31496. assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  31497. }
  31498. });
  31499. test('format month', function (assert) {
  31500. var expected = '一月 1月_二月 2月_三月 3月_四月 4月_五月 5月_六月 6月_七月 7月_八月 8月_九月 9月_十月 10月_十一月 11月_十二月 12月'.split('_'), i;
  31501. for (i = 0; i < expected.length; i++) {
  31502. assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
  31503. }
  31504. });
  31505. test('format week', function (assert) {
  31506. var expected = '星期日 週日 日_星期一 週一 一_星期二 週二 二_星期三 週三 三_星期四 週四 四_星期五 週五 五_星期六 週六 六'.split('_'), i;
  31507. for (i = 0; i < expected.length; i++) {
  31508. assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
  31509. }
  31510. });
  31511. test('from', function (assert) {
  31512. var start = moment([2007, 1, 28]);
  31513. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), '幾秒', '44 seconds = a few seconds');
  31514. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), '一分鐘', '45 seconds = a minute');
  31515. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), '一分鐘', '89 seconds = a minute');
  31516. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2分鐘', '90 seconds = 2 minutes');
  31517. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44分鐘', '44 minutes = 44 minutes');
  31518. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), '一小時', '45 minutes = an hour');
  31519. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), '一小時', '89 minutes = an hour');
  31520. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2小時', '90 minutes = 2 hours');
  31521. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5小時', '5 hours = 5 hours');
  31522. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21小時', '21 hours = 21 hours');
  31523. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), '一天', '22 hours = a day');
  31524. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), '一天', '35 hours = a day');
  31525. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2天', '36 hours = 2 days');
  31526. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), '一天', '1 day = a day');
  31527. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5天', '5 days = 5 days');
  31528. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25天', '25 days = 25 days');
  31529. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), '一個月', '26 days = a month');
  31530. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), '一個月', '30 days = a month');
  31531. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), '一個月', '43 days = a month');
  31532. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2個月', '46 days = 2 months');
  31533. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2個月', '75 days = 2 months');
  31534. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3個月', '76 days = 3 months');
  31535. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), '一個月', '1 month = a month');
  31536. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5個月', '5 months = 5 months');
  31537. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), '一年', '345 days = a year');
  31538. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2年', '548 days = 2 years');
  31539. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), '一年', '1 year = a year');
  31540. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5年', '5 years = 5 years');
  31541. });
  31542. test('suffix', function (assert) {
  31543. assert.equal(moment(30000).from(0), '幾秒內', 'prefix');
  31544. assert.equal(moment(0).from(30000), '幾秒前', 'suffix');
  31545. });
  31546. test('now from now', function (assert) {
  31547. assert.equal(moment().fromNow(), '幾秒前', 'now from now should display as in the past');
  31548. });
  31549. test('fromNow', function (assert) {
  31550. assert.equal(moment().add({s: 30}).fromNow(), '幾秒內', 'in a few seconds');
  31551. assert.equal(moment().add({d: 5}).fromNow(), '5天內', 'in 5 days');
  31552. });
  31553. test('calendar day', function (assert) {
  31554. var a = moment().hours(2).minutes(0).seconds(0);
  31555. assert.equal(moment(a).calendar(), '今天早上2點00分', 'today at the same time');
  31556. assert.equal(moment(a).add({m: 25}).calendar(), '今天早上2點25分', 'Now plus 25 min');
  31557. assert.equal(moment(a).add({h: 1}).calendar(), '今天早上3點00分', 'Now plus 1 hour');
  31558. assert.equal(moment(a).add({d: 1}).calendar(), '明天早上2點00分', 'tomorrow at the same time');
  31559. assert.equal(moment(a).subtract({h: 1}).calendar(), '今天早上1點00分', 'Now minus 1 hour');
  31560. assert.equal(moment(a).subtract({d: 1}).calendar(), '昨天早上2點00分', 'yesterday at the same time');
  31561. });
  31562. test('calendar next week', function (assert) {
  31563. var i, m;
  31564. for (i = 2; i < 7; i++) {
  31565. m = moment().add({d: i});
  31566. assert.equal(m.calendar(), m.format('[下]ddddLT'), 'Today + ' + i + ' days current time');
  31567. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  31568. assert.equal(m.calendar(), m.format('[下]ddddLT'), 'Today + ' + i + ' days beginning of day');
  31569. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  31570. assert.equal(m.calendar(), m.format('[下]ddddLT'), 'Today + ' + i + ' days end of day');
  31571. }
  31572. });
  31573. test('calendar last week', function (assert) {
  31574. var i, m;
  31575. for (i = 2; i < 7; i++) {
  31576. m = moment().subtract({d: i});
  31577. assert.equal(m.calendar(), m.format('[上]ddddLT'), 'Today - ' + i + ' days current time');
  31578. m.hours(0).minutes(0).seconds(0).milliseconds(0);
  31579. assert.equal(m.calendar(), m.format('[上]ddddLT'), 'Today - ' + i + ' days beginning of day');
  31580. m.hours(23).minutes(59).seconds(59).milliseconds(999);
  31581. assert.equal(m.calendar(), m.format('[上]ddddLT'), 'Today - ' + i + ' days end of day');
  31582. }
  31583. });
  31584. test('calendar all else', function (assert) {
  31585. var weeksAgo = moment().subtract({w: 1}),
  31586. weeksFromNow = moment().add({w: 1});
  31587. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
  31588. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
  31589. weeksAgo = moment().subtract({w: 2});
  31590. weeksFromNow = moment().add({w: 2});
  31591. assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
  31592. assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
  31593. });
  31594. test('meridiem', function (assert) {
  31595. assert.equal(moment([2011, 2, 23, 0, 0]).format('a'), '早上', 'morning');
  31596. assert.equal(moment([2011, 2, 23, 9, 0]).format('a'), '上午', 'before noon');
  31597. assert.equal(moment([2011, 2, 23, 12, 0]).format('a'), '中午', 'noon');
  31598. assert.equal(moment([2011, 2, 23, 13, 0]).format('a'), '下午', 'after noon');
  31599. assert.equal(moment([2011, 2, 23, 18, 0]).format('a'), '晚上', 'night');
  31600. assert.equal(moment([2011, 2, 23, 0, 0]).format('A'), '早上', 'morning');
  31601. assert.equal(moment([2011, 2, 23, 9, 0]).format('A'), '上午', 'before noon');
  31602. assert.equal(moment([2011, 2, 23, 12, 0]).format('A'), '中午', 'noon');
  31603. assert.equal(moment([2011, 2, 23, 13, 0]).format('A'), '下午', 'afternoon');
  31604. assert.equal(moment([2011, 2, 23, 18, 0]).format('A'), '晚上', 'night');
  31605. });
  31606. test('weeks year starting sunday', function (assert) {
  31607. assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
  31608. assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1');
  31609. assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
  31610. assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2');
  31611. assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 3');
  31612. });
  31613. test('weeks year starting monday', function (assert) {
  31614. assert.equal(moment([2006, 11, 31]).week(), 1, 'Dec 31 2006 should be week 1');
  31615. assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
  31616. assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1');
  31617. assert.equal(moment([2007, 0, 7]).week(), 2, 'Jan 7 2007 should be week 2');
  31618. assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2');
  31619. assert.equal(moment([2007, 0, 14]).week(), 3, 'Jan 14 2007 should be week 3');
  31620. });
  31621. test('weeks year starting tuesday', function (assert) {
  31622. assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52');
  31623. assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
  31624. assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1');
  31625. assert.equal(moment([2008, 0, 6]).week(), 2, 'Jan 6 2008 should be week 2');
  31626. assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2');
  31627. assert.equal(moment([2008, 0, 13]).week(), 3, 'Jan 13 2008 should be week 3');
  31628. });
  31629. test('weeks year starting wednesday', function (assert) {
  31630. assert.equal(moment([2002, 11, 29]).week(), 1, 'Dec 29 2002 should be week 1');
  31631. assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
  31632. assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1');
  31633. assert.equal(moment([2003, 0, 5]).week(), 2, 'Jan 5 2003 should be week 2');
  31634. assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2');
  31635. assert.equal(moment([2003, 0, 12]).week(), 3, 'Jan 12 2003 should be week 3');
  31636. });
  31637. test('weeks year starting thursday', function (assert) {
  31638. assert.equal(moment([2008, 11, 28]).week(), 1, 'Dec 28 2008 should be week 1');
  31639. assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
  31640. assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1');
  31641. assert.equal(moment([2009, 0, 4]).week(), 2, 'Jan 4 2009 should be week 2');
  31642. assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2');
  31643. assert.equal(moment([2009, 0, 11]).week(), 3, 'Jan 11 2009 should be week 3');
  31644. });
  31645. test('weeks year starting friday', function (assert) {
  31646. assert.equal(moment([2009, 11, 27]).week(), 1, 'Dec 27 2009 should be week 1');
  31647. assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
  31648. assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 should be week 1');
  31649. assert.equal(moment([2010, 0, 3]).week(), 2, 'Jan 3 2010 should be week 2');
  31650. assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 should be week 2');
  31651. assert.equal(moment([2010, 0, 10]).week(), 3, 'Jan 10 2010 should be week 3');
  31652. });
  31653. test('weeks year starting saturday', function (assert) {
  31654. assert.equal(moment([2010, 11, 26]).week(), 1, 'Dec 26 2010 should be week 1');
  31655. assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
  31656. assert.equal(moment([2011, 0, 2]).week(), 2, 'Jan 2 2011 should be week 2');
  31657. assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2');
  31658. assert.equal(moment([2011, 0, 9]).week(), 3, 'Jan 9 2011 should be week 3');
  31659. });
  31660. test('weeks year starting sunday format', function (assert) {
  31661. assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1週', 'Jan 1 2012 應該是第 1週');
  31662. assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1週', 'Jan 7 2012 應該是第 1週');
  31663. assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2週', 'Jan 8 2012 應該是第 2週');
  31664. assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2週', 'Jan 14 2012 應該是第 2週');
  31665. assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3週', 'Jan 15 2012 應該是第 3週');
  31666. });
  31667. test('lenient ordinal parsing', function (assert) {
  31668. var i, ordinalStr, testMoment;
  31669. for (i = 1; i <= 31; ++i) {
  31670. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  31671. testMoment = moment(ordinalStr, 'YYYY MM Do');
  31672. assert.equal(testMoment.year(), 2014,
  31673. 'lenient ordinal parsing ' + i + ' year check');
  31674. assert.equal(testMoment.month(), 0,
  31675. 'lenient ordinal parsing ' + i + ' month check');
  31676. assert.equal(testMoment.date(), i,
  31677. 'lenient ordinal parsing ' + i + ' date check');
  31678. }
  31679. });
  31680. test('lenient ordinal parsing of number', function (assert) {
  31681. var i, testMoment;
  31682. for (i = 1; i <= 31; ++i) {
  31683. testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
  31684. assert.equal(testMoment.year(), 2014,
  31685. 'lenient ordinal parsing of number ' + i + ' year check');
  31686. assert.equal(testMoment.month(), 0,
  31687. 'lenient ordinal parsing of number ' + i + ' month check');
  31688. assert.equal(testMoment.date(), i,
  31689. 'lenient ordinal parsing of number ' + i + ' date check');
  31690. }
  31691. });
  31692. test('meridiem invariant', function (assert) {
  31693. var h, m, t1, t2;
  31694. for (h = 0; h < 24; ++h) {
  31695. for (m = 0; m < 60; m += 15) {
  31696. t1 = moment.utc([2000, 0, 1, h, m]);
  31697. t2 = moment(t1.format('A h:mm'), 'A h:mm');
  31698. assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
  31699. 'meridiem at ' + t1.format('HH:mm'));
  31700. }
  31701. }
  31702. });
  31703. test('strict ordinal parsing', function (assert) {
  31704. var i, ordinalStr, testMoment;
  31705. for (i = 1; i <= 31; ++i) {
  31706. ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
  31707. testMoment = moment(ordinalStr, 'YYYY MM Do', true);
  31708. assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
  31709. }
  31710. });
  31711. }));
  31712. ;(function (global, factory) {
  31713. typeof exports === 'object' && typeof module !== 'undefined'
  31714. && typeof require === 'function' ? factory(require('../../moment')) :
  31715. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  31716. factory(global.moment)
  31717. }(this, function (moment) { 'use strict';
  31718. /*global QUnit:false*/
  31719. var test = QUnit.test;
  31720. var expect = QUnit.expect;
  31721. function module (name, lifecycle) {
  31722. QUnit.module(name, {
  31723. setup : function () {
  31724. moment.locale('en');
  31725. moment.createFromInputFallback = function (config) {
  31726. throw new Error('input not handled by moment: ' + config._i);
  31727. };
  31728. if (lifecycle && lifecycle.setup) {
  31729. lifecycle.setup();
  31730. }
  31731. },
  31732. teardown : function () {
  31733. if (lifecycle && lifecycle.teardown) {
  31734. lifecycle.teardown();
  31735. }
  31736. }
  31737. });
  31738. }
  31739. function localeModule (name, lifecycle) {
  31740. QUnit.module('locale:' + name, {
  31741. setup : function () {
  31742. moment.locale(name);
  31743. moment.createFromInputFallback = function (config) {
  31744. throw new Error('input not handled by moment: ' + config._i);
  31745. };
  31746. if (lifecycle && lifecycle.setup) {
  31747. lifecycle.setup();
  31748. }
  31749. },
  31750. teardown : function () {
  31751. moment.locale('en');
  31752. if (lifecycle && lifecycle.teardown) {
  31753. lifecycle.teardown();
  31754. }
  31755. }
  31756. });
  31757. }
  31758. module('add and subtract');
  31759. test('add short reverse args', function (assert) {
  31760. var a = moment(), b, c, d;
  31761. a.year(2011);
  31762. a.month(9);
  31763. a.date(12);
  31764. a.hours(6);
  31765. a.minutes(7);
  31766. a.seconds(8);
  31767. a.milliseconds(500);
  31768. assert.equal(a.add({ms: 50}).milliseconds(), 550, 'Add milliseconds');
  31769. assert.equal(a.add({s: 1}).seconds(), 9, 'Add seconds');
  31770. assert.equal(a.add({m: 1}).minutes(), 8, 'Add minutes');
  31771. assert.equal(a.add({h: 1}).hours(), 7, 'Add hours');
  31772. assert.equal(a.add({d: 1}).date(), 13, 'Add date');
  31773. assert.equal(a.add({w: 1}).date(), 20, 'Add week');
  31774. assert.equal(a.add({M: 1}).month(), 10, 'Add month');
  31775. assert.equal(a.add({y: 1}).year(), 2012, 'Add year');
  31776. assert.equal(a.add({Q: 1}).month(), 1, 'Add quarter');
  31777. b = moment([2010, 0, 31]).add({M: 1});
  31778. c = moment([2010, 1, 28]).subtract({M: 1});
  31779. d = moment([2010, 1, 28]).subtract({Q: 1});
  31780. assert.equal(b.month(), 1, 'add month, jan 31st to feb 28th');
  31781. assert.equal(b.date(), 28, 'add month, jan 31st to feb 28th');
  31782. assert.equal(c.month(), 0, 'subtract month, feb 28th to jan 28th');
  31783. assert.equal(c.date(), 28, 'subtract month, feb 28th to jan 28th');
  31784. assert.equal(d.month(), 10, 'subtract quarter, feb 28th 2010 to nov 28th 2009');
  31785. assert.equal(d.date(), 28, 'subtract quarter, feb 28th 2010 to nov 28th 2009');
  31786. assert.equal(d.year(), 2009, 'subtract quarter, feb 28th 2010 to nov 28th 2009');
  31787. });
  31788. test('add long reverse args', function (assert) {
  31789. var a = moment();
  31790. a.year(2011);
  31791. a.month(9);
  31792. a.date(12);
  31793. a.hours(6);
  31794. a.minutes(7);
  31795. a.seconds(8);
  31796. a.milliseconds(500);
  31797. assert.equal(a.add({milliseconds: 50}).milliseconds(), 550, 'Add milliseconds');
  31798. assert.equal(a.add({seconds: 1}).seconds(), 9, 'Add seconds');
  31799. assert.equal(a.add({minutes: 1}).minutes(), 8, 'Add minutes');
  31800. assert.equal(a.add({hours: 1}).hours(), 7, 'Add hours');
  31801. assert.equal(a.add({days: 1}).date(), 13, 'Add date');
  31802. assert.equal(a.add({weeks: 1}).date(), 20, 'Add week');
  31803. assert.equal(a.add({months: 1}).month(), 10, 'Add month');
  31804. assert.equal(a.add({years: 1}).year(), 2012, 'Add year');
  31805. assert.equal(a.add({quarters: 1}).month(), 1, 'Add quarter');
  31806. });
  31807. test('add long singular reverse args', function (assert) {
  31808. var a = moment();
  31809. a.year(2011);
  31810. a.month(9);
  31811. a.date(12);
  31812. a.hours(6);
  31813. a.minutes(7);
  31814. a.seconds(8);
  31815. a.milliseconds(500);
  31816. assert.equal(a.add({millisecond: 50}).milliseconds(), 550, 'Add milliseconds');
  31817. assert.equal(a.add({second: 1}).seconds(), 9, 'Add seconds');
  31818. assert.equal(a.add({minute: 1}).minutes(), 8, 'Add minutes');
  31819. assert.equal(a.add({hour: 1}).hours(), 7, 'Add hours');
  31820. assert.equal(a.add({day: 1}).date(), 13, 'Add date');
  31821. assert.equal(a.add({week: 1}).date(), 20, 'Add week');
  31822. assert.equal(a.add({month: 1}).month(), 10, 'Add month');
  31823. assert.equal(a.add({year: 1}).year(), 2012, 'Add year');
  31824. assert.equal(a.add({quarter: 1}).month(), 1, 'Add quarter');
  31825. });
  31826. test('add string long reverse args', function (assert) {
  31827. var a = moment(), b;
  31828. a.year(2011);
  31829. a.month(9);
  31830. a.date(12);
  31831. a.hours(6);
  31832. a.minutes(7);
  31833. a.seconds(8);
  31834. a.milliseconds(500);
  31835. b = a.clone();
  31836. assert.equal(a.add('millisecond', 50).milliseconds(), 550, 'Add milliseconds');
  31837. assert.equal(a.add('second', 1).seconds(), 9, 'Add seconds');
  31838. assert.equal(a.add('minute', 1).minutes(), 8, 'Add minutes');
  31839. assert.equal(a.add('hour', 1).hours(), 7, 'Add hours');
  31840. assert.equal(a.add('day', 1).date(), 13, 'Add date');
  31841. assert.equal(a.add('week', 1).date(), 20, 'Add week');
  31842. assert.equal(a.add('month', 1).month(), 10, 'Add month');
  31843. assert.equal(a.add('year', 1).year(), 2012, 'Add year');
  31844. assert.equal(b.add('day', '01').date(), 13, 'Add date');
  31845. assert.equal(a.add('quarter', 1).month(), 1, 'Add quarter');
  31846. });
  31847. test('add string long singular reverse args', function (assert) {
  31848. var a = moment(), b;
  31849. a.year(2011);
  31850. a.month(9);
  31851. a.date(12);
  31852. a.hours(6);
  31853. a.minutes(7);
  31854. a.seconds(8);
  31855. a.milliseconds(500);
  31856. b = a.clone();
  31857. assert.equal(a.add('milliseconds', 50).milliseconds(), 550, 'Add milliseconds');
  31858. assert.equal(a.add('seconds', 1).seconds(), 9, 'Add seconds');
  31859. assert.equal(a.add('minutes', 1).minutes(), 8, 'Add minutes');
  31860. assert.equal(a.add('hours', 1).hours(), 7, 'Add hours');
  31861. assert.equal(a.add('days', 1).date(), 13, 'Add date');
  31862. assert.equal(a.add('weeks', 1).date(), 20, 'Add week');
  31863. assert.equal(a.add('months', 1).month(), 10, 'Add month');
  31864. assert.equal(a.add('years', 1).year(), 2012, 'Add year');
  31865. assert.equal(b.add('days', '01').date(), 13, 'Add date');
  31866. assert.equal(a.add('quarters', 1).month(), 1, 'Add quarter');
  31867. });
  31868. test('add string short reverse args', function (assert) {
  31869. var a = moment();
  31870. a.year(2011);
  31871. a.month(9);
  31872. a.date(12);
  31873. a.hours(6);
  31874. a.minutes(7);
  31875. a.seconds(8);
  31876. a.milliseconds(500);
  31877. assert.equal(a.add('ms', 50).milliseconds(), 550, 'Add milliseconds');
  31878. assert.equal(a.add('s', 1).seconds(), 9, 'Add seconds');
  31879. assert.equal(a.add('m', 1).minutes(), 8, 'Add minutes');
  31880. assert.equal(a.add('h', 1).hours(), 7, 'Add hours');
  31881. assert.equal(a.add('d', 1).date(), 13, 'Add date');
  31882. assert.equal(a.add('w', 1).date(), 20, 'Add week');
  31883. assert.equal(a.add('M', 1).month(), 10, 'Add month');
  31884. assert.equal(a.add('y', 1).year(), 2012, 'Add year');
  31885. assert.equal(a.add('Q', 1).month(), 1, 'Add quarter');
  31886. });
  31887. test('add string long', function (assert) {
  31888. var a = moment();
  31889. a.year(2011);
  31890. a.month(9);
  31891. a.date(12);
  31892. a.hours(6);
  31893. a.minutes(7);
  31894. a.seconds(8);
  31895. a.milliseconds(500);
  31896. assert.equal(a.add(50, 'millisecond').milliseconds(), 550, 'Add milliseconds');
  31897. assert.equal(a.add(1, 'second').seconds(), 9, 'Add seconds');
  31898. assert.equal(a.add(1, 'minute').minutes(), 8, 'Add minutes');
  31899. assert.equal(a.add(1, 'hour').hours(), 7, 'Add hours');
  31900. assert.equal(a.add(1, 'day').date(), 13, 'Add date');
  31901. assert.equal(a.add(1, 'week').date(), 20, 'Add week');
  31902. assert.equal(a.add(1, 'month').month(), 10, 'Add month');
  31903. assert.equal(a.add(1, 'year').year(), 2012, 'Add year');
  31904. assert.equal(a.add(1, 'quarter').month(), 1, 'Add quarter');
  31905. });
  31906. test('add string long singular', function (assert) {
  31907. var a = moment();
  31908. a.year(2011);
  31909. a.month(9);
  31910. a.date(12);
  31911. a.hours(6);
  31912. a.minutes(7);
  31913. a.seconds(8);
  31914. a.milliseconds(500);
  31915. assert.equal(a.add(50, 'milliseconds').milliseconds(), 550, 'Add milliseconds');
  31916. assert.equal(a.add(1, 'seconds').seconds(), 9, 'Add seconds');
  31917. assert.equal(a.add(1, 'minutes').minutes(), 8, 'Add minutes');
  31918. assert.equal(a.add(1, 'hours').hours(), 7, 'Add hours');
  31919. assert.equal(a.add(1, 'days').date(), 13, 'Add date');
  31920. assert.equal(a.add(1, 'weeks').date(), 20, 'Add week');
  31921. assert.equal(a.add(1, 'months').month(), 10, 'Add month');
  31922. assert.equal(a.add(1, 'years').year(), 2012, 'Add year');
  31923. assert.equal(a.add(1, 'quarters').month(), 1, 'Add quarter');
  31924. });
  31925. test('add string short', function (assert) {
  31926. var a = moment();
  31927. a.year(2011);
  31928. a.month(9);
  31929. a.date(12);
  31930. a.hours(6);
  31931. a.minutes(7);
  31932. a.seconds(8);
  31933. a.milliseconds(500);
  31934. assert.equal(a.add(50, 'ms').milliseconds(), 550, 'Add milliseconds');
  31935. assert.equal(a.add(1, 's').seconds(), 9, 'Add seconds');
  31936. assert.equal(a.add(1, 'm').minutes(), 8, 'Add minutes');
  31937. assert.equal(a.add(1, 'h').hours(), 7, 'Add hours');
  31938. assert.equal(a.add(1, 'd').date(), 13, 'Add date');
  31939. assert.equal(a.add(1, 'w').date(), 20, 'Add week');
  31940. assert.equal(a.add(1, 'M').month(), 10, 'Add month');
  31941. assert.equal(a.add(1, 'y').year(), 2012, 'Add year');
  31942. assert.equal(a.add(1, 'Q').month(), 1, 'Add quarter');
  31943. });
  31944. test('add strings string short args', function (assert) {
  31945. var a = moment();
  31946. a.year(2011);
  31947. a.month(9);
  31948. a.date(12);
  31949. a.hours(6);
  31950. a.minutes(7);
  31951. a.seconds(8);
  31952. a.milliseconds(500);
  31953. assert.equal(a.add('ms', '50').milliseconds(), 550, 'Add milliseconds');
  31954. assert.equal(a.add('s', '1').seconds(), 9, 'Add seconds');
  31955. assert.equal(a.add('m', '1').minutes(), 8, 'Add minutes');
  31956. assert.equal(a.add('h', '1').hours(), 7, 'Add hours');
  31957. assert.equal(a.add('d', '1').date(), 13, 'Add date');
  31958. assert.equal(a.add('w', '1').date(), 20, 'Add week');
  31959. assert.equal(a.add('M', '1').month(), 10, 'Add month');
  31960. assert.equal(a.add('y', '1').year(), 2012, 'Add year');
  31961. assert.equal(a.add('Q', '1').month(), 1, 'Add quarter');
  31962. });
  31963. test('subtract strings string short args', function (assert) {
  31964. var a = moment();
  31965. a.year(2011);
  31966. a.month(9);
  31967. a.date(12);
  31968. a.hours(6);
  31969. a.minutes(7);
  31970. a.seconds(8);
  31971. a.milliseconds(500);
  31972. assert.equal(a.subtract('ms', '50').milliseconds(), 450, 'Subtract milliseconds');
  31973. assert.equal(a.subtract('s', '1').seconds(), 7, 'Subtract seconds');
  31974. assert.equal(a.subtract('m', '1').minutes(), 6, 'Subtract minutes');
  31975. assert.equal(a.subtract('h', '1').hours(), 5, 'Subtract hours');
  31976. assert.equal(a.subtract('d', '1').date(), 11, 'Subtract date');
  31977. assert.equal(a.subtract('w', '1').date(), 4, 'Subtract week');
  31978. assert.equal(a.subtract('M', '1').month(), 8, 'Subtract month');
  31979. assert.equal(a.subtract('y', '1').year(), 2010, 'Subtract year');
  31980. assert.equal(a.subtract('Q', '1').month(), 5, 'Subtract quarter');
  31981. });
  31982. test('add strings string short', function (assert) {
  31983. var a = moment();
  31984. a.year(2011);
  31985. a.month(9);
  31986. a.date(12);
  31987. a.hours(6);
  31988. a.minutes(7);
  31989. a.seconds(8);
  31990. a.milliseconds(500);
  31991. assert.equal(a.add('50', 'ms').milliseconds(), 550, 'Add milliseconds');
  31992. assert.equal(a.add('1', 's').seconds(), 9, 'Add seconds');
  31993. assert.equal(a.add('1', 'm').minutes(), 8, 'Add minutes');
  31994. assert.equal(a.add('1', 'h').hours(), 7, 'Add hours');
  31995. assert.equal(a.add('1', 'd').date(), 13, 'Add date');
  31996. assert.equal(a.add('1', 'w').date(), 20, 'Add week');
  31997. assert.equal(a.add('1', 'M').month(), 10, 'Add month');
  31998. assert.equal(a.add('1', 'y').year(), 2012, 'Add year');
  31999. assert.equal(a.add('1', 'Q').month(), 1, 'Add quarter');
  32000. });
  32001. test('subtract strings string short', function (assert) {
  32002. var a = moment();
  32003. a.year(2011);
  32004. a.month(9);
  32005. a.date(12);
  32006. a.hours(6);
  32007. a.minutes(7);
  32008. a.seconds(8);
  32009. a.milliseconds(500);
  32010. assert.equal(a.subtract('50', 'ms').milliseconds(), 450, 'Subtract milliseconds');
  32011. assert.equal(a.subtract('1', 's').seconds(), 7, 'Subtract seconds');
  32012. assert.equal(a.subtract('1', 'm').minutes(), 6, 'Subtract minutes');
  32013. assert.equal(a.subtract('1', 'h').hours(), 5, 'Subtract hours');
  32014. assert.equal(a.subtract('1', 'd').date(), 11, 'Subtract date');
  32015. assert.equal(a.subtract('1', 'w').date(), 4, 'Subtract week');
  32016. assert.equal(a.subtract('1', 'M').month(), 8, 'Subtract month');
  32017. assert.equal(a.subtract('1', 'y').year(), 2010, 'Subtract year');
  32018. assert.equal(a.subtract('1', 'Q').month(), 5, 'Subtract quarter');
  32019. });
  32020. test('add across DST', function (assert) {
  32021. // Detect Safari bug and bail. Hours on 13th March 2011 are shifted
  32022. // with 1 ahead.
  32023. if (new Date(2011, 2, 13, 5, 0, 0).getHours() !== 5) {
  32024. expect(0);
  32025. return;
  32026. }
  32027. var a = moment(new Date(2011, 2, 12, 5, 0, 0)),
  32028. b = moment(new Date(2011, 2, 12, 5, 0, 0)),
  32029. c = moment(new Date(2011, 2, 12, 5, 0, 0)),
  32030. d = moment(new Date(2011, 2, 12, 5, 0, 0)),
  32031. e = moment(new Date(2011, 2, 12, 5, 0, 0));
  32032. a.add(1, 'days');
  32033. b.add(24, 'hours');
  32034. c.add(1, 'months');
  32035. e.add(1, 'quarter');
  32036. assert.equal(a.hours(), 5, 'adding days over DST difference should result in the same hour');
  32037. if (b.isDST() && !d.isDST()) {
  32038. assert.equal(b.hours(), 6, 'adding hours over DST difference should result in a different hour');
  32039. } else if (!b.isDST() && d.isDST()) {
  32040. assert.equal(b.hours(), 4, 'adding hours over DST difference should result in a different hour');
  32041. } else {
  32042. assert.equal(b.hours(), 5, 'adding hours over DST difference should result in a same hour if the timezone does not have daylight savings time');
  32043. }
  32044. assert.equal(c.hours(), 5, 'adding months over DST difference should result in the same hour');
  32045. assert.equal(e.hours(), 5, 'adding quarters over DST difference should result in the same hour');
  32046. });
  32047. }));
  32048. ;(function (global, factory) {
  32049. typeof exports === 'object' && typeof module !== 'undefined'
  32050. && typeof require === 'function' ? factory(require('../../moment')) :
  32051. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  32052. factory(global.moment)
  32053. }(this, function (moment) { 'use strict';
  32054. /*global QUnit:false*/
  32055. var test = QUnit.test;
  32056. var expect = QUnit.expect;
  32057. function module (name, lifecycle) {
  32058. QUnit.module(name, {
  32059. setup : function () {
  32060. moment.locale('en');
  32061. moment.createFromInputFallback = function (config) {
  32062. throw new Error('input not handled by moment: ' + config._i);
  32063. };
  32064. if (lifecycle && lifecycle.setup) {
  32065. lifecycle.setup();
  32066. }
  32067. },
  32068. teardown : function () {
  32069. if (lifecycle && lifecycle.teardown) {
  32070. lifecycle.teardown();
  32071. }
  32072. }
  32073. });
  32074. }
  32075. function localeModule (name, lifecycle) {
  32076. QUnit.module('locale:' + name, {
  32077. setup : function () {
  32078. moment.locale(name);
  32079. moment.createFromInputFallback = function (config) {
  32080. throw new Error('input not handled by moment: ' + config._i);
  32081. };
  32082. if (lifecycle && lifecycle.setup) {
  32083. lifecycle.setup();
  32084. }
  32085. },
  32086. teardown : function () {
  32087. moment.locale('en');
  32088. if (lifecycle && lifecycle.teardown) {
  32089. lifecycle.teardown();
  32090. }
  32091. }
  32092. });
  32093. }
  32094. // These tests are for locale independent features
  32095. // locale dependent tests would be in locale test folder
  32096. module('calendar');
  32097. test('passing a function', function (assert) {
  32098. var a = moment().hours(2).minutes(0).seconds(0);
  32099. assert.equal(moment(a).calendar(null, {
  32100. 'sameDay': function () {
  32101. return 'h:mmA';
  32102. }
  32103. }), '2:00AM', 'should equate');
  32104. });
  32105. }));
  32106. ;(function (global, factory) {
  32107. typeof exports === 'object' && typeof module !== 'undefined'
  32108. && typeof require === 'function' ? factory(require('../../moment')) :
  32109. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  32110. factory(global.moment)
  32111. }(this, function (moment) { 'use strict';
  32112. /*global QUnit:false*/
  32113. var test = QUnit.test;
  32114. var expect = QUnit.expect;
  32115. function module (name, lifecycle) {
  32116. QUnit.module(name, {
  32117. setup : function () {
  32118. moment.locale('en');
  32119. moment.createFromInputFallback = function (config) {
  32120. throw new Error('input not handled by moment: ' + config._i);
  32121. };
  32122. if (lifecycle && lifecycle.setup) {
  32123. lifecycle.setup();
  32124. }
  32125. },
  32126. teardown : function () {
  32127. if (lifecycle && lifecycle.teardown) {
  32128. lifecycle.teardown();
  32129. }
  32130. }
  32131. });
  32132. }
  32133. function localeModule (name, lifecycle) {
  32134. QUnit.module('locale:' + name, {
  32135. setup : function () {
  32136. moment.locale(name);
  32137. moment.createFromInputFallback = function (config) {
  32138. throw new Error('input not handled by moment: ' + config._i);
  32139. };
  32140. if (lifecycle && lifecycle.setup) {
  32141. lifecycle.setup();
  32142. }
  32143. },
  32144. teardown : function () {
  32145. moment.locale('en');
  32146. if (lifecycle && lifecycle.teardown) {
  32147. lifecycle.teardown();
  32148. }
  32149. }
  32150. });
  32151. }
  32152. module('create');
  32153. test('array', function (assert) {
  32154. assert.ok(moment([2010]).toDate() instanceof Date, '[2010]');
  32155. assert.ok(moment([2010, 1]).toDate() instanceof Date, '[2010, 1]');
  32156. assert.ok(moment([2010, 1, 12]).toDate() instanceof Date, '[2010, 1, 12]');
  32157. assert.ok(moment([2010, 1, 12, 1]).toDate() instanceof Date, '[2010, 1, 12, 1]');
  32158. assert.ok(moment([2010, 1, 12, 1, 1]).toDate() instanceof Date, '[2010, 1, 12, 1, 1]');
  32159. assert.ok(moment([2010, 1, 12, 1, 1, 1]).toDate() instanceof Date, '[2010, 1, 12, 1, 1, 1]');
  32160. assert.ok(moment([2010, 1, 12, 1, 1, 1, 1]).toDate() instanceof Date, '[2010, 1, 12, 1, 1, 1, 1]');
  32161. assert.equal(+moment(new Date(2010, 1, 14, 15, 25, 50, 125)), +moment([2010, 1, 14, 15, 25, 50, 125]), 'constructing with array === constructing with new Date()');
  32162. });
  32163. test('array with invalid arguments', function (assert) {
  32164. assert.ok(!moment([2010, null, null]).isValid(), '[2010, null, null]');
  32165. assert.ok(!moment([1945, null, null]).isValid(), '[1945, null, null] (pre-1970)');
  32166. });
  32167. test('array copying', function (assert) {
  32168. var importantArray = [2009, 11];
  32169. moment(importantArray);
  32170. assert.deepEqual(importantArray, [2009, 11], 'initializer should not mutate the original array');
  32171. });
  32172. test('object', function (assert) {
  32173. var fmt = 'YYYY-MM-DD HH:mm:ss.SSS',
  32174. tests = [
  32175. [{year: 2010}, '2010-01-01 00:00:00.000'],
  32176. [{year: 2010, month: 1}, '2010-02-01 00:00:00.000'],
  32177. [{year: 2010, month: 1, day: 12}, '2010-02-12 00:00:00.000'],
  32178. [{year: 2010, month: 1, date: 12}, '2010-02-12 00:00:00.000'],
  32179. [{year: 2010, month: 1, day: 12, hours: 1}, '2010-02-12 01:00:00.000'],
  32180. [{year: 2010, month: 1, date: 12, hours: 1}, '2010-02-12 01:00:00.000'],
  32181. [{year: 2010, month: 1, day: 12, hours: 1, minutes: 1}, '2010-02-12 01:01:00.000'],
  32182. [{year: 2010, month: 1, date: 12, hours: 1, minutes: 1}, '2010-02-12 01:01:00.000'],
  32183. [{year: 2010, month: 1, day: 12, hours: 1, minutes: 1, seconds: 1}, '2010-02-12 01:01:01.000'],
  32184. [{year: 2010, month: 1, day: 12, hours: 1, minutes: 1, seconds: 1, milliseconds: 1}, '2010-02-12 01:01:01.001'],
  32185. [{years: 2010, months: 1, days: 14, hours: 15, minutes: 25, seconds: 50, milliseconds: 125}, '2010-02-14 15:25:50.125'],
  32186. [{year: 2010, month: 1, day: 14, hour: 15, minute: 25, second: 50, millisecond: 125}, '2010-02-14 15:25:50.125'],
  32187. [{y: 2010, M: 1, d: 14, h: 15, m: 25, s: 50, ms: 125}, '2010-02-14 15:25:50.125']
  32188. ], i;
  32189. for (i = 0; i < tests.length; ++i) {
  32190. assert.equal(moment(tests[i][0]).format(fmt), tests[i][1]);
  32191. }
  32192. });
  32193. test('multi format array copying', function (assert) {
  32194. var importantArray = ['MM/DD/YYYY', 'YYYY-MM-DD', 'MM-DD-YYYY'];
  32195. moment('1999-02-13', importantArray);
  32196. assert.deepEqual(importantArray, ['MM/DD/YYYY', 'YYYY-MM-DD', 'MM-DD-YYYY'], 'initializer should not mutate the original array');
  32197. });
  32198. test('number', function (assert) {
  32199. assert.ok(moment(1000).toDate() instanceof Date, '1000');
  32200. assert.equal(moment(1000).valueOf(), 1000, 'asserting valueOf');
  32201. assert.equal(moment.utc(1000).valueOf(), 1000, 'asserting valueOf');
  32202. });
  32203. test('unix', function (assert) {
  32204. assert.equal(moment.unix(1).valueOf(), 1000, '1 unix timestamp == 1000 Date.valueOf');
  32205. assert.equal(moment(1000).unix(), 1, '1000 Date.valueOf == 1 unix timestamp');
  32206. assert.equal(moment.unix(1000).valueOf(), 1000000, '1000 unix timestamp == 1000000 Date.valueOf');
  32207. assert.equal(moment(1500).unix(), 1, '1500 Date.valueOf == 1 unix timestamp');
  32208. assert.equal(moment(1900).unix(), 1, '1900 Date.valueOf == 1 unix timestamp');
  32209. assert.equal(moment(2100).unix(), 2, '2100 Date.valueOf == 2 unix timestamp');
  32210. assert.equal(moment(1333129333524).unix(), 1333129333, '1333129333524 Date.valueOf == 1333129333 unix timestamp');
  32211. assert.equal(moment(1333129333524000).unix(), 1333129333524, '1333129333524000 Date.valueOf == 1333129333524 unix timestamp');
  32212. });
  32213. test('date', function (assert) {
  32214. assert.ok(moment(new Date()).toDate() instanceof Date, 'new Date()');
  32215. });
  32216. test('date mutation', function (assert) {
  32217. var a = new Date();
  32218. assert.ok(moment(a).toDate() !== a, 'the date moment uses should not be the date passed in');
  32219. });
  32220. test('moment', function (assert) {
  32221. assert.ok(moment(moment()).toDate() instanceof Date, 'moment(moment())');
  32222. assert.ok(moment(moment(moment())).toDate() instanceof Date, 'moment(moment(moment()))');
  32223. });
  32224. test('cloning moment should only copy own properties', function (assert) {
  32225. assert.ok(!moment().clone().hasOwnProperty('month'), 'Should not clone prototype methods');
  32226. });
  32227. test('cloning moment works with weird clones', function (assert) {
  32228. var extend = function (a, b) {
  32229. var i;
  32230. for (i in b) {
  32231. a[i] = b[i];
  32232. }
  32233. return a;
  32234. },
  32235. now = moment(),
  32236. nowu = moment.utc();
  32237. assert.equal(+extend({}, now).clone(), +now, 'cloning extend-ed now is now');
  32238. assert.equal(+extend({}, nowu).clone(), +nowu, 'cloning extend-ed utc now is utc now');
  32239. });
  32240. test('cloning respects moment.momentProperties', function (assert) {
  32241. var m = moment();
  32242. assert.equal(m.clone()._special, undefined, 'cloning ignores extra properties');
  32243. m._special = 'bacon';
  32244. moment.momentProperties.push('_special');
  32245. assert.equal(m.clone()._special, 'bacon', 'cloning respects momentProperties');
  32246. moment.momentProperties.pop();
  32247. });
  32248. test('undefined', function (assert) {
  32249. assert.ok(moment().toDate() instanceof Date, 'undefined');
  32250. });
  32251. test('iso with bad input', function (assert) {
  32252. assert.ok(!moment('a', moment.ISO_8601).isValid(), 'iso parsing with invalid string');
  32253. assert.ok(!moment('a', moment.ISO_8601, true).isValid(), 'iso parsing with invalid string, strict');
  32254. });
  32255. test('iso format 24hrs', function (assert) {
  32256. assert.equal(moment('2014-01-01T24:00:00.000').format('YYYY-MM-DD[T]HH:mm:ss.SSS'),
  32257. '2014-01-02T00:00:00.000', 'iso format with 24:00 localtime');
  32258. assert.equal(moment.utc('2014-01-01T24:00:00.000').format('YYYY-MM-DD[T]HH:mm:ss.SSS'),
  32259. '2014-01-02T00:00:00.000', 'iso format with 24:00 utc');
  32260. });
  32261. test('string without format - json', function (assert) {
  32262. assert.equal(moment('Date(1325132654000)').valueOf(), 1325132654000, 'Date(1325132654000)');
  32263. assert.equal(moment('Date(-1325132654000)').valueOf(), -1325132654000, 'Date(-1325132654000)');
  32264. assert.equal(moment('/Date(1325132654000)/').valueOf(), 1325132654000, '/Date(1325132654000)/');
  32265. assert.equal(moment('/Date(1325132654000+0700)/').valueOf(), 1325132654000, '/Date(1325132654000+0700)/');
  32266. assert.equal(moment('/Date(1325132654000-0700)/').valueOf(), 1325132654000, '/Date(1325132654000-0700)/');
  32267. });
  32268. test('string with format dropped am/pm bug', function (assert) {
  32269. moment.locale('en');
  32270. assert.equal(moment('05/1/2012 12:25:00', 'MM/DD/YYYY h:m:s a').format('MM/DD/YYYY'), '05/01/2012', 'should not break if am/pm is left off from the parsing tokens');
  32271. assert.equal(moment('05/1/2012 12:25:00 am', 'MM/DD/YYYY h:m:s a').format('MM/DD/YYYY'), '05/01/2012', 'should not break if am/pm is left off from the parsing tokens');
  32272. assert.equal(moment('05/1/2012 12:25:00 pm', 'MM/DD/YYYY h:m:s a').format('MM/DD/YYYY'), '05/01/2012', 'should not break if am/pm is left off from the parsing tokens');
  32273. assert.ok(moment('05/1/2012 12:25:00', 'MM/DD/YYYY h:m:s a').isValid());
  32274. assert.ok(moment('05/1/2012 12:25:00 am', 'MM/DD/YYYY h:m:s a').isValid());
  32275. assert.ok(moment('05/1/2012 12:25:00 pm', 'MM/DD/YYYY h:m:s a').isValid());
  32276. });
  32277. test('empty string with formats', function (assert) {
  32278. assert.equal(moment('', 'MM').format('YYYY-MM-DD HH:mm:ss'), 'Invalid date');
  32279. assert.equal(moment(' ', 'MM').format('YYYY-MM-DD HH:mm:ss'), 'Invalid date');
  32280. assert.equal(moment(' ', 'DD').format('YYYY-MM-DD HH:mm:ss'), 'Invalid date');
  32281. assert.equal(moment(' ', ['MM', 'DD']).format('YYYY-MM-DD HH:mm:ss'), 'Invalid date');
  32282. assert.ok(!moment('', 'MM').isValid());
  32283. assert.ok(!moment(' ', 'MM').isValid());
  32284. assert.ok(!moment(' ', 'DD').isValid());
  32285. assert.ok(!moment(' ', ['MM', 'DD']).isValid());
  32286. });
  32287. test('defaulting to current date', function (assert) {
  32288. var now = moment();
  32289. assert.equal(moment('12:13:14', 'hh:mm:ss').format('YYYY-MM-DD hh:mm:ss'),
  32290. now.clone().hour(12).minute(13).second(14).format('YYYY-MM-DD hh:mm:ss'),
  32291. 'given only time default to current date');
  32292. assert.equal(moment('05', 'DD').format('YYYY-MM-DD'),
  32293. now.clone().date(5).format('YYYY-MM-DD'),
  32294. 'given day of month default to current month, year');
  32295. assert.equal(moment('05', 'MM').format('YYYY-MM-DD'),
  32296. now.clone().month(4).date(1).format('YYYY-MM-DD'),
  32297. 'given month default to current year');
  32298. assert.equal(moment('1996', 'YYYY').format('YYYY-MM-DD'),
  32299. now.clone().year(1996).month(0).date(1).format('YYYY-MM-DD'),
  32300. 'given year do not default');
  32301. });
  32302. test('matching am/pm', function (assert) {
  32303. assert.equal(moment('2012-09-03T03:00PM', 'YYYY-MM-DDThh:mmA').format('YYYY-MM-DDThh:mmA'), '2012-09-03T03:00PM', 'am/pm should parse correctly for PM');
  32304. assert.equal(moment('2012-09-03T03:00P.M.', 'YYYY-MM-DDThh:mmA').format('YYYY-MM-DDThh:mmA'), '2012-09-03T03:00PM', 'am/pm should parse correctly for P.M.');
  32305. assert.equal(moment('2012-09-03T03:00P', 'YYYY-MM-DDThh:mmA').format('YYYY-MM-DDThh:mmA'), '2012-09-03T03:00PM', 'am/pm should parse correctly for P');
  32306. assert.equal(moment('2012-09-03T03:00pm', 'YYYY-MM-DDThh:mmA').format('YYYY-MM-DDThh:mmA'), '2012-09-03T03:00PM', 'am/pm should parse correctly for pm');
  32307. assert.equal(moment('2012-09-03T03:00p.m.', 'YYYY-MM-DDThh:mmA').format('YYYY-MM-DDThh:mmA'), '2012-09-03T03:00PM', 'am/pm should parse correctly for p.m.');
  32308. assert.equal(moment('2012-09-03T03:00p', 'YYYY-MM-DDThh:mmA').format('YYYY-MM-DDThh:mmA'), '2012-09-03T03:00PM', 'am/pm should parse correctly for p');
  32309. assert.equal(moment('2012-09-03T03:00AM', 'YYYY-MM-DDThh:mmA').format('YYYY-MM-DDThh:mmA'), '2012-09-03T03:00AM', 'am/pm should parse correctly for AM');
  32310. assert.equal(moment('2012-09-03T03:00A.M.', 'YYYY-MM-DDThh:mmA').format('YYYY-MM-DDThh:mmA'), '2012-09-03T03:00AM', 'am/pm should parse correctly for A.M.');
  32311. assert.equal(moment('2012-09-03T03:00A', 'YYYY-MM-DDThh:mmA').format('YYYY-MM-DDThh:mmA'), '2012-09-03T03:00AM', 'am/pm should parse correctly for A');
  32312. assert.equal(moment('2012-09-03T03:00am', 'YYYY-MM-DDThh:mmA').format('YYYY-MM-DDThh:mmA'), '2012-09-03T03:00AM', 'am/pm should parse correctly for am');
  32313. assert.equal(moment('2012-09-03T03:00a.m.', 'YYYY-MM-DDThh:mmA').format('YYYY-MM-DDThh:mmA'), '2012-09-03T03:00AM', 'am/pm should parse correctly for a.m.');
  32314. assert.equal(moment('2012-09-03T03:00a', 'YYYY-MM-DDThh:mmA').format('YYYY-MM-DDThh:mmA'), '2012-09-03T03:00AM', 'am/pm should parse correctly for a');
  32315. assert.equal(moment('5:00p.m.March 4 2012', 'h:mmAMMMM D YYYY').format('YYYY-MM-DDThh:mmA'), '2012-03-04T05:00PM', 'am/pm should parse correctly before month names');
  32316. });
  32317. test('string with format', function (assert) {
  32318. moment.locale('en');
  32319. var a = [
  32320. ['YYYY-Q', '2014-4'],
  32321. ['MM-DD-YYYY', '12-02-1999'],
  32322. ['DD-MM-YYYY', '12-02-1999'],
  32323. ['DD/MM/YYYY', '12/02/1999'],
  32324. ['DD_MM_YYYY', '12_02_1999'],
  32325. ['DD:MM:YYYY', '12:02:1999'],
  32326. ['D-M-YY', '2-2-99'],
  32327. ['YY', '99'],
  32328. ['DDD-YYYY', '300-1999'],
  32329. ['DD-MM-YYYY h:m:s', '12-02-1999 2:45:10'],
  32330. ['DD-MM-YYYY h:m:s a', '12-02-1999 2:45:10 am'],
  32331. ['DD-MM-YYYY h:m:s a', '12-02-1999 2:45:10 pm'],
  32332. ['h:mm a', '12:00 pm'],
  32333. ['h:mm a', '12:30 pm'],
  32334. ['h:mm a', '12:00 am'],
  32335. ['h:mm a', '12:30 am'],
  32336. ['HH:mm', '12:00'],
  32337. ['YYYY-MM-DDTHH:mm:ss', '2011-11-11T11:11:11'],
  32338. ['MM-DD-YYYY [M]', '12-02-1999 M'],
  32339. ['ddd MMM DD HH:mm:ss YYYY', 'Tue Apr 07 22:52:51 2009'],
  32340. ['HH:mm:ss', '12:00:00'],
  32341. ['HH:mm:ss', '12:30:00'],
  32342. ['HH:mm:ss', '00:00:00'],
  32343. ['HH:mm:ss S', '00:30:00 1'],
  32344. ['HH:mm:ss SS', '00:30:00 12'],
  32345. ['HH:mm:ss SSS', '00:30:00 123'],
  32346. ['HH:mm:ss S', '00:30:00 7'],
  32347. ['HH:mm:ss SS', '00:30:00 78'],
  32348. ['HH:mm:ss SSS', '00:30:00 789'],
  32349. ['X', '1234567890'],
  32350. ['x', '1234567890123'],
  32351. ['LT', '12:30 AM'],
  32352. ['LTS', '12:30:29 AM'],
  32353. ['L', '09/02/1999'],
  32354. ['l', '9/2/1999'],
  32355. ['LL', 'September 2, 1999'],
  32356. ['ll', 'Sep 2, 1999'],
  32357. ['LLL', 'September 2, 1999 12:30 AM'],
  32358. ['lll', 'Sep 2, 1999 12:30 AM'],
  32359. ['LLLL', 'Thursday, September 2, 1999 12:30 AM'],
  32360. ['llll', 'Thu, Sep 2, 1999 12:30 AM']
  32361. ],
  32362. m,
  32363. i;
  32364. for (i = 0; i < a.length; i++) {
  32365. m = moment(a[i][1], a[i][0]);
  32366. assert.ok(m.isValid());
  32367. assert.equal(m.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  32368. }
  32369. });
  32370. test('2 digit year with YYYY format', function (assert) {
  32371. assert.equal(moment('9/2/99', 'D/M/YYYY').format('DD/MM/YYYY'), '09/02/1999', 'D/M/YYYY ---> 9/2/99');
  32372. assert.equal(moment('9/2/1999', 'D/M/YYYY').format('DD/MM/YYYY'), '09/02/1999', 'D/M/YYYY ---> 9/2/1999');
  32373. assert.equal(moment('9/2/68', 'D/M/YYYY').format('DD/MM/YYYY'), '09/02/2068', 'D/M/YYYY ---> 9/2/68');
  32374. assert.equal(moment('9/2/69', 'D/M/YYYY').format('DD/MM/YYYY'), '09/02/1969', 'D/M/YYYY ---> 9/2/69');
  32375. });
  32376. test('unix timestamp format', function (assert) {
  32377. var formats = ['X', 'X.S', 'X.SS', 'X.SSS'], i, format;
  32378. for (i = 0; i < formats.length; i++) {
  32379. format = formats[i];
  32380. assert.equal(moment('1234567890', format).valueOf(), 1234567890 * 1000, format + ' matches timestamp without milliseconds');
  32381. assert.equal(moment('1234567890.1', format).valueOf(), 1234567890 * 1000 + 100, format + ' matches timestamp with deciseconds');
  32382. assert.equal(moment('1234567890.12', format).valueOf(), 1234567890 * 1000 + 120, format + ' matches timestamp with centiseconds');
  32383. assert.equal(moment('1234567890.123', format).valueOf(), 1234567890 * 1000 + 123, format + ' matches timestamp with milliseconds');
  32384. }
  32385. });
  32386. test('unix offset milliseconds', function (assert) {
  32387. assert.equal(moment('1234567890123', 'x').valueOf(), 1234567890123, 'x matches unix offset in milliseconds');
  32388. });
  32389. test('milliseconds format', function (assert) {
  32390. assert.equal(moment('1', 'S').get('ms'), 100, 'deciseconds');
  32391. // assert.equal(moment('10', 'S', true).isValid(), false, 'deciseconds with two digits');
  32392. // assert.equal(moment('1', 'SS', true).isValid(), false, 'centiseconds with one digits');
  32393. assert.equal(moment('12', 'SS').get('ms'), 120, 'centiseconds');
  32394. // assert.equal(moment('123', 'SS', true).isValid(), false, 'centiseconds with three digits');
  32395. assert.equal(moment('123', 'SSS').get('ms'), 123, 'milliseconds');
  32396. assert.equal(moment('1234', 'SSSS').get('ms'), 123, 'milliseconds with SSSS');
  32397. assert.equal(moment('123456789101112', 'SSSS').get('ms'), 123, 'milliseconds with SSSS');
  32398. });
  32399. test('string with format no separators', function (assert) {
  32400. moment.locale('en');
  32401. var a = [
  32402. ['MMDDYYYY', '12021999'],
  32403. ['DDMMYYYY', '12021999'],
  32404. ['YYYYMMDD', '19991202'],
  32405. ['DDMMMYYYY', '10Sep2001']
  32406. ], i;
  32407. for (i = 0; i < a.length; i++) {
  32408. assert.equal(moment(a[i][1], a[i][0]).format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
  32409. }
  32410. });
  32411. test('string with format (timezone)', function (assert) {
  32412. assert.equal(moment('5 -0700', 'H ZZ').toDate().getUTCHours(), 12, 'parse hours \'5 -0700\' ---> \'H ZZ\'');
  32413. assert.equal(moment('5 -07:00', 'H Z').toDate().getUTCHours(), 12, 'parse hours \'5 -07:00\' ---> \'H Z\'');
  32414. assert.equal(moment('5 -0730', 'H ZZ').toDate().getUTCMinutes(), 30, 'parse hours \'5 -0730\' ---> \'H ZZ\'');
  32415. assert.equal(moment('5 -07:30', 'H Z').toDate().getUTCMinutes(), 30, 'parse hours \'5 -07:0\' ---> \'H Z\'');
  32416. assert.equal(moment('5 +0100', 'H ZZ').toDate().getUTCHours(), 4, 'parse hours \'5 +0100\' ---> \'H ZZ\'');
  32417. assert.equal(moment('5 +01:00', 'H Z').toDate().getUTCHours(), 4, 'parse hours \'5 +01:00\' ---> \'H Z\'');
  32418. assert.equal(moment('5 +0130', 'H ZZ').toDate().getUTCMinutes(), 30, 'parse hours \'5 +0130\' ---> \'H ZZ\'');
  32419. assert.equal(moment('5 +01:30', 'H Z').toDate().getUTCMinutes(), 30, 'parse hours \'5 +01:30\' ---> \'H Z\'');
  32420. });
  32421. test('string with format (timezone offset)', function (assert) {
  32422. var a, b, c, d, e, f;
  32423. a = new Date(Date.UTC(2011, 0, 1, 1));
  32424. b = moment('2011 1 1 0 -01:00', 'YYYY MM DD HH Z');
  32425. assert.equal(a.getHours(), b.hours(), 'date created with utc == parsed string with timezone offset');
  32426. assert.equal(+a, +b, 'date created with utc == parsed string with timezone offset');
  32427. c = moment('2011 2 1 10 -05:00', 'YYYY MM DD HH Z');
  32428. d = moment('2011 2 1 8 -07:00', 'YYYY MM DD HH Z');
  32429. assert.equal(c.hours(), d.hours(), '10 am central time == 8 am pacific time');
  32430. e = moment.utc('Fri, 20 Jul 2012 17:15:00', 'ddd, DD MMM YYYY HH:mm:ss');
  32431. f = moment.utc('Fri, 20 Jul 2012 10:15:00 -0700', 'ddd, DD MMM YYYY HH:mm:ss ZZ');
  32432. assert.equal(e.hours(), f.hours(), 'parse timezone offset in utc');
  32433. });
  32434. test('string with timezone around start of year', function (assert) {
  32435. assert.equal(moment('2000-01-01T00:00:00.000+01:00').toISOString(), '1999-12-31T23:00:00.000Z', '+1:00 around 2000');
  32436. assert.equal(moment('2000-01-01T00:00:00.000-01:00').toISOString(), '2000-01-01T01:00:00.000Z', '-1:00 around 2000');
  32437. assert.equal(moment('1970-01-01T00:00:00.000+01:00').toISOString(), '1969-12-31T23:00:00.000Z', '+1:00 around 1970');
  32438. assert.equal(moment('1970-01-01T00:00:00.000-01:00').toISOString(), '1970-01-01T01:00:00.000Z', '-1:00 around 1970');
  32439. assert.equal(moment('1200-01-01T00:00:00.000+01:00').toISOString(), '1199-12-31T23:00:00.000Z', '+1:00 around 1200');
  32440. assert.equal(moment('1200-01-01T00:00:00.000-01:00').toISOString(), '1200-01-01T01:00:00.000Z', '-1:00 around 1200');
  32441. });
  32442. test('string with array of formats', function (assert) {
  32443. assert.equal(moment('11-02-1999', ['MM-DD-YYYY', 'DD-MM-YYYY']).format('MM DD YYYY'), '11 02 1999', 'switching month and day');
  32444. assert.equal(moment('02-11-1999', ['MM/DD/YYYY', 'YYYY MM DD', 'MM-DD-YYYY']).format('MM DD YYYY'), '02 11 1999', 'year last');
  32445. assert.equal(moment('1999-02-11', ['MM/DD/YYYY', 'YYYY MM DD', 'MM-DD-YYYY']).format('MM DD YYYY'), '02 11 1999', 'year first');
  32446. assert.equal(moment('02-11-1999', ['MM/DD/YYYY', 'YYYY MM DD']).format('MM DD YYYY'), '02 11 1999', 'year last');
  32447. assert.equal(moment('1999-02-11', ['MM/DD/YYYY', 'YYYY MM DD']).format('MM DD YYYY'), '02 11 1999', 'year first');
  32448. assert.equal(moment('02-11-1999', ['YYYY MM DD', 'MM/DD/YYYY']).format('MM DD YYYY'), '02 11 1999', 'year last');
  32449. assert.equal(moment('1999-02-11', ['YYYY MM DD', 'MM/DD/YYYY']).format('MM DD YYYY'), '02 11 1999', 'year first');
  32450. assert.equal(moment('13-11-1999', ['MM/DD/YYYY', 'DD/MM/YYYY']).format('MM DD YYYY'), '11 13 1999', 'second must be month');
  32451. assert.equal(moment('11-13-1999', ['MM/DD/YYYY', 'DD/MM/YYYY']).format('MM DD YYYY'), '11 13 1999', 'first must be month');
  32452. assert.equal(moment('01-02-2000', ['MM/DD/YYYY', 'DD/MM/YYYY']).format('MM DD YYYY'), '01 02 2000', 'either can be a month, month first format');
  32453. assert.equal(moment('02-01-2000', ['DD/MM/YYYY', 'MM/DD/YYYY']).format('MM DD YYYY'), '01 02 2000', 'either can be a month, day first format');
  32454. assert.equal(moment('11-02-10', ['MM/DD/YY', 'YY MM DD', 'DD-MM-YY']).format('MM DD YYYY'), '02 11 2010', 'all unparsed substrings have influence on format penalty');
  32455. assert.equal(moment('11-02-10', ['MM-DD-YY HH:mm', 'YY MM DD']).format('MM DD YYYY'), '02 10 2011', 'prefer formats without extra tokens');
  32456. assert.equal(moment('11-02-10 junk', ['MM-DD-YY', 'YY.MM.DD junk']).format('MM DD YYYY'), '02 10 2011', 'prefer formats that dont result in extra characters');
  32457. assert.equal(moment('11-22-10', ['YY-MM-DD', 'YY-DD-MM']).format('MM DD YYYY'), '10 22 2011', 'prefer valid results');
  32458. assert.equal(moment('gibberish', ['YY-MM-DD', 'YY-DD-MM']).format('MM DD YYYY'), 'Invalid date', 'doest throw for invalid strings');
  32459. assert.equal(moment('gibberish', []).format('MM DD YYYY'), 'Invalid date', 'doest throw for an empty array');
  32460. //https://github.com/moment/moment/issues/1143
  32461. assert.equal(moment(
  32462. 'System Administrator and Database Assistant (7/1/2011), System Administrator and Database Assistant (7/1/2011), Database Coordinator (7/1/2011), Vice President (7/1/2011), System Administrator and Database Assistant (5/31/2012), Database Coordinator (7/1/2012), System Administrator and Database Assistant (7/1/2013)',
  32463. ['MM/DD/YYYY', 'MM-DD-YYYY', 'YYYY-MM-DD', 'YYYY-MM-DDTHH:mm:ssZ'])
  32464. .format('YYYY-MM-DD'), '2011-07-01', 'Works for long strings');
  32465. assert.equal(moment('11-02-10', ['MM.DD.YY', 'DD-MM-YY']).format('MM DD YYYY'), '02 11 2010', 'escape RegExp special characters on comparing');
  32466. assert.equal(moment('13-10-98', ['DD MM YY', 'DD MM YYYY'])._f, 'DD MM YY', 'use two digit year');
  32467. assert.equal(moment('13-10-1998', ['DD MM YY', 'DD MM YYYY'])._f, 'DD MM YYYY', 'use four digit year');
  32468. assert.equal(moment('01', ['MM', 'DD'])._f, 'MM', 'Should use first valid format');
  32469. });
  32470. test('string with array of formats + ISO', function (assert) {
  32471. assert.equal(moment('1994', [moment.ISO_8601, 'MM', 'HH:mm', 'YYYY']).year(), 1994, 'iso: assert parse YYYY');
  32472. assert.equal(moment('17:15', [moment.ISO_8601, 'MM', 'HH:mm', 'YYYY']).hour(), 17, 'iso: assert parse HH:mm (1)');
  32473. assert.equal(moment('17:15', [moment.ISO_8601, 'MM', 'HH:mm', 'YYYY']).minutes(), 15, 'iso: assert parse HH:mm (2)');
  32474. assert.equal(moment('06', [moment.ISO_8601, 'MM', 'HH:mm', 'YYYY']).month(), 6 - 1, 'iso: assert parse MM');
  32475. assert.equal(moment('2012-06-01', [moment.ISO_8601, 'MM', 'HH:mm', 'YYYY']).parsingFlags().iso, true, 'iso: assert parse iso');
  32476. assert.equal(moment('2014-05-05', [moment.ISO_8601, 'YYYY-MM-DD']).parsingFlags().iso, true, 'iso: edge case array precedence iso');
  32477. assert.equal(moment('2014-05-05', ['YYYY-MM-DD', moment.ISO_8601]).parsingFlags().iso, false, 'iso: edge case array precedence not iso');
  32478. });
  32479. test('string with format - years', function (assert) {
  32480. assert.equal(moment('67', 'YY').format('YYYY'), '2067', '67 > 2067');
  32481. assert.equal(moment('68', 'YY').format('YYYY'), '2068', '68 > 2068');
  32482. assert.equal(moment('69', 'YY').format('YYYY'), '1969', '69 > 1969');
  32483. assert.equal(moment('70', 'YY').format('YYYY'), '1970', '70 > 1970');
  32484. });
  32485. test('implicit cloning', function (assert) {
  32486. var momentA = moment([2011, 10, 10]),
  32487. momentB = moment(momentA);
  32488. momentA.month(5);
  32489. assert.equal(momentB.month(), 10, 'Calling moment() on a moment will create a clone');
  32490. assert.equal(momentA.month(), 5, 'Calling moment() on a moment will create a clone');
  32491. });
  32492. test('explicit cloning', function (assert) {
  32493. var momentA = moment([2011, 10, 10]),
  32494. momentB = momentA.clone();
  32495. momentA.month(5);
  32496. assert.equal(momentB.month(), 10, 'Calling moment() on a moment will create a clone');
  32497. assert.equal(momentA.month(), 5, 'Calling moment() on a moment will create a clone');
  32498. });
  32499. test('cloning carrying over utc mode', function (assert) {
  32500. assert.equal(moment().local().clone()._isUTC, false, 'An explicit cloned local moment should have _isUTC == false');
  32501. assert.equal(moment().utc().clone()._isUTC, true, 'An cloned utc moment should have _isUTC == true');
  32502. assert.equal(moment().clone()._isUTC, false, 'An explicit cloned local moment should have _isUTC == false');
  32503. assert.equal(moment.utc().clone()._isUTC, true, 'An explicit cloned utc moment should have _isUTC == true');
  32504. assert.equal(moment(moment().local())._isUTC, false, 'An implicit cloned local moment should have _isUTC == false');
  32505. assert.equal(moment(moment().utc())._isUTC, true, 'An implicit cloned utc moment should have _isUTC == true');
  32506. assert.equal(moment(moment())._isUTC, false, 'An implicit cloned local moment should have _isUTC == false');
  32507. assert.equal(moment(moment.utc())._isUTC, true, 'An implicit cloned utc moment should have _isUTC == true');
  32508. });
  32509. test('parsing iso', function (assert) {
  32510. var offset = moment([2011, 9, 8]).utcOffset(),
  32511. pad = function (input) {
  32512. if (input < 10) {
  32513. return '0' + input;
  32514. }
  32515. return '' + input;
  32516. },
  32517. hourOffset = (offset > 0 ? Math.floor(offset / 60) : Math.ceil(offset / 60)),
  32518. minOffset = offset - (hourOffset * 60),
  32519. tz = (offset >= 0) ?
  32520. '+' + pad(hourOffset) + ':' + pad(minOffset) :
  32521. '-' + pad(-hourOffset) + ':' + pad(-minOffset),
  32522. tz2 = tz.replace(':', ''),
  32523. tz3 = tz2.slice(0, 3),
  32524. //Tz3 removes minutes digit so will break the tests when parsed if they all use the same minutes digit
  32525. minutesForTz3 = pad((4 + minOffset) % 60),
  32526. minute = pad(4 + minOffset),
  32527. formats = [
  32528. ['2011-10-08', '2011-10-08T00:00:00.000' + tz],
  32529. ['2011-10-08T18', '2011-10-08T18:00:00.000' + tz],
  32530. ['2011-10-08T18:04', '2011-10-08T18:04:00.000' + tz],
  32531. ['2011-10-08T18:04:20', '2011-10-08T18:04:20.000' + tz],
  32532. ['2011-10-08T18:04' + tz, '2011-10-08T18:04:00.000' + tz],
  32533. ['2011-10-08T18:04:20' + tz, '2011-10-08T18:04:20.000' + tz],
  32534. ['2011-10-08T18:04' + tz2, '2011-10-08T18:04:00.000' + tz],
  32535. ['2011-10-08T18:04:20' + tz2, '2011-10-08T18:04:20.000' + tz],
  32536. ['2011-10-08T18:04' + tz3, '2011-10-08T18:' + minutesForTz3 + ':00.000' + tz],
  32537. ['2011-10-08T18:04:20' + tz3, '2011-10-08T18:' + minutesForTz3 + ':20.000' + tz],
  32538. ['2011-10-08T18:04:20.1' + tz2, '2011-10-08T18:04:20.100' + tz],
  32539. ['2011-10-08T18:04:20.11' + tz2, '2011-10-08T18:04:20.110' + tz],
  32540. ['2011-10-08T18:04:20.111' + tz2, '2011-10-08T18:04:20.111' + tz],
  32541. ['2011-10-08 18', '2011-10-08T18:00:00.000' + tz],
  32542. ['2011-10-08 18:04', '2011-10-08T18:04:00.000' + tz],
  32543. ['2011-10-08 18:04:20', '2011-10-08T18:04:20.000' + tz],
  32544. ['2011-10-08 18:04' + tz, '2011-10-08T18:04:00.000' + tz],
  32545. ['2011-10-08 18:04:20' + tz, '2011-10-08T18:04:20.000' + tz],
  32546. ['2011-10-08 18:04' + tz2, '2011-10-08T18:04:00.000' + tz],
  32547. ['2011-10-08 18:04:20' + tz2, '2011-10-08T18:04:20.000' + tz],
  32548. ['2011-10-08 18:04' + tz3, '2011-10-08T18:' + minutesForTz3 + ':00.000' + tz],
  32549. ['2011-10-08 18:04:20' + tz3, '2011-10-08T18:' + minutesForTz3 + ':20.000' + tz],
  32550. ['2011-10-08 18:04:20.1' + tz2, '2011-10-08T18:04:20.100' + tz],
  32551. ['2011-10-08 18:04:20.11' + tz2, '2011-10-08T18:04:20.110' + tz],
  32552. ['2011-10-08 18:04:20.111' + tz2, '2011-10-08T18:04:20.111' + tz],
  32553. ['2011-W40', '2011-10-03T00:00:00.000' + tz],
  32554. ['2011-W40-6', '2011-10-08T00:00:00.000' + tz],
  32555. ['2011-W40-6T18', '2011-10-08T18:00:00.000' + tz],
  32556. ['2011-W40-6T18:04', '2011-10-08T18:04:00.000' + tz],
  32557. ['2011-W40-6T18:04:20', '2011-10-08T18:04:20.000' + tz],
  32558. ['2011-W40-6T18:04' + tz, '2011-10-08T18:04:00.000' + tz],
  32559. ['2011-W40-6T18:04:20' + tz, '2011-10-08T18:04:20.000' + tz],
  32560. ['2011-W40-6T18:04' + tz2, '2011-10-08T18:04:00.000' + tz],
  32561. ['2011-W40-6T18:04:20' + tz2, '2011-10-08T18:04:20.000' + tz],
  32562. ['2011-W40-6T18:04' + tz3, '2011-10-08T18:' + minutesForTz3 + ':00.000' + tz],
  32563. ['2011-W40-6T18:04:20' + tz3, '2011-10-08T18:' + minutesForTz3 + ':20.000' + tz],
  32564. ['2011-W40-6T18:04:20.1' + tz2, '2011-10-08T18:04:20.100' + tz],
  32565. ['2011-W40-6T18:04:20.11' + tz2, '2011-10-08T18:04:20.110' + tz],
  32566. ['2011-W40-6T18:04:20.111' + tz2, '2011-10-08T18:04:20.111' + tz],
  32567. ['2011-W40-6 18', '2011-10-08T18:00:00.000' + tz],
  32568. ['2011-W40-6 18:04', '2011-10-08T18:04:00.000' + tz],
  32569. ['2011-W40-6 18:04:20', '2011-10-08T18:04:20.000' + tz],
  32570. ['2011-W40-6 18:04' + tz, '2011-10-08T18:04:00.000' + tz],
  32571. ['2011-W40-6 18:04:20' + tz, '2011-10-08T18:04:20.000' + tz],
  32572. ['2011-W40-6 18:04' + tz2, '2011-10-08T18:04:00.000' + tz],
  32573. ['2011-W40-6 18:04:20' + tz2, '2011-10-08T18:04:20.000' + tz],
  32574. ['2011-W40-6 18:04' + tz3, '2011-10-08T18:' + minutesForTz3 + ':00.000' + tz],
  32575. ['2011-W40-6 18:04:20' + tz3, '2011-10-08T18:' + minutesForTz3 + ':20.000' + tz],
  32576. ['2011-W40-6 18:04:20.1' + tz2, '2011-10-08T18:04:20.100' + tz],
  32577. ['2011-W40-6 18:04:20.11' + tz2, '2011-10-08T18:04:20.110' + tz],
  32578. ['2011-W40-6 18:04:20.111' + tz2, '2011-10-08T18:04:20.111' + tz],
  32579. ['2011-281', '2011-10-08T00:00:00.000' + tz],
  32580. ['2011-281T18', '2011-10-08T18:00:00.000' + tz],
  32581. ['2011-281T18:04', '2011-10-08T18:04:00.000' + tz],
  32582. ['2011-281T18:04:20', '2011-10-08T18:04:20.000' + tz],
  32583. ['2011-281T18:04' + tz, '2011-10-08T18:04:00.000' + tz],
  32584. ['2011-281T18:04:20' + tz, '2011-10-08T18:04:20.000' + tz],
  32585. ['2011-281T18:04' + tz2, '2011-10-08T18:04:00.000' + tz],
  32586. ['2011-281T18:04:20' + tz2, '2011-10-08T18:04:20.000' + tz],
  32587. ['2011-281T18:04' + tz3, '2011-10-08T18:' + minutesForTz3 + ':00.000' + tz],
  32588. ['2011-281T18:04:20' + tz3, '2011-10-08T18:' + minutesForTz3 + ':20.000' + tz],
  32589. ['2011-281T18:04:20.1' + tz2, '2011-10-08T18:04:20.100' + tz],
  32590. ['2011-281T18:04:20.11' + tz2, '2011-10-08T18:04:20.110' + tz],
  32591. ['2011-281T18:04:20.111' + tz2, '2011-10-08T18:04:20.111' + tz],
  32592. ['2011-281 18', '2011-10-08T18:00:00.000' + tz],
  32593. ['2011-281 18:04', '2011-10-08T18:04:00.000' + tz],
  32594. ['2011-281 18:04:20', '2011-10-08T18:04:20.000' + tz],
  32595. ['2011-281 18:04' + tz, '2011-10-08T18:04:00.000' + tz],
  32596. ['2011-281 18:04:20' + tz, '2011-10-08T18:04:20.000' + tz],
  32597. ['2011-281 18:04' + tz2, '2011-10-08T18:04:00.000' + tz],
  32598. ['2011-281 18:04:20' + tz2, '2011-10-08T18:04:20.000' + tz],
  32599. ['2011-281 18:04' + tz3, '2011-10-08T18:' + minutesForTz3 + ':00.000' + tz],
  32600. ['2011-281 18:04:20' + tz3, '2011-10-08T18:' + minutesForTz3 + ':20.000' + tz],
  32601. ['2011-281 18:04:20.1' + tz2, '2011-10-08T18:04:20.100' + tz],
  32602. ['2011-281 18:04:20.11' + tz2, '2011-10-08T18:04:20.110' + tz],
  32603. ['2011-281 18:04:20.111' + tz2, '2011-10-08T18:04:20.111' + tz],
  32604. ['20111008T18', '2011-10-08T18:00:00.000' + tz],
  32605. ['20111008T1804', '2011-10-08T18:04:00.000' + tz],
  32606. ['20111008T180420', '2011-10-08T18:04:20.000' + tz],
  32607. ['20111008T1804' + tz, '2011-10-08T18:04:00.000' + tz],
  32608. ['20111008T180420' + tz, '2011-10-08T18:04:20.000' + tz],
  32609. ['20111008T1804' + tz2, '2011-10-08T18:04:00.000' + tz],
  32610. ['20111008T180420' + tz2, '2011-10-08T18:04:20.000' + tz],
  32611. ['20111008T1804' + tz3, '2011-10-08T18:' + minutesForTz3 + ':00.000' + tz],
  32612. ['20111008T180420' + tz3, '2011-10-08T18:' + minutesForTz3 + ':20.000' + tz],
  32613. ['20111008T180420,1' + tz2, '2011-10-08T18:04:20.100' + tz],
  32614. ['20111008T180420,11' + tz2, '2011-10-08T18:04:20.110' + tz],
  32615. ['20111008T180420,111' + tz2, '2011-10-08T18:04:20.111' + tz],
  32616. ['20111008 18', '2011-10-08T18:00:00.000' + tz],
  32617. ['20111008 1804', '2011-10-08T18:04:00.000' + tz],
  32618. ['20111008 180420', '2011-10-08T18:04:20.000' + tz],
  32619. ['20111008 1804' + tz, '2011-10-08T18:04:00.000' + tz],
  32620. ['20111008 180420' + tz, '2011-10-08T18:04:20.000' + tz],
  32621. ['20111008 1804' + tz2, '2011-10-08T18:04:00.000' + tz],
  32622. ['20111008 180420' + tz2, '2011-10-08T18:04:20.000' + tz],
  32623. ['20111008 1804' + tz3, '2011-10-08T18:' + minutesForTz3 + ':00.000' + tz],
  32624. ['20111008 180420' + tz3, '2011-10-08T18:' + minutesForTz3 + ':20.000' + tz],
  32625. ['20111008 180420,1' + tz2, '2011-10-08T18:04:20.100' + tz],
  32626. ['20111008 180420,11' + tz2, '2011-10-08T18:04:20.110' + tz],
  32627. ['20111008 180420,111' + tz2, '2011-10-08T18:04:20.111' + tz],
  32628. ['2011W40', '2011-10-03T00:00:00.000' + tz],
  32629. ['2011W406', '2011-10-08T00:00:00.000' + tz],
  32630. ['2011W406T18', '2011-10-08T18:00:00.000' + tz],
  32631. ['2011W406T1804', '2011-10-08T18:04:00.000' + tz],
  32632. ['2011W406T180420', '2011-10-08T18:04:20.000' + tz],
  32633. ['2011W406 1804' + tz2, '2011-10-08T18:04:00.000' + tz],
  32634. ['2011W406T1804' + tz, '2011-10-08T18:04:00.000' + tz],
  32635. ['2011W406T180420' + tz, '2011-10-08T18:04:20.000' + tz],
  32636. ['2011W406T1804' + tz2, '2011-10-08T18:04:00.000' + tz],
  32637. ['2011W406T180420' + tz2, '2011-10-08T18:04:20.000' + tz],
  32638. ['2011W406T1804' + tz3, '2011-10-08T18:' + minutesForTz3 + ':00.000' + tz],
  32639. ['2011W406T180420' + tz3, '2011-10-08T18:' + minutesForTz3 + ':20.000' + tz],
  32640. ['2011W406T180420,1' + tz2, '2011-10-08T18:04:20.100' + tz],
  32641. ['2011W406T180420,11' + tz2, '2011-10-08T18:04:20.110' + tz],
  32642. ['2011W406T180420,111' + tz2, '2011-10-08T18:04:20.111' + tz],
  32643. ['2011W406 18', '2011-10-08T18:00:00.000' + tz],
  32644. ['2011W406 1804', '2011-10-08T18:04:00.000' + tz],
  32645. ['2011W406 180420', '2011-10-08T18:04:20.000' + tz],
  32646. ['2011W406 1804' + tz, '2011-10-08T18:04:00.000' + tz],
  32647. ['2011W406 180420' + tz, '2011-10-08T18:04:20.000' + tz],
  32648. ['2011W406 180420' + tz2, '2011-10-08T18:04:20.000' + tz],
  32649. ['2011W406 1804' + tz3, '2011-10-08T18:' + minutesForTz3 + ':00.000' + tz],
  32650. ['2011W406 180420' + tz3, '2011-10-08T18:' + minutesForTz3 + ':20.000' + tz],
  32651. ['2011W406 180420,1' + tz2, '2011-10-08T18:04:20.100' + tz],
  32652. ['2011W406 180420,11' + tz2, '2011-10-08T18:04:20.110' + tz],
  32653. ['2011W406 180420,111' + tz2, '2011-10-08T18:04:20.111' + tz],
  32654. ['2011281', '2011-10-08T00:00:00.000' + tz],
  32655. ['2011281T18', '2011-10-08T18:00:00.000' + tz],
  32656. ['2011281T1804', '2011-10-08T18:04:00.000' + tz],
  32657. ['2011281T180420', '2011-10-08T18:04:20.000' + tz],
  32658. ['2011281T1804' + tz, '2011-10-08T18:04:00.000' + tz],
  32659. ['2011281T180420' + tz, '2011-10-08T18:04:20.000' + tz],
  32660. ['2011281T1804' + tz2, '2011-10-08T18:04:00.000' + tz],
  32661. ['2011281T180420' + tz2, '2011-10-08T18:04:20.000' + tz],
  32662. ['2011281T1804' + tz3, '2011-10-08T18:' + minutesForTz3 + ':00.000' + tz],
  32663. ['2011281T180420' + tz3, '2011-10-08T18:' + minutesForTz3 + ':20.000' + tz],
  32664. ['2011281T180420,1' + tz2, '2011-10-08T18:04:20.100' + tz],
  32665. ['2011281T180420,11' + tz2, '2011-10-08T18:04:20.110' + tz],
  32666. ['2011281T180420,111' + tz2, '2011-10-08T18:04:20.111' + tz],
  32667. ['2011281 18', '2011-10-08T18:00:00.000' + tz],
  32668. ['2011281 1804', '2011-10-08T18:04:00.000' + tz],
  32669. ['2011281 180420', '2011-10-08T18:04:20.000' + tz],
  32670. ['2011281 1804' + tz, '2011-10-08T18:04:00.000' + tz],
  32671. ['2011281 180420' + tz, '2011-10-08T18:04:20.000' + tz],
  32672. ['2011281 1804' + tz2, '2011-10-08T18:04:00.000' + tz],
  32673. ['2011281 180420' + tz2, '2011-10-08T18:04:20.000' + tz],
  32674. ['2011281 1804' + tz3, '2011-10-08T18:' + minutesForTz3 + ':00.000' + tz],
  32675. ['2011281 180420' + tz3, '2011-10-08T18:' + minutesForTz3 + ':20.000' + tz],
  32676. ['2011281 180420,1' + tz2, '2011-10-08T18:04:20.100' + tz],
  32677. ['2011281 180420,11' + tz2, '2011-10-08T18:04:20.110' + tz],
  32678. ['2011281 180420,111' + tz2, '2011-10-08T18:04:20.111' + tz]
  32679. ], i;
  32680. for (i = 0; i < formats.length; i++) {
  32681. assert.equal(moment(formats[i][0]).format('YYYY-MM-DDTHH:mm:ss.SSSZ'),
  32682. formats[i][1], 'moment should be able to parse ISO ' + formats[i][0]);
  32683. assert.equal(moment(formats[i][0], moment.ISO_8601).format('YYYY-MM-DDTHH:mm:ss.SSSZ'),
  32684. formats[i][1], 'moment should be able to parse specified ISO ' + formats[i][0]);
  32685. assert.equal(moment(formats[i][0], moment.ISO_8601, true).format('YYYY-MM-DDTHH:mm:ss.SSSZ'),
  32686. formats[i][1], 'moment should be able to parse specified strict ISO ' + formats[i][0]);
  32687. }
  32688. });
  32689. test('non iso 8601 strings', function (assert) {
  32690. assert.ok(!moment('2015-10T10:15', moment.ISO_8601, true).isValid(), 'incomplete date with time');
  32691. assert.ok(!moment('2015-W10T10:15', moment.ISO_8601, true).isValid(), 'incomplete week date with time');
  32692. assert.ok(!moment('201510', moment.ISO_8601, true).isValid(), 'basic YYYYMM is not allowed');
  32693. assert.ok(!moment('2015W10T1015', moment.ISO_8601, true).isValid(), 'incomplete week date with time (basic)');
  32694. assert.ok(!moment('2015-10-08T1015', moment.ISO_8601, true).isValid(), 'mixing extended and basic format');
  32695. assert.ok(!moment('20151008T10:15', moment.ISO_8601, true).isValid(), 'mixing basic and extended format');
  32696. });
  32697. test('parsing iso week year/week/weekday', function (assert) {
  32698. assert.equal(moment.utc('2007-W01').format(), '2007-01-01T00:00:00+00:00', '2008 week 1 (1st Jan Mon)');
  32699. assert.equal(moment.utc('2008-W01').format(), '2007-12-31T00:00:00+00:00', '2008 week 1 (1st Jan Tue)');
  32700. assert.equal(moment.utc('2003-W01').format(), '2002-12-30T00:00:00+00:00', '2008 week 1 (1st Jan Wed)');
  32701. assert.equal(moment.utc('2009-W01').format(), '2008-12-29T00:00:00+00:00', '2009 week 1 (1st Jan Thu)');
  32702. assert.equal(moment.utc('2010-W01').format(), '2010-01-04T00:00:00+00:00', '2010 week 1 (1st Jan Fri)');
  32703. assert.equal(moment.utc('2011-W01').format(), '2011-01-03T00:00:00+00:00', '2011 week 1 (1st Jan Sat)');
  32704. assert.equal(moment.utc('2012-W01').format(), '2012-01-02T00:00:00+00:00', '2012 week 1 (1st Jan Sun)');
  32705. });
  32706. test('parsing week year/week/weekday (dow 1, doy 4)', function (assert) {
  32707. moment.locale('dow:1,doy:4', {week: {dow: 1, doy: 4}});
  32708. assert.equal(moment.utc('2007-01', 'gggg-ww').format(), '2007-01-01T00:00:00+00:00', '2007 week 1 (1st Jan Mon)');
  32709. assert.equal(moment.utc('2008-01', 'gggg-ww').format(), '2007-12-31T00:00:00+00:00', '2008 week 1 (1st Jan Tue)');
  32710. assert.equal(moment.utc('2003-01', 'gggg-ww').format(), '2002-12-30T00:00:00+00:00', '2003 week 1 (1st Jan Wed)');
  32711. assert.equal(moment.utc('2009-01', 'gggg-ww').format(), '2008-12-29T00:00:00+00:00', '2009 week 1 (1st Jan Thu)');
  32712. assert.equal(moment.utc('2010-01', 'gggg-ww').format(), '2010-01-04T00:00:00+00:00', '2010 week 1 (1st Jan Fri)');
  32713. assert.equal(moment.utc('2011-01', 'gggg-ww').format(), '2011-01-03T00:00:00+00:00', '2011 week 1 (1st Jan Sat)');
  32714. assert.equal(moment.utc('2012-01', 'gggg-ww').format(), '2012-01-02T00:00:00+00:00', '2012 week 1 (1st Jan Sun)');
  32715. moment.defineLocale('dow:1,doy:4', null);
  32716. });
  32717. test('parsing week year/week/weekday (dow 1, doy 7)', function (assert) {
  32718. moment.locale('dow:1,doy:7', {week: {dow: 1, doy: 7}});
  32719. assert.equal(moment.utc('2007-01', 'gggg-ww').format(), '2007-01-01T00:00:00+00:00', '2007 week 1 (1st Jan Mon)');
  32720. assert.equal(moment.utc('2008-01', 'gggg-ww').format(), '2007-12-31T00:00:00+00:00', '2008 week 1 (1st Jan Tue)');
  32721. assert.equal(moment.utc('2003-01', 'gggg-ww').format(), '2002-12-30T00:00:00+00:00', '2003 week 1 (1st Jan Wed)');
  32722. assert.equal(moment.utc('2009-01', 'gggg-ww').format(), '2008-12-29T00:00:00+00:00', '2009 week 1 (1st Jan Thu)');
  32723. assert.equal(moment.utc('2010-01', 'gggg-ww').format(), '2009-12-28T00:00:00+00:00', '2010 week 1 (1st Jan Fri)');
  32724. assert.equal(moment.utc('2011-01', 'gggg-ww').format(), '2010-12-27T00:00:00+00:00', '2011 week 1 (1st Jan Sat)');
  32725. assert.equal(moment.utc('2012-01', 'gggg-ww').format(), '2011-12-26T00:00:00+00:00', '2012 week 1 (1st Jan Sun)');
  32726. moment.defineLocale('dow:1,doy:7', null);
  32727. });
  32728. test('parsing week year/week/weekday (dow 0, doy 6)', function (assert) {
  32729. moment.locale('dow:0,doy:6', {week: {dow: 0, doy: 6}});
  32730. assert.equal(moment.utc('2007-01', 'gggg-ww').format(), '2006-12-31T00:00:00+00:00', '2007 week 1 (1st Jan Mon)');
  32731. assert.equal(moment.utc('2008-01', 'gggg-ww').format(), '2007-12-30T00:00:00+00:00', '2008 week 1 (1st Jan Tue)');
  32732. assert.equal(moment.utc('2003-01', 'gggg-ww').format(), '2002-12-29T00:00:00+00:00', '2003 week 1 (1st Jan Wed)');
  32733. assert.equal(moment.utc('2009-01', 'gggg-ww').format(), '2008-12-28T00:00:00+00:00', '2009 week 1 (1st Jan Thu)');
  32734. assert.equal(moment.utc('2010-01', 'gggg-ww').format(), '2009-12-27T00:00:00+00:00', '2010 week 1 (1st Jan Fri)');
  32735. assert.equal(moment.utc('2011-01', 'gggg-ww').format(), '2010-12-26T00:00:00+00:00', '2011 week 1 (1st Jan Sat)');
  32736. assert.equal(moment.utc('2012-01', 'gggg-ww').format(), '2012-01-01T00:00:00+00:00', '2012 week 1 (1st Jan Sun)');
  32737. moment.defineLocale('dow:0,doy:6', null);
  32738. });
  32739. test('parsing week year/week/weekday (dow 6, doy 12)', function (assert) {
  32740. moment.locale('dow:6,doy:12', {week: {dow: 6, doy: 12}});
  32741. assert.equal(moment.utc('2007-01', 'gggg-ww').format(), '2006-12-30T00:00:00+00:00', '2007 week 1 (1st Jan Mon)');
  32742. assert.equal(moment.utc('2008-01', 'gggg-ww').format(), '2007-12-29T00:00:00+00:00', '2008 week 1 (1st Jan Tue)');
  32743. assert.equal(moment.utc('2003-01', 'gggg-ww').format(), '2002-12-28T00:00:00+00:00', '2003 week 1 (1st Jan Wed)');
  32744. assert.equal(moment.utc('2009-01', 'gggg-ww').format(), '2008-12-27T00:00:00+00:00', '2009 week 1 (1st Jan Thu)');
  32745. assert.equal(moment.utc('2010-01', 'gggg-ww').format(), '2009-12-26T00:00:00+00:00', '2010 week 1 (1st Jan Fri)');
  32746. assert.equal(moment.utc('2011-01', 'gggg-ww').format(), '2011-01-01T00:00:00+00:00', '2011 week 1 (1st Jan Sat)');
  32747. assert.equal(moment.utc('2012-01', 'gggg-ww').format(), '2011-12-31T00:00:00+00:00', '2012 week 1 (1st Jan Sun)');
  32748. });
  32749. test('parsing ISO with Z', function (assert) {
  32750. var i, mom, formats = [
  32751. ['2011-10-08T18:04', '2011-10-08T18:04:00.000'],
  32752. ['2011-10-08T18:04:20', '2011-10-08T18:04:20.000'],
  32753. ['2011-10-08T18:04:20.1', '2011-10-08T18:04:20.100'],
  32754. ['2011-10-08T18:04:20.11', '2011-10-08T18:04:20.110'],
  32755. ['2011-10-08T18:04:20.111', '2011-10-08T18:04:20.111'],
  32756. ['2011-W40-6T18', '2011-10-08T18:00:00.000'],
  32757. ['2011-W40-6T18:04', '2011-10-08T18:04:00.000'],
  32758. ['2011-W40-6T18:04:20', '2011-10-08T18:04:20.000'],
  32759. ['2011-W40-6T18:04:20.1', '2011-10-08T18:04:20.100'],
  32760. ['2011-W40-6T18:04:20.11', '2011-10-08T18:04:20.110'],
  32761. ['2011-W40-6T18:04:20.111', '2011-10-08T18:04:20.111'],
  32762. ['2011-281T18', '2011-10-08T18:00:00.000'],
  32763. ['2011-281T18:04', '2011-10-08T18:04:00.000'],
  32764. ['2011-281T18:04:20', '2011-10-08T18:04:20.000'],
  32765. ['2011-281T18:04:20', '2011-10-08T18:04:20.000'],
  32766. ['2011-281T18:04:20.1', '2011-10-08T18:04:20.100'],
  32767. ['2011-281T18:04:20.11', '2011-10-08T18:04:20.110'],
  32768. ['2011-281T18:04:20.111', '2011-10-08T18:04:20.111']
  32769. ];
  32770. for (i = 0; i < formats.length; i++) {
  32771. mom = moment(formats[i][0] + 'Z').utc();
  32772. assert.equal(mom.format('YYYY-MM-DDTHH:mm:ss.SSS'), formats[i][1], 'moment should be able to parse ISO in UTC ' + formats[i][0] + 'Z');
  32773. mom = moment(formats[i][0] + ' Z').utc();
  32774. assert.equal(mom.format('YYYY-MM-DDTHH:mm:ss.SSS'), formats[i][1], 'moment should be able to parse ISO in UTC ' + formats[i][0] + ' Z');
  32775. }
  32776. });
  32777. test('parsing iso with T', function (assert) {
  32778. assert.equal(moment('2011-10-08T18')._f, 'YYYY-MM-DDTHH', 'should include \'T\' in the format');
  32779. assert.equal(moment('2011-10-08T18:20')._f, 'YYYY-MM-DDTHH:mm', 'should include \'T\' in the format');
  32780. assert.equal(moment('2011-10-08T18:20:13')._f, 'YYYY-MM-DDTHH:mm:ss', 'should include \'T\' in the format');
  32781. assert.equal(moment('2011-10-08T18:20:13.321')._f, 'YYYY-MM-DDTHH:mm:ss.SSSS', 'should include \'T\' in the format');
  32782. assert.equal(moment('2011-10-08 18')._f, 'YYYY-MM-DD HH', 'should not include \'T\' in the format');
  32783. assert.equal(moment('2011-10-08 18:20')._f, 'YYYY-MM-DD HH:mm', 'should not include \'T\' in the format');
  32784. assert.equal(moment('2011-10-08 18:20:13')._f, 'YYYY-MM-DD HH:mm:ss', 'should not include \'T\' in the format');
  32785. assert.equal(moment('2011-10-08 18:20:13.321')._f, 'YYYY-MM-DD HH:mm:ss.SSSS', 'should not include \'T\' in the format');
  32786. });
  32787. test('parsing iso Z timezone', function (assert) {
  32788. var i,
  32789. formats = [
  32790. ['2011-10-08T18:04Z', '2011-10-08T18:04:00.000+00:00'],
  32791. ['2011-10-08T18:04:20Z', '2011-10-08T18:04:20.000+00:00'],
  32792. ['2011-10-08T18:04:20.111Z', '2011-10-08T18:04:20.111+00:00']
  32793. ];
  32794. for (i = 0; i < formats.length; i++) {
  32795. assert.equal(moment.utc(formats[i][0]).format('YYYY-MM-DDTHH:mm:ss.SSSZ'), formats[i][1], 'moment should be able to parse ISO ' + formats[i][0]);
  32796. }
  32797. });
  32798. test('parsing iso Z timezone into local', function (assert) {
  32799. var m = moment('2011-10-08T18:04:20.111Z');
  32800. assert.equal(m.utc().format('YYYY-MM-DDTHH:mm:ss.SSS'), '2011-10-08T18:04:20.111', 'moment should be able to parse ISO 2011-10-08T18:04:20.111Z');
  32801. });
  32802. test('parsing iso with more subsecond precision digits', function (assert) {
  32803. assert.equal(moment.utc('2013-07-31T22:00:00.0000000Z').format(), '2013-07-31T22:00:00+00:00', 'more than 3 subsecond digits');
  32804. });
  32805. test('null or empty', function (assert) {
  32806. assert.equal(moment('').isValid(), false, 'moment(\'\') is not valid');
  32807. assert.equal(moment(null).isValid(), false, 'moment(null) is not valid');
  32808. assert.equal(moment(null, 'YYYY-MM-DD').isValid(), false, 'moment(\'\', \'format\') is not valid');
  32809. assert.equal(moment('', 'YYYY-MM-DD').isValid(), false, 'moment(\'\', \'format\') is not valid');
  32810. assert.equal(moment.utc('').isValid(), false, 'moment.utc(\'\') is not valid');
  32811. assert.equal(moment.utc(null).isValid(), false, 'moment.utc(null) is not valid');
  32812. assert.equal(moment.utc(null, 'YYYY-MM-DD').isValid(), false, 'moment.utc(null) is not valid');
  32813. assert.equal(moment.utc('', 'YYYY-MM-DD').isValid(), false, 'moment.utc(\'\', \'YYYY-MM-DD\') is not valid');
  32814. });
  32815. test('first century', function (assert) {
  32816. assert.equal(moment([0, 0, 1]).format('YYYY-MM-DD'), '0000-01-01', 'Year AD 0');
  32817. assert.equal(moment([99, 0, 1]).format('YYYY-MM-DD'), '0099-01-01', 'Year AD 99');
  32818. assert.equal(moment([999, 0, 1]).format('YYYY-MM-DD'), '0999-01-01', 'Year AD 999');
  32819. assert.equal(moment('0 1 1', 'YYYY MM DD').format('YYYY-MM-DD'), '0000-01-01', 'Year AD 0');
  32820. assert.equal(moment('999 1 1', 'YYYY MM DD').format('YYYY-MM-DD'), '0999-01-01', 'Year AD 999');
  32821. assert.equal(moment('0 1 1', 'YYYYY MM DD').format('YYYYY-MM-DD'), '00000-01-01', 'Year AD 0');
  32822. assert.equal(moment('99 1 1', 'YYYYY MM DD').format('YYYYY-MM-DD'), '00099-01-01', 'Year AD 99');
  32823. assert.equal(moment('999 1 1', 'YYYYY MM DD').format('YYYYY-MM-DD'), '00999-01-01', 'Year AD 999');
  32824. });
  32825. test('six digit years', function (assert) {
  32826. assert.equal(moment([-270000, 0, 1]).format('YYYYY-MM-DD'), '-270000-01-01', 'format BC 270,001');
  32827. assert.equal(moment([270000, 0, 1]).format('YYYYY-MM-DD'), '270000-01-01', 'format AD 270,000');
  32828. assert.equal(moment('-270000-01-01', 'YYYYY-MM-DD').toDate().getFullYear(), -270000, 'parse BC 270,001');
  32829. assert.equal(moment('270000-01-01', 'YYYYY-MM-DD').toDate().getFullYear(), 270000, 'parse AD 270,000');
  32830. assert.equal(moment('+270000-01-01', 'YYYYY-MM-DD').toDate().getFullYear(), 270000, 'parse AD +270,000');
  32831. assert.equal(moment.utc('-270000-01-01', 'YYYYY-MM-DD').toDate().getUTCFullYear(), -270000, 'parse utc BC 270,001');
  32832. assert.equal(moment.utc('270000-01-01', 'YYYYY-MM-DD').toDate().getUTCFullYear(), 270000, 'parse utc AD 270,000');
  32833. assert.equal(moment.utc('+270000-01-01', 'YYYYY-MM-DD').toDate().getUTCFullYear(), 270000, 'parse utc AD +270,000');
  32834. });
  32835. test('negative four digit years', function (assert) {
  32836. assert.equal(moment('-1000-01-01', 'YYYYY-MM-DD').toDate().getFullYear(), -1000, 'parse BC 1,001');
  32837. assert.equal(moment.utc('-1000-01-01', 'YYYYY-MM-DD').toDate().getUTCFullYear(), -1000, 'parse utc BC 1,001');
  32838. });
  32839. test('strict parsing', function (assert) {
  32840. assert.equal(moment('2014-', 'YYYY-Q', true).isValid(), false, 'fail missing quarter');
  32841. assert.equal(moment('2012-05', 'YYYY-MM', true).format('YYYY-MM'), '2012-05', 'parse correct string');
  32842. assert.equal(moment(' 2012-05', 'YYYY-MM', true).isValid(), false, 'fail on extra whitespace');
  32843. assert.equal(moment('foo 2012-05', '[foo] YYYY-MM', true).format('YYYY-MM'), '2012-05', 'handle fixed text');
  32844. assert.equal(moment('2012 05', 'YYYY-MM', true).isValid(), false, 'fail on different separator');
  32845. assert.equal(moment('2012 05', 'YYYY MM DD', true).isValid(), false, 'fail on too many tokens');
  32846. assert.equal(moment('05 30 2010', ['DD MM YYYY', 'MM DD YYYY'], true).format('MM DD YYYY'), '05 30 2010', 'array with bad date');
  32847. assert.equal(moment('05 30 2010', ['', 'MM DD YYYY'], true).format('MM DD YYYY'), '05 30 2010', 'array with invalid format');
  32848. assert.equal(moment('05 30 2010', [' DD MM YYYY', 'MM DD YYYY'], true).format('MM DD YYYY'), '05 30 2010', 'array with non-matching format');
  32849. assert.equal(moment('2010.*...', 'YYYY.*', true).isValid(), false, 'invalid format with regex chars');
  32850. assert.equal(moment('2010.*', 'YYYY.*', true).year(), 2010, 'valid format with regex chars');
  32851. assert.equal(moment('.*2010.*', '.*YYYY.*', true).year(), 2010, 'valid format with regex chars on both sides');
  32852. //strict tokens
  32853. assert.equal(moment('-5-05-25', 'YYYY-MM-DD', true).isValid(), false, 'invalid negative year');
  32854. assert.equal(moment('2-05-25', 'YYYY-MM-DD', true).isValid(), false, 'invalid one-digit year');
  32855. assert.equal(moment('20-05-25', 'YYYY-MM-DD', true).isValid(), false, 'invalid two-digit year');
  32856. assert.equal(moment('201-05-25', 'YYYY-MM-DD', true).isValid(), false, 'invalid three-digit year');
  32857. assert.equal(moment('2010-05-25', 'YYYY-MM-DD', true).isValid(), true, 'valid four-digit year');
  32858. assert.equal(moment('22010-05-25', 'YYYY-MM-DD', true).isValid(), false, 'invalid five-digit year');
  32859. assert.equal(moment('12-05-25', 'YY-MM-DD', true).isValid(), true, 'valid two-digit year');
  32860. assert.equal(moment('2012-05-25', 'YY-MM-DD', true).isValid(), false, 'invalid four-digit year');
  32861. assert.equal(moment('-5-05-25', 'Y-MM-DD', true).isValid(), true, 'valid negative year');
  32862. assert.equal(moment('2-05-25', 'Y-MM-DD', true).isValid(), true, 'valid one-digit year');
  32863. assert.equal(moment('20-05-25', 'Y-MM-DD', true).isValid(), true, 'valid two-digit year');
  32864. assert.equal(moment('201-05-25', 'Y-MM-DD', true).isValid(), true, 'valid three-digit year');
  32865. assert.equal(moment('2012-5-25', 'YYYY-M-DD', true).isValid(), true, 'valid one-digit month');
  32866. assert.equal(moment('2012-5-25', 'YYYY-MM-DD', true).isValid(), false, 'invalid one-digit month');
  32867. assert.equal(moment('2012-05-25', 'YYYY-M-DD', true).isValid(), true, 'valid one-digit month');
  32868. assert.equal(moment('2012-05-25', 'YYYY-MM-DD', true).isValid(), true, 'valid one-digit month');
  32869. assert.equal(moment('2012-05-2', 'YYYY-MM-D', true).isValid(), true, 'valid one-digit day');
  32870. assert.equal(moment('2012-05-2', 'YYYY-MM-DD', true).isValid(), false, 'invalid one-digit day');
  32871. assert.equal(moment('2012-05-02', 'YYYY-MM-D', true).isValid(), true, 'valid two-digit day');
  32872. assert.equal(moment('2012-05-02', 'YYYY-MM-DD', true).isValid(), true, 'valid two-digit day');
  32873. assert.equal(moment('+002012-05-25', 'YYYYY-MM-DD', true).isValid(), true, 'valid six-digit year');
  32874. assert.equal(moment('+2012-05-25', 'YYYYY-MM-DD', true).isValid(), false, 'invalid four-digit year');
  32875. //thse are kinda pointless, but they should work as expected
  32876. assert.equal(moment('1', 'S', true).isValid(), true, 'valid one-digit milisecond');
  32877. assert.equal(moment('12', 'S', true).isValid(), false, 'invalid two-digit milisecond');
  32878. assert.equal(moment('123', 'S', true).isValid(), false, 'invalid three-digit milisecond');
  32879. assert.equal(moment('1', 'SS', true).isValid(), false, 'invalid one-digit milisecond');
  32880. assert.equal(moment('12', 'SS', true).isValid(), true, 'valid two-digit milisecond');
  32881. assert.equal(moment('123', 'SS', true).isValid(), false, 'invalid three-digit milisecond');
  32882. assert.equal(moment('1', 'SSS', true).isValid(), false, 'invalid one-digit milisecond');
  32883. assert.equal(moment('12', 'SSS', true).isValid(), false, 'invalid two-digit milisecond');
  32884. assert.equal(moment('123', 'SSS', true).isValid(), true, 'valid three-digit milisecond');
  32885. // strict parsing respects month length
  32886. assert.ok(moment('1 January 2000', 'D MMMM YYYY', true).isValid(), 'capital long-month + MMMM');
  32887. assert.ok(!moment('1 January 2000', 'D MMM YYYY', true).isValid(), 'capital long-month + MMM');
  32888. assert.ok(!moment('1 Jan 2000', 'D MMMM YYYY', true).isValid(), 'capital short-month + MMMM');
  32889. assert.ok(moment('1 Jan 2000', 'D MMM YYYY', true).isValid(), 'capital short-month + MMM');
  32890. assert.ok(moment('1 january 2000', 'D MMMM YYYY', true).isValid(), 'lower long-month + MMMM');
  32891. assert.ok(!moment('1 january 2000', 'D MMM YYYY', true).isValid(), 'lower long-month + MMM');
  32892. assert.ok(!moment('1 jan 2000', 'D MMMM YYYY', true).isValid(), 'lower short-month + MMMM');
  32893. assert.ok(moment('1 jan 2000', 'D MMM YYYY', true).isValid(), 'lower short-month + MMM');
  32894. });
  32895. test('parsing into a locale', function (assert) {
  32896. moment.defineLocale('parselocale', {
  32897. months : 'one_two_three_four_five_six_seven_eight_nine_ten_eleven_twelve'.split('_'),
  32898. monthsShort : 'one_two_three_four_five_six_seven_eight_nine_ten_eleven_twelve'.split('_')
  32899. });
  32900. moment.locale('en');
  32901. assert.equal(moment('2012 seven', 'YYYY MMM', 'parselocale').month(), 6, 'should be able to parse in a specific locale');
  32902. moment.locale('parselocale');
  32903. assert.equal(moment('2012 july', 'YYYY MMM', 'en').month(), 6, 'should be able to parse in a specific locale');
  32904. moment.defineLocale('parselocale', null);
  32905. });
  32906. function getVerifier(test) {
  32907. return function (input, format, expected, description, asymetrical) {
  32908. var m = moment(input, format);
  32909. test.equal(m.format('YYYY MM DD'), expected, 'compare: ' + description);
  32910. //test round trip
  32911. if (!asymetrical) {
  32912. test.equal(m.format(format), input, 'round trip: ' + description);
  32913. }
  32914. };
  32915. }
  32916. test('parsing week and weekday information', function (assert) {
  32917. var ver = getVerifier(assert);
  32918. // year
  32919. ver('12', 'gg', '2012 01 01', 'week-year two digits');
  32920. ver('2012', 'gggg', '2012 01 01', 'week-year four digits');
  32921. ver('99', 'gg', '1998 12 27', 'week-year two digits previous year');
  32922. ver('1999', 'gggg', '1998 12 27', 'week-year four digits previous year');
  32923. ver('99', 'GG', '1999 01 04', 'iso week-year two digits');
  32924. ver('1999', 'GGGG', '1999 01 04', 'iso week-year four digits');
  32925. ver('13', 'GG', '2012 12 31', 'iso week-year two digits previous year');
  32926. ver('2013', 'GGGG', '2012 12 31', 'iso week-year four digits previous year');
  32927. // year + week
  32928. ver('1999 37', 'gggg w', '1999 09 05', 'week');
  32929. ver('1999 37', 'gggg ww', '1999 09 05', 'week double');
  32930. ver('1999 37', 'GGGG W', '1999 09 13', 'iso week');
  32931. ver('1999 37', 'GGGG WW', '1999 09 13', 'iso week double');
  32932. ver('1999 37 4', 'GGGG WW E', '1999 09 16', 'iso day');
  32933. ver('1999 37 04', 'GGGG WW E', '1999 09 16', 'iso day wide', true);
  32934. ver('1999 37 4', 'gggg ww e', '1999 09 09', 'day');
  32935. ver('1999 37 04', 'gggg ww e', '1999 09 09', 'day wide', true);
  32936. // year + week + day
  32937. ver('1999 37 4', 'gggg ww d', '1999 09 09', 'd');
  32938. ver('1999 37 Th', 'gggg ww dd', '1999 09 09', 'dd');
  32939. ver('1999 37 Thu', 'gggg ww ddd', '1999 09 09', 'ddd');
  32940. ver('1999 37 Thursday', 'gggg ww dddd', '1999 09 09', 'dddd');
  32941. // lower-order only
  32942. assert.equal(moment('22', 'ww').week(), 22, 'week sets the week by itself');
  32943. assert.equal(moment('22', 'ww').weekYear(), moment().weekYear(), 'week keeps this year');
  32944. assert.equal(moment('2012 22', 'YYYY ww').weekYear(), 2012, 'week keeps parsed year');
  32945. assert.equal(moment('22', 'WW').isoWeek(), 22, 'iso week sets the week by itself');
  32946. assert.equal(moment('2012 22', 'YYYY WW').weekYear(), 2012, 'iso week keeps parsed year');
  32947. assert.equal(moment('22', 'WW').isoWeekYear(), moment().isoWeekYear(), 'iso week keeps this year');
  32948. // order
  32949. ver('6 2013 2', 'e gggg w', '2013 01 12', 'order doesn\'t matter');
  32950. ver('6 2013 2', 'E GGGG W', '2013 01 12', 'iso order doesn\'t matter');
  32951. //can parse other stuff too
  32952. assert.equal(moment('1999-W37-4 3:30', 'GGGG-[W]WW-E HH:mm').format('YYYY MM DD HH:mm'), '1999 09 16 03:30', 'parsing weeks and hours');
  32953. // In safari, all years before 1300 are shifted back with one day.
  32954. // http://stackoverflow.com/questions/20768975/safari-subtracts-1-day-from-dates-before-1300
  32955. if (new Date('1300-01-01').getUTCFullYear() === 1300) {
  32956. // Years less than 100
  32957. ver('0098-06', 'GGGG-WW', '0098 02 03', 'small years work', true);
  32958. }
  32959. });
  32960. test('parsing localized weekdays', function (assert) {
  32961. var ver = getVerifier(assert);
  32962. try {
  32963. moment.locale('dow:1,doy:4', {
  32964. weekdays : 'dimanche_lundi_mardi_mercredi_jeudi_vendredi_samedi'.split('_'),
  32965. weekdaysShort : 'dim._lun._mar._mer._jeu._ven._sam.'.split('_'),
  32966. weekdaysMin : 'Di_Lu_Ma_Me_Je_Ve_Sa'.split('_'),
  32967. week: {dow: 1, doy: 4}
  32968. });
  32969. ver('1999 37 4', 'GGGG WW E', '1999 09 16', 'iso ignores locale');
  32970. ver('1999 37 7', 'GGGG WW E', '1999 09 19', 'iso ignores locale');
  32971. ver('1999 37 0', 'gggg ww e', '1999 09 13', 'localized e uses local doy and dow: 0 = monday');
  32972. ver('1999 37 4', 'gggg ww e', '1999 09 17', 'localized e uses local doy and dow: 4 = friday');
  32973. ver('1999 37 1', 'gggg ww d', '1999 09 13', 'localized d uses 0-indexed days: 1 = monday');
  32974. ver('1999 37 Lu', 'gggg ww dd', '1999 09 13', 'localized d uses 0-indexed days: Mo');
  32975. ver('1999 37 lun.', 'gggg ww ddd', '1999 09 13', 'localized d uses 0-indexed days: Mon');
  32976. ver('1999 37 lundi', 'gggg ww dddd', '1999 09 13', 'localized d uses 0-indexed days: Monday');
  32977. ver('1999 37 4', 'gggg ww d', '1999 09 16', 'localized d uses 0-indexed days: 4');
  32978. //sunday goes at the end of the week
  32979. ver('1999 37 0', 'gggg ww d', '1999 09 19', 'localized d uses 0-indexed days: 0 = sund');
  32980. ver('1999 37 Di', 'gggg ww dd', '1999 09 19', 'localized d uses 0-indexed days: 0 = sund');
  32981. }
  32982. finally {
  32983. moment.locale('en');
  32984. }
  32985. });
  32986. test('parsing with customized two-digit year', function (assert) {
  32987. var original = moment.parseTwoDigitYear;
  32988. try {
  32989. assert.equal(moment('68', 'YY').year(), 2068);
  32990. assert.equal(moment('69', 'YY').year(), 1969);
  32991. moment.parseTwoDigitYear = function (input) {
  32992. return +input + (+input > 30 ? 1900 : 2000);
  32993. };
  32994. assert.equal(moment('68', 'YY').year(), 1968);
  32995. assert.equal(moment('67', 'YY').year(), 1967);
  32996. assert.equal(moment('31', 'YY').year(), 1931);
  32997. assert.equal(moment('30', 'YY').year(), 2030);
  32998. }
  32999. finally {
  33000. moment.parseTwoDigitYear = original;
  33001. }
  33002. });
  33003. test('array with strings', function (assert) {
  33004. assert.equal(moment(['2014', '7', '31']).isValid(), true, 'string array + isValid');
  33005. });
  33006. test('object with strings', function (assert) {
  33007. assert.equal(moment({year: '2014', month: '7', day: '31'}).isValid(), true, 'string object + isValid');
  33008. });
  33009. test('utc with array of formats', function (assert) {
  33010. assert.equal(moment.utc('2014-01-01', ['YYYY-MM-DD', 'YYYY-MM']).format(), '2014-01-01T00:00:00+00:00', 'moment.utc works with array of formats');
  33011. });
  33012. test('parsing invalid string weekdays', function (assert) {
  33013. assert.equal(false, moment('a', 'dd').isValid(),
  33014. 'dd with invalid weekday, non-strict');
  33015. assert.equal(false, moment('a', 'dd', true).isValid(),
  33016. 'dd with invalid weekday, strict');
  33017. assert.equal(false, moment('a', 'ddd').isValid(),
  33018. 'ddd with invalid weekday, non-strict');
  33019. assert.equal(false, moment('a', 'ddd', true).isValid(),
  33020. 'ddd with invalid weekday, strict');
  33021. assert.equal(false, moment('a', 'dddd').isValid(),
  33022. 'dddd with invalid weekday, non-strict');
  33023. assert.equal(false, moment('a', 'dddd', true).isValid(),
  33024. 'dddd with invalid weekday, strict');
  33025. });
  33026. test('milliseconds', function (assert) {
  33027. assert.equal(moment('1', 'S').millisecond(), 100);
  33028. assert.equal(moment('12', 'SS').millisecond(), 120);
  33029. assert.equal(moment('123', 'SSS').millisecond(), 123);
  33030. assert.equal(moment('1234', 'SSSS').millisecond(), 123);
  33031. assert.equal(moment('12345', 'SSSSS').millisecond(), 123);
  33032. assert.equal(moment('123456', 'SSSSSS').millisecond(), 123);
  33033. assert.equal(moment('1234567', 'SSSSSSS').millisecond(), 123);
  33034. assert.equal(moment('12345678', 'SSSSSSSS').millisecond(), 123);
  33035. assert.equal(moment('123456789', 'SSSSSSSSS').millisecond(), 123);
  33036. });
  33037. test('hmm', function (assert) {
  33038. assert.equal(moment('123', 'hmm', true).format('HH:mm:ss'), '01:23:00', '123 with hmm');
  33039. assert.equal(moment('123a', 'hmmA', true).format('HH:mm:ss'), '01:23:00', '123a with hmmA');
  33040. assert.equal(moment('123p', 'hmmA', true).format('HH:mm:ss'), '13:23:00', '123p with hmmA');
  33041. assert.equal(moment('1234', 'hmm', true).format('HH:mm:ss'), '12:34:00', '1234 with hmm');
  33042. assert.equal(moment('1234a', 'hmmA', true).format('HH:mm:ss'), '00:34:00', '1234a with hmmA');
  33043. assert.equal(moment('1234p', 'hmmA', true).format('HH:mm:ss'), '12:34:00', '1234p with hmmA');
  33044. assert.equal(moment('12345', 'hmmss', true).format('HH:mm:ss'), '01:23:45', '12345 with hmmss');
  33045. assert.equal(moment('12345a', 'hmmssA', true).format('HH:mm:ss'), '01:23:45', '12345a with hmmssA');
  33046. assert.equal(moment('12345p', 'hmmssA', true).format('HH:mm:ss'), '13:23:45', '12345p with hmmssA');
  33047. assert.equal(moment('112345', 'hmmss', true).format('HH:mm:ss'), '11:23:45', '112345 with hmmss');
  33048. assert.equal(moment('112345a', 'hmmssA', true).format('HH:mm:ss'), '11:23:45', '112345a with hmmssA');
  33049. assert.equal(moment('112345p', 'hmmssA', true).format('HH:mm:ss'), '23:23:45', '112345p with hmmssA');
  33050. assert.equal(moment('023', 'Hmm', true).format('HH:mm:ss'), '00:23:00', '023 with Hmm');
  33051. assert.equal(moment('123', 'Hmm', true).format('HH:mm:ss'), '01:23:00', '123 with Hmm');
  33052. assert.equal(moment('1234', 'Hmm', true).format('HH:mm:ss'), '12:34:00', '1234 with Hmm');
  33053. assert.equal(moment('1534', 'Hmm', true).format('HH:mm:ss'), '15:34:00', '1234 with Hmm');
  33054. assert.equal(moment('12345', 'Hmmss', true).format('HH:mm:ss'), '01:23:45', '12345 with Hmmss');
  33055. assert.equal(moment('112345', 'Hmmss', true).format('HH:mm:ss'), '11:23:45', '112345 with Hmmss');
  33056. assert.equal(moment('172345', 'Hmmss', true).format('HH:mm:ss'), '17:23:45', '112345 with Hmmss');
  33057. });
  33058. test('Y token', function (assert) {
  33059. assert.equal(moment('1-1-2010', 'M-D-Y', true).year(), 2010, 'parsing Y');
  33060. });
  33061. }));
  33062. ;(function (global, factory) {
  33063. typeof exports === 'object' && typeof module !== 'undefined'
  33064. && typeof require === 'function' ? factory(require('../../moment')) :
  33065. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  33066. factory(global.moment)
  33067. }(this, function (moment) { 'use strict';
  33068. /*global QUnit:false*/
  33069. var test = QUnit.test;
  33070. var expect = QUnit.expect;
  33071. function module (name, lifecycle) {
  33072. QUnit.module(name, {
  33073. setup : function () {
  33074. moment.locale('en');
  33075. moment.createFromInputFallback = function (config) {
  33076. throw new Error('input not handled by moment: ' + config._i);
  33077. };
  33078. if (lifecycle && lifecycle.setup) {
  33079. lifecycle.setup();
  33080. }
  33081. },
  33082. teardown : function () {
  33083. if (lifecycle && lifecycle.teardown) {
  33084. lifecycle.teardown();
  33085. }
  33086. }
  33087. });
  33088. }
  33089. function localeModule (name, lifecycle) {
  33090. QUnit.module('locale:' + name, {
  33091. setup : function () {
  33092. moment.locale(name);
  33093. moment.createFromInputFallback = function (config) {
  33094. throw new Error('input not handled by moment: ' + config._i);
  33095. };
  33096. if (lifecycle && lifecycle.setup) {
  33097. lifecycle.setup();
  33098. }
  33099. },
  33100. teardown : function () {
  33101. moment.locale('en');
  33102. if (lifecycle && lifecycle.teardown) {
  33103. lifecycle.teardown();
  33104. }
  33105. }
  33106. });
  33107. }
  33108. module('creation data');
  33109. test('valid date', function (assert) {
  33110. var dat = moment('1992-10-22');
  33111. var orig = dat.creationData();
  33112. assert.equal(dat.isValid(), true, '1992-10-22 is valid');
  33113. assert.equal(orig.input, '1992-10-22', 'original input is not correct.');
  33114. assert.equal(orig.format, 'YYYY-MM-DD', 'original format is defined.');
  33115. assert.equal(orig.locale._abbr, 'en', 'default locale is en');
  33116. assert.equal(orig.isUTC, false, 'not a UTC date');
  33117. });
  33118. test('valid date at fr locale', function (assert) {
  33119. var dat = moment('1992-10-22', 'YYYY-MM-DD', 'fr');
  33120. var orig = dat.creationData();
  33121. assert.equal(orig.locale._abbr, 'fr', 'locale is fr');
  33122. });
  33123. test('valid date with formats', function (assert) {
  33124. var dat = moment('29-06-1995', ['MM-DD-YYYY', 'DD-MM', 'DD-MM-YYYY']);
  33125. var orig = dat.creationData();
  33126. assert.equal(orig.format, 'DD-MM-YYYY', 'DD-MM-YYYY format is defined.');
  33127. });
  33128. test('strict', function (assert) {
  33129. assert.ok(moment('2015-01-02', 'YYYY-MM-DD', true).creationData().strict, 'strict is true');
  33130. assert.ok(!moment('2015-01-02', 'YYYY-MM-DD').creationData().strict, 'strict is true');
  33131. });
  33132. }));
  33133. ;(function (global, factory) {
  33134. typeof exports === 'object' && typeof module !== 'undefined'
  33135. && typeof require === 'function' ? factory(require('../../moment')) :
  33136. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  33137. factory(global.moment)
  33138. }(this, function (moment) { 'use strict';
  33139. /*global QUnit:false*/
  33140. var test = QUnit.test;
  33141. var expect = QUnit.expect;
  33142. function module (name, lifecycle) {
  33143. QUnit.module(name, {
  33144. setup : function () {
  33145. moment.locale('en');
  33146. moment.createFromInputFallback = function (config) {
  33147. throw new Error('input not handled by moment: ' + config._i);
  33148. };
  33149. if (lifecycle && lifecycle.setup) {
  33150. lifecycle.setup();
  33151. }
  33152. },
  33153. teardown : function () {
  33154. if (lifecycle && lifecycle.teardown) {
  33155. lifecycle.teardown();
  33156. }
  33157. }
  33158. });
  33159. }
  33160. function localeModule (name, lifecycle) {
  33161. QUnit.module('locale:' + name, {
  33162. setup : function () {
  33163. moment.locale(name);
  33164. moment.createFromInputFallback = function (config) {
  33165. throw new Error('input not handled by moment: ' + config._i);
  33166. };
  33167. if (lifecycle && lifecycle.setup) {
  33168. lifecycle.setup();
  33169. }
  33170. },
  33171. teardown : function () {
  33172. moment.locale('en');
  33173. if (lifecycle && lifecycle.teardown) {
  33174. lifecycle.teardown();
  33175. }
  33176. }
  33177. });
  33178. }
  33179. function each(array, callback) {
  33180. var i;
  33181. for (i = 0; i < array.length; i++) {
  33182. callback(array[i], i, array);
  33183. }
  33184. }
  33185. module('days in month');
  33186. test('days in month', function (assert) {
  33187. each([31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], function (days, i) {
  33188. var firstDay = moment([2012, i]),
  33189. lastDay = moment([2012, i, days]);
  33190. assert.equal(firstDay.daysInMonth(), days, firstDay.format('L') + ' should have ' + days + ' days.');
  33191. assert.equal(lastDay.daysInMonth(), days, lastDay.format('L') + ' should have ' + days + ' days.');
  33192. });
  33193. });
  33194. test('days in month leap years', function (assert) {
  33195. assert.equal(moment([2010, 1]).daysInMonth(), 28, 'Feb 2010 should have 28 days');
  33196. assert.equal(moment([2100, 1]).daysInMonth(), 28, 'Feb 2100 should have 28 days');
  33197. assert.equal(moment([2008, 1]).daysInMonth(), 29, 'Feb 2008 should have 29 days');
  33198. assert.equal(moment([2000, 1]).daysInMonth(), 29, 'Feb 2000 should have 29 days');
  33199. });
  33200. }));
  33201. ;(function (global, factory) {
  33202. typeof exports === 'object' && typeof module !== 'undefined'
  33203. && typeof require === 'function' ? factory(require('../../moment')) :
  33204. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  33205. factory(global.moment)
  33206. }(this, function (moment) { 'use strict';
  33207. /*global QUnit:false*/
  33208. var test = QUnit.test;
  33209. var expect = QUnit.expect;
  33210. function module (name, lifecycle) {
  33211. QUnit.module(name, {
  33212. setup : function () {
  33213. moment.locale('en');
  33214. moment.createFromInputFallback = function (config) {
  33215. throw new Error('input not handled by moment: ' + config._i);
  33216. };
  33217. if (lifecycle && lifecycle.setup) {
  33218. lifecycle.setup();
  33219. }
  33220. },
  33221. teardown : function () {
  33222. if (lifecycle && lifecycle.teardown) {
  33223. lifecycle.teardown();
  33224. }
  33225. }
  33226. });
  33227. }
  33228. function localeModule (name, lifecycle) {
  33229. QUnit.module('locale:' + name, {
  33230. setup : function () {
  33231. moment.locale(name);
  33232. moment.createFromInputFallback = function (config) {
  33233. throw new Error('input not handled by moment: ' + config._i);
  33234. };
  33235. if (lifecycle && lifecycle.setup) {
  33236. lifecycle.setup();
  33237. }
  33238. },
  33239. teardown : function () {
  33240. moment.locale('en');
  33241. if (lifecycle && lifecycle.teardown) {
  33242. lifecycle.teardown();
  33243. }
  33244. }
  33245. });
  33246. }
  33247. function hasOwnProp(a, b) {
  33248. return Object.prototype.hasOwnProperty.call(a, b);
  33249. }
  33250. function extend(a, b) {
  33251. for (var i in b) {
  33252. if (hasOwnProp(b, i)) {
  33253. a[i] = b[i];
  33254. }
  33255. }
  33256. if (hasOwnProp(b, 'toString')) {
  33257. a.toString = b.toString;
  33258. }
  33259. if (hasOwnProp(b, 'valueOf')) {
  33260. a.valueOf = b.valueOf;
  33261. }
  33262. return a;
  33263. }
  33264. var hookCallback;
  33265. function hooks () {
  33266. return hookCallback.apply(null, arguments);
  33267. }
  33268. // This is done to register the method called with moment()
  33269. // without creating circular dependencies.
  33270. function setHookCallback (callback) {
  33271. hookCallback = callback;
  33272. }
  33273. function isUndefined(input) {
  33274. return input === void 0;
  33275. }
  33276. function warn(msg) {
  33277. if (hooks.suppressDeprecationWarnings === false &&
  33278. (typeof console !== 'undefined') && console.warn) {
  33279. console.warn('Deprecation warning: ' + msg);
  33280. }
  33281. }
  33282. function deprecate(msg, fn) {
  33283. var firstTime = true;
  33284. return extend(function () {
  33285. if (firstTime) {
  33286. warn(msg + '\nArguments: ' + Array.prototype.slice.call(arguments).join(', ') + '\n' + (new Error()).stack);
  33287. firstTime = false;
  33288. }
  33289. return fn.apply(this, arguments);
  33290. }, fn);
  33291. }
  33292. var deprecations = {};
  33293. function deprecateSimple(name, msg) {
  33294. if (!deprecations[name]) {
  33295. warn(msg);
  33296. deprecations[name] = true;
  33297. }
  33298. }
  33299. hooks.suppressDeprecationWarnings = false;
  33300. module('deprecate');
  33301. test('deprecate', function (assert) {
  33302. var fn = function () {};
  33303. var deprecatedFn = deprecate('testing deprecation', fn);
  33304. deprecatedFn();
  33305. expect(0);
  33306. });
  33307. }));
  33308. ;(function (global, factory) {
  33309. typeof exports === 'object' && typeof module !== 'undefined'
  33310. && typeof require === 'function' ? factory(require('../../moment')) :
  33311. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  33312. factory(global.moment)
  33313. }(this, function (moment) { 'use strict';
  33314. /*global QUnit:false*/
  33315. var test = QUnit.test;
  33316. var expect = QUnit.expect;
  33317. function module (name, lifecycle) {
  33318. QUnit.module(name, {
  33319. setup : function () {
  33320. moment.locale('en');
  33321. moment.createFromInputFallback = function (config) {
  33322. throw new Error('input not handled by moment: ' + config._i);
  33323. };
  33324. if (lifecycle && lifecycle.setup) {
  33325. lifecycle.setup();
  33326. }
  33327. },
  33328. teardown : function () {
  33329. if (lifecycle && lifecycle.teardown) {
  33330. lifecycle.teardown();
  33331. }
  33332. }
  33333. });
  33334. }
  33335. function localeModule (name, lifecycle) {
  33336. QUnit.module('locale:' + name, {
  33337. setup : function () {
  33338. moment.locale(name);
  33339. moment.createFromInputFallback = function (config) {
  33340. throw new Error('input not handled by moment: ' + config._i);
  33341. };
  33342. if (lifecycle && lifecycle.setup) {
  33343. lifecycle.setup();
  33344. }
  33345. },
  33346. teardown : function () {
  33347. moment.locale('en');
  33348. if (lifecycle && lifecycle.teardown) {
  33349. lifecycle.teardown();
  33350. }
  33351. }
  33352. });
  33353. }
  33354. function equal(assert, a, b, message) {
  33355. assert.ok(Math.abs(a - b) < 0.00000001, '(' + a + ' === ' + b + ') ' + message);
  33356. }
  33357. function dstForYear(year) {
  33358. var start = moment([year]),
  33359. end = moment([year + 1]),
  33360. current = start.clone(),
  33361. last;
  33362. while (current < end) {
  33363. last = current.clone();
  33364. current.add(24, 'hour');
  33365. if (last.utcOffset() !== current.utcOffset()) {
  33366. end = current.clone();
  33367. current = last.clone();
  33368. break;
  33369. }
  33370. }
  33371. while (current < end) {
  33372. last = current.clone();
  33373. current.add(1, 'hour');
  33374. if (last.utcOffset() !== current.utcOffset()) {
  33375. return {
  33376. moment : last,
  33377. diff : -(current.utcOffset() - last.utcOffset()) / 60
  33378. };
  33379. }
  33380. }
  33381. }
  33382. module('diff');
  33383. test('diff', function (assert) {
  33384. assert.equal(moment(1000).diff(0), 1000, '1 second - 0 = 1000');
  33385. assert.equal(moment(1000).diff(500), 500, '1 second - 0.5 seconds = 500');
  33386. assert.equal(moment(0).diff(1000), -1000, '0 - 1 second = -1000');
  33387. assert.equal(moment(new Date(1000)).diff(1000), 0, '1 second - 1 second = 0');
  33388. var oneHourDate = new Date(2015, 5, 21),
  33389. nowDate = new Date(+oneHourDate);
  33390. oneHourDate.setHours(oneHourDate.getHours() + 1);
  33391. assert.equal(moment(oneHourDate).diff(nowDate), 60 * 60 * 1000, '1 hour from now = 3600000');
  33392. });
  33393. test('diff key after', function (assert) {
  33394. assert.equal(moment([2010]).diff([2011], 'years'), -1, 'year diff');
  33395. assert.equal(moment([2010]).diff([2010, 2], 'months'), -2, 'month diff');
  33396. assert.equal(moment([2010]).diff([2010, 0, 7], 'weeks'), 0, 'week diff');
  33397. assert.equal(moment([2010]).diff([2010, 0, 8], 'weeks'), -1, 'week diff');
  33398. assert.equal(moment([2010]).diff([2010, 0, 21], 'weeks'), -2, 'week diff');
  33399. assert.equal(moment([2010]).diff([2010, 0, 22], 'weeks'), -3, 'week diff');
  33400. assert.equal(moment([2010]).diff([2010, 0, 4], 'days'), -3, 'day diff');
  33401. assert.equal(moment([2010]).diff([2010, 0, 1, 4], 'hours'), -4, 'hour diff');
  33402. assert.equal(moment([2010]).diff([2010, 0, 1, 0, 5], 'minutes'), -5, 'minute diff');
  33403. assert.equal(moment([2010]).diff([2010, 0, 1, 0, 0, 6], 'seconds'), -6, 'second diff');
  33404. });
  33405. test('diff key before', function (assert) {
  33406. assert.equal(moment([2011]).diff([2010], 'years'), 1, 'year diff');
  33407. assert.equal(moment([2010, 2]).diff([2010], 'months'), 2, 'month diff');
  33408. assert.equal(moment([2010, 0, 4]).diff([2010], 'days'), 3, 'day diff');
  33409. assert.equal(moment([2010, 0, 7]).diff([2010], 'weeks'), 0, 'week diff');
  33410. assert.equal(moment([2010, 0, 8]).diff([2010], 'weeks'), 1, 'week diff');
  33411. assert.equal(moment([2010, 0, 21]).diff([2010], 'weeks'), 2, 'week diff');
  33412. assert.equal(moment([2010, 0, 22]).diff([2010], 'weeks'), 3, 'week diff');
  33413. assert.equal(moment([2010, 0, 1, 4]).diff([2010], 'hours'), 4, 'hour diff');
  33414. assert.equal(moment([2010, 0, 1, 0, 5]).diff([2010], 'minutes'), 5, 'minute diff');
  33415. assert.equal(moment([2010, 0, 1, 0, 0, 6]).diff([2010], 'seconds'), 6, 'second diff');
  33416. });
  33417. test('diff key before singular', function (assert) {
  33418. assert.equal(moment([2011]).diff([2010], 'year'), 1, 'year diff singular');
  33419. assert.equal(moment([2010, 2]).diff([2010], 'month'), 2, 'month diff singular');
  33420. assert.equal(moment([2010, 0, 4]).diff([2010], 'day'), 3, 'day diff singular');
  33421. assert.equal(moment([2010, 0, 7]).diff([2010], 'week'), 0, 'week diff singular');
  33422. assert.equal(moment([2010, 0, 8]).diff([2010], 'week'), 1, 'week diff singular');
  33423. assert.equal(moment([2010, 0, 21]).diff([2010], 'week'), 2, 'week diff singular');
  33424. assert.equal(moment([2010, 0, 22]).diff([2010], 'week'), 3, 'week diff singular');
  33425. assert.equal(moment([2010, 0, 1, 4]).diff([2010], 'hour'), 4, 'hour diff singular');
  33426. assert.equal(moment([2010, 0, 1, 0, 5]).diff([2010], 'minute'), 5, 'minute diff singular');
  33427. assert.equal(moment([2010, 0, 1, 0, 0, 6]).diff([2010], 'second'), 6, 'second diff singular');
  33428. });
  33429. test('diff key before abbreviated', function (assert) {
  33430. assert.equal(moment([2011]).diff([2010], 'y'), 1, 'year diff abbreviated');
  33431. assert.equal(moment([2010, 2]).diff([2010], 'M'), 2, 'month diff abbreviated');
  33432. assert.equal(moment([2010, 0, 4]).diff([2010], 'd'), 3, 'day diff abbreviated');
  33433. assert.equal(moment([2010, 0, 7]).diff([2010], 'w'), 0, 'week diff abbreviated');
  33434. assert.equal(moment([2010, 0, 8]).diff([2010], 'w'), 1, 'week diff abbreviated');
  33435. assert.equal(moment([2010, 0, 21]).diff([2010], 'w'), 2, 'week diff abbreviated');
  33436. assert.equal(moment([2010, 0, 22]).diff([2010], 'w'), 3, 'week diff abbreviated');
  33437. assert.equal(moment([2010, 0, 1, 4]).diff([2010], 'h'), 4, 'hour diff abbreviated');
  33438. assert.equal(moment([2010, 0, 1, 0, 5]).diff([2010], 'm'), 5, 'minute diff abbreviated');
  33439. assert.equal(moment([2010, 0, 1, 0, 0, 6]).diff([2010], 's'), 6, 'second diff abbreviated');
  33440. });
  33441. test('diff month', function (assert) {
  33442. assert.equal(moment([2011, 0, 31]).diff([2011, 2, 1], 'months'), -1, 'month diff');
  33443. });
  33444. test('diff across DST', function (assert) {
  33445. var dst = dstForYear(2012), a, b, daysInMonth;
  33446. if (!dst) {
  33447. assert.equal(42, 42, 'at least one assertion');
  33448. return;
  33449. }
  33450. a = dst.moment;
  33451. b = a.clone().utc().add(12, 'hours').local();
  33452. daysInMonth = (a.daysInMonth() + b.daysInMonth()) / 2;
  33453. assert.equal(b.diff(a, 'milliseconds', true), 12 * 60 * 60 * 1000,
  33454. 'ms diff across DST');
  33455. assert.equal(b.diff(a, 'seconds', true), 12 * 60 * 60,
  33456. 'second diff across DST');
  33457. assert.equal(b.diff(a, 'minutes', true), 12 * 60,
  33458. 'minute diff across DST');
  33459. assert.equal(b.diff(a, 'hours', true), 12,
  33460. 'hour diff across DST');
  33461. assert.equal(b.diff(a, 'days', true), (12 - dst.diff) / 24,
  33462. 'day diff across DST');
  33463. equal(assert, b.diff(a, 'weeks', true), (12 - dst.diff) / 24 / 7,
  33464. 'week diff across DST');
  33465. assert.ok(0.95 / (2 * 31) < b.diff(a, 'months', true),
  33466. 'month diff across DST, lower bound');
  33467. assert.ok(b.diff(a, 'month', true) < 1.05 / (2 * 28),
  33468. 'month diff across DST, upper bound');
  33469. assert.ok(0.95 / (2 * 31 * 12) < b.diff(a, 'years', true),
  33470. 'year diff across DST, lower bound');
  33471. assert.ok(b.diff(a, 'year', true) < 1.05 / (2 * 28 * 12),
  33472. 'year diff across DST, upper bound');
  33473. a = dst.moment;
  33474. b = a.clone().utc().add(12 + dst.diff, 'hours').local();
  33475. daysInMonth = (a.daysInMonth() + b.daysInMonth()) / 2;
  33476. assert.equal(b.diff(a, 'milliseconds', true),
  33477. (12 + dst.diff) * 60 * 60 * 1000,
  33478. 'ms diff across DST');
  33479. assert.equal(b.diff(a, 'seconds', true), (12 + dst.diff) * 60 * 60,
  33480. 'second diff across DST');
  33481. assert.equal(b.diff(a, 'minutes', true), (12 + dst.diff) * 60,
  33482. 'minute diff across DST');
  33483. assert.equal(b.diff(a, 'hours', true), (12 + dst.diff),
  33484. 'hour diff across DST');
  33485. assert.equal(b.diff(a, 'days', true), 12 / 24, 'day diff across DST');
  33486. equal(assert, b.diff(a, 'weeks', true), 12 / 24 / 7,
  33487. 'week diff across DST');
  33488. assert.ok(0.95 / (2 * 31) < b.diff(a, 'months', true),
  33489. 'month diff across DST, lower bound');
  33490. assert.ok(b.diff(a, 'month', true) < 1.05 / (2 * 28),
  33491. 'month diff across DST, upper bound');
  33492. assert.ok(0.95 / (2 * 31 * 12) < b.diff(a, 'years', true),
  33493. 'year diff across DST, lower bound');
  33494. assert.ok(b.diff(a, 'year', true) < 1.05 / (2 * 28 * 12),
  33495. 'year diff across DST, upper bound');
  33496. });
  33497. test('diff overflow', function (assert) {
  33498. assert.equal(moment([2011]).diff([2010], 'months'), 12, 'month diff');
  33499. assert.equal(moment([2010, 0, 2]).diff([2010], 'hours'), 24, 'hour diff');
  33500. assert.equal(moment([2010, 0, 1, 2]).diff([2010], 'minutes'), 120, 'minute diff');
  33501. assert.equal(moment([2010, 0, 1, 0, 4]).diff([2010], 'seconds'), 240, 'second diff');
  33502. });
  33503. test('diff between utc and local', function (assert) {
  33504. if (moment([2012]).utcOffset() === moment([2011]).utcOffset()) {
  33505. // Russia's utc offset on 1st of Jan 2012 vs 2011 is different
  33506. assert.equal(moment([2012]).utc().diff([2011], 'years'), 1, 'year diff');
  33507. }
  33508. assert.equal(moment([2010, 2, 2]).utc().diff([2010, 0, 2], 'months'), 2, 'month diff');
  33509. assert.equal(moment([2010, 0, 4]).utc().diff([2010], 'days'), 3, 'day diff');
  33510. assert.equal(moment([2010, 0, 22]).utc().diff([2010], 'weeks'), 3, 'week diff');
  33511. assert.equal(moment([2010, 0, 1, 4]).utc().diff([2010], 'hours'), 4, 'hour diff');
  33512. assert.equal(moment([2010, 0, 1, 0, 5]).utc().diff([2010], 'minutes'), 5, 'minute diff');
  33513. assert.equal(moment([2010, 0, 1, 0, 0, 6]).utc().diff([2010], 'seconds'), 6, 'second diff');
  33514. });
  33515. test('diff floored', function (assert) {
  33516. assert.equal(moment([2010, 0, 1, 23]).diff([2010], 'day'), 0, '23 hours = 0 days');
  33517. assert.equal(moment([2010, 0, 1, 23, 59]).diff([2010], 'day'), 0, '23:59 hours = 0 days');
  33518. assert.equal(moment([2010, 0, 1, 24]).diff([2010], 'day'), 1, '24 hours = 1 day');
  33519. assert.equal(moment([2010, 0, 2]).diff([2011, 0, 1], 'year'), 0, 'year rounded down');
  33520. assert.equal(moment([2011, 0, 1]).diff([2010, 0, 2], 'year'), 0, 'year rounded down');
  33521. assert.equal(moment([2010, 0, 2]).diff([2011, 0, 2], 'year'), -1, 'year rounded down');
  33522. assert.equal(moment([2011, 0, 2]).diff([2010, 0, 2], 'year'), 1, 'year rounded down');
  33523. });
  33524. test('year diffs include dates', function (assert) {
  33525. assert.ok(moment([2012, 1, 19]).diff(moment([2002, 1, 20]), 'years', true) < 10, 'year diff should include date of month');
  33526. });
  33527. test('month diffs', function (assert) {
  33528. // due to floating point math errors, these tests just need to be accurate within 0.00000001
  33529. assert.equal(moment([2012, 0, 1]).diff([2012, 1, 1], 'months', true), -1, 'Jan 1 to Feb 1 should be 1 month');
  33530. equal(assert, moment([2012, 0, 1]).diff([2012, 0, 1, 12], 'months', true), -0.5 / 31, 'Jan 1 to Jan 1 noon should be 0.5 / 31 months');
  33531. assert.equal(moment([2012, 0, 15]).diff([2012, 1, 15], 'months', true), -1, 'Jan 15 to Feb 15 should be 1 month');
  33532. assert.equal(moment([2012, 0, 28]).diff([2012, 1, 28], 'months', true), -1, 'Jan 28 to Feb 28 should be 1 month');
  33533. assert.ok(moment([2012, 0, 31]).diff([2012, 1, 29], 'months', true), -1, 'Jan 31 to Feb 29 should be 1 month');
  33534. assert.ok(-1 > moment([2012, 0, 31]).diff([2012, 2, 1], 'months', true), 'Jan 31 to Mar 1 should be more than 1 month');
  33535. assert.ok(-30 / 28 < moment([2012, 0, 31]).diff([2012, 2, 1], 'months', true), 'Jan 31 to Mar 1 should be less than 1 month and 1 day');
  33536. equal(assert, moment([2012, 0, 1]).diff([2012, 0, 31], 'months', true), -(30 / 31), 'Jan 1 to Jan 31 should be 30 / 31 months');
  33537. assert.ok(0 < moment('2014-02-01').diff(moment('2014-01-31'), 'months', true), 'jan-31 to feb-1 diff is positive');
  33538. });
  33539. test('exact month diffs', function (assert) {
  33540. // generate all pairs of months and compute month diff, with fixed day
  33541. // of month = 15.
  33542. var m1, m2;
  33543. for (m1 = 0; m1 < 12; ++m1) {
  33544. for (m2 = m1; m2 < 12; ++m2) {
  33545. assert.equal(moment([2013, m2, 15]).diff(moment([2013, m1, 15]), 'months', true), m2 - m1,
  33546. 'month diff from 2013-' + m1 + '-15 to 2013-' + m2 + '-15');
  33547. }
  33548. }
  33549. });
  33550. test('year diffs', function (assert) {
  33551. // due to floating point math errors, these tests just need to be accurate within 0.00000001
  33552. equal(assert, moment([2012, 0, 1]).diff([2013, 0, 1], 'years', true), -1, 'Jan 1 2012 to Jan 1 2013 should be 1 year');
  33553. equal(assert, moment([2012, 1, 28]).diff([2013, 1, 28], 'years', true), -1, 'Feb 28 2012 to Feb 28 2013 should be 1 year');
  33554. equal(assert, moment([2012, 2, 1]).diff([2013, 2, 1], 'years', true), -1, 'Mar 1 2012 to Mar 1 2013 should be 1 year');
  33555. equal(assert, moment([2012, 11, 1]).diff([2013, 11, 1], 'years', true), -1, 'Dec 1 2012 to Dec 1 2013 should be 1 year');
  33556. equal(assert, moment([2012, 11, 31]).diff([2013, 11, 31], 'years', true), -1, 'Dec 31 2012 to Dec 31 2013 should be 1 year');
  33557. equal(assert, moment([2012, 0, 1]).diff([2013, 6, 1], 'years', true), -1.5, 'Jan 1 2012 to Jul 1 2013 should be 1.5 years');
  33558. equal(assert, moment([2012, 0, 31]).diff([2013, 6, 31], 'years', true), -1.5, 'Jan 31 2012 to Jul 31 2013 should be 1.5 years');
  33559. equal(assert, moment([2012, 0, 1]).diff([2013, 0, 1, 12], 'years', true), -1 - (0.5 / 31) / 12, 'Jan 1 2012 to Jan 1 2013 noon should be 1+(0.5 / 31) / 12 years');
  33560. equal(assert, moment([2012, 0, 1]).diff([2013, 6, 1, 12], 'years', true), -1.5 - (0.5 / 31) / 12, 'Jan 1 2012 to Jul 1 2013 noon should be 1.5+(0.5 / 31) / 12 years');
  33561. equal(assert, moment([2012, 1, 29]).diff([2013, 1, 28], 'years', true), -1, 'Feb 29 2012 to Feb 28 2013 should be 1-(1 / 28.5) / 12 years');
  33562. });
  33563. }));
  33564. ;(function (global, factory) {
  33565. typeof exports === 'object' && typeof module !== 'undefined'
  33566. && typeof require === 'function' ? factory(require('../../moment')) :
  33567. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  33568. factory(global.moment)
  33569. }(this, function (moment) { 'use strict';
  33570. /*global QUnit:false*/
  33571. var test = QUnit.test;
  33572. var expect = QUnit.expect;
  33573. function module (name, lifecycle) {
  33574. QUnit.module(name, {
  33575. setup : function () {
  33576. moment.locale('en');
  33577. moment.createFromInputFallback = function (config) {
  33578. throw new Error('input not handled by moment: ' + config._i);
  33579. };
  33580. if (lifecycle && lifecycle.setup) {
  33581. lifecycle.setup();
  33582. }
  33583. },
  33584. teardown : function () {
  33585. if (lifecycle && lifecycle.teardown) {
  33586. lifecycle.teardown();
  33587. }
  33588. }
  33589. });
  33590. }
  33591. function localeModule (name, lifecycle) {
  33592. QUnit.module('locale:' + name, {
  33593. setup : function () {
  33594. moment.locale(name);
  33595. moment.createFromInputFallback = function (config) {
  33596. throw new Error('input not handled by moment: ' + config._i);
  33597. };
  33598. if (lifecycle && lifecycle.setup) {
  33599. lifecycle.setup();
  33600. }
  33601. },
  33602. teardown : function () {
  33603. moment.locale('en');
  33604. if (lifecycle && lifecycle.teardown) {
  33605. lifecycle.teardown();
  33606. }
  33607. }
  33608. });
  33609. }
  33610. module('duration');
  33611. test('object instantiation', function (assert) {
  33612. var d = moment.duration({
  33613. years: 2,
  33614. months: 3,
  33615. weeks: 2,
  33616. days: 1,
  33617. hours: 8,
  33618. minutes: 9,
  33619. seconds: 20,
  33620. milliseconds: 12
  33621. });
  33622. assert.equal(d.years(), 2, 'years');
  33623. assert.equal(d.months(), 3, 'months');
  33624. assert.equal(d.weeks(), 2, 'weeks');
  33625. assert.equal(d.days(), 15, 'days'); // two weeks + 1 day
  33626. assert.equal(d.hours(), 8, 'hours');
  33627. assert.equal(d.minutes(), 9, 'minutes');
  33628. assert.equal(d.seconds(), 20, 'seconds');
  33629. assert.equal(d.milliseconds(), 12, 'milliseconds');
  33630. });
  33631. test('object instantiation with strings', function (assert) {
  33632. var d = moment.duration({
  33633. years: '2',
  33634. months: '3',
  33635. weeks: '2',
  33636. days: '1',
  33637. hours: '8',
  33638. minutes: '9',
  33639. seconds: '20',
  33640. milliseconds: '12'
  33641. });
  33642. assert.equal(d.years(), 2, 'years');
  33643. assert.equal(d.months(), 3, 'months');
  33644. assert.equal(d.weeks(), 2, 'weeks');
  33645. assert.equal(d.days(), 15, 'days'); // two weeks + 1 day
  33646. assert.equal(d.hours(), 8, 'hours');
  33647. assert.equal(d.minutes(), 9, 'minutes');
  33648. assert.equal(d.seconds(), 20, 'seconds');
  33649. assert.equal(d.milliseconds(), 12, 'milliseconds');
  33650. });
  33651. test('milliseconds instantiation', function (assert) {
  33652. assert.equal(moment.duration(72).milliseconds(), 72, 'milliseconds');
  33653. });
  33654. test('undefined instantiation', function (assert) {
  33655. assert.equal(moment.duration(undefined).milliseconds(), 0, 'milliseconds');
  33656. });
  33657. test('null instantiation', function (assert) {
  33658. assert.equal(moment.duration(null).milliseconds(), 0, 'milliseconds');
  33659. });
  33660. test('instantiation by type', function (assert) {
  33661. assert.equal(moment.duration(1, 'years').years(), 1, 'years');
  33662. assert.equal(moment.duration(1, 'y').years(), 1, 'y');
  33663. assert.equal(moment.duration(2, 'months').months(), 2, 'months');
  33664. assert.equal(moment.duration(2, 'M').months(), 2, 'M');
  33665. assert.equal(moment.duration(3, 'weeks').weeks(), 3, 'weeks');
  33666. assert.equal(moment.duration(3, 'w').weeks(), 3, 'weeks');
  33667. assert.equal(moment.duration(4, 'days').days(), 4, 'days');
  33668. assert.equal(moment.duration(4, 'd').days(), 4, 'd');
  33669. assert.equal(moment.duration(5, 'hours').hours(), 5, 'hours');
  33670. assert.equal(moment.duration(5, 'h').hours(), 5, 'h');
  33671. assert.equal(moment.duration(6, 'minutes').minutes(), 6, 'minutes');
  33672. assert.equal(moment.duration(6, 'm').minutes(), 6, 'm');
  33673. assert.equal(moment.duration(7, 'seconds').seconds(), 7, 'seconds');
  33674. assert.equal(moment.duration(7, 's').seconds(), 7, 's');
  33675. assert.equal(moment.duration(8, 'milliseconds').milliseconds(), 8, 'milliseconds');
  33676. assert.equal(moment.duration(8, 'ms').milliseconds(), 8, 'ms');
  33677. });
  33678. test('shortcuts', function (assert) {
  33679. assert.equal(moment.duration({y: 1}).years(), 1, 'years = y');
  33680. assert.equal(moment.duration({M: 2}).months(), 2, 'months = M');
  33681. assert.equal(moment.duration({w: 3}).weeks(), 3, 'weeks = w');
  33682. assert.equal(moment.duration({d: 4}).days(), 4, 'days = d');
  33683. assert.equal(moment.duration({h: 5}).hours(), 5, 'hours = h');
  33684. assert.equal(moment.duration({m: 6}).minutes(), 6, 'minutes = m');
  33685. assert.equal(moment.duration({s: 7}).seconds(), 7, 'seconds = s');
  33686. assert.equal(moment.duration({ms: 8}).milliseconds(), 8, 'milliseconds = ms');
  33687. });
  33688. test('generic getter', function (assert) {
  33689. assert.equal(moment.duration(1, 'years').get('years'), 1, 'years');
  33690. assert.equal(moment.duration(1, 'years').get('year'), 1, 'years = year');
  33691. assert.equal(moment.duration(1, 'years').get('y'), 1, 'years = y');
  33692. assert.equal(moment.duration(2, 'months').get('months'), 2, 'months');
  33693. assert.equal(moment.duration(2, 'months').get('month'), 2, 'months = month');
  33694. assert.equal(moment.duration(2, 'months').get('M'), 2, 'months = M');
  33695. assert.equal(moment.duration(3, 'weeks').get('weeks'), 3, 'weeks');
  33696. assert.equal(moment.duration(3, 'weeks').get('week'), 3, 'weeks = week');
  33697. assert.equal(moment.duration(3, 'weeks').get('w'), 3, 'weeks = w');
  33698. assert.equal(moment.duration(4, 'days').get('days'), 4, 'days');
  33699. assert.equal(moment.duration(4, 'days').get('day'), 4, 'days = day');
  33700. assert.equal(moment.duration(4, 'days').get('d'), 4, 'days = d');
  33701. assert.equal(moment.duration(5, 'hours').get('hours'), 5, 'hours');
  33702. assert.equal(moment.duration(5, 'hours').get('hour'), 5, 'hours = hour');
  33703. assert.equal(moment.duration(5, 'hours').get('h'), 5, 'hours = h');
  33704. assert.equal(moment.duration(6, 'minutes').get('minutes'), 6, 'minutes');
  33705. assert.equal(moment.duration(6, 'minutes').get('minute'), 6, 'minutes = minute');
  33706. assert.equal(moment.duration(6, 'minutes').get('m'), 6, 'minutes = m');
  33707. assert.equal(moment.duration(7, 'seconds').get('seconds'), 7, 'seconds');
  33708. assert.equal(moment.duration(7, 'seconds').get('second'), 7, 'seconds = second');
  33709. assert.equal(moment.duration(7, 'seconds').get('s'), 7, 'seconds = s');
  33710. assert.equal(moment.duration(8, 'milliseconds').get('milliseconds'), 8, 'milliseconds');
  33711. assert.equal(moment.duration(8, 'milliseconds').get('millisecond'), 8, 'milliseconds = millisecond');
  33712. assert.equal(moment.duration(8, 'milliseconds').get('ms'), 8, 'milliseconds = ms');
  33713. });
  33714. test('instantiation from another duration', function (assert) {
  33715. var simple = moment.duration(1234),
  33716. lengthy = moment.duration(60 * 60 * 24 * 360 * 1e3),
  33717. complicated = moment.duration({
  33718. years: 2,
  33719. months: 3,
  33720. weeks: 4,
  33721. days: 1,
  33722. hours: 8,
  33723. minutes: 9,
  33724. seconds: 20,
  33725. milliseconds: 12
  33726. }),
  33727. modified = moment.duration(1, 'day').add(moment.duration(1, 'day'));
  33728. assert.deepEqual(moment.duration(simple), simple, 'simple clones are equal');
  33729. assert.deepEqual(moment.duration(lengthy), lengthy, 'lengthy clones are equal');
  33730. assert.deepEqual(moment.duration(complicated), complicated, 'complicated clones are equal');
  33731. assert.deepEqual(moment.duration(modified), modified, 'cloning modified duration works');
  33732. });
  33733. test('instantiation from 24-hour time zero', function (assert) {
  33734. assert.equal(moment.duration('00:00').years(), 0, '0 years');
  33735. assert.equal(moment.duration('00:00').days(), 0, '0 days');
  33736. assert.equal(moment.duration('00:00').hours(), 0, '0 hours');
  33737. assert.equal(moment.duration('00:00').minutes(), 0, '0 minutes');
  33738. assert.equal(moment.duration('00:00').seconds(), 0, '0 seconds');
  33739. assert.equal(moment.duration('00:00').milliseconds(), 0, '0 milliseconds');
  33740. });
  33741. test('instantiation from 24-hour time <24 hours', function (assert) {
  33742. assert.equal(moment.duration('06:45').years(), 0, '0 years');
  33743. assert.equal(moment.duration('06:45').days(), 0, '0 days');
  33744. assert.equal(moment.duration('06:45').hours(), 6, '6 hours');
  33745. assert.equal(moment.duration('06:45').minutes(), 45, '45 minutes');
  33746. assert.equal(moment.duration('06:45').seconds(), 0, '0 seconds');
  33747. assert.equal(moment.duration('06:45').milliseconds(), 0, '0 milliseconds');
  33748. });
  33749. test('instantiation from 24-hour time >24 hours', function (assert) {
  33750. assert.equal(moment.duration('26:45').years(), 0, '0 years');
  33751. assert.equal(moment.duration('26:45').days(), 1, '0 days');
  33752. assert.equal(moment.duration('26:45').hours(), 2, '2 hours');
  33753. assert.equal(moment.duration('26:45').minutes(), 45, '45 minutes');
  33754. assert.equal(moment.duration('26:45').seconds(), 0, '0 seconds');
  33755. assert.equal(moment.duration('26:45').milliseconds(), 0, '0 milliseconds');
  33756. });
  33757. test('instatiation from serialized C# TimeSpan zero', function (assert) {
  33758. assert.equal(moment.duration('00:00:00').years(), 0, '0 years');
  33759. assert.equal(moment.duration('00:00:00').days(), 0, '0 days');
  33760. assert.equal(moment.duration('00:00:00').hours(), 0, '0 hours');
  33761. assert.equal(moment.duration('00:00:00').minutes(), 0, '0 minutes');
  33762. assert.equal(moment.duration('00:00:00').seconds(), 0, '0 seconds');
  33763. assert.equal(moment.duration('00:00:00').milliseconds(), 0, '0 milliseconds');
  33764. });
  33765. test('instatiation from serialized C# TimeSpan with days', function (assert) {
  33766. assert.equal(moment.duration('1.02:03:04.9999999').years(), 0, '0 years');
  33767. assert.equal(moment.duration('1.02:03:04.9999999').days(), 1, '1 day');
  33768. assert.equal(moment.duration('1.02:03:04.9999999').hours(), 2, '2 hours');
  33769. assert.equal(moment.duration('1.02:03:04.9999999').minutes(), 3, '3 minutes');
  33770. assert.equal(moment.duration('1.02:03:04.9999999').seconds(), 4, '4 seconds');
  33771. assert.equal(moment.duration('1.02:03:04.9999999').milliseconds(), 999, '999 milliseconds');
  33772. assert.equal(moment.duration('1 02:03:04.9999999').years(), 0, '0 years');
  33773. assert.equal(moment.duration('1 02:03:04.9999999').days(), 1, '1 day');
  33774. assert.equal(moment.duration('1 02:03:04.9999999').hours(), 2, '2 hours');
  33775. assert.equal(moment.duration('1 02:03:04.9999999').minutes(), 3, '3 minutes');
  33776. assert.equal(moment.duration('1 02:03:04.9999999').seconds(), 4, '4 seconds');
  33777. assert.equal(moment.duration('1 02:03:04.9999999').milliseconds(), 999, '999 milliseconds');
  33778. });
  33779. test('instatiation from serialized C# TimeSpan without days', function (assert) {
  33780. assert.equal(moment.duration('01:02:03.9999999').years(), 0, '0 years');
  33781. assert.equal(moment.duration('01:02:03.9999999').days(), 0, '0 days');
  33782. assert.equal(moment.duration('01:02:03.9999999').hours(), 1, '1 hour');
  33783. assert.equal(moment.duration('01:02:03.9999999').minutes(), 2, '2 minutes');
  33784. assert.equal(moment.duration('01:02:03.9999999').seconds(), 3, '3 seconds');
  33785. assert.equal(moment.duration('01:02:03.9999999').milliseconds(), 999, '999 milliseconds');
  33786. assert.equal(moment.duration('23:59:59.9999999').days(), 0, '0 days');
  33787. assert.equal(moment.duration('23:59:59.9999999').hours(), 23, '23 hours');
  33788. assert.equal(moment.duration('500:59:59.9999999').days(), 20, '500 hours overflows to 20 days');
  33789. assert.equal(moment.duration('500:59:59.9999999').hours(), 20, '500 hours overflows to 20 hours');
  33790. });
  33791. test('instatiation from serialized C# TimeSpan without days or milliseconds', function (assert) {
  33792. assert.equal(moment.duration('01:02:03').years(), 0, '0 years');
  33793. assert.equal(moment.duration('01:02:03').days(), 0, '0 days');
  33794. assert.equal(moment.duration('01:02:03').hours(), 1, '1 hour');
  33795. assert.equal(moment.duration('01:02:03').minutes(), 2, '2 minutes');
  33796. assert.equal(moment.duration('01:02:03').seconds(), 3, '3 seconds');
  33797. assert.equal(moment.duration('01:02:03').milliseconds(), 0, '0 milliseconds');
  33798. });
  33799. test('instatiation from serialized C# TimeSpan without milliseconds', function (assert) {
  33800. assert.equal(moment.duration('1.02:03:04').years(), 0, '0 years');
  33801. assert.equal(moment.duration('1.02:03:04').days(), 1, '1 day');
  33802. assert.equal(moment.duration('1.02:03:04').hours(), 2, '2 hours');
  33803. assert.equal(moment.duration('1.02:03:04').minutes(), 3, '3 minutes');
  33804. assert.equal(moment.duration('1.02:03:04').seconds(), 4, '4 seconds');
  33805. assert.equal(moment.duration('1.02:03:04').milliseconds(), 0, '0 milliseconds');
  33806. });
  33807. test('instatiation from serialized C# TimeSpan maxValue', function (assert) {
  33808. var d = moment.duration('10675199.02:48:05.4775807');
  33809. assert.equal(d.years(), 29227, '29227 years');
  33810. assert.equal(d.months(), 8, '8 months');
  33811. assert.equal(d.days(), 12, '12 day'); // if you have to change this value -- just do it
  33812. assert.equal(d.hours(), 2, '2 hours');
  33813. assert.equal(d.minutes(), 48, '48 minutes');
  33814. assert.equal(d.seconds(), 5, '5 seconds');
  33815. assert.equal(d.milliseconds(), 477, '477 milliseconds');
  33816. });
  33817. test('instatiation from serialized C# TimeSpan minValue', function (assert) {
  33818. var d = moment.duration('-10675199.02:48:05.4775808');
  33819. assert.equal(d.years(), -29227, '29653 years');
  33820. assert.equal(d.months(), -8, '8 day');
  33821. assert.equal(d.days(), -12, '12 day'); // if you have to change this value -- just do it
  33822. assert.equal(d.hours(), -2, '2 hours');
  33823. assert.equal(d.minutes(), -48, '48 minutes');
  33824. assert.equal(d.seconds(), -5, '5 seconds');
  33825. assert.equal(d.milliseconds(), -477, '477 milliseconds');
  33826. });
  33827. test('instantiation from ISO 8601 duration', function (assert) {
  33828. assert.equal(moment.duration('P1Y2M3DT4H5M6S').asSeconds(), moment.duration({y: 1, M: 2, d: 3, h: 4, m: 5, s: 6}).asSeconds(), 'all fields');
  33829. assert.equal(moment.duration('P1M').asSeconds(), moment.duration({M: 1}).asSeconds(), 'single month field');
  33830. assert.equal(moment.duration('PT1M').asSeconds(), moment.duration({m: 1}).asSeconds(), 'single minute field');
  33831. assert.equal(moment.duration('P1MT2H').asSeconds(), moment.duration({M: 1, h: 2}).asSeconds(), 'random fields missing');
  33832. assert.equal(moment.duration('-P60D').asSeconds(), moment.duration({d: -60}).asSeconds(), 'negative days');
  33833. assert.equal(moment.duration('PT0.5S').asSeconds(), moment.duration({s: 0.5}).asSeconds(), 'fractional seconds');
  33834. assert.equal(moment.duration('PT0,5S').asSeconds(), moment.duration({s: 0.5}).asSeconds(), 'fractional seconds (comma)');
  33835. });
  33836. test('serialization to ISO 8601 duration strings', function (assert) {
  33837. assert.equal(moment.duration({y: 1, M: 2, d: 3, h: 4, m: 5, s: 6}).toISOString(), 'P1Y2M3DT4H5M6S', 'all fields');
  33838. assert.equal(moment.duration({M: -1}).toISOString(), '-P1M', 'one month ago');
  33839. assert.equal(moment.duration({m: -1}).toISOString(), '-PT1M', 'one minute ago');
  33840. assert.equal(moment.duration({s: -0.5}).toISOString(), '-PT0.5S', 'one half second ago');
  33841. assert.equal(moment.duration({y: -0.5, M: 1}).toISOString(), '-P5M', 'a month after half a year ago');
  33842. assert.equal(moment.duration({}).toISOString(), 'P0D', 'zero duration');
  33843. assert.equal(moment.duration({M: 16, d:40, s: 86465}).toISOString(), 'P1Y4M40DT24H1M5S', 'all fields');
  33844. });
  33845. test('toString acts as toISOString', function (assert) {
  33846. assert.equal(moment.duration({y: 1, M: 2, d: 3, h: 4, m: 5, s: 6}).toString(), 'P1Y2M3DT4H5M6S', 'all fields');
  33847. assert.equal(moment.duration({M: -1}).toString(), '-P1M', 'one month ago');
  33848. assert.equal(moment.duration({m: -1}).toString(), '-PT1M', 'one minute ago');
  33849. assert.equal(moment.duration({s: -0.5}).toString(), '-PT0.5S', 'one half second ago');
  33850. assert.equal(moment.duration({y: -0.5, M: 1}).toString(), '-P5M', 'a month after half a year ago');
  33851. assert.equal(moment.duration({}).toString(), 'P0D', 'zero duration');
  33852. assert.equal(moment.duration({M: 16, d:40, s: 86465}).toString(), 'P1Y4M40DT24H1M5S', 'all fields');
  33853. });
  33854. test('toIsoString deprecation', function (assert) {
  33855. assert.equal(moment.duration({}).toIsoString(), moment.duration({}).toISOString(), 'toIsoString delegates to toISOString');
  33856. });
  33857. test('`isodate` (python) test cases', function (assert) {
  33858. assert.equal(moment.duration('P18Y9M4DT11H9M8S').asSeconds(), moment.duration({y: 18, M: 9, d: 4, h: 11, m: 9, s: 8}).asSeconds(), 'python isodate 1');
  33859. assert.equal(moment.duration('P2W').asSeconds(), moment.duration({w: 2}).asSeconds(), 'python isodate 2');
  33860. assert.equal(moment.duration('P3Y6M4DT12H30M5S').asSeconds(), moment.duration({y: 3, M: 6, d: 4, h: 12, m: 30, s: 5}).asSeconds(), 'python isodate 3');
  33861. assert.equal(moment.duration('P23DT23H').asSeconds(), moment.duration({d: 23, h: 23}).asSeconds(), 'python isodate 4');
  33862. assert.equal(moment.duration('P4Y').asSeconds(), moment.duration({y: 4}).asSeconds(), 'python isodate 5');
  33863. assert.equal(moment.duration('P1M').asSeconds(), moment.duration({M: 1}).asSeconds(), 'python isodate 6');
  33864. assert.equal(moment.duration('PT1M').asSeconds(), moment.duration({m: 1}).asSeconds(), 'python isodate 7');
  33865. assert.equal(moment.duration('P0.5Y').asSeconds(), moment.duration({y: 0.5}).asSeconds(), 'python isodate 8');
  33866. assert.equal(moment.duration('PT36H').asSeconds(), moment.duration({h: 36}).asSeconds(), 'python isodate 9');
  33867. assert.equal(moment.duration('P1DT12H').asSeconds(), moment.duration({d: 1, h: 12}).asSeconds(), 'python isodate 10');
  33868. assert.equal(moment.duration('-P2W').asSeconds(), moment.duration({w: -2}).asSeconds(), 'python isodate 11');
  33869. assert.equal(moment.duration('-P2.2W').asSeconds(), moment.duration({w: -2.2}).asSeconds(), 'python isodate 12');
  33870. assert.equal(moment.duration('P1DT2H3M4S').asSeconds(), moment.duration({d: 1, h: 2, m: 3, s: 4}).asSeconds(), 'python isodate 13');
  33871. assert.equal(moment.duration('P1DT2H3M').asSeconds(), moment.duration({d: 1, h: 2, m: 3}).asSeconds(), 'python isodate 14');
  33872. assert.equal(moment.duration('P1DT2H').asSeconds(), moment.duration({d: 1, h: 2}).asSeconds(), 'python isodate 15');
  33873. assert.equal(moment.duration('PT2H').asSeconds(), moment.duration({h: 2}).asSeconds(), 'python isodate 16');
  33874. assert.equal(moment.duration('PT2.3H').asSeconds(), moment.duration({h: 2.3}).asSeconds(), 'python isodate 17');
  33875. assert.equal(moment.duration('PT2H3M4S').asSeconds(), moment.duration({h: 2, m: 3, s: 4}).asSeconds(), 'python isodate 18');
  33876. assert.equal(moment.duration('PT3M4S').asSeconds(), moment.duration({m: 3, s: 4}).asSeconds(), 'python isodate 19');
  33877. assert.equal(moment.duration('PT22S').asSeconds(), moment.duration({s: 22}).asSeconds(), 'python isodate 20');
  33878. assert.equal(moment.duration('PT22.22S').asSeconds(), moment.duration({s: 22.22}).asSeconds(), 'python isodate 21');
  33879. assert.equal(moment.duration('-P2Y').asSeconds(), moment.duration({y: -2}).asSeconds(), 'python isodate 22');
  33880. assert.equal(moment.duration('-P3Y6M4DT12H30M5S').asSeconds(), moment.duration({y: -3, M: -6, d: -4, h: -12, m: -30, s: -5}).asSeconds(), 'python isodate 23');
  33881. assert.equal(moment.duration('-P1DT2H3M4S').asSeconds(), moment.duration({d: -1, h: -2, m: -3, s: -4}).asSeconds(), 'python isodate 24');
  33882. });
  33883. test('ISO 8601 misuse cases', function (assert) {
  33884. assert.equal(moment.duration('P').asSeconds(), 0, 'lonely P');
  33885. assert.equal(moment.duration('PT').asSeconds(), 0, 'just P and T');
  33886. assert.equal(moment.duration('P1H').asSeconds(), 0, 'missing T');
  33887. assert.equal(moment.duration('P1D1Y').asSeconds(), 0, 'out of order');
  33888. assert.equal(moment.duration('PT.5S').asSeconds(), 0.5, 'accept no leading zero for decimal');
  33889. assert.equal(moment.duration('PT1,S').asSeconds(), 1, 'accept trailing decimal separator');
  33890. assert.equal(moment.duration('PT1M0,,5S').asSeconds(), 60, 'extra decimal separators are ignored as 0');
  33891. assert.equal(moment.duration('P-1DS').asSeconds(), 0, 'wrong position of negative');
  33892. });
  33893. test('humanize', function (assert) {
  33894. moment.locale('en');
  33895. assert.equal(moment.duration({seconds: 44}).humanize(), 'a few seconds', '44 seconds = a few seconds');
  33896. assert.equal(moment.duration({seconds: 45}).humanize(), 'a minute', '45 seconds = a minute');
  33897. assert.equal(moment.duration({seconds: 89}).humanize(), 'a minute', '89 seconds = a minute');
  33898. assert.equal(moment.duration({seconds: 90}).humanize(), '2 minutes', '90 seconds = 2 minutes');
  33899. assert.equal(moment.duration({minutes: 44}).humanize(), '44 minutes', '44 minutes = 44 minutes');
  33900. assert.equal(moment.duration({minutes: 45}).humanize(), 'an hour', '45 minutes = an hour');
  33901. assert.equal(moment.duration({minutes: 89}).humanize(), 'an hour', '89 minutes = an hour');
  33902. assert.equal(moment.duration({minutes: 90}).humanize(), '2 hours', '90 minutes = 2 hours');
  33903. assert.equal(moment.duration({hours: 5}).humanize(), '5 hours', '5 hours = 5 hours');
  33904. assert.equal(moment.duration({hours: 21}).humanize(), '21 hours', '21 hours = 21 hours');
  33905. assert.equal(moment.duration({hours: 22}).humanize(), 'a day', '22 hours = a day');
  33906. assert.equal(moment.duration({hours: 35}).humanize(), 'a day', '35 hours = a day');
  33907. assert.equal(moment.duration({hours: 36}).humanize(), '2 days', '36 hours = 2 days');
  33908. assert.equal(moment.duration({days: 1}).humanize(), 'a day', '1 day = a day');
  33909. assert.equal(moment.duration({days: 5}).humanize(), '5 days', '5 days = 5 days');
  33910. assert.equal(moment.duration({weeks: 1}).humanize(), '7 days', '1 week = 7 days');
  33911. assert.equal(moment.duration({days: 25}).humanize(), '25 days', '25 days = 25 days');
  33912. assert.equal(moment.duration({days: 26}).humanize(), 'a month', '26 days = a month');
  33913. assert.equal(moment.duration({days: 30}).humanize(), 'a month', '30 days = a month');
  33914. assert.equal(moment.duration({days: 45}).humanize(), 'a month', '45 days = a month');
  33915. assert.equal(moment.duration({days: 46}).humanize(), '2 months', '46 days = 2 months');
  33916. assert.equal(moment.duration({days: 74}).humanize(), '2 months', '74 days = 2 months');
  33917. assert.equal(moment.duration({days: 77}).humanize(), '3 months', '77 days = 3 months');
  33918. assert.equal(moment.duration({months: 1}).humanize(), 'a month', '1 month = a month');
  33919. assert.equal(moment.duration({months: 5}).humanize(), '5 months', '5 months = 5 months');
  33920. assert.equal(moment.duration({days: 344}).humanize(), 'a year', '344 days = a year');
  33921. assert.equal(moment.duration({days: 345}).humanize(), 'a year', '345 days = a year');
  33922. assert.equal(moment.duration({days: 547}).humanize(), 'a year', '547 days = a year');
  33923. assert.equal(moment.duration({days: 548}).humanize(), '2 years', '548 days = 2 years');
  33924. assert.equal(moment.duration({years: 1}).humanize(), 'a year', '1 year = a year');
  33925. assert.equal(moment.duration({years: 5}).humanize(), '5 years', '5 years = 5 years');
  33926. assert.equal(moment.duration(7200000).humanize(), '2 hours', '7200000 = 2 minutes');
  33927. });
  33928. test('humanize duration with suffix', function (assert) {
  33929. moment.locale('en');
  33930. assert.equal(moment.duration({seconds: 44}).humanize(true), 'in a few seconds', '44 seconds = a few seconds');
  33931. assert.equal(moment.duration({seconds: -44}).humanize(true), 'a few seconds ago', '44 seconds = a few seconds');
  33932. });
  33933. test('bubble value up', function (assert) {
  33934. assert.equal(moment.duration({milliseconds: 61001}).milliseconds(), 1, '61001 milliseconds has 1 millisecond left over');
  33935. assert.equal(moment.duration({milliseconds: 61001}).seconds(), 1, '61001 milliseconds has 1 second left over');
  33936. assert.equal(moment.duration({milliseconds: 61001}).minutes(), 1, '61001 milliseconds has 1 minute left over');
  33937. assert.equal(moment.duration({minutes: 350}).minutes(), 50, '350 minutes has 50 minutes left over');
  33938. assert.equal(moment.duration({minutes: 350}).hours(), 5, '350 minutes has 5 hours left over');
  33939. });
  33940. test('clipping', function (assert) {
  33941. assert.equal(moment.duration({months: 11}).months(), 11, '11 months is 11 months');
  33942. assert.equal(moment.duration({months: 11}).years(), 0, '11 months makes no year');
  33943. assert.equal(moment.duration({months: 12}).months(), 0, '12 months is 0 months left over');
  33944. assert.equal(moment.duration({months: 12}).years(), 1, '12 months makes 1 year');
  33945. assert.equal(moment.duration({months: 13}).months(), 1, '13 months is 1 month left over');
  33946. assert.equal(moment.duration({months: 13}).years(), 1, '13 months makes 1 year');
  33947. assert.equal(moment.duration({days: 30}).days(), 30, '30 days is 30 days');
  33948. assert.equal(moment.duration({days: 30}).months(), 0, '30 days makes no month');
  33949. assert.equal(moment.duration({days: 31}).days(), 0, '31 days is 0 days left over');
  33950. assert.equal(moment.duration({days: 31}).months(), 1, '31 days is a month');
  33951. assert.equal(moment.duration({days: 32}).days(), 1, '32 days is 1 day left over');
  33952. assert.equal(moment.duration({days: 32}).months(), 1, '32 days is a month');
  33953. assert.equal(moment.duration({hours: 23}).hours(), 23, '23 hours is 23 hours');
  33954. assert.equal(moment.duration({hours: 23}).days(), 0, '23 hours makes no day');
  33955. assert.equal(moment.duration({hours: 24}).hours(), 0, '24 hours is 0 hours left over');
  33956. assert.equal(moment.duration({hours: 24}).days(), 1, '24 hours makes 1 day');
  33957. assert.equal(moment.duration({hours: 25}).hours(), 1, '25 hours is 1 hour left over');
  33958. assert.equal(moment.duration({hours: 25}).days(), 1, '25 hours makes 1 day');
  33959. });
  33960. test('bubbling consistency', function (assert) {
  33961. var days = 0, months = 0, newDays, newMonths, totalDays, d;
  33962. for (totalDays = 1; totalDays <= 500; ++totalDays) {
  33963. d = moment.duration(totalDays, 'days');
  33964. newDays = d.days();
  33965. newMonths = d.months() + d.years() * 12;
  33966. assert.ok(
  33967. (months === newMonths && days + 1 === newDays) ||
  33968. (months + 1 === newMonths && newDays === 0),
  33969. 'consistent total days ' + totalDays +
  33970. ' was ' + months + ' ' + days +
  33971. ' now ' + newMonths + ' ' + newDays);
  33972. days = newDays;
  33973. months = newMonths;
  33974. }
  33975. });
  33976. test('effective equivalency', function (assert) {
  33977. assert.deepEqual(moment.duration({seconds: 1})._data, moment.duration({milliseconds: 1000})._data, '1 second is the same as 1000 milliseconds');
  33978. assert.deepEqual(moment.duration({seconds: 60})._data, moment.duration({minutes: 1})._data, '1 minute is the same as 60 seconds');
  33979. assert.deepEqual(moment.duration({minutes: 60})._data, moment.duration({hours: 1})._data, '1 hour is the same as 60 minutes');
  33980. assert.deepEqual(moment.duration({hours: 24})._data, moment.duration({days: 1})._data, '1 day is the same as 24 hours');
  33981. assert.deepEqual(moment.duration({days: 7})._data, moment.duration({weeks: 1})._data, '1 week is the same as 7 days');
  33982. assert.deepEqual(moment.duration({days: 31})._data, moment.duration({months: 1})._data, '1 month is the same as 30 days');
  33983. assert.deepEqual(moment.duration({months: 12})._data, moment.duration({years: 1})._data, '1 years is the same as 12 months');
  33984. });
  33985. test('asGetters', function (assert) {
  33986. // 400 years have exactly 146097 days
  33987. // years
  33988. assert.equal(moment.duration(1, 'year').asYears(), 1, '1 year as years');
  33989. assert.equal(moment.duration(1, 'year').asMonths(), 12, '1 year as months');
  33990. assert.equal(moment.duration(400, 'year').asMonths(), 4800, '400 years as months');
  33991. assert.equal(moment.duration(1, 'year').asWeeks().toFixed(3), 52.143, '1 year as weeks');
  33992. assert.equal(moment.duration(1, 'year').asDays(), 365, '1 year as days');
  33993. assert.equal(moment.duration(2, 'year').asDays(), 730, '2 years as days');
  33994. assert.equal(moment.duration(3, 'year').asDays(), 1096, '3 years as days');
  33995. assert.equal(moment.duration(4, 'year').asDays(), 1461, '4 years as days');
  33996. assert.equal(moment.duration(400, 'year').asDays(), 146097, '400 years as days');
  33997. assert.equal(moment.duration(1, 'year').asHours(), 8760, '1 year as hours');
  33998. assert.equal(moment.duration(1, 'year').asMinutes(), 525600, '1 year as minutes');
  33999. assert.equal(moment.duration(1, 'year').asSeconds(), 31536000, '1 year as seconds');
  34000. assert.equal(moment.duration(1, 'year').asMilliseconds(), 31536000000, '1 year as milliseconds');
  34001. // months
  34002. assert.equal(moment.duration(1, 'month').asYears().toFixed(4), 0.0833, '1 month as years');
  34003. assert.equal(moment.duration(1, 'month').asMonths(), 1, '1 month as months');
  34004. assert.equal(moment.duration(1, 'month').asWeeks().toFixed(3), 4.286, '1 month as weeks');
  34005. assert.equal(moment.duration(1, 'month').asDays(), 30, '1 month as days');
  34006. assert.equal(moment.duration(2, 'month').asDays(), 61, '2 months as days');
  34007. assert.equal(moment.duration(3, 'month').asDays(), 91, '3 months as days');
  34008. assert.equal(moment.duration(4, 'month').asDays(), 122, '4 months as days');
  34009. assert.equal(moment.duration(5, 'month').asDays(), 152, '5 months as days');
  34010. assert.equal(moment.duration(6, 'month').asDays(), 183, '6 months as days');
  34011. assert.equal(moment.duration(7, 'month').asDays(), 213, '7 months as days');
  34012. assert.equal(moment.duration(8, 'month').asDays(), 243, '8 months as days');
  34013. assert.equal(moment.duration(9, 'month').asDays(), 274, '9 months as days');
  34014. assert.equal(moment.duration(10, 'month').asDays(), 304, '10 months as days');
  34015. assert.equal(moment.duration(11, 'month').asDays(), 335, '11 months as days');
  34016. assert.equal(moment.duration(12, 'month').asDays(), 365, '12 months as days');
  34017. assert.equal(moment.duration(24, 'month').asDays(), 730, '24 months as days');
  34018. assert.equal(moment.duration(36, 'month').asDays(), 1096, '36 months as days');
  34019. assert.equal(moment.duration(48, 'month').asDays(), 1461, '48 months as days');
  34020. assert.equal(moment.duration(4800, 'month').asDays(), 146097, '4800 months as days');
  34021. assert.equal(moment.duration(1, 'month').asHours(), 720, '1 month as hours');
  34022. assert.equal(moment.duration(1, 'month').asMinutes(), 43200, '1 month as minutes');
  34023. assert.equal(moment.duration(1, 'month').asSeconds(), 2592000, '1 month as seconds');
  34024. assert.equal(moment.duration(1, 'month').asMilliseconds(), 2592000000, '1 month as milliseconds');
  34025. // weeks
  34026. assert.equal(moment.duration(1, 'week').asYears().toFixed(4), 0.0192, '1 week as years');
  34027. assert.equal(moment.duration(1, 'week').asMonths().toFixed(3), 0.230, '1 week as months');
  34028. assert.equal(moment.duration(1, 'week').asWeeks(), 1, '1 week as weeks');
  34029. assert.equal(moment.duration(1, 'week').asDays(), 7, '1 week as days');
  34030. assert.equal(moment.duration(1, 'week').asHours(), 168, '1 week as hours');
  34031. assert.equal(moment.duration(1, 'week').asMinutes(), 10080, '1 week as minutes');
  34032. assert.equal(moment.duration(1, 'week').asSeconds(), 604800, '1 week as seconds');
  34033. assert.equal(moment.duration(1, 'week').asMilliseconds(), 604800000, '1 week as milliseconds');
  34034. // days
  34035. assert.equal(moment.duration(1, 'day').asYears().toFixed(4), 0.0027, '1 day as years');
  34036. assert.equal(moment.duration(1, 'day').asMonths().toFixed(3), 0.033, '1 day as months');
  34037. assert.equal(moment.duration(1, 'day').asWeeks().toFixed(3), 0.143, '1 day as weeks');
  34038. assert.equal(moment.duration(1, 'day').asDays(), 1, '1 day as days');
  34039. assert.equal(moment.duration(1, 'day').asHours(), 24, '1 day as hours');
  34040. assert.equal(moment.duration(1, 'day').asMinutes(), 1440, '1 day as minutes');
  34041. assert.equal(moment.duration(1, 'day').asSeconds(), 86400, '1 day as seconds');
  34042. assert.equal(moment.duration(1, 'day').asMilliseconds(), 86400000, '1 day as milliseconds');
  34043. // hours
  34044. assert.equal(moment.duration(1, 'hour').asYears().toFixed(6), 0.000114, '1 hour as years');
  34045. assert.equal(moment.duration(1, 'hour').asMonths().toFixed(5), 0.00137, '1 hour as months');
  34046. assert.equal(moment.duration(1, 'hour').asWeeks().toFixed(5), 0.00595, '1 hour as weeks');
  34047. assert.equal(moment.duration(1, 'hour').asDays().toFixed(4), 0.0417, '1 hour as days');
  34048. assert.equal(moment.duration(1, 'hour').asHours(), 1, '1 hour as hours');
  34049. assert.equal(moment.duration(1, 'hour').asMinutes(), 60, '1 hour as minutes');
  34050. assert.equal(moment.duration(1, 'hour').asSeconds(), 3600, '1 hour as seconds');
  34051. assert.equal(moment.duration(1, 'hour').asMilliseconds(), 3600000, '1 hour as milliseconds');
  34052. // minutes
  34053. assert.equal(moment.duration(1, 'minute').asYears().toFixed(8), 0.00000190, '1 minute as years');
  34054. assert.equal(moment.duration(1, 'minute').asMonths().toFixed(7), 0.0000228, '1 minute as months');
  34055. assert.equal(moment.duration(1, 'minute').asWeeks().toFixed(7), 0.0000992, '1 minute as weeks');
  34056. assert.equal(moment.duration(1, 'minute').asDays().toFixed(6), 0.000694, '1 minute as days');
  34057. assert.equal(moment.duration(1, 'minute').asHours().toFixed(4), 0.0167, '1 minute as hours');
  34058. assert.equal(moment.duration(1, 'minute').asMinutes(), 1, '1 minute as minutes');
  34059. assert.equal(moment.duration(1, 'minute').asSeconds(), 60, '1 minute as seconds');
  34060. assert.equal(moment.duration(1, 'minute').asMilliseconds(), 60000, '1 minute as milliseconds');
  34061. // seconds
  34062. assert.equal(moment.duration(1, 'second').asYears().toFixed(10), 0.0000000317, '1 second as years');
  34063. assert.equal(moment.duration(1, 'second').asMonths().toFixed(9), 0.000000380, '1 second as months');
  34064. assert.equal(moment.duration(1, 'second').asWeeks().toFixed(8), 0.00000165, '1 second as weeks');
  34065. assert.equal(moment.duration(1, 'second').asDays().toFixed(7), 0.0000116, '1 second as days');
  34066. assert.equal(moment.duration(1, 'second').asHours().toFixed(6), 0.000278, '1 second as hours');
  34067. assert.equal(moment.duration(1, 'second').asMinutes().toFixed(4), 0.0167, '1 second as minutes');
  34068. assert.equal(moment.duration(1, 'second').asSeconds(), 1, '1 second as seconds');
  34069. assert.equal(moment.duration(1, 'second').asMilliseconds(), 1000, '1 second as milliseconds');
  34070. // milliseconds
  34071. assert.equal(moment.duration(1, 'millisecond').asYears().toFixed(13), 0.0000000000317, '1 millisecond as years');
  34072. assert.equal(moment.duration(1, 'millisecond').asMonths().toFixed(12), 0.000000000380, '1 millisecond as months');
  34073. assert.equal(moment.duration(1, 'millisecond').asWeeks().toFixed(11), 0.00000000165, '1 millisecond as weeks');
  34074. assert.equal(moment.duration(1, 'millisecond').asDays().toFixed(10), 0.0000000116, '1 millisecond as days');
  34075. assert.equal(moment.duration(1, 'millisecond').asHours().toFixed(9), 0.000000278, '1 millisecond as hours');
  34076. assert.equal(moment.duration(1, 'millisecond').asMinutes().toFixed(7), 0.0000167, '1 millisecond as minutes');
  34077. assert.equal(moment.duration(1, 'millisecond').asSeconds(), 0.001, '1 millisecond as seconds');
  34078. assert.equal(moment.duration(1, 'millisecond').asMilliseconds(), 1, '1 millisecond as milliseconds');
  34079. });
  34080. test('as getters for small units', function (assert) {
  34081. var dS = moment.duration(1, 'milliseconds'),
  34082. ds = moment.duration(3, 'seconds'),
  34083. dm = moment.duration(13, 'minutes');
  34084. // Tests for issue #1867.
  34085. // Floating point errors for small duration units were introduced in version 2.8.0.
  34086. assert.equal(dS.as('milliseconds'), 1, 'as("milliseconds")');
  34087. assert.equal(dS.asMilliseconds(), 1, 'asMilliseconds()');
  34088. assert.equal(ds.as('seconds'), 3, 'as("seconds")');
  34089. assert.equal(ds.asSeconds(), 3, 'asSeconds()');
  34090. assert.equal(dm.as('minutes'), 13, 'as("minutes")');
  34091. assert.equal(dm.asMinutes(), 13, 'asMinutes()');
  34092. });
  34093. test('isDuration', function (assert) {
  34094. assert.ok(moment.isDuration(moment.duration(12345678)), 'correctly says true');
  34095. assert.ok(!moment.isDuration(moment()), 'moment object is not a duration');
  34096. assert.ok(!moment.isDuration({milliseconds: 1}), 'plain object is not a duration');
  34097. });
  34098. test('add', function (assert) {
  34099. var d = moment.duration({months: 4, weeks: 3, days: 2});
  34100. // for some reason, d._data._months does not get updated; use d._months instead.
  34101. assert.equal(d.add(1, 'month')._months, 5, 'Add months');
  34102. assert.equal(d.add(5, 'days')._days, 28, 'Add days');
  34103. assert.equal(d.add(10000)._milliseconds, 10000, 'Add milliseconds');
  34104. assert.equal(d.add({h: 23, m: 59})._milliseconds, 23 * 60 * 60 * 1000 + 59 * 60 * 1000 + 10000, 'Add hour:minute');
  34105. });
  34106. test('add and bubble', function (assert) {
  34107. var d;
  34108. assert.equal(moment.duration(1, 'second').add(1000, 'milliseconds').seconds(), 2, 'Adding milliseconds should bubble up to seconds');
  34109. assert.equal(moment.duration(1, 'minute').add(60, 'second').minutes(), 2, 'Adding seconds should bubble up to minutes');
  34110. assert.equal(moment.duration(1, 'hour').add(60, 'minutes').hours(), 2, 'Adding minutes should bubble up to hours');
  34111. assert.equal(moment.duration(1, 'day').add(24, 'hours').days(), 2, 'Adding hours should bubble up to days');
  34112. d = moment.duration(-1, 'day').add(1, 'hour');
  34113. assert.equal(d.hours(), -23, '-1 day + 1 hour == -23 hour (component)');
  34114. assert.equal(d.asHours(), -23, '-1 day + 1 hour == -23 hours');
  34115. d = moment.duration(-1, 'year').add(1, 'day');
  34116. assert.equal(d.days(), -30, '- 1 year + 1 day == -30 days (component)');
  34117. assert.equal(d.months(), -11, '- 1 year + 1 day == -11 months (component)');
  34118. assert.equal(d.years(), 0, '- 1 year + 1 day == 0 years (component)');
  34119. assert.equal(d.asDays(), -364, '- 1 year + 1 day == -364 days');
  34120. d = moment.duration(-1, 'year').add(1, 'hour');
  34121. assert.equal(d.hours(), -23, '- 1 year + 1 hour == -23 hours (component)');
  34122. assert.equal(d.days(), -30, '- 1 year + 1 hour == -30 days (component)');
  34123. assert.equal(d.months(), -11, '- 1 year + 1 hour == -11 months (component)');
  34124. assert.equal(d.years(), 0, '- 1 year + 1 hour == 0 years (component)');
  34125. });
  34126. test('subtract and bubble', function (assert) {
  34127. var d;
  34128. assert.equal(moment.duration(2, 'second').subtract(1000, 'milliseconds').seconds(), 1, 'Subtracting milliseconds should bubble up to seconds');
  34129. assert.equal(moment.duration(2, 'minute').subtract(60, 'second').minutes(), 1, 'Subtracting seconds should bubble up to minutes');
  34130. assert.equal(moment.duration(2, 'hour').subtract(60, 'minutes').hours(), 1, 'Subtracting minutes should bubble up to hours');
  34131. assert.equal(moment.duration(2, 'day').subtract(24, 'hours').days(), 1, 'Subtracting hours should bubble up to days');
  34132. d = moment.duration(1, 'day').subtract(1, 'hour');
  34133. assert.equal(d.hours(), 23, '1 day - 1 hour == 23 hour (component)');
  34134. assert.equal(d.asHours(), 23, '1 day - 1 hour == 23 hours');
  34135. d = moment.duration(1, 'year').subtract(1, 'day');
  34136. assert.equal(d.days(), 30, '1 year - 1 day == 30 days (component)');
  34137. assert.equal(d.months(), 11, '1 year - 1 day == 11 months (component)');
  34138. assert.equal(d.years(), 0, '1 year - 1 day == 0 years (component)');
  34139. assert.equal(d.asDays(), 364, '1 year - 1 day == 364 days');
  34140. d = moment.duration(1, 'year').subtract(1, 'hour');
  34141. assert.equal(d.hours(), 23, '1 year - 1 hour == 23 hours (component)');
  34142. assert.equal(d.days(), 30, '1 year - 1 hour == 30 days (component)');
  34143. assert.equal(d.months(), 11, '1 year - 1 hour == 11 months (component)');
  34144. assert.equal(d.years(), 0, '1 year - 1 hour == 0 years (component)');
  34145. });
  34146. test('subtract', function (assert) {
  34147. var d = moment.duration({months: 2, weeks: 2, days: 0, hours: 5});
  34148. // for some reason, d._data._months does not get updated; use d._months instead.
  34149. assert.equal(d.subtract(1, 'months')._months, 1, 'Subtract months');
  34150. assert.equal(d.subtract(14, 'days')._days, 0, 'Subtract days');
  34151. assert.equal(d.subtract(10000)._milliseconds, 5 * 60 * 60 * 1000 - 10000, 'Subtract milliseconds');
  34152. assert.equal(d.subtract({h: 1, m: 59})._milliseconds, 3 * 60 * 60 * 1000 + 1 * 60 * 1000 - 10000, 'Subtract hour:minute');
  34153. });
  34154. test('JSON.stringify duration', function (assert) {
  34155. var d = moment.duration(1024, 'h');
  34156. assert.equal(JSON.stringify(d), '"' + d.toISOString() + '"', 'JSON.stringify on duration should return ISO string');
  34157. });
  34158. test('duration plugins', function (assert) {
  34159. var durationObject = moment.duration();
  34160. moment.duration.fn.foo = function (arg) {
  34161. assert.equal(this, durationObject);
  34162. assert.equal(arg, 5);
  34163. };
  34164. durationObject.foo(5);
  34165. });
  34166. }));
  34167. ;(function (global, factory) {
  34168. typeof exports === 'object' && typeof module !== 'undefined'
  34169. && typeof require === 'function' ? factory(require('../../moment')) :
  34170. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  34171. factory(global.moment)
  34172. }(this, function (moment) { 'use strict';
  34173. /*global QUnit:false*/
  34174. var test = QUnit.test;
  34175. var expect = QUnit.expect;
  34176. function module (name, lifecycle) {
  34177. QUnit.module(name, {
  34178. setup : function () {
  34179. moment.locale('en');
  34180. moment.createFromInputFallback = function (config) {
  34181. throw new Error('input not handled by moment: ' + config._i);
  34182. };
  34183. if (lifecycle && lifecycle.setup) {
  34184. lifecycle.setup();
  34185. }
  34186. },
  34187. teardown : function () {
  34188. if (lifecycle && lifecycle.teardown) {
  34189. lifecycle.teardown();
  34190. }
  34191. }
  34192. });
  34193. }
  34194. function localeModule (name, lifecycle) {
  34195. QUnit.module('locale:' + name, {
  34196. setup : function () {
  34197. moment.locale(name);
  34198. moment.createFromInputFallback = function (config) {
  34199. throw new Error('input not handled by moment: ' + config._i);
  34200. };
  34201. if (lifecycle && lifecycle.setup) {
  34202. lifecycle.setup();
  34203. }
  34204. },
  34205. teardown : function () {
  34206. moment.locale('en');
  34207. if (lifecycle && lifecycle.teardown) {
  34208. lifecycle.teardown();
  34209. }
  34210. }
  34211. });
  34212. }
  34213. module('duration from moments');
  34214. test('pure year diff', function (assert) {
  34215. var m1 = moment('2012-01-01T00:00:00.000Z'),
  34216. m2 = moment('2013-01-01T00:00:00.000Z');
  34217. assert.equal(moment.duration({from: m1, to: m2}).as('years'), 1, 'year moment difference');
  34218. assert.equal(moment.duration({from: m2, to: m1}).as('years'), -1, 'negative year moment difference');
  34219. });
  34220. test('month and day diff', function (assert) {
  34221. var m1 = moment('2012-01-15T00:00:00.000Z'),
  34222. m2 = moment('2012-02-17T00:00:00.000Z'),
  34223. d = moment.duration({from: m1, to: m2});
  34224. assert.equal(d.get('days'), 2);
  34225. assert.equal(d.get('months'), 1);
  34226. });
  34227. test('day diff, separate months', function (assert) {
  34228. var m1 = moment('2012-01-15T00:00:00.000Z'),
  34229. m2 = moment('2012-02-13T00:00:00.000Z'),
  34230. d = moment.duration({from: m1, to: m2});
  34231. assert.equal(d.as('days'), 29);
  34232. });
  34233. test('hour diff', function (assert) {
  34234. var m1 = moment('2012-01-15T17:00:00.000Z'),
  34235. m2 = moment('2012-01-16T03:00:00.000Z'),
  34236. d = moment.duration({from: m1, to: m2});
  34237. assert.equal(d.as('hours'), 10);
  34238. });
  34239. test('minute diff', function (assert) {
  34240. var m1 = moment('2012-01-15T17:45:00.000Z'),
  34241. m2 = moment('2012-01-16T03:15:00.000Z'),
  34242. d = moment.duration({from: m1, to: m2});
  34243. assert.equal(d.as('hours'), 9.5);
  34244. });
  34245. }));
  34246. ;(function (global, factory) {
  34247. typeof exports === 'object' && typeof module !== 'undefined'
  34248. && typeof require === 'function' ? factory(require('../../moment')) :
  34249. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  34250. factory(global.moment)
  34251. }(this, function (moment) { 'use strict';
  34252. /*global QUnit:false*/
  34253. var test = QUnit.test;
  34254. var expect = QUnit.expect;
  34255. function module (name, lifecycle) {
  34256. QUnit.module(name, {
  34257. setup : function () {
  34258. moment.locale('en');
  34259. moment.createFromInputFallback = function (config) {
  34260. throw new Error('input not handled by moment: ' + config._i);
  34261. };
  34262. if (lifecycle && lifecycle.setup) {
  34263. lifecycle.setup();
  34264. }
  34265. },
  34266. teardown : function () {
  34267. if (lifecycle && lifecycle.teardown) {
  34268. lifecycle.teardown();
  34269. }
  34270. }
  34271. });
  34272. }
  34273. function localeModule (name, lifecycle) {
  34274. QUnit.module('locale:' + name, {
  34275. setup : function () {
  34276. moment.locale(name);
  34277. moment.createFromInputFallback = function (config) {
  34278. throw new Error('input not handled by moment: ' + config._i);
  34279. };
  34280. if (lifecycle && lifecycle.setup) {
  34281. lifecycle.setup();
  34282. }
  34283. },
  34284. teardown : function () {
  34285. moment.locale('en');
  34286. if (lifecycle && lifecycle.teardown) {
  34287. lifecycle.teardown();
  34288. }
  34289. }
  34290. });
  34291. }
  34292. module('format');
  34293. test('format YY', function (assert) {
  34294. var b = moment(new Date(2009, 1, 14, 15, 25, 50, 125));
  34295. assert.equal(b.format('YY'), '09', 'YY ---> 09');
  34296. });
  34297. test('format escape brackets', function (assert) {
  34298. moment.locale('en');
  34299. var b = moment(new Date(2009, 1, 14, 15, 25, 50, 125));
  34300. assert.equal(b.format('[day]'), 'day', 'Single bracket');
  34301. assert.equal(b.format('[day] YY [YY]'), 'day 09 YY', 'Double bracket');
  34302. assert.equal(b.format('[YY'), '[09', 'Un-ended bracket');
  34303. assert.equal(b.format('[[YY]]'), '[YY]', 'Double nested brackets');
  34304. assert.equal(b.format('[[]'), '[', 'Escape open bracket');
  34305. assert.equal(b.format('[Last]'), 'Last', 'localized tokens');
  34306. assert.equal(b.format('[L] L'), 'L 02/14/2009', 'localized tokens with escaped localized tokens');
  34307. assert.equal(b.format('[L LL LLL LLLL aLa]'), 'L LL LLL LLLL aLa', 'localized tokens with escaped localized tokens');
  34308. assert.equal(b.format('[LLL] LLL'), 'LLL February 14, 2009 3:25 PM', 'localized tokens with escaped localized tokens (recursion)');
  34309. assert.equal(b.format('YYYY[\n]DD[\n]'), '2009\n14\n', 'Newlines');
  34310. });
  34311. test('handle negative years', function (assert) {
  34312. moment.locale('en');
  34313. assert.equal(moment.utc().year(-1).format('YY'), '-01', 'YY with negative year');
  34314. assert.equal(moment.utc().year(-1).format('YYYY'), '-0001', 'YYYY with negative year');
  34315. assert.equal(moment.utc().year(-12).format('YY'), '-12', 'YY with negative year');
  34316. assert.equal(moment.utc().year(-12).format('YYYY'), '-0012', 'YYYY with negative year');
  34317. assert.equal(moment.utc().year(-123).format('YY'), '-23', 'YY with negative year');
  34318. assert.equal(moment.utc().year(-123).format('YYYY'), '-0123', 'YYYY with negative year');
  34319. assert.equal(moment.utc().year(-1234).format('YY'), '-34', 'YY with negative year');
  34320. assert.equal(moment.utc().year(-1234).format('YYYY'), '-1234', 'YYYY with negative year');
  34321. assert.equal(moment.utc().year(-12345).format('YY'), '-45', 'YY with negative year');
  34322. assert.equal(moment.utc().year(-12345).format('YYYY'), '-12345', 'YYYY with negative year');
  34323. });
  34324. test('format milliseconds', function (assert) {
  34325. var b = moment(new Date(2009, 1, 14, 15, 25, 50, 123));
  34326. assert.equal(b.format('S'), '1', 'Deciseconds');
  34327. assert.equal(b.format('SS'), '12', 'Centiseconds');
  34328. assert.equal(b.format('SSS'), '123', 'Milliseconds');
  34329. b.milliseconds(789);
  34330. assert.equal(b.format('S'), '7', 'Deciseconds');
  34331. assert.equal(b.format('SS'), '78', 'Centiseconds');
  34332. assert.equal(b.format('SSS'), '789', 'Milliseconds');
  34333. });
  34334. test('format timezone', function (assert) {
  34335. var b = moment(new Date(2010, 1, 14, 15, 25, 50, 125));
  34336. assert.ok(b.format('Z').match(/^[\+\-]\d\d:\d\d$/), b.format('Z') + ' should be something like \'+07:30\'');
  34337. assert.ok(b.format('ZZ').match(/^[\+\-]\d{4}$/), b.format('ZZ') + ' should be something like \'+0700\'');
  34338. });
  34339. test('format multiple with utc offset', function (assert) {
  34340. var b = moment('2012-10-08 -1200', ['YYYY-MM-DD HH:mm ZZ', 'YYYY-MM-DD ZZ', 'YYYY-MM-DD']);
  34341. assert.equal(b.format('YYYY-MM'), '2012-10', 'Parsing multiple formats should not crash with different sized formats');
  34342. });
  34343. test('isDST', function (assert) {
  34344. var janOffset = new Date(2011, 0, 1).getTimezoneOffset(),
  34345. julOffset = new Date(2011, 6, 1).getTimezoneOffset(),
  34346. janIsDst = janOffset < julOffset,
  34347. julIsDst = julOffset < janOffset,
  34348. jan1 = moment([2011]),
  34349. jul1 = moment([2011, 6]);
  34350. if (janIsDst && julIsDst) {
  34351. assert.ok(0, 'January and July cannot both be in DST');
  34352. assert.ok(0, 'January and July cannot both be in DST');
  34353. } else if (janIsDst) {
  34354. assert.ok(jan1.isDST(), 'January 1 is DST');
  34355. assert.ok(!jul1.isDST(), 'July 1 is not DST');
  34356. } else if (julIsDst) {
  34357. assert.ok(!jan1.isDST(), 'January 1 is not DST');
  34358. assert.ok(jul1.isDST(), 'July 1 is DST');
  34359. } else {
  34360. assert.ok(!jan1.isDST(), 'January 1 is not DST');
  34361. assert.ok(!jul1.isDST(), 'July 1 is not DST');
  34362. }
  34363. });
  34364. test('unix timestamp', function (assert) {
  34365. var m = moment('1234567890.123', 'X');
  34366. assert.equal(m.format('X'), '1234567890', 'unix timestamp without milliseconds');
  34367. assert.equal(m.format('X.S'), '1234567890.1', 'unix timestamp with deciseconds');
  34368. assert.equal(m.format('X.SS'), '1234567890.12', 'unix timestamp with centiseconds');
  34369. assert.equal(m.format('X.SSS'), '1234567890.123', 'unix timestamp with milliseconds');
  34370. m = moment(1234567890.123, 'X');
  34371. assert.equal(m.format('X'), '1234567890', 'unix timestamp as integer');
  34372. });
  34373. test('unix offset milliseconds', function (assert) {
  34374. var m = moment('1234567890123', 'x');
  34375. assert.equal(m.format('x'), '1234567890123', 'unix offset in milliseconds');
  34376. m = moment(1234567890123, 'x');
  34377. assert.equal(m.format('x'), '1234567890123', 'unix offset in milliseconds as integer');
  34378. });
  34379. test('utcOffset sanity checks', function (assert) {
  34380. assert.equal(moment().utcOffset() % 15, 0,
  34381. 'utc offset should be a multiple of 15 (was ' + moment().utcOffset() + ')');
  34382. assert.equal(moment().utcOffset(), -(new Date()).getTimezoneOffset(),
  34383. 'utcOffset should return the opposite of getTimezoneOffset');
  34384. });
  34385. test('default format', function (assert) {
  34386. var isoRegex = /\d{4}.\d\d.\d\dT\d\d.\d\d.\d\d[\+\-]\d\d:\d\d/;
  34387. assert.ok(isoRegex.exec(moment().format()), 'default format (' + moment().format() + ') should match ISO');
  34388. });
  34389. test('toJSON', function (assert) {
  34390. var supportsJson = typeof JSON !== 'undefined' && JSON.stringify && JSON.stringify.call,
  34391. date = moment('2012-10-09T21:30:40.678+0100');
  34392. assert.equal(date.toJSON(), '2012-10-09T20:30:40.678Z', 'should output ISO8601 on moment.fn.toJSON');
  34393. if (supportsJson) {
  34394. assert.equal(JSON.stringify({
  34395. date : date
  34396. }), '{"date":"2012-10-09T20:30:40.678Z"}', 'should output ISO8601 on JSON.stringify');
  34397. }
  34398. });
  34399. test('toISOString', function (assert) {
  34400. var date = moment.utc('2012-10-09T20:30:40.678');
  34401. assert.equal(date.toISOString(), '2012-10-09T20:30:40.678Z', 'should output ISO8601 on moment.fn.toISOString');
  34402. // big years
  34403. date = moment.utc('+020123-10-09T20:30:40.678');
  34404. assert.equal(date.toISOString(), '+020123-10-09T20:30:40.678Z', 'ISO8601 format on big positive year');
  34405. // negative years
  34406. date = moment.utc('-000001-10-09T20:30:40.678');
  34407. assert.equal(date.toISOString(), '-000001-10-09T20:30:40.678Z', 'ISO8601 format on negative year');
  34408. // big negative years
  34409. date = moment.utc('-020123-10-09T20:30:40.678');
  34410. assert.equal(date.toISOString(), '-020123-10-09T20:30:40.678Z', 'ISO8601 format on big negative year');
  34411. });
  34412. test('long years', function (assert) {
  34413. assert.equal(moment.utc().year(2).format('YYYYYY'), '+000002', 'small year with YYYYYY');
  34414. assert.equal(moment.utc().year(2012).format('YYYYYY'), '+002012', 'regular year with YYYYYY');
  34415. assert.equal(moment.utc().year(20123).format('YYYYYY'), '+020123', 'big year with YYYYYY');
  34416. assert.equal(moment.utc().year(-1).format('YYYYYY'), '-000001', 'small negative year with YYYYYY');
  34417. assert.equal(moment.utc().year(-2012).format('YYYYYY'), '-002012', 'negative year with YYYYYY');
  34418. assert.equal(moment.utc().year(-20123).format('YYYYYY'), '-020123', 'big negative year with YYYYYY');
  34419. });
  34420. test('iso week formats', function (assert) {
  34421. // http://en.wikipedia.org/wiki/ISO_week_date
  34422. var cases = {
  34423. '2005-01-02': '2004-53',
  34424. '2005-12-31': '2005-52',
  34425. '2007-01-01': '2007-01',
  34426. '2007-12-30': '2007-52',
  34427. '2007-12-31': '2008-01',
  34428. '2008-01-01': '2008-01',
  34429. '2008-12-28': '2008-52',
  34430. '2008-12-29': '2009-01',
  34431. '2008-12-30': '2009-01',
  34432. '2008-12-31': '2009-01',
  34433. '2009-01-01': '2009-01',
  34434. '2009-12-31': '2009-53',
  34435. '2010-01-01': '2009-53',
  34436. '2010-01-02': '2009-53',
  34437. '2010-01-03': '2009-53',
  34438. '404-12-31': '0404-53',
  34439. '405-12-31': '0405-52'
  34440. }, i, isoWeek, formatted2, formatted1;
  34441. for (i in cases) {
  34442. isoWeek = cases[i].split('-').pop();
  34443. formatted2 = moment(i, 'YYYY-MM-DD').format('WW');
  34444. assert.equal(isoWeek, formatted2, i + ': WW should be ' + isoWeek + ', but ' + formatted2);
  34445. isoWeek = isoWeek.replace(/^0+/, '');
  34446. formatted1 = moment(i, 'YYYY-MM-DD').format('W');
  34447. assert.equal(isoWeek, formatted1, i + ': W should be ' + isoWeek + ', but ' + formatted1);
  34448. }
  34449. });
  34450. test('iso week year formats', function (assert) {
  34451. // http://en.wikipedia.org/wiki/ISO_week_date
  34452. var cases = {
  34453. '2005-01-02': '2004-53',
  34454. '2005-12-31': '2005-52',
  34455. '2007-01-01': '2007-01',
  34456. '2007-12-30': '2007-52',
  34457. '2007-12-31': '2008-01',
  34458. '2008-01-01': '2008-01',
  34459. '2008-12-28': '2008-52',
  34460. '2008-12-29': '2009-01',
  34461. '2008-12-30': '2009-01',
  34462. '2008-12-31': '2009-01',
  34463. '2009-01-01': '2009-01',
  34464. '2009-12-31': '2009-53',
  34465. '2010-01-01': '2009-53',
  34466. '2010-01-02': '2009-53',
  34467. '2010-01-03': '2009-53',
  34468. '404-12-31': '0404-53',
  34469. '405-12-31': '0405-52'
  34470. }, i, isoWeekYear, formatted5, formatted4, formatted2;
  34471. for (i in cases) {
  34472. isoWeekYear = cases[i].split('-')[0];
  34473. formatted5 = moment(i, 'YYYY-MM-DD').format('GGGGG');
  34474. assert.equal('0' + isoWeekYear, formatted5, i + ': GGGGG should be ' + isoWeekYear + ', but ' + formatted5);
  34475. formatted4 = moment(i, 'YYYY-MM-DD').format('GGGG');
  34476. assert.equal(isoWeekYear, formatted4, i + ': GGGG should be ' + isoWeekYear + ', but ' + formatted4);
  34477. formatted2 = moment(i, 'YYYY-MM-DD').format('GG');
  34478. assert.equal(isoWeekYear.slice(2, 4), formatted2, i + ': GG should be ' + isoWeekYear + ', but ' + formatted2);
  34479. }
  34480. });
  34481. test('week year formats', function (assert) {
  34482. // http://en.wikipedia.org/wiki/ISO_week_date
  34483. var cases = {
  34484. '2005-01-02': '2004-53',
  34485. '2005-12-31': '2005-52',
  34486. '2007-01-01': '2007-01',
  34487. '2007-12-30': '2007-52',
  34488. '2007-12-31': '2008-01',
  34489. '2008-01-01': '2008-01',
  34490. '2008-12-28': '2008-52',
  34491. '2008-12-29': '2009-01',
  34492. '2008-12-30': '2009-01',
  34493. '2008-12-31': '2009-01',
  34494. '2009-01-01': '2009-01',
  34495. '2009-12-31': '2009-53',
  34496. '2010-01-01': '2009-53',
  34497. '2010-01-02': '2009-53',
  34498. '2010-01-03': '2009-53',
  34499. '404-12-31': '0404-53',
  34500. '405-12-31': '0405-52'
  34501. }, i, isoWeekYear, formatted5, formatted4, formatted2;
  34502. moment.locale('dow:1,doy:4', {week: {dow: 1, doy: 4}});
  34503. for (i in cases) {
  34504. isoWeekYear = cases[i].split('-')[0];
  34505. formatted5 = moment(i, 'YYYY-MM-DD').format('ggggg');
  34506. assert.equal('0' + isoWeekYear, formatted5, i + ': ggggg should be ' + isoWeekYear + ', but ' + formatted5);
  34507. formatted4 = moment(i, 'YYYY-MM-DD').format('gggg');
  34508. assert.equal(isoWeekYear, formatted4, i + ': gggg should be ' + isoWeekYear + ', but ' + formatted4);
  34509. formatted2 = moment(i, 'YYYY-MM-DD').format('gg');
  34510. assert.equal(isoWeekYear.slice(2, 4), formatted2, i + ': gg should be ' + isoWeekYear + ', but ' + formatted2);
  34511. }
  34512. });
  34513. test('iso weekday formats', function (assert) {
  34514. assert.equal(moment([1985, 1, 4]).format('E'), '1', 'Feb 4 1985 is Monday -- 1st day');
  34515. assert.equal(moment([2029, 8, 18]).format('E'), '2', 'Sep 18 2029 is Tuesday -- 2nd day');
  34516. assert.equal(moment([2013, 3, 24]).format('E'), '3', 'Apr 24 2013 is Wednesday -- 3rd day');
  34517. assert.equal(moment([2015, 2, 5]).format('E'), '4', 'Mar 5 2015 is Thursday -- 4th day');
  34518. assert.equal(moment([1970, 0, 2]).format('E'), '5', 'Jan 2 1970 is Friday -- 5th day');
  34519. assert.equal(moment([2001, 4, 12]).format('E'), '6', 'May 12 2001 is Saturday -- 6th day');
  34520. assert.equal(moment([2000, 0, 2]).format('E'), '7', 'Jan 2 2000 is Sunday -- 7th day');
  34521. });
  34522. test('weekday formats', function (assert) {
  34523. moment.locale('dow: 3,doy: 5', {week: {dow: 3, doy: 5}});
  34524. assert.equal(moment([1985, 1, 6]).format('e'), '0', 'Feb 6 1985 is Wednesday -- 0th day');
  34525. assert.equal(moment([2029, 8, 20]).format('e'), '1', 'Sep 20 2029 is Thursday -- 1st day');
  34526. assert.equal(moment([2013, 3, 26]).format('e'), '2', 'Apr 26 2013 is Friday -- 2nd day');
  34527. assert.equal(moment([2015, 2, 7]).format('e'), '3', 'Mar 7 2015 is Saturday -- 3nd day');
  34528. assert.equal(moment([1970, 0, 4]).format('e'), '4', 'Jan 4 1970 is Sunday -- 4th day');
  34529. assert.equal(moment([2001, 4, 14]).format('e'), '5', 'May 14 2001 is Monday -- 5th day');
  34530. assert.equal(moment([2000, 0, 4]).format('e'), '6', 'Jan 4 2000 is Tuesday -- 6th day');
  34531. });
  34532. test('toString is just human readable format', function (assert) {
  34533. var b = moment(new Date(2009, 1, 5, 15, 25, 50, 125));
  34534. assert.equal(b.toString(), b.format('ddd MMM DD YYYY HH:mm:ss [GMT]ZZ'));
  34535. });
  34536. test('toJSON skips postformat', function (assert) {
  34537. moment.locale('postformat', {
  34538. postformat: function (s) {
  34539. s.replace(/./g, 'X');
  34540. }
  34541. });
  34542. assert.equal(moment.utc([2000, 0, 1]).toJSON(), '2000-01-01T00:00:00.000Z', 'toJSON doesn\'t postformat');
  34543. moment.locale('postformat', null);
  34544. });
  34545. test('calendar day timezone', function (assert) {
  34546. moment.locale('en');
  34547. var zones = [60, -60, 90, -90, 360, -360, 720, -720],
  34548. b = moment().utc().startOf('day').subtract({m : 1}),
  34549. c = moment().local().startOf('day').subtract({m : 1}),
  34550. d = moment().local().startOf('day').subtract({d : 2}),
  34551. i, z, a;
  34552. for (i = 0; i < zones.length; ++i) {
  34553. z = zones[i];
  34554. a = moment().utcOffset(z).startOf('day').subtract({m: 1});
  34555. assert.equal(moment(a).utcOffset(z).calendar(), 'Yesterday at 11:59 PM',
  34556. 'Yesterday at 11:59 PM, not Today, or the wrong time, tz = ' + z);
  34557. }
  34558. assert.equal(moment(b).utc().calendar(), 'Yesterday at 11:59 PM', 'Yesterday at 11:59 PM, not Today, or the wrong time');
  34559. assert.equal(moment(c).local().calendar(), 'Yesterday at 11:59 PM', 'Yesterday at 11:59 PM, not Today, or the wrong time');
  34560. assert.equal(moment(c).local().calendar(d), 'Tomorrow at 11:59 PM', 'Tomorrow at 11:59 PM, not Yesterday, or the wrong time');
  34561. });
  34562. test('calendar with custom formats', function (assert) {
  34563. assert.equal(moment().calendar(null, {sameDay: '[Today]'}), 'Today', 'Today');
  34564. assert.equal(moment().add(1, 'days').calendar(null, {nextDay: '[Tomorrow]'}), 'Tomorrow', 'Tomorrow');
  34565. assert.equal(moment([1985, 1, 4]).calendar(null, {sameElse: 'YYYY-MM-DD'}), '1985-02-04', 'Else');
  34566. });
  34567. test('invalid', function (assert) {
  34568. assert.equal(moment.invalid().format(), 'Invalid date');
  34569. assert.equal(moment.invalid().format('YYYY-MM-DD'), 'Invalid date');
  34570. });
  34571. test('quarter formats', function (assert) {
  34572. assert.equal(moment([1985, 1, 4]).format('Q'), '1', 'Feb 4 1985 is Q1');
  34573. assert.equal(moment([2029, 8, 18]).format('Q'), '3', 'Sep 18 2029 is Q3');
  34574. assert.equal(moment([2013, 3, 24]).format('Q'), '2', 'Apr 24 2013 is Q2');
  34575. assert.equal(moment([2015, 2, 5]).format('Q'), '1', 'Mar 5 2015 is Q1');
  34576. assert.equal(moment([1970, 0, 2]).format('Q'), '1', 'Jan 2 1970 is Q1');
  34577. assert.equal(moment([2001, 11, 12]).format('Q'), '4', 'Dec 12 2001 is Q4');
  34578. assert.equal(moment([2000, 0, 2]).format('[Q]Q-YYYY'), 'Q1-2000', 'Jan 2 2000 is Q1');
  34579. });
  34580. test('quarter ordinal formats', function (assert) {
  34581. assert.equal(moment([1985, 1, 4]).format('Qo'), '1st', 'Feb 4 1985 is 1st quarter');
  34582. assert.equal(moment([2029, 8, 18]).format('Qo'), '3rd', 'Sep 18 2029 is 3rd quarter');
  34583. assert.equal(moment([2013, 3, 24]).format('Qo'), '2nd', 'Apr 24 2013 is 2nd quarter');
  34584. assert.equal(moment([2015, 2, 5]).format('Qo'), '1st', 'Mar 5 2015 is 1st quarter');
  34585. assert.equal(moment([1970, 0, 2]).format('Qo'), '1st', 'Jan 2 1970 is 1st quarter');
  34586. assert.equal(moment([2001, 11, 12]).format('Qo'), '4th', 'Dec 12 2001 is 4th quarter');
  34587. assert.equal(moment([2000, 0, 2]).format('Qo [quarter] YYYY'), '1st quarter 2000', 'Jan 2 2000 is 1st quarter');
  34588. });
  34589. test('full expanded format is returned from abbreviated formats', function (assert) {
  34590. function forEach(ar, fn) {
  34591. if (ar.forEach) {
  34592. return ar.forEach(fn);
  34593. } else {
  34594. // IE8
  34595. for (var i = 0; i < ar.length; i += 1) {
  34596. fn(ar[i]);
  34597. }
  34598. }
  34599. }
  34600. function objectKeys(obj) {
  34601. if (Object.keys) {
  34602. return Object.keys(obj);
  34603. } else {
  34604. // IE8
  34605. var res = [], i;
  34606. for (i in obj) {
  34607. if (obj.hasOwnProperty(i)) {
  34608. res.push(i);
  34609. }
  34610. }
  34611. return res;
  34612. }
  34613. }
  34614. var locales =
  34615. 'ar-sa ar-tn ar az be bg bn bo br bs ca cs cv cy da de-at de dv el ' +
  34616. 'en-au en-ca en-gb en-ie en-nz eo es et eu fa fi fo fr-ca fr-ch fr fy ' +
  34617. 'gd gl he hi hr hu hy-am id is it ja jv ka kk km ko lb lo lt lv me mk ml ' +
  34618. 'mr ms-my ms my nb ne nl nn pl pt-br pt ro ru se si sk sl sq sr-cyrl ' +
  34619. 'sr sv sw ta te th tl-ph tlh tr tzl tzm-latn tzm uk uz vi zh-cn zh-tw';
  34620. forEach(locales.split(' '), function (locale) {
  34621. var data, tokens;
  34622. data = moment().locale(locale).localeData()._longDateFormat;
  34623. tokens = objectKeys(data);
  34624. forEach(tokens, function (token) {
  34625. // Check each format string to make sure it does not contain any
  34626. // tokens that need to be expanded.
  34627. forEach(tokens, function (i) {
  34628. // strip escaped sequences
  34629. var format = data[i].replace(/(\[[^\]]*\])/g, '');
  34630. assert.equal(false, !!~format.indexOf(token), 'locale ' + locale + ' contains ' + token + ' in ' + i);
  34631. });
  34632. });
  34633. });
  34634. });
  34635. test('milliseconds', function (assert) {
  34636. var m = moment('123', 'SSS');
  34637. assert.equal(m.format('S'), '1');
  34638. assert.equal(m.format('SS'), '12');
  34639. assert.equal(m.format('SSS'), '123');
  34640. assert.equal(m.format('SSSS'), '1230');
  34641. assert.equal(m.format('SSSSS'), '12300');
  34642. assert.equal(m.format('SSSSSS'), '123000');
  34643. assert.equal(m.format('SSSSSSS'), '1230000');
  34644. assert.equal(m.format('SSSSSSSS'), '12300000');
  34645. assert.equal(m.format('SSSSSSSSS'), '123000000');
  34646. });
  34647. test('hmm and hmmss', function (assert) {
  34648. assert.equal(moment('12:34:56', 'HH:mm:ss').format('hmm'), '1234');
  34649. assert.equal(moment('01:34:56', 'HH:mm:ss').format('hmm'), '134');
  34650. assert.equal(moment('13:34:56', 'HH:mm:ss').format('hmm'), '134');
  34651. assert.equal(moment('12:34:56', 'HH:mm:ss').format('hmmss'), '123456');
  34652. assert.equal(moment('01:34:56', 'HH:mm:ss').format('hmmss'), '13456');
  34653. assert.equal(moment('13:34:56', 'HH:mm:ss').format('hmmss'), '13456');
  34654. });
  34655. test('Hmm and Hmmss', function (assert) {
  34656. assert.equal(moment('12:34:56', 'HH:mm:ss').format('Hmm'), '1234');
  34657. assert.equal(moment('01:34:56', 'HH:mm:ss').format('Hmm'), '134');
  34658. assert.equal(moment('13:34:56', 'HH:mm:ss').format('Hmm'), '1334');
  34659. assert.equal(moment('12:34:56', 'HH:mm:ss').format('Hmmss'), '123456');
  34660. assert.equal(moment('01:34:56', 'HH:mm:ss').format('Hmmss'), '13456');
  34661. assert.equal(moment('08:34:56', 'HH:mm:ss').format('Hmmss'), '83456');
  34662. assert.equal(moment('18:34:56', 'HH:mm:ss').format('Hmmss'), '183456');
  34663. });
  34664. test('Y token', function (assert) {
  34665. assert.equal(moment('2010-01-01', 'YYYY-MM-DD', true).format('Y'), '2010', 'format 2010 with Y');
  34666. assert.equal(moment('-123-01-01', 'Y-MM-DD', true).format('Y'), '-123', 'format -123 with Y');
  34667. assert.equal(moment('12345-01-01', 'Y-MM-DD', true).format('Y'), '+12345', 'format 12345 with Y');
  34668. assert.equal(moment('0-01-01', 'Y-MM-DD', true).format('Y'), '0', 'format 0 with Y');
  34669. assert.equal(moment('1-01-01', 'Y-MM-DD', true).format('Y'), '1', 'format 1 with Y');
  34670. assert.equal(moment('9999-01-01', 'Y-MM-DD', true).format('Y'), '9999', 'format 9999 with Y');
  34671. assert.equal(moment('10000-01-01', 'Y-MM-DD', true).format('Y'), '+10000', 'format 10000 with Y');
  34672. });
  34673. }));
  34674. ;(function (global, factory) {
  34675. typeof exports === 'object' && typeof module !== 'undefined'
  34676. && typeof require === 'function' ? factory(require('../../moment')) :
  34677. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  34678. factory(global.moment)
  34679. }(this, function (moment) { 'use strict';
  34680. /*global QUnit:false*/
  34681. var test = QUnit.test;
  34682. var expect = QUnit.expect;
  34683. function module (name, lifecycle) {
  34684. QUnit.module(name, {
  34685. setup : function () {
  34686. moment.locale('en');
  34687. moment.createFromInputFallback = function (config) {
  34688. throw new Error('input not handled by moment: ' + config._i);
  34689. };
  34690. if (lifecycle && lifecycle.setup) {
  34691. lifecycle.setup();
  34692. }
  34693. },
  34694. teardown : function () {
  34695. if (lifecycle && lifecycle.teardown) {
  34696. lifecycle.teardown();
  34697. }
  34698. }
  34699. });
  34700. }
  34701. function localeModule (name, lifecycle) {
  34702. QUnit.module('locale:' + name, {
  34703. setup : function () {
  34704. moment.locale(name);
  34705. moment.createFromInputFallback = function (config) {
  34706. throw new Error('input not handled by moment: ' + config._i);
  34707. };
  34708. if (lifecycle && lifecycle.setup) {
  34709. lifecycle.setup();
  34710. }
  34711. },
  34712. teardown : function () {
  34713. moment.locale('en');
  34714. if (lifecycle && lifecycle.teardown) {
  34715. lifecycle.teardown();
  34716. }
  34717. }
  34718. });
  34719. }
  34720. module('from_to');
  34721. test('from', function (assert) {
  34722. var start = moment();
  34723. moment.locale('en');
  34724. assert.equal(start.from(start.clone().add(5, 'seconds')), 'a few seconds ago', '5 seconds = a few seconds ago');
  34725. assert.equal(start.from(start.clone().add(1, 'minute')), 'a minute ago', '1 minute = a minute ago');
  34726. assert.equal(start.from(start.clone().add(5, 'minutes')), '5 minutes ago', '5 minutes = 5 minutes ago');
  34727. assert.equal(start.from(start.clone().subtract(5, 'seconds')), 'in a few seconds', '5 seconds = in a few seconds');
  34728. assert.equal(start.from(start.clone().subtract(1, 'minute')), 'in a minute', '1 minute = in a minute');
  34729. assert.equal(start.from(start.clone().subtract(5, 'minutes')), 'in 5 minutes', '5 minutes = in 5 minutes');
  34730. });
  34731. test('from with absolute duration', function (assert) {
  34732. var start = moment();
  34733. moment.locale('en');
  34734. assert.equal(start.from(start.clone().add(5, 'seconds'), true), 'a few seconds', '5 seconds = a few seconds');
  34735. assert.equal(start.from(start.clone().add(1, 'minute'), true), 'a minute', '1 minute = a minute');
  34736. assert.equal(start.from(start.clone().add(5, 'minutes'), true), '5 minutes', '5 minutes = 5 minutes');
  34737. assert.equal(start.from(start.clone().subtract(5, 'seconds'), true), 'a few seconds', '5 seconds = a few seconds');
  34738. assert.equal(start.from(start.clone().subtract(1, 'minute'), true), 'a minute', '1 minute = a minute');
  34739. assert.equal(start.from(start.clone().subtract(5, 'minutes'), true), '5 minutes', '5 minutes = 5 minutes');
  34740. });
  34741. test('to', function (assert) {
  34742. var start = moment();
  34743. moment.locale('en');
  34744. assert.equal(start.to(start.clone().subtract(5, 'seconds')), 'a few seconds ago', '5 seconds = a few seconds ago');
  34745. assert.equal(start.to(start.clone().subtract(1, 'minute')), 'a minute ago', '1 minute = a minute ago');
  34746. assert.equal(start.to(start.clone().subtract(5, 'minutes')), '5 minutes ago', '5 minutes = 5 minutes ago');
  34747. assert.equal(start.to(start.clone().add(5, 'seconds')), 'in a few seconds', '5 seconds = in a few seconds');
  34748. assert.equal(start.to(start.clone().add(1, 'minute')), 'in a minute', '1 minute = in a minute');
  34749. assert.equal(start.to(start.clone().add(5, 'minutes')), 'in 5 minutes', '5 minutes = in 5 minutes');
  34750. });
  34751. test('to with absolute duration', function (assert) {
  34752. var start = moment();
  34753. moment.locale('en');
  34754. assert.equal(start.to(start.clone().add(5, 'seconds'), true), 'a few seconds', '5 seconds = a few seconds');
  34755. assert.equal(start.to(start.clone().add(1, 'minute'), true), 'a minute', '1 minute = a minute');
  34756. assert.equal(start.to(start.clone().add(5, 'minutes'), true), '5 minutes', '5 minutes = 5 minutes');
  34757. assert.equal(start.to(start.clone().subtract(5, 'seconds'), true), 'a few seconds', '5 seconds = a few seconds');
  34758. assert.equal(start.to(start.clone().subtract(1, 'minute'), true), 'a minute', '1 minute = a minute');
  34759. assert.equal(start.to(start.clone().subtract(5, 'minutes'), true), '5 minutes', '5 minutes = 5 minutes');
  34760. });
  34761. }));
  34762. ;(function (global, factory) {
  34763. typeof exports === 'object' && typeof module !== 'undefined'
  34764. && typeof require === 'function' ? factory(require('../../moment')) :
  34765. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  34766. factory(global.moment)
  34767. }(this, function (moment) { 'use strict';
  34768. /*global QUnit:false*/
  34769. var test = QUnit.test;
  34770. var expect = QUnit.expect;
  34771. function module (name, lifecycle) {
  34772. QUnit.module(name, {
  34773. setup : function () {
  34774. moment.locale('en');
  34775. moment.createFromInputFallback = function (config) {
  34776. throw new Error('input not handled by moment: ' + config._i);
  34777. };
  34778. if (lifecycle && lifecycle.setup) {
  34779. lifecycle.setup();
  34780. }
  34781. },
  34782. teardown : function () {
  34783. if (lifecycle && lifecycle.teardown) {
  34784. lifecycle.teardown();
  34785. }
  34786. }
  34787. });
  34788. }
  34789. function localeModule (name, lifecycle) {
  34790. QUnit.module('locale:' + name, {
  34791. setup : function () {
  34792. moment.locale(name);
  34793. moment.createFromInputFallback = function (config) {
  34794. throw new Error('input not handled by moment: ' + config._i);
  34795. };
  34796. if (lifecycle && lifecycle.setup) {
  34797. lifecycle.setup();
  34798. }
  34799. },
  34800. teardown : function () {
  34801. moment.locale('en');
  34802. if (lifecycle && lifecycle.teardown) {
  34803. lifecycle.teardown();
  34804. }
  34805. }
  34806. });
  34807. }
  34808. module('getters and setters');
  34809. test('getters', function (assert) {
  34810. var a = moment([2011, 9, 12, 6, 7, 8, 9]);
  34811. assert.equal(a.year(), 2011, 'year');
  34812. assert.equal(a.month(), 9, 'month');
  34813. assert.equal(a.date(), 12, 'date');
  34814. assert.equal(a.day(), 3, 'day');
  34815. assert.equal(a.hours(), 6, 'hour');
  34816. assert.equal(a.minutes(), 7, 'minute');
  34817. assert.equal(a.seconds(), 8, 'second');
  34818. assert.equal(a.milliseconds(), 9, 'milliseconds');
  34819. });
  34820. test('getters programmatic', function (assert) {
  34821. var a = moment([2011, 9, 12, 6, 7, 8, 9]);
  34822. assert.equal(a.get('year'), 2011, 'year');
  34823. assert.equal(a.get('month'), 9, 'month');
  34824. assert.equal(a.get('date'), 12, 'date');
  34825. assert.equal(a.get('day'), 3, 'day');
  34826. assert.equal(a.get('hour'), 6, 'hour');
  34827. assert.equal(a.get('minute'), 7, 'minute');
  34828. assert.equal(a.get('second'), 8, 'second');
  34829. assert.equal(a.get('milliseconds'), 9, 'milliseconds');
  34830. //actual getters tested elsewhere
  34831. assert.equal(a.get('weekday'), a.weekday(), 'weekday');
  34832. assert.equal(a.get('isoWeekday'), a.isoWeekday(), 'isoWeekday');
  34833. assert.equal(a.get('week'), a.week(), 'week');
  34834. assert.equal(a.get('isoWeek'), a.isoWeek(), 'isoWeek');
  34835. assert.equal(a.get('dayOfYear'), a.dayOfYear(), 'dayOfYear');
  34836. });
  34837. test('setters plural', function (assert) {
  34838. var a = moment();
  34839. a.years(2011);
  34840. a.months(9);
  34841. a.dates(12);
  34842. a.hours(6);
  34843. a.minutes(7);
  34844. a.seconds(8);
  34845. a.milliseconds(9);
  34846. assert.equal(a.years(), 2011, 'years');
  34847. assert.equal(a.months(), 9, 'months');
  34848. assert.equal(a.dates(), 12, 'dates');
  34849. assert.equal(a.days(), 3, 'days');
  34850. assert.equal(a.hours(), 6, 'hours');
  34851. assert.equal(a.minutes(), 7, 'minutes');
  34852. assert.equal(a.seconds(), 8, 'seconds');
  34853. assert.equal(a.milliseconds(), 9, 'milliseconds');
  34854. });
  34855. test('setters singular', function (assert) {
  34856. var a = moment();
  34857. a.year(2011);
  34858. a.month(9);
  34859. a.date(12);
  34860. a.hour(6);
  34861. a.minute(7);
  34862. a.second(8);
  34863. a.millisecond(9);
  34864. assert.equal(a.year(), 2011, 'year');
  34865. assert.equal(a.month(), 9, 'month');
  34866. assert.equal(a.date(), 12, 'date');
  34867. assert.equal(a.day(), 3, 'day');
  34868. assert.equal(a.hour(), 6, 'hour');
  34869. assert.equal(a.minute(), 7, 'minute');
  34870. assert.equal(a.second(), 8, 'second');
  34871. assert.equal(a.millisecond(), 9, 'milliseconds');
  34872. });
  34873. test('setters', function (assert) {
  34874. var a = moment();
  34875. a.year(2011);
  34876. a.month(9);
  34877. a.date(12);
  34878. a.hours(6);
  34879. a.minutes(7);
  34880. a.seconds(8);
  34881. a.milliseconds(9);
  34882. assert.equal(a.year(), 2011, 'year');
  34883. assert.equal(a.month(), 9, 'month');
  34884. assert.equal(a.date(), 12, 'date');
  34885. assert.equal(a.day(), 3, 'day');
  34886. assert.equal(a.hours(), 6, 'hour');
  34887. assert.equal(a.minutes(), 7, 'minute');
  34888. assert.equal(a.seconds(), 8, 'second');
  34889. assert.equal(a.milliseconds(), 9, 'milliseconds');
  34890. // Test month() behavior. See https://github.com/timrwood/moment/pull/822
  34891. a = moment('20130531', 'YYYYMMDD');
  34892. a.month(3);
  34893. assert.equal(a.month(), 3, 'month edge case');
  34894. });
  34895. test('setter programmatic', function (assert) {
  34896. var a = moment();
  34897. a.set('year', 2011);
  34898. a.set('month', 9);
  34899. a.set('date', 12);
  34900. a.set('hours', 6);
  34901. a.set('minutes', 7);
  34902. a.set('seconds', 8);
  34903. a.set('milliseconds', 9);
  34904. assert.equal(a.year(), 2011, 'year');
  34905. assert.equal(a.month(), 9, 'month');
  34906. assert.equal(a.date(), 12, 'date');
  34907. assert.equal(a.day(), 3, 'day');
  34908. assert.equal(a.hours(), 6, 'hour');
  34909. assert.equal(a.minutes(), 7, 'minute');
  34910. assert.equal(a.seconds(), 8, 'second');
  34911. assert.equal(a.milliseconds(), 9, 'milliseconds');
  34912. // Test month() behavior. See https://github.com/timrwood/moment/pull/822
  34913. a = moment('20130531', 'YYYYMMDD');
  34914. a.month(3);
  34915. assert.equal(a.month(), 3, 'month edge case');
  34916. });
  34917. // Disable this, until we weekYear setter is fixed.
  34918. // https://github.com/moment/moment/issues/1379
  34919. // test('setters programatic with weeks', function (assert) {
  34920. // var a = moment();
  34921. // a.set('weekYear', 2001);
  34922. // a.set('week', 49);
  34923. // a.set('day', 4);
  34924. // assert.equals(a.weekYear(), 2001);
  34925. // assert.equals(a.week(), 49);
  34926. // assert.equals(a.day(), 4);
  34927. // a.set('weekday', 1);
  34928. // assert.equals(a.weekday(), 1);
  34929. // assert.done();
  34930. //},
  34931. // I think this suffers from the same issue as the non-iso version.
  34932. // test('setters programatic with weeks ISO', function (assert) {
  34933. // var a = moment();
  34934. // a.set('isoWeekYear', 2001);
  34935. // a.set('isoWeek', 49);
  34936. // a.set('isoWeekday', 4);
  34937. // assert.equals(a.weekYear(), 2001);
  34938. // assert.equals(a.week(), 49);
  34939. // assert.equals(a.day(), 4);
  34940. // assert.done();
  34941. //},
  34942. test('setters strings', function (assert) {
  34943. var a = moment([2012]).locale('en');
  34944. assert.equal(a.clone().day(0).day('Wednesday').day(), 3, 'day full name');
  34945. assert.equal(a.clone().day(0).day('Wed').day(), 3, 'day short name');
  34946. assert.equal(a.clone().day(0).day('We').day(), 3, 'day minimal name');
  34947. assert.equal(a.clone().day(0).day('invalid').day(), 0, 'invalid day name');
  34948. assert.equal(a.clone().month(0).month('April').month(), 3, 'month full name');
  34949. assert.equal(a.clone().month(0).month('Apr').month(), 3, 'month short name');
  34950. assert.equal(a.clone().month(0).month('invalid').month(), 0, 'invalid month name');
  34951. });
  34952. test('setters - falsey values', function (assert) {
  34953. var a = moment();
  34954. // ensure minutes wasn't coincidentally 0 already
  34955. a.minutes(1);
  34956. a.minutes(0);
  34957. assert.equal(a.minutes(), 0, 'falsey value');
  34958. });
  34959. test('chaining setters', function (assert) {
  34960. var a = moment();
  34961. a.year(2011)
  34962. .month(9)
  34963. .date(12)
  34964. .hours(6)
  34965. .minutes(7)
  34966. .seconds(8);
  34967. assert.equal(a.year(), 2011, 'year');
  34968. assert.equal(a.month(), 9, 'month');
  34969. assert.equal(a.date(), 12, 'date');
  34970. assert.equal(a.day(), 3, 'day');
  34971. assert.equal(a.hours(), 6, 'hour');
  34972. assert.equal(a.minutes(), 7, 'minute');
  34973. assert.equal(a.seconds(), 8, 'second');
  34974. });
  34975. test('setter with multiple unit values', function (assert) {
  34976. var a = moment();
  34977. a.set({
  34978. year: 2011,
  34979. month: 9,
  34980. date: 12,
  34981. hours: 6,
  34982. minutes: 7,
  34983. seconds: 8,
  34984. milliseconds: 9
  34985. });
  34986. assert.equal(a.year(), 2011, 'year');
  34987. assert.equal(a.month(), 9, 'month');
  34988. assert.equal(a.date(), 12, 'date');
  34989. assert.equal(a.day(), 3, 'day');
  34990. assert.equal(a.hours(), 6, 'hour');
  34991. assert.equal(a.minutes(), 7, 'minute');
  34992. assert.equal(a.seconds(), 8, 'second');
  34993. assert.equal(a.milliseconds(), 9, 'milliseconds');
  34994. });
  34995. test('day setter', function (assert) {
  34996. var a = moment([2011, 0, 15]);
  34997. assert.equal(moment(a).day(0).date(), 9, 'set from saturday to sunday');
  34998. assert.equal(moment(a).day(6).date(), 15, 'set from saturday to saturday');
  34999. assert.equal(moment(a).day(3).date(), 12, 'set from saturday to wednesday');
  35000. a = moment([2011, 0, 9]);
  35001. assert.equal(moment(a).day(0).date(), 9, 'set from sunday to sunday');
  35002. assert.equal(moment(a).day(6).date(), 15, 'set from sunday to saturday');
  35003. assert.equal(moment(a).day(3).date(), 12, 'set from sunday to wednesday');
  35004. a = moment([2011, 0, 12]);
  35005. assert.equal(moment(a).day(0).date(), 9, 'set from wednesday to sunday');
  35006. assert.equal(moment(a).day(6).date(), 15, 'set from wednesday to saturday');
  35007. assert.equal(moment(a).day(3).date(), 12, 'set from wednesday to wednesday');
  35008. assert.equal(moment(a).day(-7).date(), 2, 'set from wednesday to last sunday');
  35009. assert.equal(moment(a).day(-1).date(), 8, 'set from wednesday to last saturday');
  35010. assert.equal(moment(a).day(-4).date(), 5, 'set from wednesday to last wednesday');
  35011. assert.equal(moment(a).day(7).date(), 16, 'set from wednesday to next sunday');
  35012. assert.equal(moment(a).day(13).date(), 22, 'set from wednesday to next saturday');
  35013. assert.equal(moment(a).day(10).date(), 19, 'set from wednesday to next wednesday');
  35014. assert.equal(moment(a).day(14).date(), 23, 'set from wednesday to second next sunday');
  35015. assert.equal(moment(a).day(20).date(), 29, 'set from wednesday to second next saturday');
  35016. assert.equal(moment(a).day(17).date(), 26, 'set from wednesday to second next wednesday');
  35017. });
  35018. }));
  35019. ;(function (global, factory) {
  35020. typeof exports === 'object' && typeof module !== 'undefined'
  35021. && typeof require === 'function' ? factory(require('../../moment')) :
  35022. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  35023. factory(global.moment)
  35024. }(this, function (moment) { 'use strict';
  35025. /*global QUnit:false*/
  35026. var test = QUnit.test;
  35027. var expect = QUnit.expect;
  35028. function module (name, lifecycle) {
  35029. QUnit.module(name, {
  35030. setup : function () {
  35031. moment.locale('en');
  35032. moment.createFromInputFallback = function (config) {
  35033. throw new Error('input not handled by moment: ' + config._i);
  35034. };
  35035. if (lifecycle && lifecycle.setup) {
  35036. lifecycle.setup();
  35037. }
  35038. },
  35039. teardown : function () {
  35040. if (lifecycle && lifecycle.teardown) {
  35041. lifecycle.teardown();
  35042. }
  35043. }
  35044. });
  35045. }
  35046. function localeModule (name, lifecycle) {
  35047. QUnit.module('locale:' + name, {
  35048. setup : function () {
  35049. moment.locale(name);
  35050. moment.createFromInputFallback = function (config) {
  35051. throw new Error('input not handled by moment: ' + config._i);
  35052. };
  35053. if (lifecycle && lifecycle.setup) {
  35054. lifecycle.setup();
  35055. }
  35056. },
  35057. teardown : function () {
  35058. moment.locale('en');
  35059. if (lifecycle && lifecycle.teardown) {
  35060. lifecycle.teardown();
  35061. }
  35062. }
  35063. });
  35064. }
  35065. module('instanceof');
  35066. test('instanceof', function (assert) {
  35067. var mm = moment([2010, 0, 1]);
  35068. var extend = function (a, b) {
  35069. var i;
  35070. for (i in b) {
  35071. a[i] = b[i];
  35072. }
  35073. return a;
  35074. };
  35075. assert.equal(moment() instanceof moment, true, 'simple moment object');
  35076. assert.equal(extend({}, moment()) instanceof moment, false, 'extended moment object');
  35077. assert.equal(moment(null) instanceof moment, true, 'invalid moment object');
  35078. assert.equal(new Date() instanceof moment, false, 'date object is not moment object');
  35079. assert.equal(Object instanceof moment, false, 'Object is not moment object');
  35080. assert.equal('foo' instanceof moment, false, 'string is not moment object');
  35081. assert.equal(1 instanceof moment, false, 'number is not moment object');
  35082. assert.equal(NaN instanceof moment, false, 'NaN is not moment object');
  35083. assert.equal(null instanceof moment, false, 'null is not moment object');
  35084. assert.equal(undefined instanceof moment, false, 'undefined is not moment object');
  35085. });
  35086. }));
  35087. ;(function (global, factory) {
  35088. typeof exports === 'object' && typeof module !== 'undefined'
  35089. && typeof require === 'function' ? factory(require('../../moment')) :
  35090. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  35091. factory(global.moment)
  35092. }(this, function (moment) { 'use strict';
  35093. /*global QUnit:false*/
  35094. var test = QUnit.test;
  35095. var expect = QUnit.expect;
  35096. function module (name, lifecycle) {
  35097. QUnit.module(name, {
  35098. setup : function () {
  35099. moment.locale('en');
  35100. moment.createFromInputFallback = function (config) {
  35101. throw new Error('input not handled by moment: ' + config._i);
  35102. };
  35103. if (lifecycle && lifecycle.setup) {
  35104. lifecycle.setup();
  35105. }
  35106. },
  35107. teardown : function () {
  35108. if (lifecycle && lifecycle.teardown) {
  35109. lifecycle.teardown();
  35110. }
  35111. }
  35112. });
  35113. }
  35114. function localeModule (name, lifecycle) {
  35115. QUnit.module('locale:' + name, {
  35116. setup : function () {
  35117. moment.locale(name);
  35118. moment.createFromInputFallback = function (config) {
  35119. throw new Error('input not handled by moment: ' + config._i);
  35120. };
  35121. if (lifecycle && lifecycle.setup) {
  35122. lifecycle.setup();
  35123. }
  35124. },
  35125. teardown : function () {
  35126. moment.locale('en');
  35127. if (lifecycle && lifecycle.teardown) {
  35128. lifecycle.teardown();
  35129. }
  35130. }
  35131. });
  35132. }
  35133. module('invalid');
  35134. test('invalid', function (assert) {
  35135. var m = moment.invalid();
  35136. assert.equal(m.isValid(), false);
  35137. assert.equal(m.parsingFlags().userInvalidated, true);
  35138. assert.ok(isNaN(m.valueOf()));
  35139. });
  35140. test('invalid with existing flag', function (assert) {
  35141. var m = moment.invalid({invalidMonth : 'whatchamacallit'});
  35142. assert.equal(m.isValid(), false);
  35143. assert.equal(m.parsingFlags().userInvalidated, false);
  35144. assert.equal(m.parsingFlags().invalidMonth, 'whatchamacallit');
  35145. assert.ok(isNaN(m.valueOf()));
  35146. });
  35147. test('invalid with custom flag', function (assert) {
  35148. var m = moment.invalid({tooBusyWith : 'reiculating splines'});
  35149. assert.equal(m.isValid(), false);
  35150. assert.equal(m.parsingFlags().userInvalidated, false);
  35151. assert.equal(m.parsingFlags().tooBusyWith, 'reiculating splines');
  35152. assert.ok(isNaN(m.valueOf()));
  35153. });
  35154. test('invalid operations', function (assert) {
  35155. var invalids = [
  35156. moment.invalid(),
  35157. moment('xyz', 'l'),
  35158. moment('2015-01-35', 'YYYY-MM-DD'),
  35159. moment('2015-01-25 a', 'YYYY-MM-DD', true)
  35160. ],
  35161. i,
  35162. invalid,
  35163. valid = moment();
  35164. for (i = 0; i < invalids.length; ++i) {
  35165. invalid = invalids[i];
  35166. assert.ok(!invalid.clone().add(5, 'hours').isValid(), 'invalid.add is invalid');
  35167. assert.equal(invalid.calendar(), 'Invalid date', 'invalid.calendar is \'Invalid date\'');
  35168. assert.ok(!invalid.clone().isValid(), 'invalid.clone is invalid');
  35169. assert.ok(isNaN(invalid.diff(valid)), 'invalid.diff(valid) is NaN');
  35170. assert.ok(isNaN(valid.diff(invalid)), 'valid.diff(invalid) is NaN');
  35171. assert.ok(isNaN(invalid.diff(invalid)), 'invalid.diff(invalid) is NaN');
  35172. assert.ok(!invalid.clone().endOf('month').isValid(), 'invalid.endOf is invalid');
  35173. assert.equal(invalid.format(), 'Invalid date', 'invalid.format is \'Invalid date\'');
  35174. assert.equal(invalid.from(), 'Invalid date');
  35175. assert.equal(invalid.from(valid), 'Invalid date');
  35176. assert.equal(valid.from(invalid), 'Invalid date');
  35177. assert.equal(invalid.fromNow(), 'Invalid date');
  35178. assert.equal(invalid.to(), 'Invalid date');
  35179. assert.equal(invalid.to(valid), 'Invalid date');
  35180. assert.equal(valid.to(invalid), 'Invalid date');
  35181. assert.equal(invalid.toNow(), 'Invalid date');
  35182. assert.ok(isNaN(invalid.get('year')), 'invalid.get is NaN');
  35183. // TODO invalidAt
  35184. assert.ok(!invalid.isAfter(valid));
  35185. assert.ok(!valid.isAfter(invalid));
  35186. assert.ok(!invalid.isAfter(invalid));
  35187. assert.ok(!invalid.isBefore(valid));
  35188. assert.ok(!valid.isBefore(invalid));
  35189. assert.ok(!invalid.isBefore(invalid));
  35190. assert.ok(!invalid.isBetween(valid, valid));
  35191. assert.ok(!valid.isBetween(invalid, valid));
  35192. assert.ok(!valid.isBetween(valid, invalid));
  35193. assert.ok(!invalid.isSame(invalid));
  35194. assert.ok(!invalid.isSame(valid));
  35195. assert.ok(!valid.isSame(invalid));
  35196. assert.ok(!invalid.isValid());
  35197. assert.equal(invalid.locale(), 'en');
  35198. assert.equal(invalid.localeData()._abbr, 'en');
  35199. assert.ok(!invalid.clone().max(valid).isValid());
  35200. assert.ok(!valid.clone().max(invalid).isValid());
  35201. assert.ok(!invalid.clone().max(invalid).isValid());
  35202. assert.ok(!invalid.clone().min(valid).isValid());
  35203. assert.ok(!valid.clone().min(invalid).isValid());
  35204. assert.ok(!invalid.clone().min(invalid).isValid());
  35205. assert.ok(!moment.min(invalid, valid).isValid());
  35206. assert.ok(!moment.min(valid, invalid).isValid());
  35207. assert.ok(!moment.max(invalid, valid).isValid());
  35208. assert.ok(!moment.max(valid, invalid).isValid());
  35209. assert.ok(!invalid.clone().set('year', 2005).isValid());
  35210. assert.ok(!invalid.clone().startOf('month').isValid());
  35211. assert.ok(!invalid.clone().subtract(5, 'days').isValid());
  35212. assert.deepEqual(invalid.toArray(), [NaN, NaN, NaN, NaN, NaN, NaN, NaN]);
  35213. assert.deepEqual(invalid.toObject(), {
  35214. years: NaN,
  35215. months: NaN,
  35216. date: NaN,
  35217. hours: NaN,
  35218. minutes: NaN,
  35219. seconds: NaN,
  35220. milliseconds: NaN
  35221. });
  35222. assert.ok(moment.isDate(invalid.toDate()));
  35223. assert.ok(isNaN(invalid.toDate().valueOf()));
  35224. assert.equal(invalid.toJSON(), 'null');
  35225. assert.equal(invalid.toString(), 'Invalid date');
  35226. assert.ok(isNaN(invalid.unix()));
  35227. assert.ok(isNaN(invalid.valueOf()));
  35228. assert.ok(isNaN(invalid.year()));
  35229. assert.ok(isNaN(invalid.weekYear()));
  35230. assert.ok(isNaN(invalid.isoWeekYear()));
  35231. assert.ok(isNaN(invalid.quarter()));
  35232. assert.ok(isNaN(invalid.quarters()));
  35233. assert.ok(isNaN(invalid.month()));
  35234. assert.ok(isNaN(invalid.daysInMonth()));
  35235. assert.ok(isNaN(invalid.week()));
  35236. assert.ok(isNaN(invalid.weeks()));
  35237. assert.ok(isNaN(invalid.isoWeek()));
  35238. assert.ok(isNaN(invalid.isoWeeks()));
  35239. assert.ok(isNaN(invalid.weeksInYear()));
  35240. assert.ok(isNaN(invalid.isoWeeksInYear()));
  35241. assert.ok(isNaN(invalid.date()));
  35242. assert.ok(isNaN(invalid.day()));
  35243. assert.ok(isNaN(invalid.days()));
  35244. assert.ok(isNaN(invalid.weekday()));
  35245. assert.ok(isNaN(invalid.isoWeekday()));
  35246. assert.ok(isNaN(invalid.dayOfYear()));
  35247. assert.ok(isNaN(invalid.hour()));
  35248. assert.ok(isNaN(invalid.hours()));
  35249. assert.ok(isNaN(invalid.minute()));
  35250. assert.ok(isNaN(invalid.minutes()));
  35251. assert.ok(isNaN(invalid.second()));
  35252. assert.ok(isNaN(invalid.seconds()));
  35253. assert.ok(isNaN(invalid.millisecond()));
  35254. assert.ok(isNaN(invalid.milliseconds()));
  35255. assert.ok(isNaN(invalid.utcOffset()));
  35256. assert.ok(!invalid.clone().year(2001).isValid());
  35257. assert.ok(!invalid.clone().weekYear(2001).isValid());
  35258. assert.ok(!invalid.clone().isoWeekYear(2001).isValid());
  35259. assert.ok(!invalid.clone().quarter(1).isValid());
  35260. assert.ok(!invalid.clone().quarters(1).isValid());
  35261. assert.ok(!invalid.clone().month(1).isValid());
  35262. assert.ok(!invalid.clone().week(1).isValid());
  35263. assert.ok(!invalid.clone().weeks(1).isValid());
  35264. assert.ok(!invalid.clone().isoWeek(1).isValid());
  35265. assert.ok(!invalid.clone().isoWeeks(1).isValid());
  35266. assert.ok(!invalid.clone().date(1).isValid());
  35267. assert.ok(!invalid.clone().day(1).isValid());
  35268. assert.ok(!invalid.clone().days(1).isValid());
  35269. assert.ok(!invalid.clone().weekday(1).isValid());
  35270. assert.ok(!invalid.clone().isoWeekday(1).isValid());
  35271. assert.ok(!invalid.clone().dayOfYear(1).isValid());
  35272. assert.ok(!invalid.clone().hour(1).isValid());
  35273. assert.ok(!invalid.clone().hours(1).isValid());
  35274. assert.ok(!invalid.clone().minute(1).isValid());
  35275. assert.ok(!invalid.clone().minutes(1).isValid());
  35276. assert.ok(!invalid.clone().second(1).isValid());
  35277. assert.ok(!invalid.clone().seconds(1).isValid());
  35278. assert.ok(!invalid.clone().millisecond(1).isValid());
  35279. assert.ok(!invalid.clone().milliseconds(1).isValid());
  35280. assert.ok(!invalid.clone().utcOffset(1).isValid());
  35281. assert.ok(!invalid.clone().utc().isValid());
  35282. assert.ok(!invalid.clone().local().isValid());
  35283. assert.ok(!invalid.clone().parseZone('05:30').isValid());
  35284. assert.ok(!invalid.hasAlignedHourOffset());
  35285. assert.ok(!invalid.isDST());
  35286. assert.ok(!invalid.isDSTShifted());
  35287. assert.ok(!invalid.isLocal());
  35288. assert.ok(!invalid.isUtcOffset());
  35289. assert.ok(!invalid.isUtc());
  35290. assert.ok(!invalid.isUTC());
  35291. assert.ok(!invalid.isLeapYear());
  35292. assert.equal(moment.duration({from: invalid, to: valid}).asMilliseconds(), 0);
  35293. assert.equal(moment.duration({from: valid, to: invalid}).asMilliseconds(), 0);
  35294. assert.equal(moment.duration({from: invalid, to: invalid}).asMilliseconds(), 0);
  35295. }
  35296. });
  35297. }));
  35298. ;(function (global, factory) {
  35299. typeof exports === 'object' && typeof module !== 'undefined'
  35300. && typeof require === 'function' ? factory(require('../../moment')) :
  35301. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  35302. factory(global.moment)
  35303. }(this, function (moment) { 'use strict';
  35304. /*global QUnit:false*/
  35305. var test = QUnit.test;
  35306. var expect = QUnit.expect;
  35307. function module (name, lifecycle) {
  35308. QUnit.module(name, {
  35309. setup : function () {
  35310. moment.locale('en');
  35311. moment.createFromInputFallback = function (config) {
  35312. throw new Error('input not handled by moment: ' + config._i);
  35313. };
  35314. if (lifecycle && lifecycle.setup) {
  35315. lifecycle.setup();
  35316. }
  35317. },
  35318. teardown : function () {
  35319. if (lifecycle && lifecycle.teardown) {
  35320. lifecycle.teardown();
  35321. }
  35322. }
  35323. });
  35324. }
  35325. function localeModule (name, lifecycle) {
  35326. QUnit.module('locale:' + name, {
  35327. setup : function () {
  35328. moment.locale(name);
  35329. moment.createFromInputFallback = function (config) {
  35330. throw new Error('input not handled by moment: ' + config._i);
  35331. };
  35332. if (lifecycle && lifecycle.setup) {
  35333. lifecycle.setup();
  35334. }
  35335. },
  35336. teardown : function () {
  35337. moment.locale('en');
  35338. if (lifecycle && lifecycle.teardown) {
  35339. lifecycle.teardown();
  35340. }
  35341. }
  35342. });
  35343. }
  35344. module('is after');
  35345. test('is after without units', function (assert) {
  35346. var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
  35347. assert.equal(m.isAfter(moment(new Date(2012, 3, 2, 3, 5, 5, 10))), false, 'year is later');
  35348. assert.equal(m.isAfter(moment(new Date(2010, 3, 2, 3, 3, 5, 10))), true, 'year is earlier');
  35349. assert.equal(m.isAfter(moment(new Date(2011, 4, 2, 3, 4, 5, 10))), false, 'month is later');
  35350. assert.equal(m.isAfter(moment(new Date(2011, 2, 2, 3, 4, 5, 10))), true, 'month is earlier');
  35351. assert.equal(m.isAfter(moment(new Date(2011, 3, 3, 3, 4, 5, 10))), false, 'day is later');
  35352. assert.equal(m.isAfter(moment(new Date(2011, 3, 1, 3, 4, 5, 10))), true, 'day is earlier');
  35353. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 4, 4, 5, 10))), false, 'hour is later');
  35354. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 2, 4, 5, 10))), true, 'hour is earlier');
  35355. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 5, 5, 10))), false, 'minute is later');
  35356. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 3, 5, 10))), true, 'minute is earlier');
  35357. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 6, 10))), false, 'second is later');
  35358. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 4, 11))), true, 'second is earlier');
  35359. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 10))), false, 'millisecond match');
  35360. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 11))), false, 'millisecond is later');
  35361. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 9))), true, 'millisecond is earlier');
  35362. assert.equal(m.isAfter(m), false, 'moments are not after themselves');
  35363. assert.equal(+m, +mCopy, 'isAfter second should not change moment');
  35364. });
  35365. test('is after year', function (assert) {
  35366. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
  35367. assert.equal(m.isAfter(moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'year'), false, 'year match');
  35368. assert.equal(m.isAfter(moment(new Date(2010, 5, 6, 7, 8, 9, 10)), 'years'), true, 'plural should work');
  35369. assert.equal(m.isAfter(moment(new Date(2013, 5, 6, 7, 8, 9, 10)), 'year'), false, 'year is later');
  35370. assert.equal(m.isAfter(moment(new Date(2010, 5, 6, 7, 8, 9, 10)), 'year'), true, 'year is earlier');
  35371. assert.equal(m.isAfter(moment(new Date(2011, 0, 1, 0, 0, 0, 0)), 'year'), false, 'exact start of year');
  35372. assert.equal(m.isAfter(moment(new Date(2011, 11, 31, 23, 59, 59, 999)), 'year'), false, 'exact end of year');
  35373. assert.equal(m.isAfter(moment(new Date(2012, 0, 1, 0, 0, 0, 0)), 'year'), false, 'start of next year');
  35374. assert.equal(m.isAfter(moment(new Date(2010, 11, 31, 23, 59, 59, 999)), 'year'), true, 'end of previous year');
  35375. assert.equal(m.isAfter(moment(new Date(1980, 11, 31, 23, 59, 59, 999)), 'year'), true, 'end of year far before');
  35376. assert.equal(m.isAfter(m, 'year'), false, 'same moments are not after the same year');
  35377. assert.equal(+m, +mCopy, 'isAfter year should not change moment');
  35378. });
  35379. test('is after month', function (assert) {
  35380. var m = moment(new Date(2011, 2, 3, 4, 5, 6, 7)), mCopy = moment(m);
  35381. assert.equal(m.isAfter(moment(new Date(2011, 2, 6, 7, 8, 9, 10)), 'month'), false, 'month match');
  35382. assert.equal(m.isAfter(moment(new Date(2010, 2, 6, 7, 8, 9, 10)), 'months'), true, 'plural should work');
  35383. assert.equal(m.isAfter(moment(new Date(2012, 2, 6, 7, 8, 9, 10)), 'month'), false, 'year is later');
  35384. assert.equal(m.isAfter(moment(new Date(2010, 2, 6, 7, 8, 9, 10)), 'month'), true, 'year is earlier');
  35385. assert.equal(m.isAfter(moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'month'), false, 'month is later');
  35386. assert.equal(m.isAfter(moment(new Date(2011, 1, 6, 7, 8, 9, 10)), 'month'), true, 'month is earlier');
  35387. assert.equal(m.isAfter(moment(new Date(2011, 2, 1, 0, 0, 0, 0)), 'month'), false, 'exact start of month');
  35388. assert.equal(m.isAfter(moment(new Date(2011, 2, 31, 23, 59, 59, 999)), 'month'), false, 'exact end of month');
  35389. assert.equal(m.isAfter(moment(new Date(2011, 3, 1, 0, 0, 0, 0)), 'month'), false, 'start of next month');
  35390. assert.equal(m.isAfter(moment(new Date(2011, 1, 27, 23, 59, 59, 999)), 'month'), true, 'end of previous month');
  35391. assert.equal(m.isAfter(moment(new Date(2010, 12, 31, 23, 59, 59, 999)), 'month'), true, 'later month but earlier year');
  35392. assert.equal(m.isAfter(m, 'month'), false, 'same moments are not after the same month');
  35393. assert.equal(+m, +mCopy, 'isAfter month should not change moment');
  35394. });
  35395. test('is after day', function (assert) {
  35396. var m = moment(new Date(2011, 3, 2, 3, 4, 5, 6)), mCopy = moment(m);
  35397. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 7, 8, 9, 10)), 'day'), false, 'day match');
  35398. assert.equal(m.isAfter(moment(new Date(2010, 3, 2, 7, 8, 9, 10)), 'days'), true, 'plural should work');
  35399. assert.equal(m.isAfter(moment(new Date(2012, 3, 2, 7, 8, 9, 10)), 'day'), false, 'year is later');
  35400. assert.equal(m.isAfter(moment(new Date(2010, 3, 2, 7, 8, 9, 10)), 'day'), true, 'year is earlier');
  35401. assert.equal(m.isAfter(moment(new Date(2011, 4, 2, 7, 8, 9, 10)), 'day'), false, 'month is later');
  35402. assert.equal(m.isAfter(moment(new Date(2011, 2, 2, 7, 8, 9, 10)), 'day'), true, 'month is earlier');
  35403. assert.equal(m.isAfter(moment(new Date(2011, 3, 3, 7, 8, 9, 10)), 'day'), false, 'day is later');
  35404. assert.equal(m.isAfter(moment(new Date(2011, 3, 1, 7, 8, 9, 10)), 'day'), true, 'day is earlier');
  35405. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 0, 0, 0, 0)), 'day'), false, 'exact start of day');
  35406. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 23, 59, 59, 999)), 'day'), false, 'exact end of day');
  35407. assert.equal(m.isAfter(moment(new Date(2011, 3, 3, 0, 0, 0, 0)), 'day'), false, 'start of next day');
  35408. assert.equal(m.isAfter(moment(new Date(2011, 3, 1, 23, 59, 59, 999)), 'day'), true, 'end of previous day');
  35409. assert.equal(m.isAfter(moment(new Date(2010, 3, 10, 0, 0, 0, 0)), 'day'), true, 'later day but earlier year');
  35410. assert.equal(m.isAfter(m, 'day'), false, 'same moments are not after the same day');
  35411. assert.equal(+m, +mCopy, 'isAfter day should not change moment');
  35412. });
  35413. test('is after hour', function (assert) {
  35414. var m = moment(new Date(2011, 3, 2, 3, 4, 5, 6)), mCopy = moment(m);
  35415. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 8, 9, 10)), 'hour'), false, 'hour match');
  35416. assert.equal(m.isAfter(moment(new Date(2010, 3, 2, 3, 8, 9, 10)), 'hours'), true, 'plural should work');
  35417. assert.equal(m.isAfter(moment(new Date(2012, 3, 2, 3, 8, 9, 10)), 'hour'), false, 'year is later');
  35418. assert.equal(m.isAfter(moment(new Date(2010, 3, 2, 3, 8, 9, 10)), 'hour'), true, 'year is earlier');
  35419. assert.equal(m.isAfter(moment(new Date(2011, 4, 2, 3, 8, 9, 10)), 'hour'), false, 'month is later');
  35420. assert.equal(m.isAfter(moment(new Date(2011, 1, 2, 3, 8, 9, 10)), 'hour'), true, 'month is earlier');
  35421. assert.equal(m.isAfter(moment(new Date(2011, 3, 3, 3, 8, 9, 10)), 'hour'), false, 'day is later');
  35422. assert.equal(m.isAfter(moment(new Date(2011, 3, 1, 3, 8, 9, 10)), 'hour'), true, 'day is earlier');
  35423. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 4, 8, 9, 10)), 'hour'), false, 'hour is later');
  35424. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 8, 9, 10)), 'hour'), false, 'hour is earlier');
  35425. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 0, 0, 0)), 'hour'), false, 'exact start of hour');
  35426. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 59, 59, 999)), 'hour'), false, 'exact end of hour');
  35427. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 4, 0, 0, 0)), 'hour'), false, 'start of next hour');
  35428. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 2, 59, 59, 999)), 'hour'), true, 'end of previous hour');
  35429. assert.equal(m.isAfter(m, 'hour'), false, 'same moments are not after the same hour');
  35430. assert.equal(+m, +mCopy, 'isAfter hour should not change moment');
  35431. });
  35432. test('is after minute', function (assert) {
  35433. var m = moment(new Date(2011, 3, 2, 3, 4, 5, 6)), mCopy = moment(m);
  35434. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 9, 10)), 'minute'), false, 'minute match');
  35435. assert.equal(m.isAfter(moment(new Date(2010, 3, 2, 3, 4, 9, 10)), 'minutes'), true, 'plural should work');
  35436. assert.equal(m.isAfter(moment(new Date(2012, 3, 2, 3, 4, 9, 10)), 'minute'), false, 'year is later');
  35437. assert.equal(m.isAfter(moment(new Date(2010, 3, 2, 3, 4, 9, 10)), 'minute'), true, 'year is earlier');
  35438. assert.equal(m.isAfter(moment(new Date(2011, 4, 2, 3, 4, 9, 10)), 'minute'), false, 'month is later');
  35439. assert.equal(m.isAfter(moment(new Date(2011, 2, 2, 3, 4, 9, 10)), 'minute'), true, 'month is earlier');
  35440. assert.equal(m.isAfter(moment(new Date(2011, 3, 3, 3, 4, 9, 10)), 'minute'), false, 'day is later');
  35441. assert.equal(m.isAfter(moment(new Date(2011, 3, 1, 3, 4, 9, 10)), 'minute'), true, 'day is earlier');
  35442. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 4, 4, 9, 10)), 'minute'), false, 'hour is later');
  35443. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 2, 4, 9, 10)), 'minute'), true, 'hour is earler');
  35444. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 5, 9, 10)), 'minute'), false, 'minute is later');
  35445. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 3, 9, 10)), 'minute'), true, 'minute is earlier');
  35446. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 0, 0)), 'minute'), false, 'exact start of minute');
  35447. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 59, 999)), 'minute'), false, 'exact end of minute');
  35448. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 5, 0, 0)), 'minute'), false, 'start of next minute');
  35449. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 3, 59, 999)), 'minute'), true, 'end of previous minute');
  35450. assert.equal(m.isAfter(m, 'minute'), false, 'same moments are not after the same minute');
  35451. assert.equal(+m, +mCopy, 'isAfter minute should not change moment');
  35452. });
  35453. test('is after second', function (assert) {
  35454. var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
  35455. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 10)), 'second'), false, 'second match');
  35456. assert.equal(m.isAfter(moment(new Date(2010, 3, 2, 3, 4, 5, 10)), 'seconds'), true, 'plural should work');
  35457. assert.equal(m.isAfter(moment(new Date(2012, 3, 2, 3, 4, 5, 10)), 'second'), false, 'year is later');
  35458. assert.equal(m.isAfter(moment(new Date(2010, 3, 2, 3, 4, 5, 10)), 'second'), true, 'year is earlier');
  35459. assert.equal(m.isAfter(moment(new Date(2011, 4, 2, 3, 4, 5, 10)), 'second'), false, 'month is later');
  35460. assert.equal(m.isAfter(moment(new Date(2011, 2, 2, 3, 4, 5, 10)), 'second'), true, 'month is earlier');
  35461. assert.equal(m.isAfter(moment(new Date(2011, 3, 3, 3, 4, 5, 10)), 'second'), false, 'day is later');
  35462. assert.equal(m.isAfter(moment(new Date(2011, 3, 1, 1, 4, 5, 10)), 'second'), true, 'day is earlier');
  35463. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 4, 4, 5, 10)), 'second'), false, 'hour is later');
  35464. assert.equal(m.isAfter(moment(new Date(2011, 3, 1, 4, 1, 5, 10)), 'second'), true, 'hour is earlier');
  35465. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 5, 5, 10)), 'second'), false, 'minute is later');
  35466. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 3, 5, 10)), 'second'), true, 'minute is earlier');
  35467. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 6, 10)), 'second'), false, 'second is later');
  35468. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 4, 5)), 'second'), true, 'second is earlier');
  35469. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 0)), 'second'), false, 'exact start of second');
  35470. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 999)), 'second'), false, 'exact end of second');
  35471. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 6, 0)), 'second'), false, 'start of next second');
  35472. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 4, 999)), 'second'), true, 'end of previous second');
  35473. assert.equal(m.isAfter(m, 'second'), false, 'same moments are not after the same second');
  35474. assert.equal(+m, +mCopy, 'isAfter second should not change moment');
  35475. });
  35476. test('is after millisecond', function (assert) {
  35477. var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
  35478. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 10)), 'millisecond'), false, 'millisecond match');
  35479. assert.equal(m.isAfter(moment(new Date(2010, 3, 2, 3, 4, 5, 10)), 'milliseconds'), true, 'plural should work');
  35480. assert.equal(m.isAfter(moment(new Date(2012, 3, 2, 3, 4, 5, 10)), 'millisecond'), false, 'year is later');
  35481. assert.equal(m.isAfter(moment(new Date(2010, 3, 2, 3, 4, 5, 10)), 'millisecond'), true, 'year is earlier');
  35482. assert.equal(m.isAfter(moment(new Date(2011, 4, 2, 3, 4, 5, 10)), 'millisecond'), false, 'month is later');
  35483. assert.equal(m.isAfter(moment(new Date(2011, 2, 2, 3, 4, 5, 10)), 'millisecond'), true, 'month is earlier');
  35484. assert.equal(m.isAfter(moment(new Date(2011, 3, 3, 3, 4, 5, 10)), 'millisecond'), false, 'day is later');
  35485. assert.equal(m.isAfter(moment(new Date(2011, 3, 1, 1, 4, 5, 10)), 'millisecond'), true, 'day is earlier');
  35486. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 4, 4, 5, 10)), 'millisecond'), false, 'hour is later');
  35487. assert.equal(m.isAfter(moment(new Date(2011, 3, 1, 4, 1, 5, 10)), 'millisecond'), true, 'hour is earlier');
  35488. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 5, 5, 10)), 'millisecond'), false, 'minute is later');
  35489. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 3, 5, 10)), 'millisecond'), true, 'minute is earlier');
  35490. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 6, 10)), 'millisecond'), false, 'second is later');
  35491. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 4, 5)), 'millisecond'), true, 'second is earlier');
  35492. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 6, 11)), 'millisecond'), false, 'millisecond is later');
  35493. assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 4, 9)), 'millisecond'), true, 'millisecond is earlier');
  35494. assert.equal(m.isAfter(m, 'millisecond'), false, 'same moments are not after the same millisecond');
  35495. assert.equal(+m, +mCopy, 'isAfter millisecond should not change moment');
  35496. });
  35497. test('is after invalid', function (assert) {
  35498. var m = moment(), invalid = moment.invalid();
  35499. assert.equal(m.isAfter(invalid), false, 'valid moment is not after invalid moment');
  35500. assert.equal(invalid.isAfter(m), false, 'invalid moment is not after valid moment');
  35501. assert.equal(m.isAfter(invalid, 'year'), false, 'invalid moment year');
  35502. assert.equal(m.isAfter(invalid, 'month'), false, 'invalid moment month');
  35503. assert.equal(m.isAfter(invalid, 'day'), false, 'invalid moment day');
  35504. assert.equal(m.isAfter(invalid, 'hour'), false, 'invalid moment hour');
  35505. assert.equal(m.isAfter(invalid, 'minute'), false, 'invalid moment minute');
  35506. assert.equal(m.isAfter(invalid, 'second'), false, 'invalid moment second');
  35507. assert.equal(m.isAfter(invalid, 'milliseconds'), false, 'invalid moment milliseconds');
  35508. });
  35509. }));
  35510. ;(function (global, factory) {
  35511. typeof exports === 'object' && typeof module !== 'undefined'
  35512. && typeof require === 'function' ? factory(require('../../moment')) :
  35513. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  35514. factory(global.moment)
  35515. }(this, function (moment) { 'use strict';
  35516. /*global QUnit:false*/
  35517. var test = QUnit.test;
  35518. var expect = QUnit.expect;
  35519. function module (name, lifecycle) {
  35520. QUnit.module(name, {
  35521. setup : function () {
  35522. moment.locale('en');
  35523. moment.createFromInputFallback = function (config) {
  35524. throw new Error('input not handled by moment: ' + config._i);
  35525. };
  35526. if (lifecycle && lifecycle.setup) {
  35527. lifecycle.setup();
  35528. }
  35529. },
  35530. teardown : function () {
  35531. if (lifecycle && lifecycle.teardown) {
  35532. lifecycle.teardown();
  35533. }
  35534. }
  35535. });
  35536. }
  35537. function localeModule (name, lifecycle) {
  35538. QUnit.module('locale:' + name, {
  35539. setup : function () {
  35540. moment.locale(name);
  35541. moment.createFromInputFallback = function (config) {
  35542. throw new Error('input not handled by moment: ' + config._i);
  35543. };
  35544. if (lifecycle && lifecycle.setup) {
  35545. lifecycle.setup();
  35546. }
  35547. },
  35548. teardown : function () {
  35549. moment.locale('en');
  35550. if (lifecycle && lifecycle.teardown) {
  35551. lifecycle.teardown();
  35552. }
  35553. }
  35554. });
  35555. }
  35556. module('is before');
  35557. test('is after without units', function (assert) {
  35558. var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
  35559. assert.equal(m.isBefore(moment(new Date(2012, 3, 2, 3, 5, 5, 10))), true, 'year is later');
  35560. assert.equal(m.isBefore(moment(new Date(2010, 3, 2, 3, 3, 5, 10))), false, 'year is earlier');
  35561. assert.equal(m.isBefore(moment(new Date(2011, 4, 2, 3, 4, 5, 10))), true, 'month is later');
  35562. assert.equal(m.isBefore(moment(new Date(2011, 2, 2, 3, 4, 5, 10))), false, 'month is earlier');
  35563. assert.equal(m.isBefore(moment(new Date(2011, 3, 3, 3, 4, 5, 10))), true, 'day is later');
  35564. assert.equal(m.isBefore(moment(new Date(2011, 3, 1, 3, 4, 5, 10))), false, 'day is earlier');
  35565. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 4, 4, 5, 10))), true, 'hour is later');
  35566. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 2, 4, 5, 10))), false, 'hour is earlier');
  35567. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 5, 5, 10))), true, 'minute is later');
  35568. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 3, 5, 10))), false, 'minute is earlier');
  35569. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 6, 10))), true, 'second is later');
  35570. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 4, 11))), false, 'second is earlier');
  35571. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 10))), false, 'millisecond match');
  35572. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 11))), true, 'millisecond is later');
  35573. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 9))), false, 'millisecond is earlier');
  35574. assert.equal(m.isBefore(m), false, 'moments are not before themselves');
  35575. assert.equal(+m, +mCopy, 'isBefore second should not change moment');
  35576. });
  35577. test('is before year', function (assert) {
  35578. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
  35579. assert.equal(m.isBefore(moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'year'), false, 'year match');
  35580. assert.equal(m.isBefore(moment(new Date(2012, 5, 6, 7, 8, 9, 10)), 'years'), true, 'plural should work');
  35581. assert.equal(m.isBefore(moment(new Date(2013, 5, 6, 7, 8, 9, 10)), 'year'), true, 'year is later');
  35582. assert.equal(m.isBefore(moment(new Date(2010, 5, 6, 7, 8, 9, 10)), 'year'), false, 'year is earlier');
  35583. assert.equal(m.isBefore(moment(new Date(2011, 0, 1, 0, 0, 0, 0)), 'year'), false, 'exact start of year');
  35584. assert.equal(m.isBefore(moment(new Date(2011, 11, 31, 23, 59, 59, 999)), 'year'), false, 'exact end of year');
  35585. assert.equal(m.isBefore(moment(new Date(2012, 0, 1, 0, 0, 0, 0)), 'year'), true, 'start of next year');
  35586. assert.equal(m.isBefore(moment(new Date(2010, 11, 31, 23, 59, 59, 999)), 'year'), false, 'end of previous year');
  35587. assert.equal(m.isBefore(moment(new Date(1980, 11, 31, 23, 59, 59, 999)), 'year'), false, 'end of year far before');
  35588. assert.equal(m.isBefore(m, 'year'), false, 'same moments are not before the same year');
  35589. assert.equal(+m, +mCopy, 'isBefore year should not change moment');
  35590. });
  35591. test('is before month', function (assert) {
  35592. var m = moment(new Date(2011, 2, 3, 4, 5, 6, 7)), mCopy = moment(m);
  35593. assert.equal(m.isBefore(moment(new Date(2011, 2, 6, 7, 8, 9, 10)), 'month'), false, 'month match');
  35594. assert.equal(m.isBefore(moment(new Date(2012, 2, 6, 7, 8, 9, 10)), 'months'), true, 'plural should work');
  35595. assert.equal(m.isBefore(moment(new Date(2012, 2, 6, 7, 8, 9, 10)), 'month'), true, 'year is later');
  35596. assert.equal(m.isBefore(moment(new Date(2010, 2, 6, 7, 8, 9, 10)), 'month'), false, 'year is earlier');
  35597. assert.equal(m.isBefore(moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'month'), true, 'month is later');
  35598. assert.equal(m.isBefore(moment(new Date(2011, 1, 6, 7, 8, 9, 10)), 'month'), false, 'month is earlier');
  35599. assert.equal(m.isBefore(moment(new Date(2011, 2, 1, 0, 0, 0, 0)), 'month'), false, 'exact start of month');
  35600. assert.equal(m.isBefore(moment(new Date(2011, 2, 31, 23, 59, 59, 999)), 'month'), false, 'exact end of month');
  35601. assert.equal(m.isBefore(moment(new Date(2011, 3, 1, 0, 0, 0, 0)), 'month'), true, 'start of next month');
  35602. assert.equal(m.isBefore(moment(new Date(2011, 1, 27, 23, 59, 59, 999)), 'month'), false, 'end of previous month');
  35603. assert.equal(m.isBefore(moment(new Date(2010, 12, 31, 23, 59, 59, 999)), 'month'), false, 'later month but earlier year');
  35604. assert.equal(m.isBefore(m, 'month'), false, 'same moments are not before the same month');
  35605. assert.equal(+m, +mCopy, 'isBefore month should not change moment');
  35606. });
  35607. test('is before day', function (assert) {
  35608. var m = moment(new Date(2011, 3, 2, 3, 4, 5, 6)), mCopy = moment(m);
  35609. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 7, 8, 9, 10)), 'day'), false, 'day match');
  35610. assert.equal(m.isBefore(moment(new Date(2012, 3, 2, 7, 8, 9, 10)), 'days'), true, 'plural should work');
  35611. assert.equal(m.isBefore(moment(new Date(2012, 3, 2, 7, 8, 9, 10)), 'day'), true, 'year is later');
  35612. assert.equal(m.isBefore(moment(new Date(2010, 3, 2, 7, 8, 9, 10)), 'day'), false, 'year is earlier');
  35613. assert.equal(m.isBefore(moment(new Date(2011, 4, 2, 7, 8, 9, 10)), 'day'), true, 'month is later');
  35614. assert.equal(m.isBefore(moment(new Date(2011, 2, 2, 7, 8, 9, 10)), 'day'), false, 'month is earlier');
  35615. assert.equal(m.isBefore(moment(new Date(2011, 3, 3, 7, 8, 9, 10)), 'day'), true, 'day is later');
  35616. assert.equal(m.isBefore(moment(new Date(2011, 3, 1, 7, 8, 9, 10)), 'day'), false, 'day is earlier');
  35617. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 0, 0, 0, 0)), 'day'), false, 'exact start of day');
  35618. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 23, 59, 59, 999)), 'day'), false, 'exact end of day');
  35619. assert.equal(m.isBefore(moment(new Date(2011, 3, 3, 0, 0, 0, 0)), 'day'), true, 'start of next day');
  35620. assert.equal(m.isBefore(moment(new Date(2011, 3, 1, 23, 59, 59, 999)), 'day'), false, 'end of previous day');
  35621. assert.equal(m.isBefore(moment(new Date(2010, 3, 10, 0, 0, 0, 0)), 'day'), false, 'later day but earlier year');
  35622. assert.equal(m.isBefore(m, 'day'), false, 'same moments are not before the same day');
  35623. assert.equal(+m, +mCopy, 'isBefore day should not change moment');
  35624. });
  35625. test('is before hour', function (assert) {
  35626. var m = moment(new Date(2011, 3, 2, 3, 4, 5, 6)), mCopy = moment(m);
  35627. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 8, 9, 10)), 'hour'), false, 'hour match');
  35628. assert.equal(m.isBefore(moment(new Date(2012, 3, 2, 3, 8, 9, 10)), 'hours'), true, 'plural should work');
  35629. assert.equal(m.isBefore(moment(new Date(2012, 3, 2, 3, 8, 9, 10)), 'hour'), true, 'year is later');
  35630. assert.equal(m.isBefore(moment(new Date(2010, 3, 2, 3, 8, 9, 10)), 'hour'), false, 'year is earlier');
  35631. assert.equal(m.isBefore(moment(new Date(2011, 4, 2, 3, 8, 9, 10)), 'hour'), true, 'month is later');
  35632. assert.equal(m.isBefore(moment(new Date(2011, 1, 2, 3, 8, 9, 10)), 'hour'), false, 'month is earlier');
  35633. assert.equal(m.isBefore(moment(new Date(2011, 3, 3, 3, 8, 9, 10)), 'hour'), true, 'day is later');
  35634. assert.equal(m.isBefore(moment(new Date(2011, 3, 1, 3, 8, 9, 10)), 'hour'), false, 'day is earlier');
  35635. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 4, 8, 9, 10)), 'hour'), true, 'hour is later');
  35636. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 8, 9, 10)), 'hour'), false, 'hour is earlier');
  35637. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 0, 0, 0)), 'hour'), false, 'exact start of hour');
  35638. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 59, 59, 999)), 'hour'), false, 'exact end of hour');
  35639. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 4, 0, 0, 0)), 'hour'), true, 'start of next hour');
  35640. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 2, 59, 59, 999)), 'hour'), false, 'end of previous hour');
  35641. assert.equal(m.isBefore(m, 'hour'), false, 'same moments are not before the same hour');
  35642. assert.equal(+m, +mCopy, 'isBefore hour should not change moment');
  35643. });
  35644. test('is before minute', function (assert) {
  35645. var m = moment(new Date(2011, 3, 2, 3, 4, 5, 6)), mCopy = moment(m);
  35646. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 9, 10)), 'minute'), false, 'minute match');
  35647. assert.equal(m.isBefore(moment(new Date(2012, 3, 2, 3, 4, 9, 10)), 'minutes'), true, 'plural should work');
  35648. assert.equal(m.isBefore(moment(new Date(2012, 3, 2, 3, 4, 9, 10)), 'minute'), true, 'year is later');
  35649. assert.equal(m.isBefore(moment(new Date(2010, 3, 2, 3, 4, 9, 10)), 'minute'), false, 'year is earlier');
  35650. assert.equal(m.isBefore(moment(new Date(2011, 4, 2, 3, 4, 9, 10)), 'minute'), true, 'month is later');
  35651. assert.equal(m.isBefore(moment(new Date(2011, 2, 2, 3, 4, 9, 10)), 'minute'), false, 'month is earlier');
  35652. assert.equal(m.isBefore(moment(new Date(2011, 3, 3, 3, 4, 9, 10)), 'minute'), true, 'day is later');
  35653. assert.equal(m.isBefore(moment(new Date(2011, 3, 1, 3, 4, 9, 10)), 'minute'), false, 'day is earlier');
  35654. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 4, 4, 9, 10)), 'minute'), true, 'hour is later');
  35655. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 2, 4, 9, 10)), 'minute'), false, 'hour is earler');
  35656. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 5, 9, 10)), 'minute'), true, 'minute is later');
  35657. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 3, 9, 10)), 'minute'), false, 'minute is earlier');
  35658. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 0, 0)), 'minute'), false, 'exact start of minute');
  35659. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 59, 999)), 'minute'), false, 'exact end of minute');
  35660. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 5, 0, 0)), 'minute'), true, 'start of next minute');
  35661. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 3, 59, 999)), 'minute'), false, 'end of previous minute');
  35662. assert.equal(m.isBefore(m, 'minute'), false, 'same moments are not before the same minute');
  35663. assert.equal(+m, +mCopy, 'isBefore minute should not change moment');
  35664. });
  35665. test('is before second', function (assert) {
  35666. var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
  35667. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 10)), 'second'), false, 'second match');
  35668. assert.equal(m.isBefore(moment(new Date(2012, 3, 2, 3, 4, 5, 10)), 'seconds'), true, 'plural should work');
  35669. assert.equal(m.isBefore(moment(new Date(2012, 3, 2, 3, 4, 5, 10)), 'second'), true, 'year is later');
  35670. assert.equal(m.isBefore(moment(new Date(2010, 3, 2, 3, 4, 5, 10)), 'second'), false, 'year is earlier');
  35671. assert.equal(m.isBefore(moment(new Date(2011, 4, 2, 3, 4, 5, 10)), 'second'), true, 'month is later');
  35672. assert.equal(m.isBefore(moment(new Date(2011, 2, 2, 3, 4, 5, 10)), 'second'), false, 'month is earlier');
  35673. assert.equal(m.isBefore(moment(new Date(2011, 3, 3, 3, 4, 5, 10)), 'second'), true, 'day is later');
  35674. assert.equal(m.isBefore(moment(new Date(2011, 3, 1, 1, 4, 5, 10)), 'second'), false, 'day is earlier');
  35675. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 4, 4, 5, 10)), 'second'), true, 'hour is later');
  35676. assert.equal(m.isBefore(moment(new Date(2011, 3, 1, 4, 1, 5, 10)), 'second'), false, 'hour is earlier');
  35677. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 5, 5, 10)), 'second'), true, 'minute is later');
  35678. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 3, 5, 10)), 'second'), false, 'minute is earlier');
  35679. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 6, 10)), 'second'), true, 'second is later');
  35680. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 4, 5)), 'second'), false, 'second is earlier');
  35681. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 0)), 'second'), false, 'exact start of second');
  35682. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 999)), 'second'), false, 'exact end of second');
  35683. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 6, 0)), 'second'), true, 'start of next second');
  35684. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 4, 999)), 'second'), false, 'end of previous second');
  35685. assert.equal(m.isBefore(m, 'second'), false, 'same moments are not before the same second');
  35686. assert.equal(+m, +mCopy, 'isBefore second should not change moment');
  35687. });
  35688. test('is before millisecond', function (assert) {
  35689. var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
  35690. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 10)), 'millisecond'), false, 'millisecond match');
  35691. assert.equal(m.isBefore(moment(new Date(2010, 3, 2, 3, 4, 5, 10)), 'milliseconds'), false, 'plural should work');
  35692. assert.equal(m.isBefore(moment(new Date(2012, 3, 2, 3, 4, 5, 10)), 'millisecond'), true, 'year is later');
  35693. assert.equal(m.isBefore(moment(new Date(2010, 3, 2, 3, 4, 5, 10)), 'millisecond'), false, 'year is earlier');
  35694. assert.equal(m.isBefore(moment(new Date(2011, 4, 2, 3, 4, 5, 10)), 'millisecond'), true, 'month is later');
  35695. assert.equal(m.isBefore(moment(new Date(2011, 2, 2, 3, 4, 5, 10)), 'millisecond'), false, 'month is earlier');
  35696. assert.equal(m.isBefore(moment(new Date(2011, 3, 3, 3, 4, 5, 10)), 'millisecond'), true, 'day is later');
  35697. assert.equal(m.isBefore(moment(new Date(2011, 3, 1, 1, 4, 5, 10)), 'millisecond'), false, 'day is earlier');
  35698. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 4, 4, 5, 10)), 'millisecond'), true, 'hour is later');
  35699. assert.equal(m.isBefore(moment(new Date(2011, 3, 1, 4, 1, 5, 10)), 'millisecond'), false, 'hour is earlier');
  35700. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 5, 5, 10)), 'millisecond'), true, 'minute is later');
  35701. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 3, 5, 10)), 'millisecond'), false, 'minute is earlier');
  35702. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 6, 10)), 'millisecond'), true, 'second is later');
  35703. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 4, 5)), 'millisecond'), false, 'second is earlier');
  35704. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 6, 11)), 'millisecond'), true, 'millisecond is later');
  35705. assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 4, 9)), 'millisecond'), false, 'millisecond is earlier');
  35706. assert.equal(m.isBefore(m, 'millisecond'), false, 'same moments are not before the same millisecond');
  35707. assert.equal(+m, +mCopy, 'isBefore millisecond should not change moment');
  35708. });
  35709. test('is before invalid', function (assert) {
  35710. var m = moment(), invalid = moment.invalid();
  35711. assert.equal(m.isBefore(invalid), false, 'valid moment is not before invalid moment');
  35712. assert.equal(invalid.isBefore(m), false, 'invalid moment is not before valid moment');
  35713. assert.equal(m.isBefore(invalid, 'year'), false, 'invalid moment year');
  35714. assert.equal(m.isBefore(invalid, 'month'), false, 'invalid moment month');
  35715. assert.equal(m.isBefore(invalid, 'day'), false, 'invalid moment day');
  35716. assert.equal(m.isBefore(invalid, 'hour'), false, 'invalid moment hour');
  35717. assert.equal(m.isBefore(invalid, 'minute'), false, 'invalid moment minute');
  35718. assert.equal(m.isBefore(invalid, 'second'), false, 'invalid moment second');
  35719. assert.equal(m.isBefore(invalid, 'milliseconds'), false, 'invalid moment milliseconds');
  35720. });
  35721. }));
  35722. ;(function (global, factory) {
  35723. typeof exports === 'object' && typeof module !== 'undefined'
  35724. && typeof require === 'function' ? factory(require('../../moment')) :
  35725. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  35726. factory(global.moment)
  35727. }(this, function (moment) { 'use strict';
  35728. /*global QUnit:false*/
  35729. var test = QUnit.test;
  35730. var expect = QUnit.expect;
  35731. function module (name, lifecycle) {
  35732. QUnit.module(name, {
  35733. setup : function () {
  35734. moment.locale('en');
  35735. moment.createFromInputFallback = function (config) {
  35736. throw new Error('input not handled by moment: ' + config._i);
  35737. };
  35738. if (lifecycle && lifecycle.setup) {
  35739. lifecycle.setup();
  35740. }
  35741. },
  35742. teardown : function () {
  35743. if (lifecycle && lifecycle.teardown) {
  35744. lifecycle.teardown();
  35745. }
  35746. }
  35747. });
  35748. }
  35749. function localeModule (name, lifecycle) {
  35750. QUnit.module('locale:' + name, {
  35751. setup : function () {
  35752. moment.locale(name);
  35753. moment.createFromInputFallback = function (config) {
  35754. throw new Error('input not handled by moment: ' + config._i);
  35755. };
  35756. if (lifecycle && lifecycle.setup) {
  35757. lifecycle.setup();
  35758. }
  35759. },
  35760. teardown : function () {
  35761. moment.locale('en');
  35762. if (lifecycle && lifecycle.teardown) {
  35763. lifecycle.teardown();
  35764. }
  35765. }
  35766. });
  35767. }
  35768. module('is between');
  35769. test('is between without units', function (assert) {
  35770. var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
  35771. assert.equal(m.isBetween(
  35772. moment(new Date(2009, 3, 2, 3, 4, 5, 10)),
  35773. moment(new Date(2011, 3, 2, 3, 4, 5, 10))), false, 'year is later');
  35774. assert.equal(m.isBetween(
  35775. moment(new Date(2011, 3, 2, 3, 4, 5, 10)),
  35776. moment(new Date(2013, 3, 2, 3, 4, 5, 10))), false, 'year is earlier');
  35777. assert.equal(m.isBetween(
  35778. moment(new Date(2010, 3, 2, 3, 4, 5, 10)),
  35779. moment(new Date(2012, 3, 2, 3, 4, 5, 10))), true, 'year is between');
  35780. assert.equal(m.isBetween(
  35781. moment(new Date(2011, 1, 2, 3, 4, 5, 10)),
  35782. moment(new Date(2011, 3, 2, 3, 4, 5, 10))), false, 'month is later');
  35783. assert.equal(m.isBetween(
  35784. moment(new Date(2011, 3, 2, 3, 4, 5, 10)),
  35785. moment(new Date(2011, 5, 2, 3, 4, 5, 10))), false, 'month is earlier');
  35786. assert.equal(m.isBetween(
  35787. moment(new Date(2011, 2, 2, 3, 4, 5, 10)),
  35788. moment(new Date(2011, 4, 2, 3, 4, 5, 10))), true, 'month is between');
  35789. assert.equal(m.isBetween(
  35790. moment(new Date(2011, 3, 1, 3, 4, 5, 10)),
  35791. moment(new Date(2011, 3, 2, 3, 4, 5, 10))), false, 'day is later');
  35792. assert.equal(m.isBetween(
  35793. moment(new Date(2011, 3, 2, 3, 4, 5, 10)),
  35794. moment(new Date(2011, 3, 4, 3, 4, 5, 10))), false, 'day is earlier');
  35795. assert.equal(m.isBetween(
  35796. moment(new Date(2011, 3, 1, 3, 4, 5, 10)),
  35797. moment(new Date(2011, 3, 3, 3, 4, 5, 10))), true, 'day is between');
  35798. assert.equal(m.isBetween(
  35799. moment(new Date(2011, 3, 2, 1, 4, 5, 10)),
  35800. moment(new Date(2011, 3, 2, 3, 4, 5, 10))), false, 'hour is later');
  35801. assert.equal(m.isBetween(
  35802. moment(new Date(2011, 3, 2, 3, 4, 5, 10)),
  35803. moment(new Date(2011, 3, 2, 5, 4, 5, 10))), false, 'hour is earlier');
  35804. assert.equal(m.isBetween(
  35805. moment(new Date(2011, 3, 2, 2, 4, 5, 10)),
  35806. moment(new Date(2011, 3, 2, 4, 4, 5, 10))), true, 'hour is between');
  35807. assert.equal(m.isBetween(
  35808. moment(new Date(2011, 3, 2, 3, 4, 5, 10)),
  35809. moment(new Date(2011, 3, 2, 3, 6, 5, 10))), false, 'minute is later');
  35810. assert.equal(m.isBetween(
  35811. moment(new Date(2011, 3, 2, 3, 2, 5, 10)),
  35812. moment(new Date(2011, 3, 2, 3, 4, 5, 10))), false, 'minute is earlier');
  35813. assert.equal(m.isBetween(
  35814. moment(new Date(2011, 3, 2, 3, 3, 5, 10)),
  35815. moment(new Date(2011, 3, 2, 3, 5, 5, 10))), true, 'minute is between');
  35816. assert.equal(m.isBetween(
  35817. moment(new Date(2011, 3, 2, 3, 4, 5, 10)),
  35818. moment(new Date(2011, 3, 2, 3, 4, 7, 10))), false, 'second is later');
  35819. assert.equal(m.isBetween(
  35820. moment(new Date(2011, 3, 2, 3, 4, 3, 10)),
  35821. moment(new Date(2011, 3, 2, 3, 4, 5, 10))), false, 'second is earlier');
  35822. assert.equal(m.isBetween(
  35823. moment(new Date(2011, 3, 2, 3, 4, 4, 10)),
  35824. moment(new Date(2011, 3, 2, 3, 4, 6, 10))), true, 'second is between');
  35825. assert.equal(m.isBetween(
  35826. moment(new Date(2011, 3, 2, 3, 4, 5, 10)),
  35827. moment(new Date(2011, 3, 2, 3, 4, 5, 12))), false, 'millisecond is later');
  35828. assert.equal(m.isBetween(
  35829. moment(new Date(2011, 3, 2, 3, 4, 5, 8)),
  35830. moment(new Date(2011, 3, 2, 3, 4, 5, 10))), false, 'millisecond is earlier');
  35831. assert.equal(m.isBetween(
  35832. moment(new Date(2011, 3, 2, 3, 4, 5, 9)),
  35833. moment(new Date(2011, 3, 2, 3, 4, 5, 11))), true, 'millisecond is between');
  35834. assert.equal(m.isBetween(m, m), false, 'moments are not between themselves');
  35835. assert.equal(+m, +mCopy, 'isBetween second should not change moment');
  35836. });
  35837. test('is between year', function (assert) {
  35838. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
  35839. assert.equal(m.isBetween(
  35840. moment(new Date(2011, 5, 6, 7, 8, 9, 10)),
  35841. moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'year'), false, 'year match');
  35842. assert.equal(m.isBetween(
  35843. moment(new Date(2010, 5, 6, 7, 8, 9, 10)),
  35844. moment(new Date(2012, 5, 6, 7, 8, 9, 10)), 'years'), true, 'plural should work');
  35845. assert.equal(m.isBetween(
  35846. moment(new Date(2010, 5, 6, 7, 8, 9, 10)),
  35847. moment(new Date(2012, 5, 6, 7, 8, 9, 10)), 'year'), true, 'year is between');
  35848. assert.equal(m.isBetween(
  35849. moment(new Date(2011, 5, 6, 7, 8, 9, 10)),
  35850. moment(new Date(2013, 5, 6, 7, 8, 9, 10)), 'year'), false, 'year is earlier');
  35851. assert.equal(m.isBetween(
  35852. moment(new Date(2010, 5, 6, 7, 8, 9, 10)),
  35853. moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'year'), false, 'year is later');
  35854. assert.equal(m.isBetween(m, 'year'), false, 'same moments are not between the same year');
  35855. assert.equal(+m, +mCopy, 'isBetween year should not change moment');
  35856. });
  35857. test('is between month', function (assert) {
  35858. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
  35859. assert.equal(m.isBetween(
  35860. moment(new Date(2011, 1, 6, 7, 8, 9, 10)),
  35861. moment(new Date(2011, 1, 6, 7, 8, 9, 10)), 'month'), false, 'month match');
  35862. assert.equal(m.isBetween(
  35863. moment(new Date(2011, 0, 6, 7, 8, 9, 10)),
  35864. moment(new Date(2011, 2, 6, 7, 8, 9, 10)), 'months'), true, 'plural should work');
  35865. assert.equal(m.isBetween(
  35866. moment(new Date(2011, 0, 31, 23, 59, 59, 999)),
  35867. moment(new Date(2011, 2, 1, 0, 0, 0, 0)), 'month'), true, 'month is between');
  35868. assert.equal(m.isBetween(
  35869. moment(new Date(2011, 1, 6, 7, 8, 9, 10)),
  35870. moment(new Date(2011, 2, 6, 7, 8, 9, 10)), 'month'), false, 'month is earlier');
  35871. assert.equal(m.isBetween(
  35872. moment(new Date(2011, 11, 6, 7, 8, 9, 10)),
  35873. moment(new Date(2011, 1, 6, 7, 8, 9, 10)), 'month'), false, 'month is later');
  35874. assert.equal(m.isBetween(m, 'month'), false, 'same moments are not between the same month');
  35875. assert.equal(+m, +mCopy, 'isBetween month should not change moment');
  35876. });
  35877. test('is between day', function (assert) {
  35878. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
  35879. assert.equal(m.isBetween(
  35880. moment(new Date(2011, 1, 2, 7, 8, 9, 10)),
  35881. moment(new Date(2011, 1, 2, 7, 8, 9, 10)), 'day'), false, 'day match');
  35882. assert.equal(m.isBetween(
  35883. moment(new Date(2011, 1, 1, 7, 8, 9, 10)),
  35884. moment(new Date(2011, 1, 3, 7, 8, 9, 10)), 'days'), true, 'plural should work');
  35885. assert.equal(m.isBetween(
  35886. moment(new Date(2011, 1, 1, 7, 8, 9, 10)),
  35887. moment(new Date(2011, 1, 3, 7, 8, 9, 10)), 'day'), true, 'day is between');
  35888. assert.equal(m.isBetween(
  35889. moment(new Date(2011, 1, 2, 7, 8, 9, 10)),
  35890. moment(new Date(2011, 1, 4, 7, 8, 9, 10)), 'day'), false, 'day is earlier');
  35891. assert.equal(m.isBetween(
  35892. moment(new Date(2011, 1, 1, 7, 8, 9, 10)),
  35893. moment(new Date(2011, 1, 2, 7, 8, 9, 10)), 'day'), false, 'day is later');
  35894. assert.equal(m.isBetween(m, 'day'), false, 'same moments are not between the same day');
  35895. assert.equal(+m, +mCopy, 'isBetween day should not change moment');
  35896. });
  35897. test('is between hour', function (assert) {
  35898. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
  35899. assert.equal(m.isBetween(
  35900. moment(new Date(2011, 1, 2, 3, 5, 9, 10)),
  35901. moment(new Date(2011, 1, 2, 3, 9, 9, 10)), 'hour'), false, 'hour match');
  35902. assert.equal(m.isBetween(
  35903. moment(new Date(2011, 1, 2, 1, 59, 59, 999)),
  35904. moment(new Date(2011, 1, 2, 4, 0, 0, 0)), 'hours'), true, 'plural should work');
  35905. assert.equal(m.isBetween(
  35906. moment(new Date(2011, 1, 2, 2, 59, 59, 999)),
  35907. moment(new Date(2011, 1, 2, 4, 0, 0, 0)), 'hour'), true, 'hour is between');
  35908. assert.equal(m.isBetween(
  35909. moment(new Date(2011, 1, 2, 7, 8, 9, 10)),
  35910. moment(new Date(2011, 1, 2, 7, 8, 9, 10)), 'hour'), false, 'hour is earlier');
  35911. assert.equal(m.isBetween(
  35912. moment(new Date(2011, 1, 2, 7, 8, 9, 10)),
  35913. moment(new Date(2011, 1, 2, 7, 8, 9, 10)), 'hour'), false, 'hour is later');
  35914. assert.equal(m.isBetween(m, 'hour'), false, 'same moments are not between the same hour');
  35915. assert.equal(+m, +mCopy, 'isBetween hour should not change moment');
  35916. });
  35917. test('is between minute', function (assert) {
  35918. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
  35919. assert.equal(m.isBetween(
  35920. moment(new Date(2011, 1, 2, 3, 4, 9, 10)),
  35921. moment(new Date(2011, 1, 2, 3, 4, 9, 10)), 'minute'), false, 'minute match');
  35922. assert.equal(m.isBetween(
  35923. moment(new Date(2011, 1, 2, 3, 3, 9, 10)),
  35924. moment(new Date(2011, 1, 2, 3, 5, 9, 10)), 'minutes'), true, 'plural should work');
  35925. assert.equal(m.isBetween(
  35926. moment(new Date(2011, 1, 2, 3, 3, 59, 999)),
  35927. moment(new Date(2011, 1, 2, 3, 5, 0, 0)), 'minute'), true, 'minute is between');
  35928. assert.equal(m.isBetween(
  35929. moment(new Date(2011, 1, 2, 3, 5, 0, 0)),
  35930. moment(new Date(2011, 1, 2, 3, 8, 9, 10)), 'minute'), false, 'minute is earlier');
  35931. assert.equal(m.isBetween(
  35932. moment(new Date(2011, 1, 2, 3, 2, 9, 10)),
  35933. moment(new Date(2011, 1, 2, 3, 3, 59, 999)), 'minute'), false, 'minute is later');
  35934. assert.equal(m.isBetween(m, 'minute'), false, 'same moments are not between the same minute');
  35935. assert.equal(+m, +mCopy, 'isBetween minute should not change moment');
  35936. });
  35937. test('is between second', function (assert) {
  35938. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
  35939. assert.equal(m.isBetween(
  35940. moment(new Date(2011, 1, 2, 3, 4, 5, 10)),
  35941. moment(new Date(2011, 1, 2, 3, 4, 5, 10)), 'second'), false, 'second match');
  35942. assert.equal(m.isBetween(
  35943. moment(new Date(2011, 1, 2, 3, 4, 4, 10)),
  35944. moment(new Date(2011, 1, 2, 3, 4, 6, 10)), 'seconds'), true, 'plural should work');
  35945. assert.equal(m.isBetween(
  35946. moment(new Date(2011, 1, 2, 3, 4, 4, 999)),
  35947. moment(new Date(2011, 1, 2, 3, 4, 6, 0)), 'second'), true, 'second is between');
  35948. assert.equal(m.isBetween(
  35949. moment(new Date(2011, 1, 2, 3, 4, 6, 0)),
  35950. moment(new Date(2011, 1, 2, 3, 4, 7, 10)), 'second'), false, 'second is earlier');
  35951. assert.equal(m.isBetween(
  35952. moment(new Date(2011, 1, 2, 3, 4, 3, 10)),
  35953. moment(new Date(2011, 1, 2, 3, 4, 4, 999)), 'second'), false, 'second is later');
  35954. assert.equal(m.isBetween(m, 'second'), false, 'same moments are not between the same second');
  35955. assert.equal(+m, +mCopy, 'isBetween second should not change moment');
  35956. });
  35957. test('is between millisecond', function (assert) {
  35958. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
  35959. assert.equal(m.isBetween(
  35960. moment(new Date(2011, 1, 2, 3, 4, 5, 6)),
  35961. moment(new Date(2011, 1, 2, 3, 4, 5, 6)), 'millisecond'), false, 'millisecond match');
  35962. assert.equal(m.isBetween(
  35963. moment(new Date(2011, 1, 2, 3, 4, 5, 5)),
  35964. moment(new Date(2011, 1, 2, 3, 4, 5, 7)), 'milliseconds'), true, 'plural should work');
  35965. assert.equal(m.isBetween(
  35966. moment(new Date(2011, 1, 2, 3, 4, 5, 5)),
  35967. moment(new Date(2011, 1, 2, 3, 4, 5, 7)), 'millisecond'), true, 'millisecond is between');
  35968. assert.equal(m.isBetween(
  35969. moment(new Date(2011, 1, 2, 3, 4, 5, 7)),
  35970. moment(new Date(2011, 1, 2, 3, 4, 5, 10)), 'millisecond'), false, 'millisecond is earlier');
  35971. assert.equal(m.isBetween(
  35972. moment(new Date(2011, 1, 2, 3, 4, 5, 4)),
  35973. moment(new Date(2011, 1, 2, 3, 4, 5, 6)), 'millisecond'), false, 'millisecond is later');
  35974. assert.equal(m.isBetween(m, 'millisecond'), false, 'same moments are not between the same millisecond');
  35975. assert.equal(+m, +mCopy, 'isBetween millisecond should not change moment');
  35976. });
  35977. }));
  35978. ;(function (global, factory) {
  35979. typeof exports === 'object' && typeof module !== 'undefined'
  35980. && typeof require === 'function' ? factory(require('../../moment')) :
  35981. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  35982. factory(global.moment)
  35983. }(this, function (moment) { 'use strict';
  35984. /*global QUnit:false*/
  35985. var test = QUnit.test;
  35986. var expect = QUnit.expect;
  35987. function module (name, lifecycle) {
  35988. QUnit.module(name, {
  35989. setup : function () {
  35990. moment.locale('en');
  35991. moment.createFromInputFallback = function (config) {
  35992. throw new Error('input not handled by moment: ' + config._i);
  35993. };
  35994. if (lifecycle && lifecycle.setup) {
  35995. lifecycle.setup();
  35996. }
  35997. },
  35998. teardown : function () {
  35999. if (lifecycle && lifecycle.teardown) {
  36000. lifecycle.teardown();
  36001. }
  36002. }
  36003. });
  36004. }
  36005. function localeModule (name, lifecycle) {
  36006. QUnit.module('locale:' + name, {
  36007. setup : function () {
  36008. moment.locale(name);
  36009. moment.createFromInputFallback = function (config) {
  36010. throw new Error('input not handled by moment: ' + config._i);
  36011. };
  36012. if (lifecycle && lifecycle.setup) {
  36013. lifecycle.setup();
  36014. }
  36015. },
  36016. teardown : function () {
  36017. moment.locale('en');
  36018. if (lifecycle && lifecycle.teardown) {
  36019. lifecycle.teardown();
  36020. }
  36021. }
  36022. });
  36023. }
  36024. module('is date');
  36025. test('isDate recognizes Date objects', function (assert) {
  36026. assert.ok(moment.isDate(new Date()), 'no args (now)');
  36027. assert.ok(moment.isDate(new Date([2014, 2, 15])), 'array args');
  36028. assert.ok(moment.isDate(new Date('2014-03-15')), 'string args');
  36029. assert.ok(moment.isDate(new Date('does NOT look like a date')), 'invalid date');
  36030. });
  36031. test('isDate rejects non-Date objects', function (assert) {
  36032. assert.ok(!moment.isDate(), 'nothing');
  36033. assert.ok(!moment.isDate(undefined), 'undefined');
  36034. assert.ok(!moment.isDate(null), 'string args');
  36035. assert.ok(!moment.isDate(42), 'number');
  36036. assert.ok(!moment.isDate('2014-03-15'), 'string');
  36037. assert.ok(!moment.isDate([2014, 2, 15]), 'array');
  36038. assert.ok(!moment.isDate({year: 2014, month: 2, day: 15}), 'object');
  36039. assert.ok(!moment.isDate({toString: function () {
  36040. return '[object Date]';
  36041. }}), 'lying object');
  36042. });
  36043. }));
  36044. ;(function (global, factory) {
  36045. typeof exports === 'object' && typeof module !== 'undefined'
  36046. && typeof require === 'function' ? factory(require('../../moment')) :
  36047. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  36048. factory(global.moment)
  36049. }(this, function (moment) { 'use strict';
  36050. /*global QUnit:false*/
  36051. var test = QUnit.test;
  36052. var expect = QUnit.expect;
  36053. function module (name, lifecycle) {
  36054. QUnit.module(name, {
  36055. setup : function () {
  36056. moment.locale('en');
  36057. moment.createFromInputFallback = function (config) {
  36058. throw new Error('input not handled by moment: ' + config._i);
  36059. };
  36060. if (lifecycle && lifecycle.setup) {
  36061. lifecycle.setup();
  36062. }
  36063. },
  36064. teardown : function () {
  36065. if (lifecycle && lifecycle.teardown) {
  36066. lifecycle.teardown();
  36067. }
  36068. }
  36069. });
  36070. }
  36071. function localeModule (name, lifecycle) {
  36072. QUnit.module('locale:' + name, {
  36073. setup : function () {
  36074. moment.locale(name);
  36075. moment.createFromInputFallback = function (config) {
  36076. throw new Error('input not handled by moment: ' + config._i);
  36077. };
  36078. if (lifecycle && lifecycle.setup) {
  36079. lifecycle.setup();
  36080. }
  36081. },
  36082. teardown : function () {
  36083. moment.locale('en');
  36084. if (lifecycle && lifecycle.teardown) {
  36085. lifecycle.teardown();
  36086. }
  36087. }
  36088. });
  36089. }
  36090. module('is moment');
  36091. test('is moment object', function (assert) {
  36092. var MyObj = function () {},
  36093. extend = function (a, b) {
  36094. var i;
  36095. for (i in b) {
  36096. a[i] = b[i];
  36097. }
  36098. return a;
  36099. };
  36100. MyObj.prototype.toDate = function () {
  36101. return new Date();
  36102. };
  36103. assert.ok(moment.isMoment(moment()), 'simple moment object');
  36104. assert.ok(moment.isMoment(moment(null)), 'invalid moment object');
  36105. assert.ok(moment.isMoment(extend({}, moment())), 'externally cloned moments are moments');
  36106. assert.ok(moment.isMoment(extend({}, moment.utc())), 'externally cloned utc moments are moments');
  36107. assert.ok(!moment.isMoment(new MyObj()), 'myObj is not moment object');
  36108. assert.ok(!moment.isMoment(moment), 'moment function is not moment object');
  36109. assert.ok(!moment.isMoment(new Date()), 'date object is not moment object');
  36110. assert.ok(!moment.isMoment(Object), 'Object is not moment object');
  36111. assert.ok(!moment.isMoment('foo'), 'string is not moment object');
  36112. assert.ok(!moment.isMoment(1), 'number is not moment object');
  36113. assert.ok(!moment.isMoment(NaN), 'NaN is not moment object');
  36114. assert.ok(!moment.isMoment(null), 'null is not moment object');
  36115. assert.ok(!moment.isMoment(undefined), 'undefined is not moment object');
  36116. });
  36117. test('is moment with hacked hasOwnProperty', function (assert) {
  36118. var obj = {};
  36119. // HACK to suppress jshint warning about bad property name
  36120. obj['hasOwnMoney'.replace('Money', 'Property')] = function () {
  36121. return true;
  36122. };
  36123. assert.ok(!moment.isMoment(obj), 'isMoment works even if passed object has a wrong hasOwnProperty implementation (ie8)');
  36124. });
  36125. }));
  36126. ;(function (global, factory) {
  36127. typeof exports === 'object' && typeof module !== 'undefined'
  36128. && typeof require === 'function' ? factory(require('../../moment')) :
  36129. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  36130. factory(global.moment)
  36131. }(this, function (moment) { 'use strict';
  36132. /*global QUnit:false*/
  36133. var test = QUnit.test;
  36134. var expect = QUnit.expect;
  36135. function module (name, lifecycle) {
  36136. QUnit.module(name, {
  36137. setup : function () {
  36138. moment.locale('en');
  36139. moment.createFromInputFallback = function (config) {
  36140. throw new Error('input not handled by moment: ' + config._i);
  36141. };
  36142. if (lifecycle && lifecycle.setup) {
  36143. lifecycle.setup();
  36144. }
  36145. },
  36146. teardown : function () {
  36147. if (lifecycle && lifecycle.teardown) {
  36148. lifecycle.teardown();
  36149. }
  36150. }
  36151. });
  36152. }
  36153. function localeModule (name, lifecycle) {
  36154. QUnit.module('locale:' + name, {
  36155. setup : function () {
  36156. moment.locale(name);
  36157. moment.createFromInputFallback = function (config) {
  36158. throw new Error('input not handled by moment: ' + config._i);
  36159. };
  36160. if (lifecycle && lifecycle.setup) {
  36161. lifecycle.setup();
  36162. }
  36163. },
  36164. teardown : function () {
  36165. moment.locale('en');
  36166. if (lifecycle && lifecycle.teardown) {
  36167. lifecycle.teardown();
  36168. }
  36169. }
  36170. });
  36171. }
  36172. module('is same');
  36173. test('is same without units', function (assert) {
  36174. var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
  36175. assert.equal(m.isSame(moment(new Date(2012, 3, 2, 3, 5, 5, 10))), false, 'year is later');
  36176. assert.equal(m.isSame(moment(new Date(2010, 3, 2, 3, 3, 5, 10))), false, 'year is earlier');
  36177. assert.equal(m.isSame(moment(new Date(2011, 4, 2, 3, 4, 5, 10))), false, 'month is later');
  36178. assert.equal(m.isSame(moment(new Date(2011, 2, 2, 3, 4, 5, 10))), false, 'month is earlier');
  36179. assert.equal(m.isSame(moment(new Date(2011, 3, 3, 3, 4, 5, 10))), false, 'day is later');
  36180. assert.equal(m.isSame(moment(new Date(2011, 3, 1, 3, 4, 5, 10))), false, 'day is earlier');
  36181. assert.equal(m.isSame(moment(new Date(2011, 3, 2, 4, 4, 5, 10))), false, 'hour is later');
  36182. assert.equal(m.isSame(moment(new Date(2011, 3, 2, 2, 4, 5, 10))), false, 'hour is earlier');
  36183. assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 5, 5, 10))), false, 'minute is later');
  36184. assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 3, 5, 10))), false, 'minute is earlier');
  36185. assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 6, 10))), false, 'second is later');
  36186. assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 4, 11))), false, 'second is earlier');
  36187. assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 5, 10))), true, 'millisecond match');
  36188. assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 5, 11))), false, 'millisecond is later');
  36189. assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 5, 9))), false, 'millisecond is earlier');
  36190. assert.equal(m.isSame(m), true, 'moments are the same as themselves');
  36191. assert.equal(+m, +mCopy, 'isSame second should not change moment');
  36192. });
  36193. test('is same year', function (assert) {
  36194. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
  36195. assert.equal(m.isSame(moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'year'), true, 'year match');
  36196. assert.equal(m.isSame(moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'years'), true, 'plural should work');
  36197. assert.equal(m.isSame(moment(new Date(2012, 5, 6, 7, 8, 9, 10)), 'year'), false, 'year mismatch');
  36198. assert.equal(m.isSame(moment(new Date(2011, 0, 1, 0, 0, 0, 0)), 'year'), true, 'exact start of year');
  36199. assert.equal(m.isSame(moment(new Date(2011, 11, 31, 23, 59, 59, 999)), 'year'), true, 'exact end of year');
  36200. assert.equal(m.isSame(moment(new Date(2012, 0, 1, 0, 0, 0, 0)), 'year'), false, 'start of next year');
  36201. assert.equal(m.isSame(moment(new Date(2010, 11, 31, 23, 59, 59, 999)), 'year'), false, 'end of previous year');
  36202. assert.equal(m.isSame(m, 'year'), true, 'same moments are in the same year');
  36203. assert.equal(+m, +mCopy, 'isSame year should not change moment');
  36204. });
  36205. test('is same month', function (assert) {
  36206. var m = moment(new Date(2011, 2, 3, 4, 5, 6, 7)), mCopy = moment(m);
  36207. assert.equal(m.isSame(moment(new Date(2011, 2, 6, 7, 8, 9, 10)), 'month'), true, 'month match');
  36208. assert.equal(m.isSame(moment(new Date(2011, 2, 6, 7, 8, 9, 10)), 'months'), true, 'plural should work');
  36209. assert.equal(m.isSame(moment(new Date(2012, 2, 6, 7, 8, 9, 10)), 'month'), false, 'year mismatch');
  36210. assert.equal(m.isSame(moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'month'), false, 'month mismatch');
  36211. assert.equal(m.isSame(moment(new Date(2011, 2, 1, 0, 0, 0, 0)), 'month'), true, 'exact start of month');
  36212. assert.equal(m.isSame(moment(new Date(2011, 2, 31, 23, 59, 59, 999)), 'month'), true, 'exact end of month');
  36213. assert.equal(m.isSame(moment(new Date(2011, 3, 1, 0, 0, 0, 0)), 'month'), false, 'start of next month');
  36214. assert.equal(m.isSame(moment(new Date(2011, 1, 27, 23, 59, 59, 999)), 'month'), false, 'end of previous month');
  36215. assert.equal(m.isSame(m, 'month'), true, 'same moments are in the same month');
  36216. assert.equal(+m, +mCopy, 'isSame month should not change moment');
  36217. });
  36218. test('is same day', function (assert) {
  36219. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
  36220. assert.equal(m.isSame(moment(new Date(2011, 1, 2, 7, 8, 9, 10)), 'day'), true, 'day match');
  36221. assert.equal(m.isSame(moment(new Date(2011, 1, 2, 7, 8, 9, 10)), 'days'), true, 'plural should work');
  36222. assert.equal(m.isSame(moment(new Date(2012, 1, 2, 7, 8, 9, 10)), 'day'), false, 'year mismatch');
  36223. assert.equal(m.isSame(moment(new Date(2011, 2, 2, 7, 8, 9, 10)), 'day'), false, 'month mismatch');
  36224. assert.equal(m.isSame(moment(new Date(2011, 1, 3, 7, 8, 9, 10)), 'day'), false, 'day mismatch');
  36225. assert.equal(m.isSame(moment(new Date(2011, 1, 2, 0, 0, 0, 0)), 'day'), true, 'exact start of day');
  36226. assert.equal(m.isSame(moment(new Date(2011, 1, 2, 23, 59, 59, 999)), 'day'), true, 'exact end of day');
  36227. assert.equal(m.isSame(moment(new Date(2011, 1, 3, 0, 0, 0, 0)), 'day'), false, 'start of next day');
  36228. assert.equal(m.isSame(moment(new Date(2011, 1, 1, 23, 59, 59, 999)), 'day'), false, 'end of previous day');
  36229. assert.equal(m.isSame(m, 'day'), true, 'same moments are in the same day');
  36230. assert.equal(+m, +mCopy, 'isSame day should not change moment');
  36231. });
  36232. test('is same hour', function (assert) {
  36233. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
  36234. assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 8, 9, 10)), 'hour'), true, 'hour match');
  36235. assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 8, 9, 10)), 'hours'), true, 'plural should work');
  36236. assert.equal(m.isSame(moment(new Date(2012, 1, 2, 3, 8, 9, 10)), 'hour'), false, 'year mismatch');
  36237. assert.equal(m.isSame(moment(new Date(2011, 2, 2, 3, 8, 9, 10)), 'hour'), false, 'month mismatch');
  36238. assert.equal(m.isSame(moment(new Date(2011, 1, 3, 3, 8, 9, 10)), 'hour'), false, 'day mismatch');
  36239. assert.equal(m.isSame(moment(new Date(2011, 1, 2, 4, 8, 9, 10)), 'hour'), false, 'hour mismatch');
  36240. assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 0, 0, 0)), 'hour'), true, 'exact start of hour');
  36241. assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 59, 59, 999)), 'hour'), true, 'exact end of hour');
  36242. assert.equal(m.isSame(moment(new Date(2011, 1, 2, 4, 0, 0, 0)), 'hour'), false, 'start of next hour');
  36243. assert.equal(m.isSame(moment(new Date(2011, 1, 2, 2, 59, 59, 999)), 'hour'), false, 'end of previous hour');
  36244. assert.equal(m.isSame(m, 'hour'), true, 'same moments are in the same hour');
  36245. assert.equal(+m, +mCopy, 'isSame hour should not change moment');
  36246. });
  36247. test('is same minute', function (assert) {
  36248. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
  36249. assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 4, 9, 10)), 'minute'), true, 'minute match');
  36250. assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 4, 9, 10)), 'minutes'), true, 'plural should work');
  36251. assert.equal(m.isSame(moment(new Date(2012, 1, 2, 3, 4, 9, 10)), 'minute'), false, 'year mismatch');
  36252. assert.equal(m.isSame(moment(new Date(2011, 2, 2, 3, 4, 9, 10)), 'minute'), false, 'month mismatch');
  36253. assert.equal(m.isSame(moment(new Date(2011, 1, 3, 3, 4, 9, 10)), 'minute'), false, 'day mismatch');
  36254. assert.equal(m.isSame(moment(new Date(2011, 1, 2, 4, 4, 9, 10)), 'minute'), false, 'hour mismatch');
  36255. assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 5, 9, 10)), 'minute'), false, 'minute mismatch');
  36256. assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 4, 0, 0)), 'minute'), true, 'exact start of minute');
  36257. assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 4, 59, 999)), 'minute'), true, 'exact end of minute');
  36258. assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 5, 0, 0)), 'minute'), false, 'start of next minute');
  36259. assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 3, 59, 999)), 'minute'), false, 'end of previous minute');
  36260. assert.equal(m.isSame(m, 'minute'), true, 'same moments are in the same minute');
  36261. assert.equal(+m, +mCopy, 'isSame minute should not change moment');
  36262. });
  36263. test('is same second', function (assert) {
  36264. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
  36265. assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 4, 5, 10)), 'second'), true, 'second match');
  36266. assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 4, 5, 10)), 'seconds'), true, 'plural should work');
  36267. assert.equal(m.isSame(moment(new Date(2012, 1, 2, 3, 4, 5, 10)), 'second'), false, 'year mismatch');
  36268. assert.equal(m.isSame(moment(new Date(2011, 2, 2, 3, 4, 5, 10)), 'second'), false, 'month mismatch');
  36269. assert.equal(m.isSame(moment(new Date(2011, 1, 3, 3, 4, 5, 10)), 'second'), false, 'day mismatch');
  36270. assert.equal(m.isSame(moment(new Date(2011, 1, 2, 4, 4, 5, 10)), 'second'), false, 'hour mismatch');
  36271. assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 5, 5, 10)), 'second'), false, 'minute mismatch');
  36272. assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 4, 6, 10)), 'second'), false, 'second mismatch');
  36273. assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 4, 5, 0)), 'second'), true, 'exact start of second');
  36274. assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 4, 5, 999)), 'second'), true, 'exact end of second');
  36275. assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 4, 6, 0)), 'second'), false, 'start of next second');
  36276. assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 4, 4, 999)), 'second'), false, 'end of previous second');
  36277. assert.equal(m.isSame(m, 'second'), true, 'same moments are in the same second');
  36278. assert.equal(+m, +mCopy, 'isSame second should not change moment');
  36279. });
  36280. test('is same millisecond', function (assert) {
  36281. var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
  36282. assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 5, 10)), 'millisecond'), true, 'millisecond match');
  36283. assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 5, 10)), 'milliseconds'), true, 'plural should work');
  36284. assert.equal(m.isSame(moment(new Date(2012, 3, 2, 3, 4, 5, 10)), 'millisecond'), false, 'year is later');
  36285. assert.equal(m.isSame(moment(new Date(2010, 3, 2, 3, 4, 5, 10)), 'millisecond'), false, 'year is earlier');
  36286. assert.equal(m.isSame(moment(new Date(2011, 4, 2, 3, 4, 5, 10)), 'millisecond'), false, 'month is later');
  36287. assert.equal(m.isSame(moment(new Date(2011, 2, 2, 3, 4, 5, 10)), 'millisecond'), false, 'month is earlier');
  36288. assert.equal(m.isSame(moment(new Date(2011, 3, 3, 3, 4, 5, 10)), 'millisecond'), false, 'day is later');
  36289. assert.equal(m.isSame(moment(new Date(2011, 3, 1, 1, 4, 5, 10)), 'millisecond'), false, 'day is earlier');
  36290. assert.equal(m.isSame(moment(new Date(2011, 3, 2, 4, 4, 5, 10)), 'millisecond'), false, 'hour is later');
  36291. assert.equal(m.isSame(moment(new Date(2011, 3, 1, 4, 1, 5, 10)), 'millisecond'), false, 'hour is earlier');
  36292. assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 5, 5, 10)), 'millisecond'), false, 'minute is later');
  36293. assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 3, 5, 10)), 'millisecond'), false, 'minute is earlier');
  36294. assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 6, 10)), 'millisecond'), false, 'second is later');
  36295. assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 4, 5)), 'millisecond'), false, 'second is earlier');
  36296. assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 6, 11)), 'millisecond'), false, 'millisecond is later');
  36297. assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 4, 9)), 'millisecond'), false, 'millisecond is earlier');
  36298. assert.equal(m.isSame(m, 'millisecond'), true, 'same moments are in the same millisecond');
  36299. assert.equal(+m, +mCopy, 'isSame millisecond should not change moment');
  36300. });
  36301. test('is same with utc offset moments', function (assert) {
  36302. assert.ok(moment.parseZone('2013-02-01T-05:00').isSame(moment('2013-02-01'), 'year'), 'zoned vs local moment');
  36303. assert.ok(moment('2013-02-01').isSame(moment('2013-02-01').utcOffset('-05:00'), 'year'), 'local vs zoned moment');
  36304. assert.ok(moment.parseZone('2013-02-01T-05:00').isSame(moment.parseZone('2013-02-01T-06:30'), 'year'),
  36305. 'zoned vs (differently) zoned moment');
  36306. });
  36307. test('is same with invalid moments', function (assert) {
  36308. assert.equal(moment.invalid().isSame(moment.invalid()), false, 'invalid moments are not considered equal');
  36309. });
  36310. }));
  36311. ;(function (global, factory) {
  36312. typeof exports === 'object' && typeof module !== 'undefined'
  36313. && typeof require === 'function' ? factory(require('../../moment')) :
  36314. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  36315. factory(global.moment)
  36316. }(this, function (moment) { 'use strict';
  36317. /*global QUnit:false*/
  36318. var test = QUnit.test;
  36319. var expect = QUnit.expect;
  36320. function module (name, lifecycle) {
  36321. QUnit.module(name, {
  36322. setup : function () {
  36323. moment.locale('en');
  36324. moment.createFromInputFallback = function (config) {
  36325. throw new Error('input not handled by moment: ' + config._i);
  36326. };
  36327. if (lifecycle && lifecycle.setup) {
  36328. lifecycle.setup();
  36329. }
  36330. },
  36331. teardown : function () {
  36332. if (lifecycle && lifecycle.teardown) {
  36333. lifecycle.teardown();
  36334. }
  36335. }
  36336. });
  36337. }
  36338. function localeModule (name, lifecycle) {
  36339. QUnit.module('locale:' + name, {
  36340. setup : function () {
  36341. moment.locale(name);
  36342. moment.createFromInputFallback = function (config) {
  36343. throw new Error('input not handled by moment: ' + config._i);
  36344. };
  36345. if (lifecycle && lifecycle.setup) {
  36346. lifecycle.setup();
  36347. }
  36348. },
  36349. teardown : function () {
  36350. moment.locale('en');
  36351. if (lifecycle && lifecycle.teardown) {
  36352. lifecycle.teardown();
  36353. }
  36354. }
  36355. });
  36356. }
  36357. module('is same or after');
  36358. test('is same or after without units', function (assert) {
  36359. var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
  36360. assert.equal(m.isSameOrAfter(moment(new Date(2012, 3, 2, 3, 5, 5, 10))), false, 'year is later');
  36361. assert.equal(m.isSameOrAfter(moment(new Date(2010, 3, 2, 3, 3, 5, 10))), true, 'year is earlier');
  36362. assert.equal(m.isSameOrAfter(moment(new Date(2011, 4, 2, 3, 4, 5, 10))), false, 'month is later');
  36363. assert.equal(m.isSameOrAfter(moment(new Date(2011, 2, 2, 3, 4, 5, 10))), true, 'month is earlier');
  36364. assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 3, 3, 4, 5, 10))), false, 'day is later');
  36365. assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 1, 3, 4, 5, 10))), true, 'day is earlier');
  36366. assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 2, 4, 4, 5, 10))), false, 'hour is later');
  36367. assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 2, 2, 4, 5, 10))), true, 'hour is earlier');
  36368. assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 2, 3, 5, 5, 10))), false, 'minute is later');
  36369. assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 2, 3, 3, 5, 10))), true, 'minute is earlier');
  36370. assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 2, 3, 4, 6, 10))), false, 'second is later');
  36371. assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 2, 3, 4, 4, 11))), true, 'second is earlier');
  36372. assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 10))), true, 'millisecond match');
  36373. assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 11))), false, 'millisecond is later');
  36374. assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 9))), true, 'millisecond is earlier');
  36375. assert.equal(m.isSameOrAfter(m), true, 'moments are the same as themselves');
  36376. assert.equal(+m, +mCopy, 'isSameOrAfter second should not change moment');
  36377. });
  36378. test('is same or after year', function (assert) {
  36379. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
  36380. assert.equal(m.isSameOrAfter(moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'year'), true, 'year match');
  36381. assert.equal(m.isSameOrAfter(moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'years'), true, 'plural should work');
  36382. assert.equal(m.isSameOrAfter(moment(new Date(2012, 5, 6, 7, 8, 9, 10)), 'year'), false, 'year is later');
  36383. assert.equal(m.isSameOrAfter(moment(new Date(2010, 5, 6, 7, 8, 9, 10)), 'year'), true, 'year is earlier');
  36384. assert.equal(m.isSameOrAfter(moment(new Date(2011, 0, 1, 0, 0, 0, 0)), 'year'), true, 'exact start of year');
  36385. assert.equal(m.isSameOrAfter(moment(new Date(2011, 11, 31, 23, 59, 59, 999)), 'year'), true, 'exact end of year');
  36386. assert.equal(m.isSameOrAfter(moment(new Date(2012, 0, 1, 0, 0, 0, 0)), 'year'), false, 'start of next year');
  36387. assert.equal(m.isSameOrAfter(moment(new Date(2010, 11, 31, 23, 59, 59, 999)), 'year'), true, 'end of previous year');
  36388. assert.equal(m.isSameOrAfter(m, 'year'), true, 'same moments are in the same year');
  36389. assert.equal(+m, +mCopy, 'isSameOrAfter year should not change moment');
  36390. });
  36391. test('is same or after month', function (assert) {
  36392. var m = moment(new Date(2011, 2, 3, 4, 5, 6, 7)), mCopy = moment(m);
  36393. assert.equal(m.isSameOrAfter(moment(new Date(2011, 2, 6, 7, 8, 9, 10)), 'month'), true, 'month match');
  36394. assert.equal(m.isSameOrAfter(moment(new Date(2011, 2, 6, 7, 8, 9, 10)), 'months'), true, 'plural should work');
  36395. assert.equal(m.isSameOrAfter(moment(new Date(2012, 2, 6, 7, 8, 9, 10)), 'month'), false, 'year is later');
  36396. assert.equal(m.isSameOrAfter(moment(new Date(2010, 2, 6, 7, 8, 9, 10)), 'month'), true, 'year is earlier');
  36397. assert.equal(m.isSameOrAfter(moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'month'), false, 'month is later');
  36398. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 6, 7, 8, 9, 10)), 'month'), true, 'month is earlier');
  36399. assert.equal(m.isSameOrAfter(moment(new Date(2011, 2, 1, 0, 0, 0, 0)), 'month'), true, 'exact start of month');
  36400. assert.equal(m.isSameOrAfter(moment(new Date(2011, 2, 31, 23, 59, 59, 999)), 'month'), true, 'exact end of month');
  36401. assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 1, 0, 0, 0, 0)), 'month'), false, 'start of next month');
  36402. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 27, 23, 59, 59, 999)), 'month'), true, 'end of previous month');
  36403. assert.equal(m.isSameOrAfter(m, 'month'), true, 'same moments are in the same month');
  36404. assert.equal(+m, +mCopy, 'isSameOrAfter month should not change moment');
  36405. });
  36406. test('is same or after day', function (assert) {
  36407. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
  36408. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 7, 8, 9, 10)), 'day'), true, 'day match');
  36409. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 7, 8, 9, 10)), 'days'), true, 'plural should work');
  36410. assert.equal(m.isSameOrAfter(moment(new Date(2012, 1, 2, 7, 8, 9, 10)), 'day'), false, 'year is later');
  36411. assert.equal(m.isSameOrAfter(moment(new Date(2010, 1, 2, 7, 8, 9, 10)), 'day'), true, 'year is earlier');
  36412. assert.equal(m.isSameOrAfter(moment(new Date(2011, 2, 2, 7, 8, 9, 10)), 'day'), false, 'month is later');
  36413. assert.equal(m.isSameOrAfter(moment(new Date(2010, 12, 2, 7, 8, 9, 10)), 'day'), true, 'month is earlier');
  36414. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 3, 7, 8, 9, 10)), 'day'), false, 'day is later');
  36415. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 1, 7, 8, 9, 10)), 'day'), true, 'day is earlier');
  36416. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 0, 0, 0, 0)), 'day'), true, 'exact start of day');
  36417. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 23, 59, 59, 999)), 'day'), true, 'exact end of day');
  36418. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 3, 0, 0, 0, 0)), 'day'), false, 'start of next day');
  36419. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 1, 23, 59, 59, 999)), 'day'), true, 'end of previous day');
  36420. assert.equal(m.isSameOrAfter(m, 'day'), true, 'same moments are in the same day');
  36421. assert.equal(+m, +mCopy, 'isSameOrAfter day should not change moment');
  36422. });
  36423. test('is same or after hour', function (assert) {
  36424. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
  36425. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 8, 9, 10)), 'hour'), true, 'hour match');
  36426. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 8, 9, 10)), 'hours'), true, 'plural should work');
  36427. assert.equal(m.isSameOrAfter(moment(new Date(2012, 1, 2, 3, 8, 9, 10)), 'hour'), false, 'year is later');
  36428. assert.equal(m.isSameOrAfter(moment(new Date(2010, 1, 2, 3, 8, 9, 10)), 'hour'), true, 'year is earlier');
  36429. assert.equal(m.isSameOrAfter(moment(new Date(2011, 2, 2, 3, 8, 9, 10)), 'hour'), false, 'month is later');
  36430. assert.equal(m.isSameOrAfter(moment(new Date(2010, 12, 2, 3, 8, 9, 10)), 'hour'), true, 'month is earlier');
  36431. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 3, 3, 8, 9, 10)), 'hour'), false, 'day is later');
  36432. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 1, 3, 8, 9, 10)), 'hour'), true, 'day is earlier');
  36433. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 4, 8, 9, 10)), 'hour'), false, 'hour is later');
  36434. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 2, 8, 9, 10)), 'hour'), true, 'hour is earlier');
  36435. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 0, 0, 0)), 'hour'), true, 'exact start of hour');
  36436. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 59, 59, 999)), 'hour'), true, 'exact end of hour');
  36437. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 4, 0, 0, 0)), 'hour'), false, 'start of next hour');
  36438. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 2, 59, 59, 999)), 'hour'), true, 'end of previous hour');
  36439. assert.equal(m.isSameOrAfter(m, 'hour'), true, 'same moments are in the same hour');
  36440. assert.equal(+m, +mCopy, 'isSameOrAfter hour should not change moment');
  36441. });
  36442. test('is same or after minute', function (assert) {
  36443. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
  36444. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 4, 9, 10)), 'minute'), true, 'minute match');
  36445. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 4, 9, 10)), 'minutes'), true, 'plural should work');
  36446. assert.equal(m.isSameOrAfter(moment(new Date(2012, 1, 2, 3, 4, 9, 10)), 'minute'), false, 'year is later');
  36447. assert.equal(m.isSameOrAfter(moment(new Date(2010, 1, 2, 3, 4, 9, 10)), 'minute'), true, 'year is earlier');
  36448. assert.equal(m.isSameOrAfter(moment(new Date(2011, 2, 2, 3, 4, 9, 10)), 'minute'), false, 'month is later');
  36449. assert.equal(m.isSameOrAfter(moment(new Date(2010, 12, 2, 3, 4, 9, 10)), 'minute'), true, 'month is earlier');
  36450. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 3, 3, 4, 9, 10)), 'minute'), false, 'day is later');
  36451. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 1, 3, 4, 9, 10)), 'minute'), true, 'day is earlier');
  36452. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 4, 4, 9, 10)), 'minute'), false, 'hour is later');
  36453. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 2, 4, 9, 10)), 'minute'), true, 'hour is earlier');
  36454. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 5, 9, 10)), 'minute'), false, 'minute is later');
  36455. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 3, 9, 10)), 'minute'), true, 'minute is earlier');
  36456. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 4, 0, 0)), 'minute'), true, 'exact start of minute');
  36457. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 4, 59, 999)), 'minute'), true, 'exact end of minute');
  36458. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 5, 0, 0)), 'minute'), false, 'start of next minute');
  36459. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 3, 59, 999)), 'minute'), true, 'end of previous minute');
  36460. assert.equal(m.isSameOrAfter(m, 'minute'), true, 'same moments are in the same minute');
  36461. assert.equal(+m, +mCopy, 'isSameOrAfter minute should not change moment');
  36462. });
  36463. test('is same or after second', function (assert) {
  36464. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
  36465. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 4, 5, 10)), 'second'), true, 'second match');
  36466. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 4, 5, 10)), 'seconds'), true, 'plural should work');
  36467. assert.equal(m.isSameOrAfter(moment(new Date(2012, 1, 2, 3, 4, 5, 10)), 'second'), false, 'year is later');
  36468. assert.equal(m.isSameOrAfter(moment(new Date(2010, 1, 2, 3, 4, 5, 10)), 'second'), true, 'year is earlier');
  36469. assert.equal(m.isSameOrAfter(moment(new Date(2011, 2, 2, 3, 4, 5, 10)), 'second'), false, 'month is later');
  36470. assert.equal(m.isSameOrAfter(moment(new Date(2010, 12, 2, 3, 4, 5, 10)), 'second'), true, 'month is earlier');
  36471. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 3, 3, 4, 5, 10)), 'second'), false, 'day is later');
  36472. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 1, 3, 4, 5, 10)), 'second'), true, 'day is earlier');
  36473. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 4, 4, 5, 10)), 'second'), false, 'hour is later');
  36474. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 2, 4, 5, 10)), 'second'), true, 'hour is earlier');
  36475. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 5, 5, 10)), 'second'), false, 'minute is later');
  36476. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 3, 5, 10)), 'second'), true, 'minute is earlier');
  36477. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 4, 6, 10)), 'second'), false, 'second is later');
  36478. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 4, 4, 10)), 'second'), true, 'second is earlier');
  36479. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 4, 5, 0)), 'second'), true, 'exact start of second');
  36480. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 4, 5, 999)), 'second'), true, 'exact end of second');
  36481. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 4, 6, 0)), 'second'), false, 'start of next second');
  36482. assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 4, 4, 999)), 'second'), true, 'end of previous second');
  36483. assert.equal(m.isSameOrAfter(m, 'second'), true, 'same moments are in the same second');
  36484. assert.equal(+m, +mCopy, 'isSameOrAfter second should not change moment');
  36485. });
  36486. test('is same or after millisecond', function (assert) {
  36487. var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
  36488. assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 10)), 'millisecond'), true, 'millisecond match');
  36489. assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 10)), 'milliseconds'), true, 'plural should work');
  36490. assert.equal(m.isSameOrAfter(moment(new Date(2012, 3, 2, 3, 4, 5, 10)), 'millisecond'), false, 'year is later');
  36491. assert.equal(m.isSameOrAfter(moment(new Date(2010, 3, 2, 3, 4, 5, 10)), 'millisecond'), true, 'year is earlier');
  36492. assert.equal(m.isSameOrAfter(moment(new Date(2011, 4, 2, 3, 4, 5, 10)), 'millisecond'), false, 'month is later');
  36493. assert.equal(m.isSameOrAfter(moment(new Date(2011, 2, 2, 3, 4, 5, 10)), 'millisecond'), true, 'month is earlier');
  36494. assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 3, 3, 4, 5, 10)), 'millisecond'), false, 'day is later');
  36495. assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 1, 1, 4, 5, 10)), 'millisecond'), true, 'day is earlier');
  36496. assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 2, 4, 4, 5, 10)), 'millisecond'), false, 'hour is later');
  36497. assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 1, 4, 1, 5, 10)), 'millisecond'), true, 'hour is earlier');
  36498. assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 2, 3, 5, 5, 10)), 'millisecond'), false, 'minute is later');
  36499. assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 2, 3, 3, 5, 10)), 'millisecond'), true, 'minute is earlier');
  36500. assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 2, 3, 4, 6, 10)), 'millisecond'), false, 'second is later');
  36501. assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 2, 3, 4, 4, 5)), 'millisecond'), true, 'second is earlier');
  36502. assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 2, 3, 4, 6, 11)), 'millisecond'), false, 'millisecond is later');
  36503. assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 2, 3, 4, 4, 9)), 'millisecond'), true, 'millisecond is earlier');
  36504. assert.equal(m.isSameOrAfter(m, 'millisecond'), true, 'same moments are in the same millisecond');
  36505. assert.equal(+m, +mCopy, 'isSameOrAfter millisecond should not change moment');
  36506. });
  36507. test('is same or after with utc offset moments', function (assert) {
  36508. assert.ok(moment.parseZone('2013-02-01T-05:00').isSameOrAfter(moment('2013-02-01'), 'year'), 'zoned vs local moment');
  36509. assert.ok(moment('2013-02-01').isSameOrAfter(moment('2013-02-01').utcOffset('-05:00'), 'year'), 'local vs zoned moment');
  36510. assert.ok(moment.parseZone('2013-02-01T-05:00').isSameOrAfter(moment.parseZone('2013-02-01T-06:30'), 'year'),
  36511. 'zoned vs (differently) zoned moment');
  36512. });
  36513. test('is same or after with invalid moments', function (assert) {
  36514. var m = moment(), invalid = moment.invalid();
  36515. assert.equal(invalid.isSameOrAfter(invalid), false, 'invalid moments are not considered equal');
  36516. assert.equal(m.isSameOrAfter(invalid), false, 'valid moment is not after invalid moment');
  36517. assert.equal(invalid.isSameOrAfter(m), false, 'invalid moment is not after valid moment');
  36518. assert.equal(m.isSameOrAfter(invalid, 'year'), false, 'invalid moment year');
  36519. assert.equal(m.isSameOrAfter(invalid, 'month'), false, 'invalid moment month');
  36520. assert.equal(m.isSameOrAfter(invalid, 'day'), false, 'invalid moment day');
  36521. assert.equal(m.isSameOrAfter(invalid, 'hour'), false, 'invalid moment hour');
  36522. assert.equal(m.isSameOrAfter(invalid, 'minute'), false, 'invalid moment minute');
  36523. assert.equal(m.isSameOrAfter(invalid, 'second'), false, 'invalid moment second');
  36524. assert.equal(m.isSameOrAfter(invalid, 'milliseconds'), false, 'invalid moment milliseconds');
  36525. });
  36526. }));
  36527. ;(function (global, factory) {
  36528. typeof exports === 'object' && typeof module !== 'undefined'
  36529. && typeof require === 'function' ? factory(require('../../moment')) :
  36530. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  36531. factory(global.moment)
  36532. }(this, function (moment) { 'use strict';
  36533. /*global QUnit:false*/
  36534. var test = QUnit.test;
  36535. var expect = QUnit.expect;
  36536. function module (name, lifecycle) {
  36537. QUnit.module(name, {
  36538. setup : function () {
  36539. moment.locale('en');
  36540. moment.createFromInputFallback = function (config) {
  36541. throw new Error('input not handled by moment: ' + config._i);
  36542. };
  36543. if (lifecycle && lifecycle.setup) {
  36544. lifecycle.setup();
  36545. }
  36546. },
  36547. teardown : function () {
  36548. if (lifecycle && lifecycle.teardown) {
  36549. lifecycle.teardown();
  36550. }
  36551. }
  36552. });
  36553. }
  36554. function localeModule (name, lifecycle) {
  36555. QUnit.module('locale:' + name, {
  36556. setup : function () {
  36557. moment.locale(name);
  36558. moment.createFromInputFallback = function (config) {
  36559. throw new Error('input not handled by moment: ' + config._i);
  36560. };
  36561. if (lifecycle && lifecycle.setup) {
  36562. lifecycle.setup();
  36563. }
  36564. },
  36565. teardown : function () {
  36566. moment.locale('en');
  36567. if (lifecycle && lifecycle.teardown) {
  36568. lifecycle.teardown();
  36569. }
  36570. }
  36571. });
  36572. }
  36573. module('is same or before');
  36574. test('is same or before without units', function (assert) {
  36575. var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
  36576. assert.equal(m.isSameOrBefore(moment(new Date(2012, 3, 2, 3, 5, 5, 10))), true, 'year is later');
  36577. assert.equal(m.isSameOrBefore(moment(new Date(2010, 3, 2, 3, 3, 5, 10))), false, 'year is earlier');
  36578. assert.equal(m.isSameOrBefore(moment(new Date(2011, 4, 2, 3, 4, 5, 10))), true, 'month is later');
  36579. assert.equal(m.isSameOrBefore(moment(new Date(2011, 2, 2, 3, 4, 5, 10))), false, 'month is earlier');
  36580. assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 3, 3, 4, 5, 10))), true, 'day is later');
  36581. assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 1, 3, 4, 5, 10))), false, 'day is earlier');
  36582. assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 2, 4, 4, 5, 10))), true, 'hour is later');
  36583. assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 2, 2, 4, 5, 10))), false, 'hour is earlier');
  36584. assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 2, 3, 5, 5, 10))), true, 'minute is later');
  36585. assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 2, 3, 3, 5, 10))), false, 'minute is earlier');
  36586. assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 2, 3, 4, 6, 10))), true, 'second is later');
  36587. assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 2, 3, 4, 4, 11))), false, 'second is earlier');
  36588. assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 10))), true, 'millisecond match');
  36589. assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 11))), true, 'millisecond is later');
  36590. assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 9))), false, 'millisecond is earlier');
  36591. assert.equal(m.isSameOrBefore(m), true, 'moments are the same as themselves');
  36592. assert.equal(+m, +mCopy, 'isSameOrBefore second should not change moment');
  36593. });
  36594. test('is same or before year', function (assert) {
  36595. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
  36596. assert.equal(m.isSameOrBefore(moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'year'), true, 'year match');
  36597. assert.equal(m.isSameOrBefore(moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'years'), true, 'plural should work');
  36598. assert.equal(m.isSameOrBefore(moment(new Date(2012, 5, 6, 7, 8, 9, 10)), 'year'), true, 'year is later');
  36599. assert.equal(m.isSameOrBefore(moment(new Date(2010, 5, 6, 7, 8, 9, 10)), 'year'), false, 'year is earlier');
  36600. assert.equal(m.isSameOrBefore(moment(new Date(2011, 0, 1, 0, 0, 0, 0)), 'year'), true, 'exact start of year');
  36601. assert.equal(m.isSameOrBefore(moment(new Date(2011, 11, 31, 23, 59, 59, 999)), 'year'), true, 'exact end of year');
  36602. assert.equal(m.isSameOrBefore(moment(new Date(2012, 0, 1, 0, 0, 0, 0)), 'year'), true, 'start of next year');
  36603. assert.equal(m.isSameOrBefore(moment(new Date(2010, 11, 31, 23, 59, 59, 999)), 'year'), false, 'end of previous year');
  36604. assert.equal(m.isSameOrBefore(m, 'year'), true, 'same moments are in the same year');
  36605. assert.equal(+m, +mCopy, 'isSameOrBefore year should not change moment');
  36606. });
  36607. test('is same or before month', function (assert) {
  36608. var m = moment(new Date(2011, 2, 3, 4, 5, 6, 7)), mCopy = moment(m);
  36609. assert.equal(m.isSameOrBefore(moment(new Date(2011, 2, 6, 7, 8, 9, 10)), 'month'), true, 'month match');
  36610. assert.equal(m.isSameOrBefore(moment(new Date(2011, 2, 6, 7, 8, 9, 10)), 'months'), true, 'plural should work');
  36611. assert.equal(m.isSameOrBefore(moment(new Date(2012, 2, 6, 7, 8, 9, 10)), 'month'), true, 'year is later');
  36612. assert.equal(m.isSameOrBefore(moment(new Date(2010, 2, 6, 7, 8, 9, 10)), 'month'), false, 'year is earlier');
  36613. assert.equal(m.isSameOrBefore(moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'month'), true, 'month is later');
  36614. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 6, 7, 8, 9, 10)), 'month'), false, 'month is earlier');
  36615. assert.equal(m.isSameOrBefore(moment(new Date(2011, 2, 1, 0, 0, 0, 0)), 'month'), true, 'exact start of month');
  36616. assert.equal(m.isSameOrBefore(moment(new Date(2011, 2, 31, 23, 59, 59, 999)), 'month'), true, 'exact end of month');
  36617. assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 1, 0, 0, 0, 0)), 'month'), true, 'start of next month');
  36618. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 27, 23, 59, 59, 999)), 'month'), false, 'end of previous month');
  36619. assert.equal(m.isSameOrBefore(m, 'month'), true, 'same moments are in the same month');
  36620. assert.equal(+m, +mCopy, 'isSameOrBefore month should not change moment');
  36621. });
  36622. test('is same or before day', function (assert) {
  36623. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
  36624. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 7, 8, 9, 10)), 'day'), true, 'day match');
  36625. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 7, 8, 9, 10)), 'days'), true, 'plural should work');
  36626. assert.equal(m.isSameOrBefore(moment(new Date(2012, 1, 2, 7, 8, 9, 10)), 'day'), true, 'year is later');
  36627. assert.equal(m.isSameOrBefore(moment(new Date(2010, 1, 2, 7, 8, 9, 10)), 'day'), false, 'year is earlier');
  36628. assert.equal(m.isSameOrBefore(moment(new Date(2011, 2, 2, 7, 8, 9, 10)), 'day'), true, 'month is later');
  36629. assert.equal(m.isSameOrBefore(moment(new Date(2010, 12, 2, 7, 8, 9, 10)), 'day'), false, 'month is earlier');
  36630. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 3, 7, 8, 9, 10)), 'day'), true, 'day is later');
  36631. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 1, 7, 8, 9, 10)), 'day'), false, 'day is earlier');
  36632. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 0, 0, 0, 0)), 'day'), true, 'exact start of day');
  36633. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 23, 59, 59, 999)), 'day'), true, 'exact end of day');
  36634. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 3, 0, 0, 0, 0)), 'day'), true, 'start of next day');
  36635. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 1, 23, 59, 59, 999)), 'day'), false, 'end of previous day');
  36636. assert.equal(m.isSameOrBefore(m, 'day'), true, 'same moments are in the same day');
  36637. assert.equal(+m, +mCopy, 'isSameOrBefore day should not change moment');
  36638. });
  36639. test('is same or before hour', function (assert) {
  36640. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
  36641. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 8, 9, 10)), 'hour'), true, 'hour match');
  36642. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 8, 9, 10)), 'hours'), true, 'plural should work');
  36643. assert.equal(m.isSameOrBefore(moment(new Date(2012, 1, 2, 3, 8, 9, 10)), 'hour'), true, 'year is later');
  36644. assert.equal(m.isSameOrBefore(moment(new Date(2010, 1, 2, 3, 8, 9, 10)), 'hour'), false, 'year is earlier');
  36645. assert.equal(m.isSameOrBefore(moment(new Date(2011, 2, 2, 3, 8, 9, 10)), 'hour'), true, 'month is later');
  36646. assert.equal(m.isSameOrBefore(moment(new Date(2010, 12, 2, 3, 8, 9, 10)), 'hour'), false, 'month is earlier');
  36647. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 3, 3, 8, 9, 10)), 'hour'), true, 'day is later');
  36648. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 1, 3, 8, 9, 10)), 'hour'), false, 'day is earlier');
  36649. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 4, 8, 9, 10)), 'hour'), true, 'hour is later');
  36650. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 2, 8, 9, 10)), 'hour'), false, 'hour is earlier');
  36651. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 0, 0, 0)), 'hour'), true, 'exact start of hour');
  36652. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 59, 59, 999)), 'hour'), true, 'exact end of hour');
  36653. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 4, 0, 0, 0)), 'hour'), true, 'start of next hour');
  36654. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 2, 59, 59, 999)), 'hour'), false, 'end of previous hour');
  36655. assert.equal(m.isSameOrBefore(m, 'hour'), true, 'same moments are in the same hour');
  36656. assert.equal(+m, +mCopy, 'isSameOrBefore hour should not change moment');
  36657. });
  36658. test('is same or before minute', function (assert) {
  36659. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
  36660. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 4, 9, 10)), 'minute'), true, 'minute match');
  36661. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 4, 9, 10)), 'minutes'), true, 'plural should work');
  36662. assert.equal(m.isSameOrBefore(moment(new Date(2012, 1, 2, 3, 4, 9, 10)), 'minute'), true, 'year is later');
  36663. assert.equal(m.isSameOrBefore(moment(new Date(2010, 1, 2, 3, 4, 9, 10)), 'minute'), false, 'year is earlier');
  36664. assert.equal(m.isSameOrBefore(moment(new Date(2011, 2, 2, 3, 4, 9, 10)), 'minute'), true, 'month is later');
  36665. assert.equal(m.isSameOrBefore(moment(new Date(2010, 12, 2, 3, 4, 9, 10)), 'minute'), false, 'month is earlier');
  36666. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 3, 3, 4, 9, 10)), 'minute'), true, 'day is later');
  36667. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 1, 3, 4, 9, 10)), 'minute'), false, 'day is earlier');
  36668. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 4, 4, 9, 10)), 'minute'), true, 'hour is later');
  36669. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 2, 4, 9, 10)), 'minute'), false, 'hour is earlier');
  36670. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 5, 9, 10)), 'minute'), true, 'minute is later');
  36671. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 3, 9, 10)), 'minute'), false, 'minute is earlier');
  36672. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 4, 0, 0)), 'minute'), true, 'exact start of minute');
  36673. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 4, 59, 999)), 'minute'), true, 'exact end of minute');
  36674. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 5, 0, 0)), 'minute'), true, 'start of next minute');
  36675. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 3, 59, 999)), 'minute'), false, 'end of previous minute');
  36676. assert.equal(m.isSameOrBefore(m, 'minute'), true, 'same moments are in the same minute');
  36677. assert.equal(+m, +mCopy, 'isSameOrBefore minute should not change moment');
  36678. });
  36679. test('is same or before second', function (assert) {
  36680. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
  36681. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 4, 5, 10)), 'second'), true, 'second match');
  36682. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 4, 5, 10)), 'seconds'), true, 'plural should work');
  36683. assert.equal(m.isSameOrBefore(moment(new Date(2012, 1, 2, 3, 4, 5, 10)), 'second'), true, 'year is later');
  36684. assert.equal(m.isSameOrBefore(moment(new Date(2010, 1, 2, 3, 4, 5, 10)), 'second'), false, 'year is earlier');
  36685. assert.equal(m.isSameOrBefore(moment(new Date(2011, 2, 2, 3, 4, 5, 10)), 'second'), true, 'month is later');
  36686. assert.equal(m.isSameOrBefore(moment(new Date(2010, 12, 2, 3, 4, 5, 10)), 'second'), false, 'month is earlier');
  36687. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 3, 3, 4, 5, 10)), 'second'), true, 'day is later');
  36688. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 1, 3, 4, 5, 10)), 'second'), false, 'day is earlier');
  36689. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 4, 4, 5, 10)), 'second'), true, 'hour is later');
  36690. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 2, 4, 5, 10)), 'second'), false, 'hour is earlier');
  36691. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 5, 5, 10)), 'second'), true, 'minute is later');
  36692. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 3, 5, 10)), 'second'), false, 'minute is earlier');
  36693. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 4, 6, 10)), 'second'), true, 'second is later');
  36694. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 4, 4, 10)), 'second'), false, 'second is earlier');
  36695. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 4, 5, 0)), 'second'), true, 'exact start of second');
  36696. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 4, 5, 999)), 'second'), true, 'exact end of second');
  36697. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 4, 6, 0)), 'second'), true, 'start of next second');
  36698. assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 4, 4, 999)), 'second'), false, 'end of previous second');
  36699. assert.equal(m.isSameOrBefore(m, 'second'), true, 'same moments are in the same second');
  36700. assert.equal(+m, +mCopy, 'isSameOrBefore second should not change moment');
  36701. });
  36702. test('is same or before millisecond', function (assert) {
  36703. var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
  36704. assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 10)), 'millisecond'), true, 'millisecond match');
  36705. assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 10)), 'milliseconds'), true, 'plural should work');
  36706. assert.equal(m.isSameOrBefore(moment(new Date(2012, 3, 2, 3, 4, 5, 10)), 'millisecond'), true, 'year is later');
  36707. assert.equal(m.isSameOrBefore(moment(new Date(2010, 3, 2, 3, 4, 5, 10)), 'millisecond'), false, 'year is earlier');
  36708. assert.equal(m.isSameOrBefore(moment(new Date(2011, 4, 2, 3, 4, 5, 10)), 'millisecond'), true, 'month is later');
  36709. assert.equal(m.isSameOrBefore(moment(new Date(2011, 2, 2, 3, 4, 5, 10)), 'millisecond'), false, 'month is earlier');
  36710. assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 3, 3, 4, 5, 10)), 'millisecond'), true, 'day is later');
  36711. assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 1, 1, 4, 5, 10)), 'millisecond'), false, 'day is earlier');
  36712. assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 2, 4, 4, 5, 10)), 'millisecond'), true, 'hour is later');
  36713. assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 1, 4, 1, 5, 10)), 'millisecond'), false, 'hour is earlier');
  36714. assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 2, 3, 5, 5, 10)), 'millisecond'), true, 'minute is later');
  36715. assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 2, 3, 3, 5, 10)), 'millisecond'), false, 'minute is earlier');
  36716. assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 2, 3, 4, 6, 10)), 'millisecond'), true, 'second is later');
  36717. assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 2, 3, 4, 4, 5)), 'millisecond'), false, 'second is earlier');
  36718. assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 2, 3, 4, 6, 11)), 'millisecond'), true, 'millisecond is later');
  36719. assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 2, 3, 4, 4, 9)), 'millisecond'), false, 'millisecond is earlier');
  36720. assert.equal(m.isSameOrBefore(m, 'millisecond'), true, 'same moments are in the same millisecond');
  36721. assert.equal(+m, +mCopy, 'isSameOrBefore millisecond should not change moment');
  36722. });
  36723. test('is same with utc offset moments', function (assert) {
  36724. assert.ok(moment.parseZone('2013-02-01T-05:00').isSameOrBefore(moment('2013-02-01'), 'year'), 'zoned vs local moment');
  36725. assert.ok(moment('2013-02-01').isSameOrBefore(moment('2013-02-01').utcOffset('-05:00'), 'year'), 'local vs zoned moment');
  36726. assert.ok(moment.parseZone('2013-02-01T-05:00').isSameOrBefore(moment.parseZone('2013-02-01T-06:30'), 'year'),
  36727. 'zoned vs (differently) zoned moment');
  36728. });
  36729. test('is same with invalid moments', function (assert) {
  36730. var m = moment(), invalid = moment.invalid();
  36731. assert.equal(invalid.isSameOrBefore(invalid), false, 'invalid moments are not considered equal');
  36732. assert.equal(m.isSameOrBefore(invalid), false, 'valid moment is not before invalid moment');
  36733. assert.equal(invalid.isSameOrBefore(m), false, 'invalid moment is not before valid moment');
  36734. assert.equal(m.isSameOrBefore(invalid, 'year'), false, 'invalid moment year');
  36735. assert.equal(m.isSameOrBefore(invalid, 'month'), false, 'invalid moment month');
  36736. assert.equal(m.isSameOrBefore(invalid, 'day'), false, 'invalid moment day');
  36737. assert.equal(m.isSameOrBefore(invalid, 'hour'), false, 'invalid moment hour');
  36738. assert.equal(m.isSameOrBefore(invalid, 'minute'), false, 'invalid moment minute');
  36739. assert.equal(m.isSameOrBefore(invalid, 'second'), false, 'invalid moment second');
  36740. assert.equal(m.isSameOrBefore(invalid, 'milliseconds'), false, 'invalid moment milliseconds');
  36741. });
  36742. }));
  36743. ;(function (global, factory) {
  36744. typeof exports === 'object' && typeof module !== 'undefined'
  36745. && typeof require === 'function' ? factory(require('../../moment')) :
  36746. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  36747. factory(global.moment)
  36748. }(this, function (moment) { 'use strict';
  36749. /*global QUnit:false*/
  36750. var test = QUnit.test;
  36751. var expect = QUnit.expect;
  36752. function module (name, lifecycle) {
  36753. QUnit.module(name, {
  36754. setup : function () {
  36755. moment.locale('en');
  36756. moment.createFromInputFallback = function (config) {
  36757. throw new Error('input not handled by moment: ' + config._i);
  36758. };
  36759. if (lifecycle && lifecycle.setup) {
  36760. lifecycle.setup();
  36761. }
  36762. },
  36763. teardown : function () {
  36764. if (lifecycle && lifecycle.teardown) {
  36765. lifecycle.teardown();
  36766. }
  36767. }
  36768. });
  36769. }
  36770. function localeModule (name, lifecycle) {
  36771. QUnit.module('locale:' + name, {
  36772. setup : function () {
  36773. moment.locale(name);
  36774. moment.createFromInputFallback = function (config) {
  36775. throw new Error('input not handled by moment: ' + config._i);
  36776. };
  36777. if (lifecycle && lifecycle.setup) {
  36778. lifecycle.setup();
  36779. }
  36780. },
  36781. teardown : function () {
  36782. moment.locale('en');
  36783. if (lifecycle && lifecycle.teardown) {
  36784. lifecycle.teardown();
  36785. }
  36786. }
  36787. });
  36788. }
  36789. module('is valid');
  36790. test('array bad month', function (assert) {
  36791. assert.equal(moment([2010, -1]).isValid(), false, 'month -1 invalid');
  36792. assert.equal(moment([2100, 12]).isValid(), false, 'month 12 invalid');
  36793. });
  36794. test('array good month', function (assert) {
  36795. for (var i = 0; i < 12; i++) {
  36796. assert.equal(moment([2010, i]).isValid(), true, 'month ' + i);
  36797. assert.equal(moment.utc([2010, i]).isValid(), true, 'month ' + i);
  36798. }
  36799. });
  36800. test('array bad date', function (assert) {
  36801. var tests = [
  36802. moment([2010, 0, 0]),
  36803. moment([2100, 0, 32]),
  36804. moment.utc([2010, 0, 0]),
  36805. moment.utc([2100, 0, 32])
  36806. ],
  36807. i, m;
  36808. for (i in tests) {
  36809. m = tests[i];
  36810. assert.equal(m.isValid(), false);
  36811. }
  36812. });
  36813. test('h/hh with hour > 12', function (assert) {
  36814. assert.ok(moment('06/20/2014 11:51 PM', 'MM/DD/YYYY hh:mm A', true).isValid(), '11 for hh');
  36815. assert.ok(moment('06/20/2014 11:51 AM', 'MM/DD/YYYY hh:mm A', true).isValid(), '11 for hh');
  36816. assert.ok(moment('06/20/2014 23:51 PM', 'MM/DD/YYYY hh:mm A').isValid(), 'non-strict validity 23 for hh');
  36817. assert.ok(moment('06/20/2014 23:51 PM', 'MM/DD/YYYY hh:mm A').parsingFlags().bigHour, 'non-strict bigHour 23 for hh');
  36818. assert.ok(!moment('06/20/2014 23:51 PM', 'MM/DD/YYYY hh:mm A', true).isValid(), 'validity 23 for hh');
  36819. assert.ok(moment('06/20/2014 23:51 PM', 'MM/DD/YYYY hh:mm A', true).parsingFlags().bigHour, 'bigHour 23 for hh');
  36820. });
  36821. test('array bad date leap year', function (assert) {
  36822. assert.equal(moment([2010, 1, 29]).isValid(), false, '2010 feb 29');
  36823. assert.equal(moment([2100, 1, 29]).isValid(), false, '2100 feb 29');
  36824. assert.equal(moment([2008, 1, 30]).isValid(), false, '2008 feb 30');
  36825. assert.equal(moment([2000, 1, 30]).isValid(), false, '2000 feb 30');
  36826. assert.equal(moment.utc([2010, 1, 29]).isValid(), false, 'utc 2010 feb 29');
  36827. assert.equal(moment.utc([2100, 1, 29]).isValid(), false, 'utc 2100 feb 29');
  36828. assert.equal(moment.utc([2008, 1, 30]).isValid(), false, 'utc 2008 feb 30');
  36829. assert.equal(moment.utc([2000, 1, 30]).isValid(), false, 'utc 2000 feb 30');
  36830. });
  36831. test('string + formats bad date', function (assert) {
  36832. assert.equal(moment('2020-00-00', []).isValid(), false, 'invalid on empty array');
  36833. assert.equal(moment('2020-00-00', ['YYYY-MM-DD', 'DD-MM-YYYY']).isValid(), false, 'invalid on all in array');
  36834. assert.equal(moment('2020-00-00', ['DD-MM-YYYY', 'YYYY-MM-DD']).isValid(), false, 'invalid on all in array');
  36835. assert.equal(moment('2020-01-01', ['YYYY-MM-DD', 'DD-MM-YYYY']).isValid(), true, 'valid on first');
  36836. assert.equal(moment('2020-01-01', ['DD-MM-YYYY', 'YYYY-MM-DD']).isValid(), true, 'valid on last');
  36837. assert.equal(moment('2020-01-01', ['YYYY-MM-DD', 'YYYY-DD-MM']).isValid(), true, 'valid on both');
  36838. assert.equal(moment('2020-13-01', ['YYYY-MM-DD', 'YYYY-DD-MM']).isValid(), true, 'valid on last');
  36839. assert.equal(moment('12-13-2012', ['DD-MM-YYYY', 'YYYY-MM-DD']).isValid(), false, 'month rollover');
  36840. assert.equal(moment('12-13-2012', ['DD-MM-YYYY', 'DD-MM-YYYY']).isValid(), false, 'month rollover');
  36841. assert.equal(moment('38-12-2012', ['DD-MM-YYYY']).isValid(), false, 'day rollover');
  36842. });
  36843. test('string nonsensical with format', function (assert) {
  36844. assert.equal(moment('fail', 'MM-DD-YYYY').isValid(), false, 'string \'fail\' with format \'MM-DD-YYYY\'');
  36845. assert.equal(moment('xx-xx-2001', 'DD-MM-YYY').isValid(), true, 'string \'xx-xx-2001\' with format \'MM-DD-YYYY\'');
  36846. });
  36847. test('string with bad month name', function (assert) {
  36848. assert.equal(moment('01-Nam-2012', 'DD-MMM-YYYY').isValid(), false, '\'Nam\' is an invalid month');
  36849. assert.equal(moment('01-Aug-2012', 'DD-MMM-YYYY').isValid(), true, '\'Aug\' is a valid month');
  36850. });
  36851. test('string with spaceless format', function (assert) {
  36852. assert.equal(moment('10Sep2001', 'DDMMMYYYY').isValid(), true, 'Parsing 10Sep2001 should result in a valid date');
  36853. });
  36854. test('invalid string iso 8601', function (assert) {
  36855. var tests = [
  36856. '2010-00-00',
  36857. '2010-01-00',
  36858. '2010-01-40',
  36859. '2010-01-01T24:01', // 24:00:00 is actually valid
  36860. '2010-01-01T23:60',
  36861. '2010-01-01T23:59:60'
  36862. ], i;
  36863. for (i = 0; i < tests.length; i++) {
  36864. assert.equal(moment(tests[i], moment.ISO_8601).isValid(), false, tests[i] + ' should be invalid');
  36865. assert.equal(moment.utc(tests[i], moment.ISO_8601).isValid(), false, tests[i] + ' should be invalid');
  36866. }
  36867. });
  36868. test('invalid string iso 8601 + timezone', function (assert) {
  36869. var tests = [
  36870. '2010-00-00T+00:00',
  36871. '2010-01-00T+00:00',
  36872. '2010-01-40T+00:00',
  36873. '2010-01-40T24:01+00:00',
  36874. '2010-01-40T23:60+00:00',
  36875. '2010-01-40T23:59:60+00:00',
  36876. '2010-01-40T23:59:59.9999+00:00',
  36877. '2010-01-40T23:59:59,9999+00:00'
  36878. ], i;
  36879. for (i = 0; i < tests.length; i++) {
  36880. assert.equal(moment(tests[i], moment.ISO_8601).isValid(), false, tests[i] + ' should be invalid');
  36881. assert.equal(moment.utc(tests[i], moment.ISO_8601).isValid(), false, tests[i] + ' should be invalid');
  36882. }
  36883. });
  36884. test('valid string iso 8601 - not strict', function (assert) {
  36885. var tests = [
  36886. '2010-01-30 00:00:00,000Z',
  36887. '20100101',
  36888. '20100130',
  36889. '20100130T23+00:00',
  36890. '20100130T2359+0000',
  36891. '20100130T235959+0000',
  36892. '20100130T235959,999+0000',
  36893. '20100130T235959,999-0700',
  36894. '20100130T000000,000+0700',
  36895. '20100130 000000,000Z'
  36896. ];
  36897. for (var i = 0; i < tests.length; i++) {
  36898. assert.equal(moment(tests[i]).isValid(), true, tests[i] + ' should be valid in normal');
  36899. assert.equal(moment.utc(tests[i]).isValid(), true, tests[i] + ' should be valid in normal');
  36900. }
  36901. });
  36902. test('valid string iso 8601 + timezone', function (assert) {
  36903. var tests = [
  36904. '2010-01-01',
  36905. '2010-01-30',
  36906. '2010-01-30T23+00:00',
  36907. '2010-01-30T23:59+00:00',
  36908. '2010-01-30T23:59:59+00:00',
  36909. '2010-01-30T23:59:59.999+00:00',
  36910. '2010-01-30T23:59:59.999-07:00',
  36911. '2010-01-30T00:00:00.000+07:00',
  36912. '2010-01-30T23:59:59.999-07',
  36913. '2010-01-30T00:00:00.000+07',
  36914. '2010-01-30 00:00:00.000Z'
  36915. ], i;
  36916. for (i = 0; i < tests.length; i++) {
  36917. assert.equal(moment(tests[i]).isValid(), true, tests[i] + ' should be valid in normal');
  36918. assert.equal(moment.utc(tests[i]).isValid(), true, tests[i] + ' should be valid in normal');
  36919. assert.equal(moment(tests[i], moment.ISO_8601, true).isValid(), true, tests[i] + ' should be valid in strict');
  36920. assert.equal(moment.utc(tests[i], moment.ISO_8601, true).isValid(), true, tests[i] + ' should be valid in strict');
  36921. }
  36922. });
  36923. test('invalidAt', function (assert) {
  36924. assert.equal(moment([2000, 12]).invalidAt(), 1, 'month 12 is invalid: 0-11');
  36925. assert.equal(moment([2000, 1, 30]).invalidAt(), 2, '30 is not a valid february day');
  36926. assert.equal(moment([2000, 1, 29, 25]).invalidAt(), 3, '25 is invalid hour');
  36927. assert.equal(moment([2000, 1, 29, 24, 1]).invalidAt(), 3, '24:01 is invalid hour');
  36928. assert.equal(moment([2000, 1, 29, 23, 60]).invalidAt(), 4, '60 is invalid minute');
  36929. assert.equal(moment([2000, 1, 29, 23, 59, 60]).invalidAt(), 5, '60 is invalid second');
  36930. assert.equal(moment([2000, 1, 29, 23, 59, 59, 1000]).invalidAt(), 6, '1000 is invalid millisecond');
  36931. assert.equal(moment([2000, 1, 29, 23, 59, 59, 999]).invalidAt(), -1, '-1 if everything is fine');
  36932. });
  36933. test('valid Unix timestamp', function (assert) {
  36934. assert.equal(moment(1371065286, 'X').isValid(), true, 'number integer');
  36935. assert.equal(moment(1379066897.0, 'X').isValid(), true, 'number whole 1dp');
  36936. assert.equal(moment(1379066897.7, 'X').isValid(), true, 'number 1dp');
  36937. assert.equal(moment(1379066897.00, 'X').isValid(), true, 'number whole 2dp');
  36938. assert.equal(moment(1379066897.07, 'X').isValid(), true, 'number 2dp');
  36939. assert.equal(moment(1379066897.17, 'X').isValid(), true, 'number 2dp');
  36940. assert.equal(moment(1379066897.000, 'X').isValid(), true, 'number whole 3dp');
  36941. assert.equal(moment(1379066897.007, 'X').isValid(), true, 'number 3dp');
  36942. assert.equal(moment(1379066897.017, 'X').isValid(), true, 'number 3dp');
  36943. assert.equal(moment(1379066897.157, 'X').isValid(), true, 'number 3dp');
  36944. assert.equal(moment('1371065286', 'X').isValid(), true, 'string integer');
  36945. assert.equal(moment('1379066897.', 'X').isValid(), true, 'string trailing .');
  36946. assert.equal(moment('1379066897.0', 'X').isValid(), true, 'string whole 1dp');
  36947. assert.equal(moment('1379066897.7', 'X').isValid(), true, 'string 1dp');
  36948. assert.equal(moment('1379066897.00', 'X').isValid(), true, 'string whole 2dp');
  36949. assert.equal(moment('1379066897.07', 'X').isValid(), true, 'string 2dp');
  36950. assert.equal(moment('1379066897.17', 'X').isValid(), true, 'string 2dp');
  36951. assert.equal(moment('1379066897.000', 'X').isValid(), true, 'string whole 3dp');
  36952. assert.equal(moment('1379066897.007', 'X').isValid(), true, 'string 3dp');
  36953. assert.equal(moment('1379066897.017', 'X').isValid(), true, 'string 3dp');
  36954. assert.equal(moment('1379066897.157', 'X').isValid(), true, 'string 3dp');
  36955. });
  36956. test('invalid Unix timestamp', function (assert) {
  36957. assert.equal(moment(undefined, 'X').isValid(), false, 'undefined');
  36958. assert.equal(moment('undefined', 'X').isValid(), false, 'string undefined');
  36959. try {
  36960. assert.equal(moment(null, 'X').isValid(), false, 'null');
  36961. } catch (e) {
  36962. assert.ok(true, 'null');
  36963. }
  36964. assert.equal(moment('null', 'X').isValid(), false, 'string null');
  36965. assert.equal(moment([], 'X').isValid(), false, 'array');
  36966. assert.equal(moment('{}', 'X').isValid(), false, 'object');
  36967. try {
  36968. assert.equal(moment('', 'X').isValid(), false, 'string empty');
  36969. } catch (e) {
  36970. assert.ok(true, 'string empty');
  36971. }
  36972. assert.equal(moment(' ', 'X').isValid(), false, 'string space');
  36973. });
  36974. test('valid Unix offset milliseconds', function (assert) {
  36975. assert.equal(moment(1234567890123, 'x').isValid(), true, 'number integer');
  36976. assert.equal(moment('1234567890123', 'x').isValid(), true, 'string integer');
  36977. });
  36978. test('invalid Unix offset milliseconds', function (assert) {
  36979. assert.equal(moment(undefined, 'x').isValid(), false, 'undefined');
  36980. assert.equal(moment('undefined', 'x').isValid(), false, 'string undefined');
  36981. try {
  36982. assert.equal(moment(null, 'x').isValid(), false, 'null');
  36983. } catch (e) {
  36984. assert.ok(true, 'null');
  36985. }
  36986. assert.equal(moment('null', 'x').isValid(), false, 'string null');
  36987. assert.equal(moment([], 'x').isValid(), false, 'array');
  36988. assert.equal(moment('{}', 'x').isValid(), false, 'object');
  36989. try {
  36990. assert.equal(moment('', 'x').isValid(), false, 'string empty');
  36991. } catch (e) {
  36992. assert.ok(true, 'string empty');
  36993. }
  36994. assert.equal(moment(' ', 'x').isValid(), false, 'string space');
  36995. });
  36996. test('empty', function (assert) {
  36997. assert.equal(moment(null).isValid(), false, 'null');
  36998. assert.equal(moment('').isValid(), false, 'empty string');
  36999. assert.equal(moment(null, 'YYYY').isValid(), false, 'format + null');
  37000. assert.equal(moment('', 'YYYY').isValid(), false, 'format + empty string');
  37001. assert.equal(moment(' ', 'YYYY').isValid(), false, 'format + empty when trimmed');
  37002. });
  37003. test('days of the year', function (assert) {
  37004. assert.equal(moment('2010 300', 'YYYY DDDD').isValid(), true, 'day 300 of year valid');
  37005. assert.equal(moment('2010 365', 'YYYY DDDD').isValid(), true, 'day 365 of year valid');
  37006. assert.equal(moment('2010 366', 'YYYY DDDD').isValid(), false, 'day 366 of year invalid');
  37007. assert.equal(moment('2012 365', 'YYYY DDDD').isValid(), true, 'day 365 of leap year valid');
  37008. assert.equal(moment('2012 366', 'YYYY DDDD').isValid(), true, 'day 366 of leap year valid');
  37009. assert.equal(moment('2012 367', 'YYYY DDDD').isValid(), false, 'day 367 of leap year invalid');
  37010. });
  37011. test('24:00:00.000 is valid', function (assert) {
  37012. assert.equal(moment('2014-01-01 24', 'YYYY-MM-DD HH').isValid(), true, '24 is valid');
  37013. assert.equal(moment('2014-01-01 24:00', 'YYYY-MM-DD HH:mm').isValid(), true, '24:00 is valid');
  37014. assert.equal(moment('2014-01-01 24:01', 'YYYY-MM-DD HH:mm').isValid(), false, '24:01 is not valid');
  37015. });
  37016. test('oddball permissiveness', function (assert) {
  37017. //https://github.com/moment/moment/issues/1128
  37018. assert.ok(moment('2010-10-3199', ['MM/DD/YYYY', 'MM-DD-YYYY', 'YYYY-MM-DD']).isValid());
  37019. //https://github.com/moment/moment/issues/1122
  37020. assert.ok(moment('3:25', ['h:mma', 'hh:mma', 'H:mm', 'HH:mm']).isValid());
  37021. });
  37022. test('0 hour is invalid in strict', function (assert) {
  37023. assert.equal(moment('00:01', 'hh:mm', true).isValid(), false, '00 hour is invalid in strict');
  37024. assert.equal(moment('00:01', 'hh:mm').isValid(), true, '00 hour is valid in normal');
  37025. assert.equal(moment('0:01', 'h:mm', true).isValid(), false, '0 hour is invalid in strict');
  37026. assert.equal(moment('0:01', 'h:mm').isValid(), true, '0 hour is valid in normal');
  37027. });
  37028. }));
  37029. ;(function (global, factory) {
  37030. typeof exports === 'object' && typeof module !== 'undefined'
  37031. && typeof require === 'function' ? factory(require('../../moment')) :
  37032. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  37033. factory(global.moment)
  37034. }(this, function (moment) { 'use strict';
  37035. /*global QUnit:false*/
  37036. var test = QUnit.test;
  37037. var expect = QUnit.expect;
  37038. function module (name, lifecycle) {
  37039. QUnit.module(name, {
  37040. setup : function () {
  37041. moment.locale('en');
  37042. moment.createFromInputFallback = function (config) {
  37043. throw new Error('input not handled by moment: ' + config._i);
  37044. };
  37045. if (lifecycle && lifecycle.setup) {
  37046. lifecycle.setup();
  37047. }
  37048. },
  37049. teardown : function () {
  37050. if (lifecycle && lifecycle.teardown) {
  37051. lifecycle.teardown();
  37052. }
  37053. }
  37054. });
  37055. }
  37056. function localeModule (name, lifecycle) {
  37057. QUnit.module('locale:' + name, {
  37058. setup : function () {
  37059. moment.locale(name);
  37060. moment.createFromInputFallback = function (config) {
  37061. throw new Error('input not handled by moment: ' + config._i);
  37062. };
  37063. if (lifecycle && lifecycle.setup) {
  37064. lifecycle.setup();
  37065. }
  37066. },
  37067. teardown : function () {
  37068. moment.locale('en');
  37069. if (lifecycle && lifecycle.teardown) {
  37070. lifecycle.teardown();
  37071. }
  37072. }
  37073. });
  37074. }
  37075. module('leap year');
  37076. test('leap year', function (assert) {
  37077. assert.equal(moment([2010, 0, 1]).isLeapYear(), false, '2010');
  37078. assert.equal(moment([2100, 0, 1]).isLeapYear(), false, '2100');
  37079. assert.equal(moment([2008, 0, 1]).isLeapYear(), true, '2008');
  37080. assert.equal(moment([2000, 0, 1]).isLeapYear(), true, '2000');
  37081. });
  37082. }));
  37083. ;(function (global, factory) {
  37084. typeof exports === 'object' && typeof module !== 'undefined'
  37085. && typeof require === 'function' ? factory(require('../../moment')) :
  37086. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  37087. factory(global.moment)
  37088. }(this, function (moment) { 'use strict';
  37089. /*global QUnit:false*/
  37090. var test = QUnit.test;
  37091. var expect = QUnit.expect;
  37092. function module (name, lifecycle) {
  37093. QUnit.module(name, {
  37094. setup : function () {
  37095. moment.locale('en');
  37096. moment.createFromInputFallback = function (config) {
  37097. throw new Error('input not handled by moment: ' + config._i);
  37098. };
  37099. if (lifecycle && lifecycle.setup) {
  37100. lifecycle.setup();
  37101. }
  37102. },
  37103. teardown : function () {
  37104. if (lifecycle && lifecycle.teardown) {
  37105. lifecycle.teardown();
  37106. }
  37107. }
  37108. });
  37109. }
  37110. function localeModule (name, lifecycle) {
  37111. QUnit.module('locale:' + name, {
  37112. setup : function () {
  37113. moment.locale(name);
  37114. moment.createFromInputFallback = function (config) {
  37115. throw new Error('input not handled by moment: ' + config._i);
  37116. };
  37117. if (lifecycle && lifecycle.setup) {
  37118. lifecycle.setup();
  37119. }
  37120. },
  37121. teardown : function () {
  37122. moment.locale('en');
  37123. if (lifecycle && lifecycle.teardown) {
  37124. lifecycle.teardown();
  37125. }
  37126. }
  37127. });
  37128. }
  37129. module('listers');
  37130. test('default', function (assert) {
  37131. assert.deepEqual(moment.months(), ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']);
  37132. assert.deepEqual(moment.monthsShort(), ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']);
  37133. assert.deepEqual(moment.weekdays(), ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']);
  37134. assert.deepEqual(moment.weekdaysShort(), ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']);
  37135. assert.deepEqual(moment.weekdaysMin(), ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa']);
  37136. });
  37137. test('index', function (assert) {
  37138. assert.equal(moment.months(0), 'January');
  37139. assert.equal(moment.months(2), 'March');
  37140. assert.equal(moment.monthsShort(0), 'Jan');
  37141. assert.equal(moment.monthsShort(2), 'Mar');
  37142. assert.equal(moment.weekdays(0), 'Sunday');
  37143. assert.equal(moment.weekdays(2), 'Tuesday');
  37144. assert.equal(moment.weekdaysShort(0), 'Sun');
  37145. assert.equal(moment.weekdaysShort(2), 'Tue');
  37146. assert.equal(moment.weekdaysMin(0), 'Su');
  37147. assert.equal(moment.weekdaysMin(2), 'Tu');
  37148. });
  37149. test('localized', function (assert) {
  37150. var months = 'one_two_three_four_five_six_seven_eight_nine_ten_eleven_twelve'.split('_'),
  37151. monthsShort = 'on_tw_th_fo_fi_si_se_ei_ni_te_el_tw'.split('_'),
  37152. weekdays = 'one_two_three_four_five_six_seven'.split('_'),
  37153. weekdaysShort = 'on_tw_th_fo_fi_si_se'.split('_'),
  37154. weekdaysMin = '1_2_3_4_5_6_7'.split('_');
  37155. moment.locale('numerologists', {
  37156. months : months,
  37157. monthsShort : monthsShort,
  37158. weekdays : weekdays,
  37159. weekdaysShort: weekdaysShort,
  37160. weekdaysMin: weekdaysMin
  37161. });
  37162. assert.deepEqual(moment.months(), months);
  37163. assert.deepEqual(moment.monthsShort(), monthsShort);
  37164. assert.deepEqual(moment.weekdays(), weekdays);
  37165. assert.deepEqual(moment.weekdaysShort(), weekdaysShort);
  37166. assert.deepEqual(moment.weekdaysMin(), weekdaysMin);
  37167. assert.equal(moment.months(0), 'one');
  37168. assert.equal(moment.monthsShort(0), 'on');
  37169. assert.equal(moment.weekdays(0), 'one');
  37170. assert.equal(moment.weekdaysShort(0), 'on');
  37171. assert.equal(moment.weekdaysMin(0), '1');
  37172. assert.equal(moment.months(2), 'three');
  37173. assert.equal(moment.monthsShort(2), 'th');
  37174. assert.equal(moment.weekdays(2), 'three');
  37175. assert.equal(moment.weekdaysShort(2), 'th');
  37176. assert.equal(moment.weekdaysMin(2), '3');
  37177. });
  37178. test('with functions', function (assert) {
  37179. var monthsShort = 'one_two_three_four_five_six_seven_eight_nine_ten_eleven_twelve'.split('_'),
  37180. monthsShortWeird = 'onesy_twosy_threesy_foursy_fivesy_sixsy_sevensy_eightsy_ninesy_tensy_elevensy_twelvesy'.split('_');
  37181. moment.locale('difficult', {
  37182. monthsShort: function (m, format) {
  37183. var arr = format.match(/-MMM-/) ? monthsShortWeird : monthsShort;
  37184. return arr[m.month()];
  37185. }
  37186. });
  37187. assert.deepEqual(moment.monthsShort(), monthsShort);
  37188. assert.deepEqual(moment.monthsShort('MMM'), monthsShort);
  37189. assert.deepEqual(moment.monthsShort('-MMM-'), monthsShortWeird);
  37190. assert.deepEqual(moment.monthsShort('MMM', 2), 'three');
  37191. assert.deepEqual(moment.monthsShort('-MMM-', 2), 'threesy');
  37192. assert.deepEqual(moment.monthsShort(2), 'three');
  37193. });
  37194. }));
  37195. ;(function (global, factory) {
  37196. typeof exports === 'object' && typeof module !== 'undefined'
  37197. && typeof require === 'function' ? factory(require('../../moment')) :
  37198. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  37199. factory(global.moment)
  37200. }(this, function (moment) { 'use strict';
  37201. /*global QUnit:false*/
  37202. var test = QUnit.test;
  37203. var expect = QUnit.expect;
  37204. function module (name, lifecycle) {
  37205. QUnit.module(name, {
  37206. setup : function () {
  37207. moment.locale('en');
  37208. moment.createFromInputFallback = function (config) {
  37209. throw new Error('input not handled by moment: ' + config._i);
  37210. };
  37211. if (lifecycle && lifecycle.setup) {
  37212. lifecycle.setup();
  37213. }
  37214. },
  37215. teardown : function () {
  37216. if (lifecycle && lifecycle.teardown) {
  37217. lifecycle.teardown();
  37218. }
  37219. }
  37220. });
  37221. }
  37222. function localeModule (name, lifecycle) {
  37223. QUnit.module('locale:' + name, {
  37224. setup : function () {
  37225. moment.locale(name);
  37226. moment.createFromInputFallback = function (config) {
  37227. throw new Error('input not handled by moment: ' + config._i);
  37228. };
  37229. if (lifecycle && lifecycle.setup) {
  37230. lifecycle.setup();
  37231. }
  37232. },
  37233. teardown : function () {
  37234. moment.locale('en');
  37235. if (lifecycle && lifecycle.teardown) {
  37236. lifecycle.teardown();
  37237. }
  37238. }
  37239. });
  37240. }
  37241. function each(array, callback) {
  37242. var i;
  37243. for (i = 0; i < array.length; i++) {
  37244. callback(array[i], i, array);
  37245. }
  37246. }
  37247. module('locale', {
  37248. setup : function () {
  37249. // TODO: Remove once locales are switched to ES6
  37250. each([{
  37251. name: 'en-gb',
  37252. data: {}
  37253. }, {
  37254. name: 'en-ca',
  37255. data: {}
  37256. }, {
  37257. name: 'es',
  37258. data: {
  37259. relativeTime: {past: 'hace %s', s: 'unos segundos', d: 'un día'},
  37260. months: 'enero_febrero_marzo_abril_mayo_junio_julio_agosto_septiembre_octubre_noviembre_diciembre'.split('_')
  37261. }
  37262. }, {
  37263. name: 'fr',
  37264. data: {}
  37265. }, {
  37266. name: 'fr-ca',
  37267. data: {}
  37268. }, {
  37269. name: 'it',
  37270. data: {}
  37271. }, {
  37272. name: 'zh-cn',
  37273. data: {
  37274. months: '一月_二月_三月_四月_五月_六月_七月_八月_九月_十月_十一月_十二月'.split('_')
  37275. }
  37276. }], function (locale) {
  37277. if (moment.locale(locale.name) !== locale.name) {
  37278. moment.defineLocale(locale.name, locale.data);
  37279. }
  37280. });
  37281. moment.locale('en');
  37282. }
  37283. });
  37284. test('library getters and setters', function (assert) {
  37285. var r = moment.locale('en');
  37286. assert.equal(r, 'en', 'locale should return en by default');
  37287. assert.equal(moment.locale(), 'en', 'locale should return en by default');
  37288. moment.locale('fr');
  37289. assert.equal(moment.locale(), 'fr', 'locale should return the changed locale');
  37290. moment.locale('en-gb');
  37291. assert.equal(moment.locale(), 'en-gb', 'locale should return the changed locale');
  37292. moment.locale('en');
  37293. assert.equal(moment.locale(), 'en', 'locale should reset');
  37294. moment.locale('does-not-exist');
  37295. assert.equal(moment.locale(), 'en', 'locale should reset');
  37296. moment.locale('EN');
  37297. assert.equal(moment.locale(), 'en', 'Normalize locale key case');
  37298. moment.locale('EN_gb');
  37299. assert.equal(moment.locale(), 'en-gb', 'Normalize locale key underscore');
  37300. });
  37301. test('library setter array of locales', function (assert) {
  37302. assert.equal(moment.locale(['non-existent', 'fr', 'also-non-existent']), 'fr', 'passing an array uses the first valid locale');
  37303. assert.equal(moment.locale(['es', 'fr', 'also-non-existent']), 'es', 'passing an array uses the first valid locale');
  37304. });
  37305. test('library setter locale substrings', function (assert) {
  37306. assert.equal(moment.locale('fr-crap'), 'fr', 'use substrings');
  37307. assert.equal(moment.locale('fr-does-not-exist'), 'fr', 'uses deep substrings');
  37308. assert.equal(moment.locale('fr-CA-does-not-exist'), 'fr-ca', 'uses deepest substring');
  37309. });
  37310. test('library getter locale array and substrings', function (assert) {
  37311. assert.equal(moment.locale(['en-CH', 'fr']), 'en', 'prefer root locale to shallower ones');
  37312. assert.equal(moment.locale(['en-gb-leeds', 'en-CA']), 'en-gb', 'prefer root locale to shallower ones');
  37313. assert.equal(moment.locale(['en-fake', 'en-CA']), 'en-ca', 'prefer alternatives with shared roots');
  37314. assert.equal(moment.locale(['en-fake', 'en-fake2', 'en-ca']), 'en-ca', 'prefer alternatives with shared roots');
  37315. assert.equal(moment.locale(['fake-CA', 'fake-MX', 'fr']), 'fr', 'always find something if possible');
  37316. assert.equal(moment.locale(['fake-CA', 'fake-MX', 'fr']), 'fr', 'always find something if possible');
  37317. assert.equal(moment.locale(['fake-CA', 'fake-MX', 'fr-fake-fake-fake']), 'fr', 'always find something if possible');
  37318. assert.equal(moment.locale(['en', 'en-CA']), 'en', 'prefer earlier if it works');
  37319. });
  37320. test('library ensure inheritance', function (assert) {
  37321. moment.locale('made-up', {
  37322. // I put them out of order
  37323. months : 'February_March_April_May_June_July_August_September_October_November_December_January'.split('_')
  37324. // the rest of the properties should be inherited.
  37325. });
  37326. assert.equal(moment([2012, 5, 6]).format('MMMM'), 'July', 'Override some of the configs');
  37327. assert.equal(moment([2012, 5, 6]).format('MMM'), 'Jun', 'But not all of them');
  37328. });
  37329. test('library ensure inheritance LT L LL LLL LLLL', function (assert) {
  37330. var locale = 'test-inherit-lt';
  37331. moment.defineLocale(locale, {
  37332. longDateFormat : {
  37333. LT : '-[LT]-',
  37334. L : '-[L]-',
  37335. LL : '-[LL]-',
  37336. LLL : '-[LLL]-',
  37337. LLLL : '-[LLLL]-'
  37338. },
  37339. calendar : {
  37340. sameDay : '[sameDay] LT',
  37341. nextDay : '[nextDay] L',
  37342. nextWeek : '[nextWeek] LL',
  37343. lastDay : '[lastDay] LLL',
  37344. lastWeek : '[lastWeek] LLLL',
  37345. sameElse : 'L'
  37346. }
  37347. });
  37348. moment.locale('es');
  37349. assert.equal(moment().locale(locale).calendar(), 'sameDay -LT-', 'Should use instance locale in LT formatting');
  37350. assert.equal(moment().add(1, 'days').locale(locale).calendar(), 'nextDay -L-', 'Should use instance locale in L formatting');
  37351. assert.equal(moment().add(-1, 'days').locale(locale).calendar(), 'lastDay -LLL-', 'Should use instance locale in LL formatting');
  37352. assert.equal(moment().add(4, 'days').locale(locale).calendar(), 'nextWeek -LL-', 'Should use instance locale in LLL formatting');
  37353. assert.equal(moment().add(-4, 'days').locale(locale).calendar(), 'lastWeek -LLLL-', 'Should use instance locale in LLLL formatting');
  37354. });
  37355. test('library localeData', function (assert) {
  37356. moment.locale('en');
  37357. var jan = moment([2000, 0]);
  37358. assert.equal(moment.localeData().months(jan), 'January', 'no arguments returns global');
  37359. assert.equal(moment.localeData('zh-cn').months(jan), '一月', 'a string returns the locale based on key');
  37360. assert.equal(moment.localeData(moment().locale('es')).months(jan), 'enero', 'if you pass in a moment it uses the moment\'s locale');
  37361. });
  37362. test('library deprecations', function (assert) {
  37363. moment.lang('dude', {months: ['Movember']});
  37364. assert.equal(moment.locale(), 'dude', 'setting the lang sets the locale');
  37365. assert.equal(moment.lang(), moment.locale());
  37366. assert.equal(moment.langData(), moment.localeData(), 'langData is localeData');
  37367. });
  37368. test('defineLocale', function (assert) {
  37369. moment.locale('en');
  37370. moment.defineLocale('dude', {months: ['Movember']});
  37371. assert.equal(moment().locale(), 'dude', 'defineLocale also sets it');
  37372. assert.equal(moment().locale('dude').locale(), 'dude', 'defineLocale defines a locale');
  37373. });
  37374. test('library convenience', function (assert) {
  37375. moment.locale('something', {week: {dow: 3}});
  37376. moment.locale('something');
  37377. assert.equal(moment.locale(), 'something', 'locale can be used to create the locale too');
  37378. });
  37379. test('firstDayOfWeek firstDayOfYear locale getters', function (assert) {
  37380. moment.locale('something', {week: {dow: 3, doy: 4}});
  37381. moment.locale('something');
  37382. assert.equal(moment.localeData().firstDayOfWeek(), 3, 'firstDayOfWeek');
  37383. assert.equal(moment.localeData().firstDayOfYear(), 4, 'firstDayOfYear');
  37384. });
  37385. test('instance locale method', function (assert) {
  37386. moment.locale('en');
  37387. assert.equal(moment([2012, 5, 6]).format('MMMM'), 'June', 'Normally default to global');
  37388. assert.equal(moment([2012, 5, 6]).locale('es').format('MMMM'), 'junio', 'Use the instance specific locale');
  37389. assert.equal(moment([2012, 5, 6]).format('MMMM'), 'June', 'Using an instance specific locale does not affect other moments');
  37390. });
  37391. test('instance locale method with array', function (assert) {
  37392. var m = moment().locale(['non-existent', 'fr', 'also-non-existent']);
  37393. assert.equal(m.locale(), 'fr', 'passing an array uses the first valid locale');
  37394. m = moment().locale(['es', 'fr', 'also-non-existent']);
  37395. assert.equal(m.locale(), 'es', 'passing an array uses the first valid locale');
  37396. });
  37397. test('instance getter locale substrings', function (assert) {
  37398. var m = moment();
  37399. m.locale('fr-crap');
  37400. assert.equal(m.locale(), 'fr', 'use substrings');
  37401. m.locale('fr-does-not-exist');
  37402. assert.equal(m.locale(), 'fr', 'uses deep substrings');
  37403. });
  37404. test('instance locale persists with manipulation', function (assert) {
  37405. moment.locale('en');
  37406. assert.equal(moment([2012, 5, 6]).locale('es').add({days: 1}).format('MMMM'), 'junio', 'With addition');
  37407. assert.equal(moment([2012, 5, 6]).locale('es').day(0).format('MMMM'), 'junio', 'With day getter');
  37408. assert.equal(moment([2012, 5, 6]).locale('es').endOf('day').format('MMMM'), 'junio', 'With endOf');
  37409. });
  37410. test('instance locale persists with cloning', function (assert) {
  37411. moment.locale('en');
  37412. var a = moment([2012, 5, 6]).locale('es'),
  37413. b = a.clone(),
  37414. c = moment(a);
  37415. assert.equal(b.format('MMMM'), 'junio', 'using moment.fn.clone()');
  37416. assert.equal(b.format('MMMM'), 'junio', 'using moment()');
  37417. });
  37418. test('duration locale method', function (assert) {
  37419. moment.locale('en');
  37420. assert.equal(moment.duration({seconds: 44}).humanize(), 'a few seconds', 'Normally default to global');
  37421. assert.equal(moment.duration({seconds: 44}).locale('es').humanize(), 'unos segundos', 'Use the instance specific locale');
  37422. assert.equal(moment.duration({seconds: 44}).humanize(), 'a few seconds', 'Using an instance specific locale does not affect other durations');
  37423. });
  37424. test('duration locale persists with cloning', function (assert) {
  37425. moment.locale('en');
  37426. var a = moment.duration({seconds: 44}).locale('es'),
  37427. b = moment.duration(a);
  37428. assert.equal(b.humanize(), 'unos segundos', 'using moment.duration()');
  37429. });
  37430. test('changing the global locale doesn\'t affect existing duration instances', function (assert) {
  37431. var mom = moment.duration();
  37432. moment.locale('fr');
  37433. assert.equal('en', mom.locale());
  37434. });
  37435. test('duration deprecations', function (assert) {
  37436. assert.equal(moment.duration().lang(), moment.duration().localeData(), 'duration.lang is the same as duration.localeData');
  37437. });
  37438. test('from and fromNow with invalid date', function (assert) {
  37439. assert.equal(moment(NaN).from(), 'Invalid date', 'moment.from with invalid moment');
  37440. assert.equal(moment(NaN).fromNow(), 'Invalid date', 'moment.fromNow with invalid moment');
  37441. });
  37442. test('from relative time future', function (assert) {
  37443. var start = moment([2007, 1, 28]);
  37444. assert.equal(start.from(moment([2007, 1, 28]).subtract({s: 44})), 'in a few seconds', '44 seconds = a few seconds');
  37445. assert.equal(start.from(moment([2007, 1, 28]).subtract({s: 45})), 'in a minute', '45 seconds = a minute');
  37446. assert.equal(start.from(moment([2007, 1, 28]).subtract({s: 89})), 'in a minute', '89 seconds = a minute');
  37447. assert.equal(start.from(moment([2007, 1, 28]).subtract({s: 90})), 'in 2 minutes', '90 seconds = 2 minutes');
  37448. assert.equal(start.from(moment([2007, 1, 28]).subtract({m: 44})), 'in 44 minutes', '44 minutes = 44 minutes');
  37449. assert.equal(start.from(moment([2007, 1, 28]).subtract({m: 45})), 'in an hour', '45 minutes = an hour');
  37450. assert.equal(start.from(moment([2007, 1, 28]).subtract({m: 89})), 'in an hour', '89 minutes = an hour');
  37451. assert.equal(start.from(moment([2007, 1, 28]).subtract({m: 90})), 'in 2 hours', '90 minutes = 2 hours');
  37452. assert.equal(start.from(moment([2007, 1, 28]).subtract({h: 5})), 'in 5 hours', '5 hours = 5 hours');
  37453. assert.equal(start.from(moment([2007, 1, 28]).subtract({h: 21})), 'in 21 hours', '21 hours = 21 hours');
  37454. assert.equal(start.from(moment([2007, 1, 28]).subtract({h: 22})), 'in a day', '22 hours = a day');
  37455. assert.equal(start.from(moment([2007, 1, 28]).subtract({h: 35})), 'in a day', '35 hours = a day');
  37456. assert.equal(start.from(moment([2007, 1, 28]).subtract({h: 36})), 'in 2 days', '36 hours = 2 days');
  37457. assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 1})), 'in a day', '1 day = a day');
  37458. assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 5})), 'in 5 days', '5 days = 5 days');
  37459. assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 25})), 'in 25 days', '25 days = 25 days');
  37460. assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 26})), 'in a month', '26 days = a month');
  37461. assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 30})), 'in a month', '30 days = a month');
  37462. assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 45})), 'in a month', '45 days = a month');
  37463. assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 47})), 'in 2 months', '47 days = 2 months');
  37464. assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 74})), 'in 2 months', '74 days = 2 months');
  37465. assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 78})), 'in 3 months', '78 days = 3 months');
  37466. assert.equal(start.from(moment([2007, 1, 28]).subtract({M: 1})), 'in a month', '1 month = a month');
  37467. assert.equal(start.from(moment([2007, 1, 28]).subtract({M: 5})), 'in 5 months', '5 months = 5 months');
  37468. assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 315})), 'in 10 months', '315 days = 10 months');
  37469. assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 344})), 'in a year', '344 days = a year');
  37470. assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 345})), 'in a year', '345 days = a year');
  37471. assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 548})), 'in 2 years', '548 days = in 2 years');
  37472. assert.equal(start.from(moment([2007, 1, 28]).subtract({y: 1})), 'in a year', '1 year = a year');
  37473. assert.equal(start.from(moment([2007, 1, 28]).subtract({y: 5})), 'in 5 years', '5 years = 5 years');
  37474. });
  37475. test('from relative time past', function (assert) {
  37476. var start = moment([2007, 1, 28]);
  37477. assert.equal(start.from(moment([2007, 1, 28]).add({s: 44})), 'a few seconds ago', '44 seconds = a few seconds');
  37478. assert.equal(start.from(moment([2007, 1, 28]).add({s: 45})), 'a minute ago', '45 seconds = a minute');
  37479. assert.equal(start.from(moment([2007, 1, 28]).add({s: 89})), 'a minute ago', '89 seconds = a minute');
  37480. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90})), '2 minutes ago', '90 seconds = 2 minutes');
  37481. assert.equal(start.from(moment([2007, 1, 28]).add({m: 44})), '44 minutes ago', '44 minutes = 44 minutes');
  37482. assert.equal(start.from(moment([2007, 1, 28]).add({m: 45})), 'an hour ago', '45 minutes = an hour');
  37483. assert.equal(start.from(moment([2007, 1, 28]).add({m: 89})), 'an hour ago', '89 minutes = an hour');
  37484. assert.equal(start.from(moment([2007, 1, 28]).add({m: 90})), '2 hours ago', '90 minutes = 2 hours');
  37485. assert.equal(start.from(moment([2007, 1, 28]).add({h: 5})), '5 hours ago', '5 hours = 5 hours');
  37486. assert.equal(start.from(moment([2007, 1, 28]).add({h: 21})), '21 hours ago', '21 hours = 21 hours');
  37487. assert.equal(start.from(moment([2007, 1, 28]).add({h: 22})), 'a day ago', '22 hours = a day');
  37488. assert.equal(start.from(moment([2007, 1, 28]).add({h: 35})), 'a day ago', '35 hours = a day');
  37489. assert.equal(start.from(moment([2007, 1, 28]).add({h: 36})), '2 days ago', '36 hours = 2 days');
  37490. assert.equal(start.from(moment([2007, 1, 28]).add({d: 1})), 'a day ago', '1 day = a day');
  37491. assert.equal(start.from(moment([2007, 1, 28]).add({d: 5})), '5 days ago', '5 days = 5 days');
  37492. assert.equal(start.from(moment([2007, 1, 28]).add({d: 25})), '25 days ago', '25 days = 25 days');
  37493. assert.equal(start.from(moment([2007, 1, 28]).add({d: 26})), 'a month ago', '26 days = a month');
  37494. assert.equal(start.from(moment([2007, 1, 28]).add({d: 30})), 'a month ago', '30 days = a month');
  37495. assert.equal(start.from(moment([2007, 1, 28]).add({d: 43})), 'a month ago', '43 days = a month');
  37496. assert.equal(start.from(moment([2007, 1, 28]).add({d: 46})), '2 months ago', '46 days = 2 months');
  37497. assert.equal(start.from(moment([2007, 1, 28]).add({d: 74})), '2 months ago', '75 days = 2 months');
  37498. assert.equal(start.from(moment([2007, 1, 28]).add({d: 76})), '3 months ago', '76 days = 3 months');
  37499. assert.equal(start.from(moment([2007, 1, 28]).add({M: 1})), 'a month ago', '1 month = a month');
  37500. assert.equal(start.from(moment([2007, 1, 28]).add({M: 5})), '5 months ago', '5 months = 5 months');
  37501. assert.equal(start.from(moment([2007, 1, 28]).add({d: 315})), '10 months ago', '315 days = 10 months');
  37502. assert.equal(start.from(moment([2007, 1, 28]).add({d: 344})), 'a year ago', '344 days = a year');
  37503. assert.equal(start.from(moment([2007, 1, 28]).add({d: 345})), 'a year ago', '345 days = a year');
  37504. assert.equal(start.from(moment([2007, 1, 28]).add({d: 548})), '2 years ago', '548 days = 2 years');
  37505. assert.equal(start.from(moment([2007, 1, 28]).add({y: 1})), 'a year ago', '1 year = a year');
  37506. assert.equal(start.from(moment([2007, 1, 28]).add({y: 5})), '5 years ago', '5 years = 5 years');
  37507. });
  37508. test('instance locale used with from', function (assert) {
  37509. moment.locale('en');
  37510. var a = moment([2012, 5, 6]).locale('es'),
  37511. b = moment([2012, 5, 7]);
  37512. assert.equal(a.from(b), 'hace un día', 'preserve locale of first moment');
  37513. assert.equal(b.from(a), 'in a day', 'do not preserve locale of second moment');
  37514. });
  37515. test('instance localeData', function (assert) {
  37516. moment.defineLocale('dude', {week: {dow: 3}});
  37517. assert.equal(moment().locale('dude').localeData()._week.dow, 3);
  37518. });
  37519. test('month name callback function', function (assert) {
  37520. function fakeReplace(m, format) {
  37521. if (/test/.test(format)) {
  37522. return 'test';
  37523. }
  37524. if (m.date() === 1) {
  37525. return 'date';
  37526. }
  37527. return 'default';
  37528. }
  37529. moment.locale('made-up-2', {
  37530. months : fakeReplace,
  37531. monthsShort : fakeReplace,
  37532. weekdays : fakeReplace,
  37533. weekdaysShort : fakeReplace,
  37534. weekdaysMin : fakeReplace
  37535. });
  37536. assert.equal(moment().format('[test] dd ddd dddd MMM MMMM'), 'test test test test test test', 'format month name function should be able to access the format string');
  37537. assert.equal(moment([2011, 0, 1]).format('dd ddd dddd MMM MMMM'), 'date date date date date', 'format month name function should be able to access the moment object');
  37538. assert.equal(moment([2011, 0, 2]).format('dd ddd dddd MMM MMMM'), 'default default default default default', 'format month name function should be able to access the moment object');
  37539. });
  37540. test('changing parts of a locale config', function (assert) {
  37541. moment.locale('partial-lang', {
  37542. months : 'a b c d e f g h i j k l'.split(' ')
  37543. });
  37544. assert.equal(moment([2011, 0, 1]).format('MMMM'), 'a', 'should be able to set locale values when creating the localeuage');
  37545. moment.locale('partial-lang', {
  37546. monthsShort : 'A B C D E F G H I J K L'.split(' ')
  37547. });
  37548. assert.equal(moment([2011, 0, 1]).format('MMMM MMM'), 'a A', 'should be able to set locale values after creating the localeuage');
  37549. });
  37550. test('start/endOf week feature for first-day-is-monday locales', function (assert) {
  37551. moment.locale('monday-lang', {
  37552. week : {
  37553. dow : 1 // Monday is the first day of the week
  37554. }
  37555. });
  37556. moment.locale('monday-lang');
  37557. assert.equal(moment([2013, 0, 1]).startOf('week').day(), 1, 'for locale monday-lang first day of the week should be monday');
  37558. assert.equal(moment([2013, 0, 1]).endOf('week').day(), 0, 'for locale monday-lang last day of the week should be sunday');
  37559. });
  37560. test('meridiem parsing', function (assert) {
  37561. moment.locale('meridiem-parsing', {
  37562. meridiemParse : /[bd]/i,
  37563. isPM : function (input) {
  37564. return input === 'b';
  37565. }
  37566. });
  37567. moment.locale('meridiem-parsing');
  37568. assert.equal(moment('2012-01-01 3b', 'YYYY-MM-DD ha').hour(), 15, 'Custom parsing of meridiem should work');
  37569. assert.equal(moment('2012-01-01 3d', 'YYYY-MM-DD ha').hour(), 3, 'Custom parsing of meridiem should work');
  37570. });
  37571. test('invalid date formatting', function (assert) {
  37572. moment.locale('has-invalid', {
  37573. invalidDate: 'KHAAAAAAAAAAAN!'
  37574. });
  37575. assert.equal(moment.invalid().format(), 'KHAAAAAAAAAAAN!');
  37576. assert.equal(moment.invalid().format('YYYY-MM-DD'), 'KHAAAAAAAAAAAN!');
  37577. });
  37578. test('return locale name', function (assert) {
  37579. var registered = moment.locale('return-this', {});
  37580. assert.equal(registered, 'return-this', 'returns the locale configured');
  37581. });
  37582. test('changing the global locale doesn\'t affect existing instances', function (assert) {
  37583. var mom = moment();
  37584. moment.locale('fr');
  37585. assert.equal('en', mom.locale());
  37586. });
  37587. test('setting a language on instance returns the original moment for chaining', function (assert) {
  37588. var mom = moment();
  37589. assert.equal(mom.lang('fr'), mom, 'setting the language (lang) returns the original moment for chaining');
  37590. assert.equal(mom.locale('it'), mom, 'setting the language (locale) returns the original moment for chaining');
  37591. });
  37592. test('lang(key) changes the language of the instance', function (assert) {
  37593. var m = moment().month(0);
  37594. m.lang('fr');
  37595. assert.equal(m.locale(), 'fr', 'm.lang(key) changes instance locale');
  37596. });
  37597. test('moment#locale(false) resets to global locale', function (assert) {
  37598. var m = moment();
  37599. moment.locale('fr');
  37600. m.locale('it');
  37601. assert.equal(moment.locale(), 'fr', 'global locale is it');
  37602. assert.equal(m.locale(), 'it', 'instance locale is it');
  37603. m.locale(false);
  37604. assert.equal(m.locale(), 'fr', 'instance locale reset to global locale');
  37605. });
  37606. test('moment().locale with missing key doesn\'t change locale', function (assert) {
  37607. assert.equal(moment().locale('boo').localeData(), moment.localeData(),
  37608. 'preserve global locale in case of bad locale id');
  37609. });
  37610. test('moment().lang with missing key doesn\'t change locale', function (assert) {
  37611. assert.equal(moment().lang('boo').localeData(), moment.localeData(),
  37612. 'preserve global locale in case of bad locale id');
  37613. });
  37614. // TODO: Enable this after fixing pl months parse hack hack
  37615. // test('monthsParseExact', function (assert) {
  37616. // var locale = 'test-months-parse-exact';
  37617. // moment.defineLocale(locale, {
  37618. // monthsParseExact: true,
  37619. // months: 'A_AA_AAA_B_B B_BB B_C_C-C_C,C2C_D_D+D_D`D*D'.split('_'),
  37620. // monthsShort: 'E_EE_EEE_F_FF_FFF_G_GG_GGG_H_HH_HHH'.split('_')
  37621. // });
  37622. // assert.equal(moment('A', 'MMMM', true).month(), 0, 'parse long month 0 with MMMM');
  37623. // assert.equal(moment('AA', 'MMMM', true).month(), 1, 'parse long month 1 with MMMM');
  37624. // assert.equal(moment('AAA', 'MMMM', true).month(), 2, 'parse long month 2 with MMMM');
  37625. // assert.equal(moment('B B', 'MMMM', true).month(), 4, 'parse long month 4 with MMMM');
  37626. // assert.equal(moment('BB B', 'MMMM', true).month(), 5, 'parse long month 5 with MMMM');
  37627. // assert.equal(moment('C-C', 'MMMM', true).month(), 7, 'parse long month 7 with MMMM');
  37628. // assert.equal(moment('C,C2C', 'MMMM', true).month(), 8, 'parse long month 8 with MMMM');
  37629. // assert.equal(moment('D+D', 'MMMM', true).month(), 10, 'parse long month 10 with MMMM');
  37630. // assert.equal(moment('D`D*D', 'MMMM', true).month(), 11, 'parse long month 11 with MMMM');
  37631. // assert.equal(moment('E', 'MMM', true).month(), 0, 'parse long month 0 with MMM');
  37632. // assert.equal(moment('EE', 'MMM', true).month(), 1, 'parse long month 1 with MMM');
  37633. // assert.equal(moment('EEE', 'MMM', true).month(), 2, 'parse long month 2 with MMM');
  37634. // assert.equal(moment('A', 'MMM').month(), 0, 'non-strict parse long month 0 with MMM');
  37635. // assert.equal(moment('AA', 'MMM').month(), 1, 'non-strict parse long month 1 with MMM');
  37636. // assert.equal(moment('AAA', 'MMM').month(), 2, 'non-strict parse long month 2 with MMM');
  37637. // assert.equal(moment('E', 'MMMM').month(), 0, 'non-strict parse short month 0 with MMMM');
  37638. // assert.equal(moment('EE', 'MMMM').month(), 1, 'non-strict parse short month 1 with MMMM');
  37639. // assert.equal(moment('EEE', 'MMMM').month(), 2, 'non-strict parse short month 2 with MMMM');
  37640. // });
  37641. }));
  37642. ;(function (global, factory) {
  37643. typeof exports === 'object' && typeof module !== 'undefined'
  37644. && typeof require === 'function' ? factory(require('../../moment')) :
  37645. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  37646. factory(global.moment)
  37647. }(this, function (moment) { 'use strict';
  37648. /*global QUnit:false*/
  37649. var test = QUnit.test;
  37650. var expect = QUnit.expect;
  37651. function module (name, lifecycle) {
  37652. QUnit.module(name, {
  37653. setup : function () {
  37654. moment.locale('en');
  37655. moment.createFromInputFallback = function (config) {
  37656. throw new Error('input not handled by moment: ' + config._i);
  37657. };
  37658. if (lifecycle && lifecycle.setup) {
  37659. lifecycle.setup();
  37660. }
  37661. },
  37662. teardown : function () {
  37663. if (lifecycle && lifecycle.teardown) {
  37664. lifecycle.teardown();
  37665. }
  37666. }
  37667. });
  37668. }
  37669. function localeModule (name, lifecycle) {
  37670. QUnit.module('locale:' + name, {
  37671. setup : function () {
  37672. moment.locale(name);
  37673. moment.createFromInputFallback = function (config) {
  37674. throw new Error('input not handled by moment: ' + config._i);
  37675. };
  37676. if (lifecycle && lifecycle.setup) {
  37677. lifecycle.setup();
  37678. }
  37679. },
  37680. teardown : function () {
  37681. moment.locale('en');
  37682. if (lifecycle && lifecycle.teardown) {
  37683. lifecycle.teardown();
  37684. }
  37685. }
  37686. });
  37687. }
  37688. module('min max');
  37689. test('min', function (assert) {
  37690. var now = moment(),
  37691. future = now.clone().add(1, 'month'),
  37692. past = now.clone().subtract(1, 'month'),
  37693. invalid = moment.invalid();
  37694. assert.equal(moment.min(now, future, past), past, 'min(now, future, past)');
  37695. assert.equal(moment.min(future, now, past), past, 'min(future, now, past)');
  37696. assert.equal(moment.min(future, past, now), past, 'min(future, past, now)');
  37697. assert.equal(moment.min(past, future, now), past, 'min(past, future, now)');
  37698. assert.equal(moment.min(now, past), past, 'min(now, past)');
  37699. assert.equal(moment.min(past, now), past, 'min(past, now)');
  37700. assert.equal(moment.min(now), now, 'min(now, past)');
  37701. assert.equal(moment.min([now, future, past]), past, 'min([now, future, past])');
  37702. assert.equal(moment.min([now, past]), past, 'min(now, past)');
  37703. assert.equal(moment.min([now]), now, 'min(now)');
  37704. assert.equal(moment.min([now, invalid]), invalid, 'min(now, invalid)');
  37705. assert.equal(moment.min([invalid, now]), invalid, 'min(invalid, now)');
  37706. });
  37707. test('max', function (assert) {
  37708. var now = moment(),
  37709. future = now.clone().add(1, 'month'),
  37710. past = now.clone().subtract(1, 'month'),
  37711. invalid = moment.invalid();
  37712. assert.equal(moment.max(now, future, past), future, 'max(now, future, past)');
  37713. assert.equal(moment.max(future, now, past), future, 'max(future, now, past)');
  37714. assert.equal(moment.max(future, past, now), future, 'max(future, past, now)');
  37715. assert.equal(moment.max(past, future, now), future, 'max(past, future, now)');
  37716. assert.equal(moment.max(now, past), now, 'max(now, past)');
  37717. assert.equal(moment.max(past, now), now, 'max(past, now)');
  37718. assert.equal(moment.max(now), now, 'max(now, past)');
  37719. assert.equal(moment.max([now, future, past]), future, 'max([now, future, past])');
  37720. assert.equal(moment.max([now, past]), now, 'max(now, past)');
  37721. assert.equal(moment.max([now]), now, 'max(now)');
  37722. assert.equal(moment.max([now, invalid]), invalid, 'max(now, invalid)');
  37723. assert.equal(moment.max([invalid, now]), invalid, 'max(invalid, now)');
  37724. });
  37725. }));
  37726. ;(function (global, factory) {
  37727. typeof exports === 'object' && typeof module !== 'undefined'
  37728. && typeof require === 'function' ? factory(require('../../moment')) :
  37729. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  37730. factory(global.moment)
  37731. }(this, function (moment) { 'use strict';
  37732. /*global QUnit:false*/
  37733. var test = QUnit.test;
  37734. var expect = QUnit.expect;
  37735. function module (name, lifecycle) {
  37736. QUnit.module(name, {
  37737. setup : function () {
  37738. moment.locale('en');
  37739. moment.createFromInputFallback = function (config) {
  37740. throw new Error('input not handled by moment: ' + config._i);
  37741. };
  37742. if (lifecycle && lifecycle.setup) {
  37743. lifecycle.setup();
  37744. }
  37745. },
  37746. teardown : function () {
  37747. if (lifecycle && lifecycle.teardown) {
  37748. lifecycle.teardown();
  37749. }
  37750. }
  37751. });
  37752. }
  37753. function localeModule (name, lifecycle) {
  37754. QUnit.module('locale:' + name, {
  37755. setup : function () {
  37756. moment.locale(name);
  37757. moment.createFromInputFallback = function (config) {
  37758. throw new Error('input not handled by moment: ' + config._i);
  37759. };
  37760. if (lifecycle && lifecycle.setup) {
  37761. lifecycle.setup();
  37762. }
  37763. },
  37764. teardown : function () {
  37765. moment.locale('en');
  37766. if (lifecycle && lifecycle.teardown) {
  37767. lifecycle.teardown();
  37768. }
  37769. }
  37770. });
  37771. }
  37772. module('mutable');
  37773. test('manipulation methods', function (assert) {
  37774. var m = moment();
  37775. assert.equal(m, m.year(2011), 'year() should be mutable');
  37776. assert.equal(m, m.month(1), 'month() should be mutable');
  37777. assert.equal(m, m.hours(7), 'hours() should be mutable');
  37778. assert.equal(m, m.minutes(33), 'minutes() should be mutable');
  37779. assert.equal(m, m.seconds(44), 'seconds() should be mutable');
  37780. assert.equal(m, m.milliseconds(55), 'milliseconds() should be mutable');
  37781. assert.equal(m, m.day(2), 'day() should be mutable');
  37782. assert.equal(m, m.startOf('week'), 'startOf() should be mutable');
  37783. assert.equal(m, m.add(1, 'days'), 'add() should be mutable');
  37784. assert.equal(m, m.subtract(2, 'years'), 'subtract() should be mutable');
  37785. assert.equal(m, m.local(), 'local() should be mutable');
  37786. assert.equal(m, m.utc(), 'utc() should be mutable');
  37787. });
  37788. test('non mutable methods', function (assert) {
  37789. var m = moment();
  37790. assert.notEqual(m, m.clone(), 'clone() should not be mutable');
  37791. });
  37792. }));
  37793. ;(function (global, factory) {
  37794. typeof exports === 'object' && typeof module !== 'undefined'
  37795. && typeof require === 'function' ? factory(require('../../moment')) :
  37796. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  37797. factory(global.moment)
  37798. }(this, function (moment) { 'use strict';
  37799. /*global QUnit:false*/
  37800. var test = QUnit.test;
  37801. var expect = QUnit.expect;
  37802. function module (name, lifecycle) {
  37803. QUnit.module(name, {
  37804. setup : function () {
  37805. moment.locale('en');
  37806. moment.createFromInputFallback = function (config) {
  37807. throw new Error('input not handled by moment: ' + config._i);
  37808. };
  37809. if (lifecycle && lifecycle.setup) {
  37810. lifecycle.setup();
  37811. }
  37812. },
  37813. teardown : function () {
  37814. if (lifecycle && lifecycle.teardown) {
  37815. lifecycle.teardown();
  37816. }
  37817. }
  37818. });
  37819. }
  37820. function localeModule (name, lifecycle) {
  37821. QUnit.module('locale:' + name, {
  37822. setup : function () {
  37823. moment.locale(name);
  37824. moment.createFromInputFallback = function (config) {
  37825. throw new Error('input not handled by moment: ' + config._i);
  37826. };
  37827. if (lifecycle && lifecycle.setup) {
  37828. lifecycle.setup();
  37829. }
  37830. },
  37831. teardown : function () {
  37832. moment.locale('en');
  37833. if (lifecycle && lifecycle.teardown) {
  37834. lifecycle.teardown();
  37835. }
  37836. }
  37837. });
  37838. }
  37839. module('normalize units');
  37840. test('normalize units', function (assert) {
  37841. var fullKeys = ['year', 'quarter', 'month', 'isoWeek', 'week', 'day', 'hour', 'minute', 'second', 'millisecond', 'date', 'dayOfYear', 'weekday', 'isoWeekday', 'weekYear', 'isoWeekYear'],
  37842. aliases = ['y', 'Q', 'M', 'W', 'w', 'd', 'h', 'm', 's', 'ms', 'D', 'DDD', 'e', 'E', 'gg', 'GG'],
  37843. length = fullKeys.length,
  37844. fullKey,
  37845. fullKeyCaps,
  37846. fullKeyPlural,
  37847. fullKeyCapsPlural,
  37848. fullKeyLower,
  37849. alias,
  37850. index;
  37851. for (index = 0; index < length; index += 1) {
  37852. fullKey = fullKeys[index];
  37853. fullKeyCaps = fullKey.toUpperCase();
  37854. fullKeyLower = fullKey.toLowerCase();
  37855. fullKeyPlural = fullKey + 's';
  37856. fullKeyCapsPlural = fullKeyCaps + 's';
  37857. alias = aliases[index];
  37858. assert.equal(moment.normalizeUnits(fullKey), fullKey, 'Testing full key ' + fullKey);
  37859. assert.equal(moment.normalizeUnits(fullKeyCaps), fullKey, 'Testing full key capitalised ' + fullKey);
  37860. assert.equal(moment.normalizeUnits(fullKeyPlural), fullKey, 'Testing full key plural ' + fullKey);
  37861. assert.equal(moment.normalizeUnits(fullKeyCapsPlural), fullKey, 'Testing full key capitalised and plural ' + fullKey);
  37862. assert.equal(moment.normalizeUnits(alias), fullKey, 'Testing alias ' + fullKey);
  37863. }
  37864. });
  37865. }));
  37866. ;(function (global, factory) {
  37867. typeof exports === 'object' && typeof module !== 'undefined'
  37868. && typeof require === 'function' ? factory(require('../../moment')) :
  37869. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  37870. factory(global.moment)
  37871. }(this, function (moment) { 'use strict';
  37872. /*global QUnit:false*/
  37873. var test = QUnit.test;
  37874. var expect = QUnit.expect;
  37875. function module (name, lifecycle) {
  37876. QUnit.module(name, {
  37877. setup : function () {
  37878. moment.locale('en');
  37879. moment.createFromInputFallback = function (config) {
  37880. throw new Error('input not handled by moment: ' + config._i);
  37881. };
  37882. if (lifecycle && lifecycle.setup) {
  37883. lifecycle.setup();
  37884. }
  37885. },
  37886. teardown : function () {
  37887. if (lifecycle && lifecycle.teardown) {
  37888. lifecycle.teardown();
  37889. }
  37890. }
  37891. });
  37892. }
  37893. function localeModule (name, lifecycle) {
  37894. QUnit.module('locale:' + name, {
  37895. setup : function () {
  37896. moment.locale(name);
  37897. moment.createFromInputFallback = function (config) {
  37898. throw new Error('input not handled by moment: ' + config._i);
  37899. };
  37900. if (lifecycle && lifecycle.setup) {
  37901. lifecycle.setup();
  37902. }
  37903. },
  37904. teardown : function () {
  37905. moment.locale('en');
  37906. if (lifecycle && lifecycle.teardown) {
  37907. lifecycle.teardown();
  37908. }
  37909. }
  37910. });
  37911. }
  37912. module('now');
  37913. test('now', function (assert) {
  37914. var startOfTest = new Date().valueOf(),
  37915. momentNowTime = moment.now(),
  37916. afterMomentCreationTime = new Date().valueOf();
  37917. assert.ok(startOfTest <= momentNowTime, 'moment now() time should be now, not in the past');
  37918. assert.ok(momentNowTime <= afterMomentCreationTime, 'moment now() time should be now, not in the future');
  37919. });
  37920. test('now - Date mocked', function (assert) {
  37921. // We need to test mocking the global Date object, so disable 'Read Only' jshint check
  37922. /* jshint -W020 */
  37923. var RealDate = Date,
  37924. customTimeMs = moment('2015-01-01T01:30:00.000Z').valueOf();
  37925. function MockDate() {
  37926. return new RealDate(customTimeMs);
  37927. }
  37928. MockDate.now = function () {
  37929. return new MockDate().valueOf();
  37930. };
  37931. MockDate.prototype = RealDate.prototype;
  37932. Date = MockDate;
  37933. try {
  37934. assert.equal(moment().valueOf(), customTimeMs, 'moment now() time should use the global Date object');
  37935. } finally {
  37936. Date = RealDate;
  37937. }
  37938. });
  37939. test('now - custom value', function (assert) {
  37940. var customTimeStr = '2015-01-01T01:30:00.000Z',
  37941. customTime = moment(customTimeStr, moment.ISO_8601).valueOf(),
  37942. oldFn = moment.now;
  37943. moment.now = function () {
  37944. return customTime;
  37945. };
  37946. try {
  37947. assert.ok(moment().toISOString() === customTimeStr, 'moment() constructor should use the function defined by moment.now, but it did not');
  37948. assert.ok(moment.utc().toISOString() === customTimeStr, 'moment() constructor should use the function defined by moment.now, but it did not');
  37949. assert.ok(moment.utc([]).toISOString() === '2015-01-01T00:00:00.000Z', 'moment() constructor should fall back to the date defined by moment.now when an empty array is given, but it did not');
  37950. } finally {
  37951. moment.now = oldFn;
  37952. }
  37953. });
  37954. }));
  37955. ;(function (global, factory) {
  37956. typeof exports === 'object' && typeof module !== 'undefined'
  37957. && typeof require === 'function' ? factory(require('../../moment')) :
  37958. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  37959. factory(global.moment)
  37960. }(this, function (moment) { 'use strict';
  37961. /*global QUnit:false*/
  37962. var test = QUnit.test;
  37963. var expect = QUnit.expect;
  37964. function module (name, lifecycle) {
  37965. QUnit.module(name, {
  37966. setup : function () {
  37967. moment.locale('en');
  37968. moment.createFromInputFallback = function (config) {
  37969. throw new Error('input not handled by moment: ' + config._i);
  37970. };
  37971. if (lifecycle && lifecycle.setup) {
  37972. lifecycle.setup();
  37973. }
  37974. },
  37975. teardown : function () {
  37976. if (lifecycle && lifecycle.teardown) {
  37977. lifecycle.teardown();
  37978. }
  37979. }
  37980. });
  37981. }
  37982. function localeModule (name, lifecycle) {
  37983. QUnit.module('locale:' + name, {
  37984. setup : function () {
  37985. moment.locale(name);
  37986. moment.createFromInputFallback = function (config) {
  37987. throw new Error('input not handled by moment: ' + config._i);
  37988. };
  37989. if (lifecycle && lifecycle.setup) {
  37990. lifecycle.setup();
  37991. }
  37992. },
  37993. teardown : function () {
  37994. moment.locale('en');
  37995. if (lifecycle && lifecycle.teardown) {
  37996. lifecycle.teardown();
  37997. }
  37998. }
  37999. });
  38000. }
  38001. module('parsing flags');
  38002. function flags () {
  38003. return moment.apply(null, arguments).parsingFlags();
  38004. }
  38005. test('overflow with array', function (assert) {
  38006. //months
  38007. assert.equal(flags([2010, 0]).overflow, -1, 'month 0 valid');
  38008. assert.equal(flags([2010, 1]).overflow, -1, 'month 1 valid');
  38009. assert.equal(flags([2010, -1]).overflow, 1, 'month -1 invalid');
  38010. assert.equal(flags([2100, 12]).overflow, 1, 'month 12 invalid');
  38011. //days
  38012. assert.equal(flags([2010, 1, 16]).overflow, -1, 'date valid');
  38013. assert.equal(flags([2010, 1, -1]).overflow, 2, 'date -1 invalid');
  38014. assert.equal(flags([2010, 1, 0]).overflow, 2, 'date 0 invalid');
  38015. assert.equal(flags([2010, 1, 32]).overflow, 2, 'date 32 invalid');
  38016. assert.equal(flags([2012, 1, 29]).overflow, -1, 'date leap year valid');
  38017. assert.equal(flags([2010, 1, 29]).overflow, 2, 'date leap year invalid');
  38018. //hours
  38019. assert.equal(flags([2010, 1, 1, 8]).overflow, -1, 'hour valid');
  38020. assert.equal(flags([2010, 1, 1, 0]).overflow, -1, 'hour 0 valid');
  38021. assert.equal(flags([2010, 1, 1, -1]).overflow, 3, 'hour -1 invalid');
  38022. assert.equal(flags([2010, 1, 1, 25]).overflow, 3, 'hour 25 invalid');
  38023. assert.equal(flags([2010, 1, 1, 24, 1]).overflow, 3, 'hour 24:01 invalid');
  38024. //minutes
  38025. assert.equal(flags([2010, 1, 1, 8, 15]).overflow, -1, 'minute valid');
  38026. assert.equal(flags([2010, 1, 1, 8, 0]).overflow, -1, 'minute 0 valid');
  38027. assert.equal(flags([2010, 1, 1, 8, -1]).overflow, 4, 'minute -1 invalid');
  38028. assert.equal(flags([2010, 1, 1, 8, 60]).overflow, 4, 'minute 60 invalid');
  38029. //seconds
  38030. assert.equal(flags([2010, 1, 1, 8, 15, 12]).overflow, -1, 'second valid');
  38031. assert.equal(flags([2010, 1, 1, 8, 15, 0]).overflow, -1, 'second 0 valid');
  38032. assert.equal(flags([2010, 1, 1, 8, 15, -1]).overflow, 5, 'second -1 invalid');
  38033. assert.equal(flags([2010, 1, 1, 8, 15, 60]).overflow, 5, 'second 60 invalid');
  38034. //milliseconds
  38035. assert.equal(flags([2010, 1, 1, 8, 15, 12, 345]).overflow, -1, 'millisecond valid');
  38036. assert.equal(flags([2010, 1, 1, 8, 15, 12, 0]).overflow, -1, 'millisecond 0 valid');
  38037. assert.equal(flags([2010, 1, 1, 8, 15, 12, -1]).overflow, 6, 'millisecond -1 invalid');
  38038. assert.equal(flags([2010, 1, 1, 8, 15, 12, 1000]).overflow, 6, 'millisecond 1000 invalid');
  38039. // 24 hrs
  38040. assert.equal(flags([2010, 1, 1, 24, 0, 0, 0]).overflow, -1, '24:00:00.000 is fine');
  38041. assert.equal(flags([2010, 1, 1, 24, 1, 0, 0]).overflow, 3, '24:01:00.000 is wrong hour');
  38042. assert.equal(flags([2010, 1, 1, 24, 0, 1, 0]).overflow, 3, '24:00:01.000 is wrong hour');
  38043. assert.equal(flags([2010, 1, 1, 24, 0, 0, 1]).overflow, 3, '24:00:00.001 is wrong hour');
  38044. });
  38045. test('overflow without format', function (assert) {
  38046. //months
  38047. assert.equal(flags('2001-01', 'YYYY-MM').overflow, -1, 'month 1 valid');
  38048. assert.equal(flags('2001-12', 'YYYY-MM').overflow, -1, 'month 12 valid');
  38049. assert.equal(flags('2001-13', 'YYYY-MM').overflow, 1, 'month 13 invalid');
  38050. //days
  38051. assert.equal(flags('2010-01-16', 'YYYY-MM-DD').overflow, -1, 'date 16 valid');
  38052. assert.equal(flags('2010-01-0', 'YYYY-MM-DD').overflow, 2, 'date 0 invalid');
  38053. assert.equal(flags('2010-01-32', 'YYYY-MM-DD').overflow, 2, 'date 32 invalid');
  38054. assert.equal(flags('2012-02-29', 'YYYY-MM-DD').overflow, -1, 'date leap year valid');
  38055. assert.equal(flags('2010-02-29', 'YYYY-MM-DD').overflow, 2, 'date leap year invalid');
  38056. //days of the year
  38057. assert.equal(flags('2010 300', 'YYYY DDDD').overflow, -1, 'day 300 of year valid');
  38058. assert.equal(flags('2010 365', 'YYYY DDDD').overflow, -1, 'day 365 of year valid');
  38059. assert.equal(flags('2010 366', 'YYYY DDDD').overflow, 2, 'day 366 of year invalid');
  38060. assert.equal(flags('2012 366', 'YYYY DDDD').overflow, -1, 'day 366 of leap year valid');
  38061. assert.equal(flags('2012 367', 'YYYY DDDD').overflow, 2, 'day 367 of leap year invalid');
  38062. //hours
  38063. assert.equal(flags('08', 'HH').overflow, -1, 'hour valid');
  38064. assert.equal(flags('00', 'HH').overflow, -1, 'hour 0 valid');
  38065. assert.equal(flags('25', 'HH').overflow, 3, 'hour 25 invalid');
  38066. assert.equal(flags('24:01', 'HH:mm').overflow, 3, 'hour 24:01 invalid');
  38067. //minutes
  38068. assert.equal(flags('08:15', 'HH:mm').overflow, -1, 'minute valid');
  38069. assert.equal(flags('08:00', 'HH:mm').overflow, -1, 'minute 0 valid');
  38070. assert.equal(flags('08:60', 'HH:mm').overflow, 4, 'minute 60 invalid');
  38071. //seconds
  38072. assert.equal(flags('08:15:12', 'HH:mm:ss').overflow, -1, 'second valid');
  38073. assert.equal(flags('08:15:00', 'HH:mm:ss').overflow, -1, 'second 0 valid');
  38074. assert.equal(flags('08:15:60', 'HH:mm:ss').overflow, 5, 'second 60 invalid');
  38075. //milliseconds
  38076. assert.equal(flags('08:15:12:345', 'HH:mm:ss:SSSS').overflow, -1, 'millisecond valid');
  38077. assert.equal(flags('08:15:12:000', 'HH:mm:ss:SSSS').overflow, -1, 'millisecond 0 valid');
  38078. //this is OK because we don't match the last digit, so it's 100 ms
  38079. assert.equal(flags('08:15:12:1000', 'HH:mm:ss:SSSS').overflow, -1, 'millisecond 1000 actually valid');
  38080. });
  38081. test('extra tokens', function (assert) {
  38082. assert.deepEqual(flags('1982-05-25', 'YYYY-MM-DD').unusedTokens, [], 'nothing extra');
  38083. assert.deepEqual(flags('1982-05', 'YYYY-MM-DD').unusedTokens, ['DD'], 'extra formatting token');
  38084. assert.deepEqual(flags('1982', 'YYYY-MM-DD').unusedTokens, ['MM', 'DD'], 'multiple extra formatting tokens');
  38085. assert.deepEqual(flags('1982-05', 'YYYY-MM-').unusedTokens, [], 'extra non-formatting token');
  38086. assert.deepEqual(flags('1982-05-', 'YYYY-MM-DD').unusedTokens, ['DD'], 'non-extra non-formatting token');
  38087. assert.deepEqual(flags('1982 05 1982', 'YYYY-MM-DD').unusedTokens, [], 'different non-formatting token');
  38088. });
  38089. test('extra tokens strict', function (assert) {
  38090. assert.deepEqual(flags('1982-05-25', 'YYYY-MM-DD', true).unusedTokens, [], 'nothing extra');
  38091. assert.deepEqual(flags('1982-05', 'YYYY-MM-DD', true).unusedTokens, ['-', 'DD'], 'extra formatting token');
  38092. assert.deepEqual(flags('1982', 'YYYY-MM-DD', true).unusedTokens, ['-', 'MM', '-', 'DD'], 'multiple extra formatting tokens');
  38093. assert.deepEqual(flags('1982-05', 'YYYY-MM-', true).unusedTokens, ['-'], 'extra non-formatting token');
  38094. assert.deepEqual(flags('1982-05-', 'YYYY-MM-DD', true).unusedTokens, ['DD'], 'non-extra non-formatting token');
  38095. assert.deepEqual(flags('1982 05 1982', 'YYYY-MM-DD', true).unusedTokens, ['-', '-'], 'different non-formatting token');
  38096. });
  38097. test('unused input', function (assert) {
  38098. assert.deepEqual(flags('1982-05-25', 'YYYY-MM-DD').unusedInput, [], 'normal input');
  38099. assert.deepEqual(flags('1982-05-25 this is more stuff', 'YYYY-MM-DD').unusedInput, [' this is more stuff'], 'trailing nonsense');
  38100. assert.deepEqual(flags('1982-05-25 09:30', 'YYYY-MM-DD').unusedInput, [' 09:30'], ['trailing legit-looking input']);
  38101. assert.deepEqual(flags('1982-05-25 some junk', 'YYYY-MM-DD [some junk]').unusedInput, [], 'junk that actually gets matched');
  38102. assert.deepEqual(flags('stuff at beginning 1982-05-25', 'YYYY-MM-DD').unusedInput, ['stuff at beginning '], 'leading junk');
  38103. assert.deepEqual(flags('junk 1982 more junk 05 yet more junk25', 'YYYY-MM-DD').unusedInput, ['junk ', ' more junk ', ' yet more junk'], 'interstitial junk');
  38104. });
  38105. test('unused input strict', function (assert) {
  38106. assert.deepEqual(flags('1982-05-25', 'YYYY-MM-DD', true).unusedInput, [], 'normal input');
  38107. assert.deepEqual(flags('1982-05-25 this is more stuff', 'YYYY-MM-DD', true).unusedInput, [' this is more stuff'], 'trailing nonsense');
  38108. assert.deepEqual(flags('1982-05-25 09:30', 'YYYY-MM-DD', true).unusedInput, [' 09:30'], ['trailing legit-looking input']);
  38109. assert.deepEqual(flags('1982-05-25 some junk', 'YYYY-MM-DD [some junk]', true).unusedInput, [], 'junk that actually gets matched');
  38110. assert.deepEqual(flags('stuff at beginning 1982-05-25', 'YYYY-MM-DD', true).unusedInput, ['stuff at beginning '], 'leading junk');
  38111. assert.deepEqual(flags('junk 1982 more junk 05 yet more junk25', 'YYYY-MM-DD', true).unusedInput, ['junk ', ' more junk ', ' yet more junk'], 'interstitial junk');
  38112. });
  38113. test('chars left over', function (assert) {
  38114. assert.equal(flags('1982-05-25', 'YYYY-MM-DD').charsLeftOver, 0, 'normal input');
  38115. assert.equal(flags('1982-05-25 this is more stuff', 'YYYY-MM-DD').charsLeftOver, ' this is more stuff'.length, 'trailing nonsense');
  38116. assert.equal(flags('1982-05-25 09:30', 'YYYY-MM-DD').charsLeftOver, ' 09:30'.length, 'trailing legit-looking input');
  38117. assert.equal(flags('stuff at beginning 1982-05-25', 'YYYY-MM-DD').charsLeftOver, 'stuff at beginning '.length, 'leading junk');
  38118. assert.equal(flags('1982 junk 05 more junk25', 'YYYY-MM-DD').charsLeftOver, [' junk ', ' more junk'].join('').length, 'interstitial junk');
  38119. assert.equal(flags('stuff at beginning 1982 junk 05 more junk25', 'YYYY-MM-DD').charsLeftOver, ['stuff at beginning ', ' junk ', ' more junk'].join('').length, 'leading and interstitial junk');
  38120. });
  38121. test('empty', function (assert) {
  38122. assert.equal(flags('1982-05-25', 'YYYY-MM-DD').empty, false, 'normal input');
  38123. assert.equal(flags('nothing here', 'YYYY-MM-DD').empty, true, 'pure garbage');
  38124. assert.equal(flags('junk but has the number 2000 in it', 'YYYY-MM-DD').empty, false, 'only mostly garbage');
  38125. assert.equal(flags('', 'YYYY-MM-DD').empty, true, 'empty string');
  38126. assert.equal(flags('', 'YYYY-MM-DD').empty, true, 'blank string');
  38127. });
  38128. test('null', function (assert) {
  38129. assert.equal(flags('1982-05-25', 'YYYY-MM-DD').nullInput, false, 'normal input');
  38130. assert.equal(flags(null).nullInput, true, 'just null');
  38131. assert.equal(flags(null, 'YYYY-MM-DD').nullInput, true, 'null with format');
  38132. });
  38133. test('invalid month', function (assert) {
  38134. assert.equal(flags('1982 May', 'YYYY MMMM').invalidMonth, null, 'normal input');
  38135. assert.equal(flags('1982 Laser', 'YYYY MMMM').invalidMonth, 'Laser', 'bad month name');
  38136. });
  38137. test('empty format array', function (assert) {
  38138. assert.equal(flags('1982 May', ['YYYY MMM']).invalidFormat, false, 'empty format array');
  38139. assert.equal(flags('1982 May', []).invalidFormat, true, 'empty format array');
  38140. });
  38141. }));
  38142. ;(function (global, factory) {
  38143. typeof exports === 'object' && typeof module !== 'undefined'
  38144. && typeof require === 'function' ? factory(require('../../moment')) :
  38145. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  38146. factory(global.moment)
  38147. }(this, function (moment) { 'use strict';
  38148. /*global QUnit:false*/
  38149. var test = QUnit.test;
  38150. var expect = QUnit.expect;
  38151. function module (name, lifecycle) {
  38152. QUnit.module(name, {
  38153. setup : function () {
  38154. moment.locale('en');
  38155. moment.createFromInputFallback = function (config) {
  38156. throw new Error('input not handled by moment: ' + config._i);
  38157. };
  38158. if (lifecycle && lifecycle.setup) {
  38159. lifecycle.setup();
  38160. }
  38161. },
  38162. teardown : function () {
  38163. if (lifecycle && lifecycle.teardown) {
  38164. lifecycle.teardown();
  38165. }
  38166. }
  38167. });
  38168. }
  38169. function localeModule (name, lifecycle) {
  38170. QUnit.module('locale:' + name, {
  38171. setup : function () {
  38172. moment.locale(name);
  38173. moment.createFromInputFallback = function (config) {
  38174. throw new Error('input not handled by moment: ' + config._i);
  38175. };
  38176. if (lifecycle && lifecycle.setup) {
  38177. lifecycle.setup();
  38178. }
  38179. },
  38180. teardown : function () {
  38181. moment.locale('en');
  38182. if (lifecycle && lifecycle.teardown) {
  38183. lifecycle.teardown();
  38184. }
  38185. }
  38186. });
  38187. }
  38188. var symbolMap = {
  38189. '1': '!',
  38190. '2': '@',
  38191. '3': '#',
  38192. '4': '$',
  38193. '5': '%',
  38194. '6': '^',
  38195. '7': '&',
  38196. '8': '*',
  38197. '9': '(',
  38198. '0': ')'
  38199. },
  38200. numberMap = {
  38201. '!': '1',
  38202. '@': '2',
  38203. '#': '3',
  38204. '$': '4',
  38205. '%': '5',
  38206. '^': '6',
  38207. '&': '7',
  38208. '*': '8',
  38209. '(': '9',
  38210. ')': '0'
  38211. };
  38212. module('preparse and postformat', {
  38213. setup: function () {
  38214. moment.locale('symbol', {
  38215. preparse: function (string) {
  38216. return string.replace(/[!@#$%\^&*()]/g, function (match) {
  38217. return numberMap[match];
  38218. });
  38219. },
  38220. postformat: function (string) {
  38221. return string.replace(/\d/g, function (match) {
  38222. return symbolMap[match];
  38223. });
  38224. }
  38225. });
  38226. }
  38227. });
  38228. test('transform', function (assert) {
  38229. assert.equal(moment.utc('@)!@-)*-@&', 'YYYY-MM-DD').unix(), 1346025600, 'preparse string + format');
  38230. assert.equal(moment.utc('@)!@-)*-@&').unix(), 1346025600, 'preparse ISO8601 string');
  38231. assert.equal(moment.unix(1346025600).utc().format('YYYY-MM-DD'), '@)!@-)*-@&', 'postformat');
  38232. });
  38233. test('transform from', function (assert) {
  38234. var start = moment([2007, 1, 28]);
  38235. assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '@ minutes', 'postformat should work on moment.fn.from');
  38236. assert.equal(moment().add(6, 'd').fromNow(true), '^ days', 'postformat should work on moment.fn.fromNow');
  38237. assert.equal(moment.duration(10, 'h').humanize(), '!) hours', 'postformat should work on moment.duration.fn.humanize');
  38238. });
  38239. test('calendar day', function (assert) {
  38240. var a = moment().hours(2).minutes(0).seconds(0);
  38241. assert.equal(moment(a).calendar(), 'Today at @:)) AM', 'today at the same time');
  38242. assert.equal(moment(a).add({m: 25}).calendar(), 'Today at @:@% AM', 'Now plus 25 min');
  38243. assert.equal(moment(a).add({h: 1}).calendar(), 'Today at #:)) AM', 'Now plus 1 hour');
  38244. assert.equal(moment(a).add({d: 1}).calendar(), 'Tomorrow at @:)) AM', 'tomorrow at the same time');
  38245. assert.equal(moment(a).subtract({h: 1}).calendar(), 'Today at !:)) AM', 'Now minus 1 hour');
  38246. assert.equal(moment(a).subtract({d: 1}).calendar(), 'Yesterday at @:)) AM', 'yesterday at the same time');
  38247. });
  38248. }));
  38249. ;(function (global, factory) {
  38250. typeof exports === 'object' && typeof module !== 'undefined'
  38251. && typeof require === 'function' ? factory(require('../../moment')) :
  38252. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  38253. factory(global.moment)
  38254. }(this, function (moment) { 'use strict';
  38255. /*global QUnit:false*/
  38256. var test = QUnit.test;
  38257. var expect = QUnit.expect;
  38258. function module (name, lifecycle) {
  38259. QUnit.module(name, {
  38260. setup : function () {
  38261. moment.locale('en');
  38262. moment.createFromInputFallback = function (config) {
  38263. throw new Error('input not handled by moment: ' + config._i);
  38264. };
  38265. if (lifecycle && lifecycle.setup) {
  38266. lifecycle.setup();
  38267. }
  38268. },
  38269. teardown : function () {
  38270. if (lifecycle && lifecycle.teardown) {
  38271. lifecycle.teardown();
  38272. }
  38273. }
  38274. });
  38275. }
  38276. function localeModule (name, lifecycle) {
  38277. QUnit.module('locale:' + name, {
  38278. setup : function () {
  38279. moment.locale(name);
  38280. moment.createFromInputFallback = function (config) {
  38281. throw new Error('input not handled by moment: ' + config._i);
  38282. };
  38283. if (lifecycle && lifecycle.setup) {
  38284. lifecycle.setup();
  38285. }
  38286. },
  38287. teardown : function () {
  38288. moment.locale('en');
  38289. if (lifecycle && lifecycle.teardown) {
  38290. lifecycle.teardown();
  38291. }
  38292. }
  38293. });
  38294. }
  38295. module('quarter');
  38296. test('library quarter getter', function (assert) {
  38297. assert.equal(moment([1985, 1, 4]).quarter(), 1, 'Feb 4 1985 is Q1');
  38298. assert.equal(moment([2029, 8, 18]).quarter(), 3, 'Sep 18 2029 is Q3');
  38299. assert.equal(moment([2013, 3, 24]).quarter(), 2, 'Apr 24 2013 is Q2');
  38300. assert.equal(moment([2015, 2, 5]).quarter(), 1, 'Mar 5 2015 is Q1');
  38301. assert.equal(moment([1970, 0, 2]).quarter(), 1, 'Jan 2 1970 is Q1');
  38302. assert.equal(moment([2001, 11, 12]).quarter(), 4, 'Dec 12 2001 is Q4');
  38303. assert.equal(moment([2000, 0, 2]).quarter(), 1, 'Jan 2 2000 is Q1');
  38304. });
  38305. test('quarter setter singular', function (assert) {
  38306. var m = moment([2014, 4, 11]);
  38307. assert.equal(m.quarter(2).month(), 4, 'set same quarter');
  38308. assert.equal(m.quarter(3).month(), 7, 'set 3rd quarter');
  38309. assert.equal(m.quarter(1).month(), 1, 'set 1st quarter');
  38310. assert.equal(m.quarter(4).month(), 10, 'set 4th quarter');
  38311. });
  38312. test('quarter setter plural', function (assert) {
  38313. var m = moment([2014, 4, 11]);
  38314. assert.equal(m.quarters(2).month(), 4, 'set same quarter');
  38315. assert.equal(m.quarters(3).month(), 7, 'set 3rd quarter');
  38316. assert.equal(m.quarters(1).month(), 1, 'set 1st quarter');
  38317. assert.equal(m.quarters(4).month(), 10, 'set 4th quarter');
  38318. });
  38319. test('quarter setter programmatic', function (assert) {
  38320. var m = moment([2014, 4, 11]);
  38321. assert.equal(m.set('quarter', 2).month(), 4, 'set same quarter');
  38322. assert.equal(m.set('quarter', 3).month(), 7, 'set 3rd quarter');
  38323. assert.equal(m.set('quarter', 1).month(), 1, 'set 1st quarter');
  38324. assert.equal(m.set('quarter', 4).month(), 10, 'set 4th quarter');
  38325. });
  38326. test('quarter setter programmatic plural', function (assert) {
  38327. var m = moment([2014, 4, 11]);
  38328. assert.equal(m.set('quarters', 2).month(), 4, 'set same quarter');
  38329. assert.equal(m.set('quarters', 3).month(), 7, 'set 3rd quarter');
  38330. assert.equal(m.set('quarters', 1).month(), 1, 'set 1st quarter');
  38331. assert.equal(m.set('quarters', 4).month(), 10, 'set 4th quarter');
  38332. });
  38333. test('quarter setter programmatic abbr', function (assert) {
  38334. var m = moment([2014, 4, 11]);
  38335. assert.equal(m.set('Q', 2).month(), 4, 'set same quarter');
  38336. assert.equal(m.set('Q', 3).month(), 7, 'set 3rd quarter');
  38337. assert.equal(m.set('Q', 1).month(), 1, 'set 1st quarter');
  38338. assert.equal(m.set('Q', 4).month(), 10, 'set 4th quarter');
  38339. });
  38340. test('quarter setter only month changes', function (assert) {
  38341. var m = moment([2014, 4, 11, 1, 2, 3, 4]).quarter(4);
  38342. assert.equal(m.year(), 2014, 'keep year');
  38343. assert.equal(m.month(), 10, 'set month');
  38344. assert.equal(m.date(), 11, 'keep date');
  38345. assert.equal(m.hour(), 1, 'keep hour');
  38346. assert.equal(m.minute(), 2, 'keep minutes');
  38347. assert.equal(m.second(), 3, 'keep seconds');
  38348. assert.equal(m.millisecond(), 4, 'keep milliseconds');
  38349. });
  38350. test('quarter setter bubble to next year', function (assert) {
  38351. var m = moment([2014, 4, 11, 1, 2, 3, 4]).quarter(7);
  38352. assert.equal(m.year(), 2015, 'year bubbled');
  38353. assert.equal(m.month(), 7, 'set month');
  38354. assert.equal(m.date(), 11, 'keep date');
  38355. assert.equal(m.hour(), 1, 'keep hour');
  38356. assert.equal(m.minute(), 2, 'keep minutes');
  38357. assert.equal(m.second(), 3, 'keep seconds');
  38358. assert.equal(m.millisecond(), 4, 'keep milliseconds');
  38359. });
  38360. test('quarter diff', function (assert) {
  38361. assert.equal(moment('2014-01-01').diff(moment('2014-04-01'), 'quarter'),
  38362. -1, 'diff -1 quarter');
  38363. assert.equal(moment('2014-04-01').diff(moment('2014-01-01'), 'quarter'),
  38364. 1, 'diff 1 quarter');
  38365. assert.equal(moment('2014-05-01').diff(moment('2014-01-01'), 'quarter'),
  38366. 1, 'diff 1 quarter');
  38367. assert.ok(Math.abs((4 / 3) - moment('2014-05-01').diff(
  38368. moment('2014-01-01'), 'quarter', true)) < 0.00001,
  38369. 'diff 1 1/3 quarter');
  38370. assert.equal(moment('2015-01-01').diff(moment('2014-01-01'), 'quarter'),
  38371. 4, 'diff 4 quarters');
  38372. });
  38373. test('quarter setter bubble to previous year', function (assert) {
  38374. var m = moment([2014, 4, 11, 1, 2, 3, 4]).quarter(-3);
  38375. assert.equal(m.year(), 2013, 'year bubbled');
  38376. assert.equal(m.month(), 1, 'set month');
  38377. assert.equal(m.date(), 11, 'keep date');
  38378. assert.equal(m.hour(), 1, 'keep hour');
  38379. assert.equal(m.minute(), 2, 'keep minutes');
  38380. assert.equal(m.second(), 3, 'keep seconds');
  38381. assert.equal(m.millisecond(), 4, 'keep milliseconds');
  38382. });
  38383. }));
  38384. ;(function (global, factory) {
  38385. typeof exports === 'object' && typeof module !== 'undefined'
  38386. && typeof require === 'function' ? factory(require('../../moment')) :
  38387. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  38388. factory(global.moment)
  38389. }(this, function (moment) { 'use strict';
  38390. /*global QUnit:false*/
  38391. var test = QUnit.test;
  38392. var expect = QUnit.expect;
  38393. function module (name, lifecycle) {
  38394. QUnit.module(name, {
  38395. setup : function () {
  38396. moment.locale('en');
  38397. moment.createFromInputFallback = function (config) {
  38398. throw new Error('input not handled by moment: ' + config._i);
  38399. };
  38400. if (lifecycle && lifecycle.setup) {
  38401. lifecycle.setup();
  38402. }
  38403. },
  38404. teardown : function () {
  38405. if (lifecycle && lifecycle.teardown) {
  38406. lifecycle.teardown();
  38407. }
  38408. }
  38409. });
  38410. }
  38411. function localeModule (name, lifecycle) {
  38412. QUnit.module('locale:' + name, {
  38413. setup : function () {
  38414. moment.locale(name);
  38415. moment.createFromInputFallback = function (config) {
  38416. throw new Error('input not handled by moment: ' + config._i);
  38417. };
  38418. if (lifecycle && lifecycle.setup) {
  38419. lifecycle.setup();
  38420. }
  38421. },
  38422. teardown : function () {
  38423. moment.locale('en');
  38424. if (lifecycle && lifecycle.teardown) {
  38425. lifecycle.teardown();
  38426. }
  38427. }
  38428. });
  38429. }
  38430. module('relative time');
  38431. test('default thresholds fromNow', function (assert) {
  38432. var a = moment();
  38433. // Seconds to minutes threshold
  38434. a.subtract(44, 'seconds');
  38435. assert.equal(a.fromNow(), 'a few seconds ago', 'Below default seconds to minutes threshold');
  38436. a.subtract(1, 'seconds');
  38437. assert.equal(a.fromNow(), 'a minute ago', 'Above default seconds to minutes threshold');
  38438. // Minutes to hours threshold
  38439. a = moment();
  38440. a.subtract(44, 'minutes');
  38441. assert.equal(a.fromNow(), '44 minutes ago', 'Below default minute to hour threshold');
  38442. a.subtract(1, 'minutes');
  38443. assert.equal(a.fromNow(), 'an hour ago', 'Above default minute to hour threshold');
  38444. // Hours to days threshold
  38445. a = moment();
  38446. a.subtract(21, 'hours');
  38447. assert.equal(a.fromNow(), '21 hours ago', 'Below default hours to day threshold');
  38448. a.subtract(1, 'hours');
  38449. assert.equal(a.fromNow(), 'a day ago', 'Above default hours to day threshold');
  38450. // Days to month threshold
  38451. a = moment();
  38452. a.subtract(25, 'days');
  38453. assert.equal(a.fromNow(), '25 days ago', 'Below default days to month (singular) threshold');
  38454. a.subtract(1, 'days');
  38455. assert.equal(a.fromNow(), 'a month ago', 'Above default days to month (singular) threshold');
  38456. // months to year threshold
  38457. a = moment();
  38458. a.subtract(10, 'months');
  38459. assert.equal(a.fromNow(), '10 months ago', 'Below default days to years threshold');
  38460. a.subtract(1, 'month');
  38461. assert.equal(a.fromNow(), 'a year ago', 'Above default days to years threshold');
  38462. });
  38463. test('default thresholds toNow', function (assert) {
  38464. var a = moment();
  38465. // Seconds to minutes threshold
  38466. a.subtract(44, 'seconds');
  38467. assert.equal(a.toNow(), 'in a few seconds', 'Below default seconds to minutes threshold');
  38468. a.subtract(1, 'seconds');
  38469. assert.equal(a.toNow(), 'in a minute', 'Above default seconds to minutes threshold');
  38470. // Minutes to hours threshold
  38471. a = moment();
  38472. a.subtract(44, 'minutes');
  38473. assert.equal(a.toNow(), 'in 44 minutes', 'Below default minute to hour threshold');
  38474. a.subtract(1, 'minutes');
  38475. assert.equal(a.toNow(), 'in an hour', 'Above default minute to hour threshold');
  38476. // Hours to days threshold
  38477. a = moment();
  38478. a.subtract(21, 'hours');
  38479. assert.equal(a.toNow(), 'in 21 hours', 'Below default hours to day threshold');
  38480. a.subtract(1, 'hours');
  38481. assert.equal(a.toNow(), 'in a day', 'Above default hours to day threshold');
  38482. // Days to month threshold
  38483. a = moment();
  38484. a.subtract(25, 'days');
  38485. assert.equal(a.toNow(), 'in 25 days', 'Below default days to month (singular) threshold');
  38486. a.subtract(1, 'days');
  38487. assert.equal(a.toNow(), 'in a month', 'Above default days to month (singular) threshold');
  38488. // months to year threshold
  38489. a = moment();
  38490. a.subtract(10, 'months');
  38491. assert.equal(a.toNow(), 'in 10 months', 'Below default days to years threshold');
  38492. a.subtract(1, 'month');
  38493. assert.equal(a.toNow(), 'in a year', 'Above default days to years threshold');
  38494. });
  38495. test('custom thresholds', function (assert) {
  38496. var a;
  38497. // Seconds to minute threshold, under 30
  38498. moment.relativeTimeThreshold('s', 25);
  38499. a = moment();
  38500. a.subtract(24, 'seconds');
  38501. assert.equal(a.fromNow(), 'a few seconds ago', 'Below custom seconds to minute threshold, s < 30');
  38502. a.subtract(1, 'seconds');
  38503. assert.equal(a.fromNow(), 'a minute ago', 'Above custom seconds to minute threshold, s < 30');
  38504. // Seconds to minutes threshold
  38505. moment.relativeTimeThreshold('s', 55);
  38506. a = moment();
  38507. a.subtract(54, 'seconds');
  38508. assert.equal(a.fromNow(), 'a few seconds ago', 'Below custom seconds to minutes threshold');
  38509. a.subtract(1, 'seconds');
  38510. assert.equal(a.fromNow(), 'a minute ago', 'Above custom seconds to minutes threshold');
  38511. moment.relativeTimeThreshold('s', 45);
  38512. // Minutes to hours threshold
  38513. moment.relativeTimeThreshold('m', 55);
  38514. a = moment();
  38515. a.subtract(54, 'minutes');
  38516. assert.equal(a.fromNow(), '54 minutes ago', 'Below custom minutes to hours threshold');
  38517. a.subtract(1, 'minutes');
  38518. assert.equal(a.fromNow(), 'an hour ago', 'Above custom minutes to hours threshold');
  38519. moment.relativeTimeThreshold('m', 45);
  38520. // Hours to days threshold
  38521. moment.relativeTimeThreshold('h', 24);
  38522. a = moment();
  38523. a.subtract(23, 'hours');
  38524. assert.equal(a.fromNow(), '23 hours ago', 'Below custom hours to days threshold');
  38525. a.subtract(1, 'hours');
  38526. assert.equal(a.fromNow(), 'a day ago', 'Above custom hours to days threshold');
  38527. moment.relativeTimeThreshold('h', 22);
  38528. // Days to month threshold
  38529. moment.relativeTimeThreshold('d', 28);
  38530. a = moment();
  38531. a.subtract(27, 'days');
  38532. assert.equal(a.fromNow(), '27 days ago', 'Below custom days to month (singular) threshold');
  38533. a.subtract(1, 'days');
  38534. assert.equal(a.fromNow(), 'a month ago', 'Above custom days to month (singular) threshold');
  38535. moment.relativeTimeThreshold('d', 26);
  38536. // months to years threshold
  38537. moment.relativeTimeThreshold('M', 9);
  38538. a = moment();
  38539. a.subtract(8, 'months');
  38540. assert.equal(a.fromNow(), '8 months ago', 'Below custom days to years threshold');
  38541. a.subtract(1, 'months');
  38542. assert.equal(a.fromNow(), 'a year ago', 'Above custom days to years threshold');
  38543. moment.relativeTimeThreshold('M', 11);
  38544. });
  38545. test('retrive threshold settings', function (assert) {
  38546. moment.relativeTimeThreshold('m', 45);
  38547. var minuteThreshold = moment.relativeTimeThreshold('m');
  38548. assert.equal(minuteThreshold, 45, 'Can retrieve minute setting');
  38549. });
  38550. }));
  38551. ;(function (global, factory) {
  38552. typeof exports === 'object' && typeof module !== 'undefined'
  38553. && typeof require === 'function' ? factory(require('../../moment')) :
  38554. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  38555. factory(global.moment)
  38556. }(this, function (moment) { 'use strict';
  38557. /*global QUnit:false*/
  38558. var test = QUnit.test;
  38559. var expect = QUnit.expect;
  38560. function module (name, lifecycle) {
  38561. QUnit.module(name, {
  38562. setup : function () {
  38563. moment.locale('en');
  38564. moment.createFromInputFallback = function (config) {
  38565. throw new Error('input not handled by moment: ' + config._i);
  38566. };
  38567. if (lifecycle && lifecycle.setup) {
  38568. lifecycle.setup();
  38569. }
  38570. },
  38571. teardown : function () {
  38572. if (lifecycle && lifecycle.teardown) {
  38573. lifecycle.teardown();
  38574. }
  38575. }
  38576. });
  38577. }
  38578. function localeModule (name, lifecycle) {
  38579. QUnit.module('locale:' + name, {
  38580. setup : function () {
  38581. moment.locale(name);
  38582. moment.createFromInputFallback = function (config) {
  38583. throw new Error('input not handled by moment: ' + config._i);
  38584. };
  38585. if (lifecycle && lifecycle.setup) {
  38586. lifecycle.setup();
  38587. }
  38588. },
  38589. teardown : function () {
  38590. moment.locale('en');
  38591. if (lifecycle && lifecycle.teardown) {
  38592. lifecycle.teardown();
  38593. }
  38594. }
  38595. });
  38596. }
  38597. module('start and end of units');
  38598. test('start of year', function (assert) {
  38599. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('year'),
  38600. ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('years'),
  38601. ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('y');
  38602. assert.equal(+m, +ms, 'Plural or singular should work');
  38603. assert.equal(+m, +ma, 'Full or abbreviated should work');
  38604. assert.equal(m.year(), 2011, 'keep the year');
  38605. assert.equal(m.month(), 0, 'strip out the month');
  38606. assert.equal(m.date(), 1, 'strip out the day');
  38607. assert.equal(m.hours(), 0, 'strip out the hours');
  38608. assert.equal(m.minutes(), 0, 'strip out the minutes');
  38609. assert.equal(m.seconds(), 0, 'strip out the seconds');
  38610. assert.equal(m.milliseconds(), 0, 'strip out the milliseconds');
  38611. });
  38612. test('end of year', function (assert) {
  38613. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('year'),
  38614. ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('years'),
  38615. ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('y');
  38616. assert.equal(+m, +ms, 'Plural or singular should work');
  38617. assert.equal(+m, +ma, 'Full or abbreviated should work');
  38618. assert.equal(m.year(), 2011, 'keep the year');
  38619. assert.equal(m.month(), 11, 'set the month');
  38620. assert.equal(m.date(), 31, 'set the day');
  38621. assert.equal(m.hours(), 23, 'set the hours');
  38622. assert.equal(m.minutes(), 59, 'set the minutes');
  38623. assert.equal(m.seconds(), 59, 'set the seconds');
  38624. assert.equal(m.milliseconds(), 999, 'set the seconds');
  38625. });
  38626. test('start of quarter', function (assert) {
  38627. var m = moment(new Date(2011, 4, 2, 3, 4, 5, 6)).startOf('quarter'),
  38628. ms = moment(new Date(2011, 4, 2, 3, 4, 5, 6)).startOf('quarters'),
  38629. ma = moment(new Date(2011, 4, 2, 3, 4, 5, 6)).startOf('Q');
  38630. assert.equal(+m, +ms, 'Plural or singular should work');
  38631. assert.equal(+m, +ma, 'Full or abbreviated should work');
  38632. assert.equal(m.year(), 2011, 'keep the year');
  38633. assert.equal(m.quarter(), 2, 'keep the quarter');
  38634. assert.equal(m.month(), 3, 'strip out the month');
  38635. assert.equal(m.date(), 1, 'strip out the day');
  38636. assert.equal(m.hours(), 0, 'strip out the hours');
  38637. assert.equal(m.minutes(), 0, 'strip out the minutes');
  38638. assert.equal(m.seconds(), 0, 'strip out the seconds');
  38639. assert.equal(m.milliseconds(), 0, 'strip out the milliseconds');
  38640. });
  38641. test('end of quarter', function (assert) {
  38642. var m = moment(new Date(2011, 4, 2, 3, 4, 5, 6)).endOf('quarter'),
  38643. ms = moment(new Date(2011, 4, 2, 3, 4, 5, 6)).endOf('quarters'),
  38644. ma = moment(new Date(2011, 4, 2, 3, 4, 5, 6)).endOf('Q');
  38645. assert.equal(+m, +ms, 'Plural or singular should work');
  38646. assert.equal(+m, +ma, 'Full or abbreviated should work');
  38647. assert.equal(m.year(), 2011, 'keep the year');
  38648. assert.equal(m.quarter(), 2, 'keep the quarter');
  38649. assert.equal(m.month(), 5, 'set the month');
  38650. assert.equal(m.date(), 30, 'set the day');
  38651. assert.equal(m.hours(), 23, 'set the hours');
  38652. assert.equal(m.minutes(), 59, 'set the minutes');
  38653. assert.equal(m.seconds(), 59, 'set the seconds');
  38654. assert.equal(m.milliseconds(), 999, 'set the seconds');
  38655. });
  38656. test('start of month', function (assert) {
  38657. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('month'),
  38658. ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('months'),
  38659. ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('M');
  38660. assert.equal(+m, +ms, 'Plural or singular should work');
  38661. assert.equal(+m, +ma, 'Full or abbreviated should work');
  38662. assert.equal(m.year(), 2011, 'keep the year');
  38663. assert.equal(m.month(), 1, 'keep the month');
  38664. assert.equal(m.date(), 1, 'strip out the day');
  38665. assert.equal(m.hours(), 0, 'strip out the hours');
  38666. assert.equal(m.minutes(), 0, 'strip out the minutes');
  38667. assert.equal(m.seconds(), 0, 'strip out the seconds');
  38668. assert.equal(m.milliseconds(), 0, 'strip out the milliseconds');
  38669. });
  38670. test('end of month', function (assert) {
  38671. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('month'),
  38672. ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('months'),
  38673. ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('M');
  38674. assert.equal(+m, +ms, 'Plural or singular should work');
  38675. assert.equal(+m, +ma, 'Full or abbreviated should work');
  38676. assert.equal(m.year(), 2011, 'keep the year');
  38677. assert.equal(m.month(), 1, 'keep the month');
  38678. assert.equal(m.date(), 28, 'set the day');
  38679. assert.equal(m.hours(), 23, 'set the hours');
  38680. assert.equal(m.minutes(), 59, 'set the minutes');
  38681. assert.equal(m.seconds(), 59, 'set the seconds');
  38682. assert.equal(m.milliseconds(), 999, 'set the seconds');
  38683. });
  38684. test('start of week', function (assert) {
  38685. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('week'),
  38686. ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('weeks'),
  38687. ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('w');
  38688. assert.equal(+m, +ms, 'Plural or singular should work');
  38689. assert.equal(+m, +ma, 'Full or abbreviated should work');
  38690. assert.equal(m.year(), 2011, 'keep the year');
  38691. assert.equal(m.month(), 0, 'rolls back to January');
  38692. assert.equal(m.day(), 0, 'set day of week');
  38693. assert.equal(m.date(), 30, 'set correct date');
  38694. assert.equal(m.hours(), 0, 'strip out the hours');
  38695. assert.equal(m.minutes(), 0, 'strip out the minutes');
  38696. assert.equal(m.seconds(), 0, 'strip out the seconds');
  38697. assert.equal(m.milliseconds(), 0, 'strip out the milliseconds');
  38698. });
  38699. test('end of week', function (assert) {
  38700. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('week'),
  38701. ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('weeks'),
  38702. ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('weeks');
  38703. assert.equal(+m, +ms, 'Plural or singular should work');
  38704. assert.equal(+m, +ma, 'Full or abbreviated should work');
  38705. assert.equal(m.year(), 2011, 'keep the year');
  38706. assert.equal(m.month(), 1, 'keep the month');
  38707. assert.equal(m.day(), 6, 'set the day of the week');
  38708. assert.equal(m.date(), 5, 'set the day');
  38709. assert.equal(m.hours(), 23, 'set the hours');
  38710. assert.equal(m.minutes(), 59, 'set the minutes');
  38711. assert.equal(m.seconds(), 59, 'set the seconds');
  38712. assert.equal(m.milliseconds(), 999, 'set the seconds');
  38713. });
  38714. test('start of iso-week', function (assert) {
  38715. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('isoWeek'),
  38716. ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('isoWeeks'),
  38717. ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('W');
  38718. assert.equal(+m, +ms, 'Plural or singular should work');
  38719. assert.equal(+m, +ma, 'Full or abbreviated should work');
  38720. assert.equal(m.year(), 2011, 'keep the year');
  38721. assert.equal(m.month(), 0, 'rollback to January');
  38722. assert.equal(m.isoWeekday(), 1, 'set day of iso-week');
  38723. assert.equal(m.date(), 31, 'set correct date');
  38724. assert.equal(m.hours(), 0, 'strip out the hours');
  38725. assert.equal(m.minutes(), 0, 'strip out the minutes');
  38726. assert.equal(m.seconds(), 0, 'strip out the seconds');
  38727. assert.equal(m.milliseconds(), 0, 'strip out the milliseconds');
  38728. });
  38729. test('end of iso-week', function (assert) {
  38730. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('isoWeek'),
  38731. ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('isoWeeks'),
  38732. ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('W');
  38733. assert.equal(+m, +ms, 'Plural or singular should work');
  38734. assert.equal(+m, +ma, 'Full or abbreviated should work');
  38735. assert.equal(m.year(), 2011, 'keep the year');
  38736. assert.equal(m.month(), 1, 'keep the month');
  38737. assert.equal(m.isoWeekday(), 7, 'set the day of the week');
  38738. assert.equal(m.date(), 6, 'set the day');
  38739. assert.equal(m.hours(), 23, 'set the hours');
  38740. assert.equal(m.minutes(), 59, 'set the minutes');
  38741. assert.equal(m.seconds(), 59, 'set the seconds');
  38742. assert.equal(m.milliseconds(), 999, 'set the seconds');
  38743. });
  38744. test('start of day', function (assert) {
  38745. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('day'),
  38746. ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('days'),
  38747. ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('d');
  38748. assert.equal(+m, +ms, 'Plural or singular should work');
  38749. assert.equal(+m, +ma, 'Full or abbreviated should work');
  38750. assert.equal(m.year(), 2011, 'keep the year');
  38751. assert.equal(m.month(), 1, 'keep the month');
  38752. assert.equal(m.date(), 2, 'keep the day');
  38753. assert.equal(m.hours(), 0, 'strip out the hours');
  38754. assert.equal(m.minutes(), 0, 'strip out the minutes');
  38755. assert.equal(m.seconds(), 0, 'strip out the seconds');
  38756. assert.equal(m.milliseconds(), 0, 'strip out the milliseconds');
  38757. });
  38758. test('end of day', function (assert) {
  38759. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('day'),
  38760. ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('days'),
  38761. ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('d');
  38762. assert.equal(+m, +ms, 'Plural or singular should work');
  38763. assert.equal(+m, +ma, 'Full or abbreviated should work');
  38764. assert.equal(m.year(), 2011, 'keep the year');
  38765. assert.equal(m.month(), 1, 'keep the month');
  38766. assert.equal(m.date(), 2, 'keep the day');
  38767. assert.equal(m.hours(), 23, 'set the hours');
  38768. assert.equal(m.minutes(), 59, 'set the minutes');
  38769. assert.equal(m.seconds(), 59, 'set the seconds');
  38770. assert.equal(m.milliseconds(), 999, 'set the seconds');
  38771. });
  38772. test('start of hour', function (assert) {
  38773. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('hour'),
  38774. ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('hours'),
  38775. ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('h');
  38776. assert.equal(+m, +ms, 'Plural or singular should work');
  38777. assert.equal(+m, +ma, 'Full or abbreviated should work');
  38778. assert.equal(m.year(), 2011, 'keep the year');
  38779. assert.equal(m.month(), 1, 'keep the month');
  38780. assert.equal(m.date(), 2, 'keep the day');
  38781. assert.equal(m.hours(), 3, 'keep the hours');
  38782. assert.equal(m.minutes(), 0, 'strip out the minutes');
  38783. assert.equal(m.seconds(), 0, 'strip out the seconds');
  38784. assert.equal(m.milliseconds(), 0, 'strip out the milliseconds');
  38785. });
  38786. test('end of hour', function (assert) {
  38787. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('hour'),
  38788. ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('hours'),
  38789. ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('h');
  38790. assert.equal(+m, +ms, 'Plural or singular should work');
  38791. assert.equal(+m, +ma, 'Full or abbreviated should work');
  38792. assert.equal(m.year(), 2011, 'keep the year');
  38793. assert.equal(m.month(), 1, 'keep the month');
  38794. assert.equal(m.date(), 2, 'keep the day');
  38795. assert.equal(m.hours(), 3, 'keep the hours');
  38796. assert.equal(m.minutes(), 59, 'set the minutes');
  38797. assert.equal(m.seconds(), 59, 'set the seconds');
  38798. assert.equal(m.milliseconds(), 999, 'set the seconds');
  38799. });
  38800. test('start of minute', function (assert) {
  38801. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('minute'),
  38802. ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('minutes'),
  38803. ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('m');
  38804. assert.equal(+m, +ms, 'Plural or singular should work');
  38805. assert.equal(+m, +ma, 'Full or abbreviated should work');
  38806. assert.equal(m.year(), 2011, 'keep the year');
  38807. assert.equal(m.month(), 1, 'keep the month');
  38808. assert.equal(m.date(), 2, 'keep the day');
  38809. assert.equal(m.hours(), 3, 'keep the hours');
  38810. assert.equal(m.minutes(), 4, 'keep the minutes');
  38811. assert.equal(m.seconds(), 0, 'strip out the seconds');
  38812. assert.equal(m.milliseconds(), 0, 'strip out the milliseconds');
  38813. });
  38814. test('end of minute', function (assert) {
  38815. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('minute'),
  38816. ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('minutes'),
  38817. ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('m');
  38818. assert.equal(+m, +ms, 'Plural or singular should work');
  38819. assert.equal(+m, +ma, 'Full or abbreviated should work');
  38820. assert.equal(m.year(), 2011, 'keep the year');
  38821. assert.equal(m.month(), 1, 'keep the month');
  38822. assert.equal(m.date(), 2, 'keep the day');
  38823. assert.equal(m.hours(), 3, 'keep the hours');
  38824. assert.equal(m.minutes(), 4, 'keep the minutes');
  38825. assert.equal(m.seconds(), 59, 'set the seconds');
  38826. assert.equal(m.milliseconds(), 999, 'set the seconds');
  38827. });
  38828. test('start of second', function (assert) {
  38829. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('second'),
  38830. ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('seconds'),
  38831. ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('s');
  38832. assert.equal(+m, +ms, 'Plural or singular should work');
  38833. assert.equal(+m, +ma, 'Full or abbreviated should work');
  38834. assert.equal(m.year(), 2011, 'keep the year');
  38835. assert.equal(m.month(), 1, 'keep the month');
  38836. assert.equal(m.date(), 2, 'keep the day');
  38837. assert.equal(m.hours(), 3, 'keep the hours');
  38838. assert.equal(m.minutes(), 4, 'keep the minutes');
  38839. assert.equal(m.seconds(), 5, 'keep the the seconds');
  38840. assert.equal(m.milliseconds(), 0, 'strip out the milliseconds');
  38841. });
  38842. test('end of second', function (assert) {
  38843. var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('second'),
  38844. ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('seconds'),
  38845. ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('s');
  38846. assert.equal(+m, +ms, 'Plural or singular should work');
  38847. assert.equal(+m, +ma, 'Full or abbreviated should work');
  38848. assert.equal(m.year(), 2011, 'keep the year');
  38849. assert.equal(m.month(), 1, 'keep the month');
  38850. assert.equal(m.date(), 2, 'keep the day');
  38851. assert.equal(m.hours(), 3, 'keep the hours');
  38852. assert.equal(m.minutes(), 4, 'keep the minutes');
  38853. assert.equal(m.seconds(), 5, 'keep the seconds');
  38854. assert.equal(m.milliseconds(), 999, 'set the seconds');
  38855. });
  38856. test('startOf across DST +1', function (assert) {
  38857. var oldUpdateOffset = moment.updateOffset,
  38858. // Based on a real story somewhere in America/Los_Angeles
  38859. dstAt = moment('2014-03-09T02:00:00-08:00').parseZone(),
  38860. m;
  38861. moment.updateOffset = function (mom, keepTime) {
  38862. if (mom.isBefore(dstAt)) {
  38863. mom.utcOffset(-8, keepTime);
  38864. } else {
  38865. mom.utcOffset(-7, keepTime);
  38866. }
  38867. };
  38868. m = moment('2014-03-15T00:00:00-07:00').parseZone();
  38869. m.startOf('M');
  38870. assert.equal(m.format(), '2014-03-01T00:00:00-08:00', 'startOf(\'month\') across +1');
  38871. m = moment('2014-03-09T09:00:00-07:00').parseZone();
  38872. m.startOf('d');
  38873. assert.equal(m.format(), '2014-03-09T00:00:00-08:00', 'startOf(\'day\') across +1');
  38874. m = moment('2014-03-09T03:05:00-07:00').parseZone();
  38875. m.startOf('h');
  38876. assert.equal(m.format(), '2014-03-09T03:00:00-07:00', 'startOf(\'hour\') after +1');
  38877. m = moment('2014-03-09T01:35:00-08:00').parseZone();
  38878. m.startOf('h');
  38879. assert.equal(m.format(), '2014-03-09T01:00:00-08:00', 'startOf(\'hour\') before +1');
  38880. // There is no such time as 2:30-7 to try startOf('hour') across that
  38881. moment.updateOffset = oldUpdateOffset;
  38882. });
  38883. test('startOf across DST -1', function (assert) {
  38884. var oldUpdateOffset = moment.updateOffset,
  38885. // Based on a real story somewhere in America/Los_Angeles
  38886. dstAt = moment('2014-11-02T02:00:00-07:00').parseZone(),
  38887. m;
  38888. moment.updateOffset = function (mom, keepTime) {
  38889. if (mom.isBefore(dstAt)) {
  38890. mom.utcOffset(-7, keepTime);
  38891. } else {
  38892. mom.utcOffset(-8, keepTime);
  38893. }
  38894. };
  38895. m = moment('2014-11-15T00:00:00-08:00').parseZone();
  38896. m.startOf('M');
  38897. assert.equal(m.format(), '2014-11-01T00:00:00-07:00', 'startOf(\'month\') across -1');
  38898. m = moment('2014-11-02T09:00:00-08:00').parseZone();
  38899. m.startOf('d');
  38900. assert.equal(m.format(), '2014-11-02T00:00:00-07:00', 'startOf(\'day\') across -1');
  38901. // note that utc offset is -8
  38902. m = moment('2014-11-02T01:30:00-08:00').parseZone();
  38903. m.startOf('h');
  38904. assert.equal(m.format(), '2014-11-02T01:00:00-08:00', 'startOf(\'hour\') after +1');
  38905. // note that utc offset is -7
  38906. m = moment('2014-11-02T01:30:00-07:00').parseZone();
  38907. m.startOf('h');
  38908. assert.equal(m.format(), '2014-11-02T01:00:00-07:00', 'startOf(\'hour\') before +1');
  38909. moment.updateOffset = oldUpdateOffset;
  38910. });
  38911. test('endOf millisecond and no-arg', function (assert) {
  38912. var m = moment();
  38913. assert.equal(+m, +m.clone().endOf(), 'endOf without argument should change time');
  38914. assert.equal(+m, +m.clone().endOf('ms'), 'endOf with ms argument should change time');
  38915. assert.equal(+m, +m.clone().endOf('millisecond'), 'endOf with millisecond argument should change time');
  38916. assert.equal(+m, +m.clone().endOf('milliseconds'), 'endOf with milliseconds argument should change time');
  38917. });
  38918. }));
  38919. ;(function (global, factory) {
  38920. typeof exports === 'object' && typeof module !== 'undefined'
  38921. && typeof require === 'function' ? factory(require('../../moment')) :
  38922. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  38923. factory(global.moment)
  38924. }(this, function (moment) { 'use strict';
  38925. /*global QUnit:false*/
  38926. var test = QUnit.test;
  38927. var expect = QUnit.expect;
  38928. function module (name, lifecycle) {
  38929. QUnit.module(name, {
  38930. setup : function () {
  38931. moment.locale('en');
  38932. moment.createFromInputFallback = function (config) {
  38933. throw new Error('input not handled by moment: ' + config._i);
  38934. };
  38935. if (lifecycle && lifecycle.setup) {
  38936. lifecycle.setup();
  38937. }
  38938. },
  38939. teardown : function () {
  38940. if (lifecycle && lifecycle.teardown) {
  38941. lifecycle.teardown();
  38942. }
  38943. }
  38944. });
  38945. }
  38946. function localeModule (name, lifecycle) {
  38947. QUnit.module('locale:' + name, {
  38948. setup : function () {
  38949. moment.locale(name);
  38950. moment.createFromInputFallback = function (config) {
  38951. throw new Error('input not handled by moment: ' + config._i);
  38952. };
  38953. if (lifecycle && lifecycle.setup) {
  38954. lifecycle.setup();
  38955. }
  38956. },
  38957. teardown : function () {
  38958. moment.locale('en');
  38959. if (lifecycle && lifecycle.teardown) {
  38960. lifecycle.teardown();
  38961. }
  38962. }
  38963. });
  38964. }
  38965. module('string prototype');
  38966. test('string prototype overrides call', function (assert) {
  38967. var prior = String.prototype.call, b;
  38968. String.prototype.call = function () {
  38969. return null;
  38970. };
  38971. b = moment(new Date(2011, 7, 28, 15, 25, 50, 125));
  38972. assert.equal(b.format('MMMM Do YYYY, h:mm a'), 'August 28th 2011, 3:25 pm');
  38973. String.prototype.call = prior;
  38974. });
  38975. }));
  38976. ;(function (global, factory) {
  38977. typeof exports === 'object' && typeof module !== 'undefined'
  38978. && typeof require === 'function' ? factory(require('../../moment')) :
  38979. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  38980. factory(global.moment)
  38981. }(this, function (moment) { 'use strict';
  38982. /*global QUnit:false*/
  38983. var test = QUnit.test;
  38984. var expect = QUnit.expect;
  38985. function module (name, lifecycle) {
  38986. QUnit.module(name, {
  38987. setup : function () {
  38988. moment.locale('en');
  38989. moment.createFromInputFallback = function (config) {
  38990. throw new Error('input not handled by moment: ' + config._i);
  38991. };
  38992. if (lifecycle && lifecycle.setup) {
  38993. lifecycle.setup();
  38994. }
  38995. },
  38996. teardown : function () {
  38997. if (lifecycle && lifecycle.teardown) {
  38998. lifecycle.teardown();
  38999. }
  39000. }
  39001. });
  39002. }
  39003. function localeModule (name, lifecycle) {
  39004. QUnit.module('locale:' + name, {
  39005. setup : function () {
  39006. moment.locale(name);
  39007. moment.createFromInputFallback = function (config) {
  39008. throw new Error('input not handled by moment: ' + config._i);
  39009. };
  39010. if (lifecycle && lifecycle.setup) {
  39011. lifecycle.setup();
  39012. }
  39013. },
  39014. teardown : function () {
  39015. moment.locale('en');
  39016. if (lifecycle && lifecycle.teardown) {
  39017. lifecycle.teardown();
  39018. }
  39019. }
  39020. });
  39021. }
  39022. module('to type');
  39023. test('toObject', function (assert) {
  39024. var expected = {
  39025. years:2010,
  39026. months:3,
  39027. date:5,
  39028. hours:15,
  39029. minutes:10,
  39030. seconds:3,
  39031. milliseconds:123
  39032. };
  39033. assert.deepEqual(moment(expected).toObject(), expected, 'toObject invalid');
  39034. });
  39035. test('toArray', function (assert) {
  39036. var expected = [2014, 11, 26, 11, 46, 58, 17];
  39037. assert.deepEqual(moment(expected).toArray(), expected, 'toArray invalid');
  39038. });
  39039. }));
  39040. ;(function (global, factory) {
  39041. typeof exports === 'object' && typeof module !== 'undefined'
  39042. && typeof require === 'function' ? factory(require('../../moment')) :
  39043. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  39044. factory(global.moment)
  39045. }(this, function (moment) { 'use strict';
  39046. /*global QUnit:false*/
  39047. var test = QUnit.test;
  39048. var expect = QUnit.expect;
  39049. function module (name, lifecycle) {
  39050. QUnit.module(name, {
  39051. setup : function () {
  39052. moment.locale('en');
  39053. moment.createFromInputFallback = function (config) {
  39054. throw new Error('input not handled by moment: ' + config._i);
  39055. };
  39056. if (lifecycle && lifecycle.setup) {
  39057. lifecycle.setup();
  39058. }
  39059. },
  39060. teardown : function () {
  39061. if (lifecycle && lifecycle.teardown) {
  39062. lifecycle.teardown();
  39063. }
  39064. }
  39065. });
  39066. }
  39067. function localeModule (name, lifecycle) {
  39068. QUnit.module('locale:' + name, {
  39069. setup : function () {
  39070. moment.locale(name);
  39071. moment.createFromInputFallback = function (config) {
  39072. throw new Error('input not handled by moment: ' + config._i);
  39073. };
  39074. if (lifecycle && lifecycle.setup) {
  39075. lifecycle.setup();
  39076. }
  39077. },
  39078. teardown : function () {
  39079. moment.locale('en');
  39080. if (lifecycle && lifecycle.teardown) {
  39081. lifecycle.teardown();
  39082. }
  39083. }
  39084. });
  39085. }
  39086. module('utc');
  39087. test('utc and local', function (assert) {
  39088. var m = moment(Date.UTC(2011, 1, 2, 3, 4, 5, 6)), offset, expected;
  39089. m.utc();
  39090. // utc
  39091. assert.equal(m.date(), 2, 'the day should be correct for utc');
  39092. assert.equal(m.day(), 3, 'the date should be correct for utc');
  39093. assert.equal(m.hours(), 3, 'the hours should be correct for utc');
  39094. // local
  39095. m.local();
  39096. if (m.zone() > 180) {
  39097. assert.equal(m.date(), 1, 'the date should be correct for local');
  39098. assert.equal(m.day(), 2, 'the day should be correct for local');
  39099. } else {
  39100. assert.equal(m.date(), 2, 'the date should be correct for local');
  39101. assert.equal(m.day(), 3, 'the day should be correct for local');
  39102. }
  39103. offset = Math.floor(m.utcOffset() / 60);
  39104. expected = (24 + 3 + offset) % 24;
  39105. assert.equal(m.hours(), expected, 'the hours (' + m.hours() + ') should be correct for local');
  39106. assert.equal(moment().utc().utcOffset(), 0, 'timezone in utc should always be zero');
  39107. });
  39108. test('creating with utc and no arguments', function (assert) {
  39109. var startOfTest = new Date().valueOf(),
  39110. momentDefaultUtcTime = moment.utc().valueOf(),
  39111. afterMomentCreationTime = new Date().valueOf();
  39112. assert.ok(startOfTest <= momentDefaultUtcTime, 'moment UTC default time should be now, not in the past');
  39113. assert.ok(momentDefaultUtcTime <= afterMomentCreationTime, 'moment UTC default time should be now, not in the future');
  39114. });
  39115. test('creating with utc and a date parameter array', function (assert) {
  39116. var m = moment.utc([2011, 1, 2, 3, 4, 5, 6]);
  39117. assert.equal(m.date(), 2, 'the day should be correct for utc array');
  39118. assert.equal(m.hours(), 3, 'the hours should be correct for utc array');
  39119. m = moment.utc('2011-02-02 3:04:05', 'YYYY-MM-DD HH:mm:ss');
  39120. assert.equal(m.date(), 2, 'the day should be correct for utc parsing format');
  39121. assert.equal(m.hours(), 3, 'the hours should be correct for utc parsing format');
  39122. m = moment.utc('2011-02-02T03:04:05+00:00');
  39123. assert.equal(m.date(), 2, 'the day should be correct for utc parsing iso');
  39124. assert.equal(m.hours(), 3, 'the hours should be correct for utc parsing iso');
  39125. });
  39126. test('creating with utc without timezone', function (assert) {
  39127. var m = moment.utc('2012-01-02T08:20:00');
  39128. assert.equal(m.date(), 2, 'the day should be correct for utc parse without timezone');
  39129. assert.equal(m.hours(), 8, 'the hours should be correct for utc parse without timezone');
  39130. m = moment.utc('2012-01-02T08:20:00+09:00');
  39131. assert.equal(m.date(), 1, 'the day should be correct for utc parse with timezone');
  39132. assert.equal(m.hours(), 23, 'the hours should be correct for utc parse with timezone');
  39133. });
  39134. test('cloning with utc offset', function (assert) {
  39135. var m = moment.utc('2012-01-02T08:20:00');
  39136. assert.equal(moment.utc(m)._isUTC, true, 'the local offset should be converted to UTC');
  39137. assert.equal(moment.utc(m.clone().utc())._isUTC, true, 'the local offset should stay in UTC');
  39138. m.utcOffset(120);
  39139. assert.equal(moment.utc(m)._isUTC, true, 'the explicit utc offset should stay in UTC');
  39140. assert.equal(moment.utc(m).utcOffset(), 0, 'the explicit utc offset should have an offset of 0');
  39141. });
  39142. test('weekday with utc', function (assert) {
  39143. assert.equal(
  39144. moment('2013-09-15T00:00:00Z').utc().weekday(), // first minute of the day
  39145. moment('2013-09-15T23:59:00Z').utc().weekday(), // last minute of the day
  39146. 'a UTC-moment\'s .weekday() should not be affected by the local timezone'
  39147. );
  39148. });
  39149. }));
  39150. ;(function (global, factory) {
  39151. typeof exports === 'object' && typeof module !== 'undefined'
  39152. && typeof require === 'function' ? factory(require('../../moment')) :
  39153. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  39154. factory(global.moment)
  39155. }(this, function (moment) { 'use strict';
  39156. /*global QUnit:false*/
  39157. var test = QUnit.test;
  39158. var expect = QUnit.expect;
  39159. function module (name, lifecycle) {
  39160. QUnit.module(name, {
  39161. setup : function () {
  39162. moment.locale('en');
  39163. moment.createFromInputFallback = function (config) {
  39164. throw new Error('input not handled by moment: ' + config._i);
  39165. };
  39166. if (lifecycle && lifecycle.setup) {
  39167. lifecycle.setup();
  39168. }
  39169. },
  39170. teardown : function () {
  39171. if (lifecycle && lifecycle.teardown) {
  39172. lifecycle.teardown();
  39173. }
  39174. }
  39175. });
  39176. }
  39177. function localeModule (name, lifecycle) {
  39178. QUnit.module('locale:' + name, {
  39179. setup : function () {
  39180. moment.locale(name);
  39181. moment.createFromInputFallback = function (config) {
  39182. throw new Error('input not handled by moment: ' + config._i);
  39183. };
  39184. if (lifecycle && lifecycle.setup) {
  39185. lifecycle.setup();
  39186. }
  39187. },
  39188. teardown : function () {
  39189. moment.locale('en');
  39190. if (lifecycle && lifecycle.teardown) {
  39191. lifecycle.teardown();
  39192. }
  39193. }
  39194. });
  39195. }
  39196. module('utc offset');
  39197. test('setter / getter blackbox', function (assert) {
  39198. var m = moment([2010]);
  39199. assert.equal(m.clone().utcOffset(0).utcOffset(), 0, 'utcOffset 0');
  39200. assert.equal(m.clone().utcOffset(1).utcOffset(), 60, 'utcOffset 1 is 60');
  39201. assert.equal(m.clone().utcOffset(60).utcOffset(), 60, 'utcOffset 60');
  39202. assert.equal(m.clone().utcOffset('+01:00').utcOffset(), 60, 'utcOffset +01:00 is 60');
  39203. assert.equal(m.clone().utcOffset('+0100').utcOffset(), 60, 'utcOffset +0100 is 60');
  39204. assert.equal(m.clone().utcOffset(-1).utcOffset(), -60, 'utcOffset -1 is -60');
  39205. assert.equal(m.clone().utcOffset(-60).utcOffset(), -60, 'utcOffset -60');
  39206. assert.equal(m.clone().utcOffset('-01:00').utcOffset(), -60, 'utcOffset -01:00 is -60');
  39207. assert.equal(m.clone().utcOffset('-0100').utcOffset(), -60, 'utcOffset -0100 is -60');
  39208. assert.equal(m.clone().utcOffset(1.5).utcOffset(), 90, 'utcOffset 1.5 is 90');
  39209. assert.equal(m.clone().utcOffset(90).utcOffset(), 90, 'utcOffset 1.5 is 90');
  39210. assert.equal(m.clone().utcOffset('+01:30').utcOffset(), 90, 'utcOffset +01:30 is 90');
  39211. assert.equal(m.clone().utcOffset('+0130').utcOffset(), 90, 'utcOffset +0130 is 90');
  39212. assert.equal(m.clone().utcOffset(-1.5).utcOffset(), -90, 'utcOffset -1.5');
  39213. assert.equal(m.clone().utcOffset(-90).utcOffset(), -90, 'utcOffset -90');
  39214. assert.equal(m.clone().utcOffset('-01:30').utcOffset(), -90, 'utcOffset +01:30 is 90');
  39215. assert.equal(m.clone().utcOffset('-0130').utcOffset(), -90, 'utcOffset +0130 is 90');
  39216. assert.equal(m.clone().utcOffset('+00:10').utcOffset(), 10, 'utcOffset +00:10 is 10');
  39217. assert.equal(m.clone().utcOffset('-00:10').utcOffset(), -10, 'utcOffset +00:10 is 10');
  39218. assert.equal(m.clone().utcOffset('+0010').utcOffset(), 10, 'utcOffset +0010 is 10');
  39219. assert.equal(m.clone().utcOffset('-0010').utcOffset(), -10, 'utcOffset +0010 is 10');
  39220. });
  39221. test('utcOffset shorthand hours -> minutes', function (assert) {
  39222. var i;
  39223. for (i = -15; i <= 15; ++i) {
  39224. assert.equal(moment().utcOffset(i).utcOffset(), i * 60,
  39225. '' + i + ' -> ' + i * 60);
  39226. }
  39227. assert.equal(moment().utcOffset(-16).utcOffset(), -16, '-16 -> -16');
  39228. assert.equal(moment().utcOffset(16).utcOffset(), 16, '16 -> 16');
  39229. });
  39230. test('isLocal, isUtc, isUtcOffset', function (assert) {
  39231. assert.ok(moment().isLocal(), 'moment() creates objects in local time');
  39232. assert.ok(!moment.utc().isLocal(), 'moment.utc creates objects NOT in local time');
  39233. assert.ok(moment.utc().local().isLocal(), 'moment.fn.local() converts to local time');
  39234. assert.ok(!moment().utcOffset(5).isLocal(), 'moment.fn.utcOffset(N) puts objects NOT in local time');
  39235. assert.ok(moment().utcOffset(5).local().isLocal(), 'moment.fn.local() converts to local time');
  39236. assert.ok(moment.utc().isUtc(), 'moment.utc() creates objects in utc time');
  39237. assert.ok(moment().utcOffset(0).isUtc(), 'utcOffset(0) is equivalent to utc mode');
  39238. assert.ok(!moment().utcOffset(1).isUtc(), 'utcOffset(1) is NOT equivalent to utc mode');
  39239. assert.ok(!moment().isUtcOffset(), 'moment() creates objects NOT in utc-offset mode');
  39240. assert.ok(moment.utc().isUtcOffset(), 'moment.utc() creates objects in utc-offset mode');
  39241. assert.ok(moment().utcOffset(3).isUtcOffset(), 'utcOffset(N != 0) creates objects in utc-offset mode');
  39242. assert.ok(moment().utcOffset(0).isUtcOffset(), 'utcOffset(0) creates objects in utc-offset mode');
  39243. });
  39244. test('isUTC', function (assert) {
  39245. assert.ok(moment.utc().isUTC(), 'moment.utc() creates objects in utc time');
  39246. assert.ok(moment().utcOffset(0).isUTC(), 'utcOffset(0) is equivalent to utc mode');
  39247. assert.ok(!moment().utcOffset(1).isUTC(), 'utcOffset(1) is NOT equivalent to utc mode');
  39248. });
  39249. test('change hours when changing the utc offset', function (assert) {
  39250. var m = moment.utc([2000, 0, 1, 6]);
  39251. assert.equal(m.hour(), 6, 'UTC 6AM should be 6AM at +0000');
  39252. // sanity check
  39253. m.utcOffset(0);
  39254. assert.equal(m.hour(), 6, 'UTC 6AM should be 6AM at +0000');
  39255. m.utcOffset(-60);
  39256. assert.equal(m.hour(), 5, 'UTC 6AM should be 5AM at -0100');
  39257. m.utcOffset(60);
  39258. assert.equal(m.hour(), 7, 'UTC 6AM should be 7AM at +0100');
  39259. });
  39260. test('change minutes when changing the utc offset', function (assert) {
  39261. var m = moment.utc([2000, 0, 1, 6, 31]);
  39262. m.utcOffset(0);
  39263. assert.equal(m.format('HH:mm'), '06:31', 'UTC 6:31AM should be 6:31AM at +0000');
  39264. m.utcOffset(-30);
  39265. assert.equal(m.format('HH:mm'), '06:01', 'UTC 6:31AM should be 6:01AM at -0030');
  39266. m.utcOffset(30);
  39267. assert.equal(m.format('HH:mm'), '07:01', 'UTC 6:31AM should be 7:01AM at +0030');
  39268. m.utcOffset(-1380);
  39269. assert.equal(m.format('HH:mm'), '07:31', 'UTC 6:31AM should be 7:31AM at +1380');
  39270. });
  39271. test('distance from the unix epoch', function (assert) {
  39272. var zoneA = moment(),
  39273. zoneB = moment(zoneA),
  39274. zoneC = moment(zoneA),
  39275. zoneD = moment(zoneA),
  39276. zoneE = moment(zoneA);
  39277. zoneB.utc();
  39278. assert.equal(+zoneA, +zoneB, 'moment should equal moment.utc');
  39279. zoneC.utcOffset(60);
  39280. assert.equal(+zoneA, +zoneC, 'moment should equal moment.utcOffset(60)');
  39281. zoneD.utcOffset(-480);
  39282. assert.equal(+zoneA, +zoneD,
  39283. 'moment should equal moment.utcOffset(-480)');
  39284. zoneE.utcOffset(-1000);
  39285. assert.equal(+zoneA, +zoneE,
  39286. 'moment should equal moment.utcOffset(-1000)');
  39287. });
  39288. test('update offset after changing any values', function (assert) {
  39289. var oldOffset = moment.updateOffset,
  39290. m = moment.utc([2000, 6, 1]);
  39291. moment.updateOffset = function (mom, keepTime) {
  39292. if (mom.__doChange) {
  39293. if (+mom > 962409600000) {
  39294. mom.utcOffset(-120, keepTime);
  39295. } else {
  39296. mom.utcOffset(-60, keepTime);
  39297. }
  39298. }
  39299. };
  39300. assert.equal(m.format('ZZ'), '+0000', 'should be at +0000');
  39301. assert.equal(m.format('HH:mm'), '00:00', 'should start 12AM at +0000 timezone');
  39302. m.__doChange = true;
  39303. m.add(1, 'h');
  39304. assert.equal(m.format('ZZ'), '-0200', 'should be at -0200');
  39305. assert.equal(m.format('HH:mm'), '23:00', '1AM at +0000 should be 11PM at -0200 timezone');
  39306. m.subtract(1, 'h');
  39307. assert.equal(m.format('ZZ'), '-0100', 'should be at -0100');
  39308. assert.equal(m.format('HH:mm'), '23:00', '12AM at +0000 should be 11PM at -0100 timezone');
  39309. moment.updateOffset = oldOffset;
  39310. });
  39311. //////////////////
  39312. test('getters and setters', function (assert) {
  39313. var a = moment([2011, 5, 20]);
  39314. assert.equal(a.clone().utcOffset(-120).year(2012).year(), 2012, 'should get and set year correctly');
  39315. assert.equal(a.clone().utcOffset(-120).month(1).month(), 1, 'should get and set month correctly');
  39316. assert.equal(a.clone().utcOffset(-120).date(2).date(), 2, 'should get and set date correctly');
  39317. assert.equal(a.clone().utcOffset(-120).day(1).day(), 1, 'should get and set day correctly');
  39318. assert.equal(a.clone().utcOffset(-120).hour(1).hour(), 1, 'should get and set hour correctly');
  39319. assert.equal(a.clone().utcOffset(-120).minute(1).minute(), 1, 'should get and set minute correctly');
  39320. });
  39321. test('getters', function (assert) {
  39322. var a = moment.utc([2012, 0, 1, 0, 0, 0]);
  39323. assert.equal(a.clone().utcOffset(-120).year(), 2011, 'should get year correctly');
  39324. assert.equal(a.clone().utcOffset(-120).month(), 11, 'should get month correctly');
  39325. assert.equal(a.clone().utcOffset(-120).date(), 31, 'should get date correctly');
  39326. assert.equal(a.clone().utcOffset(-120).hour(), 22, 'should get hour correctly');
  39327. assert.equal(a.clone().utcOffset(-120).minute(), 0, 'should get minute correctly');
  39328. assert.equal(a.clone().utcOffset(120).year(), 2012, 'should get year correctly');
  39329. assert.equal(a.clone().utcOffset(120).month(), 0, 'should get month correctly');
  39330. assert.equal(a.clone().utcOffset(120).date(), 1, 'should get date correctly');
  39331. assert.equal(a.clone().utcOffset(120).hour(), 2, 'should get hour correctly');
  39332. assert.equal(a.clone().utcOffset(120).minute(), 0, 'should get minute correctly');
  39333. assert.equal(a.clone().utcOffset(90).year(), 2012, 'should get year correctly');
  39334. assert.equal(a.clone().utcOffset(90).month(), 0, 'should get month correctly');
  39335. assert.equal(a.clone().utcOffset(90).date(), 1, 'should get date correctly');
  39336. assert.equal(a.clone().utcOffset(90).hour(), 1, 'should get hour correctly');
  39337. assert.equal(a.clone().utcOffset(90).minute(), 30, 'should get minute correctly');
  39338. });
  39339. test('from', function (assert) {
  39340. var zoneA = moment(),
  39341. zoneB = moment(zoneA).utcOffset(-720),
  39342. zoneC = moment(zoneA).utcOffset(-360),
  39343. zoneD = moment(zoneA).utcOffset(690),
  39344. other = moment(zoneA).add(35, 'm');
  39345. assert.equal(zoneA.from(other), zoneB.from(other), 'moment#from should be the same in all zones');
  39346. assert.equal(zoneA.from(other), zoneC.from(other), 'moment#from should be the same in all zones');
  39347. assert.equal(zoneA.from(other), zoneD.from(other), 'moment#from should be the same in all zones');
  39348. });
  39349. test('diff', function (assert) {
  39350. var zoneA = moment(),
  39351. zoneB = moment(zoneA).utcOffset(-720),
  39352. zoneC = moment(zoneA).utcOffset(-360),
  39353. zoneD = moment(zoneA).utcOffset(690),
  39354. other = moment(zoneA).add(35, 'm');
  39355. assert.equal(zoneA.diff(other), zoneB.diff(other), 'moment#diff should be the same in all zones');
  39356. assert.equal(zoneA.diff(other), zoneC.diff(other), 'moment#diff should be the same in all zones');
  39357. assert.equal(zoneA.diff(other), zoneD.diff(other), 'moment#diff should be the same in all zones');
  39358. assert.equal(zoneA.diff(other, 'minute', true), zoneB.diff(other, 'minute', true), 'moment#diff should be the same in all zones');
  39359. assert.equal(zoneA.diff(other, 'minute', true), zoneC.diff(other, 'minute', true), 'moment#diff should be the same in all zones');
  39360. assert.equal(zoneA.diff(other, 'minute', true), zoneD.diff(other, 'minute', true), 'moment#diff should be the same in all zones');
  39361. assert.equal(zoneA.diff(other, 'hour', true), zoneB.diff(other, 'hour', true), 'moment#diff should be the same in all zones');
  39362. assert.equal(zoneA.diff(other, 'hour', true), zoneC.diff(other, 'hour', true), 'moment#diff should be the same in all zones');
  39363. assert.equal(zoneA.diff(other, 'hour', true), zoneD.diff(other, 'hour', true), 'moment#diff should be the same in all zones');
  39364. });
  39365. test('unix offset and timestamp', function (assert) {
  39366. var zoneA = moment(),
  39367. zoneB = moment(zoneA).utcOffset(-720),
  39368. zoneC = moment(zoneA).utcOffset(-360),
  39369. zoneD = moment(zoneA).utcOffset(690);
  39370. assert.equal(zoneA.unix(), zoneB.unix(), 'moment#unix should be the same in all zones');
  39371. assert.equal(zoneA.unix(), zoneC.unix(), 'moment#unix should be the same in all zones');
  39372. assert.equal(zoneA.unix(), zoneD.unix(), 'moment#unix should be the same in all zones');
  39373. assert.equal(+zoneA, +zoneB, 'moment#valueOf should be the same in all zones');
  39374. assert.equal(+zoneA, +zoneC, 'moment#valueOf should be the same in all zones');
  39375. assert.equal(+zoneA, +zoneD, 'moment#valueOf should be the same in all zones');
  39376. });
  39377. test('cloning', function (assert) {
  39378. assert.equal(moment().utcOffset(-120).clone().utcOffset(), -120,
  39379. 'explicit cloning should retain the offset');
  39380. assert.equal(moment().utcOffset(120).clone().utcOffset(), 120,
  39381. 'explicit cloning should retain the offset');
  39382. assert.equal(moment(moment().utcOffset(-120)).utcOffset(), -120,
  39383. 'implicit cloning should retain the offset');
  39384. assert.equal(moment(moment().utcOffset(120)).utcOffset(), 120,
  39385. 'implicit cloning should retain the offset');
  39386. });
  39387. test('start of / end of', function (assert) {
  39388. var a = moment.utc([2010, 1, 2, 0, 0, 0]).utcOffset(-450);
  39389. assert.equal(a.clone().startOf('day').hour(), 0,
  39390. 'start of day should work on moments with utc offset');
  39391. assert.equal(a.clone().startOf('day').minute(), 0,
  39392. 'start of day should work on moments with utc offset');
  39393. assert.equal(a.clone().startOf('hour').minute(), 0,
  39394. 'start of hour should work on moments with utc offset');
  39395. assert.equal(a.clone().endOf('day').hour(), 23,
  39396. 'end of day should work on moments with utc offset');
  39397. assert.equal(a.clone().endOf('day').minute(), 59,
  39398. 'end of day should work on moments with utc offset');
  39399. assert.equal(a.clone().endOf('hour').minute(), 59,
  39400. 'end of hour should work on moments with utc offset');
  39401. });
  39402. test('reset offset with moment#utc', function (assert) {
  39403. var a = moment.utc([2012]).utcOffset(-480);
  39404. assert.equal(a.clone().hour(), 16, 'different utc offset should have different hour');
  39405. assert.equal(a.clone().utc().hour(), 0, 'calling moment#utc should reset the offset');
  39406. });
  39407. test('reset offset with moment#local', function (assert) {
  39408. var a = moment([2012]).utcOffset(-480);
  39409. assert.equal(a.clone().local().hour(), 0, 'calling moment#local should reset the offset');
  39410. });
  39411. test('toDate', function (assert) {
  39412. var zoneA = new Date(),
  39413. zoneB = moment(zoneA).utcOffset(-720).toDate(),
  39414. zoneC = moment(zoneA).utcOffset(-360).toDate(),
  39415. zoneD = moment(zoneA).utcOffset(690).toDate();
  39416. assert.equal(+zoneA, +zoneB, 'moment#toDate should output a date with the right unix timestamp');
  39417. assert.equal(+zoneA, +zoneC, 'moment#toDate should output a date with the right unix timestamp');
  39418. assert.equal(+zoneA, +zoneD, 'moment#toDate should output a date with the right unix timestamp');
  39419. });
  39420. test('same / before / after', function (assert) {
  39421. var zoneA = moment().utc(),
  39422. zoneB = moment(zoneA).utcOffset(-120),
  39423. zoneC = moment(zoneA).utcOffset(120);
  39424. assert.ok(zoneA.isSame(zoneB), 'two moments with different offsets should be the same');
  39425. assert.ok(zoneA.isSame(zoneC), 'two moments with different offsets should be the same');
  39426. assert.ok(zoneA.isSame(zoneB, 'hour'), 'two moments with different offsets should be the same hour');
  39427. assert.ok(zoneA.isSame(zoneC, 'hour'), 'two moments with different offsets should be the same hour');
  39428. zoneA.add(1, 'hour');
  39429. assert.ok(zoneA.isAfter(zoneB), 'isAfter should work with two moments with different offsets');
  39430. assert.ok(zoneA.isAfter(zoneC), 'isAfter should work with two moments with different offsets');
  39431. assert.ok(zoneA.isAfter(zoneB, 'hour'), 'isAfter:hour should work with two moments with different offsets');
  39432. assert.ok(zoneA.isAfter(zoneC, 'hour'), 'isAfter:hour should work with two moments with different offsets');
  39433. zoneA.subtract(2, 'hour');
  39434. assert.ok(zoneA.isBefore(zoneB), 'isBefore should work with two moments with different offsets');
  39435. assert.ok(zoneA.isBefore(zoneC), 'isBefore should work with two moments with different offsets');
  39436. assert.ok(zoneA.isBefore(zoneB, 'hour'), 'isBefore:hour should work with two moments with different offsets');
  39437. assert.ok(zoneA.isBefore(zoneC, 'hour'), 'isBefore:hour should work with two moments with different offsets');
  39438. });
  39439. test('add / subtract over dst', function (assert) {
  39440. var oldOffset = moment.updateOffset,
  39441. m = moment.utc([2000, 2, 31, 3]);
  39442. moment.updateOffset = function (mom, keepTime) {
  39443. if (mom.clone().utc().month() > 2) {
  39444. mom.utcOffset(60, keepTime);
  39445. } else {
  39446. mom.utcOffset(0, keepTime);
  39447. }
  39448. };
  39449. assert.equal(m.hour(), 3, 'should start at 00:00');
  39450. m.add(24, 'hour');
  39451. assert.equal(m.hour(), 4, 'adding 24 hours should disregard dst');
  39452. m.subtract(24, 'hour');
  39453. assert.equal(m.hour(), 3, 'subtracting 24 hours should disregard dst');
  39454. m.add(1, 'day');
  39455. assert.equal(m.hour(), 3, 'adding 1 day should have the same hour');
  39456. m.subtract(1, 'day');
  39457. assert.equal(m.hour(), 3, 'subtracting 1 day should have the same hour');
  39458. m.add(1, 'month');
  39459. assert.equal(m.hour(), 3, 'adding 1 month should have the same hour');
  39460. m.subtract(1, 'month');
  39461. assert.equal(m.hour(), 3, 'subtracting 1 month should have the same hour');
  39462. moment.updateOffset = oldOffset;
  39463. });
  39464. test('isDST', function (assert) {
  39465. var oldOffset = moment.updateOffset;
  39466. moment.updateOffset = function (mom, keepTime) {
  39467. if (mom.month() > 2 && mom.month() < 9) {
  39468. mom.utcOffset(60, keepTime);
  39469. } else {
  39470. mom.utcOffset(0, keepTime);
  39471. }
  39472. };
  39473. assert.ok(!moment().month(0).isDST(), 'Jan should not be summer dst');
  39474. assert.ok(moment().month(6).isDST(), 'Jul should be summer dst');
  39475. assert.ok(!moment().month(11).isDST(), 'Dec should not be summer dst');
  39476. moment.updateOffset = function (mom) {
  39477. if (mom.month() > 2 && mom.month() < 9) {
  39478. mom.utcOffset(0);
  39479. } else {
  39480. mom.utcOffset(60);
  39481. }
  39482. };
  39483. assert.ok(moment().month(0).isDST(), 'Jan should be winter dst');
  39484. assert.ok(!moment().month(6).isDST(), 'Jul should not be winter dst');
  39485. assert.ok(moment().month(11).isDST(), 'Dec should be winter dst');
  39486. moment.updateOffset = oldOffset;
  39487. });
  39488. test('zone names', function (assert) {
  39489. assert.equal(moment().zoneAbbr(), '', 'Local zone abbr should be empty');
  39490. assert.equal(moment().format('z'), '', 'Local zone formatted abbr should be empty');
  39491. assert.equal(moment().zoneName(), '', 'Local zone name should be empty');
  39492. assert.equal(moment().format('zz'), '', 'Local zone formatted name should be empty');
  39493. assert.equal(moment.utc().zoneAbbr(), 'UTC', 'UTC zone abbr should be UTC');
  39494. assert.equal(moment.utc().format('z'), 'UTC', 'UTC zone formatted abbr should be UTC');
  39495. assert.equal(moment.utc().zoneName(), 'Coordinated Universal Time', 'UTC zone abbr should be Coordinated Universal Time');
  39496. assert.equal(moment.utc().format('zz'), 'Coordinated Universal Time', 'UTC zone formatted abbr should be Coordinated Universal Time');
  39497. });
  39498. test('hours alignment with UTC', function (assert) {
  39499. assert.equal(moment().utcOffset(-120).hasAlignedHourOffset(), true);
  39500. assert.equal(moment().utcOffset(180).hasAlignedHourOffset(), true);
  39501. assert.equal(moment().utcOffset(-90).hasAlignedHourOffset(), false);
  39502. assert.equal(moment().utcOffset(90).hasAlignedHourOffset(), false);
  39503. });
  39504. test('hours alignment with other zone', function (assert) {
  39505. var m = moment().utcOffset(-120);
  39506. assert.equal(m.hasAlignedHourOffset(moment().utcOffset(-180)), true);
  39507. assert.equal(m.hasAlignedHourOffset(moment().utcOffset(180)), true);
  39508. assert.equal(m.hasAlignedHourOffset(moment().utcOffset(-90)), false);
  39509. assert.equal(m.hasAlignedHourOffset(moment().utcOffset(90)), false);
  39510. m = moment().utcOffset(-90);
  39511. assert.equal(m.hasAlignedHourOffset(moment().utcOffset(-180)), false);
  39512. assert.equal(m.hasAlignedHourOffset(moment().utcOffset(180)), false);
  39513. assert.equal(m.hasAlignedHourOffset(moment().utcOffset(-30)), true);
  39514. assert.equal(m.hasAlignedHourOffset(moment().utcOffset(30)), true);
  39515. m = moment().utcOffset(60);
  39516. assert.equal(m.hasAlignedHourOffset(moment().utcOffset(-180)), true);
  39517. assert.equal(m.hasAlignedHourOffset(moment().utcOffset(180)), true);
  39518. assert.equal(m.hasAlignedHourOffset(moment().utcOffset(-90)), false);
  39519. assert.equal(m.hasAlignedHourOffset(moment().utcOffset(90)), false);
  39520. m = moment().utcOffset(-25);
  39521. assert.equal(m.hasAlignedHourOffset(moment().utcOffset(35)), true);
  39522. assert.equal(m.hasAlignedHourOffset(moment().utcOffset(-85)), true);
  39523. assert.equal(m.hasAlignedHourOffset(moment().utcOffset(-35)), false);
  39524. assert.equal(m.hasAlignedHourOffset(moment().utcOffset(85)), false);
  39525. });
  39526. test('parse zone', function (assert) {
  39527. var m = moment('2013-01-01T00:00:00-13:00').parseZone();
  39528. assert.equal(m.utcOffset(), -13 * 60);
  39529. assert.equal(m.hours(), 0);
  39530. });
  39531. test('parse zone static', function (assert) {
  39532. var m = moment.parseZone('2013-01-01T00:00:00-13:00');
  39533. assert.equal(m.utcOffset(), -13 * 60);
  39534. assert.equal(m.hours(), 0);
  39535. });
  39536. test('parse zone with more arguments', function (assert) {
  39537. var m;
  39538. m = moment.parseZone('2013 01 01 05 -13:00', 'YYYY MM DD HH ZZ');
  39539. assert.equal(m.format(), '2013-01-01T05:00:00-13:00', 'accept input and format');
  39540. m = moment.parseZone('2013-01-01-13:00', 'YYYY MM DD ZZ', true);
  39541. assert.equal(m.isValid(), false, 'accept input, format and strict flag');
  39542. m = moment.parseZone('2013-01-01-13:00', ['DD MM YYYY ZZ', 'YYYY MM DD ZZ']);
  39543. assert.equal(m.format(), '2013-01-01T00:00:00-13:00', 'accept input and array of formats');
  39544. });
  39545. test('parse zone with a timezone from the format string', function (assert) {
  39546. var m = moment('11-12-2013 -0400 +1100', 'DD-MM-YYYY ZZ #####').parseZone();
  39547. assert.equal(m.utcOffset(), -4 * 60);
  39548. });
  39549. test('parse zone without a timezone included in the format string', function (assert) {
  39550. var m = moment('11-12-2013 -0400 +1100', 'DD-MM-YYYY').parseZone();
  39551. assert.equal(m.utcOffset(), 11 * 60);
  39552. });
  39553. test('timezone format', function (assert) {
  39554. assert.equal(moment().utcOffset(60).format('ZZ'), '+0100', '-60 -> +0100');
  39555. assert.equal(moment().utcOffset(90).format('ZZ'), '+0130', '-90 -> +0130');
  39556. assert.equal(moment().utcOffset(120).format('ZZ'), '+0200', '-120 -> +0200');
  39557. assert.equal(moment().utcOffset(-60).format('ZZ'), '-0100', '+60 -> -0100');
  39558. assert.equal(moment().utcOffset(-90).format('ZZ'), '-0130', '+90 -> -0130');
  39559. assert.equal(moment().utcOffset(-120).format('ZZ'), '-0200', '+120 -> -0200');
  39560. });
  39561. test('local to utc, keepLocalTime = true', function (assert) {
  39562. var m = moment(),
  39563. fmt = 'YYYY-DD-MM HH:mm:ss';
  39564. assert.equal(m.clone().utc(true).format(fmt), m.format(fmt), 'local to utc failed to keep local time');
  39565. });
  39566. test('local to utc, keepLocalTime = false', function (assert) {
  39567. var m = moment();
  39568. assert.equal(m.clone().utc().valueOf(), m.valueOf(), 'local to utc failed to keep utc time (implicit)');
  39569. assert.equal(m.clone().utc(false).valueOf(), m.valueOf(), 'local to utc failed to keep utc time (explicit)');
  39570. });
  39571. test('local to zone, keepLocalTime = true', function (assert) {
  39572. var m = moment(),
  39573. fmt = 'YYYY-DD-MM HH:mm:ss',
  39574. z;
  39575. // Apparently there is -12:00 and +14:00
  39576. // http://en.wikipedia.org/wiki/UTC+14:00
  39577. // http://en.wikipedia.org/wiki/UTC-12:00
  39578. for (z = -12; z <= 14; ++z) {
  39579. assert.equal(m.clone().utcOffset(z * 60, true).format(fmt),
  39580. m.format(fmt),
  39581. 'local to utcOffset(' + z + ':00) failed to keep local time');
  39582. }
  39583. });
  39584. test('local to zone, keepLocalTime = false', function (assert) {
  39585. var m = moment(),
  39586. z;
  39587. // Apparently there is -12:00 and +14:00
  39588. // http://en.wikipedia.org/wiki/UTC+14:00
  39589. // http://en.wikipedia.org/wiki/UTC-12:00
  39590. for (z = -12; z <= 14; ++z) {
  39591. assert.equal(m.clone().utcOffset(z * 60).valueOf(),
  39592. m.valueOf(),
  39593. 'local to utcOffset(' + z + ':00) failed to keep utc time (implicit)');
  39594. assert.equal(m.clone().utcOffset(z * 60, false).valueOf(),
  39595. m.valueOf(),
  39596. 'local to utcOffset(' + z + ':00) failed to keep utc time (explicit)');
  39597. }
  39598. });
  39599. test('utc to local, keepLocalTime = true', function (assert) {
  39600. var um = moment.utc(),
  39601. fmt = 'YYYY-DD-MM HH:mm:ss';
  39602. assert.equal(um.clone().local(true).format(fmt), um.format(fmt), 'utc to local failed to keep local time');
  39603. });
  39604. test('utc to local, keepLocalTime = false', function (assert) {
  39605. var um = moment.utc();
  39606. assert.equal(um.clone().local().valueOf(), um.valueOf(), 'utc to local failed to keep utc time (implicit)');
  39607. assert.equal(um.clone().local(false).valueOf(), um.valueOf(), 'utc to local failed to keep utc time (explicit)');
  39608. });
  39609. test('zone to local, keepLocalTime = true', function (assert) {
  39610. var m = moment(),
  39611. fmt = 'YYYY-DD-MM HH:mm:ss',
  39612. z;
  39613. // Apparently there is -12:00 and +14:00
  39614. // http://en.wikipedia.org/wiki/UTC+14:00
  39615. // http://en.wikipedia.org/wiki/UTC-12:00
  39616. for (z = -12; z <= 14; ++z) {
  39617. m.utcOffset(z * 60);
  39618. assert.equal(m.clone().local(true).format(fmt),
  39619. m.format(fmt),
  39620. 'utcOffset(' + z + ':00) to local failed to keep local time');
  39621. }
  39622. });
  39623. test('zone to local, keepLocalTime = false', function (assert) {
  39624. var m = moment(),
  39625. z;
  39626. // Apparently there is -12:00 and +14:00
  39627. // http://en.wikipedia.org/wiki/UTC+14:00
  39628. // http://en.wikipedia.org/wiki/UTC-12:00
  39629. for (z = -12; z <= 14; ++z) {
  39630. m.utcOffset(z * 60);
  39631. assert.equal(m.clone().local(false).valueOf(), m.valueOf(),
  39632. 'utcOffset(' + z + ':00) to local failed to keep utc time (explicit)');
  39633. assert.equal(m.clone().local().valueOf(), m.valueOf(),
  39634. 'utcOffset(' + z + ':00) to local failed to keep utc time (implicit)');
  39635. }
  39636. });
  39637. }));
  39638. ;(function (global, factory) {
  39639. typeof exports === 'object' && typeof module !== 'undefined'
  39640. && typeof require === 'function' ? factory(require('../../moment')) :
  39641. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  39642. factory(global.moment)
  39643. }(this, function (moment) { 'use strict';
  39644. /*global QUnit:false*/
  39645. var test = QUnit.test;
  39646. var expect = QUnit.expect;
  39647. function module (name, lifecycle) {
  39648. QUnit.module(name, {
  39649. setup : function () {
  39650. moment.locale('en');
  39651. moment.createFromInputFallback = function (config) {
  39652. throw new Error('input not handled by moment: ' + config._i);
  39653. };
  39654. if (lifecycle && lifecycle.setup) {
  39655. lifecycle.setup();
  39656. }
  39657. },
  39658. teardown : function () {
  39659. if (lifecycle && lifecycle.teardown) {
  39660. lifecycle.teardown();
  39661. }
  39662. }
  39663. });
  39664. }
  39665. function localeModule (name, lifecycle) {
  39666. QUnit.module('locale:' + name, {
  39667. setup : function () {
  39668. moment.locale(name);
  39669. moment.createFromInputFallback = function (config) {
  39670. throw new Error('input not handled by moment: ' + config._i);
  39671. };
  39672. if (lifecycle && lifecycle.setup) {
  39673. lifecycle.setup();
  39674. }
  39675. },
  39676. teardown : function () {
  39677. moment.locale('en');
  39678. if (lifecycle && lifecycle.teardown) {
  39679. lifecycle.teardown();
  39680. }
  39681. }
  39682. });
  39683. }
  39684. module('week year');
  39685. test('iso week year', function (assert) {
  39686. // Some examples taken from http://en.wikipedia.org/wiki/ISO_week
  39687. assert.equal(moment([2005, 0, 1]).isoWeekYear(), 2004);
  39688. assert.equal(moment([2005, 0, 2]).isoWeekYear(), 2004);
  39689. assert.equal(moment([2005, 0, 3]).isoWeekYear(), 2005);
  39690. assert.equal(moment([2005, 11, 31]).isoWeekYear(), 2005);
  39691. assert.equal(moment([2006, 0, 1]).isoWeekYear(), 2005);
  39692. assert.equal(moment([2006, 0, 2]).isoWeekYear(), 2006);
  39693. assert.equal(moment([2007, 0, 1]).isoWeekYear(), 2007);
  39694. assert.equal(moment([2007, 11, 30]).isoWeekYear(), 2007);
  39695. assert.equal(moment([2007, 11, 31]).isoWeekYear(), 2008);
  39696. assert.equal(moment([2008, 0, 1]).isoWeekYear(), 2008);
  39697. assert.equal(moment([2008, 11, 28]).isoWeekYear(), 2008);
  39698. assert.equal(moment([2008, 11, 29]).isoWeekYear(), 2009);
  39699. assert.equal(moment([2008, 11, 30]).isoWeekYear(), 2009);
  39700. assert.equal(moment([2008, 11, 31]).isoWeekYear(), 2009);
  39701. assert.equal(moment([2009, 0, 1]).isoWeekYear(), 2009);
  39702. assert.equal(moment([2010, 0, 1]).isoWeekYear(), 2009);
  39703. assert.equal(moment([2010, 0, 2]).isoWeekYear(), 2009);
  39704. assert.equal(moment([2010, 0, 3]).isoWeekYear(), 2009);
  39705. assert.equal(moment([2010, 0, 4]).isoWeekYear(), 2010);
  39706. });
  39707. test('week year', function (assert) {
  39708. // Some examples taken from http://en.wikipedia.org/wiki/ISO_week
  39709. moment.locale('dow: 1,doy: 4', {week: {dow: 1, doy: 4}}); // like iso
  39710. assert.equal(moment([2005, 0, 1]).weekYear(), 2004);
  39711. assert.equal(moment([2005, 0, 2]).weekYear(), 2004);
  39712. assert.equal(moment([2005, 0, 3]).weekYear(), 2005);
  39713. assert.equal(moment([2005, 11, 31]).weekYear(), 2005);
  39714. assert.equal(moment([2006, 0, 1]).weekYear(), 2005);
  39715. assert.equal(moment([2006, 0, 2]).weekYear(), 2006);
  39716. assert.equal(moment([2007, 0, 1]).weekYear(), 2007);
  39717. assert.equal(moment([2007, 11, 30]).weekYear(), 2007);
  39718. assert.equal(moment([2007, 11, 31]).weekYear(), 2008);
  39719. assert.equal(moment([2008, 0, 1]).weekYear(), 2008);
  39720. assert.equal(moment([2008, 11, 28]).weekYear(), 2008);
  39721. assert.equal(moment([2008, 11, 29]).weekYear(), 2009);
  39722. assert.equal(moment([2008, 11, 30]).weekYear(), 2009);
  39723. assert.equal(moment([2008, 11, 31]).weekYear(), 2009);
  39724. assert.equal(moment([2009, 0, 1]).weekYear(), 2009);
  39725. assert.equal(moment([2010, 0, 1]).weekYear(), 2009);
  39726. assert.equal(moment([2010, 0, 2]).weekYear(), 2009);
  39727. assert.equal(moment([2010, 0, 3]).weekYear(), 2009);
  39728. assert.equal(moment([2010, 0, 4]).weekYear(), 2010);
  39729. moment.locale('dow: 1,doy: 7', {week: {dow: 1, doy: 7}});
  39730. assert.equal(moment([2004, 11, 26]).weekYear(), 2004);
  39731. assert.equal(moment([2004, 11, 27]).weekYear(), 2005);
  39732. assert.equal(moment([2005, 11, 25]).weekYear(), 2005);
  39733. assert.equal(moment([2005, 11, 26]).weekYear(), 2006);
  39734. assert.equal(moment([2006, 11, 31]).weekYear(), 2006);
  39735. assert.equal(moment([2007, 0, 1]).weekYear(), 2007);
  39736. assert.equal(moment([2007, 11, 30]).weekYear(), 2007);
  39737. assert.equal(moment([2007, 11, 31]).weekYear(), 2008);
  39738. assert.equal(moment([2008, 11, 28]).weekYear(), 2008);
  39739. assert.equal(moment([2008, 11, 29]).weekYear(), 2009);
  39740. assert.equal(moment([2009, 11, 27]).weekYear(), 2009);
  39741. assert.equal(moment([2009, 11, 28]).weekYear(), 2010);
  39742. });
  39743. // Verifies that the week number, week day computation is correct for all dow, doy combinations
  39744. test('week year roundtrip', function (assert) {
  39745. var dow, doy, wd, m;
  39746. for (dow = 0; dow < 7; ++dow) {
  39747. for (doy = dow; doy < dow + 7; ++doy) {
  39748. for (wd = 0; wd < 7; ++wd) {
  39749. moment.locale('dow: ' + dow + ', doy: ' + doy, {week: {dow: dow, doy: doy}});
  39750. // We use the 10th week as the 1st one can spill to the previous year
  39751. m = moment('2015 10 ' + wd, 'gggg w d', true);
  39752. assert.equal(m.format('gggg w d'), '2015 10 ' + wd, 'dow: ' + dow + ' doy: ' + doy + ' wd: ' + wd);
  39753. m = moment('2015 10 ' + wd, 'gggg w e', true);
  39754. assert.equal(m.format('gggg w e'), '2015 10 ' + wd, 'dow: ' + dow + ' doy: ' + doy + ' wd: ' + wd);
  39755. }
  39756. }
  39757. }
  39758. });
  39759. test('week numbers 2012/2013', function (assert) {
  39760. moment.locale('dow: 6, doy: 12', {week: {dow: 6, doy: 12}});
  39761. assert.equal(52, moment('2012-12-28', 'YYYY-MM-DD').week(), '2012-12-28 is week 52'); // 51 -- should be 52?
  39762. assert.equal(1, moment('2012-12-29', 'YYYY-MM-DD').week(), '2012-12-29 is week 1'); // 52 -- should be 1
  39763. assert.equal(1, moment('2013-01-01', 'YYYY-MM-DD').week(), '2013-01-01 is week 1'); // 52 -- should be 1
  39764. assert.equal(2, moment('2013-01-08', 'YYYY-MM-DD').week(), '2013-01-08 is week 2'); // 53 -- should be 2
  39765. assert.equal(2, moment('2013-01-11', 'YYYY-MM-DD').week(), '2013-01-11 is week 2'); // 53 -- should be 2
  39766. assert.equal(3, moment('2013-01-12', 'YYYY-MM-DD').week(), '2013-01-12 is week 3'); // 1 -- should be 3
  39767. assert.equal(52, moment('2012-01-01', 'YYYY-MM-DD').weeksInYear(), 'weeks in 2012 are 52'); // 52
  39768. });
  39769. test('week year overflows', function (assert) {
  39770. assert.equal('2005-01-01', moment.utc('2004-W53-6', moment.ISO_8601, true).format('YYYY-MM-DD'), '2004-W53-6 is 1st Jan 2005');
  39771. assert.equal('2007-12-31', moment.utc('2008-W01-1', moment.ISO_8601, true).format('YYYY-MM-DD'), '2008-W01-1 is 31st Dec 2007');
  39772. });
  39773. test('weeks overflow', function (assert) {
  39774. assert.equal(7, moment.utc('2004-W54-1', moment.ISO_8601, true).parsingFlags().overflow, '2004 has only 53 weeks');
  39775. assert.equal(7, moment.utc('2004-W00-1', moment.ISO_8601, true).parsingFlags().overflow, 'there is no 0th week');
  39776. });
  39777. test('weekday overflow', function (assert) {
  39778. assert.equal(8, moment.utc('2004-W30-0', moment.ISO_8601, true).parsingFlags().overflow, 'there is no 0 iso weekday');
  39779. assert.equal(8, moment.utc('2004-W30-8', moment.ISO_8601, true).parsingFlags().overflow, 'there is no 8 iso weekday');
  39780. assert.equal(8, moment.utc('2004-w30-7', 'gggg-[w]ww-e', true).parsingFlags().overflow, 'there is no 7 \'e\' weekday');
  39781. assert.equal(8, moment.utc('2004-w30-7', 'gggg-[w]ww-d', true).parsingFlags().overflow, 'there is no 7 \'d\' weekday');
  39782. });
  39783. test('week year setter works', function (assert) {
  39784. for (var year = 2000; year <= 2020; year += 1) {
  39785. assert.equal(moment.utc('2012-12-31T00:00:00.000Z').isoWeekYear(year).isoWeekYear(), year, 'setting iso-week-year to ' + year);
  39786. assert.equal(moment.utc('2012-12-31T00:00:00.000Z').weekYear(year).weekYear(), year, 'setting week-year to ' + year);
  39787. }
  39788. assert.equal(moment.utc('2004-W53-1', moment.ISO_8601, true).isoWeekYear(2013).format('GGGG-[W]WW-E'), '2013-W52-1', '2004-W53-1 to 2013');
  39789. assert.equal(moment.utc('2004-W53-1', moment.ISO_8601, true).isoWeekYear(2020).format('GGGG-[W]WW-E'), '2020-W53-1', '2004-W53-1 to 2020');
  39790. assert.equal(moment.utc('2005-W52-1', moment.ISO_8601, true).isoWeekYear(2004).format('GGGG-[W]WW-E'), '2004-W52-1', '2005-W52-1 to 2004');
  39791. assert.equal(moment.utc('2013-W30-4', moment.ISO_8601, true).isoWeekYear(2015).format('GGGG-[W]WW-E'), '2015-W30-4', '2013-W30-4 to 2015');
  39792. assert.equal(moment.utc('2005-w53-0', 'gggg-[w]ww-e', true).weekYear(2013).format('gggg-[w]ww-e'), '2013-w52-0', '2005-w53-0 to 2013');
  39793. assert.equal(moment.utc('2005-w53-0', 'gggg-[w]ww-e', true).weekYear(2016).format('gggg-[w]ww-e'), '2016-w53-0', '2005-w53-0 to 2016');
  39794. assert.equal(moment.utc('2004-w52-0', 'gggg-[w]ww-e', true).weekYear(2005).format('gggg-[w]ww-e'), '2005-w52-0', '2004-w52-0 to 2005');
  39795. assert.equal(moment.utc('2013-w30-4', 'gggg-[w]ww-e', true).weekYear(2015).format('gggg-[w]ww-e'), '2015-w30-4', '2013-w30-4 to 2015');
  39796. });
  39797. }));
  39798. ;(function (global, factory) {
  39799. typeof exports === 'object' && typeof module !== 'undefined'
  39800. && typeof require === 'function' ? factory(require('../../moment')) :
  39801. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  39802. factory(global.moment)
  39803. }(this, function (moment) { 'use strict';
  39804. /*global QUnit:false*/
  39805. var test = QUnit.test;
  39806. var expect = QUnit.expect;
  39807. function module (name, lifecycle) {
  39808. QUnit.module(name, {
  39809. setup : function () {
  39810. moment.locale('en');
  39811. moment.createFromInputFallback = function (config) {
  39812. throw new Error('input not handled by moment: ' + config._i);
  39813. };
  39814. if (lifecycle && lifecycle.setup) {
  39815. lifecycle.setup();
  39816. }
  39817. },
  39818. teardown : function () {
  39819. if (lifecycle && lifecycle.teardown) {
  39820. lifecycle.teardown();
  39821. }
  39822. }
  39823. });
  39824. }
  39825. function localeModule (name, lifecycle) {
  39826. QUnit.module('locale:' + name, {
  39827. setup : function () {
  39828. moment.locale(name);
  39829. moment.createFromInputFallback = function (config) {
  39830. throw new Error('input not handled by moment: ' + config._i);
  39831. };
  39832. if (lifecycle && lifecycle.setup) {
  39833. lifecycle.setup();
  39834. }
  39835. },
  39836. teardown : function () {
  39837. moment.locale('en');
  39838. if (lifecycle && lifecycle.teardown) {
  39839. lifecycle.teardown();
  39840. }
  39841. }
  39842. });
  39843. }
  39844. module('week day');
  39845. test('iso weekday', function (assert) {
  39846. var i;
  39847. for (i = 0; i < 7; ++i) {
  39848. moment.locale('dow:' + i + ',doy: 6', {week: {dow: i, doy: 6}});
  39849. assert.equal(moment([1985, 1, 4]).isoWeekday(), 1, 'Feb 4 1985 is Monday -- 1st day');
  39850. assert.equal(moment([2029, 8, 18]).isoWeekday(), 2, 'Sep 18 2029 is Tuesday -- 2nd day');
  39851. assert.equal(moment([2013, 3, 24]).isoWeekday(), 3, 'Apr 24 2013 is Wednesday -- 3rd day');
  39852. assert.equal(moment([2015, 2, 5]).isoWeekday(), 4, 'Mar 5 2015 is Thursday -- 4th day');
  39853. assert.equal(moment([1970, 0, 2]).isoWeekday(), 5, 'Jan 2 1970 is Friday -- 5th day');
  39854. assert.equal(moment([2001, 4, 12]).isoWeekday(), 6, 'May 12 2001 is Saturday -- 6th day');
  39855. assert.equal(moment([2000, 0, 2]).isoWeekday(), 7, 'Jan 2 2000 is Sunday -- 7th day');
  39856. }
  39857. });
  39858. test('iso weekday setter', function (assert) {
  39859. var a = moment([2011, 0, 10]);
  39860. assert.equal(moment(a).isoWeekday(1).date(), 10, 'set from mon to mon');
  39861. assert.equal(moment(a).isoWeekday(4).date(), 13, 'set from mon to thu');
  39862. assert.equal(moment(a).isoWeekday(7).date(), 16, 'set from mon to sun');
  39863. assert.equal(moment(a).isoWeekday(-6).date(), 3, 'set from mon to last mon');
  39864. assert.equal(moment(a).isoWeekday(-3).date(), 6, 'set from mon to last thu');
  39865. assert.equal(moment(a).isoWeekday(0).date(), 9, 'set from mon to last sun');
  39866. assert.equal(moment(a).isoWeekday(8).date(), 17, 'set from mon to next mon');
  39867. assert.equal(moment(a).isoWeekday(11).date(), 20, 'set from mon to next thu');
  39868. assert.equal(moment(a).isoWeekday(14).date(), 23, 'set from mon to next sun');
  39869. a = moment([2011, 0, 13]);
  39870. assert.equal(moment(a).isoWeekday(1).date(), 10, 'set from thu to mon');
  39871. assert.equal(moment(a).isoWeekday(4).date(), 13, 'set from thu to thu');
  39872. assert.equal(moment(a).isoWeekday(7).date(), 16, 'set from thu to sun');
  39873. assert.equal(moment(a).isoWeekday(-6).date(), 3, 'set from thu to last mon');
  39874. assert.equal(moment(a).isoWeekday(-3).date(), 6, 'set from thu to last thu');
  39875. assert.equal(moment(a).isoWeekday(0).date(), 9, 'set from thu to last sun');
  39876. assert.equal(moment(a).isoWeekday(8).date(), 17, 'set from thu to next mon');
  39877. assert.equal(moment(a).isoWeekday(11).date(), 20, 'set from thu to next thu');
  39878. assert.equal(moment(a).isoWeekday(14).date(), 23, 'set from thu to next sun');
  39879. a = moment([2011, 0, 16]);
  39880. assert.equal(moment(a).isoWeekday(1).date(), 10, 'set from sun to mon');
  39881. assert.equal(moment(a).isoWeekday(4).date(), 13, 'set from sun to thu');
  39882. assert.equal(moment(a).isoWeekday(7).date(), 16, 'set from sun to sun');
  39883. assert.equal(moment(a).isoWeekday(-6).date(), 3, 'set from sun to last mon');
  39884. assert.equal(moment(a).isoWeekday(-3).date(), 6, 'set from sun to last thu');
  39885. assert.equal(moment(a).isoWeekday(0).date(), 9, 'set from sun to last sun');
  39886. assert.equal(moment(a).isoWeekday(8).date(), 17, 'set from sun to next mon');
  39887. assert.equal(moment(a).isoWeekday(11).date(), 20, 'set from sun to next thu');
  39888. assert.equal(moment(a).isoWeekday(14).date(), 23, 'set from sun to next sun');
  39889. });
  39890. test('weekday first day of week Sunday (dow 0)', function (assert) {
  39891. moment.locale('dow: 0,doy: 6', {week: {dow: 0, doy: 6}});
  39892. assert.equal(moment([1985, 1, 3]).weekday(), 0, 'Feb 3 1985 is Sunday -- 0th day');
  39893. assert.equal(moment([2029, 8, 17]).weekday(), 1, 'Sep 17 2029 is Monday -- 1st day');
  39894. assert.equal(moment([2013, 3, 23]).weekday(), 2, 'Apr 23 2013 is Tuesday -- 2nd day');
  39895. assert.equal(moment([2015, 2, 4]).weekday(), 3, 'Mar 4 2015 is Wednesday -- 3nd day');
  39896. assert.equal(moment([1970, 0, 1]).weekday(), 4, 'Jan 1 1970 is Thursday -- 4th day');
  39897. assert.equal(moment([2001, 4, 11]).weekday(), 5, 'May 11 2001 is Friday -- 5th day');
  39898. assert.equal(moment([2000, 0, 1]).weekday(), 6, 'Jan 1 2000 is Saturday -- 6th day');
  39899. });
  39900. test('weekday first day of week Monday (dow 1)', function (assert) {
  39901. moment.locale('dow: 1,doy: 6', {week: {dow: 1, doy: 6}});
  39902. assert.equal(moment([1985, 1, 4]).weekday(), 0, 'Feb 4 1985 is Monday -- 0th day');
  39903. assert.equal(moment([2029, 8, 18]).weekday(), 1, 'Sep 18 2029 is Tuesday -- 1st day');
  39904. assert.equal(moment([2013, 3, 24]).weekday(), 2, 'Apr 24 2013 is Wednesday -- 2nd day');
  39905. assert.equal(moment([2015, 2, 5]).weekday(), 3, 'Mar 5 2015 is Thursday -- 3nd day');
  39906. assert.equal(moment([1970, 0, 2]).weekday(), 4, 'Jan 2 1970 is Friday -- 4th day');
  39907. assert.equal(moment([2001, 4, 12]).weekday(), 5, 'May 12 2001 is Saturday -- 5th day');
  39908. assert.equal(moment([2000, 0, 2]).weekday(), 6, 'Jan 2 2000 is Sunday -- 6th day');
  39909. });
  39910. test('weekday first day of week Tuesday (dow 2)', function (assert) {
  39911. moment.locale('dow: 2,doy: 6', {week: {dow: 2, doy: 6}});
  39912. assert.equal(moment([1985, 1, 5]).weekday(), 0, 'Feb 5 1985 is Tuesday -- 0th day');
  39913. assert.equal(moment([2029, 8, 19]).weekday(), 1, 'Sep 19 2029 is Wednesday -- 1st day');
  39914. assert.equal(moment([2013, 3, 25]).weekday(), 2, 'Apr 25 2013 is Thursday -- 2nd day');
  39915. assert.equal(moment([2015, 2, 6]).weekday(), 3, 'Mar 6 2015 is Friday -- 3nd day');
  39916. assert.equal(moment([1970, 0, 3]).weekday(), 4, 'Jan 3 1970 is Staturday -- 4th day');
  39917. assert.equal(moment([2001, 4, 13]).weekday(), 5, 'May 13 2001 is Sunday -- 5th day');
  39918. assert.equal(moment([2000, 0, 3]).weekday(), 6, 'Jan 3 2000 is Monday -- 6th day');
  39919. });
  39920. test('weekday first day of week Wednesday (dow 3)', function (assert) {
  39921. moment.locale('dow: 3,doy: 6', {week: {dow: 3, doy: 6}});
  39922. assert.equal(moment([1985, 1, 6]).weekday(), 0, 'Feb 6 1985 is Wednesday -- 0th day');
  39923. assert.equal(moment([2029, 8, 20]).weekday(), 1, 'Sep 20 2029 is Thursday -- 1st day');
  39924. assert.equal(moment([2013, 3, 26]).weekday(), 2, 'Apr 26 2013 is Friday -- 2nd day');
  39925. assert.equal(moment([2015, 2, 7]).weekday(), 3, 'Mar 7 2015 is Saturday -- 3nd day');
  39926. assert.equal(moment([1970, 0, 4]).weekday(), 4, 'Jan 4 1970 is Sunday -- 4th day');
  39927. assert.equal(moment([2001, 4, 14]).weekday(), 5, 'May 14 2001 is Monday -- 5th day');
  39928. assert.equal(moment([2000, 0, 4]).weekday(), 6, 'Jan 4 2000 is Tuesday -- 6th day');
  39929. moment.locale('dow:3,doy:6', null);
  39930. });
  39931. test('weekday first day of week Thursday (dow 4)', function (assert) {
  39932. moment.locale('dow: 4,doy: 6', {week: {dow: 4, doy: 6}});
  39933. assert.equal(moment([1985, 1, 7]).weekday(), 0, 'Feb 7 1985 is Thursday -- 0th day');
  39934. assert.equal(moment([2029, 8, 21]).weekday(), 1, 'Sep 21 2029 is Friday -- 1st day');
  39935. assert.equal(moment([2013, 3, 27]).weekday(), 2, 'Apr 27 2013 is Saturday -- 2nd day');
  39936. assert.equal(moment([2015, 2, 8]).weekday(), 3, 'Mar 8 2015 is Sunday -- 3nd day');
  39937. assert.equal(moment([1970, 0, 5]).weekday(), 4, 'Jan 5 1970 is Monday -- 4th day');
  39938. assert.equal(moment([2001, 4, 15]).weekday(), 5, 'May 15 2001 is Tuesday -- 5th day');
  39939. assert.equal(moment([2000, 0, 5]).weekday(), 6, 'Jan 5 2000 is Wednesday -- 6th day');
  39940. });
  39941. test('weekday first day of week Friday (dow 5)', function (assert) {
  39942. moment.locale('dow: 5,doy: 6', {week: {dow: 5, doy: 6}});
  39943. assert.equal(moment([1985, 1, 8]).weekday(), 0, 'Feb 8 1985 is Friday -- 0th day');
  39944. assert.equal(moment([2029, 8, 22]).weekday(), 1, 'Sep 22 2029 is Staturday -- 1st day');
  39945. assert.equal(moment([2013, 3, 28]).weekday(), 2, 'Apr 28 2013 is Sunday -- 2nd day');
  39946. assert.equal(moment([2015, 2, 9]).weekday(), 3, 'Mar 9 2015 is Monday -- 3nd day');
  39947. assert.equal(moment([1970, 0, 6]).weekday(), 4, 'Jan 6 1970 is Tuesday -- 4th day');
  39948. assert.equal(moment([2001, 4, 16]).weekday(), 5, 'May 16 2001 is Wednesday -- 5th day');
  39949. assert.equal(moment([2000, 0, 6]).weekday(), 6, 'Jan 6 2000 is Thursday -- 6th day');
  39950. });
  39951. test('weekday first day of week Saturday (dow 6)', function (assert) {
  39952. moment.locale('dow: 6,doy: 6', {week: {dow: 6, doy: 6}});
  39953. assert.equal(moment([1985, 1, 9]).weekday(), 0, 'Feb 9 1985 is Staturday -- 0th day');
  39954. assert.equal(moment([2029, 8, 23]).weekday(), 1, 'Sep 23 2029 is Sunday -- 1st day');
  39955. assert.equal(moment([2013, 3, 29]).weekday(), 2, 'Apr 29 2013 is Monday -- 2nd day');
  39956. assert.equal(moment([2015, 2, 10]).weekday(), 3, 'Mar 10 2015 is Tuesday -- 3nd day');
  39957. assert.equal(moment([1970, 0, 7]).weekday(), 4, 'Jan 7 1970 is Wednesday -- 4th day');
  39958. assert.equal(moment([2001, 4, 17]).weekday(), 5, 'May 17 2001 is Thursday -- 5th day');
  39959. assert.equal(moment([2000, 0, 7]).weekday(), 6, 'Jan 7 2000 is Friday -- 6th day');
  39960. });
  39961. }));
  39962. ;(function (global, factory) {
  39963. typeof exports === 'object' && typeof module !== 'undefined'
  39964. && typeof require === 'function' ? factory(require('../../moment')) :
  39965. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  39966. factory(global.moment)
  39967. }(this, function (moment) { 'use strict';
  39968. /*global QUnit:false*/
  39969. var test = QUnit.test;
  39970. var expect = QUnit.expect;
  39971. function module (name, lifecycle) {
  39972. QUnit.module(name, {
  39973. setup : function () {
  39974. moment.locale('en');
  39975. moment.createFromInputFallback = function (config) {
  39976. throw new Error('input not handled by moment: ' + config._i);
  39977. };
  39978. if (lifecycle && lifecycle.setup) {
  39979. lifecycle.setup();
  39980. }
  39981. },
  39982. teardown : function () {
  39983. if (lifecycle && lifecycle.teardown) {
  39984. lifecycle.teardown();
  39985. }
  39986. }
  39987. });
  39988. }
  39989. function localeModule (name, lifecycle) {
  39990. QUnit.module('locale:' + name, {
  39991. setup : function () {
  39992. moment.locale(name);
  39993. moment.createFromInputFallback = function (config) {
  39994. throw new Error('input not handled by moment: ' + config._i);
  39995. };
  39996. if (lifecycle && lifecycle.setup) {
  39997. lifecycle.setup();
  39998. }
  39999. },
  40000. teardown : function () {
  40001. moment.locale('en');
  40002. if (lifecycle && lifecycle.teardown) {
  40003. lifecycle.teardown();
  40004. }
  40005. }
  40006. });
  40007. }
  40008. module('weeks');
  40009. test('day of year', function (assert) {
  40010. assert.equal(moment([2000, 0, 1]).dayOfYear(), 1, 'Jan 1 2000 should be day 1 of the year');
  40011. assert.equal(moment([2000, 1, 28]).dayOfYear(), 59, 'Feb 28 2000 should be day 59 of the year');
  40012. assert.equal(moment([2000, 1, 29]).dayOfYear(), 60, 'Feb 28 2000 should be day 60 of the year');
  40013. assert.equal(moment([2000, 11, 31]).dayOfYear(), 366, 'Dec 31 2000 should be day 366 of the year');
  40014. assert.equal(moment([2001, 0, 1]).dayOfYear(), 1, 'Jan 1 2001 should be day 1 of the year');
  40015. assert.equal(moment([2001, 1, 28]).dayOfYear(), 59, 'Feb 28 2001 should be day 59 of the year');
  40016. assert.equal(moment([2001, 2, 1]).dayOfYear(), 60, 'Mar 1 2001 should be day 60 of the year');
  40017. assert.equal(moment([2001, 11, 31]).dayOfYear(), 365, 'Dec 31 2001 should be day 365 of the year');
  40018. });
  40019. test('day of year setters', function (assert) {
  40020. assert.equal(moment([2000, 0, 1]).dayOfYear(200).dayOfYear(), 200, 'Setting Jan 1 2000 day of the year to 200 should work');
  40021. assert.equal(moment([2000, 1, 28]).dayOfYear(200).dayOfYear(), 200, 'Setting Feb 28 2000 day of the year to 200 should work');
  40022. assert.equal(moment([2000, 1, 29]).dayOfYear(200).dayOfYear(), 200, 'Setting Feb 28 2000 day of the year to 200 should work');
  40023. assert.equal(moment([2000, 11, 31]).dayOfYear(200).dayOfYear(), 200, 'Setting Dec 31 2000 day of the year to 200 should work');
  40024. assert.equal(moment().dayOfYear(1).dayOfYear(), 1, 'Setting day of the year to 1 should work');
  40025. assert.equal(moment().dayOfYear(59).dayOfYear(), 59, 'Setting day of the year to 59 should work');
  40026. assert.equal(moment().dayOfYear(60).dayOfYear(), 60, 'Setting day of the year to 60 should work');
  40027. assert.equal(moment().dayOfYear(365).dayOfYear(), 365, 'Setting day of the year to 365 should work');
  40028. });
  40029. test('iso weeks year starting sunday', function (assert) {
  40030. assert.equal(moment([2012, 0, 1]).isoWeek(), 52, 'Jan 1 2012 should be iso week 52');
  40031. assert.equal(moment([2012, 0, 2]).isoWeek(), 1, 'Jan 2 2012 should be iso week 1');
  40032. assert.equal(moment([2012, 0, 8]).isoWeek(), 1, 'Jan 8 2012 should be iso week 1');
  40033. assert.equal(moment([2012, 0, 9]).isoWeek(), 2, 'Jan 9 2012 should be iso week 2');
  40034. assert.equal(moment([2012, 0, 15]).isoWeek(), 2, 'Jan 15 2012 should be iso week 2');
  40035. });
  40036. test('iso weeks year starting monday', function (assert) {
  40037. assert.equal(moment([2007, 0, 1]).isoWeek(), 1, 'Jan 1 2007 should be iso week 1');
  40038. assert.equal(moment([2007, 0, 7]).isoWeek(), 1, 'Jan 7 2007 should be iso week 1');
  40039. assert.equal(moment([2007, 0, 8]).isoWeek(), 2, 'Jan 8 2007 should be iso week 2');
  40040. assert.equal(moment([2007, 0, 14]).isoWeek(), 2, 'Jan 14 2007 should be iso week 2');
  40041. assert.equal(moment([2007, 0, 15]).isoWeek(), 3, 'Jan 15 2007 should be iso week 3');
  40042. });
  40043. test('iso weeks year starting tuesday', function (assert) {
  40044. assert.equal(moment([2007, 11, 31]).isoWeek(), 1, 'Dec 31 2007 should be iso week 1');
  40045. assert.equal(moment([2008, 0, 1]).isoWeek(), 1, 'Jan 1 2008 should be iso week 1');
  40046. assert.equal(moment([2008, 0, 6]).isoWeek(), 1, 'Jan 6 2008 should be iso week 1');
  40047. assert.equal(moment([2008, 0, 7]).isoWeek(), 2, 'Jan 7 2008 should be iso week 2');
  40048. assert.equal(moment([2008, 0, 13]).isoWeek(), 2, 'Jan 13 2008 should be iso week 2');
  40049. assert.equal(moment([2008, 0, 14]).isoWeek(), 3, 'Jan 14 2008 should be iso week 3');
  40050. });
  40051. test('iso weeks year starting wednesday', function (assert) {
  40052. assert.equal(moment([2002, 11, 30]).isoWeek(), 1, 'Dec 30 2002 should be iso week 1');
  40053. assert.equal(moment([2003, 0, 1]).isoWeek(), 1, 'Jan 1 2003 should be iso week 1');
  40054. assert.equal(moment([2003, 0, 5]).isoWeek(), 1, 'Jan 5 2003 should be iso week 1');
  40055. assert.equal(moment([2003, 0, 6]).isoWeek(), 2, 'Jan 6 2003 should be iso week 2');
  40056. assert.equal(moment([2003, 0, 12]).isoWeek(), 2, 'Jan 12 2003 should be iso week 2');
  40057. assert.equal(moment([2003, 0, 13]).isoWeek(), 3, 'Jan 13 2003 should be iso week 3');
  40058. });
  40059. test('iso weeks year starting thursday', function (assert) {
  40060. assert.equal(moment([2008, 11, 29]).isoWeek(), 1, 'Dec 29 2008 should be iso week 1');
  40061. assert.equal(moment([2009, 0, 1]).isoWeek(), 1, 'Jan 1 2009 should be iso week 1');
  40062. assert.equal(moment([2009, 0, 4]).isoWeek(), 1, 'Jan 4 2009 should be iso week 1');
  40063. assert.equal(moment([2009, 0, 5]).isoWeek(), 2, 'Jan 5 2009 should be iso week 2');
  40064. assert.equal(moment([2009, 0, 11]).isoWeek(), 2, 'Jan 11 2009 should be iso week 2');
  40065. assert.equal(moment([2009, 0, 13]).isoWeek(), 3, 'Jan 12 2009 should be iso week 3');
  40066. });
  40067. test('iso weeks year starting friday', function (assert) {
  40068. assert.equal(moment([2009, 11, 28]).isoWeek(), 53, 'Dec 28 2009 should be iso week 53');
  40069. assert.equal(moment([2010, 0, 1]).isoWeek(), 53, 'Jan 1 2010 should be iso week 53');
  40070. assert.equal(moment([2010, 0, 3]).isoWeek(), 53, 'Jan 3 2010 should be iso week 53');
  40071. assert.equal(moment([2010, 0, 4]).isoWeek(), 1, 'Jan 4 2010 should be iso week 1');
  40072. assert.equal(moment([2010, 0, 10]).isoWeek(), 1, 'Jan 10 2010 should be iso week 1');
  40073. assert.equal(moment([2010, 0, 11]).isoWeek(), 2, 'Jan 11 2010 should be iso week 2');
  40074. });
  40075. test('iso weeks year starting saturday', function (assert) {
  40076. assert.equal(moment([2010, 11, 27]).isoWeek(), 52, 'Dec 27 2010 should be iso week 52');
  40077. assert.equal(moment([2011, 0, 1]).isoWeek(), 52, 'Jan 1 2011 should be iso week 52');
  40078. assert.equal(moment([2011, 0, 2]).isoWeek(), 52, 'Jan 2 2011 should be iso week 52');
  40079. assert.equal(moment([2011, 0, 3]).isoWeek(), 1, 'Jan 3 2011 should be iso week 1');
  40080. assert.equal(moment([2011, 0, 9]).isoWeek(), 1, 'Jan 9 2011 should be iso week 1');
  40081. assert.equal(moment([2011, 0, 10]).isoWeek(), 2, 'Jan 10 2011 should be iso week 2');
  40082. });
  40083. test('iso weeks year starting sunday formatted', function (assert) {
  40084. assert.equal(moment([2012, 0, 1]).format('W WW Wo'), '52 52 52nd', 'Jan 1 2012 should be iso week 52');
  40085. assert.equal(moment([2012, 0, 2]).format('W WW Wo'), '1 01 1st', 'Jan 2 2012 should be iso week 1');
  40086. assert.equal(moment([2012, 0, 8]).format('W WW Wo'), '1 01 1st', 'Jan 8 2012 should be iso week 1');
  40087. assert.equal(moment([2012, 0, 9]).format('W WW Wo'), '2 02 2nd', 'Jan 9 2012 should be iso week 2');
  40088. assert.equal(moment([2012, 0, 15]).format('W WW Wo'), '2 02 2nd', 'Jan 15 2012 should be iso week 2');
  40089. });
  40090. test('weeks plural year starting sunday', function (assert) {
  40091. assert.equal(moment([2012, 0, 1]).weeks(), 1, 'Jan 1 2012 should be week 1');
  40092. assert.equal(moment([2012, 0, 7]).weeks(), 1, 'Jan 7 2012 should be week 1');
  40093. assert.equal(moment([2012, 0, 8]).weeks(), 2, 'Jan 8 2012 should be week 2');
  40094. assert.equal(moment([2012, 0, 14]).weeks(), 2, 'Jan 14 2012 should be week 2');
  40095. assert.equal(moment([2012, 0, 15]).weeks(), 3, 'Jan 15 2012 should be week 3');
  40096. });
  40097. test('iso weeks plural year starting sunday', function (assert) {
  40098. assert.equal(moment([2012, 0, 1]).isoWeeks(), 52, 'Jan 1 2012 should be iso week 52');
  40099. assert.equal(moment([2012, 0, 2]).isoWeeks(), 1, 'Jan 2 2012 should be iso week 1');
  40100. assert.equal(moment([2012, 0, 8]).isoWeeks(), 1, 'Jan 8 2012 should be iso week 1');
  40101. assert.equal(moment([2012, 0, 9]).isoWeeks(), 2, 'Jan 9 2012 should be iso week 2');
  40102. assert.equal(moment([2012, 0, 15]).isoWeeks(), 2, 'Jan 15 2012 should be iso week 2');
  40103. });
  40104. test('weeks setter', function (assert) {
  40105. assert.equal(moment([2012, 0, 1]).week(30).week(), 30, 'Setting Jan 1 2012 to week 30 should work');
  40106. assert.equal(moment([2012, 0, 7]).week(30).week(), 30, 'Setting Jan 7 2012 to week 30 should work');
  40107. assert.equal(moment([2012, 0, 8]).week(30).week(), 30, 'Setting Jan 8 2012 to week 30 should work');
  40108. assert.equal(moment([2012, 0, 14]).week(30).week(), 30, 'Setting Jan 14 2012 to week 30 should work');
  40109. assert.equal(moment([2012, 0, 15]).week(30).week(), 30, 'Setting Jan 15 2012 to week 30 should work');
  40110. });
  40111. test('iso weeks setter', function (assert) {
  40112. assert.equal(moment([2012, 0, 1]).isoWeeks(25).isoWeeks(), 25, 'Setting Jan 1 2012 to week 25 should work');
  40113. assert.equal(moment([2012, 0, 2]).isoWeeks(24).isoWeeks(), 24, 'Setting Jan 2 2012 to week 24 should work');
  40114. assert.equal(moment([2012, 0, 8]).isoWeeks(23).isoWeeks(), 23, 'Setting Jan 8 2012 to week 23 should work');
  40115. assert.equal(moment([2012, 0, 9]).isoWeeks(22).isoWeeks(), 22, 'Setting Jan 9 2012 to week 22 should work');
  40116. assert.equal(moment([2012, 0, 15]).isoWeeks(21).isoWeeks(), 21, 'Setting Jan 15 2012 to week 21 should work');
  40117. });
  40118. test('iso weeks setter day of year', function (assert) {
  40119. assert.equal(moment([2012, 0, 1]).isoWeek(1).dayOfYear(), 9, 'Setting Jan 1 2012 to week 1 should be day of year 8');
  40120. assert.equal(moment([2012, 0, 1]).isoWeek(1).year(), 2011, 'Setting Jan 1 2012 to week 1 should be year 2011');
  40121. assert.equal(moment([2012, 0, 2]).isoWeek(1).dayOfYear(), 2, 'Setting Jan 2 2012 to week 1 should be day of year 2');
  40122. assert.equal(moment([2012, 0, 8]).isoWeek(1).dayOfYear(), 8, 'Setting Jan 8 2012 to week 1 should be day of year 8');
  40123. assert.equal(moment([2012, 0, 9]).isoWeek(1).dayOfYear(), 2, 'Setting Jan 9 2012 to week 1 should be day of year 2');
  40124. assert.equal(moment([2012, 0, 15]).isoWeek(1).dayOfYear(), 8, 'Setting Jan 15 2012 to week 1 should be day of year 8');
  40125. });
  40126. test('years with iso week 53', function (assert) {
  40127. // Based on a table taken from http://en.wikipedia.org/wiki/ISO_week_date
  40128. // (as downloaded on 2014-01-06) listing the 71 years in a 400-year cycle
  40129. // that have 53 weeks; in this case reflecting the 2000 based cycle
  40130. assert.equal(moment([2004, 11, 31]).isoWeek(), 53, 'Dec 31 2004 should be iso week 53');
  40131. assert.equal(moment([2009, 11, 31]).isoWeek(), 53, 'Dec 31 2009 should be iso week 53');
  40132. assert.equal(moment([2015, 11, 31]).isoWeek(), 53, 'Dec 31 2015 should be iso week 53');
  40133. assert.equal(moment([2020, 11, 31]).isoWeek(), 53, 'Dec 31 2020 should be iso week 53');
  40134. assert.equal(moment([2026, 11, 31]).isoWeek(), 53, 'Dec 31 2026 should be iso week 53');
  40135. assert.equal(moment([2032, 11, 31]).isoWeek(), 53, 'Dec 31 2032 should be iso week 53');
  40136. assert.equal(moment([2037, 11, 31]).isoWeek(), 53, 'Dec 31 2037 should be iso week 53');
  40137. assert.equal(moment([2043, 11, 31]).isoWeek(), 53, 'Dec 31 2043 should be iso week 53');
  40138. assert.equal(moment([2048, 11, 31]).isoWeek(), 53, 'Dec 31 2048 should be iso week 53');
  40139. assert.equal(moment([2054, 11, 31]).isoWeek(), 53, 'Dec 31 2054 should be iso week 53');
  40140. assert.equal(moment([2060, 11, 31]).isoWeek(), 53, 'Dec 31 2060 should be iso week 53');
  40141. assert.equal(moment([2065, 11, 31]).isoWeek(), 53, 'Dec 31 2065 should be iso week 53');
  40142. assert.equal(moment([2071, 11, 31]).isoWeek(), 53, 'Dec 31 2071 should be iso week 53');
  40143. assert.equal(moment([2076, 11, 31]).isoWeek(), 53, 'Dec 31 2076 should be iso week 53');
  40144. assert.equal(moment([2082, 11, 31]).isoWeek(), 53, 'Dec 31 2082 should be iso week 53');
  40145. assert.equal(moment([2088, 11, 31]).isoWeek(), 53, 'Dec 31 2088 should be iso week 53');
  40146. assert.equal(moment([2093, 11, 31]).isoWeek(), 53, 'Dec 31 2093 should be iso week 53');
  40147. assert.equal(moment([2099, 11, 31]).isoWeek(), 53, 'Dec 31 2099 should be iso week 53');
  40148. assert.equal(moment([2105, 11, 31]).isoWeek(), 53, 'Dec 31 2105 should be iso week 53');
  40149. assert.equal(moment([2111, 11, 31]).isoWeek(), 53, 'Dec 31 2111 should be iso week 53');
  40150. assert.equal(moment([2116, 11, 31]).isoWeek(), 53, 'Dec 31 2116 should be iso week 53');
  40151. assert.equal(moment([2122, 11, 31]).isoWeek(), 53, 'Dec 31 2122 should be iso week 53');
  40152. assert.equal(moment([2128, 11, 31]).isoWeek(), 53, 'Dec 31 2128 should be iso week 53');
  40153. assert.equal(moment([2133, 11, 31]).isoWeek(), 53, 'Dec 31 2133 should be iso week 53');
  40154. assert.equal(moment([2139, 11, 31]).isoWeek(), 53, 'Dec 31 2139 should be iso week 53');
  40155. assert.equal(moment([2144, 11, 31]).isoWeek(), 53, 'Dec 31 2144 should be iso week 53');
  40156. assert.equal(moment([2150, 11, 31]).isoWeek(), 53, 'Dec 31 2150 should be iso week 53');
  40157. assert.equal(moment([2156, 11, 31]).isoWeek(), 53, 'Dec 31 2156 should be iso week 53');
  40158. assert.equal(moment([2161, 11, 31]).isoWeek(), 53, 'Dec 31 2161 should be iso week 53');
  40159. assert.equal(moment([2167, 11, 31]).isoWeek(), 53, 'Dec 31 2167 should be iso week 53');
  40160. assert.equal(moment([2172, 11, 31]).isoWeek(), 53, 'Dec 31 2172 should be iso week 53');
  40161. assert.equal(moment([2178, 11, 31]).isoWeek(), 53, 'Dec 31 2178 should be iso week 53');
  40162. assert.equal(moment([2184, 11, 31]).isoWeek(), 53, 'Dec 31 2184 should be iso week 53');
  40163. assert.equal(moment([2189, 11, 31]).isoWeek(), 53, 'Dec 31 2189 should be iso week 53');
  40164. assert.equal(moment([2195, 11, 31]).isoWeek(), 53, 'Dec 31 2195 should be iso week 53');
  40165. assert.equal(moment([2201, 11, 31]).isoWeek(), 53, 'Dec 31 2201 should be iso week 53');
  40166. assert.equal(moment([2207, 11, 31]).isoWeek(), 53, 'Dec 31 2207 should be iso week 53');
  40167. assert.equal(moment([2212, 11, 31]).isoWeek(), 53, 'Dec 31 2212 should be iso week 53');
  40168. assert.equal(moment([2218, 11, 31]).isoWeek(), 53, 'Dec 31 2218 should be iso week 53');
  40169. assert.equal(moment([2224, 11, 31]).isoWeek(), 53, 'Dec 31 2224 should be iso week 53');
  40170. assert.equal(moment([2229, 11, 31]).isoWeek(), 53, 'Dec 31 2229 should be iso week 53');
  40171. assert.equal(moment([2235, 11, 31]).isoWeek(), 53, 'Dec 31 2235 should be iso week 53');
  40172. assert.equal(moment([2240, 11, 31]).isoWeek(), 53, 'Dec 31 2240 should be iso week 53');
  40173. assert.equal(moment([2246, 11, 31]).isoWeek(), 53, 'Dec 31 2246 should be iso week 53');
  40174. assert.equal(moment([2252, 11, 31]).isoWeek(), 53, 'Dec 31 2252 should be iso week 53');
  40175. assert.equal(moment([2257, 11, 31]).isoWeek(), 53, 'Dec 31 2257 should be iso week 53');
  40176. assert.equal(moment([2263, 11, 31]).isoWeek(), 53, 'Dec 31 2263 should be iso week 53');
  40177. assert.equal(moment([2268, 11, 31]).isoWeek(), 53, 'Dec 31 2268 should be iso week 53');
  40178. assert.equal(moment([2274, 11, 31]).isoWeek(), 53, 'Dec 31 2274 should be iso week 53');
  40179. assert.equal(moment([2280, 11, 31]).isoWeek(), 53, 'Dec 31 2280 should be iso week 53');
  40180. assert.equal(moment([2285, 11, 31]).isoWeek(), 53, 'Dec 31 2285 should be iso week 53');
  40181. assert.equal(moment([2291, 11, 31]).isoWeek(), 53, 'Dec 31 2291 should be iso week 53');
  40182. assert.equal(moment([2296, 11, 31]).isoWeek(), 53, 'Dec 31 2296 should be iso week 53');
  40183. assert.equal(moment([2303, 11, 31]).isoWeek(), 53, 'Dec 31 2303 should be iso week 53');
  40184. assert.equal(moment([2308, 11, 31]).isoWeek(), 53, 'Dec 31 2308 should be iso week 53');
  40185. assert.equal(moment([2314, 11, 31]).isoWeek(), 53, 'Dec 31 2314 should be iso week 53');
  40186. assert.equal(moment([2320, 11, 31]).isoWeek(), 53, 'Dec 31 2320 should be iso week 53');
  40187. assert.equal(moment([2325, 11, 31]).isoWeek(), 53, 'Dec 31 2325 should be iso week 53');
  40188. assert.equal(moment([2331, 11, 31]).isoWeek(), 53, 'Dec 31 2331 should be iso week 53');
  40189. assert.equal(moment([2336, 11, 31]).isoWeek(), 53, 'Dec 31 2336 should be iso week 53');
  40190. assert.equal(moment([2342, 11, 31]).isoWeek(), 53, 'Dec 31 2342 should be iso week 53');
  40191. assert.equal(moment([2348, 11, 31]).isoWeek(), 53, 'Dec 31 2348 should be iso week 53');
  40192. assert.equal(moment([2353, 11, 31]).isoWeek(), 53, 'Dec 31 2353 should be iso week 53');
  40193. assert.equal(moment([2359, 11, 31]).isoWeek(), 53, 'Dec 31 2359 should be iso week 53');
  40194. assert.equal(moment([2364, 11, 31]).isoWeek(), 53, 'Dec 31 2364 should be iso week 53');
  40195. assert.equal(moment([2370, 11, 31]).isoWeek(), 53, 'Dec 31 2370 should be iso week 53');
  40196. assert.equal(moment([2376, 11, 31]).isoWeek(), 53, 'Dec 31 2376 should be iso week 53');
  40197. assert.equal(moment([2381, 11, 31]).isoWeek(), 53, 'Dec 31 2381 should be iso week 53');
  40198. assert.equal(moment([2387, 11, 31]).isoWeek(), 53, 'Dec 31 2387 should be iso week 53');
  40199. assert.equal(moment([2392, 11, 31]).isoWeek(), 53, 'Dec 31 2392 should be iso week 53');
  40200. assert.equal(moment([2398, 11, 31]).isoWeek(), 53, 'Dec 31 2398 should be iso week 53');
  40201. });
  40202. test('count years with iso week 53', function (assert) {
  40203. // Based on http://en.wikipedia.org/wiki/ISO_week_date (as seen on 2014-01-06)
  40204. // stating that there are 71 years in a 400-year cycle that have 53 weeks;
  40205. // in this case reflecting the 2000 based cycle
  40206. var count = 0, i;
  40207. for (i = 0; i < 400; i++) {
  40208. count += (moment([2000 + i, 11, 31]).isoWeek() === 53) ? 1 : 0;
  40209. }
  40210. assert.equal(count, 71, 'Should have 71 years in 400-year cycle with iso week 53');
  40211. });
  40212. }));
  40213. ;(function (global, factory) {
  40214. typeof exports === 'object' && typeof module !== 'undefined'
  40215. && typeof require === 'function' ? factory(require('../../moment')) :
  40216. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  40217. factory(global.moment)
  40218. }(this, function (moment) { 'use strict';
  40219. /*global QUnit:false*/
  40220. var test = QUnit.test;
  40221. var expect = QUnit.expect;
  40222. function module (name, lifecycle) {
  40223. QUnit.module(name, {
  40224. setup : function () {
  40225. moment.locale('en');
  40226. moment.createFromInputFallback = function (config) {
  40227. throw new Error('input not handled by moment: ' + config._i);
  40228. };
  40229. if (lifecycle && lifecycle.setup) {
  40230. lifecycle.setup();
  40231. }
  40232. },
  40233. teardown : function () {
  40234. if (lifecycle && lifecycle.teardown) {
  40235. lifecycle.teardown();
  40236. }
  40237. }
  40238. });
  40239. }
  40240. function localeModule (name, lifecycle) {
  40241. QUnit.module('locale:' + name, {
  40242. setup : function () {
  40243. moment.locale(name);
  40244. moment.createFromInputFallback = function (config) {
  40245. throw new Error('input not handled by moment: ' + config._i);
  40246. };
  40247. if (lifecycle && lifecycle.setup) {
  40248. lifecycle.setup();
  40249. }
  40250. },
  40251. teardown : function () {
  40252. moment.locale('en');
  40253. if (lifecycle && lifecycle.teardown) {
  40254. lifecycle.teardown();
  40255. }
  40256. }
  40257. });
  40258. }
  40259. module('weeks in year');
  40260. test('isoWeeksInYear', function (assert) {
  40261. assert.equal(moment([2004]).isoWeeksInYear(), 53, '2004 has 53 iso weeks');
  40262. assert.equal(moment([2005]).isoWeeksInYear(), 52, '2005 has 53 iso weeks');
  40263. assert.equal(moment([2006]).isoWeeksInYear(), 52, '2006 has 53 iso weeks');
  40264. assert.equal(moment([2007]).isoWeeksInYear(), 52, '2007 has 52 iso weeks');
  40265. assert.equal(moment([2008]).isoWeeksInYear(), 52, '2008 has 53 iso weeks');
  40266. assert.equal(moment([2009]).isoWeeksInYear(), 53, '2009 has 53 iso weeks');
  40267. assert.equal(moment([2010]).isoWeeksInYear(), 52, '2010 has 52 iso weeks');
  40268. assert.equal(moment([2011]).isoWeeksInYear(), 52, '2011 has 52 iso weeks');
  40269. assert.equal(moment([2012]).isoWeeksInYear(), 52, '2012 has 52 iso weeks');
  40270. assert.equal(moment([2013]).isoWeeksInYear(), 52, '2013 has 52 iso weeks');
  40271. assert.equal(moment([2014]).isoWeeksInYear(), 52, '2014 has 52 iso weeks');
  40272. assert.equal(moment([2015]).isoWeeksInYear(), 53, '2015 has 53 iso weeks');
  40273. });
  40274. test('weeksInYear doy/dow = 1/4', function (assert) {
  40275. moment.locale('1/4', {week: {dow: 1, doy: 4}});
  40276. assert.equal(moment([2004]).weeksInYear(), 53, '2004 has 53 weeks');
  40277. assert.equal(moment([2005]).weeksInYear(), 52, '2005 has 53 weeks');
  40278. assert.equal(moment([2006]).weeksInYear(), 52, '2006 has 53 weeks');
  40279. assert.equal(moment([2007]).weeksInYear(), 52, '2007 has 52 weeks');
  40280. assert.equal(moment([2008]).weeksInYear(), 52, '2008 has 53 weeks');
  40281. assert.equal(moment([2009]).weeksInYear(), 53, '2009 has 53 weeks');
  40282. assert.equal(moment([2010]).weeksInYear(), 52, '2010 has 52 weeks');
  40283. assert.equal(moment([2011]).weeksInYear(), 52, '2011 has 52 weeks');
  40284. assert.equal(moment([2012]).weeksInYear(), 52, '2012 has 52 weeks');
  40285. assert.equal(moment([2013]).weeksInYear(), 52, '2013 has 52 weeks');
  40286. assert.equal(moment([2014]).weeksInYear(), 52, '2014 has 52 weeks');
  40287. assert.equal(moment([2015]).weeksInYear(), 53, '2015 has 53 weeks');
  40288. });
  40289. test('weeksInYear doy/dow = 6/12', function (assert) {
  40290. moment.locale('6/12', {week: {dow: 6, doy: 12}});
  40291. assert.equal(moment([2004]).weeksInYear(), 53, '2004 has 53 weeks');
  40292. assert.equal(moment([2005]).weeksInYear(), 52, '2005 has 53 weeks');
  40293. assert.equal(moment([2006]).weeksInYear(), 52, '2006 has 53 weeks');
  40294. assert.equal(moment([2007]).weeksInYear(), 52, '2007 has 52 weeks');
  40295. assert.equal(moment([2008]).weeksInYear(), 52, '2008 has 53 weeks');
  40296. assert.equal(moment([2009]).weeksInYear(), 52, '2009 has 53 weeks');
  40297. assert.equal(moment([2010]).weeksInYear(), 53, '2010 has 52 weeks');
  40298. assert.equal(moment([2011]).weeksInYear(), 52, '2011 has 52 weeks');
  40299. assert.equal(moment([2012]).weeksInYear(), 52, '2012 has 52 weeks');
  40300. assert.equal(moment([2013]).weeksInYear(), 52, '2013 has 52 weeks');
  40301. assert.equal(moment([2014]).weeksInYear(), 52, '2014 has 52 weeks');
  40302. assert.equal(moment([2015]).weeksInYear(), 52, '2015 has 53 weeks');
  40303. });
  40304. test('weeksInYear doy/dow = 1/7', function (assert) {
  40305. moment.locale('1/7', {week: {dow: 1, doy: 7}});
  40306. assert.equal(moment([2004]).weeksInYear(), 52, '2004 has 53 weeks');
  40307. assert.equal(moment([2005]).weeksInYear(), 52, '2005 has 53 weeks');
  40308. assert.equal(moment([2006]).weeksInYear(), 53, '2006 has 53 weeks');
  40309. assert.equal(moment([2007]).weeksInYear(), 52, '2007 has 52 weeks');
  40310. assert.equal(moment([2008]).weeksInYear(), 52, '2008 has 53 weeks');
  40311. assert.equal(moment([2009]).weeksInYear(), 52, '2009 has 53 weeks');
  40312. assert.equal(moment([2010]).weeksInYear(), 52, '2010 has 52 weeks');
  40313. assert.equal(moment([2011]).weeksInYear(), 52, '2011 has 52 weeks');
  40314. assert.equal(moment([2012]).weeksInYear(), 53, '2012 has 52 weeks');
  40315. assert.equal(moment([2013]).weeksInYear(), 52, '2013 has 52 weeks');
  40316. assert.equal(moment([2014]).weeksInYear(), 52, '2014 has 52 weeks');
  40317. assert.equal(moment([2015]).weeksInYear(), 52, '2015 has 53 weeks');
  40318. });
  40319. test('weeksInYear doy/dow = 0/6', function (assert) {
  40320. moment.locale('0/6', {week: {dow: 0, doy: 6}});
  40321. assert.equal(moment([2004]).weeksInYear(), 52, '2004 has 53 weeks');
  40322. assert.equal(moment([2005]).weeksInYear(), 53, '2005 has 53 weeks');
  40323. assert.equal(moment([2006]).weeksInYear(), 52, '2006 has 53 weeks');
  40324. assert.equal(moment([2007]).weeksInYear(), 52, '2007 has 52 weeks');
  40325. assert.equal(moment([2008]).weeksInYear(), 52, '2008 has 53 weeks');
  40326. assert.equal(moment([2009]).weeksInYear(), 52, '2009 has 53 weeks');
  40327. assert.equal(moment([2010]).weeksInYear(), 52, '2010 has 52 weeks');
  40328. assert.equal(moment([2011]).weeksInYear(), 53, '2011 has 52 weeks');
  40329. assert.equal(moment([2012]).weeksInYear(), 52, '2012 has 52 weeks');
  40330. assert.equal(moment([2013]).weeksInYear(), 52, '2013 has 52 weeks');
  40331. assert.equal(moment([2014]).weeksInYear(), 52, '2014 has 52 weeks');
  40332. assert.equal(moment([2015]).weeksInYear(), 52, '2015 has 53 weeks');
  40333. });
  40334. }));
  40335. ;(function (global, factory) {
  40336. typeof exports === 'object' && typeof module !== 'undefined'
  40337. && typeof require === 'function' ? factory(require('../../moment')) :
  40338. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  40339. factory(global.moment)
  40340. }(this, function (moment) { 'use strict';
  40341. /*global QUnit:false*/
  40342. var test = QUnit.test;
  40343. var expect = QUnit.expect;
  40344. function module (name, lifecycle) {
  40345. QUnit.module(name, {
  40346. setup : function () {
  40347. moment.locale('en');
  40348. moment.createFromInputFallback = function (config) {
  40349. throw new Error('input not handled by moment: ' + config._i);
  40350. };
  40351. if (lifecycle && lifecycle.setup) {
  40352. lifecycle.setup();
  40353. }
  40354. },
  40355. teardown : function () {
  40356. if (lifecycle && lifecycle.teardown) {
  40357. lifecycle.teardown();
  40358. }
  40359. }
  40360. });
  40361. }
  40362. function localeModule (name, lifecycle) {
  40363. QUnit.module('locale:' + name, {
  40364. setup : function () {
  40365. moment.locale(name);
  40366. moment.createFromInputFallback = function (config) {
  40367. throw new Error('input not handled by moment: ' + config._i);
  40368. };
  40369. if (lifecycle && lifecycle.setup) {
  40370. lifecycle.setup();
  40371. }
  40372. },
  40373. teardown : function () {
  40374. moment.locale('en');
  40375. if (lifecycle && lifecycle.teardown) {
  40376. lifecycle.teardown();
  40377. }
  40378. }
  40379. });
  40380. }
  40381. module('zone switching');
  40382. test('local to utc, keepLocalTime = true', function (assert) {
  40383. var m = moment(),
  40384. fmt = 'YYYY-DD-MM HH:mm:ss';
  40385. assert.equal(m.clone().utc(true).format(fmt), m.format(fmt), 'local to utc failed to keep local time');
  40386. });
  40387. test('local to utc, keepLocalTime = false', function (assert) {
  40388. var m = moment();
  40389. assert.equal(m.clone().utc().valueOf(), m.valueOf(), 'local to utc failed to keep utc time (implicit)');
  40390. assert.equal(m.clone().utc(false).valueOf(), m.valueOf(), 'local to utc failed to keep utc time (explicit)');
  40391. });
  40392. test('local to zone, keepLocalTime = true', function (assert) {
  40393. var m = moment(),
  40394. fmt = 'YYYY-DD-MM HH:mm:ss',
  40395. z;
  40396. // Apparently there is -12:00 and +14:00
  40397. // http://en.wikipedia.org/wiki/UTC+14:00
  40398. // http://en.wikipedia.org/wiki/UTC-12:00
  40399. for (z = -12; z <= 14; ++z) {
  40400. assert.equal(m.clone().zone(z * 60, true).format(fmt), m.format(fmt),
  40401. 'local to zone(' + z + ':00) failed to keep local time');
  40402. }
  40403. });
  40404. test('local to zone, keepLocalTime = false', function (assert) {
  40405. var m = moment(),
  40406. z;
  40407. // Apparently there is -12:00 and +14:00
  40408. // http://en.wikipedia.org/wiki/UTC+14:00
  40409. // http://en.wikipedia.org/wiki/UTC-12:00
  40410. for (z = -12; z <= 14; ++z) {
  40411. assert.equal(m.clone().zone(z * 60).valueOf(), m.valueOf(),
  40412. 'local to zone(' + z + ':00) failed to keep utc time (implicit)');
  40413. assert.equal(m.clone().zone(z * 60, false).valueOf(), m.valueOf(),
  40414. 'local to zone(' + z + ':00) failed to keep utc time (explicit)');
  40415. }
  40416. });
  40417. test('utc to local, keepLocalTime = true', function (assert) {
  40418. var um = moment.utc(),
  40419. fmt = 'YYYY-DD-MM HH:mm:ss';
  40420. assert.equal(um.clone().local(true).format(fmt), um.format(fmt), 'utc to local failed to keep local time');
  40421. });
  40422. test('utc to local, keepLocalTime = false', function (assert) {
  40423. var um = moment.utc();
  40424. assert.equal(um.clone().local().valueOf(), um.valueOf(), 'utc to local failed to keep utc time (implicit)');
  40425. assert.equal(um.clone().local(false).valueOf(), um.valueOf(), 'utc to local failed to keep utc time (explicit)');
  40426. });
  40427. test('zone to local, keepLocalTime = true', function (assert) {
  40428. var m = moment(),
  40429. fmt = 'YYYY-DD-MM HH:mm:ss',
  40430. z;
  40431. // Apparently there is -12:00 and +14:00
  40432. // http://en.wikipedia.org/wiki/UTC+14:00
  40433. // http://en.wikipedia.org/wiki/UTC-12:00
  40434. for (z = -12; z <= 14; ++z) {
  40435. m.zone(z * 60);
  40436. assert.equal(m.clone().local(true).format(fmt), m.format(fmt),
  40437. 'zone(' + z + ':00) to local failed to keep local time');
  40438. }
  40439. });
  40440. test('zone to local, keepLocalTime = false', function (assert) {
  40441. var m = moment(),
  40442. z;
  40443. // Apparently there is -12:00 and +14:00
  40444. // http://en.wikipedia.org/wiki/UTC+14:00
  40445. // http://en.wikipedia.org/wiki/UTC-12:00
  40446. for (z = -12; z <= 14; ++z) {
  40447. m.zone(z * 60);
  40448. assert.equal(m.clone().local(false).valueOf(), m.valueOf(),
  40449. 'zone(' + z + ':00) to local failed to keep utc time (explicit)');
  40450. assert.equal(m.clone().local().valueOf(), m.valueOf(),
  40451. 'zone(' + z + ':00) to local failed to keep utc time (implicit)');
  40452. }
  40453. });
  40454. }));
  40455. ;(function (global, factory) {
  40456. typeof exports === 'object' && typeof module !== 'undefined'
  40457. && typeof require === 'function' ? factory(require('../../moment')) :
  40458. typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
  40459. factory(global.moment)
  40460. }(this, function (moment) { 'use strict';
  40461. /*global QUnit:false*/
  40462. var test = QUnit.test;
  40463. var expect = QUnit.expect;
  40464. function module (name, lifecycle) {
  40465. QUnit.module(name, {
  40466. setup : function () {
  40467. moment.locale('en');
  40468. moment.createFromInputFallback = function (config) {
  40469. throw new Error('input not handled by moment: ' + config._i);
  40470. };
  40471. if (lifecycle && lifecycle.setup) {
  40472. lifecycle.setup();
  40473. }
  40474. },
  40475. teardown : function () {
  40476. if (lifecycle && lifecycle.teardown) {
  40477. lifecycle.teardown();
  40478. }
  40479. }
  40480. });
  40481. }
  40482. function localeModule (name, lifecycle) {
  40483. QUnit.module('locale:' + name, {
  40484. setup : function () {
  40485. moment.locale(name);
  40486. moment.createFromInputFallback = function (config) {
  40487. throw new Error('input not handled by moment: ' + config._i);
  40488. };
  40489. if (lifecycle && lifecycle.setup) {
  40490. lifecycle.setup();
  40491. }
  40492. },
  40493. teardown : function () {
  40494. moment.locale('en');
  40495. if (lifecycle && lifecycle.teardown) {
  40496. lifecycle.teardown();
  40497. }
  40498. }
  40499. });
  40500. }
  40501. module('zones');
  40502. test('set zone', function (assert) {
  40503. var zone = moment();
  40504. zone.zone(0);
  40505. assert.equal(zone.zone(), 0, 'should be able to set the zone to 0');
  40506. zone.zone(60);
  40507. assert.equal(zone.zone(), 60, 'should be able to set the zone to 60');
  40508. zone.zone(-60);
  40509. assert.equal(zone.zone(), -60, 'should be able to set the zone to -60');
  40510. });
  40511. test('set zone shorthand', function (assert) {
  40512. var zone = moment();
  40513. zone.zone(1);
  40514. assert.equal(zone.zone(), 60, 'setting the zone to 1 should imply hours and convert to 60');
  40515. zone.zone(-1);
  40516. assert.equal(zone.zone(), -60, 'setting the zone to -1 should imply hours and convert to -60');
  40517. zone.zone(15);
  40518. assert.equal(zone.zone(), 900, 'setting the zone to 15 should imply hours and convert to 900');
  40519. zone.zone(-15);
  40520. assert.equal(zone.zone(), -900, 'setting the zone to -15 should imply hours and convert to -900');
  40521. zone.zone(16);
  40522. assert.equal(zone.zone(), 16, 'setting the zone to 16 should imply minutes');
  40523. zone.zone(-16);
  40524. assert.equal(zone.zone(), -16, 'setting the zone to -16 should imply minutes');
  40525. });
  40526. test('set zone with string', function (assert) {
  40527. var zone = moment();
  40528. zone.zone('+00:00');
  40529. assert.equal(zone.zone(), 0, 'set the zone with a timezone string');
  40530. zone.zone('2013-03-07T07:00:00-08:00');
  40531. assert.equal(zone.zone(), 480, 'set the zone with a string that does not begin with the timezone');
  40532. zone.zone('2013-03-07T07:00:00+0100');
  40533. assert.equal(zone.zone(), -60, 'set the zone with a string that uses the +0000 syntax');
  40534. zone.zone('2013-03-07T07:00:00+02');
  40535. assert.equal(zone.zone(), -120, 'set the zone with a string that uses the +00 syntax');
  40536. zone.zone('03-07-2013T07:00:00-08:00');
  40537. assert.equal(zone.zone(), 480, 'set the zone with a string with a non-ISO 8601 date');
  40538. });
  40539. test('change hours when changing the zone', function (assert) {
  40540. var zone = moment.utc([2000, 0, 1, 6]);
  40541. zone.zone(0);
  40542. assert.equal(zone.hour(), 6, 'UTC 6AM should be 6AM at +0000');
  40543. zone.zone(60);
  40544. assert.equal(zone.hour(), 5, 'UTC 6AM should be 5AM at -0100');
  40545. zone.zone(-60);
  40546. assert.equal(zone.hour(), 7, 'UTC 6AM should be 7AM at +0100');
  40547. });
  40548. test('change minutes when changing the zone', function (assert) {
  40549. var zone = moment.utc([2000, 0, 1, 6, 31]);
  40550. zone.zone(0);
  40551. assert.equal(zone.format('HH:mm'), '06:31', 'UTC 6:31AM should be 6:31AM at +0000');
  40552. zone.zone(30);
  40553. assert.equal(zone.format('HH:mm'), '06:01', 'UTC 6:31AM should be 6:01AM at -0030');
  40554. zone.zone(-30);
  40555. assert.equal(zone.format('HH:mm'), '07:01', 'UTC 6:31AM should be 7:01AM at +0030');
  40556. zone.zone(1380);
  40557. assert.equal(zone.format('HH:mm'), '07:31', 'UTC 6:31AM should be 7:31AM at +1380');
  40558. });
  40559. test('distance from the unix epoch', function (assert) {
  40560. var zoneA = moment(),
  40561. zoneB = moment(zoneA),
  40562. zoneC = moment(zoneA),
  40563. zoneD = moment(zoneA),
  40564. zoneE = moment(zoneA);
  40565. zoneB.utc();
  40566. assert.equal(+zoneA, +zoneB, 'moment should equal moment.utc');
  40567. zoneC.zone(-60);
  40568. assert.equal(+zoneA, +zoneC, 'moment should equal moment.zone(-60)');
  40569. zoneD.zone(480);
  40570. assert.equal(+zoneA, +zoneD, 'moment should equal moment.zone(480)');
  40571. zoneE.zone(1000);
  40572. assert.equal(+zoneA, +zoneE, 'moment should equal moment.zone(1000)');
  40573. });
  40574. test('update offset after changing any values', function (assert) {
  40575. var oldOffset = moment.updateOffset,
  40576. m = moment.utc([2000, 6, 1]);
  40577. moment.updateOffset = function (mom, keepTime) {
  40578. if (mom.__doChange) {
  40579. if (+mom > 962409600000) {
  40580. mom.zone(120, keepTime);
  40581. } else {
  40582. mom.zone(60, keepTime);
  40583. }
  40584. }
  40585. };
  40586. assert.equal(m.format('ZZ'), '+0000', 'should be at +0000');
  40587. assert.equal(m.format('HH:mm'), '00:00', 'should start 12AM at +0000 timezone');
  40588. m.__doChange = true;
  40589. m.add(1, 'h');
  40590. assert.equal(m.format('ZZ'), '-0200', 'should be at -0200');
  40591. assert.equal(m.format('HH:mm'), '23:00', '1AM at +0000 should be 11PM at -0200 timezone');
  40592. m.subtract(1, 'h');
  40593. assert.equal(m.format('ZZ'), '-0100', 'should be at -0100');
  40594. assert.equal(m.format('HH:mm'), '23:00', '12AM at +0000 should be 11PM at -0100 timezone');
  40595. moment.updateOffset = oldOffset;
  40596. });
  40597. test('getters and setters', function (assert) {
  40598. var a = moment([2011, 5, 20]);
  40599. assert.equal(a.clone().zone(120).year(2012).year(), 2012, 'should get and set year correctly');
  40600. assert.equal(a.clone().zone(120).month(1).month(), 1, 'should get and set month correctly');
  40601. assert.equal(a.clone().zone(120).date(2).date(), 2, 'should get and set date correctly');
  40602. assert.equal(a.clone().zone(120).day(1).day(), 1, 'should get and set day correctly');
  40603. assert.equal(a.clone().zone(120).hour(1).hour(), 1, 'should get and set hour correctly');
  40604. assert.equal(a.clone().zone(120).minute(1).minute(), 1, 'should get and set minute correctly');
  40605. });
  40606. test('getters', function (assert) {
  40607. var a = moment.utc([2012, 0, 1, 0, 0, 0]);
  40608. assert.equal(a.clone().zone(120).year(), 2011, 'should get year correctly');
  40609. assert.equal(a.clone().zone(120).month(), 11, 'should get month correctly');
  40610. assert.equal(a.clone().zone(120).date(), 31, 'should get date correctly');
  40611. assert.equal(a.clone().zone(120).hour(), 22, 'should get hour correctly');
  40612. assert.equal(a.clone().zone(120).minute(), 0, 'should get minute correctly');
  40613. assert.equal(a.clone().zone(-120).year(), 2012, 'should get year correctly');
  40614. assert.equal(a.clone().zone(-120).month(), 0, 'should get month correctly');
  40615. assert.equal(a.clone().zone(-120).date(), 1, 'should get date correctly');
  40616. assert.equal(a.clone().zone(-120).hour(), 2, 'should get hour correctly');
  40617. assert.equal(a.clone().zone(-120).minute(), 0, 'should get minute correctly');
  40618. assert.equal(a.clone().zone(-90).year(), 2012, 'should get year correctly');
  40619. assert.equal(a.clone().zone(-90).month(), 0, 'should get month correctly');
  40620. assert.equal(a.clone().zone(-90).date(), 1, 'should get date correctly');
  40621. assert.equal(a.clone().zone(-90).hour(), 1, 'should get hour correctly');
  40622. assert.equal(a.clone().zone(-90).minute(), 30, 'should get minute correctly');
  40623. });
  40624. test('from', function (assert) {
  40625. var zoneA = moment(),
  40626. zoneB = moment(zoneA).zone(720),
  40627. zoneC = moment(zoneA).zone(360),
  40628. zoneD = moment(zoneA).zone(-690),
  40629. other = moment(zoneA).add(35, 'm');
  40630. assert.equal(zoneA.from(other), zoneB.from(other), 'moment#from should be the same in all zones');
  40631. assert.equal(zoneA.from(other), zoneC.from(other), 'moment#from should be the same in all zones');
  40632. assert.equal(zoneA.from(other), zoneD.from(other), 'moment#from should be the same in all zones');
  40633. });
  40634. test('diff', function (assert) {
  40635. var zoneA = moment(),
  40636. zoneB = moment(zoneA).zone(720),
  40637. zoneC = moment(zoneA).zone(360),
  40638. zoneD = moment(zoneA).zone(-690),
  40639. other = moment(zoneA).add(35, 'm');
  40640. assert.equal(zoneA.diff(other), zoneB.diff(other), 'moment#diff should be the same in all zones');
  40641. assert.equal(zoneA.diff(other), zoneC.diff(other), 'moment#diff should be the same in all zones');
  40642. assert.equal(zoneA.diff(other), zoneD.diff(other), 'moment#diff should be the same in all zones');
  40643. assert.equal(zoneA.diff(other, 'minute', true), zoneB.diff(other, 'minute', true), 'moment#diff should be the same in all zones');
  40644. assert.equal(zoneA.diff(other, 'minute', true), zoneC.diff(other, 'minute', true), 'moment#diff should be the same in all zones');
  40645. assert.equal(zoneA.diff(other, 'minute', true), zoneD.diff(other, 'minute', true), 'moment#diff should be the same in all zones');
  40646. assert.equal(zoneA.diff(other, 'hour', true), zoneB.diff(other, 'hour', true), 'moment#diff should be the same in all zones');
  40647. assert.equal(zoneA.diff(other, 'hour', true), zoneC.diff(other, 'hour', true), 'moment#diff should be the same in all zones');
  40648. assert.equal(zoneA.diff(other, 'hour', true), zoneD.diff(other, 'hour', true), 'moment#diff should be the same in all zones');
  40649. });
  40650. test('unix offset and timestamp', function (assert) {
  40651. var zoneA = moment(),
  40652. zoneB = moment(zoneA).zone(720),
  40653. zoneC = moment(zoneA).zone(360),
  40654. zoneD = moment(zoneA).zone(-690);
  40655. assert.equal(zoneA.unix(), zoneB.unix(), 'moment#unix should be the same in all zones');
  40656. assert.equal(zoneA.unix(), zoneC.unix(), 'moment#unix should be the same in all zones');
  40657. assert.equal(zoneA.unix(), zoneD.unix(), 'moment#unix should be the same in all zones');
  40658. assert.equal(+zoneA, +zoneB, 'moment#valueOf should be the same in all zones');
  40659. assert.equal(+zoneA, +zoneC, 'moment#valueOf should be the same in all zones');
  40660. assert.equal(+zoneA, +zoneD, 'moment#valueOf should be the same in all zones');
  40661. });
  40662. test('cloning', function (assert) {
  40663. assert.equal(moment().zone(120).clone().zone(), 120, 'explicit cloning should retain the zone');
  40664. assert.equal(moment().zone(-120).clone().zone(), -120, 'explicit cloning should retain the zone');
  40665. assert.equal(moment(moment().zone(120)).zone(), 120, 'implicit cloning should retain the zone');
  40666. assert.equal(moment(moment().zone(-120)).zone(), -120, 'implicit cloning should retain the zone');
  40667. });
  40668. test('start of / end of', function (assert) {
  40669. var a = moment.utc([2010, 1, 2, 0, 0, 0]).zone(450);
  40670. assert.equal(a.clone().startOf('day').hour(), 0, 'start of day should work on moments with a zone');
  40671. assert.equal(a.clone().startOf('day').minute(), 0, 'start of day should work on moments with a zone');
  40672. assert.equal(a.clone().startOf('hour').minute(), 0, 'start of hour should work on moments with a zone');
  40673. assert.equal(a.clone().endOf('day').hour(), 23, 'end of day should work on moments with a zone');
  40674. assert.equal(a.clone().endOf('day').minute(), 59, 'end of day should work on moments with a zone');
  40675. assert.equal(a.clone().endOf('hour').minute(), 59, 'end of hour should work on moments with a zone');
  40676. });
  40677. test('reset zone with moment#utc', function (assert) {
  40678. var a = moment.utc([2012]).zone(480);
  40679. assert.equal(a.clone().hour(), 16, 'different zone should have different hour');
  40680. assert.equal(a.clone().utc().hour(), 0, 'calling moment#utc should reset the offset');
  40681. });
  40682. test('reset zone with moment#local', function (assert) {
  40683. var a = moment([2012]).zone(480);
  40684. assert.equal(a.clone().local().hour(), 0, 'calling moment#local should reset the offset');
  40685. });
  40686. test('toDate', function (assert) {
  40687. var zoneA = new Date(),
  40688. zoneB = moment(zoneA).zone(720).toDate(),
  40689. zoneC = moment(zoneA).zone(360).toDate(),
  40690. zoneD = moment(zoneA).zone(-690).toDate();
  40691. assert.equal(+zoneA, +zoneB, 'moment#toDate should output a date with the right unix timestamp');
  40692. assert.equal(+zoneA, +zoneC, 'moment#toDate should output a date with the right unix timestamp');
  40693. assert.equal(+zoneA, +zoneD, 'moment#toDate should output a date with the right unix timestamp');
  40694. });
  40695. test('same / before / after', function (assert) {
  40696. var zoneA = moment().utc(),
  40697. zoneB = moment(zoneA).zone(120),
  40698. zoneC = moment(zoneA).zone(-120);
  40699. assert.ok(zoneA.isSame(zoneB), 'two moments with different offsets should be the same');
  40700. assert.ok(zoneA.isSame(zoneC), 'two moments with different offsets should be the same');
  40701. assert.ok(zoneA.isSame(zoneB, 'hour'), 'two moments with different offsets should be the same hour');
  40702. assert.ok(zoneA.isSame(zoneC, 'hour'), 'two moments with different offsets should be the same hour');
  40703. zoneA.add(1, 'hour');
  40704. assert.ok(zoneA.isAfter(zoneB), 'isAfter should work with two moments with different offsets');
  40705. assert.ok(zoneA.isAfter(zoneC), 'isAfter should work with two moments with different offsets');
  40706. assert.ok(zoneA.isAfter(zoneB, 'hour'), 'isAfter:hour should work with two moments with different offsets');
  40707. assert.ok(zoneA.isAfter(zoneC, 'hour'), 'isAfter:hour should work with two moments with different offsets');
  40708. zoneA.subtract(2, 'hour');
  40709. assert.ok(zoneA.isBefore(zoneB), 'isBefore should work with two moments with different offsets');
  40710. assert.ok(zoneA.isBefore(zoneC), 'isBefore should work with two moments with different offsets');
  40711. assert.ok(zoneA.isBefore(zoneB, 'hour'), 'isBefore:hour should work with two moments with different offsets');
  40712. assert.ok(zoneA.isBefore(zoneC, 'hour'), 'isBefore:hour should work with two moments with different offsets');
  40713. });
  40714. test('add / subtract over dst', function (assert) {
  40715. var oldOffset = moment.updateOffset,
  40716. m = moment.utc([2000, 2, 31, 3]);
  40717. moment.updateOffset = function (mom, keepTime) {
  40718. if (mom.clone().utc().month() > 2) {
  40719. mom.zone(-60, keepTime);
  40720. } else {
  40721. mom.zone(0, keepTime);
  40722. }
  40723. };
  40724. assert.equal(m.hour(), 3, 'should start at 00:00');
  40725. m.add(24, 'hour');
  40726. assert.equal(m.hour(), 4, 'adding 24 hours should disregard dst');
  40727. m.subtract(24, 'hour');
  40728. assert.equal(m.hour(), 3, 'subtracting 24 hours should disregard dst');
  40729. m.add(1, 'day');
  40730. assert.equal(m.hour(), 3, 'adding 1 day should have the same hour');
  40731. m.subtract(1, 'day');
  40732. assert.equal(m.hour(), 3, 'subtracting 1 day should have the same hour');
  40733. m.add(1, 'month');
  40734. assert.equal(m.hour(), 3, 'adding 1 month should have the same hour');
  40735. m.subtract(1, 'month');
  40736. assert.equal(m.hour(), 3, 'subtracting 1 month should have the same hour');
  40737. moment.updateOffset = oldOffset;
  40738. });
  40739. test('isDST', function (assert) {
  40740. var oldOffset = moment.updateOffset;
  40741. moment.updateOffset = function (mom, keepTime) {
  40742. if (mom.month() > 2 && mom.month() < 9) {
  40743. mom.zone(-60, keepTime);
  40744. } else {
  40745. mom.zone(0, keepTime);
  40746. }
  40747. };
  40748. assert.ok(!moment().month(0).isDST(), 'Jan should not be summer dst');
  40749. assert.ok(moment().month(6).isDST(), 'Jul should be summer dst');
  40750. assert.ok(!moment().month(11).isDST(), 'Dec should not be summer dst');
  40751. moment.updateOffset = function (mom) {
  40752. if (mom.month() > 2 && mom.month() < 9) {
  40753. mom.zone(0);
  40754. } else {
  40755. mom.zone(-60);
  40756. }
  40757. };
  40758. assert.ok(moment().month(0).isDST(), 'Jan should be winter dst');
  40759. assert.ok(!moment().month(6).isDST(), 'Jul should not be winter dst');
  40760. assert.ok(moment().month(11).isDST(), 'Dec should be winter dst');
  40761. moment.updateOffset = oldOffset;
  40762. });
  40763. test('zone names', function (assert) {
  40764. assert.equal(moment().zoneAbbr(), '', 'Local zone abbr should be empty');
  40765. assert.equal(moment().format('z'), '', 'Local zone formatted abbr should be empty');
  40766. assert.equal(moment().zoneName(), '', 'Local zone name should be empty');
  40767. assert.equal(moment().format('zz'), '', 'Local zone formatted name should be empty');
  40768. assert.equal(moment.utc().zoneAbbr(), 'UTC', 'UTC zone abbr should be UTC');
  40769. assert.equal(moment.utc().format('z'), 'UTC', 'UTC zone formatted abbr should be UTC');
  40770. assert.equal(moment.utc().zoneName(), 'Coordinated Universal Time', 'UTC zone abbr should be Coordinated Universal Time');
  40771. assert.equal(moment.utc().format('zz'), 'Coordinated Universal Time', 'UTC zone formatted abbr should be Coordinated Universal Time');
  40772. });
  40773. test('hours alignment with UTC', function (assert) {
  40774. assert.equal(moment().zone(120).hasAlignedHourOffset(), true);
  40775. assert.equal(moment().zone(-180).hasAlignedHourOffset(), true);
  40776. assert.equal(moment().zone(90).hasAlignedHourOffset(), false);
  40777. assert.equal(moment().zone(-90).hasAlignedHourOffset(), false);
  40778. });
  40779. test('hours alignment with other zone', function (assert) {
  40780. var m = moment().zone(120);
  40781. assert.equal(m.hasAlignedHourOffset(moment().zone(180)), true);
  40782. assert.equal(m.hasAlignedHourOffset(moment().zone(-180)), true);
  40783. assert.equal(m.hasAlignedHourOffset(moment().zone(90)), false);
  40784. assert.equal(m.hasAlignedHourOffset(moment().zone(-90)), false);
  40785. m = moment().zone(90);
  40786. assert.equal(m.hasAlignedHourOffset(moment().zone(180)), false);
  40787. assert.equal(m.hasAlignedHourOffset(moment().zone(-180)), false);
  40788. assert.equal(m.hasAlignedHourOffset(moment().zone(30)), true);
  40789. assert.equal(m.hasAlignedHourOffset(moment().zone(-30)), true);
  40790. m = moment().zone(-60);
  40791. assert.equal(m.hasAlignedHourOffset(moment().zone(180)), true);
  40792. assert.equal(m.hasAlignedHourOffset(moment().zone(-180)), true);
  40793. assert.equal(m.hasAlignedHourOffset(moment().zone(90)), false);
  40794. assert.equal(m.hasAlignedHourOffset(moment().zone(-90)), false);
  40795. m = moment().zone(25);
  40796. assert.equal(m.hasAlignedHourOffset(moment().zone(-35)), true);
  40797. assert.equal(m.hasAlignedHourOffset(moment().zone(85)), true);
  40798. assert.equal(m.hasAlignedHourOffset(moment().zone(35)), false);
  40799. assert.equal(m.hasAlignedHourOffset(moment().zone(-85)), false);
  40800. });
  40801. test('parse zone', function (assert) {
  40802. var m = moment('2013-01-01T00:00:00-13:00').parseZone();
  40803. assert.equal(m.zone(), 13 * 60);
  40804. assert.equal(m.hours(), 0);
  40805. });
  40806. test('parse zone static', function (assert) {
  40807. var m = moment.parseZone('2013-01-01T00:00:00-13:00');
  40808. assert.equal(m.zone(), 13 * 60);
  40809. assert.equal(m.hours(), 0);
  40810. });
  40811. test('parse zone with more arguments', function (assert) {
  40812. var m;
  40813. m = moment.parseZone('2013 01 01 05 -13:00', 'YYYY MM DD HH ZZ');
  40814. assert.equal(m.format(), '2013-01-01T05:00:00-13:00', 'accept input and format');
  40815. m = moment.parseZone('2013-01-01-13:00', 'YYYY MM DD ZZ', true);
  40816. assert.equal(m.isValid(), false, 'accept input, format and strict flag');
  40817. m = moment.parseZone('2013-01-01-13:00', ['DD MM YYYY ZZ', 'YYYY MM DD ZZ']);
  40818. assert.equal(m.format(), '2013-01-01T00:00:00-13:00', 'accept input and array of formats');
  40819. });
  40820. test('parse zone with a timezone from the format string', function (assert) {
  40821. var m = moment('11-12-2013 -0400 +1100', 'DD-MM-YYYY ZZ #####').parseZone();
  40822. assert.equal(m.zone(), 4 * 60);
  40823. });
  40824. test('parse zone without a timezone included in the format string', function (assert) {
  40825. var m = moment('11-12-2013 -0400 +1100', 'DD-MM-YYYY').parseZone();
  40826. assert.equal(m.zone(), -11 * 60);
  40827. });
  40828. test('timezone format', function (assert) {
  40829. assert.equal(moment().zone(-60).format('ZZ'), '+0100', '-60 -> +0100');
  40830. assert.equal(moment().zone(-90).format('ZZ'), '+0130', '-90 -> +0130');
  40831. assert.equal(moment().zone(-120).format('ZZ'), '+0200', '-120 -> +0200');
  40832. assert.equal(moment().zone(+60).format('ZZ'), '-0100', '+60 -> -0100');
  40833. assert.equal(moment().zone(+90).format('ZZ'), '-0130', '+90 -> -0130');
  40834. assert.equal(moment().zone(+120).format('ZZ'), '-0200', '+120 -> -0200');
  40835. });
  40836. }));