none
Are the DateTimeFormat settings for pt-PT and fr-FR wrong? RRS feed

  • Question

  • Hi,

    I encountered the problem, that the DateTimeFormat settings, that .Net 4.6.1 presents in the calendars for european portuguese and european french speaking countries, seem to have wrong settings for CalendarWeekRule and FirstDayOfWeek.

    A little example:

    var culture = new CultureInfo("fr-FR");
    Console.WriteLine(string.Format("Culture: {0}; CalendarWeekRule: {1}; FirstDayOfWeek: {2}", culture.ToString(), culture.DateTimeFormat.CalendarWeekRule, culture.DateTimeFormat.FirstDayOfWeek));
    
    culture = new CultureInfo("fr-BE");
    Console.WriteLine(string.Format("Culture: {0}; CalendarWeekRule: {1}; FirstDayOfWeek: {2}", culture.ToString(), culture.DateTimeFormat.CalendarWeekRule, culture.DateTimeFormat.FirstDayOfWeek));
    
    culture = new CultureInfo("pt-PT");
    Console.WriteLine(string.Format("Culture: {0}; CalendarWeekRule: {1}; FirstDayOfWeek: {2}", culture.ToString(), culture.DateTimeFormat.CalendarWeekRule, culture.DateTimeFormat.FirstDayOfWeek));

    This gives the following output:

    Culture: fr-FR; CalendarWeekRule: FirstDay; FirstDayOfWeek: Monday
    Culture: fr-BE; CalendarWeekRule: FirstDay; FirstDayOfWeek: Monday
    Culture: pt-PT; CalendarWeekRule: FirstDay; FirstDayOfWeek: Sunday

    As far as I know, these countries use the CalendarWeekRule.FirstFourDayWeek according to ISO 8601. Also Portugal uses the monday, instead of sunday as the first day of the week. We received bug reports for our software from customers from those countries because of these settings.

    Is this really a bug in .Net or am I missing something here?

    Greetings

    THamTHon

    Tuesday, November 22, 2016 3:15 PM

All replies

  • Dear THamTHon,

    >>I encountered the problem, that the DateTimeFormat settings, that .Net 4.6.1 presents in the calendars for european portuguese and european french speaking countries, seem to have wrong settings for CalendarWeekRule and FirstDayOfWeek.

    I've tested on my side, all versions of .Net Framework show first day of week is Sunday. According to your description, do you mean it is related to .Net framework 4.6.1 or Portugal uses the Monday actually?  Which one is right?

    From my side, I think this is not a issue related .NET Framework.

    If I misunderstood you, please feel free to let me know.

    Best regards,

    Kristin


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, November 23, 2016 3:37 AM
  • Hi Kristin,

    thx for your reply.

    The problem is not related only to .Net 4.6.1. It behaves the same on previous versions. .Net 4.6.1 is just the last version, that i checked and currently use.

    Let me explain the problem a little bit more verbose. Different countries have different rules for their calendars. For example here in Germany we use the Monday as the first day of the week. In the USA Sunday is used as first day of the week. .Net usually handles these settings quite well. These culture specific settings are stored in the DateTimeFormat-Property of the CultureInfo-Class of the specific culture (as you can see in my code example). So when .Net or a developer works with different cultures, he gets the correct settings.

    My problem is, that the settings in .Net for some of the languages seem to be wrong.

    My code example shows some of the settings, that are wrong in my opinion.

    fr-FR, fr-BE (and also other cultures, that use french as language, except fr-CA) are set to CalendarWeekRule.FirstDay in .Net. But it should be "FirstFourDayWeek" in my opinion.

    pt-PT is also set to CalendarWeekRule.FirstDay and but it should be "FirstFourDayWeek" in my opinion. Furthermore the FirstDayOfWeek should be set to Monday, while it is currently set to "Sunday".

    Maybe i should have reported this as a bug immediately, but i am a little but confused, that no one noticed this before me. That is why i am asking here first. ;)

    Kind regards

    THamTHon

    Wednesday, November 23, 2016 10:15 AM
  • Hi THamTHon

    Thanks for providing more detailed information.

    As far as I know, there isn't a workaround for CultureInfo directly.  .NET does allow you to get the current culture info and then change it for your app. You could, in theory, store the first week of year as a config entry and then use that to configure the culture when your app starts. It isn't a good idea.

    >>pt-PT is also set to CalendarWeekRule.FirstDay and but it should be "FirstFourDayWeek" in my opinion. Furthermore the FirstDayOfWeek should be set to Monday, while it is currently set to "Sunday".

    Here I found a blog article from MS on how to write such a function. It would probably be better for you to expose this method as an extension method off DateTime rather than trying to use the CultureInfo directly.

    Hope it helps!

    Best regards,

    Kristin


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    • Edited by Kristin Xie Thursday, November 24, 2016 7:52 AM
    Thursday, November 24, 2016 7:52 AM