date-en-US.js 127 KB

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