/// <include file='doc\CultureInfo.uex' path='docs/doc[@for="CultureInfo.Clone"]/*' /> public virtual Object Clone() { CultureInfo ci = (CultureInfo)MemberwiseClone(); //If this is exactly our type, we can make certain optimizations so that we don't allocate NumberFormatInfo or DTFI unless //they've already been allocated. If this is a derived type, we'll take a more generic codepath. if (ci.GetType() == typeof(CultureInfo)) { if (dateTimeInfo != null) { ci.dateTimeInfo = (DateTimeFormatInfo)dateTimeInfo.Clone(); } if (numInfo != null) { ci.numInfo = (NumberFormatInfo)numInfo.Clone(); } ci.m_isReadOnly = false; } else { ci.m_isReadOnly = false; ci.DateTimeFormat = (DateTimeFormatInfo)this.DateTimeFormat.Clone(); ci.NumberFormat = (NumberFormatInfo)this.NumberFormat.Clone(); } return(ci); }
public void Clone(DateTimeFormatInfo format) { DateTimeFormatInfo clone = (DateTimeFormatInfo)format.Clone(); Assert.NotSame(format, clone); Assert.False(clone.IsReadOnly); Assert.Equal(format.AbbreviatedDayNames, clone.AbbreviatedDayNames); Assert.Equal(format.AbbreviatedMonthGenitiveNames, clone.AbbreviatedMonthGenitiveNames); Assert.Equal(format.AbbreviatedMonthNames, clone.AbbreviatedMonthNames); Assert.Equal(format.DayNames, clone.DayNames); Assert.Equal(format.MonthGenitiveNames, clone.MonthGenitiveNames); Assert.Equal(format.MonthNames, clone.MonthNames); Assert.Equal(format.ShortestDayNames, clone.ShortestDayNames); Assert.Equal(format.AMDesignator, clone.AMDesignator); Assert.Equal(format.FullDateTimePattern, clone.FullDateTimePattern); Assert.Equal(format.LongDatePattern, clone.LongDatePattern); Assert.Equal(format.LongTimePattern, clone.LongTimePattern); Assert.Equal(format.MonthDayPattern, clone.MonthDayPattern); Assert.Equal(format.PMDesignator, clone.PMDesignator); Assert.Equal(format.RFC1123Pattern, clone.RFC1123Pattern); Assert.Equal(format.ShortDatePattern, clone.ShortDatePattern); Assert.Equal(format.ShortTimePattern, clone.ShortTimePattern); Assert.Equal(format.SortableDateTimePattern, clone.SortableDateTimePattern); Assert.Equal(format.UniversalSortableDateTimePattern, clone.UniversalSortableDateTimePattern); Assert.Equal(format.YearMonthPattern, clone.YearMonthPattern); Assert.Equal(format.CalendarWeekRule, clone.CalendarWeekRule); Assert.Equal(format.FirstDayOfWeek, clone.FirstDayOfWeek); }
public static DateTimeFormatInfo ReadOnly(DateTimeFormatInfo dtfi) { DateTimeFormatInfo copy = (DateTimeFormatInfo)dtfi.Clone(); copy.m_isReadOnly = true; return(copy); }
private void ConstructInvariant(bool read_only) { cultureID = InvariantCultureId; /* NumberFormatInfo defaults to the invariant data */ numInfo = NumberFormatInfo.InvariantInfo; /* DateTimeFormatInfo defaults to the invariant data */ dateTimeInfo = DateTimeFormatInfo.InvariantInfo; if (!read_only) { numInfo = (NumberFormatInfo)numInfo.Clone(); dateTimeInfo = (DateTimeFormatInfo)dateTimeInfo.Clone(); } textInfo = CreateTextInfo(read_only); m_name = String.Empty; displayname = englishname = nativename = "Invariant Language (Invariant Country)"; iso3lang = "IVL"; iso2lang = "iv"; icu_name = "en_US_POSIX"; win3lang = "IVL"; }
private static string ExpandPredefinedFormat(string format, ref DateTime dateTime, ref DateTimeFormatInfo dtfi, ref TimeSpan offset) { switch (format[0]) { case 'o': case 'O': dtfi = DateTimeFormatInfo.InvariantInfo; goto Label_0160; case 'r': case 'R': if (offset != NullOffset) { dateTime -= offset; } else if (dateTime.Kind == DateTimeKind.Local) { InvalidFormatForLocal(format, dateTime); } dtfi = DateTimeFormatInfo.InvariantInfo; goto Label_0160; case 's': dtfi = DateTimeFormatInfo.InvariantInfo; goto Label_0160; case 'u': if (offset == NullOffset) { if (dateTime.Kind == DateTimeKind.Local) { InvalidFormatForLocal(format, dateTime); } break; } dateTime -= offset; break; case 'U': if (offset != NullOffset) { throw new FormatException(Environment.GetResourceString("Format_InvalidString")); } dtfi = (DateTimeFormatInfo) dtfi.Clone(); if (dtfi.Calendar.GetType() != typeof(GregorianCalendar)) { dtfi.Calendar = GregorianCalendar.GetDefaultInstance(); } dateTime = dateTime.ToUniversalTime(); goto Label_0160; default: goto Label_0160; } dtfi = DateTimeFormatInfo.InvariantInfo; Label_0160: format = GetRealFormat(format, dtfi); return format; }
// Create a read-only copy of a DateTimeFormatInfo object. public static DateTimeFormatInfo ReadOnly(DateTimeFormatInfo dtfi) { if (dtfi == null) { throw new ArgumentNullException("dtfi"); } else if (dtfi.IsReadOnly) { return(dtfi); } else { DateTimeFormatInfo newDtfi; newDtfi = (DateTimeFormatInfo)(dtfi.Clone()); newDtfi.readOnly = true; return(newDtfi); } }
// Implementation of the ICloneable interface. public virtual Object Clone() { #if !ECMA_COMPAT CultureInfo culture = (CultureInfo)(MemberwiseClone()); culture.readOnly = false; // clone DateTimeFormat and NumberFormat if available if (dateTimeFormat != null) { culture.dateTimeFormat = (DateTimeFormatInfo)dateTimeFormat.Clone(); } if (numberFormat != null) { culture.numberFormat = (NumberFormatInfo)numberFormat.Clone(); } return(culture); #else return(MemberwiseClone()); #endif }
private void ConstructInvariant() { m_lcid = InvariantCultureId; /* NumberFormatInfo defaults to the invariant data */ m_numInfo = NumberFormatInfo.InvariantInfo; /* DateTimeFormatInfo defaults to the invariant data */ m_dateTimeInfo = DateTimeFormatInfo.InvariantInfo; if (!m_isReadOnly) { m_numInfo = (NumberFormatInfo)m_numInfo.Clone(); m_dateTimeInfo = (DateTimeFormatInfo)m_dateTimeInfo.Clone(); } m_textInfo = new TextInfo(this, InvariantCultureId); m_name = ""; m_displayName = m_englishName = m_nativeName = "Invariant Language (Invariant Country)"; m_iso3lang = "IVL"; m_iso2lang = "iv"; m_icuName = "en_US_POSIX"; m_win3lang = "IVL"; }
// Expand a pre-defined format string (like "D" for long date) to the real format that // we are going to use in the date time parsing. // This method also set the dtfi according/parseInfo to some special pre-defined // formats. // private static String ExpandPredefinedFormat(String format, ref DateTimeFormatInfo dtfi, ref ParsingInfo parseInfo, ref DateTimeResult result) { // // Check the format to see if we need to override the dtfi to be InvariantInfo, // and see if we need to set up the userUniversalTime flag. // switch (format[0]) { case 'o': case 'O': // Round Trip Format parseInfo.calendar = GregorianCalendar.GetDefaultInstance(); dtfi = DateTimeFormatInfo.InvariantInfo; break; case 'r': case 'R': // RFC 1123 Standard. (in Universal time) parseInfo.calendar = GregorianCalendar.GetDefaultInstance(); dtfi = DateTimeFormatInfo.InvariantInfo; if ((result.flags & ParseFlags.CaptureOffset) != 0) { result.flags |= ParseFlags.Rfc1123Pattern; } break; case 's': // Sortable format (in local time) dtfi = DateTimeFormatInfo.InvariantInfo; parseInfo.calendar = GregorianCalendar.GetDefaultInstance(); break; case 'u': // Universal time format in sortable format. parseInfo.calendar = GregorianCalendar.GetDefaultInstance(); dtfi = DateTimeFormatInfo.InvariantInfo; if ((result.flags & ParseFlags.CaptureOffset) != 0) { result.flags |= ParseFlags.UtcSortPattern; } break; case 'U': // Universal time format with culture-dependent format. parseInfo.calendar = GregorianCalendar.GetDefaultInstance(); result.flags |= ParseFlags.TimeZoneUsed; result.timeZoneOffset = new TimeSpan(0); result.flags |= ParseFlags.TimeZoneUtc; if (dtfi.Calendar.GetType() != typeof(GregorianCalendar)) { dtfi = (DateTimeFormatInfo)dtfi.Clone(); dtfi.Calendar = GregorianCalendar.GetDefaultInstance(); } break; } // // Expand the pre-defined format character to the real format from DateTimeFormatInfo. // return (DateTimeFormat.GetRealFormat(format, dtfi)); }
// Expand a pre-defined format string (like "D" for long date) to the real format that // we are going to use in the date time parsing. // This method also set the dtfi according/parseInfo to some special pre-defined // formats. // private static String ExpandPredefinedFormat(String format, ref DateTimeFormatInfo dtfi, ParsingInfo parseInfo) { // // Check the format to see if we need to override the dtfi to be InvariantInfo, // and see if we need to set up the userUniversalTime flag. // switch (format[0]) { case 'r': case 'R': // RFC 1123 Standard. (in Universal time) parseInfo.calendar = GregorianCalendar.GetDefaultInstance(); dtfi = DateTimeFormatInfo.InvariantInfo; break; case 's': // Sortable format (in local time) dtfi = DateTimeFormatInfo.InvariantInfo; parseInfo.calendar = GregorianCalendar.GetDefaultInstance(); break; case 'u': // Universal time format in sortable format. parseInfo.calendar = GregorianCalendar.GetDefaultInstance(); dtfi = DateTimeFormatInfo.InvariantInfo; break; case 'U': // Universal time format with culture-dependent format. parseInfo.calendar = GregorianCalendar.GetDefaultInstance(); parseInfo.fUseUniversalTime = true; if (dtfi.Calendar.GetType() != typeof(GregorianCalendar)) { dtfi = (DateTimeFormatInfo)dtfi.Clone(); dtfi.Calendar = GregorianCalendar.GetDefaultInstance(); } break; } // // Expand the pre-defined format character to the real format from DateTimeFormatInfo. // return (DateTimeFormat.GetRealFormat(format, dtfi)); }
// Expand a pre-defined format string (like "D" for long date) to the real format that // we are going to use in the date time parsing. // This method also convert the dateTime if necessary (e.g. when the format is in Universal time), // and change dtfi if necessary (e.g. when the format should use invariant culture). // private static String ExpandPredefinedFormat(String format, ref DateTime dateTime, ref DateTimeFormatInfo dtfi, ref TimeSpan offset) { switch (format[0]) { case 'o': case 'O': // Round trip format dtfi = DateTimeFormatInfo.InvariantInfo; break; case 'r': case 'R': // RFC 1123 Standard if (offset != NullOffset) { // Convert to UTC invariants mean this will be in range dateTime = dateTime - offset; } else if (dateTime.Kind == DateTimeKind.Local) { InvalidFormatForLocal(format, dateTime); } dtfi = DateTimeFormatInfo.InvariantInfo; break; case 's': // Sortable without Time Zone Info dtfi = DateTimeFormatInfo.InvariantInfo; break; case 'u': // Universal time in sortable format. if (offset != NullOffset) { // Convert to UTC invariants mean this will be in range dateTime = dateTime - offset; } else if (dateTime.Kind == DateTimeKind.Local) { InvalidFormatForLocal(format, dateTime); } dtfi = DateTimeFormatInfo.InvariantInfo; break; case 'U': // Universal time in culture dependent format. if (offset != NullOffset) { // This format is not supported by DateTimeOffset throw new FormatException(Environment.GetResourceString("Format_InvalidString")); } // Universal time is always in Greogrian calendar. // // Change the Calendar to be Gregorian Calendar. // dtfi = (DateTimeFormatInfo)dtfi.Clone(); if (dtfi.Calendar.GetType() != typeof(GregorianCalendar)) { dtfi.Calendar = GregorianCalendar.GetDefaultInstance(); } dateTime = dateTime.ToUniversalTime(); break; } format = GetRealFormat(format, dtfi); return (format); }
public static DateTimeFormatInfo ReadOnly(DateTimeFormatInfo dtfi) { DateTimeFormatInfo copy = (DateTimeFormatInfo)dtfi.Clone(); copy.m_isReadOnly = true; return copy; }
// Expand a pre-defined format string (like "D" for long date) to the real format that // we are going to use in the date time parsing. // This method also convert the dateTime if necessary (e.g. when the format is in Universal time), // and change dtfi if necessary (e.g. when the format should use invariant culture). // private static String ExpandPredefinedFormat(String format, ref DateTime dateTime, ref DateTimeFormatInfo dtfi) { switch (format[0]) { case 'o': case 'O': // Round trip format dtfi = DateTimeFormatInfo.InvariantInfo; break; case 'r': case 'R': // RFC 1123 Standard if (dateTime.Kind == DateTimeKind.Local) { InvalidFormatForLocal(format, dateTime); } dtfi = DateTimeFormatInfo.InvariantInfo; break; case 's': // Sortable without Time Zone Info dtfi = DateTimeFormatInfo.InvariantInfo; break; case 'u': // Universal time in sortable format. if (dateTime.Kind == DateTimeKind.Local) { InvalidFormatForLocal(format, dateTime); } dtfi = DateTimeFormatInfo.InvariantInfo; break; case 'U': // Universal time in culture dependent format. // Universal time is always in Greogrian calendar. // // Change the Calendar to be Gregorian Calendar. // dtfi = (DateTimeFormatInfo)dtfi.Clone(); if (dtfi.Calendar.GetType() != typeof(GregorianCalendar)) { dtfi.Calendar = GregorianCalendar.GetDefaultInstance(); } dateTime = dateTime.ToUniversalTime(); break; } format = GetRealFormat(format, dtfi); return (format); }
internal static DateTimeFormatInfo Build(DateTimeFormatInfo original) { var persianFormats = (DateTimeFormatInfo)original.Clone(); var persianCalendarMonthNames = new[] { "فررودین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند", "" // 13 months names always necessary... }; persianFormats.MonthNames = persianFormats.AbbreviatedMonthNames = persianFormats.MonthGenitiveNames = persianFormats.AbbreviatedMonthGenitiveNames = persianCalendarMonthNames; var persianDayNames = new[] { "یکشنبه", // Changes the Arabic "ي" and "ك" to the Farsi "ی" and "ک" respectively (incorrect in .NET Framework). "دوشنبه", "سه شنبه", "چهارشنبه", "پنجشنبه", "جمعه", "شنبه" }; persianFormats.DayNames = persianFormats.AbbreviatedDayNames = persianDayNames; persianFormats.SetAllDateTimePatterns(new[] { "yyyy/MM/dd", "yy/MM/dd", "yyyy/M/d", "yy/M/d" }, 'd'); persianFormats.SetAllDateTimePatterns(new[] { "dddd، d MMMM yyyy", "d MMMM yyyy" }, 'D'); persianFormats.SetAllDateTimePatterns(new[] { "MMMM yyyy", "MMMM yy" }, 'y'); persianFormats.SetAllDateTimePatterns(new[] { "HH:mm", "H:mm", "hh:mm tt", "h:mm tt" }, 't'); persianFormats.SetAllDateTimePatterns(new[] { "HH:mm:ss", "H:mm:ss", "hh:mm:ss tt", "h:mm:ss tt" }, 'T'); return persianFormats; }
private static string ExpandPredefinedFormat(string format, ref DateTimeFormatInfo dtfi, ref ParsingInfo parseInfo, ref DateTimeResult result) { char c = format[0]; if (c <= 'R') { if (c != 'O') { if (c != 'R') { goto IL_160; } goto IL_65; } } else { if (c != 'U') { switch (c) { case 'o': { break; } case 'p': case 'q': case 't': { goto IL_160; } case 'r': { goto IL_65; } case 's': { dtfi = DateTimeFormatInfo.InvariantInfo; parseInfo.calendar = GregorianCalendar.GetDefaultInstance(); goto IL_160; } case 'u': { parseInfo.calendar = GregorianCalendar.GetDefaultInstance(); dtfi = DateTimeFormatInfo.InvariantInfo; if ((result.flags & ParseFlags.CaptureOffset) != (ParseFlags)0) { result.flags |= ParseFlags.UtcSortPattern; goto IL_160; } goto IL_160; } default: { goto IL_160; } } } else { parseInfo.calendar = GregorianCalendar.GetDefaultInstance(); result.flags |= ParseFlags.TimeZoneUsed; result.timeZoneOffset = new TimeSpan(0L); result.flags |= ParseFlags.TimeZoneUtc; if (dtfi.Calendar.GetType() != typeof(GregorianCalendar)) { dtfi = (DateTimeFormatInfo)dtfi.Clone(); dtfi.Calendar = GregorianCalendar.GetDefaultInstance(); goto IL_160; } goto IL_160; } } parseInfo.calendar = GregorianCalendar.GetDefaultInstance(); dtfi = DateTimeFormatInfo.InvariantInfo; goto IL_160; IL_65: parseInfo.calendar = GregorianCalendar.GetDefaultInstance(); dtfi = DateTimeFormatInfo.InvariantInfo; if ((result.flags & ParseFlags.CaptureOffset) != (ParseFlags)0) { result.flags |= ParseFlags.Rfc1123Pattern; } IL_160: return DateTimeFormat.GetRealFormat(format, dtfi); }
private void ConstructInvariant (bool read_only) { cultureID = InvariantCultureId; /* NumberFormatInfo defaults to the invariant data */ numInfo=NumberFormatInfo.InvariantInfo; /* DateTimeFormatInfo defaults to the invariant data */ dateTimeInfo=DateTimeFormatInfo.InvariantInfo; if (!read_only) { numInfo = (NumberFormatInfo) numInfo.Clone (); dateTimeInfo = (DateTimeFormatInfo) dateTimeInfo.Clone (); } textInfo = CreateTextInfo (read_only); m_name=String.Empty; displayname= englishname= nativename="Invariant Language (Invariant Country)"; iso3lang="IVL"; iso2lang="iv"; icu_name="en_US_POSIX"; win3lang="IVL"; }
private static string ExpandPredefinedFormat(string format, ref DateTimeFormatInfo dtfi, ref ParsingInfo parseInfo, ref DateTimeResult result) { switch (format[0]) { case 'o': case 'O': parseInfo.calendar = GregorianCalendar.GetDefaultInstance(); dtfi = DateTimeFormatInfo.InvariantInfo; break; case 'r': case 'R': parseInfo.calendar = GregorianCalendar.GetDefaultInstance(); dtfi = DateTimeFormatInfo.InvariantInfo; if ((result.flags & ParseFlags.CaptureOffset) != 0) { result.flags |= ParseFlags.Rfc1123Pattern; } break; case 's': dtfi = DateTimeFormatInfo.InvariantInfo; parseInfo.calendar = GregorianCalendar.GetDefaultInstance(); break; case 'u': parseInfo.calendar = GregorianCalendar.GetDefaultInstance(); dtfi = DateTimeFormatInfo.InvariantInfo; if ((result.flags & ParseFlags.CaptureOffset) != 0) { result.flags |= ParseFlags.UtcSortPattern; } break; case 'U': parseInfo.calendar = GregorianCalendar.GetDefaultInstance(); result.flags |= ParseFlags.TimeZoneUsed; result.timeZoneOffset = new TimeSpan(0L); result.flags |= ParseFlags.TimeZoneUtc; if (dtfi.Calendar.GetType() != typeof(GregorianCalendar)) { dtfi = (DateTimeFormatInfo) dtfi.Clone(); dtfi.Calendar = GregorianCalendar.GetDefaultInstance(); } break; } return DateTimeFormat.GetRealFormat(format, dtfi); }
private static string ExpandPredefinedFormat(string format, ref DateTime dateTime, ref DateTimeFormatInfo dtfi, ref TimeSpan offset) { char c = format[0]; if (c <= 'R') { if (c != 'O') { if (c != 'R') { goto IL_160; } goto IL_5A; } } else { if (c != 'U') { switch (c) { case 'o': { break; } case 'p': case 'q': case 't': { goto IL_160; } case 'r': { goto IL_5A; } case 's': { dtfi = DateTimeFormatInfo.InvariantInfo; goto IL_160; } case 'u': { if (offset != DateTimeFormat.NullOffset) { dateTime -= offset; } else { if (dateTime.Kind == DateTimeKind.Local) { DateTimeFormat.InvalidFormatForLocal(format, dateTime); } } dtfi = DateTimeFormatInfo.InvariantInfo; goto IL_160; } default: { goto IL_160; } } } else { if (offset != DateTimeFormat.NullOffset) { throw new FormatException(Environment.GetResourceString("Format_InvalidString")); } dtfi = (DateTimeFormatInfo)dtfi.Clone(); if (dtfi.Calendar.GetType() != typeof(GregorianCalendar)) { dtfi.Calendar = GregorianCalendar.GetDefaultInstance(); } dateTime = dateTime.ToUniversalTime(); goto IL_160; } } dtfi = DateTimeFormatInfo.InvariantInfo; goto IL_160; IL_5A: if (offset != DateTimeFormat.NullOffset) { dateTime -= offset; } else { if (dateTime.Kind == DateTimeKind.Local) { DateTimeFormat.InvalidFormatForLocal(format, dateTime); } } dtfi = DateTimeFormatInfo.InvariantInfo; IL_160: format = DateTimeFormat.GetRealFormat(format, dtfi); return format; }
public void PosTest1() { DateTimeFormatInfo expected = new DateTimeFormatInfo(); VerificationHelper(expected, expected.Clone()); }
// Create a read-only copy of a DateTimeFormatInfo object. public static DateTimeFormatInfo ReadOnly(DateTimeFormatInfo dtfi) { if(dtfi == null) { throw new ArgumentNullException("dtfi"); } else if(dtfi.IsReadOnly) { return dtfi; } else { DateTimeFormatInfo newDtfi; newDtfi = (DateTimeFormatInfo)(dtfi.Clone()); newDtfi.readOnly = true; return newDtfi; } }