diff options
author | Marek Safar <marek.safar@gmail.com> | 2013-03-26 20:23:18 +0400 |
---|---|---|
committer | Marek Safar <marek.safar@gmail.com> | 2013-03-26 22:18:55 +0400 |
commit | 0b62a137ab85ab36bb200c8e1024f4ac391553a6 (patch) | |
tree | cd63ef434d73361be2d97c92071351df34a510d8 /mcs | |
parent | bbc5b610d0337d189bb8e2fd874bf957635bbcef (diff) |
Set invariant DateTimeFormatInfo for all invariant format specifiers. Fixes #11364
Diffstat (limited to 'mcs')
-rw-r--r-- | mcs/class/corlib/System/DateTime.cs | 6 | ||||
-rw-r--r-- | mcs/class/corlib/System/DateTimeUtils.cs | 7 | ||||
-rw-r--r-- | mcs/class/corlib/Test/System/DateTimeTest.cs | 4 |
3 files changed, 8 insertions, 9 deletions
diff --git a/mcs/class/corlib/System/DateTime.cs b/mcs/class/corlib/System/DateTime.cs index 086f35059ac..6185ae95621 100644 --- a/mcs/class/corlib/System/DateTime.cs +++ b/mcs/class/corlib/System/DateTime.cs @@ -2003,10 +2003,9 @@ namespace System if (format == null || format == String.Empty) format = "G"; - bool useutc = false, use_invariant = false; - if (format.Length == 1) { char fchar = format [0]; + bool use_invariant, useutc; format = DateTimeUtils.GetStandardPattern (fchar, dfi, out useutc, out use_invariant); if (fchar == 'U') return DateTimeUtils.ToString (ToUniversalTime (), format, dfi); @@ -2014,6 +2013,9 @@ namespace System if (format == null) throw new FormatException ("format is not one of the format specifier characters defined for DateTimeFormatInfo"); + + if (use_invariant) + dfi = DateTimeFormatInfo.InvariantInfo; } // Don't convert UTC value. It just adds 'Z' for diff --git a/mcs/class/corlib/System/DateTimeUtils.cs b/mcs/class/corlib/System/DateTimeUtils.cs index 3def45668ad..61bbe7a5db6 100644 --- a/mcs/class/corlib/System/DateTimeUtils.cs +++ b/mcs/class/corlib/System/DateTimeUtils.cs @@ -184,13 +184,6 @@ namespace System { // Add + 10 for cases like mmmm dddd StringBuilder result = new StringBuilder (format.Length + 10); - // For some cases, the output should not use culture dependent calendar - DateTimeFormatInfo inv = DateTimeFormatInfo.InvariantInfo; - if (format == inv.RFC1123Pattern) - dfi = inv; - else if (format == inv.UniversalSortableDateTimePattern) - dfi = inv; - int i = 0; bool saw_day_specifier = false; diff --git a/mcs/class/corlib/Test/System/DateTimeTest.cs b/mcs/class/corlib/Test/System/DateTimeTest.cs index 05fd44ea528..72da88876a3 100644 --- a/mcs/class/corlib/Test/System/DateTimeTest.cs +++ b/mcs/class/corlib/Test/System/DateTimeTest.cs @@ -2265,6 +2265,10 @@ namespace MonoTests.System Assert.AreEqual ("2000-01-01T00:00:00.0000000Z", DateTime.SpecifyKind (new DateTime (2000, 1, 1), DateTimeKind.Utc).ToString ("o"), "#2"); Assert.AreEqual ("2000-01-01T00:00:00.0000000+09:00".Length, DateTime.SpecifyKind ( new DateTime (2000, 1, 1), DateTimeKind.Local).ToString ("o").Length, "#3"); + + var culture = new CultureInfo ("ps-AF"); + Assert.AreEqual ("1976-06-19T00:00:00.0000000", new DateTime(1976, 6, 19).ToString ("O", culture), "#4"); + Assert.AreEqual ("1976-06-19T00:00:00.0000000", new DateTime(1976, 6, 19).ToString ("o", culture), "#5"); } [Test] |