We need you! We're working hard on the next version of Developer Fusion -
Let us know what you think we should be up to!
- namespace System.Globalization
- {
- using System;
- using System.Security;
- using System.Threading;
- using System.Collections;
- using System.Runtime.Serialization;
- using System.Security.Permissions;
- using System.Runtime.InteropServices;
- using System.Text;
-
-
-
-
-
-
-
-
-
- [Flags()]
- internal enum MonthNameStyles
- {
- Regular = 0,
- Genitive = 1,
- LeapYear = 2
- }
-
-
-
-
-
-
-
-
-
-
- [Flags()]
- internal enum DateTimeFormatFlags
- {
- None = 0,
- UseGenitiveMonth = 1,
- UseLeapYearMonth = 2,
- UseSpacesInMonthNames = 4,
-
- UseHebrewRule = 8,
-
- UseSpacesInDayNames = 16,
-
- UseDigitPrefixInTokens = 32,
-
- NotInitialized = -1
- }
-
-
- [Serializable()]
- [System.Runtime.InteropServices.ComVisible(true)]
- public sealed class DateTimeFormatInfo : ICloneable, IFormatProvider
- {
-
-
-
- private static DateTimeFormatInfo invariantInfo;
-
-
- [NonSerialized()]
- internal CultureTableRecord m_cultureTableRecord;
-
-
- [OptionalField(VersionAdded = 2)]
- internal string m_name = null;
-
-
- [NonSerialized()]
- internal string m_langName = null;
-
-
- [NonSerialized()]
- internal CompareInfo m_compareInfo = null;
-
-
-
- internal bool m_isDefaultCalendar;
-
- internal int CultureId {
- get { return this.m_cultureTableRecord.CultureID; }
- }
-
-
-
-
-
-
- internal bool bUseCalendarInfo = false;
-
-
-
-
- internal string amDesignator = null;
- internal string pmDesignator = null;
- internal string dateSeparator = null;
- internal string longTimePattern = null;
- internal string shortTimePattern = null;
- internal string generalShortTimePattern = null;
- internal string generalLongTimePattern = null;
- internal string timeSeparator = null;
- internal string monthDayPattern = null;
-
-
-
-
- internal string[] allShortTimePatterns = null;
- internal string[] allLongTimePatterns = null;
-
-
-
-
- internal const string rfc1123Pattern = "ddd, dd MMM yyyy HH':'mm':'ss 'GMT'";
-
- internal const string sortableDateTimePattern = "yyyy'-'MM'-'dd'T'HH':'mm':'ss";
- internal const string universalSortableDateTimePattern = "yyyy'-'MM'-'dd HH':'mm':'ss'Z'";
-
-
-
-
- internal Calendar calendar = null;
-
- internal int firstDayOfWeek = -1;
- internal int calendarWeekRule = -1;
-
- internal string fullDateTimePattern = null;
-
- internal string longDatePattern = null;
-
- internal string shortDatePattern = null;
-
- internal string yearMonthPattern = null;
-
- internal string[] abbreviatedDayNames = null;
-
- [OptionalField(VersionAdded = 2)]
- internal string[] m_superShortDayNames = null;
-
- internal string[] dayNames = null;
- internal string[] abbreviatedMonthNames = null;
- internal string[] monthNames = null;
-
- [OptionalField(VersionAdded = 2)]
- internal string[] genitiveMonthNames = null;
-
-
- [OptionalField(VersionAdded = 2)]
- internal string[] m_genitiveAbbreviatedMonthNames = null;
-
-
- [OptionalField(VersionAdded = 2)]
- internal string[] leapYearMonthNames = null;
-
-
-
-
-
- [NonSerialized()]
-
- internal string[] allYearMonthPatterns = null;
- internal string[] allShortDatePatterns = null;
- internal string[] allLongDatePatterns = null;
-
-
-
-
- internal string[] m_eraNames = null;
- internal string[] m_abbrevEraNames = null;
- internal string[] m_abbrevEnglishEraNames = null;
-
- internal string[] m_dateWords = null;
-
- internal int[] optionalCalendars = null;
-
- private const int DEFAULT_ALL_DATETIMES_SIZE = 132;
-
- internal bool m_isReadOnly = false;
-
-
- [OptionalField(VersionAdded = 2)]
- internal DateTimeFormatFlags formatFlags = DateTimeFormatFlags.NotInitialized;
-
- private static Hashtable m_calendarNativeNames;
-
- private static object s_InternalSyncObject;
-
- private static object InternalSyncObject {
- get {
- if (s_InternalSyncObject == null) {
- object o = new object();
- Interlocked.CompareExchange(ref s_InternalSyncObject, o, null);
- }
- return s_InternalSyncObject;
- }
- }
-
- internal string CultureName {
- get {
- if (m_name == null) {
- m_name = this.m_cultureTableRecord.SNAME;
- }
- return (m_name);
- }
- }
-
- internal string LanguageName {
- get {
- if (m_langName == null) {
- m_langName = this.m_cultureTableRecord.SISO639LANGNAME;
- }
- return (m_langName);
- }
- }
-
- ////////////////////////////////////////////////////////////////////////////
-
-
-
- ////////////////////////////////////////////////////////////////////////////
-
- private string[] GetAbbreviatedDayOfWeekNames()
- {
- if (abbreviatedDayNames == null) {
- if (abbreviatedDayNames == null) {
- string[] temp = null;
- if (!m_isDefaultCalendar) {
- BCLDebug.Assert(Calendar.ID > 0, "[DateTimeFormatInfo.GetAbbreviatedDayOfWeekNames] Expected Calendar.ID > 0");
- temp = CalendarTable.Default.SABBREVDAYNAMES(Calendar.ID);
- }
- if (temp == null || temp.Length == 0 || temp[0].Length == 0)
- temp = this.m_cultureTableRecord.SABBREVDAYNAMES;
- System.Threading.Thread.MemoryBarrier();
- abbreviatedDayNames = temp;
- BCLDebug.Assert(abbreviatedDayNames.Length == 7, "[DateTimeFormatInfo.GetAbbreviatedDayOfWeekNames] Expected 7 day names in a week");
- }
- }
- return (abbreviatedDayNames);
- }
-
- ////////////////////////////////////////////////////////////////////////
-
-
-
-
-
-
-
-
-
- ////////////////////////////////////////////////////////////////////////
-
- private string[] internalGetSuperShortDayNames()
- {
- if (this.m_superShortDayNames == null) {
- if (this.m_superShortDayNames == null) {
- string[] temp = null;
- if (!m_isDefaultCalendar) {
- BCLDebug.Assert(Calendar.ID > 0, "[DateTimeFormatInfo.internalGetSuperShortDayNames] Expected Calendar.ID > 0");
- temp = CalendarTable.Default.SSUPERSHORTDAYNAMES(Calendar.ID);
- }
- if (temp == null || temp.Length == 0 || temp[0].Length == 0)
- temp = this.m_cultureTableRecord.SSUPERSHORTDAYNAMES;
- System.Threading.Thread.MemoryBarrier();
- this.m_superShortDayNames = temp;
- BCLDebug.Assert(this.m_superShortDayNames.Length == 7, "[DateTimeFormatInfo.internalGetSuperShortDayNames] Expected 7 day names in a week");
- }
- }
- return (this.m_superShortDayNames);
- }
-
- ////////////////////////////////////////////////////////////////////////////
-
-
-
- ////////////////////////////////////////////////////////////////////////////
-
- private string[] GetDayOfWeekNames()
- {
- if (dayNames == null) {
- if (dayNames == null) {
- string[] temp = null;
- if (!m_isDefaultCalendar) {
- BCLDebug.Assert(Calendar.ID > 0, "[DateTimeFormatInfo.GetDayOfWeekNames] Expected Calendar.ID > 0");
- temp = CalendarTable.Default.SDAYNAMES(Calendar.ID);
- }
- if (temp == null || temp.Length == 0 || temp[0].Length == 0)
- temp = this.m_cultureTableRecord.SDAYNAMES;
- System.Threading.Thread.MemoryBarrier();
- dayNames = temp;
- BCLDebug.Assert(dayNames.Length == 7, "[DateTimeFormatInfo.GetDayOfWeekNames] Expected 7 day names in a week");
- }
- }
- return (dayNames);
- }
-
- ////////////////////////////////////////////////////////////////////////////
-
-
-
- ////////////////////////////////////////////////////////////////////////////
-
- private string[] GetAbbreviatedMonthNames()
- {
- if (abbreviatedMonthNames == null) {
- if (abbreviatedMonthNames == null) {
- string[] temp = null;
- if (!m_isDefaultCalendar) {
- BCLDebug.Assert(Calendar.ID > 0, "[DateTimeFormatInfo.GetAbbreviatedMonthNames] Expected Calendar.ID > 0");
- temp = CalendarTable.Default.SABBREVMONTHNAMES(Calendar.ID);
- }
- if (temp == null || temp.Length == 0 || temp[0].Length == 0)
- temp = this.m_cultureTableRecord.SABBREVMONTHNAMES;
- System.Threading.Thread.MemoryBarrier();
- abbreviatedMonthNames = temp;
- BCLDebug.Assert(abbreviatedMonthNames.Length == 12 || abbreviatedMonthNames.Length == 13, "[DateTimeFormatInfo.GetAbbreviatedMonthNames] Expected 12 or 13 month names in a year");
- }
- }
- return (abbreviatedMonthNames);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////
-
-
-
- ////////////////////////////////////////////////////////////////////////////
-
- private string[] GetMonthNames()
- {
- if (monthNames == null) {
- string[] temp = null;
- if (!m_isDefaultCalendar) {
- BCLDebug.Assert(Calendar.ID > 0, "[DateTimeFormatInfo.GetMonthNames] Expected Calendar.ID > 0");
- temp = CalendarTable.Default.SMONTHNAMES(Calendar.ID);
- }
- if (temp == null || temp.Length == 0 || temp[0].Length == 0)
- temp = this.m_cultureTableRecord.SMONTHNAMES;
- System.Threading.Thread.MemoryBarrier();
- monthNames = temp;
- BCLDebug.Assert(MonthNames.Length == 12 || MonthNames.Length == 13, "[DateTimeFormatInfo.GetMonthNames] Expected 12 or 13 month names in a year");
- }
-
- return (monthNames);
- }
-
-
- public DateTimeFormatInfo()
- {
-
-
-
- this.m_cultureTableRecord = CultureInfo.InvariantCulture.m_cultureTableRecord;
-
-
- this.m_isDefaultCalendar = true;
- this.calendar = GregorianCalendar.GetDefaultInstance();
-
-
-
- InitializeOverridableProperties();
- }
-
- internal DateTimeFormatInfo(CultureTableRecord cultureTable, int cultureID, Calendar cal)
- {
- this.m_cultureTableRecord = cultureTable;
-
- this.Calendar = cal;
- }
-
- #region Serialization
-
- private int CultureID;
- private bool m_useUserOverride;
- private int nDataItem;
-
- [OnDeserialized()]
- private void OnDeserialized(StreamingContext ctx)
- {
- BCLDebug.Assert(CultureID >= 0, "[DateTimeFormatInfo.OnDeserialized] clulture ID < 0");
-
- if (CultureTableRecord.IsCustomCultureId(CultureID))
- m_cultureTableRecord = CultureTableRecord.GetCultureTableRecord(m_name, m_useUserOverride);
- else
- m_cultureTableRecord = CultureTableRecord.GetCultureTableRecord(CultureID, m_useUserOverride);
-
- if (calendar == null) {
- calendar = (Calendar)GregorianCalendar.GetDefaultInstance().Clone();
- calendar.SetReadOnlyState(m_isReadOnly);
- }
- else {
- CultureInfo.CheckDomainSafetyObject(calendar, this);
- }
-
- InitializeOverridableProperties();
- }
-
- [OnSerializing()]
- private void OnSerializing(StreamingContext ctx)
- {
- CultureID = m_cultureTableRecord.CultureID;
- m_useUserOverride = m_cultureTableRecord.UseUserOverride;
- nDataItem = m_cultureTableRecord.EverettDataItem();
-
-
-
-
-
-
- if (CultureTableRecord.IsCustomCultureId(CultureID)) {
-
- m_name = this.CultureName;
- }
- }
- #endregion Serialization
-
-
-
-
-
-
- public static DateTimeFormatInfo InvariantInfo {
- get {
- if (invariantInfo == null) {
- DateTimeFormatInfo info = new DateTimeFormatInfo();
- info.Calendar.SetReadOnlyState(true);
- info.m_isReadOnly = true;
- invariantInfo = info;
- }
- return (invariantInfo);
- }
- }
-
-
-
-
- public static DateTimeFormatInfo CurrentInfo {
- get {
- System.Globalization.CultureInfo culture = System.Threading.Thread.CurrentThread.CurrentCulture;
- if (!culture.m_isInherited) {
- DateTimeFormatInfo info = culture.dateTimeInfo;
- if (info != null) {
- return info;
- }
- }
- return (DateTimeFormatInfo)culture.GetFormat(typeof(DateTimeFormatInfo));
- }
- }
-
-
- public static DateTimeFormatInfo GetInstance(IFormatProvider provider)
- {
-
- DateTimeFormatInfo info;
- CultureInfo cultureProvider = provider as CultureInfo;
- if (cultureProvider != null && !cultureProvider.m_isInherited) {
- info = cultureProvider.dateTimeInfo;
- if (info != null) {
- return info;
- }
- else {
- return cultureProvider.DateTimeFormat;
- }
- }
-
- info = provider as DateTimeFormatInfo;
- if (info != null) {
- return info;
- }
- if (provider != null) {
- info = provider.GetFormat(typeof(DateTimeFormatInfo)) as DateTimeFormatInfo;
- if (info != null) {
- return info;
- }
- }
- return CurrentInfo;
- }
-
-
- public object GetFormat(Type formatType)
- {
- return (formatType == typeof(DateTimeFormatInfo) ? this : null);
- }
-
-
- public object Clone()
- {
- DateTimeFormatInfo n = (DateTimeFormatInfo)MemberwiseClone();
-
-
- n.calendar = (Calendar)this.Calendar.Clone();
- n.m_isReadOnly = false;
- return n;
- }
-
-
- public string AMDesignator {
- get {
- BCLDebug.Assert(amDesignator != null, "DateTimeFormatInfo.AMDesignator, amDesignator != null");
- return (amDesignator);
- }
-
- set {
- VerifyWritable();
- if (value == null) {
- throw new ArgumentNullException("value", Environment.GetResourceString("ArgumentNull_String"));
- }
- ClearTokenHashTable(true);
- amDesignator = value;
- }
- }
-
- private void InitializeOverridableProperties()
- {
-
-
- if (amDesignator == null) {
- amDesignator = m_cultureTableRecord.S1159;
- }
- if (pmDesignator == null) {
- pmDesignator = m_cultureTableRecord.S2359;
- }
- if (longTimePattern == null) {
- longTimePattern = m_cultureTableRecord.STIMEFORMAT;
- }
- if (firstDayOfWeek == -1) {
- firstDayOfWeek = m_cultureTableRecord.IFIRSTDAYOFWEEK;
- }
- if (calendarWeekRule == -1) {
- calendarWeekRule = m_cultureTableRecord.IFIRSTWEEKOFYEAR;
- }
-
-
- if (yearMonthPattern == null) {
- yearMonthPattern = GetYearMonthPattern(calendar.ID);
- }
- if (shortDatePattern == null) {
- shortDatePattern = GetShortDatePattern(calendar.ID);
- }
- if (longDatePattern == null) {
- longDatePattern = GetLongDatePattern(calendar.ID);
- }
- }
-
-
- public Calendar Calendar {
- get {
- BCLDebug.Assert(calendar != null, "DateTimeFormatInfo.Calendar: calendar != null");
- return (calendar);
- }
-
- set {
- VerifyWritable();
- if (value == null) {
- throw new ArgumentNullException("value", Environment.GetResourceString("ArgumentNull_Obj"));
- }
- if (value == calendar) {
- return;
- }
-
-
-
-
-
- CultureInfo.CheckDomainSafetyObject(value, this);
-
- for (int i = 0; i < OptionalCalendars.Length; i++) {
- if (OptionalCalendars[i] == value.ID) {
- ClearTokenHashTable(false);
-
-
-
- m_isDefaultCalendar = (value.ID == Calendar.CAL_GREGORIAN);
-
-
-
- if (calendar != null) {
-
-
-
-
-
- m_eraNames = null;
- m_abbrevEraNames = null;
- m_abbrevEnglishEraNames = null;
-
- shortDatePattern = null;
- yearMonthPattern = null;
- monthDayPattern = null;
- longDatePattern = null;
-
- dayNames = null;
- abbreviatedDayNames = null;
- m_superShortDayNames = null;
- monthNames = null;
- abbreviatedMonthNames = null;
- genitiveMonthNames = null;
- m_genitiveAbbreviatedMonthNames = null;
- leapYearMonthNames = null;
- formatFlags = DateTimeFormatFlags.NotInitialized;
-
-
- fullDateTimePattern = null;
- generalShortTimePattern = null;
- generalLongTimePattern = null;
- allShortDatePatterns = null;
- allLongDatePatterns = null;
- allYearMonthPatterns = null;
-
-
- }
-
- calendar = value;
-
- if (this.m_cultureTableRecord.UseCurrentCalendar(value.ID)) {
-
-
-
-
-
-
-
- DTFIUserOverrideValues temp = new DTFIUserOverrideValues();
-
-
-
-
-
-
- m_cultureTableRecord.GetDTFIOverrideValues(ref temp);
-
-
- amDesignator = temp.amDesignator;
- pmDesignator = temp.pmDesignator;
- longTimePattern = temp.longTimePattern;
- firstDayOfWeek = (int)temp.firstDayOfWeek;
- calendarWeekRule = (int)temp.calendarWeekRule;
- shortDatePattern = temp.shortDatePattern;
- longDatePattern = temp.longDatePattern;
- yearMonthPattern = temp.yearMonthPattern;
-
-
-
-
-
-
-
- if (yearMonthPattern == null || yearMonthPattern.Length == 0) {
- yearMonthPattern = GetYearMonthPattern(value.ID);
- }
-
- }
- else {
-
-
- InitializeOverridableProperties();
- }
- return;
- }
- }
-
- throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("Argument_InvalidCalendar"));
- }
- }
-
- internal int[] OptionalCalendars {
- get {
- if (optionalCalendars == null) {
- optionalCalendars = this.m_cultureTableRecord.IOPTIONALCALENDARS;
- }
- return (optionalCalendars);
- }
- }
-
-
-
-
- public int GetEra(string eraName)
- {
- if (eraName == null) {
- throw new ArgumentNullException("eraName", Environment.GetResourceString("ArgumentNull_String"));
- }
-
-
-
-
-
-
-
- for (int i = 0; i < EraNames.Length; i++) {
-
- if (m_eraNames[i].Length > 0) {
- if (String.Compare(eraName, m_eraNames[i], true, CultureInfo.CurrentCulture) == 0) {
- return (i + 1);
- }
- }
- }
- for (int i = 0; i < AbbreviatedEraNames.Length; i++) {
- if (String.Compare(eraName, m_abbrevEraNames[i], true, CultureInfo.CurrentCulture) == 0) {
- return (i + 1);
- }
- }
- for (int i = 0; i < AbbreviatedEnglishEraNames.Length; i++) {
-
-
- if (String.Compare(eraName, m_abbrevEnglishEraNames[i], true, CultureInfo.InvariantCulture) == 0) {
- return (i + 1);
- }
- }
- return (-1);
- }
-
- internal string[] EraNames {
- get {
- if (m_eraNames == null) {
- if (Calendar.ID == Calendar.CAL_GREGORIAN) {
-
-
- m_eraNames = new string[1] {this.m_cultureTableRecord.SADERA};
- }
- else if (Calendar.ID != Calendar.CAL_TAIWAN) {
-
- BCLDebug.Assert(Calendar.ID > 0, "[DateTimeFormatInfo.EraNames] Expected Calendar.ID > 0");
- m_eraNames = CalendarTable.Default.SERANAMES(Calendar.ID);
- }
- else {
-
-
- m_eraNames = new string[] {CalendarTable.nativeGetEraName(1028, Calendar.ID)};
- }
- }
- return (m_eraNames);
- }
- }
-
-
-
-
- public string GetEraName(int era)
- {
- if (era == Calendar.CurrentEra) {
- era = Calendar.CurrentEraValue;
- }
-
-
-
-
- if ((--era) < EraNames.Length && (era >= 0)) {
- return (m_eraNames[era]);
- }
- throw new ArgumentOutOfRangeException("era", Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue"));
- }
-
- internal string[] AbbreviatedEraNames {
- get {
- if (m_abbrevEraNames == null) {
- if (Calendar.ID == Calendar.CAL_TAIWAN) {
-