DateTimeFormatInfo.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. // System.Globalization.DateTimeFormatInfo
  2. //
  3. // Some useful functions are missing in the ECMA specs.
  4. // They have been added following MS SDK Beta2
  5. //
  6. // Martin Weindel ([email protected])
  7. //
  8. // (C) Martin Weindel ([email protected])
  9. //
  10. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  11. //
  12. // Permission is hereby granted, free of charge, to any person obtaining
  13. // a copy of this software and associated documentation files (the
  14. // "Software"), to deal in the Software without restriction, including
  15. // without limitation the rights to use, copy, modify, merge, publish,
  16. // distribute, sublicense, and/or sell copies of the Software, and to
  17. // permit persons to whom the Software is furnished to do so, subject to
  18. // the following conditions:
  19. //
  20. // The above copyright notice and this permission notice shall be
  21. // included in all copies or substantial portions of the Software.
  22. //
  23. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  27. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  28. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. //
  31. using System;
  32. using System.Collections;
  33. using System.Threading;
  34. namespace System.Globalization
  35. {
  36. [Serializable]
  37. [MonoTODO ("Fix serialization compatibility with MS.NET")]
  38. public sealed class DateTimeFormatInfo : ICloneable, IFormatProvider {
  39. private static readonly string MSG_READONLY = "This instance is read only";
  40. private static readonly string MSG_ARRAYSIZE_MONTH = "An array with exactly 13 elements is needed";
  41. private static readonly string MSG_ARRAYSIZE_DAY = "An array with exactly 7 elements is needed";
  42. private static readonly string[] INVARIANT_ABBREVIATED_DAY_NAMES
  43. = new string[7] { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
  44. private static readonly string[] INVARIANT_DAY_NAMES
  45. = new string[7] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
  46. private static readonly string[] INVARIANT_ABBREVIATED_MONTH_NAMES
  47. = new string[13] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", ""};
  48. private static readonly string[] INVARIANT_MONTH_NAMES
  49. = new string[13] { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", ""};
  50. private static readonly string[] INVARIANT_ERA_NAMES = {"A.D."};
  51. private static DateTimeFormatInfo theInvariantDateTimeFormatInfo;
  52. private bool readOnly;
  53. private string _AMDesignator;
  54. private string _PMDesignator;
  55. private string _DateSeparator;
  56. private string _TimeSeparator;
  57. private string _ShortDatePattern;
  58. private string _LongDatePattern;
  59. private string _ShortTimePattern;
  60. private string _LongTimePattern;
  61. private string _MonthDayPattern;
  62. private string _YearMonthPattern;
  63. private string _FullDateTimePattern;
  64. private string _RFC1123Pattern;
  65. private string _SortableDateTimePattern;
  66. private string _UniversalSortableDateTimePattern;
  67. private DayOfWeek _FirstDayOfWeek;
  68. private Calendar _Calendar;
  69. private CalendarWeekRule _CalendarWeekRule;
  70. private string[] _AbbreviatedDayNames;
  71. private string[] _DayNames;
  72. private string[] _MonthNames;
  73. private string[] _AbbreviatedMonthNames;
  74. // FIXME: not supported other than invariant
  75. private string [] _ShortDatePatterns;
  76. private string [] _LongDatePatterns;
  77. private string [] _ShortTimePatterns;
  78. private string [] _LongTimePatterns;
  79. private string [] _MonthDayPatterns;
  80. private string [] _YearMonthPatterns;
  81. public DateTimeFormatInfo()
  82. {
  83. readOnly = false;
  84. _AMDesignator = "AM";
  85. _PMDesignator = "PM";
  86. _DateSeparator = "/";
  87. _TimeSeparator = ":";
  88. _ShortDatePattern = "MM/dd/yyyy";
  89. _LongDatePattern = "dddd, dd MMMM yyyy";
  90. _ShortTimePattern = "HH:mm";
  91. _LongTimePattern = "HH:mm:ss";
  92. _MonthDayPattern = "MMMM dd";
  93. _YearMonthPattern = "yyyy MMMM";
  94. _FullDateTimePattern = "dddd, dd MMMM yyyy HH:mm:ss";
  95. // FIXME: for the following three pattern: "The
  96. // default value of this property is derived
  97. // from the calendar that is set for
  98. // CultureInfo.CurrentCulture or the default
  99. // calendar of CultureInfo.CurrentCulture."
  100. // Actually, no predefined culture has different values
  101. // than those default values.
  102. _RFC1123Pattern = "ddd, dd MMM yyyy HH':'mm':'ss 'GMT'";
  103. _SortableDateTimePattern = "yyyy'-'MM'-'dd'T'HH':'mm':'ss";
  104. _UniversalSortableDateTimePattern = "yyyy'-'MM'-'dd HH':'mm':'ss'Z'";
  105. _FirstDayOfWeek = DayOfWeek.Sunday;
  106. _Calendar = new GregorianCalendar();
  107. _CalendarWeekRule = CalendarWeekRule.FirstDay;
  108. _AbbreviatedDayNames = INVARIANT_ABBREVIATED_DAY_NAMES;
  109. _DayNames = INVARIANT_DAY_NAMES;
  110. _AbbreviatedMonthNames = INVARIANT_ABBREVIATED_MONTH_NAMES;
  111. _MonthNames = INVARIANT_MONTH_NAMES;
  112. }
  113. // LAMESPEC: this is not in ECMA specs
  114. public static DateTimeFormatInfo GetInstance(IFormatProvider provider)
  115. {
  116. if (provider != null) {
  117. DateTimeFormatInfo dtfi;
  118. dtfi = (DateTimeFormatInfo)provider.GetFormat(typeof(DateTimeFormatInfo));
  119. if (dtfi != null)
  120. return dtfi;
  121. }
  122. return CurrentInfo;
  123. }
  124. public bool IsReadOnly {
  125. get {
  126. return readOnly;
  127. }
  128. }
  129. public static DateTimeFormatInfo ReadOnly(DateTimeFormatInfo dtfi)
  130. {
  131. DateTimeFormatInfo copy = (DateTimeFormatInfo)dtfi.Clone();
  132. copy.readOnly = true;
  133. return copy;
  134. }
  135. public object Clone ()
  136. {
  137. DateTimeFormatInfo clone = (DateTimeFormatInfo) MemberwiseClone();
  138. // clone is not read only
  139. clone.readOnly = false;
  140. return clone;
  141. }
  142. public object GetFormat(Type formatType)
  143. {
  144. return (formatType == GetType()) ? this : null;
  145. }
  146. public string GetAbbreviatedEraName (int era)
  147. {
  148. if (era < 0 || era >= _Calendar.AbbreviatedEraNames.Length)
  149. throw new ArgumentOutOfRangeException ("era", era.ToString ());
  150. return _Calendar.AbbreviatedEraNames [era];
  151. }
  152. public string GetAbbreviatedMonthName(int month)
  153. {
  154. if (month < 1 || month > 13) throw new ArgumentOutOfRangeException();
  155. return _AbbreviatedMonthNames[month-1];
  156. }
  157. public int GetEra (string eraName)
  158. {
  159. if (eraName == null)
  160. throw new ArgumentNullException ();
  161. string [] eras = _Calendar.EraNames;
  162. for (int i = 0; i < eras.Length; i++)
  163. if (CultureInfo.InvariantCulture.CompareInfo
  164. .Compare (eraName, eras [i],
  165. CompareOptions.IgnoreCase) == 0)
  166. return i;
  167. return -1;
  168. }
  169. public string GetEraName (int era)
  170. {
  171. if (era < 0 || era > _Calendar.EraNames.Length)
  172. throw new ArgumentOutOfRangeException ("era", era.ToString ());
  173. return _Calendar.EraNames [era - 1];
  174. }
  175. public string GetMonthName(int month)
  176. {
  177. if (month < 1 || month > 13) throw new ArgumentOutOfRangeException();
  178. return _MonthNames[month-1];
  179. }
  180. public string[] AbbreviatedDayNames
  181. {
  182. get
  183. {
  184. return (string[]) _AbbreviatedDayNames.Clone();
  185. }
  186. set
  187. {
  188. if (IsReadOnly) throw new InvalidOperationException(MSG_READONLY);
  189. if (value == null) throw new ArgumentNullException();
  190. if (value.GetLength(0) != 7) throw new ArgumentException(MSG_ARRAYSIZE_DAY);
  191. _AbbreviatedDayNames = (string[]) value.Clone();
  192. }
  193. }
  194. public string[] AbbreviatedMonthNames
  195. {
  196. get
  197. {
  198. return (string[]) _AbbreviatedMonthNames.Clone();
  199. }
  200. set
  201. {
  202. if (IsReadOnly) throw new InvalidOperationException(MSG_READONLY);
  203. if (value == null) throw new ArgumentNullException();
  204. if (value.GetLength(0) != 13) throw new ArgumentException(MSG_ARRAYSIZE_MONTH);
  205. _AbbreviatedMonthNames = (string[]) value.Clone();
  206. }
  207. }
  208. public string[] DayNames
  209. {
  210. get
  211. {
  212. return (string[]) _DayNames.Clone();
  213. }
  214. set
  215. {
  216. if (IsReadOnly) throw new InvalidOperationException(MSG_READONLY);
  217. if (value == null) throw new ArgumentNullException();
  218. if (value.GetLength(0) != 7) throw new ArgumentException(MSG_ARRAYSIZE_DAY);
  219. _DayNames = (string[]) value.Clone();
  220. }
  221. }
  222. public string[] MonthNames
  223. {
  224. get
  225. {
  226. return (string[]) _MonthNames.Clone();
  227. }
  228. set
  229. {
  230. if (IsReadOnly) throw new InvalidOperationException(MSG_READONLY);
  231. if (value == null) throw new ArgumentNullException();
  232. if (value.GetLength(0) != 13) throw new ArgumentException(MSG_ARRAYSIZE_MONTH);
  233. _MonthNames = (string[]) value.Clone();
  234. }
  235. }
  236. public string AMDesignator
  237. {
  238. get
  239. {
  240. return _AMDesignator;
  241. }
  242. set
  243. {
  244. if (IsReadOnly) throw new InvalidOperationException(MSG_READONLY);
  245. if (value == null) throw new ArgumentNullException();
  246. _AMDesignator = value;
  247. }
  248. }
  249. public string PMDesignator
  250. {
  251. get
  252. {
  253. return _PMDesignator;
  254. }
  255. set
  256. {
  257. if (IsReadOnly) throw new InvalidOperationException(MSG_READONLY);
  258. if (value == null) throw new ArgumentNullException();
  259. _PMDesignator = value;
  260. }
  261. }
  262. public string DateSeparator
  263. {
  264. get
  265. {
  266. return _DateSeparator;
  267. }
  268. set
  269. {
  270. if (IsReadOnly) throw new InvalidOperationException(MSG_READONLY);
  271. if (value == null) throw new ArgumentNullException();
  272. _DateSeparator = value;
  273. }
  274. }
  275. public string TimeSeparator
  276. {
  277. get
  278. {
  279. return _TimeSeparator;
  280. }
  281. set
  282. {
  283. if (IsReadOnly) throw new InvalidOperationException(MSG_READONLY);
  284. if (value == null) throw new ArgumentNullException();
  285. _TimeSeparator = value;
  286. }
  287. }
  288. public string LongDatePattern
  289. {
  290. get
  291. {
  292. return _LongDatePattern;
  293. }
  294. set
  295. {
  296. if (IsReadOnly) throw new InvalidOperationException(MSG_READONLY);
  297. if (value == null) throw new ArgumentNullException();
  298. _LongDatePattern = value;
  299. }
  300. }
  301. public string ShortDatePattern
  302. {
  303. get
  304. {
  305. return _ShortDatePattern;
  306. }
  307. set
  308. {
  309. if (IsReadOnly) throw new InvalidOperationException(MSG_READONLY);
  310. if (value == null) throw new ArgumentNullException();
  311. _ShortDatePattern = value;
  312. }
  313. }
  314. public string ShortTimePattern
  315. {
  316. get
  317. {
  318. return _ShortTimePattern;
  319. }
  320. set
  321. {
  322. if (IsReadOnly) throw new InvalidOperationException(MSG_READONLY);
  323. if (value == null) throw new ArgumentNullException();
  324. _ShortTimePattern = value;
  325. }
  326. }
  327. public string LongTimePattern
  328. {
  329. get
  330. {
  331. return _LongTimePattern;
  332. }
  333. set
  334. {
  335. if (IsReadOnly) throw new InvalidOperationException(MSG_READONLY);
  336. if (value == null) throw new ArgumentNullException();
  337. _LongTimePattern = value;
  338. }
  339. }
  340. public string MonthDayPattern
  341. {
  342. get
  343. {
  344. return _MonthDayPattern;
  345. }
  346. set
  347. {
  348. if (IsReadOnly) throw new InvalidOperationException(MSG_READONLY);
  349. if (value == null) throw new ArgumentNullException();
  350. _MonthDayPattern = value;
  351. }
  352. }
  353. public string YearMonthPattern
  354. {
  355. get
  356. {
  357. return _YearMonthPattern;
  358. }
  359. set
  360. {
  361. if (IsReadOnly) throw new InvalidOperationException(MSG_READONLY);
  362. if (value == null) throw new ArgumentNullException();
  363. _YearMonthPattern = value;
  364. }
  365. }
  366. public string FullDateTimePattern
  367. {
  368. get
  369. {
  370. if(_FullDateTimePattern!=null) {
  371. return _FullDateTimePattern;
  372. } else {
  373. return(_LongDatePattern + " " + _LongTimePattern);
  374. }
  375. }
  376. set
  377. {
  378. if (IsReadOnly) throw new InvalidOperationException(MSG_READONLY);
  379. if (value == null) throw new ArgumentNullException();
  380. _FullDateTimePattern = value;
  381. }
  382. }
  383. public static DateTimeFormatInfo CurrentInfo
  384. {
  385. get
  386. {
  387. return Thread.CurrentThread.CurrentCulture.DateTimeFormat;
  388. }
  389. }
  390. public static DateTimeFormatInfo InvariantInfo
  391. {
  392. get
  393. {
  394. if (theInvariantDateTimeFormatInfo == null) {
  395. theInvariantDateTimeFormatInfo =
  396. DateTimeFormatInfo.ReadOnly(new DateTimeFormatInfo());
  397. theInvariantDateTimeFormatInfo.FillInvariantPatterns ();
  398. }
  399. return theInvariantDateTimeFormatInfo;
  400. }
  401. }
  402. // LAMESPEC: this is not in ECMA specs
  403. public DayOfWeek FirstDayOfWeek
  404. {
  405. get
  406. {
  407. return _FirstDayOfWeek;
  408. }
  409. set
  410. {
  411. if (IsReadOnly) throw new InvalidOperationException(MSG_READONLY);
  412. if ((int) value < 0 || (int) value > 6) throw new ArgumentOutOfRangeException();
  413. _FirstDayOfWeek = value;
  414. }
  415. }
  416. // LAMESPEC: this is not in ECMA specs
  417. public Calendar Calendar
  418. {
  419. get
  420. {
  421. return _Calendar;
  422. }
  423. set
  424. {
  425. if (IsReadOnly) throw new InvalidOperationException(MSG_READONLY);
  426. if (value == null) throw new ArgumentNullException();
  427. _Calendar = value;
  428. }
  429. }
  430. public CalendarWeekRule CalendarWeekRule
  431. {
  432. get
  433. {
  434. return _CalendarWeekRule;
  435. }
  436. set
  437. {
  438. if (IsReadOnly) throw new InvalidOperationException(MSG_READONLY);
  439. _CalendarWeekRule = value;
  440. }
  441. }
  442. // LAMESPEC: this is not in ECMA specs
  443. public string RFC1123Pattern
  444. {
  445. get
  446. {
  447. return _RFC1123Pattern;
  448. }
  449. }
  450. // LAMESPEC: this is not in ECMA specs
  451. public string SortableDateTimePattern
  452. {
  453. get
  454. {
  455. return _SortableDateTimePattern;
  456. }
  457. }
  458. // LAMESPEC: this is not in ECMA specs
  459. public string UniversalSortableDateTimePattern
  460. {
  461. get
  462. {
  463. return _UniversalSortableDateTimePattern;
  464. }
  465. }
  466. // LAMESPEC: this is not in ECMA specs
  467. [MonoTODO ("Not complete depending on GetAllDateTimePatterns(char)")]
  468. public string[] GetAllDateTimePatterns()
  469. {
  470. FillAllDateTimePatterns ();
  471. return (string []) all_date_time_patterns.Clone ();
  472. }
  473. // Same as above, but with no cloning, because we know that
  474. // clients are friendly
  475. internal string [] GetAllDateTimePatternsInternal ()
  476. {
  477. FillAllDateTimePatterns ();
  478. return all_date_time_patterns;
  479. }
  480. // Prevent write reordering
  481. volatile string [] all_date_time_patterns;
  482. void FillAllDateTimePatterns (){
  483. if (all_date_time_patterns != null)
  484. return;
  485. ArrayList al = new ArrayList ();
  486. foreach (string s in GetAllDateTimePatterns ('d'))
  487. al.Add (s);
  488. foreach (string s in GetAllDateTimePatterns ('D'))
  489. al.Add (s);
  490. foreach (string s in GetAllDateTimePatterns ('g'))
  491. al.Add (s);
  492. foreach (string s in GetAllDateTimePatterns ('G'))
  493. al.Add (s);
  494. foreach (string s in GetAllDateTimePatterns ('f'))
  495. al.Add (s);
  496. foreach (string s in GetAllDateTimePatterns ('F'))
  497. al.Add (s);
  498. // Yes, that is very meaningless, but that is what MS
  499. // is doing (LAMESPEC: Since it is documented that
  500. // 'M' and 'm' are equal, they should not cosider
  501. // that there is a possibility that 'M' and 'm' are
  502. // different.)
  503. foreach (string s in GetAllDateTimePatterns ('m'))
  504. al.Add (s);
  505. foreach (string s in GetAllDateTimePatterns ('M'))
  506. al.Add (s);
  507. foreach (string s in GetAllDateTimePatterns ('r'))
  508. al.Add (s);
  509. foreach (string s in GetAllDateTimePatterns ('R'))
  510. al.Add (s);
  511. foreach (string s in GetAllDateTimePatterns ('s'))
  512. al.Add (s);
  513. foreach (string s in GetAllDateTimePatterns ('t'))
  514. al.Add (s);
  515. foreach (string s in GetAllDateTimePatterns ('T'))
  516. al.Add (s);
  517. foreach (string s in GetAllDateTimePatterns ('u'))
  518. al.Add (s);
  519. foreach (string s in GetAllDateTimePatterns ('U'))
  520. al.Add (s);
  521. foreach (string s in GetAllDateTimePatterns ('y'))
  522. al.Add (s);
  523. foreach (string s in GetAllDateTimePatterns ('Y'))
  524. al.Add (s);
  525. // all_date_time_patterns needs to be volatile to prevent
  526. // reordering of writes here and still avoid any locking.
  527. all_date_time_patterns = (string []) al.ToArray (typeof (string)) as string [];
  528. }
  529. // LAMESPEC: this is not in ECMA specs
  530. [MonoTODO ("We need more culture data in locale-builder")]
  531. public string[] GetAllDateTimePatterns (char format)
  532. {
  533. string [] list;
  534. switch (format) {
  535. // Date
  536. case 'D':
  537. if (_LongDatePatterns != null && _LongDatePatterns.Length > 0)
  538. return _LongDatePatterns.Clone () as string [];
  539. return new string [] {LongDatePattern};
  540. case 'd':
  541. if (_ShortDatePatterns != null && _ShortDatePatterns.Length > 0)
  542. return _ShortDatePatterns.Clone () as string [];
  543. return new string [] {ShortDatePattern};
  544. // Time
  545. case 'T':
  546. if (_LongTimePatterns != null && _LongTimePatterns.Length > 0)
  547. return _LongTimePatterns.Clone () as string [];
  548. return new string [] {LongTimePattern};
  549. case 't':
  550. if (_ShortTimePatterns != null && _ShortTimePatterns.Length > 0)
  551. return _ShortTimePatterns.Clone () as string [];
  552. return new string [] {ShortTimePattern};
  553. // {Short|Long}Date + {Short|Long}Time
  554. // FIXME: they should be the agglegation of the
  555. // combination of the Date patterns and Time patterns.
  556. case 'G':
  557. list = PopulateCombinedList (_ShortDatePatterns, _LongTimePatterns);
  558. if (list != null && list.Length > 0)
  559. return list;
  560. return new string [] {ShortDatePattern + " " + LongTimePattern};
  561. case 'g':
  562. list = PopulateCombinedList (_ShortDatePatterns, _ShortTimePatterns);
  563. if (list != null && list.Length > 0)
  564. return list;
  565. return new string [] {ShortDatePattern + " " + ShortTimePattern};
  566. // The 'U' pattern strings are always the same as 'F'.
  567. // (only differs in assuming UTC or not.)
  568. case 'U':
  569. case 'F':
  570. list = PopulateCombinedList (_LongDatePatterns, _LongTimePatterns);
  571. if (list != null && list.Length > 0)
  572. return list;
  573. return new string [] {LongDatePattern + " " + LongTimePattern};
  574. case 'f':
  575. list = PopulateCombinedList (_LongDatePatterns, _ShortTimePatterns);
  576. if (list != null && list.Length > 0)
  577. return list;
  578. return new string [] {LongDatePattern + " " + ShortTimePattern};
  579. // MonthDay
  580. case 'm':
  581. case 'M':
  582. if (_MonthDayPatterns != null && _MonthDayPatterns.Length > 0)
  583. return _MonthDayPatterns.Clone () as string [];
  584. return new string [] {MonthDayPattern};
  585. // YearMonth
  586. case 'Y':
  587. case 'y':
  588. if (_YearMonthPatterns != null && _YearMonthPatterns.Length > 0)
  589. return _YearMonthPatterns.Clone () as string [];
  590. return new string [] {YearMonthPattern};
  591. // RFC1123
  592. case 'r':
  593. case 'R':
  594. return new string [] {RFC1123Pattern};
  595. case 's':
  596. return new string [] {SortableDateTimePattern};
  597. case 'u':
  598. return new string [] {UniversalSortableDateTimePattern};
  599. }
  600. throw new ArgumentException ("Format specifier was invalid.");
  601. }
  602. // LAMESPEC: this is not in ECMA specs
  603. public string GetDayName(DayOfWeek dayofweek)
  604. {
  605. int index = (int) dayofweek;
  606. if (index < 0 || index > 6) throw new ArgumentOutOfRangeException();
  607. return _DayNames[index];
  608. }
  609. // LAMESPEC: this is not in ECMA specs
  610. public string GetAbbreviatedDayName(DayOfWeek dayofweek)
  611. {
  612. int index = (int) dayofweek;
  613. if (index < 0 || index > 6) throw new ArgumentOutOfRangeException();
  614. return _AbbreviatedDayNames[index];
  615. }
  616. private void FillInvariantPatterns ()
  617. {
  618. _ShortDatePatterns = new string [] {"MM/dd/yyyy"};
  619. _LongDatePatterns = new string [] {"dddd, dd MMMM yyyy"};
  620. _LongTimePatterns = new string [] {"HH:mm:ss"};
  621. _ShortTimePatterns = new string [] {
  622. "HH:mm",
  623. "hh:mm tt",
  624. "H:mm",
  625. "h:mm tt"
  626. };
  627. _MonthDayPatterns = new string [] {"MMMM dd"};
  628. _YearMonthPatterns = new string [] {"yyyy MMMM"};
  629. }
  630. private string [] PopulateCombinedList (string [] dates, string [] times)
  631. {
  632. if (dates != null && times != null) {
  633. string [] list = new string [dates.Length * times.Length];
  634. int i = 0;
  635. foreach (string d in dates)
  636. foreach (string t in times)
  637. list [i++] = d + " " + t;
  638. return list;
  639. }
  640. return null;
  641. }
  642. }
  643. }