date-uz-Cyrl-UZ.js 133 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526
  1. /**
  2. * @overview datejs
  3. * @version 1.0.0-rc3
  4. * @author Gregory Wild-Smith <gregory@wild-smith.com>
  5. * @copyright 2014 Gregory Wild-Smith
  6. * @license MIT
  7. * @homepage https://github.com/abritinthebay/datejs
  8. */
  9. /*
  10. * DateJS Culture String File
  11. * Country Code: uz-Cyrl-UZ
  12. * Name: Uzbek (Cyrillic, Uzbekistan)
  13. * Format: "key" : "value"
  14. * Key is the en-US term, Value is the Key in the current language.
  15. */
  16. Date.CultureStrings = Date.CultureStrings || {};
  17. Date.CultureStrings["uz-Cyrl-UZ"] = {
  18. "name": "uz-Cyrl-UZ",
  19. "englishName": "Uzbek (Cyrillic, Uzbekistan)",
  20. "nativeName": "Ўзбек (Ўзбекистон)",
  21. "Sunday": "якшанба",
  22. "Monday": "душанба",
  23. "Tuesday": "сешанба",
  24. "Wednesday": "чоршанба",
  25. "Thursday": "пайшанба",
  26. "Friday": "жума",
  27. "Saturday": "шанба",
  28. "Sun": "якш",
  29. "Mon": "дш",
  30. "Tue": "сш",
  31. "Wed": "чш",
  32. "Thu": "пш",
  33. "Fri": "ж",
  34. "Sat": "ш",
  35. "Su": "якш",
  36. "Mo": "дш",
  37. "Tu": "сш",
  38. "We": "чш",
  39. "Th": "пш",
  40. "Fr": "ж",
  41. "Sa": "ш",
  42. "S_Sun_Initial": "я",
  43. "M_Mon_Initial": "д",
  44. "T_Tue_Initial": "с",
  45. "W_Wed_Initial": "ч",
  46. "T_Thu_Initial": "п",
  47. "F_Fri_Initial": "ж",
  48. "S_Sat_Initial": "ш",
  49. "January": "Январ",
  50. "February": "Феврал",
  51. "March": "Март",
  52. "April": "Апрел",
  53. "May": "Май",
  54. "June": "Июн",
  55. "July": "Июл",
  56. "August": "Август",
  57. "September": "Сентябр",
  58. "October": "Октябр",
  59. "November": "Ноябр",
  60. "December": "Декабр",
  61. "Jan_Abbr": "Янв",
  62. "Feb_Abbr": "Фев",
  63. "Mar_Abbr": "Мар",
  64. "Apr_Abbr": "Апр",
  65. "May_Abbr": "Май",
  66. "Jun_Abbr": "Июн",
  67. "Jul_Abbr": "Июл",
  68. "Aug_Abbr": "Авг",
  69. "Sep_Abbr": "Сен",
  70. "Oct_Abbr": "Окт",
  71. "Nov_Abbr": "Ноя",
  72. "Dec_Abbr": "Дек",
  73. "AM": "",
  74. "PM": "",
  75. "firstDayOfWeek": 1,
  76. "twoDigitYearMax": 2029,
  77. "mdy": "dmy",
  78. "M/d/yyyy": "dd.MM.yyyy",
  79. "dddd, MMMM dd, yyyy": "yyyy 'йил' d-MMMM",
  80. "h:mm tt": "HH:mm",
  81. "h:mm:ss tt": "HH:mm:ss",
  82. "dddd, MMMM dd, yyyy h:mm:ss tt": "yyyy 'йил' d-MMMM HH:mm:ss",
  83. "yyyy-MM-ddTHH:mm:ss": "yyyy-MM-ddTHH:mm:ss",
  84. "yyyy-MM-dd HH:mm:ssZ": "yyyy-MM-dd HH:mm:ssZ",
  85. "ddd, dd MMM yyyy HH:mm:ss": "ddd, dd MMM yyyy HH:mm:ss",
  86. "MMMM dd": "d-MMMM",
  87. "MMMM, yyyy": "MMMM yyyy",
  88. "/jan(uary)?/": "янв(ар)?",
  89. "/feb(ruary)?/": "фев(рал)?",
  90. "/mar(ch)?/": "мар(т)?",
  91. "/apr(il)?/": "апр(ел)?",
  92. "/may/": "май",
  93. "/jun(e)?/": "июн",
  94. "/jul(y)?/": "июл",
  95. "/aug(ust)?/": "авг(уст)?",
  96. "/sep(t(ember)?)?/": "сен(тябр)?",
  97. "/oct(ober)?/": "окт(ябр)?",
  98. "/nov(ember)?/": "ноя(бр)?",
  99. "/dec(ember)?/": "дек(абр)?",
  100. "/^su(n(day)?)?/": "^якшанба",
  101. "/^mo(n(day)?)?/": "^душанба",
  102. "/^tu(e(s(day)?)?)?/": "^сешанба",
  103. "/^we(d(nesday)?)?/": "^чоршанба",
  104. "/^th(u(r(s(day)?)?)?)?/": "^пайшанба",
  105. "/^fr(i(day)?)?/": "^жума",
  106. "/^sa(t(urday)?)?/": "^шанба",
  107. "/^next/": "^next",
  108. "/^last|past|prev(ious)?/": "^last|past|prev(ious)?",
  109. "/^(\\+|aft(er)?|from|hence)/": "^(\\+|aft(er)?|from|hence)",
  110. "/^(\\-|bef(ore)?|ago)/": "^(\\-|bef(ore)?|ago)",
  111. "/^yes(terday)?/": "^yes(terday)?",
  112. "/^t(od(ay)?)?/": "^t(od(ay)?)?",
  113. "/^tom(orrow)?/": "^tom(orrow)?",
  114. "/^n(ow)?/": "^n(ow)?",
  115. "/^ms|milli(second)?s?/": "^ms|milli(second)?s?",
  116. "/^sec(ond)?s?/": "^sec(ond)?s?",
  117. "/^mn|min(ute)?s?/": "^mn|min(ute)?s?",
  118. "/^h(our)?s?/": "^h(our)?s?",
  119. "/^w(eek)?s?/": "^w(eek)?s?",
  120. "/^m(onth)?s?/": "^m(onth)?s?",
  121. "/^d(ay)?s?/": "^d(ay)?s?",
  122. "/^y(ear)?s?/": "^y(ear)?s?",
  123. "/^(a|p)/": "^(a|p)",
  124. "/^(a\\.?m?\\.?|p\\.?m?\\.?)/": "^(a\\.?m?\\.?|p\\.?m?\\.?)",
  125. "/^((e(s|d)t|c(s|d)t|m(s|d)t|p(s|d)t)|((gmt)?\\s*(\\+|\\-)\\s*\\d\\d\\d\\d?)|gmt|utc)/": "^((e(s|d)t|c(s|d)t|m(s|d)t|p(s|d)t)|((gmt)?\\s*(\\+|\\-)\\s*\\d\\d\\d\\d?)|gmt|utc)",
  126. "/^\\s*(st|nd|rd|th)/": "^\\s*(st|nd|rd|th)",
  127. "/^\\s*(\\:|a(?!u|p)|p)/": "^\\s*(\\:|a(?!u|p)|p)",
  128. "LINT": "LINT",
  129. "TOT": "TOT",
  130. "CHAST": "CHAST",
  131. "NZST": "NZST",
  132. "NFT": "NFT",
  133. "SBT": "SBT",
  134. "AEST": "AEST",
  135. "ACST": "ACST",
  136. "JST": "JST",
  137. "CWST": "CWST",
  138. "CT": "CT",
  139. "ICT": "ICT",
  140. "MMT": "MMT",
  141. "BIOT": "BST",
  142. "NPT": "NPT",
  143. "IST": "IST",
  144. "PKT": "PKT",
  145. "AFT": "AFT",
  146. "MSK": "MSK",
  147. "IRST": "IRST",
  148. "FET": "FET",
  149. "EET": "EET",
  150. "CET": "CET",
  151. "UTC": "UTC",
  152. "GMT": "GMT",
  153. "CVT": "CVT",
  154. "GST": "GST",
  155. "BRT": "BRT",
  156. "NST": "NST",
  157. "AST": "AST",
  158. "EST": "EST",
  159. "CST": "CST",
  160. "MST": "MST",
  161. "PST": "PST",
  162. "AKST": "AKST",
  163. "MIT": "MIT",
  164. "HST": "HST",
  165. "SST": "SST",
  166. "BIT": "BIT",
  167. "CHADT": "CHADT",
  168. "NZDT": "NZDT",
  169. "AEDT": "AEDT",
  170. "ACDT": "ACDT",
  171. "AZST": "AZST",
  172. "IRDT": "IRDT",
  173. "EEST": "EEST",
  174. "CEST": "CEST",
  175. "BST": "BST",
  176. "PMDT": "PMDT",
  177. "ADT": "ADT",
  178. "NDT": "NDT",
  179. "EDT": "EDT",
  180. "CDT": "CDT",
  181. "MDT": "MDT",
  182. "PDT": "PDT",
  183. "AKDT": "AKDT",
  184. "HADT": "HADT"
  185. };
  186. Date.CultureStrings.lang = "uz-Cyrl-UZ";
  187. /**
  188. * @overview datejs
  189. * @version 1.0.0-rc3
  190. * @author Gregory Wild-Smith <gregory@wild-smith.com>
  191. * @copyright 2014 Gregory Wild-Smith
  192. * @license MIT
  193. * @homepage https://github.com/abritinthebay/datejs
  194. */(function () {
  195. var $D = Date;
  196. var lang = Date.CultureStrings ? Date.CultureStrings.lang : null;
  197. var loggedKeys = {}; // for debug purposes.
  198. var getText = {
  199. getFromKey: function (key, countryCode) {
  200. var output;
  201. if (Date.CultureStrings && Date.CultureStrings[countryCode] && Date.CultureStrings[countryCode][key]) {
  202. output = Date.CultureStrings[countryCode][key];
  203. } else {
  204. output = getText.buildFromDefault(key);
  205. }
  206. if (key.charAt(0) === "/") { // Assume it's a regex
  207. output = getText.buildFromRegex(key, countryCode);
  208. }
  209. return output;
  210. },
  211. getFromObjectValues: function (obj, countryCode) {
  212. var key, output = {};
  213. for(key in obj) {
  214. if (obj.hasOwnProperty(key)) {
  215. output[key] = getText.getFromKey(obj[key], countryCode);
  216. }
  217. }
  218. return output;
  219. },
  220. getFromObjectKeys: function (obj, countryCode) {
  221. var key, output = {};
  222. for(key in obj) {
  223. if (obj.hasOwnProperty(key)) {
  224. output[getText.getFromKey(key, countryCode)] = obj[key];
  225. }
  226. }
  227. return output;
  228. },
  229. getFromArray: function (arr, countryCode) {
  230. var output = [];
  231. for (var i=0; i < arr.length; i++){
  232. if (i in arr) {
  233. output[i] = getText.getFromKey(arr[i], countryCode);
  234. }
  235. }
  236. return output;
  237. },
  238. buildFromDefault: function (key) {
  239. var output, length, split, last;
  240. switch(key) {
  241. case "name":
  242. output = "en-US";
  243. break;
  244. case "englishName":
  245. output = "English (United States)";
  246. break;
  247. case "nativeName":
  248. output = "English (United States)";
  249. break;
  250. case "twoDigitYearMax":
  251. output = 2049;
  252. break;
  253. case "firstDayOfWeek":
  254. output = 0;
  255. break;
  256. default:
  257. output = key;
  258. split = key.split("_");
  259. length = split.length;
  260. if (length > 1 && key.charAt(0) !== "/") {
  261. // if the key isn't a regex and it has a split.
  262. last = split[(length - 1)].toLowerCase();
  263. if (last === "initial" || last === "abbr") {
  264. output = split[0];
  265. }
  266. }
  267. break;
  268. }
  269. return output;
  270. },
  271. buildFromRegex: function (key, countryCode) {
  272. var output;
  273. if (Date.CultureStrings && Date.CultureStrings[countryCode] && Date.CultureStrings[countryCode][key]) {
  274. output = new RegExp(Date.CultureStrings[countryCode][key], "i");
  275. } else {
  276. output = new RegExp(key.replace(new RegExp("/", "g"),""), "i");
  277. }
  278. return output;
  279. }
  280. };
  281. var shallowMerge = function (obj1, obj2) {
  282. for (var attrname in obj2) {
  283. if (obj2.hasOwnProperty(attrname)) {
  284. obj1[attrname] = obj2[attrname];
  285. }
  286. }
  287. };
  288. var __ = function (key, language) {
  289. var countryCode = (language) ? language : lang;
  290. loggedKeys[key] = key;
  291. if (typeof key === "object") {
  292. if (key instanceof Array) {
  293. return getText.getFromArray(key, countryCode);
  294. } else {
  295. return getText.getFromObjectKeys(key, countryCode);
  296. }
  297. } else {
  298. return getText.getFromKey(key, countryCode);
  299. }
  300. };
  301. var loadI18nScript = function (code) {
  302. // paatterned after jQuery's getScript.
  303. var url = Date.Config.i18n + code + ".js";
  304. var head = document.getElementsByTagName("head")[0] || document.documentElement;
  305. var script = document.createElement("script");
  306. script.src = url;
  307. var completed = false;
  308. var events = {
  309. done: function (){} // placeholder function
  310. };
  311. // Attach handlers for all browsers
  312. script.onload = script.onreadystatechange = function() {
  313. if ( !completed && (!this.readyState || this.readyState === "loaded" || this.readyState === "complete") ) {
  314. events.done();
  315. head.removeChild(script);
  316. }
  317. };
  318. setTimeout(function() {
  319. head.insertBefore(script, head.firstChild);
  320. }, 0); // allows return to execute first
  321. return {
  322. done: function (cb) {
  323. events.done = function() {
  324. if (cb) {
  325. setTimeout(cb,0);
  326. }
  327. };
  328. }
  329. };
  330. };
  331. var buildInfo = {
  332. buildFromMethodHash: function (obj) {
  333. var key;
  334. for(key in obj) {
  335. if (obj.hasOwnProperty(key)) {
  336. obj[key] = buildInfo[obj[key]]();
  337. }
  338. }
  339. return obj;
  340. },
  341. timeZoneDST: function () {
  342. var DST = {
  343. "CHADT": "+1345",
  344. "NZDT": "+1300",
  345. "AEDT": "+1100",
  346. "ACDT": "+1030",
  347. "AZST": "+0500",
  348. "IRDT": "+0430",
  349. "EEST": "+0300",
  350. "CEST": "+0200",
  351. "BST": "+0100",
  352. "PMDT": "-0200",
  353. "ADT": "-0300",
  354. "NDT": "-0230",
  355. "EDT": "-0400",
  356. "CDT": "-0500",
  357. "MDT": "-0600",
  358. "PDT": "-0700",
  359. "AKDT": "-0800",
  360. "HADT": "-0900"
  361. };
  362. return __(DST);
  363. },
  364. timeZoneStandard: function () {
  365. var standard = {
  366. "LINT": "+1400",
  367. "TOT": "+1300",
  368. "CHAST": "+1245",
  369. "NZST": "+1200",
  370. "NFT": "+1130",
  371. "SBT": "+1100",
  372. "AEST": "+1000",
  373. "ACST": "+0930",
  374. "JST": "+0900",
  375. "CWST": "+0845",
  376. "CT": "+0800",
  377. "ICT": "+0700",
  378. "MMT": "+0630",
  379. "BST": "+0600",
  380. "NPT": "+0545",
  381. "IST": "+0530",
  382. "PKT": "+0500",
  383. "AFT": "+0430",
  384. "MSK": "+0400",
  385. "IRST": "+0330",
  386. "FET": "+0300",
  387. "EET": "+0200",
  388. "CET": "+0100",
  389. "GMT": "+0000",
  390. "UTC": "+0000",
  391. "CVT": "-0100",
  392. "GST": "-0200",
  393. "BRT": "-0300",
  394. "NST": "-0330",
  395. "AST": "-0400",
  396. "EST": "-0500",
  397. "CST": "-0600",
  398. "MST": "-0700",
  399. "PST": "-0800",
  400. "AKST": "-0900",
  401. "MIT": "-0930",
  402. "HST": "-1000",
  403. "SST": "-1100",
  404. "BIT": "-1200"
  405. };
  406. return __(standard);
  407. },
  408. timeZones: function (data) {
  409. var zone;
  410. data.timezones = [];
  411. for (zone in data.abbreviatedTimeZoneStandard) {
  412. if (data.abbreviatedTimeZoneStandard.hasOwnProperty(zone)) {
  413. data.timezones.push({ name: zone, offset: data.abbreviatedTimeZoneStandard[zone]});
  414. }
  415. }
  416. for (zone in data.abbreviatedTimeZoneDST) {
  417. if (data.abbreviatedTimeZoneDST.hasOwnProperty(zone)) {
  418. data.timezones.push({ name: zone, offset: data.abbreviatedTimeZoneDST[zone], dst: true});
  419. }
  420. }
  421. return data.timezones;
  422. },
  423. days: function () {
  424. return __(["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]);
  425. },
  426. dayAbbr: function () {
  427. return __(["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]);
  428. },
  429. dayShortNames: function () {
  430. return __(["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]);
  431. },
  432. dayFirstLetters: function () {
  433. return __(["S_Sun_Initial", "M_Mon_Initial", "T_Tues_Initial", "W_Wed_Initial", "T_Thu_Initial", "F_Fri_Initial", "S_Sat_Initial"]);
  434. },
  435. months: function () {
  436. return __(["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]);
  437. },
  438. monthAbbr: function () {
  439. return __(["Jan_Abbr", "Feb_Abbr", "Mar_Abbr", "Apr_Abbr", "May_Abbr", "Jun_Abbr", "Jul_Abbr", "Aug_Abbr", "Sep_Abbr", "Oct_Abbr", "Nov_Abbr", "Dec_Abbr"]);
  440. },
  441. formatPatterns: function () {
  442. return getText.getFromObjectValues({
  443. shortDate: "M/d/yyyy",
  444. longDate: "dddd, MMMM dd, yyyy",
  445. shortTime: "h:mm tt",
  446. longTime: "h:mm:ss tt",
  447. fullDateTime: "dddd, MMMM dd, yyyy h:mm:ss tt",
  448. sortableDateTime: "yyyy-MM-ddTHH:mm:ss",
  449. universalSortableDateTime: "yyyy-MM-dd HH:mm:ssZ",
  450. rfc1123: "ddd, dd MMM yyyy HH:mm:ss",
  451. monthDay: "MMMM dd",
  452. yearMonth: "MMMM, yyyy"
  453. }, Date.i18n.currentLanguage());
  454. },
  455. regex: function () {
  456. return getText.getFromObjectValues({
  457. inTheMorning: "/( in the )(morn(ing)?)\\b/",
  458. thisMorning: "/(this )(morn(ing)?)\\b/",
  459. amThisMorning: "/(\b\\d(am)? )(this )(morn(ing)?)/",
  460. inTheEvening: "/( in the )(even(ing)?)\\b/",
  461. thisEvening: "/(this )(even(ing)?)\\b/",
  462. pmThisEvening: "/(\b\\d(pm)? )(this )(even(ing)?)/",
  463. jan: "/jan(uary)?/",
  464. feb: "/feb(ruary)?/",
  465. mar: "/mar(ch)?/",
  466. apr: "/apr(il)?/",
  467. may: "/may/",
  468. jun: "/jun(e)?/",
  469. jul: "/jul(y)?/",
  470. aug: "/aug(ust)?/",
  471. sep: "/sep(t(ember)?)?/",
  472. oct: "/oct(ober)?/",
  473. nov: "/nov(ember)?/",
  474. dec: "/dec(ember)?/",
  475. sun: "/^su(n(day)?)?/",
  476. mon: "/^mo(n(day)?)?/",
  477. tue: "/^tu(e(s(day)?)?)?/",
  478. wed: "/^we(d(nesday)?)?/",
  479. thu: "/^th(u(r(s(day)?)?)?)?/",
  480. fri: "/fr(i(day)?)?/",
  481. sat: "/^sa(t(urday)?)?/",
  482. future: "/^next/",
  483. past: "/^last|past|prev(ious)?/",
  484. add: "/^(\\+|aft(er)?|from|hence)/",
  485. subtract: "/^(\\-|bef(ore)?|ago)/",
  486. yesterday: "/^yes(terday)?/",
  487. today: "/^t(od(ay)?)?/",
  488. tomorrow: "/^tom(orrow)?/",
  489. now: "/^n(ow)?/",
  490. millisecond: "/^ms|milli(second)?s?/",
  491. second: "/^sec(ond)?s?/",
  492. minute: "/^mn|min(ute)?s?/",
  493. hour: "/^h(our)?s?/",
  494. week: "/^w(eek)?s?/",
  495. month: "/^m(onth)?s?/",
  496. day: "/^d(ay)?s?/",
  497. year: "/^y(ear)?s?/",
  498. shortMeridian: "/^(a|p)/",
  499. longMeridian: "/^(a\\.?m?\\.?|p\\.?m?\\.?)/",
  500. timezone: "/^((e(s|d)t|c(s|d)t|m(s|d)t|p(s|d)t)|((gmt)?\\s*(\\+|\\-)\\s*\\d\\d\\d\\d?)|gmt|utc)/",
  501. ordinalSuffix: "/^\\s*(st|nd|rd|th)/",
  502. timeContext: "/^\\s*(\\:|a(?!u|p)|p)/"
  503. }, Date.i18n.currentLanguage());
  504. }
  505. };
  506. var CultureInfo = function () {
  507. var info = getText.getFromObjectValues({
  508. name: "name",
  509. englishName: "englishName",
  510. nativeName: "nativeName",
  511. amDesignator: "AM",
  512. pmDesignator: "PM",
  513. firstDayOfWeek: "firstDayOfWeek",
  514. twoDigitYearMax: "twoDigitYearMax",
  515. dateElementOrder: "mdy"
  516. }, Date.i18n.currentLanguage());
  517. var constructedInfo = buildInfo.buildFromMethodHash({
  518. dayNames: "days",
  519. abbreviatedDayNames: "dayAbbr",
  520. shortestDayNames: "dayShortNames",
  521. firstLetterDayNames: "dayFirstLetters",
  522. monthNames: "months",
  523. abbreviatedMonthNames: "monthAbbr",
  524. formatPatterns: "formatPatterns",
  525. regexPatterns: "regex",
  526. abbreviatedTimeZoneDST: "timeZoneDST",
  527. abbreviatedTimeZoneStandard: "timeZoneStandard"
  528. });
  529. shallowMerge(info, constructedInfo);
  530. buildInfo.timeZones(info);
  531. return info;
  532. };
  533. $D.i18n = {
  534. __: function (key, lang) {
  535. return __(key, lang);
  536. },
  537. currentLanguage: function () {
  538. return lang || "en-US";
  539. },
  540. setLanguage: function (code, force, cb) {
  541. var async = false;
  542. if (force || code === "en-US" || (!!Date.CultureStrings && !!Date.CultureStrings[code])) {
  543. lang = code;
  544. Date.CultureStrings = Date.CultureStrings || {};
  545. Date.CultureStrings.lang = code;
  546. Date.CultureInfo = new CultureInfo();
  547. } else {
  548. if (!(!!Date.CultureStrings && !!Date.CultureStrings[code])) {
  549. if (typeof exports !== "undefined" && this.exports !== exports) {
  550. // we're in a Node enviroment, load it using require
  551. try {
  552. require("../i18n/" + code + ".js");
  553. lang = code;
  554. Date.CultureStrings.lang = code;
  555. Date.CultureInfo = new CultureInfo();
  556. } catch (e) {
  557. // var str = "The language for '" + code + "' could not be loaded by Node. It likely does not exist.";
  558. throw new Error("The DateJS IETF language tag '" + code + "' could not be loaded by Node. It likely does not exist.");
  559. }
  560. } else if (Date.Config && Date.Config.i18n) {
  561. // we know the location of the files, so lets load them
  562. async = true;
  563. loadI18nScript(code).done(function(){
  564. lang = code;
  565. Date.CultureStrings = Date.CultureStrings || {};
  566. Date.CultureStrings.lang = code;
  567. Date.CultureInfo = new CultureInfo();
  568. $D.Parsing.Normalizer.buildReplaceData(); // because this is async
  569. if ($D.Grammar) {
  570. $D.Grammar.buildGrammarFormats(); // so we can parse those strings...
  571. }
  572. if (cb) {
  573. setTimeout(cb,0);
  574. }
  575. });
  576. } else {
  577. Date.console.error("The DateJS IETF language tag '" + code + "' is not available and has not been loaded.");
  578. return false;
  579. }
  580. }
  581. }
  582. $D.Parsing.Normalizer.buildReplaceData(); // rebuild normalizer strings
  583. if ($D.Grammar) {
  584. $D.Grammar.buildGrammarFormats(); // so we can parse those strings...
  585. }
  586. if (!async && cb) {
  587. setTimeout(cb,0);
  588. }
  589. },
  590. getLoggedKeys: function () {
  591. return loggedKeys;
  592. },
  593. updateCultureInfo: function () {
  594. Date.CultureInfo = new CultureInfo();
  595. }
  596. };
  597. $D.i18n.updateCultureInfo(); // run automatically
  598. }());
  599. (function () {
  600. var $D = Date,
  601. $P = $D.prototype,
  602. p = function (s, l) {
  603. if (!l) {
  604. l = 2;
  605. }
  606. return ("000" + s).slice(l * -1);
  607. };
  608. if (typeof window !== "undefined" && typeof window.console !== "undefined" && typeof window.console.log !== "undefined") {
  609. $D.console = console; // used only to raise non-critical errors if available
  610. } else {
  611. // set mock so we don't give errors.
  612. $D.console = {
  613. log: function(){},
  614. error: function(){}
  615. };
  616. }
  617. $D.Config = $D.Config || {};
  618. $D.initOverloads = function() {
  619. /**
  620. * Overload of Date.now. Allows an alternate call for Date.now where it returns the
  621. * current Date as an object rather than just milliseconds since the Unix Epoch.
  622. *
  623. * Also provides an implementation of now() for browsers (IE<9) that don't have it.
  624. *
  625. * Backwards compatible so with work with either:
  626. * Date.now() [returns ms]
  627. * or
  628. * Date.now(true) [returns Date]
  629. */
  630. if (!$D.now) {
  631. $D._now = function now() {
  632. return new Date().getTime();
  633. };
  634. } else if (!$D._now) {
  635. $D._now = $D.now;
  636. }
  637. $D.now = function (returnObj) {
  638. if (returnObj) {
  639. return $D.present();
  640. } else {
  641. return $D._now();
  642. }
  643. };
  644. if ( !$P.toISOString ) {
  645. $P.toISOString = function() {
  646. return this.getUTCFullYear() +
  647. "-" + p(this.getUTCMonth() + 1) +
  648. "-" + p(this.getUTCDate()) +
  649. "T" + p(this.getUTCHours()) +
  650. ":" + p(this.getUTCMinutes()) +
  651. ":" + p(this.getUTCSeconds()) +
  652. "." + String( (this.getUTCMilliseconds()/1000).toFixed(3)).slice(2, 5) +
  653. "Z";
  654. };
  655. }
  656. // private
  657. if ( $P._toString === undefined ){
  658. $P._toString = $P.toString;
  659. }
  660. };
  661. $D.initOverloads();
  662. /**
  663. * Gets a date that is set to the current date. The time is set to the start of the day (00:00 or 12:00 AM).
  664. * @return {Date} The current date.
  665. */
  666. $D.today = function () {
  667. return new Date().clearTime();
  668. };
  669. /**
  670. * Gets a date that is set to the current date and time (same as new Date, but chainable)
  671. * @return {Date} The current date.
  672. */
  673. $D.present = function () {
  674. return new Date();
  675. };
  676. /**
  677. * Compares the first date to the second date and returns an number indication of their relative values.
  678. * @param {Date} First Date object to compare [Required].
  679. * @param {Date} Second Date object to compare to [Required].
  680. * @return {Number} -1 = date1 is lessthan date2. 0 = values are equal. 1 = date1 is greaterthan date2.
  681. */
  682. $D.compare = function (date1, date2) {
  683. if (isNaN(date1) || isNaN(date2)) {
  684. throw new Error(date1 + " - " + date2);
  685. } else if (date1 instanceof Date && date2 instanceof Date) {
  686. return (date1 < date2) ? -1 : (date1 > date2) ? 1 : 0;
  687. } else {
  688. throw new TypeError(date1 + " - " + date2);
  689. }
  690. };
  691. /**
  692. * Compares the first Date object to the second Date object and returns true if they are equal.
  693. * @param {Date} First Date object to compare [Required]
  694. * @param {Date} Second Date object to compare to [Required]
  695. * @return {Boolean} true if dates are equal. false if they are not equal.
  696. */
  697. $D.equals = function (date1, date2) {
  698. return (date1.compareTo(date2) === 0);
  699. };
  700. /**
  701. * Gets the language appropriate day name when given the day number(0-6)
  702. * eg - 0 == Sunday
  703. * @return {String} The day name
  704. */
  705. $D.getDayName = function (n) {
  706. return Date.CultureInfo.dayNames[n];
  707. };
  708. /**
  709. * Gets the day number (0-6) if given a CultureInfo specific string which is a valid dayName, abbreviatedDayName or shortestDayName (two char).
  710. * @param {String} The name of the day (eg. "Monday, "Mon", "tuesday", "tue", "We", "we").
  711. * @return {Number} The day number
  712. */
  713. $D.getDayNumberFromName = function (name) {
  714. var n = Date.CultureInfo.dayNames, m = Date.CultureInfo.abbreviatedDayNames, o = Date.CultureInfo.shortestDayNames, s = name.toLowerCase();
  715. for (var i = 0; i < n.length; i++) {
  716. if (n[i].toLowerCase() === s || m[i].toLowerCase() === s || o[i].toLowerCase() === s) {
  717. return i;
  718. }
  719. }
  720. return -1;
  721. };
  722. /**
  723. * Gets the month number (0-11) if given a Culture Info specific string which is a valid monthName or abbreviatedMonthName.
  724. * @param {String} The name of the month (eg. "February, "Feb", "october", "oct").
  725. * @return {Number} The day number
  726. */
  727. $D.getMonthNumberFromName = function (name) {
  728. var n = Date.CultureInfo.monthNames, m = Date.CultureInfo.abbreviatedMonthNames, s = name.toLowerCase();
  729. for (var i = 0; i < n.length; i++) {
  730. if (n[i].toLowerCase() === s || m[i].toLowerCase() === s) {
  731. return i;
  732. }
  733. }
  734. return -1;
  735. };
  736. /**
  737. * Gets the language appropriate month name when given the month number(0-11)
  738. * eg - 0 == January
  739. * @return {String} The month name
  740. */
  741. $D.getMonthName = function (n) {
  742. return Date.CultureInfo.monthNames[n];
  743. };
  744. /**
  745. * Determines if the current date instance is within a LeapYear.
  746. * @param {Number} The year.
  747. * @return {Boolean} true if date is within a LeapYear, otherwise false.
  748. */
  749. $D.isLeapYear = function (year) {
  750. return ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0);
  751. };
  752. /**
  753. * Gets the number of days in the month, given a year and month value. Automatically corrects for LeapYear.
  754. * @param {Number} The year.
  755. * @param {Number} The month (0-11).
  756. * @return {Number} The number of days in the month.
  757. */
  758. $D.getDaysInMonth = function (year, month) {
  759. if (!month && $D.validateMonth(year)) {
  760. month = year;
  761. year = Date.today().getFullYear();
  762. }
  763. return [31, ($D.isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
  764. };
  765. $P.getDaysInMonth = function () {
  766. return $D.getDaysInMonth(this.getFullYear(), this.getMonth());
  767. };
  768. $D.getTimezoneAbbreviation = function (offset, dst) {
  769. var p, n = (dst || false) ? Date.CultureInfo.abbreviatedTimeZoneDST : Date.CultureInfo.abbreviatedTimeZoneStandard;
  770. for (p in n) {
  771. if (n.hasOwnProperty(p)) {
  772. if (n[p] === offset) {
  773. return p;
  774. }
  775. }
  776. }
  777. return null;
  778. };
  779. $D.getTimezoneOffset = function (name, dst) {
  780. var i, a =[], z = Date.CultureInfo.timezones;
  781. if (!name) { name = (new Date()).getTimezone();}
  782. for (i = 0; i < z.length; i++) {
  783. if (z[i].name === name.toUpperCase()) {
  784. a.push(i);
  785. }
  786. }
  787. if (!z[a[0]]) {
  788. return null;
  789. }
  790. if (a.length === 1 || !dst) {
  791. return z[a[0]].offset;
  792. } else {
  793. for (i=0; i < a.length; i++) {
  794. if (z[a[i]].dst) {
  795. return z[a[i]].offset;
  796. }
  797. }
  798. }
  799. };
  800. $D.getQuarter = function (d) {
  801. d = d || new Date(); // If no date supplied, use today
  802. var q = [1,2,3,4];
  803. return q[Math.floor(d.getMonth() / 3)]; // ~~~ is a bitwise op. Faster than Math.floor
  804. };
  805. $D.getDaysLeftInQuarter = function (d) {
  806. d = d || new Date();
  807. var qEnd = new Date(d);
  808. qEnd.setMonth(qEnd.getMonth() + 3 - qEnd.getMonth() % 3, 0);
  809. return Math.floor((qEnd - d) / 8.64e7);
  810. };
  811. // private
  812. var validate = function (n, min, max, name) {
  813. name = name ? name : "Object";
  814. if (typeof n === "undefined") {
  815. return false;
  816. } else if (typeof n !== "number") {
  817. throw new TypeError(n + " is not a Number.");
  818. } else if (n < min || n > max) {
  819. // As failing validation is *not* an exceptional circumstance
  820. // lets not throw a RangeError Exception here.
  821. // It's semantically correct but it's not sensible.
  822. return false;
  823. }
  824. return true;
  825. };
  826. /**
  827. * Validates the number is within an acceptable range for milliseconds [0-999].
  828. * @param {Number} The number to check if within range.
  829. * @return {Boolean} true if within range, otherwise false.
  830. */
  831. $D.validateMillisecond = function (value) {
  832. return validate(value, 0, 999, "millisecond");
  833. };
  834. /**
  835. * Validates the number is within an acceptable range for seconds [0-59].
  836. * @param {Number} The number to check if within range.
  837. * @return {Boolean} true if within range, otherwise false.
  838. */
  839. $D.validateSecond = function (value) {
  840. return validate(value, 0, 59, "second");
  841. };
  842. /**
  843. * Validates the number is within an acceptable range for minutes [0-59].
  844. * @param {Number} The number to check if within range.
  845. * @return {Boolean} true if within range, otherwise false.
  846. */
  847. $D.validateMinute = function (value) {
  848. return validate(value, 0, 59, "minute");
  849. };
  850. /**
  851. * Validates the number is within an acceptable range for hours [0-23].
  852. * @param {Number} The number to check if within range.
  853. * @return {Boolean} true if within range, otherwise false.
  854. */
  855. $D.validateHour = function (value) {
  856. return validate(value, 0, 23, "hour");
  857. };
  858. /**
  859. * Validates the number is within an acceptable range for the days in a month [0-MaxDaysInMonth].
  860. * @param {Number} The number to check if within range.
  861. * @return {Boolean} true if within range, otherwise false.
  862. */
  863. $D.validateDay = function (value, year, month) {
  864. if (year === undefined || year === null || month === undefined || month === null) { return false;}
  865. return validate(value, 1, $D.getDaysInMonth(year, month), "day");
  866. };
  867. /**
  868. * Validates the number is within an acceptable range for months [0-11].
  869. * @param {Number} The number to check if within range.
  870. * @return {Boolean} true if within range, otherwise false.
  871. */
  872. $D.validateWeek = function (value) {
  873. return validate(value, 0, 53, "week");
  874. };
  875. /**
  876. * Validates the number is within an acceptable range for months [0-11].
  877. * @param {Number} The number to check if within range.
  878. * @return {Boolean} true if within range, otherwise false.
  879. */
  880. $D.validateMonth = function (value) {
  881. return validate(value, 0, 11, "month");
  882. };
  883. /**
  884. * Validates the number is within an acceptable range for years.
  885. * @param {Number} The number to check if within range.
  886. * @return {Boolean} true if within range, otherwise false.
  887. */
  888. $D.validateYear = function (value) {
  889. /**
  890. * Per ECMAScript spec the range of times supported by Date objects is
  891. * exactly -100,000,000 days to +100,000,000 days measured relative to
  892. * midnight at the beginning of 01 January, 1970 UTC.
  893. * This gives a range of 8,640,000,000,000,000 milliseconds to either
  894. * side of 01 January, 1970 UTC.
  895. *
  896. * Earliest possible date: Tue, 20 Apr 271,822 B.C. 00:00:00 UTC
  897. * Latest possible date: Sat, 13 Sep 275,760 00:00:00 UTC
  898. */
  899. return validate(value, -271822, 275760, "year");
  900. };
  901. $D.validateTimezone = function(value) {
  902. var timezones = {"ACDT":1,"ACST":1,"ACT":1,"ADT":1,"AEDT":1,"AEST":1,"AFT":1,"AKDT":1,"AKST":1,"AMST":1,"AMT":1,"ART":1,"AST":1,"AWDT":1,"AWST":1,"AZOST":1,"AZT":1,"BDT":1,"BIOT":1,"BIT":1,"BOT":1,"BRT":1,"BST":1,"BTT":1,"CAT":1,"CCT":1,"CDT":1,"CEDT":1,"CEST":1,"CET":1,"CHADT":1,"CHAST":1,"CHOT":1,"ChST":1,"CHUT":1,"CIST":1,"CIT":1,"CKT":1,"CLST":1,"CLT":1,"COST":1,"COT":1,"CST":1,"CT":1,"CVT":1,"CWST":1,"CXT":1,"DAVT":1,"DDUT":1,"DFT":1,"EASST":1,"EAST":1,"EAT":1,"ECT":1,"EDT":1,"EEDT":1,"EEST":1,"EET":1,"EGST":1,"EGT":1,"EIT":1,"EST":1,"FET":1,"FJT":1,"FKST":1,"FKT":1,"FNT":1,"GALT":1,"GAMT":1,"GET":1,"GFT":1,"GILT":1,"GIT":1,"GMT":1,"GST":1,"GYT":1,"HADT":1,"HAEC":1,"HAST":1,"HKT":1,"HMT":1,"HOVT":1,"HST":1,"ICT":1,"IDT":1,"IOT":1,"IRDT":1,"IRKT":1,"IRST":1,"IST":1,"JST":1,"KGT":1,"KOST":1,"KRAT":1,"KST":1,"LHST":1,"LINT":1,"MAGT":1,"MART":1,"MAWT":1,"MDT":1,"MET":1,"MEST":1,"MHT":1,"MIST":1,"MIT":1,"MMT":1,"MSK":1,"MST":1,"MUT":1,"MVT":1,"MYT":1,"NCT":1,"NDT":1,"NFT":1,"NPT":1,"NST":1,"NT":1,"NUT":1,"NZDT":1,"NZST":1,"OMST":1,"ORAT":1,"PDT":1,"PET":1,"PETT":1,"PGT":1,"PHOT":1,"PHT":1,"PKT":1,"PMDT":1,"PMST":1,"PONT":1,"PST":1,"PYST":1,"PYT":1,"RET":1,"ROTT":1,"SAKT":1,"SAMT":1,"SAST":1,"SBT":1,"SCT":1,"SGT":1,"SLST":1,"SRT":1,"SST":1,"SYOT":1,"TAHT":1,"THA":1,"TFT":1,"TJT":1,"TKT":1,"TLT":1,"TMT":1,"TOT":1,"TVT":1,"UCT":1,"ULAT":1,"UTC":1,"UYST":1,"UYT":1,"UZT":1,"VET":1,"VLAT":1,"VOLT":1,"VOST":1,"VUT":1,"WAKT":1,"WAST":1,"WAT":1,"WEDT":1,"WEST":1,"WET":1,"WST":1,"YAKT":1,"YEKT":1,"Z":1};
  903. return (timezones[value] === 1);
  904. };
  905. $D.validateTimezoneOffset= function(value) {
  906. // timezones go from +14hrs to -12hrs, the +X hours are negative offsets.
  907. return (value > -841 && value < 721);
  908. };
  909. }());
  910. (function () {
  911. var $D = Date,
  912. $P = $D.prototype,
  913. p = function (s, l) {
  914. if (!l) {
  915. l = 2;
  916. }
  917. return ("000" + s).slice(l * -1);
  918. };
  919. var validateConfigObject = function (obj) {
  920. var result = {}, self = this, prop, testFunc;
  921. testFunc = function (prop, func, value) {
  922. if (prop === "day") {
  923. var month = (obj.month !== undefined) ? obj.month : self.getMonth();
  924. var year = (obj.year !== undefined) ? obj.year : self.getFullYear();
  925. return $D[func](value, year, month);
  926. } else {
  927. return $D[func](value);
  928. }
  929. };
  930. for (prop in obj) {
  931. if (hasOwnProperty.call(obj, prop)) {
  932. var func = "validate" + prop.charAt(0).toUpperCase() + prop.slice(1);
  933. if ($D[func] && obj[prop] !== null && testFunc(prop, func, obj[prop])) {
  934. result[prop] = obj[prop];
  935. }
  936. }
  937. }
  938. return result;
  939. };
  940. /**
  941. * Resets the time of this Date object to 12:00 AM (00:00), which is the start of the day.
  942. * @param {Boolean} .clone() this date instance before clearing Time
  943. * @return {Date} this
  944. */
  945. $P.clearTime = function () {
  946. this.setHours(0);
  947. this.setMinutes(0);
  948. this.setSeconds(0);
  949. this.setMilliseconds(0);
  950. return this;
  951. };
  952. /**
  953. * Resets the time of this Date object to the current time ('now').
  954. * @return {Date} this
  955. */
  956. $P.setTimeToNow = function () {
  957. var n = new Date();
  958. this.setHours(n.getHours());
  959. this.setMinutes(n.getMinutes());
  960. this.setSeconds(n.getSeconds());
  961. this.setMilliseconds(n.getMilliseconds());
  962. return this;
  963. };
  964. /**
  965. * Returns a new Date object that is an exact date and time copy of the original instance.
  966. * @return {Date} A new Date instance
  967. */
  968. $P.clone = function () {
  969. return new Date(this.getTime());
  970. };
  971. /**
  972. * Compares this instance to a Date object and returns an number indication of their relative values.
  973. * @param {Date} Date object to compare [Required]
  974. * @return {Number} -1 = this is lessthan date. 0 = values are equal. 1 = this is greaterthan date.
  975. */
  976. $P.compareTo = function (date) {
  977. return Date.compare(this, date);
  978. };
  979. /**
  980. * Compares this instance to another Date object and returns true if they are equal.
  981. * @param {Date} Date object to compare. If no date to compare, new Date() [now] is used.
  982. * @return {Boolean} true if dates are equal. false if they are not equal.
  983. */
  984. $P.equals = function (date) {
  985. return Date.equals(this, (date !== undefined ? date : new Date()));
  986. };
  987. /**
  988. * Determines if this instance is between a range of two dates or equal to either the start or end dates.
  989. * @param {Date} Start of range [Required]
  990. * @param {Date} End of range [Required]
  991. * @return {Boolean} true is this is between or equal to the start and end dates, else false
  992. */
  993. $P.between = function (start, end) {
  994. return this.getTime() >= start.getTime() && this.getTime() <= end.getTime();
  995. };
  996. /**
  997. * Determines if this date occurs after the date to compare to.
  998. * @param {Date} Date object to compare. If no date to compare, new Date() ("now") is used.
  999. * @return {Boolean} true if this date instance is greater than the date to compare to (or "now"), otherwise false.
  1000. */
  1001. $P.isAfter = function (date) {
  1002. return this.compareTo(date || new Date()) === 1;
  1003. };
  1004. /**
  1005. * Determines if this date occurs before the date to compare to.
  1006. * @param {Date} Date object to compare. If no date to compare, new Date() ("now") is used.
  1007. * @return {Boolean} true if this date instance is less than the date to compare to (or "now").
  1008. */
  1009. $P.isBefore = function (date) {
  1010. return (this.compareTo(date || new Date()) === -1);
  1011. };
  1012. /**
  1013. * Determines if the current Date instance occurs today.
  1014. * @return {Boolean} true if this date instance is 'today', otherwise false.
  1015. */
  1016. /**
  1017. * Determines if the current Date instance occurs on the same Date as the supplied 'date'.
  1018. * If no 'date' to compare to is provided, the current Date instance is compared to 'today'.
  1019. * @param {date} Date object to compare. If no date to compare, the current Date ("now") is used.
  1020. * @return {Boolean} true if this Date instance occurs on the same Day as the supplied 'date'.
  1021. */
  1022. $P.isToday = $P.isSameDay = function (date) {
  1023. return this.clone().clearTime().equals((date || new Date()).clone().clearTime());
  1024. };
  1025. /**
  1026. * Adds the specified number of milliseconds to this instance.
  1027. * @param {Number} The number of milliseconds to add. The number can be positive or negative [Required]
  1028. * @return {Date} this
  1029. */
  1030. $P.addMilliseconds = function (value) {
  1031. if (!value) { return this; }
  1032. this.setTime(this.getTime() + value * 1);
  1033. return this;
  1034. };
  1035. /**
  1036. * Adds the specified number of seconds to this instance.
  1037. * @param {Number} The number of seconds to add. The number can be positive or negative [Required]
  1038. * @return {Date} this
  1039. */
  1040. $P.addSeconds = function (value) {
  1041. if (!value) { return this; }
  1042. return this.addMilliseconds(value * 1000);
  1043. };
  1044. /**
  1045. * Adds the specified number of seconds to this instance.
  1046. * @param {Number} The number of seconds to add. The number can be positive or negative [Required]
  1047. * @return {Date} this
  1048. */
  1049. $P.addMinutes = function (value) {
  1050. if (!value) { return this; }
  1051. return this.addMilliseconds(value * 60000); // 60*1000
  1052. };
  1053. /**
  1054. * Adds the specified number of hours to this instance.
  1055. * @param {Number} The number of hours to add. The number can be positive or negative [Required]
  1056. * @return {Date} this
  1057. */
  1058. $P.addHours = function (value) {
  1059. if (!value) { return this; }
  1060. return this.addMilliseconds(value * 3600000); // 60*60*1000
  1061. };
  1062. /**
  1063. * Adds the specified number of days to this instance.
  1064. * @param {Number} The number of days to add. The number can be positive or negative [Required]
  1065. * @return {Date} this
  1066. */
  1067. $P.addDays = function (value) {
  1068. if (!value) { return this; }
  1069. this.setDate(this.getDate() + value * 1);
  1070. return this;
  1071. };
  1072. /**
  1073. * Adds the specified number of weekdays (ie - not sat or sun) to this instance.
  1074. * @param {Number} The number of days to add. The number can be positive or negative [Required]
  1075. * @return {Date} this
  1076. */
  1077. $P.addWeekdays = function (value) {
  1078. if (!value) { return this; }
  1079. var day = this.getDay();
  1080. var weeks = (Math.ceil(Math.abs(value)/7));
  1081. if (day === 0 || day === 6) {
  1082. if (value > 0) {
  1083. this.next().monday();
  1084. this.addDays(-1);
  1085. day = this.getDay();
  1086. }
  1087. }
  1088. if (value < 0) {
  1089. while (value < 0) {
  1090. this.addDays(-1);
  1091. day = this.getDay();
  1092. if (day !== 0 && day !== 6) {
  1093. value++;
  1094. }
  1095. }
  1096. return this;
  1097. } else if (value > 5 || (6-day) <= value) {
  1098. value = value + (weeks * 2);
  1099. }
  1100. return this.addDays(value);
  1101. };
  1102. /**
  1103. * Adds the specified number of weeks to this instance.
  1104. * @param {Number} The number of weeks to add. The number can be positive or negative [Required]
  1105. * @return {Date} this
  1106. */
  1107. $P.addWeeks = function (value) {
  1108. if (!value) { return this; }
  1109. return this.addDays(value * 7);
  1110. };
  1111. /**
  1112. * Adds the specified number of months to this instance.
  1113. * @param {Number} The number of months to add. The number can be positive or negative [Required]
  1114. * @return {Date} this
  1115. */
  1116. $P.addMonths = function (value) {
  1117. if (!value) { return this; }
  1118. var n = this.getDate();
  1119. this.setDate(1);
  1120. this.setMonth(this.getMonth() + value * 1);
  1121. this.setDate(Math.min(n, $D.getDaysInMonth(this.getFullYear(), this.getMonth())));
  1122. return this;
  1123. };
  1124. $P.addQuarters = function (value) {
  1125. if (!value) { return this; }
  1126. // note this will take you to the same point in the quarter as you are now.
  1127. // i.e. - if you are 15 days into the quarter you'll be 15 days into the resulting one.
  1128. // bonus: this allows adding fractional quarters
  1129. return this.addMonths(value * 3);
  1130. };
  1131. /**
  1132. * Adds the specified number of years to this instance.
  1133. * @param {Number} The number of years to add. The number can be positive or negative [Required]
  1134. * @return {Date} this
  1135. */
  1136. $P.addYears = function (value) {
  1137. if (!value) { return this; }
  1138. return this.addMonths(value * 12);
  1139. };
  1140. /**
  1141. * Adds (or subtracts) to the value of the years, months, weeks, days, hours, minutes, seconds, milliseconds of the date instance using given configuration object. Positive and Negative values allowed.
  1142. * Example
  1143. <pre><code>
  1144. Date.today().add( { days: 1, months: 1 } )
  1145. new Date().add( { years: -1 } )
  1146. </code></pre>
  1147. * @param {Object} Configuration object containing attributes (months, days, etc.)
  1148. * @return {Date} this
  1149. */
  1150. $P.add = function (config) {
  1151. if (typeof config === "number") {
  1152. this._orient = config;
  1153. return this;
  1154. }
  1155. var x = config;
  1156. if (x.day) {
  1157. // If we should be a different date than today (eg: for 'tomorrow -1d', etc).
  1158. // Should only effect parsing, not direct usage (eg, Finish and FinishExact)
  1159. if ((x.day - this.getDate()) !== 0) {
  1160. this.setDate(x.day);
  1161. }
  1162. }
  1163. if (x.milliseconds) {
  1164. this.addMilliseconds(x.milliseconds);
  1165. }
  1166. if (x.seconds) {
  1167. this.addSeconds(x.seconds);
  1168. }
  1169. if (x.minutes) {
  1170. this.addMinutes(x.minutes);
  1171. }
  1172. if (x.hours) {
  1173. this.addHours(x.hours);
  1174. }
  1175. if (x.weeks) {
  1176. this.addWeeks(x.weeks);
  1177. }
  1178. if (x.months) {
  1179. this.addMonths(x.months);
  1180. }
  1181. if (x.years) {
  1182. this.addYears(x.years);
  1183. }
  1184. if (x.days) {
  1185. this.addDays(x.days);
  1186. }
  1187. return this;
  1188. };
  1189. /**
  1190. * Get the week number. Week one (1) is the week which contains the first Thursday of the year. Monday is considered the first day of the week.
  1191. * The .getWeek() function does NOT convert the date to UTC. The local datetime is used.
  1192. * Please use .getISOWeek() to get the week of the UTC converted date.
  1193. * @return {Number} 1 to 53
  1194. */
  1195. $P.getWeek = function (utc) {
  1196. // Create a copy of this date object
  1197. var self, target = new Date(this.valueOf());
  1198. if (utc) {
  1199. target.addMinutes(target.getTimezoneOffset());
  1200. self = target.clone();
  1201. } else {
  1202. self = this;
  1203. }
  1204. // ISO week date weeks start on monday
  1205. // so correct the day number
  1206. var dayNr = (self.getDay() + 6) % 7;
  1207. // ISO 8601 states that week 1 is the week
  1208. // with the first thursday of that year.
  1209. // Set the target date to the thursday in the target week
  1210. target.setDate(target.getDate() - dayNr + 3);
  1211. // Store the millisecond value of the target date
  1212. var firstThursday = target.valueOf();
  1213. // Set the target to the first thursday of the year
  1214. // First set the target to january first
  1215. target.setMonth(0, 1);
  1216. // Not a thursday? Correct the date to the next thursday
  1217. if (target.getDay() !== 4) {
  1218. target.setMonth(0, 1 + ((4 - target.getDay()) + 7) % 7);
  1219. }
  1220. // The weeknumber is the number of weeks between the
  1221. // first thursday of the year and the thursday in the target week
  1222. return 1 + Math.ceil((firstThursday - target) / 604800000); // 604800000 = 7 * 24 * 3600 * 1000
  1223. };
  1224. /**
  1225. * Get the ISO 8601 week number. Week one ("01") is the week which contains the first Thursday of the year. Monday is considered the first day of the week.
  1226. * The .getISOWeek() function does convert the date to it's UTC value. Please use .getWeek() to get the week of the local date.
  1227. * @return {String} "01" to "53"
  1228. */
  1229. $P.getISOWeek = function () {
  1230. return p(this.getWeek(true));
  1231. };
  1232. /**
  1233. * Moves the date to Monday of the week set. Week one (1) is the week which contains the first Thursday of the year.
  1234. * @param {Number} A Number (1 to 53) that represents the week of the year.
  1235. * @return {Date} this
  1236. */
  1237. $P.setWeek = function (n) {
  1238. if ((n - this.getWeek()) === 0) {
  1239. if (this.getDay() !== 1) {
  1240. return this.moveToDayOfWeek(1, (this.getDay() > 1 ? -1 : 1));
  1241. } else {
  1242. return this;
  1243. }
  1244. } else {
  1245. return this.moveToDayOfWeek(1, (this.getDay() > 1 ? -1 : 1)).addWeeks(n - this.getWeek());
  1246. }
  1247. };
  1248. $P.setQuarter = function (qtr) {
  1249. var month = Math.abs(((qtr-1) * 3) + 1);
  1250. return this.setMonth(month, 1);
  1251. };
  1252. $P.getQuarter = function () {
  1253. return Date.getQuarter(this);
  1254. };
  1255. $P.getDaysLeftInQuarter = function () {
  1256. return Date.getDaysLeftInQuarter(this);
  1257. };
  1258. /**
  1259. * Moves the date to the next n'th occurrence of the dayOfWeek starting from the beginning of the month. The number (-1) is a magic number and will return the last occurrence of the dayOfWeek in the month.
  1260. * @param {Number} The dayOfWeek to move to
  1261. * @param {Number} The n'th occurrence to move to. Use (-1) to return the last occurrence in the month
  1262. * @return {Date} this
  1263. */
  1264. $P.moveToNthOccurrence = function (dayOfWeek, occurrence) {
  1265. if (dayOfWeek === "Weekday") {
  1266. if (occurrence > 0) {
  1267. this.moveToFirstDayOfMonth();
  1268. if (this.is().weekday()) {
  1269. occurrence -= 1;
  1270. }
  1271. } else if (occurrence < 0) {
  1272. this.moveToLastDayOfMonth();
  1273. if (this.is().weekday()) {
  1274. occurrence += 1;
  1275. }
  1276. } else {
  1277. return this;
  1278. }
  1279. return this.addWeekdays(occurrence);
  1280. }
  1281. var shift = 0;
  1282. if (occurrence > 0) {
  1283. shift = occurrence - 1;
  1284. }
  1285. else if (occurrence === -1) {
  1286. this.moveToLastDayOfMonth();
  1287. if (this.getDay() !== dayOfWeek) {
  1288. this.moveToDayOfWeek(dayOfWeek, -1);
  1289. }
  1290. return this;
  1291. }
  1292. return this.moveToFirstDayOfMonth().addDays(-1).moveToDayOfWeek(dayOfWeek, +1).addWeeks(shift);
  1293. };
  1294. var moveToN = function (getFunc, addFunc, nVal) {
  1295. return function (value, orient) {
  1296. var diff = (value - this[getFunc]() + nVal * (orient || +1)) % nVal;
  1297. return this[addFunc]((diff === 0) ? diff += nVal * (orient || +1) : diff);
  1298. };
  1299. };
  1300. /**
  1301. * Move to the next or last dayOfWeek based on the orient value.
  1302. * @param {Number} The dayOfWeek to move to
  1303. * @param {Number} Forward (+1) or Back (-1). Defaults to +1. [Optional]
  1304. * @return {Date} this
  1305. */
  1306. $P.moveToDayOfWeek = moveToN("getDay", "addDays", 7);
  1307. /**
  1308. * Move to the next or last month based on the orient value.
  1309. * @param {Number} The month to move to. 0 = January, 11 = December
  1310. * @param {Number} Forward (+1) or Back (-1). Defaults to +1. [Optional]
  1311. * @return {Date} this
  1312. */
  1313. $P.moveToMonth = moveToN("getMonth", "addMonths", 12);
  1314. /**
  1315. * Get the Ordinate of the current day ("th", "st", "rd").
  1316. * @return {String}
  1317. */
  1318. $P.getOrdinate = function () {
  1319. var num = this.getDate();
  1320. return ord(num);
  1321. };
  1322. /**
  1323. * Get the Ordinal day (numeric day number) of the year, adjusted for leap year.
  1324. * @return {Number} 1 through 365 (366 in leap years)
  1325. */
  1326. $P.getOrdinalNumber = function () {
  1327. return Math.ceil((this.clone().clearTime() - new Date(this.getFullYear(), 0, 1)) / 86400000) + 1;
  1328. };
  1329. /**
  1330. * Get the time zone abbreviation of the current date.
  1331. * @return {String} The abbreviated time zone name (e.g. "EST")
  1332. */
  1333. $P.getTimezone = function () {
  1334. return $D.getTimezoneAbbreviation(this.getUTCOffset(), this.isDaylightSavingTime());
  1335. };
  1336. $P.setTimezoneOffset = function (offset) {
  1337. var here = this.getTimezoneOffset(), there = Number(offset) * -6 / 10;
  1338. return (there || there === 0) ? this.addMinutes(there - here) : this;
  1339. };
  1340. $P.setTimezone = function (offset) {
  1341. return this.setTimezoneOffset($D.getTimezoneOffset(offset));
  1342. };
  1343. /**
  1344. * Indicates whether Daylight Saving Time is observed in the current time zone.
  1345. * @return {Boolean} true|false
  1346. */
  1347. $P.hasDaylightSavingTime = function () {
  1348. return (Date.today().set({month: 0, day: 1}).getTimezoneOffset() !== Date.today().set({month: 6, day: 1}).getTimezoneOffset());
  1349. };
  1350. /**
  1351. * Indicates whether this Date instance is within the Daylight Saving Time range for the current time zone.
  1352. * @return {Boolean} true|false
  1353. */
  1354. $P.isDaylightSavingTime = function () {
  1355. return Date.today().set({month: 0, day: 1}).getTimezoneOffset() !== this.getTimezoneOffset();
  1356. };
  1357. /**
  1358. * Get the offset from UTC of the current date.
  1359. * @return {String} The 4-character offset string prefixed with + or - (e.g. "-0500")
  1360. */
  1361. $P.getUTCOffset = function (offset) {
  1362. var n = (offset || this.getTimezoneOffset()) * -10 / 6, r;
  1363. if (n < 0) {
  1364. r = (n - 10000).toString();
  1365. return r.charAt(0) + r.substr(2);
  1366. } else {
  1367. r = (n + 10000).toString();
  1368. return "+" + r.substr(1);
  1369. }
  1370. };
  1371. /**
  1372. * Returns the number of milliseconds between this date and date.
  1373. * @param {Date} Defaults to now
  1374. * @return {Number} The diff in milliseconds
  1375. */
  1376. $P.getElapsed = function (date) {
  1377. return (date || new Date()) - this;
  1378. };
  1379. /**
  1380. * Set the value of year, month, day, hour, minute, second, millisecond of date instance using given configuration object.
  1381. * Example
  1382. <pre><code>
  1383. Date.today().set( { day: 20, month: 1 } )
  1384. new Date().set( { millisecond: 0 } )
  1385. </code></pre>
  1386. *
  1387. * @param {Object} Configuration object containing attributes (month, day, etc.)
  1388. * @return {Date} this
  1389. */
  1390. $P.set = function (config) {
  1391. config = validateConfigObject.call(this, config);
  1392. var key;
  1393. for (key in config) {
  1394. if (hasOwnProperty.call(config, key)) {
  1395. var name = key.charAt(0).toUpperCase() + key.slice(1);
  1396. var addFunc, getFunc;
  1397. if (key !== "week" && key !== "month" && key !== "timezone" && key !== "timezoneOffset") {
  1398. name += "s";
  1399. }
  1400. addFunc = "add" + name;
  1401. getFunc = "get" + name;
  1402. if (key === "month") {
  1403. addFunc = addFunc + "s";
  1404. } else if (key === "year"){
  1405. getFunc = "getFullYear";
  1406. }
  1407. if (key !== "day" && key !== "timezone" && key !== "timezoneOffset" && key !== "week" && key !== "hour") {
  1408. this[addFunc](config[key] - this[getFunc]());
  1409. } else if ( key === "timezone"|| key === "timezoneOffset" || key === "week" || key === "hour") {
  1410. this["set"+name](config[key]);
  1411. }
  1412. }
  1413. }
  1414. // day has to go last because you can't validate the day without first knowing the month
  1415. if (config.day) {
  1416. this.addDays(config.day - this.getDate());
  1417. }
  1418. return this;
  1419. };
  1420. /**
  1421. * Moves the date to the first day of the month.
  1422. * @return {Date} this
  1423. */
  1424. $P.moveToFirstDayOfMonth = function () {
  1425. return this.set({ day: 1 });
  1426. };
  1427. /**
  1428. * Moves the date to the last day of the month.
  1429. * @return {Date} this
  1430. */
  1431. $P.moveToLastDayOfMonth = function () {
  1432. return this.set({ day: $D.getDaysInMonth(this.getFullYear(), this.getMonth())});
  1433. };
  1434. /**
  1435. * Converts the value of the current Date object to its equivalent string representation.
  1436. * Format Specifiers
  1437. * CUSTOM DATE AND TIME FORMAT STRINGS
  1438. * Format Description Example
  1439. * ------ --------------------------------------------------------------------------- -----------------------
  1440. * s The seconds of the minute between 0-59. "0" to "59"
  1441. * ss The seconds of the minute with leading zero if required. "00" to "59"
  1442. *
  1443. * m The minute of the hour between 0-59. "0" or "59"
  1444. * mm The minute of the hour with leading zero if required. "00" or "59"
  1445. *
  1446. * h The hour of the day between 1-12. "1" to "12"
  1447. * hh The hour of the day with leading zero if required. "01" to "12"
  1448. *
  1449. * H The hour of the day between 0-23. "0" to "23"
  1450. * HH The hour of the day with leading zero if required. "00" to "23"
  1451. *
  1452. * d The day of the month between 1 and 31. "1" to "31"
  1453. * dd The day of the month with leading zero if required. "01" to "31"
  1454. * ddd Abbreviated day name. Date.CultureInfo.abbreviatedDayNames. "Mon" to "Sun"
  1455. * dddd The full day name. Date.CultureInfo.dayNames. "Monday" to "Sunday"
  1456. *
  1457. * M The month of the year between 1-12. "1" to "12"
  1458. * MM The month of the year with leading zero if required. "01" to "12"
  1459. * MMM Abbreviated month name. Date.CultureInfo.abbreviatedMonthNames. "Jan" to "Dec"
  1460. * MMMM The full month name. Date.CultureInfo.monthNames. "January" to "December"
  1461. *
  1462. * yy The year as a two-digit number. "99" or "08"
  1463. * yyyy The full four digit year. "1999" or "2008"
  1464. *
  1465. * t Displays the first character of the A.M./P.M. designator. "A" or "P"
  1466. * Date.CultureInfo.amDesignator or Date.CultureInfo.pmDesignator
  1467. * tt Displays the A.M./P.M. designator. "AM" or "PM"
  1468. * Date.CultureInfo.amDesignator or Date.CultureInfo.pmDesignator
  1469. *
  1470. * S The ordinal suffix ("st, "nd", "rd" or "th") of the current day. "st, "nd", "rd" or "th"
  1471. *
  1472. * STANDARD DATE AND TIME FORMAT STRINGS
  1473. * Format Description Example
  1474. *------ --------------------------------------------------------------------------- -----------------------
  1475. * d The CultureInfo shortDate Format Pattern "M/d/yyyy"
  1476. * D The CultureInfo longDate Format Pattern "dddd, MMMM dd, yyyy"
  1477. * F The CultureInfo fullDateTime Format Pattern "dddd, MMMM dd, yyyy h:mm:ss tt"
  1478. * m The CultureInfo monthDay Format Pattern "MMMM dd"
  1479. * r The CultureInfo rfc1123 Format Pattern "ddd, dd MMM yyyy HH:mm:ss GMT"
  1480. * s The CultureInfo sortableDateTime Format Pattern "yyyy-MM-ddTHH:mm:ss"
  1481. * t The CultureInfo shortTime Format Pattern "h:mm tt"
  1482. * T The CultureInfo longTime Format Pattern "h:mm:ss tt"
  1483. * u The CultureInfo universalSortableDateTime Format Pattern "yyyy-MM-dd HH:mm:ssZ"
  1484. * y The CultureInfo yearMonth Format Pattern "MMMM, yyyy"
  1485. *
  1486. * @param {String} A format string consisting of one or more format spcifiers [Optional].
  1487. * @return {String} A string representation of the current Date object.
  1488. */
  1489. var ord = function (n) {
  1490. switch (n * 1) {
  1491. case 1:
  1492. case 21:
  1493. case 31:
  1494. return "st";
  1495. case 2:
  1496. case 22:
  1497. return "nd";
  1498. case 3:
  1499. case 23:
  1500. return "rd";
  1501. default:
  1502. return "th";
  1503. }
  1504. };
  1505. var parseStandardFormats = function (format) {
  1506. var y, c = Date.CultureInfo.formatPatterns;
  1507. switch (format) {
  1508. case "d":
  1509. return this.toString(c.shortDate);
  1510. case "D":
  1511. return this.toString(c.longDate);
  1512. case "F":
  1513. return this.toString(c.fullDateTime);
  1514. case "m":
  1515. return this.toString(c.monthDay);
  1516. case "r":
  1517. case "R":
  1518. y = this.clone().addMinutes(this.getTimezoneOffset());
  1519. return y.toString(c.rfc1123) + " GMT";
  1520. case "s":
  1521. return this.toString(c.sortableDateTime);
  1522. case "t":
  1523. return this.toString(c.shortTime);
  1524. case "T":
  1525. return this.toString(c.longTime);
  1526. case "u":
  1527. y = this.clone().addMinutes(this.getTimezoneOffset());
  1528. return y.toString(c.universalSortableDateTime);
  1529. case "y":
  1530. return this.toString(c.yearMonth);
  1531. default:
  1532. return false;
  1533. }
  1534. };
  1535. var parseFormatStringsClosure = function (context) {
  1536. return function (m) {
  1537. if (m.charAt(0) === "\\") {
  1538. return m.replace("\\", "");
  1539. }
  1540. switch (m) {
  1541. case "hh":
  1542. return p(context.getHours() < 13 ? (context.getHours() === 0 ? 12 : context.getHours()) : (context.getHours() - 12));
  1543. case "h":
  1544. return context.getHours() < 13 ? (context.getHours() === 0 ? 12 : context.getHours()) : (context.getHours() - 12);
  1545. case "HH":
  1546. return p(context.getHours());
  1547. case "H":
  1548. return context.getHours();
  1549. case "mm":
  1550. return p(context.getMinutes());
  1551. case "m":
  1552. return context.getMinutes();
  1553. case "ss":
  1554. return p(context.getSeconds());
  1555. case "s":
  1556. return context.getSeconds();
  1557. case "yyyy":
  1558. return p(context.getFullYear(), 4);
  1559. case "yy":
  1560. return p(context.getFullYear());
  1561. case "y":
  1562. return context.getFullYear();
  1563. case "E":
  1564. case "dddd":
  1565. return Date.CultureInfo.dayNames[context.getDay()];
  1566. case "ddd":
  1567. return Date.CultureInfo.abbreviatedDayNames[context.getDay()];
  1568. case "dd":
  1569. return p(context.getDate());
  1570. case "d":
  1571. return context.getDate();
  1572. case "MMMM":
  1573. return Date.CultureInfo.monthNames[context.getMonth()];
  1574. case "MMM":
  1575. return Date.CultureInfo.abbreviatedMonthNames[context.getMonth()];
  1576. case "MM":
  1577. return p((context.getMonth() + 1));
  1578. case "M":
  1579. return context.getMonth() + 1;
  1580. case "t":
  1581. return context.getHours() < 12 ? Date.CultureInfo.amDesignator.substring(0, 1) : Date.CultureInfo.pmDesignator.substring(0, 1);
  1582. case "tt":
  1583. return context.getHours() < 12 ? Date.CultureInfo.amDesignator : Date.CultureInfo.pmDesignator;
  1584. case "S":
  1585. return ord(context.getDate());
  1586. case "W":
  1587. return context.getWeek();
  1588. case "WW":
  1589. return context.getISOWeek();
  1590. case "Q":
  1591. return "Q" + context.getQuarter();
  1592. case "q":
  1593. return String(context.getQuarter());
  1594. case "z":
  1595. return context.getTimezone();
  1596. case "Z":
  1597. case "X":
  1598. return Date.getTimezoneOffset(context.getTimezone());
  1599. case "ZZ": // Timezone offset in seconds
  1600. return context.getTimezoneOffset() * -60;
  1601. case "u":
  1602. return context.getDay();
  1603. case "L":
  1604. return ($D.isLeapYear(context.getFullYear())) ? 1 : 0;
  1605. case "B":
  1606. // Swatch Internet Time (.beats)
  1607. return "@"+((context.getUTCSeconds() + (context.getUTCMinutes()*60) + ((context.getUTCHours()+1)*3600))/86.4);
  1608. default:
  1609. return m;
  1610. }
  1611. };
  1612. };
  1613. $P.toString = function (format, ignoreStandards) {
  1614. // Standard Date and Time Format Strings. Formats pulled from CultureInfo file and
  1615. // may vary by culture.
  1616. if (!ignoreStandards && format && format.length === 1) {
  1617. output = parseStandardFormats.call(this, format);
  1618. if (output) {
  1619. return output;
  1620. }
  1621. }
  1622. var parseFormatStrings = parseFormatStringsClosure(this);
  1623. return format ? format.replace(/((\\)?(dd?d?d?|MM?M?M?|yy?y?y?|hh?|HH?|mm?|ss?|tt?|S|q|Q|WW?W?W?)(?![^\[]*\]))/g, parseFormatStrings).replace(/\[|\]/g, "") : this._toString();
  1624. };
  1625. }());
  1626. /*************************************************************
  1627. * SugarPak - Domain Specific Language - Syntactical Sugar *
  1628. *************************************************************/
  1629. (function () {
  1630. var $D = Date, $P = $D.prototype, $N = Number.prototype;
  1631. // private
  1632. $P._orient = +1;
  1633. // private
  1634. $P._nth = null;
  1635. // private
  1636. $P._is = false;
  1637. // private
  1638. $P._same = false;
  1639. // private
  1640. $P._isSecond = false;
  1641. // private
  1642. $N._dateElement = "days";
  1643. /**
  1644. * Moves the date to the next instance of a date as specified by the subsequent date element function (eg. .day(), .month()), month name function (eg. .january(), .jan()) or day name function (eg. .friday(), fri()).
  1645. * Example
  1646. <pre><code>
  1647. Date.today().next().friday();
  1648. Date.today().next().fri();
  1649. Date.today().next().march();
  1650. Date.today().next().mar();
  1651. Date.today().next().week();
  1652. </code></pre>
  1653. *
  1654. * @return {Date} date
  1655. */
  1656. $P.next = function () {
  1657. this._move = true;
  1658. this._orient = +1;
  1659. return this;
  1660. };
  1661. /**
  1662. * Creates a new Date (Date.today()) and moves the date to the next instance of the date as specified by the subsequent date element function (eg. .day(), .month()), month name function (eg. .january(), .jan()) or day name function (eg. .friday(), fri()).
  1663. * Example
  1664. <pre><code>
  1665. Date.next().friday();
  1666. Date.next().fri();
  1667. Date.next().march();
  1668. Date.next().mar();
  1669. Date.next().week();
  1670. </code></pre>
  1671. *
  1672. * @return {Date} date
  1673. */
  1674. $D.next = function () {
  1675. return $D.today().next();
  1676. };
  1677. /**
  1678. * Moves the date to the previous instance of a date as specified by the subsequent date element function (eg. .day(), .month()), month name function (eg. .january(), .jan()) or day name function (eg. .friday(), fri()).
  1679. * Example
  1680. <pre><code>
  1681. Date.today().last().friday();
  1682. Date.today().last().fri();
  1683. Date.today().last().march();
  1684. Date.today().last().mar();
  1685. Date.today().last().week();
  1686. </code></pre>
  1687. *
  1688. * @return {Date} date
  1689. */
  1690. $P.last = $P.prev = $P.previous = function () {
  1691. this._move = true;
  1692. this._orient = -1;
  1693. return this;
  1694. };
  1695. /**
  1696. * Creates a new Date (Date.today()) and moves the date to the previous instance of the date as specified by the subsequent date element function (eg. .day(), .month()), month name function (eg. .january(), .jan()) or day name function (eg. .friday(), fri()).
  1697. * Example
  1698. <pre><code>
  1699. Date.last().friday();
  1700. Date.last().fri();
  1701. Date.previous().march();
  1702. Date.prev().mar();
  1703. Date.last().week();
  1704. </code></pre>
  1705. *
  1706. * @return {Date} date
  1707. */
  1708. $D.last = $D.prev = $D.previous = function () {
  1709. return $D.today().last();
  1710. };
  1711. /**
  1712. * Performs a equality check when followed by either a month name, day name or .weekday() function.
  1713. * Example
  1714. <pre><code>
  1715. Date.today().is().friday(); // true|false
  1716. Date.today().is().fri();
  1717. Date.today().is().march();
  1718. Date.today().is().mar();
  1719. </code></pre>
  1720. *
  1721. * @return {Boolean} true|false
  1722. */
  1723. $P.is = function () {
  1724. this._is = true;
  1725. return this;
  1726. };
  1727. /**
  1728. * Determines if two date objects occur on/in exactly the same instance of the subsequent date part function.
  1729. * The function .same() must be followed by a date part function (example: .day(), .month(), .year(), etc).
  1730. *
  1731. * An optional Date can be passed in the date part function. If now date is passed as a parameter, 'Now' is used.
  1732. *
  1733. * The following example demonstrates how to determine if two dates fall on the exact same day.
  1734. *
  1735. * Example
  1736. <pre><code>
  1737. var d1 = Date.today(); // today at 00:00
  1738. var d2 = new Date(); // exactly now.
  1739. // Do they occur on the same day?
  1740. d1.same().day(d2); // true
  1741. // Do they occur on the same hour?
  1742. d1.same().hour(d2); // false, unless d2 hour is '00' (midnight).
  1743. // What if it's the same day, but one year apart?
  1744. var nextYear = Date.today().add(1).year();
  1745. d1.same().day(nextYear); // false, because the dates must occur on the exact same day.
  1746. </code></pre>
  1747. *
  1748. * Scenario: Determine if a given date occurs during some week period 2 months from now.
  1749. *
  1750. * Example
  1751. <pre><code>
  1752. var future = Date.today().add(2).months();
  1753. return someDate.same().week(future); // true|false;
  1754. </code></pre>
  1755. *
  1756. * @return {Boolean} true|false
  1757. */
  1758. $P.same = function () {
  1759. this._same = true;
  1760. this._isSecond = false;
  1761. return this;
  1762. };
  1763. /**
  1764. * Determines if the current date/time occurs during Today. Must be preceded by the .is() function.
  1765. * Example
  1766. <pre><code>
  1767. someDate.is().today(); // true|false
  1768. new Date().is().today(); // true
  1769. Date.today().is().today();// true
  1770. Date.today().add(-1).day().is().today(); // false
  1771. </code></pre>
  1772. *
  1773. * @return {Boolean} true|false
  1774. */
  1775. $P.today = function () {
  1776. return this.same().day();
  1777. };
  1778. /**
  1779. * Determines if the current date is a weekday. This function must be preceded by the .is() function.
  1780. * Example
  1781. <pre><code>
  1782. Date.today().is().weekday(); // true|false
  1783. </code></pre>
  1784. *
  1785. * @return {Boolean} true|false
  1786. */
  1787. $P.weekday = function () {
  1788. if (this._nth) {
  1789. return df("Weekday").call(this);
  1790. }
  1791. if (this._move) {
  1792. return this.addWeekdays(this._orient);
  1793. }
  1794. if (this._is) {
  1795. this._is = false;
  1796. return (!this.is().sat() && !this.is().sun());
  1797. }
  1798. return false;
  1799. };
  1800. /**
  1801. * Determines if the current date is on the weekend. This function must be preceded by the .is() function.
  1802. * Example
  1803. <pre><code>
  1804. Date.today().is().weekend(); // true|false
  1805. </code></pre>
  1806. *
  1807. * @return {Boolean} true|false
  1808. */
  1809. $P.weekend = function () {
  1810. if (this._is) {
  1811. this._is = false;
  1812. return (this.is().sat() || this.is().sun());
  1813. }
  1814. return false;
  1815. };
  1816. /**
  1817. * Sets the Time of the current Date instance. A string "6:15 pm" or config object {hour:18, minute:15} are accepted.
  1818. * Example
  1819. <pre><code>
  1820. // Set time to 6:15pm with a String
  1821. Date.today().at("6:15pm");
  1822. // Set time to 6:15pm with a config object
  1823. Date.today().at({hour:18, minute:15});
  1824. </code></pre>
  1825. *
  1826. * @return {Date} date
  1827. */
  1828. $P.at = function (time) {
  1829. return (typeof time === "string") ? $D.parse(this.toString("d") + " " + time) : this.set(time);
  1830. };
  1831. /**
  1832. * Creates a new Date() and adds this (Number) to the date based on the preceding date element function (eg. second|minute|hour|day|month|year).
  1833. * Example
  1834. <pre><code>
  1835. // Undeclared Numbers must be wrapped with parentheses. Requirment of JavaScript.
  1836. (3).days().fromNow();
  1837. (6).months().fromNow();
  1838. // Declared Number variables do not require parentheses.
  1839. var n = 6;
  1840. n.months().fromNow();
  1841. </code></pre>
  1842. *
  1843. * @return {Date} A new Date instance
  1844. */
  1845. $N.fromNow = $N.after = function (date) {
  1846. var c = {};
  1847. c[this._dateElement] = this;
  1848. return ((!date) ? new Date() : date.clone()).add(c);
  1849. };
  1850. /**
  1851. * Creates a new Date() and subtract this (Number) from the date based on the preceding date element function (eg. second|minute|hour|day|month|year).
  1852. * Example
  1853. <pre><code>
  1854. // Undeclared Numbers must be wrapped with parentheses. Requirment of JavaScript.
  1855. (3).days().ago();
  1856. (6).months().ago();
  1857. // Declared Number variables do not require parentheses.
  1858. var n = 6;
  1859. n.months().ago();
  1860. </code></pre>
  1861. *
  1862. * @return {Date} A new Date instance
  1863. */
  1864. $N.ago = $N.before = function (date) {
  1865. var c = {},
  1866. s = (this._dateElement[this._dateElement.length-1] !== "s") ? this._dateElement + "s" : this._dateElement;
  1867. c[s] = this * -1;
  1868. return ((!date) ? new Date() : date.clone()).add(c);
  1869. };
  1870. // Do NOT modify the following string tokens. These tokens are used to build dynamic functions.
  1871. // All culture-specific strings can be found in the CultureInfo files.
  1872. var dx = ("sunday monday tuesday wednesday thursday friday saturday").split(/\s/),
  1873. mx = ("january february march april may june july august september october november december").split(/\s/),
  1874. px = ("Millisecond Second Minute Hour Day Week Month Year Quarter Weekday").split(/\s/),
  1875. pxf = ("Milliseconds Seconds Minutes Hours Date Week Month FullYear Quarter").split(/\s/),
  1876. nth = ("final first second third fourth fifth").split(/\s/),
  1877. de;
  1878. /**
  1879. * Returns an object literal of all the date parts.
  1880. * Example
  1881. <pre><code>
  1882. var o = new Date().toObject();
  1883. // { year: 2008, month: 4, week: 20, day: 13, hour: 18, minute: 9, second: 32, millisecond: 812 }
  1884. // The object properties can be referenced directly from the object.
  1885. alert(o.day); // alerts "13"
  1886. alert(o.year); // alerts "2008"
  1887. </code></pre>
  1888. *
  1889. * @return {Date} An object literal representing the original date object.
  1890. */
  1891. $P.toObject = function () {
  1892. var o = {};
  1893. for (var i = 0; i < px.length; i++) {
  1894. if (this["get" + pxf[i]]) {
  1895. o[px[i].toLowerCase()] = this["get" + pxf[i]]();
  1896. }
  1897. }
  1898. return o;
  1899. };
  1900. /**
  1901. * Returns a date created from an object literal. Ignores the .week property if set in the config.
  1902. * Example
  1903. <pre><code>
  1904. var o = new Date().toObject();
  1905. return Date.fromObject(o); // will return the same date.
  1906. var o2 = {month: 1, day: 20, hour: 18}; // birthday party!
  1907. Date.fromObject(o2);
  1908. </code></pre>
  1909. *
  1910. * @return {Date} An object literal representing the original date object.
  1911. */
  1912. $D.fromObject = function(config) {
  1913. config.week = null;
  1914. return Date.today().set(config);
  1915. };
  1916. // Create day name functions and abbreviated day name functions (eg. monday(), friday(), fri()).
  1917. var df = function (n) {
  1918. return function () {
  1919. if (this._is) {
  1920. this._is = false;
  1921. return this.getDay() === n;
  1922. }
  1923. if (this._move) { this._move = null; }
  1924. if (this._nth !== null) {
  1925. // If the .second() function was called earlier, remove the _orient
  1926. // from the date, and then continue.
  1927. // This is required because 'second' can be used in two different context.
  1928. //
  1929. // Example
  1930. //
  1931. // Date.today().add(1).second();
  1932. // Date.march().second().monday();
  1933. //
  1934. // Things get crazy with the following...
  1935. // Date.march().add(1).second().second().monday(); // but it works!!
  1936. //
  1937. if (this._isSecond) {
  1938. this.addSeconds(this._orient * -1);
  1939. }
  1940. // make sure we reset _isSecond
  1941. this._isSecond = false;
  1942. var ntemp = this._nth;
  1943. this._nth = null;
  1944. var temp = this.clone().moveToLastDayOfMonth();
  1945. this.moveToNthOccurrence(n, ntemp);
  1946. if (this > temp) {
  1947. throw new RangeError($D.getDayName(n) + " does not occur " + ntemp + " times in the month of " + $D.getMonthName(temp.getMonth()) + " " + temp.getFullYear() + ".");
  1948. }
  1949. return this;
  1950. }
  1951. return this.moveToDayOfWeek(n, this._orient);
  1952. };
  1953. };
  1954. var sdf = function (n) {
  1955. return function () {
  1956. var t = $D.today(), shift = n - t.getDay();
  1957. if (n === 0 && Date.CultureInfo.firstDayOfWeek === 1 && t.getDay() !== 0) {
  1958. shift = shift + 7;
  1959. }
  1960. return t.addDays(shift);
  1961. };
  1962. };
  1963. // Create month name functions and abbreviated month name functions (eg. january(), march(), mar()).
  1964. var month_instance_functions = function (n) {
  1965. return function () {
  1966. if (this._is) {
  1967. this._is = false;
  1968. return this.getMonth() === n;
  1969. }
  1970. return this.moveToMonth(n, this._orient);
  1971. };
  1972. };
  1973. var month_static_functions = function (n) {
  1974. return function () {
  1975. return $D.today().set({ month: n, day: 1 });
  1976. };
  1977. };
  1978. var processTerms = function (names, staticFunc, instanceFunc) {
  1979. for (var i = 0; i < names.length; i++) {
  1980. // Create constant static Name variables.
  1981. $D[names[i].toUpperCase()] = $D[names[i].toUpperCase().substring(0, 3)] = i;
  1982. // Create Name functions.
  1983. $D[names[i]] = $D[names[i].substring(0, 3)] = staticFunc(i);
  1984. // Create Name instance functions.
  1985. $P[names[i]] = $P[names[i].substring(0, 3)] = instanceFunc(i);
  1986. }
  1987. };
  1988. processTerms(dx, sdf, df);
  1989. processTerms(mx, month_static_functions, month_instance_functions);
  1990. // Create date element functions and plural date element functions used with Date (eg. day(), days(), months()).
  1991. var ef = function (j) {
  1992. return function () {
  1993. // if the .second() function was called earlier, the _orient
  1994. // has alread been added. Just return this and reset _isSecond.
  1995. if (this._isSecond) {
  1996. this._isSecond = false;
  1997. return this;
  1998. }
  1999. if (this._same) {
  2000. this._same = this._is = false;
  2001. var o1 = this.toObject(),
  2002. o2 = (arguments[0] || new Date()).toObject(),
  2003. v = "",
  2004. k = j.toLowerCase();
  2005. // the substr trick with -1 doesn't work in IE8 or less
  2006. k = (k[k.length-1] === "s") ? k.substring(0,k.length-1) : k;
  2007. for (var m = (px.length - 1); m > -1; m--) {
  2008. v = px[m].toLowerCase();
  2009. if (o1[v] !== o2[v]) {
  2010. return false;
  2011. }
  2012. if (k === v) {
  2013. break;
  2014. }
  2015. }
  2016. return true;
  2017. }
  2018. if (j.substring(j.length - 1) !== "s") {
  2019. j += "s";
  2020. }
  2021. if (this._move) { this._move = null; }
  2022. return this["add" + j](this._orient);
  2023. };
  2024. };
  2025. var nf = function (n) {
  2026. return function () {
  2027. this._dateElement = n;
  2028. return this;
  2029. };
  2030. };
  2031. for (var k = 0; k < px.length; k++) {
  2032. de = px[k].toLowerCase();
  2033. if(de !== "weekday") {
  2034. // Create date element functions and plural date element functions used with Date (eg. day(), days(), months()).
  2035. $P[de] = $P[de + "s"] = ef(px[k]);
  2036. // Create date element functions and plural date element functions used with Number (eg. day(), days(), months()).
  2037. $N[de] = $N[de + "s"] = nf(de + "s");
  2038. }
  2039. }
  2040. $P._ss = ef("Second");
  2041. var nthfn = function (n) {
  2042. return function (dayOfWeek) {
  2043. if (this._same) {
  2044. return this._ss(arguments[0]);
  2045. }
  2046. if (dayOfWeek || dayOfWeek === 0) {
  2047. return this.moveToNthOccurrence(dayOfWeek, n);
  2048. }
  2049. this._nth = n;
  2050. // if the operator is 'second' add the _orient, then deal with it later...
  2051. if (n === 2 && (dayOfWeek === undefined || dayOfWeek === null)) {
  2052. this._isSecond = true;
  2053. return this.addSeconds(this._orient);
  2054. }
  2055. return this;
  2056. };
  2057. };
  2058. for (var l = 0; l < nth.length; l++) {
  2059. $P[nth[l]] = (l === 0) ? nthfn(-1) : nthfn(l);
  2060. }
  2061. }());
  2062. (function () {
  2063. "use strict";
  2064. Date.Parsing = {
  2065. Exception: function (s) {
  2066. this.message = "Parse error at '" + s.substring(0, 10) + " ...'";
  2067. }
  2068. };
  2069. var $P = Date.Parsing;
  2070. var dayOffsets = {
  2071. standard: [0,31,59,90,120,151,181,212,243,273,304,334],
  2072. leap: [0,31,60,91,121,152,182,213,244,274,305,335]
  2073. };
  2074. $P.isLeapYear = function(year) {
  2075. return ((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0);
  2076. };
  2077. var utils = {
  2078. multiReplace : function (str, hash ) {
  2079. var key;
  2080. for (key in hash) {
  2081. if (Object.prototype.hasOwnProperty.call(hash, key)) {
  2082. var regex;
  2083. if (typeof hash[key] === "function") {
  2084. } else {
  2085. regex = (hash[key] instanceof RegExp) ? hash[key] : new RegExp(hash[key], "g");
  2086. }
  2087. str = str.replace(regex, key);
  2088. }
  2089. }
  2090. return str;
  2091. },
  2092. getDayOfYearFromWeek : function (obj) {
  2093. var d, jan4, offset;
  2094. obj.weekDay = (!obj.weekDay && obj.weekDay !== 0) ? 1 : obj.weekDay;
  2095. d = new Date(obj.year, 0, 4);
  2096. jan4 = d.getDay() === 0 ? 7 : d.getDay(); // JS is 0 indexed on Sunday.
  2097. offset = jan4+3;
  2098. obj.dayOfYear = ((obj.week * 7) + (obj.weekDay === 0 ? 7 : obj.weekDay))-offset;
  2099. return obj;
  2100. },
  2101. getDayOfYear : function (obj, dayOffset) {
  2102. if (!obj.dayOfYear) {
  2103. obj = utils.getDayOfYearFromWeek(obj);
  2104. }
  2105. for (var i=0;i <= dayOffset.length;i++) {
  2106. if (obj.dayOfYear < dayOffset[i] || i === dayOffset.length) {
  2107. obj.day = obj.day ? obj.day : (obj.dayOfYear - dayOffset[i-1]);
  2108. break;
  2109. } else {
  2110. obj.month = i;
  2111. }
  2112. }
  2113. return obj;
  2114. },
  2115. adjustForTimeZone : function (obj, date) {
  2116. var offset;
  2117. if (obj.zone.toUpperCase() === "Z" || (obj.zone_hours === 0 && obj.zone_minutes === 0)) {
  2118. // it's UTC/GML so work out the current timeszone offset
  2119. offset = -date.getTimezoneOffset();
  2120. } else {
  2121. offset = (obj.zone_hours*60) + (obj.zone_minutes || 0);
  2122. if (obj.zone_sign === "+") {
  2123. offset *= -1;
  2124. }
  2125. offset -= date.getTimezoneOffset();
  2126. }
  2127. date.setMinutes(date.getMinutes()+offset);
  2128. return date;
  2129. },
  2130. setDefaults : function (obj) {
  2131. obj.year = obj.year || Date.today().getFullYear();
  2132. obj.hours = obj.hours || 0;
  2133. obj.minutes = obj.minutes || 0;
  2134. obj.seconds = obj.seconds || 0;
  2135. obj.milliseconds = obj.milliseconds || 0;
  2136. if (!(!obj.month && (obj.week || obj.dayOfYear))) {
  2137. // if we have a month, or if we don't but don't have the day calculation data
  2138. obj.month = obj.month || 0;
  2139. obj.day = obj.day || 1;
  2140. }
  2141. return obj;
  2142. },
  2143. dataNum: function (data, mod, explict, postProcess) {
  2144. var dataNum = data*1;
  2145. if (mod) {
  2146. if (postProcess) {
  2147. return data ? mod(data)*1 : data;
  2148. } else {
  2149. return data ? mod(dataNum) : data;
  2150. }
  2151. } else if (!explict){
  2152. return data ? dataNum : data;
  2153. } else {
  2154. return (data && typeof data !== "undefined") ? dataNum : data;
  2155. }
  2156. },
  2157. timeDataProcess: function (obj) {
  2158. var timeObj = {};
  2159. for (var x in obj.data) {
  2160. if (obj.data.hasOwnProperty(x)) {
  2161. timeObj[x] = obj.ignore[x] ? obj.data[x] : utils.dataNum(obj.data[x], obj.mods[x], obj.explict[x], obj.postProcess[x]);
  2162. }
  2163. }
  2164. if (obj.data.secmins) {
  2165. obj.data.secmins = obj.data.secmins.replace(",", ".") * 60;
  2166. if (!timeObj.minutes) {
  2167. timeObj.minutes = obj.data.secmins;
  2168. } else if (!timeObj.seconds) {
  2169. timeObj.seconds = obj.data.secmins;
  2170. }
  2171. delete obj.secmins;
  2172. }
  2173. return timeObj;
  2174. },
  2175. buildTimeObjectFromData: function (data) {
  2176. var time = utils.timeDataProcess({
  2177. data: {
  2178. year : data[1],
  2179. month : data[5],
  2180. day : data[7],
  2181. week : data[8],
  2182. dayOfYear : data[10],
  2183. hours : data[15],
  2184. zone_hours : data[23],
  2185. zone_minutes : data[24],
  2186. zone : data[21],
  2187. zone_sign : data[22],
  2188. weekDay : data[9],
  2189. minutes: data[16],
  2190. seconds: data[19],
  2191. milliseconds: data[20],
  2192. secmins: data[18]
  2193. },
  2194. mods: {
  2195. month: function(data) {
  2196. return data-1;
  2197. },
  2198. weekDay: function (data) {
  2199. data = Math.abs(data);
  2200. return (data === 7 ? 0 : data);
  2201. },
  2202. minutes: function (data) {
  2203. return data.replace(":","");
  2204. },
  2205. seconds: function (data) {
  2206. return Math.floor( (data.replace(":","").replace(",","."))*1 );
  2207. },
  2208. milliseconds: function (data) {
  2209. return (data.replace(",",".")*1000);
  2210. }
  2211. },
  2212. postProcess: {
  2213. minutes: true,
  2214. seconds: true,
  2215. milliseconds: true
  2216. },
  2217. explict: {
  2218. zone_hours: true,
  2219. zone_minutes: true
  2220. },
  2221. ignore: {
  2222. zone: true,
  2223. zone_sign: true,
  2224. secmins: true
  2225. }
  2226. });
  2227. return time;
  2228. },
  2229. addToHash: function (hash, keys, data) {
  2230. keys = keys;
  2231. data = data;
  2232. var len = keys.length;
  2233. for (var i = 0; i < len; i++) {
  2234. hash[keys[i]] = data[i];
  2235. }
  2236. return hash;
  2237. },
  2238. combineRegex: function (r1, r2) {
  2239. return new RegExp("(("+r1.source+")\\s("+r2.source+"))");
  2240. },
  2241. getDateNthString: function(add, last, inc){
  2242. if (add) {
  2243. return Date.today().addDays(inc).toString("d");
  2244. } else if (last) {
  2245. return Date.today().last()[inc]().toString("d");
  2246. }
  2247. },
  2248. buildRegexData: function (array) {
  2249. var arr = [];
  2250. var len = array.length;
  2251. for (var i=0; i < len; i++) {
  2252. if (Object.prototype.toString.call(array[i]) === '[object Array]') { // oldIE compat version of Array.isArray
  2253. arr.push(this.combineRegex(array[i][0], array[i][1]));
  2254. } else {
  2255. arr.push(array[i]);
  2256. }
  2257. }
  2258. return arr;
  2259. }
  2260. };
  2261. $P.processTimeObject = function (obj) {
  2262. var date, dayOffset;
  2263. utils.setDefaults(obj);
  2264. dayOffset = ($P.isLeapYear(obj.year)) ? dayOffsets.leap : dayOffsets.standard;
  2265. if (!obj.month && (obj.week || obj.dayOfYear)) {
  2266. utils.getDayOfYear(obj, dayOffset);
  2267. } else {
  2268. obj.dayOfYear = dayOffset[obj.month] + obj.day;
  2269. }
  2270. date = new Date(obj.year, obj.month, obj.day, obj.hours, obj.minutes, obj.seconds, obj.milliseconds);
  2271. if (obj.zone) {
  2272. utils.adjustForTimeZone(obj, date); // adjust (and calculate) for timezone
  2273. }
  2274. return date;
  2275. };
  2276. $P.ISO = {
  2277. regex : /^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-3])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-4])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?\s?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/,
  2278. parse : function (s) {
  2279. var time, data = s.match(this.regex);
  2280. if (!data || !data.length) {
  2281. return null;
  2282. }
  2283. time = utils.buildTimeObjectFromData(data);
  2284. if (!time.year || (!time.year && (!time.month && !time.day) && (!time.week && !time.dayOfYear)) ) {
  2285. return null;
  2286. }
  2287. return $P.processTimeObject(time);
  2288. }
  2289. };
  2290. $P.Numeric = {
  2291. isNumeric: function (e){return!isNaN(parseFloat(e))&&isFinite(e);},
  2292. regex: /\b([0-1]?[0-9])([0-3]?[0-9])([0-2]?[0-9]?[0-9][0-9])\b/i,
  2293. parse: function (s) {
  2294. var data, i,
  2295. time = {},
  2296. order = Date.CultureInfo.dateElementOrder.split("");
  2297. if (!(this.isNumeric(s)) || // if it's non-numeric OR
  2298. (s[0] === "+" && s[0] === "-")) { // It's an arithmatic string (eg +/-1000)
  2299. return null;
  2300. }
  2301. if (s.length < 5 && s.indexOf(".") < 0 && s.indexOf("/") < 0) { // assume it's just a year.
  2302. time.year = s;
  2303. return $P.processTimeObject(time);
  2304. }
  2305. data = s.match(this.regex);
  2306. if (!data || !data.length) {
  2307. return null;
  2308. }
  2309. for (i=0; i < order.length; i++) {
  2310. switch(order[i]) {
  2311. case "d":
  2312. time.day = data[i+1];
  2313. break;
  2314. case "m":
  2315. time.month = (data[i+1]-1);
  2316. break;
  2317. case "y":
  2318. time.year = data[i+1];
  2319. break;
  2320. }
  2321. }
  2322. return $P.processTimeObject(time);
  2323. }
  2324. };
  2325. $P.Normalizer = {
  2326. regexData: function () {
  2327. var $R = Date.CultureInfo.regexPatterns;
  2328. return utils.buildRegexData([
  2329. $R.tomorrow,
  2330. $R.yesterday,
  2331. [$R.past, $R.mon],
  2332. [$R.past, $R.tue],
  2333. [$R.past, $R.wed],
  2334. [$R.past, $R.thu],
  2335. [$R.past, $R.fri],
  2336. [$R.past, $R.sat],
  2337. [$R.past, $R.sun]
  2338. ]);
  2339. },
  2340. basicReplaceHash : function() {
  2341. var $R = Date.CultureInfo.regexPatterns;
  2342. return {
  2343. "January": $R.jan.source,
  2344. "February": $R.feb,
  2345. "March": $R.mar,
  2346. "April": $R.apr,
  2347. "May": $R.may,
  2348. "June": $R.jun,
  2349. "July": $R.jul,
  2350. "August": $R.aug,
  2351. "September": $R.sep,
  2352. "October": $R.oct,
  2353. "November": $R.nov,
  2354. "December": $R.dec,
  2355. "": /\bat\b/gi,
  2356. " ": /\s{2,}/,
  2357. "am": $R.inTheMorning,
  2358. "9am": $R.thisMorning,
  2359. "pm": $R.inTheEvening,
  2360. "7pm":$R.thisEvening
  2361. };
  2362. },
  2363. keys : function(){
  2364. return [
  2365. utils.getDateNthString(true, false, 1), // tomorrow
  2366. utils.getDateNthString(true, false, -1), // yesterday
  2367. utils.getDateNthString(false, true, "monday"), //last mon
  2368. utils.getDateNthString(false, true, "tuesday"), //last tues
  2369. utils.getDateNthString(false, true, "wednesday"), //last wed
  2370. utils.getDateNthString(false, true, "thursday"), //last thurs
  2371. utils.getDateNthString(false, true, "friday"), //last fri
  2372. utils.getDateNthString(false, true, "saturday"), //last sat
  2373. utils.getDateNthString(false, true, "sunday") //last sun
  2374. ];
  2375. },
  2376. buildRegexFunctions: function () {
  2377. var $R = Date.CultureInfo.regexPatterns;
  2378. var __ = Date.i18n.__;
  2379. var tomorrowRE = new RegExp("(\\b\\d\\d?("+__("AM")+"|"+__("PM")+")? )("+$R.tomorrow.source.slice(1)+")", "i"); // adapted tomorrow regex for AM PM relative dates
  2380. var todayRE = new RegExp($R.today.source + "(?!\\s*([+-]))\\b"); // today, but excludes the math operators (eg "today + 2h")
  2381. this.replaceFuncs = [
  2382. [todayRE, function (full) {
  2383. return (full.length > 1) ? Date.today().toString("d") : full;
  2384. }],
  2385. [tomorrowRE,
  2386. function(full, m1) {
  2387. var t = Date.today().addDays(1).toString("d");
  2388. return (t + " " + m1);
  2389. }],
  2390. [$R.amThisMorning, function(str, am){return am;}],
  2391. [$R.pmThisEvening, function(str, pm){return pm;}]
  2392. ];
  2393. },
  2394. buildReplaceData: function () {
  2395. this.buildRegexFunctions();
  2396. this.replaceHash = utils.addToHash(this.basicReplaceHash(), this.keys(), this.regexData());
  2397. },
  2398. stringReplaceFuncs: function (s) {
  2399. for (var i=0; i < this.replaceFuncs.length; i++) {
  2400. s = s.replace(this.replaceFuncs[i][0], this.replaceFuncs[i][1]);
  2401. }
  2402. return s;
  2403. },
  2404. parse: function (s) {
  2405. s = this.stringReplaceFuncs(s);
  2406. s = utils.multiReplace(s, this.replaceHash);
  2407. try {
  2408. var n = s.split(/([\s\-\.\,\/\x27]+)/);
  2409. if (n.length === 3 &&
  2410. $P.Numeric.isNumeric(n[0]) &&
  2411. $P.Numeric.isNumeric(n[2]) &&
  2412. (n[2].length >= 4)) {
  2413. // ok, so we're dealing with x/year. But that's not a full date.
  2414. // This fixes wonky dateElementOrder parsing when set to dmy order.
  2415. if (Date.CultureInfo.dateElementOrder[0] === "d") {
  2416. s = "1/" + n[0] + "/" + n[2]; // set to 1st of month and normalize the seperator
  2417. }
  2418. }
  2419. } catch (e) {}
  2420. return s;
  2421. }
  2422. };
  2423. $P.Normalizer.buildReplaceData();
  2424. }());
  2425. (function () {
  2426. var $P = Date.Parsing;
  2427. var _ = $P.Operators = {
  2428. //
  2429. // Tokenizers
  2430. //
  2431. rtoken: function (r) { // regex token
  2432. return function (s) {
  2433. var mx = s.match(r);
  2434. if (mx) {
  2435. return ([ mx[0], s.substring(mx[0].length) ]);
  2436. } else {
  2437. throw new $P.Exception(s);
  2438. }
  2439. };
  2440. },
  2441. token: function () { // whitespace-eating token
  2442. return function (s) {
  2443. return _.rtoken(new RegExp("^\\s*" + s + "\\s*"))(s);
  2444. };
  2445. },
  2446. stoken: function (s) { // string token
  2447. return _.rtoken(new RegExp("^" + s));
  2448. },
  2449. // Atomic Operators
  2450. until: function (p) {
  2451. return function (s) {
  2452. var qx = [], rx = null;
  2453. while (s.length) {
  2454. try {
  2455. rx = p.call(this, s);
  2456. } catch (e) {
  2457. qx.push(rx[0]);
  2458. s = rx[1];
  2459. continue;
  2460. }
  2461. break;
  2462. }
  2463. return [ qx, s ];
  2464. };
  2465. },
  2466. many: function (p) {
  2467. return function (s) {
  2468. var rx = [], r = null;
  2469. while (s.length) {
  2470. try {
  2471. r = p.call(this, s);
  2472. } catch (e) {
  2473. return [ rx, s ];
  2474. }
  2475. rx.push(r[0]);
  2476. s = r[1];
  2477. }
  2478. return [ rx, s ];
  2479. };
  2480. },
  2481. // generator operators -- see below
  2482. optional: function (p) {
  2483. return function (s) {
  2484. var r = null;
  2485. try {
  2486. r = p.call(this, s);
  2487. } catch (e) {
  2488. return [ null, s ];
  2489. }
  2490. return [ r[0], r[1] ];
  2491. };
  2492. },
  2493. not: function (p) {
  2494. return function (s) {
  2495. try {
  2496. p.call(this, s);
  2497. } catch (e) {
  2498. return [null, s];
  2499. }
  2500. throw new $P.Exception(s);
  2501. };
  2502. },
  2503. ignore: function (p) {
  2504. return p ?
  2505. function (s) {
  2506. var r = null;
  2507. r = p.call(this, s);
  2508. return [null, r[1]];
  2509. } : null;
  2510. },
  2511. product: function () {
  2512. var px = arguments[0],
  2513. qx = Array.prototype.slice.call(arguments, 1), rx = [];
  2514. for (var i = 0 ; i < px.length ; i++) {
  2515. rx.push(_.each(px[i], qx));
  2516. }
  2517. return rx;
  2518. },
  2519. cache: function (rule) {
  2520. var cache = {}, cache_length = 0, cache_keys = [], CACHE_MAX = Date.Config.CACHE_MAX || 100000, r = null;
  2521. var cacheCheck = function () {
  2522. if (cache_length === CACHE_MAX) {
  2523. // kill several keys, don't want to have to do this all the time...
  2524. for (var i=0; i < 10; i++) {
  2525. var key = cache_keys.shift();
  2526. if (key) {
  2527. delete cache[key];
  2528. cache_length--;
  2529. }
  2530. }
  2531. }
  2532. };
  2533. return function (s) {
  2534. cacheCheck();
  2535. try {
  2536. r = cache[s] = (cache[s] || rule.call(this, s));
  2537. } catch (e) {
  2538. r = cache[s] = e;
  2539. }
  2540. cache_length++;
  2541. cache_keys.push(s);
  2542. if (r instanceof $P.Exception) {
  2543. throw r;
  2544. } else {
  2545. return r;
  2546. }
  2547. };
  2548. },
  2549. // vector operators -- see below
  2550. any: function () {
  2551. var px = arguments;
  2552. return function (s) {
  2553. var r = null;
  2554. for (var i = 0; i < px.length; i++) {
  2555. if (px[i] == null) {
  2556. continue;
  2557. }
  2558. try {
  2559. r = (px[i].call(this, s));
  2560. } catch (e) {
  2561. r = null;
  2562. }
  2563. if (r) {
  2564. return r;
  2565. }
  2566. }
  2567. throw new $P.Exception(s);
  2568. };
  2569. },
  2570. each: function () {
  2571. var px = arguments;
  2572. return function (s) {
  2573. var rx = [], r = null;
  2574. for (var i = 0; i < px.length ; i++) {
  2575. if (px[i] == null) {
  2576. continue;
  2577. }
  2578. try {
  2579. r = (px[i].call(this, s));
  2580. } catch (e) {
  2581. throw new $P.Exception(s);
  2582. }
  2583. rx.push(r[0]);
  2584. s = r[1];
  2585. }
  2586. return [ rx, s];
  2587. };
  2588. },
  2589. all: function () {
  2590. var px = arguments, _ = _;
  2591. return _.each(_.optional(px));
  2592. },
  2593. // delimited operators
  2594. sequence: function (px, d, c) {
  2595. d = d || _.rtoken(/^\s*/);
  2596. c = c || null;
  2597. if (px.length === 1) {
  2598. return px[0];
  2599. }
  2600. return function (s) {
  2601. var r = null, q = null;
  2602. var rx = [];
  2603. for (var i = 0; i < px.length ; i++) {
  2604. try {
  2605. r = px[i].call(this, s);
  2606. } catch (e) {
  2607. break;
  2608. }
  2609. rx.push(r[0]);
  2610. try {
  2611. q = d.call(this, r[1]);
  2612. } catch (ex) {
  2613. q = null;
  2614. break;
  2615. }
  2616. s = q[1];
  2617. }
  2618. if (!r) {
  2619. throw new $P.Exception(s);
  2620. }
  2621. if (q) {
  2622. throw new $P.Exception(q[1]);
  2623. }
  2624. if (c) {
  2625. try {
  2626. r = c.call(this, r[1]);
  2627. } catch (ey) {
  2628. throw new $P.Exception(r[1]);
  2629. }
  2630. }
  2631. return [ rx, (r?r[1]:s) ];
  2632. };
  2633. },
  2634. //
  2635. // Composite Operators
  2636. //
  2637. between: function (d1, p, d2) {
  2638. d2 = d2 || d1;
  2639. var _fn = _.each(_.ignore(d1), p, _.ignore(d2));
  2640. return function (s) {
  2641. var rx = _fn.call(this, s);
  2642. return [[rx[0][0], r[0][2]], rx[1]];
  2643. };
  2644. },
  2645. list: function (p, d, c) {
  2646. d = d || _.rtoken(/^\s*/);
  2647. c = c || null;
  2648. return (p instanceof Array ?
  2649. _.each(_.product(p.slice(0, -1), _.ignore(d)), p.slice(-1), _.ignore(c)) :
  2650. _.each(_.many(_.each(p, _.ignore(d))), px, _.ignore(c)));
  2651. },
  2652. set: function (px, d, c) {
  2653. d = d || _.rtoken(/^\s*/);
  2654. c = c || null;
  2655. return function (s) {
  2656. // r is the current match, best the current 'best' match
  2657. // which means it parsed the most amount of input
  2658. var r = null, p = null, q = null, rx = null, best = [[], s], last = false;
  2659. // go through the rules in the given set
  2660. for (var i = 0; i < px.length ; i++) {
  2661. // last is a flag indicating whether this must be the last element
  2662. // if there is only 1 element, then it MUST be the last one
  2663. q = null;
  2664. p = null;
  2665. r = null;
  2666. last = (px.length === 1);
  2667. // first, we try simply to match the current pattern
  2668. // if not, try the next pattern
  2669. try {
  2670. r = px[i].call(this, s);
  2671. } catch (e) {
  2672. continue;
  2673. }
  2674. // since we are matching against a set of elements, the first
  2675. // thing to do is to add r[0] to matched elements
  2676. rx = [[r[0]], r[1]];
  2677. // if we matched and there is still input to parse and
  2678. // we don't already know this is the last element,
  2679. // we're going to next check for the delimiter ...
  2680. // if there's none, or if there's no input left to parse
  2681. // than this must be the last element after all ...
  2682. if (r[1].length > 0 && ! last) {
  2683. try {
  2684. q = d.call(this, r[1]);
  2685. } catch (ex) {
  2686. last = true;
  2687. }
  2688. } else {
  2689. last = true;
  2690. }
  2691. // if we parsed the delimiter and now there's no more input,
  2692. // that means we shouldn't have parsed the delimiter at all
  2693. // so don't update r and mark this as the last element ...
  2694. if (!last && q[1].length === 0) {
  2695. last = true;
  2696. }
  2697. // so, if this isn't the last element, we're going to see if
  2698. // we can get any more matches from the remaining (unmatched)
  2699. // elements ...
  2700. if (!last) {
  2701. // build a list of the remaining rules we can match against,
  2702. // i.e., all but the one we just matched against
  2703. var qx = [];
  2704. for (var j = 0; j < px.length ; j++) {
  2705. if (i !== j) {
  2706. qx.push(px[j]);
  2707. }
  2708. }
  2709. // now invoke recursively set with the remaining input
  2710. // note that we don't include the closing delimiter ...
  2711. // we'll check for that ourselves at the end
  2712. p = _.set(qx, d).call(this, q[1]);
  2713. // if we got a non-empty set as a result ...
  2714. // (otw rx already contains everything we want to match)
  2715. if (p[0].length > 0) {
  2716. // update current result, which is stored in rx ...
  2717. // basically, pick up the remaining text from p[1]
  2718. // and concat the result from p[0] so that we don't
  2719. // get endless nesting ...
  2720. rx[0] = rx[0].concat(p[0]);
  2721. rx[1] = p[1];
  2722. }
  2723. }
  2724. // at this point, rx either contains the last matched element
  2725. // or the entire matched set that starts with this element.
  2726. // now we just check to see if this variation is better than
  2727. // our best so far, in terms of how much of the input is parsed
  2728. if (rx[1].length < best[1].length) {
  2729. best = rx;
  2730. }
  2731. // if we've parsed all the input, then we're finished
  2732. if (best[1].length === 0) {
  2733. break;
  2734. }
  2735. }
  2736. // so now we've either gone through all the patterns trying them
  2737. // as the initial match; or we found one that parsed the entire
  2738. // input string ...
  2739. // if best has no matches, just return empty set ...
  2740. if (best[0].length === 0) {
  2741. return best;
  2742. }
  2743. // if a closing delimiter is provided, then we have to check it also
  2744. if (c) {
  2745. // we try this even if there is no remaining input because the pattern
  2746. // may well be optional or match empty input ...
  2747. try {
  2748. q = c.call(this, best[1]);
  2749. } catch (ey) {
  2750. throw new $P.Exception(best[1]);
  2751. }
  2752. // it parsed ... be sure to update the best match remaining input
  2753. best[1] = q[1];
  2754. }
  2755. // if we're here, either there was no closing delimiter or we parsed it
  2756. // so now we have the best match; just return it!
  2757. return best;
  2758. };
  2759. },
  2760. forward: function (gr, fname) {
  2761. return function (s) {
  2762. return gr[fname].call(this, s);
  2763. };
  2764. },
  2765. //
  2766. // Translation Operators
  2767. //
  2768. replace: function (rule, repl) {
  2769. return function (s) {
  2770. var r = rule.call(this, s);
  2771. return [repl, r[1]];
  2772. };
  2773. },
  2774. process: function (rule, fn) {
  2775. return function (s) {
  2776. var r = rule.call(this, s);
  2777. return [fn.call(this, r[0]), r[1]];
  2778. };
  2779. },
  2780. min: function (min, rule) {
  2781. return function (s) {
  2782. var rx = rule.call(this, s);
  2783. if (rx[0].length < min) {
  2784. throw new $P.Exception(s);
  2785. }
  2786. return rx;
  2787. };
  2788. }
  2789. };
  2790. // Generator Operators And Vector Operators
  2791. // Generators are operators that have a signature of F(R) => R,
  2792. // taking a given rule and returning another rule, such as
  2793. // ignore, which parses a given rule and throws away the result.
  2794. // Vector operators are those that have a signature of F(R1,R2,...) => R,
  2795. // take a list of rules and returning a new rule, such as each.
  2796. // Generator operators are converted (via the following _generator
  2797. // function) into functions that can also take a list or array of rules
  2798. // and return an array of new rules as though the function had been
  2799. // called on each rule in turn (which is what actually happens).
  2800. // This allows generators to be used with vector operators more easily.
  2801. // Example:
  2802. // each(ignore(foo, bar)) instead of each(ignore(foo), ignore(bar))
  2803. // This also turns generators into vector operators, which allows
  2804. // constructs like:
  2805. // not(cache(foo, bar))
  2806. var _generator = function (op) {
  2807. function gen() {
  2808. var args = null, rx = [], px, i;
  2809. if (arguments.length > 1) {
  2810. args = Array.prototype.slice.call(arguments);
  2811. } else if (arguments[0] instanceof Array) {
  2812. args = arguments[0];
  2813. }
  2814. if (args) {
  2815. px = args.shift();
  2816. if (px.length > 0) {
  2817. args.unshift(px[i]);
  2818. rx.push(op.apply(null, args));
  2819. args.shift();
  2820. return rx;
  2821. }
  2822. } else {
  2823. return op.apply(null, arguments);
  2824. }
  2825. }
  2826. return gen;
  2827. };
  2828. var gx = "optional not ignore cache".split(/\s/);
  2829. for (var i = 0 ; i < gx.length ; i++) {
  2830. _[gx[i]] = _generator(_[gx[i]]);
  2831. }
  2832. var _vector = function (op) {
  2833. return function () {
  2834. if (arguments[0] instanceof Array) {
  2835. return op.apply(null, arguments[0]);
  2836. } else {
  2837. return op.apply(null, arguments);
  2838. }
  2839. };
  2840. };
  2841. var vx = "each any all".split(/\s/);
  2842. for (var j = 0 ; j < vx.length ; j++) {
  2843. _[vx[j]] = _vector(_[vx[j]]);
  2844. }
  2845. }());
  2846. (function () {
  2847. var $D = Date;
  2848. var flattenAndCompact = function (ax) {
  2849. var rx = [];
  2850. for (var i = 0; i < ax.length; i++) {
  2851. if (ax[i] instanceof Array) {
  2852. rx = rx.concat(flattenAndCompact(ax[i]));
  2853. } else {
  2854. if (ax[i]) {
  2855. rx.push(ax[i]);
  2856. }
  2857. }
  2858. }
  2859. return rx;
  2860. };
  2861. var parseMeridian = function () {
  2862. if (this.meridian && (this.hour || this.hour === 0)) {
  2863. if (this.meridian === "a" && this.hour > 11 && Date.Config.strict24hr){
  2864. throw "Invalid hour and meridian combination";
  2865. } else if (this.meridian === "p" && this.hour < 12 && Date.Config.strict24hr){
  2866. throw "Invalid hour and meridian combination";
  2867. } else if (this.meridian === "p" && this.hour < 12) {
  2868. this.hour = this.hour + 12;
  2869. } else if (this.meridian === "a" && this.hour === 12) {
  2870. this.hour = 0;
  2871. }
  2872. }
  2873. };
  2874. var setDefaults = function () {
  2875. var now = new Date();
  2876. if ((this.hour || this.minute) && (!this.month && !this.year && !this.day)) {
  2877. this.day = now.getDate();
  2878. }
  2879. if (!this.year) {
  2880. this.year = now.getFullYear();
  2881. }
  2882. if (!this.month && this.month !== 0) {
  2883. this.month = now.getMonth();
  2884. }
  2885. if (!this.day) {
  2886. this.day = 1;
  2887. }
  2888. if (!this.hour) {
  2889. this.hour = 0;
  2890. }
  2891. if (!this.minute) {
  2892. this.minute = 0;
  2893. }
  2894. if (!this.second) {
  2895. this.second = 0;
  2896. }
  2897. if (!this.millisecond) {
  2898. this.millisecond = 0;
  2899. }
  2900. };
  2901. var finishUtils = {
  2902. getToday: function () {
  2903. if (this.now || "hour minute second".indexOf(this.unit) !== -1) {
  2904. return new Date();
  2905. } else {
  2906. return $D.today();
  2907. }
  2908. },
  2909. setDaysFromWeekday: function (today, orient){
  2910. var gap;
  2911. orient = orient || 1;
  2912. this.unit = "day";
  2913. gap = ($D.getDayNumberFromName(this.weekday) - today.getDay());
  2914. this.days = gap ? ((gap + (orient * 7)) % 7) : (orient * 7);
  2915. return this;
  2916. },
  2917. setMonthsFromMonth: function (today, orient) {
  2918. var gap;
  2919. orient = orient || 1;
  2920. this.unit = "month";
  2921. gap = (this.month - today.getMonth());
  2922. this.months = gap ? ((gap + (orient * 12)) % 12) : (orient * 12);
  2923. this.month = null;
  2924. return this;
  2925. },
  2926. setDMYFromWeekday: function () {
  2927. var d = Date[this.weekday]();
  2928. this.day = d.getDate();
  2929. if (!this.month) {
  2930. this.month = d.getMonth();
  2931. }
  2932. this.year = d.getFullYear();
  2933. return this;
  2934. },
  2935. setUnitValue: function (orient) {
  2936. if (!this.value && this.operator && this.operator !== null && this[this.unit + "s"] && this[this.unit + "s"] !== null) {
  2937. this[this.unit + "s"] = this[this.unit + "s"] + ((this.operator === "add") ? 1 : -1) + (this.value||0) * orient;
  2938. } else if (this[this.unit + "s"] == null || this.operator != null) {
  2939. if (!this.value) {
  2940. this.value = 1;
  2941. }
  2942. this[this.unit + "s"] = this.value * orient;
  2943. }
  2944. },
  2945. generateDateFromWeeks: function () {
  2946. var weekday = (this.weekday !== undefined) ? this.weekday : "today";
  2947. var d = Date[weekday]().addWeeks(this.weeks);
  2948. if (this.now) {
  2949. d.setTimeToNow();
  2950. }
  2951. return d;
  2952. }
  2953. };
  2954. $D.Translator = {
  2955. hour: function (s) {
  2956. return function () {
  2957. this.hour = Number(s);
  2958. };
  2959. },
  2960. minute: function (s) {
  2961. return function () {
  2962. this.minute = Number(s);
  2963. };
  2964. },
  2965. second: function (s) {
  2966. return function () {
  2967. this.second = Number(s);
  2968. };
  2969. },
  2970. /* for ss.s format */
  2971. secondAndMillisecond: function (s) {
  2972. return function () {
  2973. var mx = s.match(/^([0-5][0-9])\.([0-9]{1,3})/);
  2974. this.second = Number(mx[1]);
  2975. this.millisecond = Number(mx[2]);
  2976. };
  2977. },
  2978. meridian: function (s) {
  2979. return function () {
  2980. this.meridian = s.slice(0, 1).toLowerCase();
  2981. };
  2982. },
  2983. timezone: function (s) {
  2984. return function () {
  2985. var n = s.replace(/[^\d\+\-]/g, "");
  2986. if (n.length) {
  2987. this.timezoneOffset = Number(n);
  2988. } else {
  2989. this.timezone = s.toLowerCase();
  2990. }
  2991. };
  2992. },
  2993. day: function (x) {
  2994. var s = x[0];
  2995. return function () {
  2996. this.day = Number(s.match(/\d+/)[0]);
  2997. if (this.day < 1) {
  2998. throw "invalid day";
  2999. }
  3000. };
  3001. },
  3002. month: function (s) {
  3003. return function () {
  3004. this.month = (s.length === 3) ? "jan feb mar apr may jun jul aug sep oct nov dec".indexOf(s)/4 : Number(s) - 1;
  3005. if (this.month < 0) {
  3006. throw "invalid month";
  3007. }
  3008. };
  3009. },
  3010. year: function (s) {
  3011. return function () {
  3012. var n = Number(s);
  3013. this.year = ((s.length > 2) ? n :
  3014. (n + (((n + 2000) < Date.CultureInfo.twoDigitYearMax) ? 2000 : 1900)));
  3015. };
  3016. },
  3017. rday: function (s) {
  3018. return function () {
  3019. switch (s) {
  3020. case "yesterday":
  3021. this.days = -1;
  3022. break;
  3023. case "tomorrow":
  3024. this.days = 1;
  3025. break;
  3026. case "today":
  3027. this.days = 0;
  3028. break;
  3029. case "now":
  3030. this.days = 0;
  3031. this.now = true;
  3032. break;
  3033. }
  3034. };
  3035. },
  3036. finishExact: function (x) {
  3037. var d;
  3038. x = (x instanceof Array) ? x : [x];
  3039. for (var i = 0 ; i < x.length ; i++) {
  3040. if (x[i]) {
  3041. x[i].call(this);
  3042. }
  3043. }
  3044. setDefaults.call(this);
  3045. parseMeridian.call(this);
  3046. if (this.day > $D.getDaysInMonth(this.year, this.month)) {
  3047. throw new RangeError(this.day + " is not a valid value for days.");
  3048. }
  3049. d = new Date(this.year, this.month, this.day, this.hour, this.minute, this.second, this.millisecond);
  3050. if (this.year < 100) {
  3051. d.setFullYear(this.year); // means years less that 100 are process correctly. JS will parse it otherwise as 1900-1999.
  3052. }
  3053. if (this.timezone) {
  3054. d.set({ timezone: this.timezone });
  3055. } else if (this.timezoneOffset) {
  3056. d.set({ timezoneOffset: this.timezoneOffset });
  3057. }
  3058. return d;
  3059. },
  3060. finish: function (x) {
  3061. var today, expression, orient, temp;
  3062. x = (x instanceof Array) ? flattenAndCompact(x) : [ x ];
  3063. if (x.length === 0) {
  3064. return null;
  3065. }
  3066. for (var i = 0 ; i < x.length ; i++) {
  3067. if (typeof x[i] === "function") {
  3068. x[i].call(this);
  3069. }
  3070. }
  3071. if (this.now && !this.unit && !this.operator) {
  3072. return new Date();
  3073. } else {
  3074. today = finishUtils.getToday.call(this);
  3075. }
  3076. expression = !!(this.days && this.days !== null || this.orient || this.operator);
  3077. orient = ((this.orient === "past" || this.operator === "subtract") ? -1 : 1);
  3078. if (this.month && this.unit === "week") {
  3079. this.value = this.month + 1;
  3080. delete this.month;
  3081. delete this.day;
  3082. }
  3083. if ((this.month || this.month === 0) && "year day hour minute second".indexOf(this.unit) !== -1) {
  3084. if (!this.value) {
  3085. this.value = this.month + 1;
  3086. }
  3087. this.month = null;
  3088. expression = true;
  3089. }
  3090. if (!expression && this.weekday && !this.day && !this.days) {
  3091. finishUtils.setDMYFromWeekday.call(this);
  3092. }
  3093. if (expression && this.weekday && this.unit !== "month" && this.unit !== "week") {
  3094. finishUtils.setDaysFromWeekday.call(this, today, orient);
  3095. }
  3096. if (this.weekday && this.unit !== "week" && !this.day && !this.days) {
  3097. temp = Date[this.weekday]();
  3098. this.day = temp.getDate();
  3099. if (temp.getMonth() !== today.getMonth()) {
  3100. this.month = temp.getMonth();
  3101. }
  3102. }
  3103. if (this.month && this.unit === "day" && this.operator) {
  3104. if (!this.value) {
  3105. this.value = (this.month + 1);
  3106. }
  3107. this.month = null;
  3108. }
  3109. if (this.value != null && this.month != null && this.year != null) {
  3110. this.day = this.value * 1;
  3111. }
  3112. if (this.month && !this.day && this.value) {
  3113. today.set({ day: this.value * 1 });
  3114. if (!expression) {
  3115. this.day = this.value * 1;
  3116. }
  3117. }
  3118. if (!this.month && this.value && this.unit === "month" && !this.now) {
  3119. this.month = this.value;
  3120. expression = true;
  3121. }
  3122. if (expression && (this.month || this.month === 0) && this.unit !== "year") {
  3123. finishUtils.setMonthsFromMonth.call(this, today, orient);
  3124. }
  3125. if (!this.unit) {
  3126. this.unit = "day";
  3127. }
  3128. finishUtils.setUnitValue.call(this, orient);
  3129. parseMeridian.call(this);
  3130. if ((this.month || this.month === 0) && !this.day) {
  3131. this.day = 1;
  3132. }
  3133. if (!this.orient && !this.operator && this.unit === "week" && this.value && !this.day && !this.month) {
  3134. return Date.today().setWeek(this.value);
  3135. }
  3136. if (this.unit === "week" && this.weeks && !this.day && !this.month) {
  3137. return finishUtils.generateDateFromWeeks.call(this);
  3138. }
  3139. if (expression && this.timezone && this.day && this.days) {
  3140. this.day = this.days;
  3141. }
  3142. if (expression){
  3143. today.add(this);
  3144. } else {
  3145. today.set(this);
  3146. }
  3147. if (this.timezone) {
  3148. this.timezone = this.timezone.toUpperCase();
  3149. var offset = $D.getTimezoneOffset(this.timezone);
  3150. var timezone;
  3151. if (today.hasDaylightSavingTime()) {
  3152. // lets check that we're being sane with timezone setting
  3153. timezone = $D.getTimezoneAbbreviation(offset, today.isDaylightSavingTime());
  3154. if (timezone !== this.timezone) {
  3155. // bugger, we're in a place where things like EST vs EDT matters.
  3156. if (today.isDaylightSavingTime()) {
  3157. today.addHours(-1);
  3158. } else {
  3159. today.addHours(1);
  3160. }
  3161. }
  3162. }
  3163. today.setTimezoneOffset(offset);
  3164. }
  3165. return today;
  3166. }
  3167. };
  3168. }());
  3169. (function () {
  3170. var $D = Date;
  3171. $D.Grammar = {};
  3172. var _ = $D.Parsing.Operators, g = $D.Grammar, t = $D.Translator, _fn;
  3173. // Allow rolling up into general purpose rules
  3174. _fn = function () {
  3175. return _.each(_.any.apply(null, arguments), _.not(g.ctoken2("timeContext")));
  3176. };
  3177. g.datePartDelimiter = _.rtoken(/^([\s\-\.\,\/\x27]+)/);
  3178. g.timePartDelimiter = _.stoken(":");
  3179. g.whiteSpace = _.rtoken(/^\s*/);
  3180. g.generalDelimiter = _.rtoken(/^(([\s\,]|at|@|on)+)/);
  3181. var _C = {};
  3182. g.ctoken = function (keys) {
  3183. var fn = _C[keys];
  3184. if (! fn) {
  3185. var c = Date.CultureInfo.regexPatterns;
  3186. var kx = keys.split(/\s+/), px = [];
  3187. for (var i = 0; i < kx.length ; i++) {
  3188. px.push(_.replace(_.rtoken(c[kx[i]]), kx[i]));
  3189. }
  3190. fn = _C[keys] = _.any.apply(null, px);
  3191. }
  3192. return fn;
  3193. };
  3194. g.ctoken2 = function (key) {
  3195. return _.rtoken(Date.CultureInfo.regexPatterns[key]);
  3196. };
  3197. var cacheProcessRtoken = function (key, token, type, eachToken) {
  3198. if (eachToken) {
  3199. g[key] = _.cache(_.process(_.each(_.rtoken(token),_.optional(g.ctoken2(eachToken))), type));
  3200. } else {
  3201. g[key] = _.cache(_.process(_.rtoken(token), type));
  3202. }
  3203. };
  3204. var cacheProcessCtoken = function (token, type) {
  3205. return _.cache(_.process(g.ctoken2(token), type));
  3206. };
  3207. var _F = {}; //function cache
  3208. var _get = function (f) {
  3209. _F[f] = (_F[f] || g.format(f)[0]);
  3210. return _F[f];
  3211. };
  3212. g.allformats = function (fx) {
  3213. var rx = [];
  3214. if (fx instanceof Array) {
  3215. for (var i = 0; i < fx.length; i++) {
  3216. rx.push(_get(fx[i]));
  3217. }
  3218. } else {
  3219. rx.push(_get(fx));
  3220. }
  3221. return rx;
  3222. };
  3223. g.formats = function (fx) {
  3224. if (fx instanceof Array) {
  3225. var rx = [];
  3226. for (var i = 0 ; i < fx.length ; i++) {
  3227. rx.push(_get(fx[i]));
  3228. }
  3229. return _.any.apply(null, rx);
  3230. } else {
  3231. return _get(fx);
  3232. }
  3233. };
  3234. var grammarFormats = {
  3235. timeFormats: function(){
  3236. var i,
  3237. RTokenKeys = [
  3238. "h",
  3239. "hh",
  3240. "H",
  3241. "HH",
  3242. "m",
  3243. "mm",
  3244. "s",
  3245. "ss",
  3246. "ss.s",
  3247. "z",
  3248. "zz"
  3249. ],
  3250. RToken = [
  3251. /^(0[0-9]|1[0-2]|[1-9])/,
  3252. /^(0[0-9]|1[0-2])/,
  3253. /^([0-1][0-9]|2[0-3]|[0-9])/,
  3254. /^([0-1][0-9]|2[0-3])/,
  3255. /^([0-5][0-9]|[0-9])/,
  3256. /^[0-5][0-9]/,
  3257. /^([0-5][0-9]|[0-9])/,
  3258. /^[0-5][0-9]/,
  3259. /^[0-5][0-9]\.[0-9]{1,3}/,
  3260. /^((\+|\-)\s*\d\d\d\d)|((\+|\-)\d\d\:?\d\d)/,
  3261. /^((\+|\-)\s*\d\d\d\d)|((\+|\-)\d\d\:?\d\d)/
  3262. ],
  3263. tokens = [
  3264. t.hour,
  3265. t.hour,
  3266. t.hour,
  3267. t.minute,
  3268. t.minute,
  3269. t.second,
  3270. t.second,
  3271. t.secondAndMillisecond,
  3272. t.timezone,
  3273. t.timezone,
  3274. t.timezone
  3275. ];
  3276. for (i=0; i < RTokenKeys.length; i++) {
  3277. cacheProcessRtoken(RTokenKeys[i], RToken[i], tokens[i]);
  3278. }
  3279. g.hms = _.cache(_.sequence([g.H, g.m, g.s], g.timePartDelimiter));
  3280. g.t = cacheProcessCtoken("shortMeridian", t.meridian);
  3281. g.tt = cacheProcessCtoken("longMeridian", t.meridian);
  3282. g.zzz = cacheProcessCtoken("timezone", t.timezone);
  3283. g.timeSuffix = _.each(_.ignore(g.whiteSpace), _.set([ g.tt, g.zzz ]));
  3284. g.time = _.each(_.optional(_.ignore(_.stoken("T"))), g.hms, g.timeSuffix);
  3285. },
  3286. dateFormats: function () {
  3287. // pre-loaded rules for different date part order preferences
  3288. var _setfn = function () {
  3289. return _.set(arguments, g.datePartDelimiter);
  3290. };
  3291. var i,
  3292. RTokenKeys = [
  3293. "d",
  3294. "dd",
  3295. "M",
  3296. "MM",
  3297. "y",
  3298. "yy",
  3299. "yyy",
  3300. "yyyy"
  3301. ],
  3302. RToken = [
  3303. /^([0-2]\d|3[0-1]|\d)/,
  3304. /^([0-2]\d|3[0-1])/,
  3305. /^(1[0-2]|0\d|\d)/,
  3306. /^(1[0-2]|0\d)/,
  3307. /^(\d+)/,
  3308. /^(\d\d)/,
  3309. /^(\d\d?\d?\d?)/,
  3310. /^(\d\d\d\d)/
  3311. ],
  3312. tokens = [
  3313. t.day,
  3314. t.day,
  3315. t.month,
  3316. t.month,
  3317. t.year,
  3318. t.year,
  3319. t.year,
  3320. t.year
  3321. ],
  3322. eachToken = [
  3323. "ordinalSuffix",
  3324. "ordinalSuffix"
  3325. ];
  3326. for (i=0; i < RTokenKeys.length; i++) {
  3327. cacheProcessRtoken(RTokenKeys[i], RToken[i], tokens[i], eachToken[i]);
  3328. }
  3329. g.MMM = g.MMMM = _.cache(_.process(g.ctoken("jan feb mar apr may jun jul aug sep oct nov dec"), t.month));
  3330. g.ddd = g.dddd = _.cache(_.process(g.ctoken("sun mon tue wed thu fri sat"),
  3331. function (s) {
  3332. return function () {
  3333. this.weekday = s;
  3334. };
  3335. }
  3336. ));
  3337. g.day = _fn(g.d, g.dd);
  3338. g.month = _fn(g.M, g.MMM);
  3339. g.year = _fn(g.yyyy, g.yy);
  3340. g.mdy = _setfn(g.ddd, g.month, g.day, g.year);
  3341. g.ymd = _setfn(g.ddd, g.year, g.month, g.day);
  3342. g.dmy = _setfn(g.ddd, g.day, g.month, g.year);
  3343. g.date = function (s) {
  3344. return ((g[Date.CultureInfo.dateElementOrder] || g.mdy).call(this, s));
  3345. };
  3346. },
  3347. relative: function () {
  3348. // relative date / time expressions
  3349. g.orientation = _.process(g.ctoken("past future"),
  3350. function (s) {
  3351. return function () {
  3352. this.orient = s;
  3353. };
  3354. }
  3355. );
  3356. g.operator = _.process(g.ctoken("add subtract"),
  3357. function (s) {
  3358. return function () {
  3359. this.operator = s;
  3360. };
  3361. }
  3362. );
  3363. g.rday = _.process(g.ctoken("yesterday tomorrow today now"), t.rday);
  3364. g.unit = _.process(g.ctoken("second minute hour day week month year"),
  3365. function (s) {
  3366. return function () {
  3367. this.unit = s;
  3368. };
  3369. }
  3370. );
  3371. }
  3372. };
  3373. g.buildGrammarFormats = function () {
  3374. // these need to be rebuilt every time the language changes.
  3375. _C = {};
  3376. grammarFormats.timeFormats();
  3377. grammarFormats.dateFormats();
  3378. grammarFormats.relative();
  3379. g.value = _.process(_.rtoken(/^([-+]?\d+)?(st|nd|rd|th)?/),
  3380. function (s) {
  3381. return function () {
  3382. this.value = s.replace(/\D/g, "");
  3383. };
  3384. }
  3385. );
  3386. g.expression = _.set([g.rday, g.operator, g.value, g.unit, g.orientation, g.ddd, g.MMM ]);
  3387. g.format = _.process(_.many(
  3388. _.any(
  3389. // translate format specifiers into grammar rules
  3390. _.process(
  3391. _.rtoken(/^(dd?d?d?(?!e)|MM?M?M?|yy?y?y?|hh?|HH?|mm?|ss?|tt?|zz?z?)/),
  3392. function (fmt) {
  3393. if (g[fmt]) {
  3394. return g[fmt];
  3395. } else {
  3396. throw $D.Parsing.Exception(fmt);
  3397. }
  3398. }
  3399. ),
  3400. // translate separator tokens into token rules
  3401. _.process(_.rtoken(/^[^dMyhHmstz]+/), // all legal separators
  3402. function (s) {
  3403. return _.ignore(_.stoken(s));
  3404. }
  3405. )
  3406. )
  3407. ),
  3408. // construct the parser ...
  3409. function (rules) {
  3410. return _.process(_.each.apply(null, rules), t.finishExact);
  3411. }
  3412. );
  3413. // starting rule for general purpose grammar
  3414. g._start = _.process(_.set([ g.date, g.time, g.expression ],
  3415. g.generalDelimiter, g.whiteSpace), t.finish);
  3416. };
  3417. g.buildGrammarFormats();
  3418. // parsing date format specifiers - ex: "h:m:s tt"
  3419. // this little guy will generate a custom parser based
  3420. // on the format string, ex: g.format("h:m:s tt")
  3421. // check for these formats first
  3422. g._formats = g.formats([
  3423. "\"yyyy-MM-ddTHH:mm:ssZ\"",
  3424. "yyyy-MM-ddTHH:mm:ss.sz",
  3425. "yyyy-MM-ddTHH:mm:ssZ",
  3426. "yyyy-MM-ddTHH:mm:ssz",
  3427. "yyyy-MM-ddTHH:mm:ss",
  3428. "yyyy-MM-ddTHH:mmZ",
  3429. "yyyy-MM-ddTHH:mmz",
  3430. "yyyy-MM-ddTHH:mm",
  3431. "ddd, MMM dd, yyyy H:mm:ss tt",
  3432. "ddd MMM d yyyy HH:mm:ss zzz",
  3433. "MMddyyyy",
  3434. "ddMMyyyy",
  3435. "Mddyyyy",
  3436. "ddMyyyy",
  3437. "Mdyyyy",
  3438. "dMyyyy",
  3439. "yyyy",
  3440. "Mdyy",
  3441. "dMyy",
  3442. "d"
  3443. ]);
  3444. // real starting rule: tries selected formats first,
  3445. // then general purpose rule
  3446. g.start = function (s) {
  3447. try {
  3448. var r = g._formats.call({}, s);
  3449. if (r[1].length === 0) {
  3450. return r;
  3451. }
  3452. } catch (e) {}
  3453. return g._start.call({}, s);
  3454. };
  3455. }());
  3456. (function () {
  3457. var $D = Date;
  3458. /**
  3459. * @desc Converts the specified string value into its JavaScript Date equivalent using CultureInfo specific format information.
  3460. *
  3461. * Example
  3462. <pre><code>
  3463. ///////////
  3464. // Dates //
  3465. ///////////
  3466. // 15-Oct-2004
  3467. var d1 = Date.parse("10/15/2004");
  3468. // 15-Oct-2004
  3469. var d1 = Date.parse("15-Oct-2004");
  3470. // 15-Oct-2004
  3471. var d1 = Date.parse("2004.10.15");
  3472. //Fri Oct 15, 2004
  3473. var d1 = Date.parse("Fri Oct 15, 2004");
  3474. ///////////
  3475. // Times //
  3476. ///////////
  3477. // Today at 10 PM.
  3478. var d1 = Date.parse("10 PM");
  3479. // Today at 10:30 PM.
  3480. var d1 = Date.parse("10:30 P.M.");
  3481. // Today at 6 AM.
  3482. var d1 = Date.parse("06am");
  3483. /////////////////////
  3484. // Dates and Times //
  3485. /////////////////////
  3486. // 8-July-2004 @ 10:30 PM
  3487. var d1 = Date.parse("July 8th, 2004, 10:30 PM");
  3488. // 1-July-2004 @ 10:30 PM
  3489. var d1 = Date.parse("2004-07-01T22:30:00");
  3490. ////////////////////
  3491. // Relative Dates //
  3492. ////////////////////
  3493. // Returns today's date. The string "today" is culture specific.
  3494. var d1 = Date.parse("today");
  3495. // Returns yesterday's date. The string "yesterday" is culture specific.
  3496. var d1 = Date.parse("yesterday");
  3497. // Returns the date of the next thursday.
  3498. var d1 = Date.parse("Next thursday");
  3499. // Returns the date of the most previous monday.
  3500. var d1 = Date.parse("last monday");
  3501. // Returns today's day + one year.
  3502. var d1 = Date.parse("next year");
  3503. ///////////////
  3504. // Date Math //
  3505. ///////////////
  3506. // Today + 2 days
  3507. var d1 = Date.parse("t+2");
  3508. // Today + 2 days
  3509. var d1 = Date.parse("today + 2 days");
  3510. // Today + 3 months
  3511. var d1 = Date.parse("t+3m");
  3512. // Today - 1 year
  3513. var d1 = Date.parse("today - 1 year");
  3514. // Today - 1 year
  3515. var d1 = Date.parse("t-1y");
  3516. /////////////////////////////
  3517. // Partial Dates and Times //
  3518. /////////////////////////////
  3519. // July 15th of this year.
  3520. var d1 = Date.parse("July 15");
  3521. // 15th day of current day and year.
  3522. var d1 = Date.parse("15");
  3523. // July 1st of current year at 10pm.
  3524. var d1 = Date.parse("7/1 10pm");
  3525. </code></pre>
  3526. *
  3527. * @param {String} The string value to convert into a Date object [Required]
  3528. * @return {Date} A Date object or null if the string cannot be converted into a Date.
  3529. */
  3530. var parseUtils = {
  3531. removeOrds: function (s) {
  3532. ords = s.match(/\b(\d+)(?:st|nd|rd|th)\b/); // find ordinal matches
  3533. s = ((ords && ords.length === 2) ? s.replace(ords[0], ords[1]) : s);
  3534. return s;
  3535. },
  3536. grammarParser: function (s) {
  3537. var r = null;
  3538. try {
  3539. r = $D.Grammar.start.call({}, s.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"));
  3540. } catch (e) {
  3541. return null;
  3542. }
  3543. return ((r[1].length === 0) ? r[0] : null);
  3544. },
  3545. nativeFallback: function(s) {
  3546. var t;
  3547. try {
  3548. // ok we haven't parsed it, last ditch attempt with the built-in parser.
  3549. t = Date._parse(s);
  3550. return (t || t === 0) ? new Date(t) : null;
  3551. } catch (e) {
  3552. return null;
  3553. }
  3554. }
  3555. };
  3556. function parse (s) {
  3557. var d;
  3558. if (!s) {
  3559. return null;
  3560. }
  3561. if (s instanceof Date) {
  3562. return s.clone();
  3563. }
  3564. if (s.length >= 4 && s.charAt(0) !== "0" && s.charAt(0) !== "+"&& s.charAt(0) !== "-") { // ie: 2004 will pass, 0800 won't.
  3565. // Start with specific formats
  3566. d = $D.Parsing.ISO.parse(s) || $D.Parsing.Numeric.parse(s);
  3567. }
  3568. if (d instanceof Date && !isNaN(d.getTime())) {
  3569. return d;
  3570. } else {
  3571. // find ordinal dates (1st, 3rd, 8th, etc and remove them as they cause parsing issues)
  3572. s = $D.Parsing.Normalizer.parse(parseUtils.removeOrds(s));
  3573. d = parseUtils.grammarParser(s);
  3574. if (d !== null) {
  3575. return d;
  3576. } else {
  3577. return parseUtils.nativeFallback(s);
  3578. }
  3579. }
  3580. }
  3581. if (!$D._parse) {
  3582. $D._parse = $D.parse;
  3583. }
  3584. $D.parse = parse;
  3585. Date.getParseFunction = function (fx) {
  3586. var fns = Date.Grammar.allformats(fx);
  3587. return function (s) {
  3588. var r = null;
  3589. for (var i = 0; i < fns.length; i++) {
  3590. try {
  3591. r = fns[i].call({}, s);
  3592. } catch (e) {
  3593. continue;
  3594. }
  3595. if (r[1].length === 0) {
  3596. return r[0];
  3597. }
  3598. }
  3599. return null;
  3600. };
  3601. };
  3602. /**
  3603. * Converts the specified string value into its JavaScript Date equivalent using the specified format {String} or formats {Array} and the CultureInfo specific format information.
  3604. * The format of the string value must match one of the supplied formats exactly.
  3605. *
  3606. * Example
  3607. <pre><code>
  3608. // 15-Oct-2004
  3609. var d1 = Date.parseExact("10/15/2004", "M/d/yyyy");
  3610. // 15-Oct-2004
  3611. var d1 = Date.parse("15-Oct-2004", "M-ddd-yyyy");
  3612. // 15-Oct-2004
  3613. var d1 = Date.parse("2004.10.15", "yyyy.MM.dd");
  3614. // Multiple formats
  3615. var d1 = Date.parseExact("10/15/2004", ["M/d/yyyy", "MMMM d, yyyy"]);
  3616. </code></pre>
  3617. *
  3618. * @param {String} The string value to convert into a Date object [Required].
  3619. * @param {Object} The expected format {String} or an array of expected formats {Array} of the date string [Required].
  3620. * @return {Date} A Date object or null if the string cannot be converted into a Date.
  3621. */
  3622. $D.parseExact = function (s, fx) {
  3623. return $D.getParseFunction(fx)(s);
  3624. };
  3625. }());
  3626. (function () {
  3627. var $D = Date,
  3628. $P = $D.prototype,
  3629. // $C = $D.CultureInfo, // not used atm
  3630. p = function (s, l) {
  3631. if (!l) {
  3632. l = 2;
  3633. }
  3634. return ("000" + s).slice(l * -1);
  3635. };
  3636. /**
  3637. * Converts a PHP format string to Java/.NET format string.
  3638. * A PHP format string can be used with ._format or .format.
  3639. * A Java/.NET format string can be used with .toString().
  3640. * The .parseExact function will only accept a Java/.NET format string
  3641. *
  3642. * Example
  3643. * var f1 = "%m/%d/%y"
  3644. * var f2 = Date.normalizeFormat(f1); // "MM/dd/yy"
  3645. *
  3646. * new Date().format(f1); // "04/13/08"
  3647. * new Date()._format(f1); // "04/13/08"
  3648. * new Date().toString(f2); // "04/13/08"
  3649. *
  3650. * var date = Date.parseExact("04/13/08", f2); // Sun Apr 13 2008
  3651. *
  3652. * @param {String} A PHP format string consisting of one or more format spcifiers.
  3653. * @return {String} The PHP format converted to a Java/.NET format string.
  3654. */
  3655. var normalizerSubstitutions = {
  3656. "d" : "dd",
  3657. "%d": "dd",
  3658. "D" : "ddd",
  3659. "%a": "ddd",
  3660. "j" : "dddd",
  3661. "l" : "dddd",
  3662. "%A": "dddd",
  3663. "S" : "S",
  3664. "F" : "MMMM",
  3665. "%B": "MMMM",
  3666. "m" : "MM",
  3667. "%m": "MM",
  3668. "M" : "MMM",
  3669. "%b": "MMM",
  3670. "%h": "MMM",
  3671. "n" : "M",
  3672. "Y" : "yyyy",
  3673. "%Y": "yyyy",
  3674. "y" : "yy",
  3675. "%y": "yy",
  3676. "g" : "h",
  3677. "%I": "h",
  3678. "G" : "H",
  3679. "h" : "hh",
  3680. "H" : "HH",
  3681. "%H": "HH",
  3682. "i" : "mm",
  3683. "%M": "mm",
  3684. "s" : "ss",
  3685. "%S": "ss",
  3686. "%r": "hh:mm tt",
  3687. "%R": "H:mm",
  3688. "%T": "H:mm:ss",
  3689. "%X": "t",
  3690. "%x": "d",
  3691. "%e": "d",
  3692. "%D": "MM/dd/yy",
  3693. "%n": "\\n",
  3694. "%t": "\\t",
  3695. "e" : "z",
  3696. "T" : "z",
  3697. "%z": "z",
  3698. "%Z": "z",
  3699. "Z" : "ZZ",
  3700. "N" : "u",
  3701. "w" : "u",
  3702. "%w": "u",
  3703. "W" : "W",
  3704. "%V": "W"
  3705. };
  3706. var normalizer = {
  3707. substitutes: function (m) {
  3708. return normalizerSubstitutions[m];
  3709. },
  3710. interpreted: function (m, x) {
  3711. var y;
  3712. switch (m) {
  3713. case "%u":
  3714. return x.getDay() + 1;
  3715. case "z":
  3716. return x.getOrdinalNumber();
  3717. case "%j":
  3718. return p(x.getOrdinalNumber(), 3);
  3719. case "%U":
  3720. var d1 = x.clone().set({month: 0, day: 1}).addDays(-1).moveToDayOfWeek(0),
  3721. d2 = x.clone().addDays(1).moveToDayOfWeek(0, -1);
  3722. return (d2 < d1) ? "00" : p((d2.getOrdinalNumber() - d1.getOrdinalNumber()) / 7 + 1);
  3723. case "%W":
  3724. return p(x.getWeek());
  3725. case "t":
  3726. return $D.getDaysInMonth(x.getFullYear(), x.getMonth());
  3727. case "o":
  3728. case "%G":
  3729. return x.setWeek(x.getISOWeek()).toString("yyyy");
  3730. case "%g":
  3731. return x._format("%G").slice(-2);
  3732. case "a":
  3733. case "%p":
  3734. return t("tt").toLowerCase();
  3735. case "A":
  3736. return t("tt").toUpperCase();
  3737. case "u":
  3738. return p(x.getMilliseconds(), 3);
  3739. case "I":
  3740. return (x.isDaylightSavingTime()) ? 1 : 0;
  3741. case "O":
  3742. return x.getUTCOffset();
  3743. case "P":
  3744. y = x.getUTCOffset();
  3745. return y.substring(0, y.length - 2) + ":" + y.substring(y.length - 2);
  3746. case "B":
  3747. var now = new Date();
  3748. return Math.floor(((now.getHours() * 3600) + (now.getMinutes() * 60) + now.getSeconds() + (now.getTimezoneOffset() + 60) * 60) / 86.4);
  3749. case "c":
  3750. return x.toISOString().replace(/\"/g, "");
  3751. case "U":
  3752. return $D.strtotime("now");
  3753. case "%c":
  3754. return t("d") + " " + t("t");
  3755. case "%C":
  3756. return Math.floor(x.getFullYear() / 100 + 1);
  3757. }
  3758. },
  3759. shouldOverrideDefaults: function (m) {
  3760. switch (m) {
  3761. case "%e":
  3762. return true;
  3763. default:
  3764. return false;
  3765. }
  3766. },
  3767. parse: function (m, context) {
  3768. var formatString, c = context || new Date();
  3769. formatString = normalizer.substitutes(m);
  3770. if (formatString) {
  3771. return formatString;
  3772. }
  3773. formatString = normalizer.interpreted(m, c);
  3774. if (formatString) {
  3775. return formatString;
  3776. } else {
  3777. return m;
  3778. }
  3779. }
  3780. };
  3781. $D.normalizeFormat = function (format, context) {
  3782. return format.replace(/(%|\\)?.|%%/g, function(t){
  3783. return normalizer.parse(t, context);
  3784. });
  3785. };
  3786. /**
  3787. * Format a local Unix timestamp according to locale settings
  3788. *
  3789. * Example:
  3790. * Date.strftime("%m/%d/%y", new Date()); // "04/13/08"
  3791. * Date.strftime("c", "2008-04-13T17:52:03Z"); // "04/13/08"
  3792. *
  3793. * @param {String} A format string consisting of one or more format spcifiers [Optional].
  3794. * @param {Number|String} The number representing the number of seconds that have elapsed since January 1, 1970 (local time).
  3795. * @return {String} A string representation of the current Date object.
  3796. */
  3797. $D.strftime = function (format, time) {
  3798. var d = Date.parse(time);
  3799. return d._format(format);
  3800. };
  3801. /**
  3802. * Parse any textual datetime description into a Unix timestamp.
  3803. * A Unix timestamp is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT).
  3804. *
  3805. * Example:
  3806. * Date.strtotime("04/13/08"); // 1208044800
  3807. * Date.strtotime("1970-01-01T00:00:00Z"); // 0
  3808. *
  3809. * @param {String} A format string consisting of one or more format spcifiers [Optional].
  3810. * @param {Object} A string or date object.
  3811. * @return {String} A string representation of the current Date object.
  3812. */
  3813. $D.strtotime = function (time) {
  3814. var d = $D.parse(time);
  3815. return Math.round($D.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(), d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds()) / 1000);
  3816. };
  3817. /**
  3818. * Converts the value of the current Date object to its equivalent string representation using a PHP/Unix style of date format specifiers.
  3819. * Format Specifiers
  3820. * Format Description Example
  3821. * ------ --------------------------------------------------------------------------- -----------------------
  3822. * %a abbreviated weekday name according to the current localed "Mon" through "Sun"
  3823. * %A full weekday name according to the current localed "Sunday" through "Saturday"
  3824. * %b abbreviated month name according to the current localed "Jan" through "Dec"
  3825. * %B full month name according to the current locale "January" through "December"
  3826. * %c preferred date and time representation for the current locale "4/13/2008 12:33 PM"
  3827. * %C century number (the year divided by 100 and truncated to an integer) "00" to "99"
  3828. * %d day of the month as a decimal number "01" to "31"
  3829. * %D same as %m/%d/%y "04/13/08"
  3830. * %e day of the month as a decimal number, a single digit is preceded by a space "1" to "31"
  3831. * %g like %G, but without the century "08"
  3832. * %G The 4-digit year corresponding to the ISO week number (see %V). "2008"
  3833. * This has the same format and value as %Y, except that if the ISO week number
  3834. * belongs to the previous or next year, that year is used instead.
  3835. * %h same as %b "Jan" through "Dec"
  3836. * %H hour as a decimal number using a 24-hour clock. "00" to "23"
  3837. * %I hour as a decimal number using a 12-hour clock. "01" to "12"
  3838. * %j day of the year as a decimal number. "001" to "366"
  3839. * %m month as a decimal number. "01" to "12"
  3840. * %M minute as a decimal number. "00" to "59"
  3841. * %n newline character "\n"
  3842. * %p either "am" or "pm" according to the given time value, or the "am" or "pm"
  3843. * corresponding strings for the current locale.
  3844. * %r time in a.m. and p.m. notation "8:44 PM"
  3845. * %R time in 24 hour notation "20:44"
  3846. * %S second as a decimal number "00" to "59"
  3847. * %t tab character "\t"
  3848. * %T current time, equal to %H:%M:%S "12:49:11"
  3849. * %u weekday as a decimal number ["1", "7"], with "1" representing Monday "1" to "7"
  3850. * %U week number of the current year as a decimal number, starting with the "0" to ("52" or "53")
  3851. * first Sunday as the first day of the first week
  3852. * %V The ISO 8601:1988 week number of the current year as a decimal number, "00" to ("52" or "53")
  3853. * range 01 to 53, where week 1 is the first week that has at least 4 days
  3854. * in the current year, and with Monday as the first day of the week.
  3855. * (Use %G or %g for the year component that corresponds to the week number
  3856. * for the specified timestamp.)
  3857. * %W week number of the current year as a decimal number, starting with the "00" to ("52" or "53")
  3858. * first Monday as the first day of the first week
  3859. * %w day of the week as a decimal, Sunday being "0" "0" to "6"
  3860. * %x preferred date representation for the current locale without the time "4/13/2008"
  3861. * %X preferred time representation for the current locale without the date "12:53:05"
  3862. * %y year as a decimal number without a century "00" "99"
  3863. * %Y year as a decimal number including the century "2008"
  3864. * %Z time zone or name or abbreviation "UTC", "EST", "PST"
  3865. * %z same as %Z
  3866. * %% a literal "%" characters "%"
  3867. * d Day of the month, 2 digits with leading zeros "01" to "31"
  3868. * D A textual representation of a day, three letters "Mon" through "Sun"
  3869. * j Day of the month without leading zeros "1" to "31"
  3870. * l A full textual representation of the day of the week (lowercase "L") "Sunday" through "Saturday"
  3871. * N ISO-8601 numeric representation of the day of the week (added in PHP 5.1.0) "1" (for Monday) through "7" (for Sunday)
  3872. * S English ordinal suffix for the day of the month, 2 characters "st", "nd", "rd" or "th". Works well with j
  3873. * w Numeric representation of the day of the week "0" (for Sunday) through "6" (for Saturday)
  3874. * z The day of the year (starting from "0") "0" through "365"
  3875. * W ISO-8601 week number of year, weeks starting on Monday "00" to ("52" or "53")
  3876. * F A full textual representation of a month, such as January or March "January" through "December"
  3877. * m Numeric representation of a month, with leading zeros "01" through "12"
  3878. * M A short textual representation of a month, three letters "Jan" through "Dec"
  3879. * n Numeric representation of a month, without leading zeros "1" through "12"
  3880. * t Number of days in the given month "28" through "31"
  3881. * L Whether it's a leap year "1" if it is a leap year, "0" otherwise
  3882. * o ISO-8601 year number. This has the same value as Y, except that if the "2008"
  3883. * ISO week number (W) belongs to the previous or next year, that year
  3884. * is used instead.
  3885. * Y A full numeric representation of a year, 4 digits "2008"
  3886. * y A two digit representation of a year "08"
  3887. * a Lowercase Ante meridiem and Post meridiem "am" or "pm"
  3888. * A Uppercase Ante meridiem and Post meridiem "AM" or "PM"
  3889. * B Swatch Internet time "000" through "999"
  3890. * g 12-hour format of an hour without leading zeros "1" through "12"
  3891. * G 24-hour format of an hour without leading zeros "0" through "23"
  3892. * h 12-hour format of an hour with leading zeros "01" through "12"
  3893. * H 24-hour format of an hour with leading zeros "00" through "23"
  3894. * i Minutes with leading zeros "00" to "59"
  3895. * s Seconds, with leading zeros "00" through "59"
  3896. * u Milliseconds "54321"
  3897. * e Timezone identifier "UTC", "EST", "PST"
  3898. * I Whether or not the date is in daylight saving time (uppercase i) "1" if Daylight Saving Time, "0" otherwise
  3899. * O Difference to Greenwich time (GMT) in hours "+0200", "-0600"
  3900. * P Difference to Greenwich time (GMT) with colon between hours and minutes "+02:00", "-06:00"
  3901. * T Timezone abbreviation "UTC", "EST", "PST"
  3902. * Z Timezone offset in seconds. The offset for timezones west of UTC is "-43200" through "50400"
  3903. * always negative, and for those east of UTC is always positive.
  3904. * c ISO 8601 date "2004-02-12T15:19:21+00:00"
  3905. * r RFC 2822 formatted date "Thu, 21 Dec 2000 16:01:07 +0200"
  3906. * U Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) "0"
  3907. * @param {String} A format string consisting of one or more format spcifiers [Optional].
  3908. * @return {String} A string representation of the current Date object.
  3909. */
  3910. var formatReplace = function (context) {
  3911. return function (m) {
  3912. var formatString, override = false;
  3913. if (m.charAt(0) === "\\" || m.substring(0, 2) === "%%") {
  3914. return m.replace("\\", "").replace("%%", "%");
  3915. }
  3916. override = normalizer.shouldOverrideDefaults(m);
  3917. formatString = $D.normalizeFormat(m, context);
  3918. if (formatString) {
  3919. return context.toString(formatString, override);
  3920. }
  3921. };
  3922. };
  3923. $P._format = function (format) {
  3924. var formatter = formatReplace(this);
  3925. if (!format) {
  3926. return this._toString();
  3927. } else {
  3928. return format.replace(/(%|\\)?.|%%/g, formatter);
  3929. }
  3930. };
  3931. if (!$P.format) {
  3932. $P.format = $P._format;
  3933. }
  3934. }());
  3935. (function () {
  3936. "use strict";
  3937. var gFn = function (attr) {
  3938. return function () {
  3939. return this[attr];
  3940. };
  3941. };
  3942. var sFn = function (attr) {
  3943. return function (val) {
  3944. this[attr] = val;
  3945. return this;
  3946. };
  3947. };
  3948. var attrs = ["years", "months", "days", "hours", "minutes", "seconds", "milliseconds"];
  3949. var addSetFuncs = function (context, attrs) {
  3950. for (var i = 0; i < attrs.length ; i++) {
  3951. var $a = attrs[i], $b = $a.slice(0, 1).toUpperCase() + $a.slice(1);
  3952. context.prototype[$a] = 0;
  3953. context.prototype["get" + $b] = gFn($a);
  3954. context.prototype["set" + $b] = sFn($a);
  3955. }
  3956. };
  3957. /**
  3958. * new TimeSpan(milliseconds);
  3959. * new TimeSpan(days, hours, minutes, seconds);
  3960. * new TimeSpan(days, hours, minutes, seconds, milliseconds);
  3961. */
  3962. var TimeSpan = function (days, hours, minutes, seconds, milliseconds) {
  3963. if (arguments.length === 1 && typeof days === "number") {
  3964. var orient = (days < 0) ? -1 : +1;
  3965. var millsLeft = Math.abs(days);
  3966. this.setDays(Math.floor(millsLeft / 86400000) * orient);
  3967. millsLeft = millsLeft % 86400000;
  3968. this.setHours(Math.floor(millsLeft / 3600000) * orient);
  3969. millsLeft = millsLeft % 3600000;
  3970. this.setMinutes(Math.floor(millsLeft / 60000) * orient);
  3971. millsLeft = millsLeft % 60000;
  3972. this.setSeconds(Math.floor(millsLeft / 1000) * orient);
  3973. millsLeft = millsLeft % 1000;
  3974. this.setMilliseconds(millsLeft * orient);
  3975. } else {
  3976. this.set(days, hours, minutes, seconds, milliseconds);
  3977. }
  3978. this.getTotalMilliseconds = function () {
  3979. return (this.getDays() * 86400000) +
  3980. (this.getHours() * 3600000) +
  3981. (this.getMinutes() * 60000) +
  3982. (this.getSeconds() * 1000);
  3983. };
  3984. this.compareTo = function (time) {
  3985. var t1 = new Date(1970, 1, 1, this.getHours(), this.getMinutes(), this.getSeconds()), t2;
  3986. if (time === null) {
  3987. t2 = new Date(1970, 1, 1, 0, 0, 0);
  3988. }
  3989. else {
  3990. t2 = new Date(1970, 1, 1, time.getHours(), time.getMinutes(), time.getSeconds());
  3991. }
  3992. return (t1 < t2) ? -1 : (t1 > t2) ? 1 : 0;
  3993. };
  3994. this.equals = function (time) {
  3995. return (this.compareTo(time) === 0);
  3996. };
  3997. this.add = function (time) {
  3998. return (time === null) ? this : this.addSeconds(time.getTotalMilliseconds() / 1000);
  3999. };
  4000. this.subtract = function (time) {
  4001. return (time === null) ? this : this.addSeconds(-time.getTotalMilliseconds() / 1000);
  4002. };
  4003. this.addDays = function (n) {
  4004. return new TimeSpan(this.getTotalMilliseconds() + (n * 86400000));
  4005. };
  4006. this.addHours = function (n) {
  4007. return new TimeSpan(this.getTotalMilliseconds() + (n * 3600000));
  4008. };
  4009. this.addMinutes = function (n) {
  4010. return new TimeSpan(this.getTotalMilliseconds() + (n * 60000));
  4011. };
  4012. this.addSeconds = function (n) {
  4013. return new TimeSpan(this.getTotalMilliseconds() + (n * 1000));
  4014. };
  4015. this.addMilliseconds = function (n) {
  4016. return new TimeSpan(this.getTotalMilliseconds() + n);
  4017. };
  4018. this.get12HourHour = function () {
  4019. return (this.getHours() > 12) ? this.getHours() - 12 : (this.getHours() === 0) ? 12 : this.getHours();
  4020. };
  4021. this.getDesignator = function () {
  4022. return (this.getHours() < 12) ? Date.CultureInfo.amDesignator : Date.CultureInfo.pmDesignator;
  4023. };
  4024. this.toString = function (format) {
  4025. this._toString = function () {
  4026. if (this.getDays() !== null && this.getDays() > 0) {
  4027. return this.getDays() + "." + this.getHours() + ":" + this.p(this.getMinutes()) + ":" + this.p(this.getSeconds());
  4028. } else {
  4029. return this.getHours() + ":" + this.p(this.getMinutes()) + ":" + this.p(this.getSeconds());
  4030. }
  4031. };
  4032. this.p = function (s) {
  4033. return (s.toString().length < 2) ? "0" + s : s;
  4034. };
  4035. var me = this;
  4036. return format ? format.replace(/dd?|HH?|hh?|mm?|ss?|tt?/g,
  4037. function (format) {
  4038. switch (format) {
  4039. case "d":
  4040. return me.getDays();
  4041. case "dd":
  4042. return me.p(me.getDays());
  4043. case "H":
  4044. return me.getHours();
  4045. case "HH":
  4046. return me.p(me.getHours());
  4047. case "h":
  4048. return me.get12HourHour();
  4049. case "hh":
  4050. return me.p(me.get12HourHour());
  4051. case "m":
  4052. return me.getMinutes();
  4053. case "mm":
  4054. return me.p(me.getMinutes());
  4055. case "s":
  4056. return me.getSeconds();
  4057. case "ss":
  4058. return me.p(me.getSeconds());
  4059. case "t":
  4060. return ((me.getHours() < 12) ? Date.CultureInfo.amDesignator : Date.CultureInfo.pmDesignator).substring(0, 1);
  4061. case "tt":
  4062. return (me.getHours() < 12) ? Date.CultureInfo.amDesignator : Date.CultureInfo.pmDesignator;
  4063. }
  4064. }
  4065. ) : this._toString();
  4066. };
  4067. return this;
  4068. };
  4069. addSetFuncs(TimeSpan, attrs.slice(2));
  4070. TimeSpan.prototype.set = function (days, hours, minutes, seconds, milliseconds){
  4071. this.setDays(days || this.getDays());
  4072. this.setHours(hours || this.getHours());
  4073. this.setMinutes(minutes || this.getMinutes());
  4074. this.setSeconds(seconds || this.getSeconds());
  4075. this.setMilliseconds(milliseconds || this.getMilliseconds());
  4076. };
  4077. /**
  4078. * Gets the time of day for this date instances.
  4079. * @return {TimeSpan} TimeSpan
  4080. */
  4081. Date.prototype.getTimeOfDay = function () {
  4082. return new TimeSpan(0, this.getHours(), this.getMinutes(), this.getSeconds(), this.getMilliseconds());
  4083. };
  4084. Date.TimeSpan = TimeSpan;
  4085. if (typeof window !== "undefined" ) {
  4086. // keeping API compatible for v1.x
  4087. window.TimeSpan = TimeSpan;
  4088. }
  4089. }());
  4090. (function () {
  4091. "use strict";
  4092. var attrs = ["years", "months", "days", "hours", "minutes", "seconds", "milliseconds"];
  4093. var gFn = function (attr) {
  4094. return function () {
  4095. return this[attr];
  4096. };
  4097. };
  4098. var sFn = function (attr) {
  4099. return function (val) {
  4100. this[attr] = val;
  4101. return this;
  4102. };
  4103. };
  4104. var addSetFuncs = function (context, attrs) {
  4105. for (var i = 0; i < attrs.length ; i++) {
  4106. var $a = attrs[i], $b = $a.slice(0, 1).toUpperCase() + $a.slice(1);
  4107. context.prototype[$a] = 0;
  4108. context.prototype["get" + $b] = gFn($a);
  4109. context.prototype["set" + $b] = sFn($a);
  4110. }
  4111. };
  4112. var setMonthsAndYears = function (orient, d1, d2, context) {
  4113. function inc() {
  4114. d1.addMonths(-orient);
  4115. context.months++;
  4116. if (context.months === 12) {
  4117. context.years++;
  4118. context.months = 0;
  4119. }
  4120. }
  4121. if (orient === +1) {
  4122. while (d1 > d2) {
  4123. inc();
  4124. }
  4125. } else {
  4126. while (d1 < d2) {
  4127. inc();
  4128. }
  4129. }
  4130. context.months--;
  4131. context.months *= orient;
  4132. context.years *= orient;
  4133. };
  4134. var adjustForDST = function(orient, startDate, endDate) {
  4135. var hasDSTMismatch = (false === (startDate.isDaylightSavingTime() === endDate.isDaylightSavingTime()));
  4136. if (hasDSTMismatch && orient === 1) {
  4137. startDate.addHours(-1);
  4138. } else if (hasDSTMismatch) {
  4139. startDate.addHours(1);
  4140. }
  4141. };
  4142. /**
  4143. * TimePeriod(startDate, endDate);
  4144. * TimePeriod(years, months, days, hours, minutes, seconds, milliseconds);
  4145. */
  4146. var TimePeriod = function (years, months, days, hours, minutes, seconds, milliseconds) {
  4147. if (arguments.length === 7) {
  4148. this.set(years, months, days, hours, minutes, seconds, milliseconds);
  4149. } else if (arguments.length === 2 && arguments[0] instanceof Date && arguments[1] instanceof Date) {
  4150. var startDate = arguments[0].clone();
  4151. var endDate = arguments[1].clone();
  4152. var orient = (startDate > endDate) ? +1 : -1;
  4153. this.dates = {
  4154. start: arguments[0].clone(),
  4155. end: arguments[1].clone()
  4156. };
  4157. setMonthsAndYears(orient, startDate, endDate, this);
  4158. adjustForDST(orient, startDate, endDate);
  4159. // // TODO - adjust for DST
  4160. var diff = endDate - startDate;
  4161. if (diff !== 0) {
  4162. var ts = new TimeSpan(diff);
  4163. this.set(this.years, this.months, ts.getDays(), ts.getHours(), ts.getMinutes(), ts.getSeconds(), ts.getMilliseconds());
  4164. }
  4165. }
  4166. return this;
  4167. };
  4168. // create all the set functions.
  4169. addSetFuncs(TimePeriod, attrs);
  4170. TimePeriod.prototype.set = function (years, months, days, hours, minutes, seconds, milliseconds){
  4171. this.setYears(years || this.getYears());
  4172. this.setMonths(months || this.getMonths());
  4173. this.setDays(days || this.getDays());
  4174. this.setHours(hours || this.getHours());
  4175. this.setMinutes(minutes || this.getMinutes());
  4176. this.setSeconds(seconds || this.getSeconds());
  4177. this.setMilliseconds(milliseconds || this.getMilliseconds());
  4178. };
  4179. Date.TimePeriod = TimePeriod;
  4180. if (typeof window !== "undefined") {
  4181. // keeping API compatible for v1.x
  4182. window.TimePeriod = TimePeriod;
  4183. }
  4184. }());