The inventory shows a truly unexpected ten-item surplus

by Michael S. Kaplan, published on 2007/11/01 10:16 -04:00, original URI: http://blogs.msdn.com/b/michkap/archive/2007/11/01/5807844.aspx


Oli reported an apparent bug yesterday:

Hi Michael,

me again -

I observed some very strange behavior where the number of date/time patterns of a culture differs depending on whether I got the culture info object through GetCultures() or by GetCultureInfo. In the following code,

System.Globalization.CultureInfo persian = System.Globalization.CultureInfo.GetCultureInfo("fa-IR");

foreach (System.Globalization.CultureInfo ci in System.Globalization.CultureInfo.GetCultures(System.Globalization.CultureTypes.AllCultures))
{
 if (ci.Name.Equals(persian.Name))
 {
  int enumCount = ci.DateTimeFormat.GetAllDateTimePatterns().Length;
  int objCount = persian.DateTimeFormat.GetAllDateTimePatterns().Length;
 }
}

"persian" is retrieved using S.G.C.GetCultureInfo() while "ci" iterates through all known cultures.

ci.ReadOnly = false while persian.ReadOnly = true, the prior probably is cloned.

Most astonishingly, though, the number of date/time patterns differs between the two (48 vs 38), and that's IMO a bug. I'm using C# 3.0 on XP.

I've tested this for all non-neutral cultures, the only one where it happens is fa-IR. For all others the number of date/time patterns is identical.

Let me know whether to better file this through standard channels.

Cheers, Oli

Okay, let's modify the code a bit to test out the full scenario....

And let's take a look ast the extra formats to see what they are:

using System;
using System.Globalization;
namespace WeirdDateStuff {
    class Crap {
        [STAThread]
        static void Main(string[] args) {
            foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures | CultureTypes.WindowsOnlyCultures)) {
                CultureInfo gci = CultureInfo.GetCultureInfo(ci.Name);
                string[] rgstci = ci.DateTimeFormat.GetAllDateTimePatterns();
                string[] rgstgci = gci.DateTimeFormat.GetAllDateTimePatterns();
                if (rgstci.Length != rgstgci.Length) {
                    Console.WriteLine(ci.Name + "   " + ci.EnglishName);
                    Console.WriteLine("    {0} from ci out of GetCultures() call.", rgstci.Length);
                    foreach(string st in rgstci) {
                        Console.WriteLine("        " + st);
                    }
                    Console.WriteLine("    {0} from ci out of GetCultureInfo() call.", rgstgci.Length);
                    foreach(string st in rgstgci) {
                        Console.WriteLine("        " + st);
                    }
                }
            }
        }
    }
}

The output (on XP SP2), with all of the "extra" formats marked in red:

fa-IR   Persian (Iran)
    48 from ci out of GetCultures() call.
        M/d/yyyy
        M/d/yy
        MM/dd/yy
        MM/dd/yyyy
        dddd, MMMM dd, yyyy
        MMMM dd, yyyy
        dddd, MMMM dd, yyyy hh:mm tt
        dddd, MMMM dd, yyyy HH:mm
        MMMM dd, yyyy hh:mm tt
        MMMM dd, yyyy HH:mm
        dddd, MMMM dd, yyyy hh:mm:ss tt
        dddd, MMMM dd, yyyy HH:mm:ss
        MMMM dd, yyyy hh:mm:ss tt
        MMMM dd, yyyy HH:mm:ss
        M/d/yyyy hh:mm tt
        M/d/yyyy HH:mm
        M/d/yy hh:mm tt
        M/d/yy HH:mm
        MM/dd/yy hh:mm tt
        MM/dd/yy HH:mm
        MM/dd/yyyy hh:mm tt
        MM/dd/yyyy HH:mm
        M/d/yyyy hh:mm:ss tt
        M/d/yyyy HH:mm:ss
        M/d/yy hh:mm:ss tt
        M/d/yy HH:mm:ss
        MM/dd/yy hh:mm:ss tt
        MM/dd/yy HH:mm:ss
        MM/dd/yyyy hh:mm:ss tt
        MM/dd/yyyy HH:mm:ss
        MMMM dd
        MMMM dd
        yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK
        yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK
        ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
        ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
        yyyy'-'MM'-'dd'T'HH':'mm':'ss
        hh:mm tt
        HH:mm
        hh:mm:ss tt
        HH:mm:ss
        yyyy'-'MM'-'dd HH':'mm':'ss'Z'
        dddd, MMMM dd, yyyy hh:mm:ss tt
        dddd, MMMM dd, yyyy HH:mm:ss
        MMMM dd, yyyy hh:mm:ss tt
        MMMM dd, yyyy HH:mm:ss
        MMMM, yyyy
        MMMM, yyyy
    38 from ci out of GetCultureInfo() call.
        MM/dd/yyyy
        MM/dd/yy
        dddd, MMMM dd, yyyy
        MMMM dd, yyyy
        dddd, MMMM dd, yyyy hh:mm tt
        dddd, MMMM dd, yyyy HH:mm
        MMMM dd, yyyy hh:mm tt
        MMMM dd, yyyy HH:mm
        dddd, MMMM dd, yyyy hh:mm:ss tt
        dddd, MMMM dd, yyyy HH:mm:ss
        MMMM dd, yyyy hh:mm:ss tt
        MMMM dd, yyyy HH:mm:ss
        MM/dd/yyyy hh:mm tt
        MM/dd/yyyy HH:mm
        MM/dd/yy hh:mm tt
        MM/dd/yy HH:mm
        MM/dd/yyyy hh:mm:ss tt
        MM/dd/yyyy HH:mm:ss
        MM/dd/yy hh:mm:ss tt
        MM/dd/yy HH:mm:ss
        MMMM dd
        MMMM dd
        yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK
        yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK
        ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
        ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
        yyyy'-'MM'-'dd'T'HH':'mm':'ss
        hh:mm tt
        HH:mm
        hh:mm:ss tt
        HH:mm:ss
        yyyy'-'MM'-'dd HH':'mm':'ss'Z'
        dddd, MMMM dd, yyyy hh:mm:ss tt
        dddd, MMMM dd, yyyy HH:mm:ss
        MMMM dd, yyyy hh:mm:ss tt
        MMMM dd, yyyy HH:mm:ss
        MMMM, yyyy
        MMMM, yyyy

And like Oli said, only for Persian -- those 10 extra entries.

        M/d/yyyy
        M/d/yy
        M/d/yyyy hh:mm tt
        M/d/yyyy HH:mm
        M/d/yy hh:mm tt
        M/d/yy HH:mm
        M/d/yyyy hh:mm:ss tt
        M/d/yyyy HH:mm:ss
        M/d/yy hh:mm:ss tt
        M/d/yy HH:mm:ss

Seems like a bug to me, too....

Anyone from the NLS test team want to get a bug report in? :-)

To answer the generic question of bug reporting, you can always go to the site that used to be the MSDN Product Feedback Center and report it there, or if I think it seems like an interesting blog post then I'll put it here. Whichever....

 

This post brought to you by ؍ (U+060d, a.k.a. ARABIC DATE SEPARATOR)


no comments

Please consider a donation to keep this archive running, maintained and free of advertising.
Donate €20 or more to receive an offline copy of the whole archive including all images.

go to newer or older post, or back to index or month or day