Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

Silverlight Calendar doesn't display Thai Year correctly RSS

10 replies

Last post Mar 18, 2009 10:05 PM by Kathykam

(0)
  • nant15

    nant15

    0 Points

    7 Posts

    Silverlight Calendar doesn't display Thai Year correctly

    Mar 03, 2009 01:22 AM | LINK

     I have searched the forum and it seems like no over ever brought this up yet. [:(] I just discovered when I tried to use the calendar recently that there is a small problem with Silverlight Calendar Control when displaying Thai Calendar because it shows the year part in Christian era which is 543 years off ours.

    From the screenshot above, notice that all short dates and month was localized correctly and event the week starts with Monday correctly! However, 2009 should be 2552 (2009 + 543 = 2552) in Thai locale. What happened is the calendar confuses people and i have found some user that tried so hard to dial the calendar to year 2552 and submit it  (which became year 3095 in the database)

     I hope that this very minor issue would get fixed in the next release. Since, DateTime.Now.ToString( "yyyy" ) shows "2552" correctly, it shouldn't be that hard to fix the calendar. [:D]

     

  • xusun

    xusun

    Participant

    1694 Points

    261 Posts

    Microsoft

    Re: Silverlight Calendar doesn't display Thai Year correctly

    Mar 03, 2009 07:58 AM | LINK

    SL2 only supports gregorian calendar.

    Thanks,
    Xun Sun - MSFT
  • nant15

    nant15

    0 Points

    7 Posts

    Re: Silverlight Calendar doesn't display Thai Year correctly

    Mar 03, 2009 05:44 PM | LINK

    In case you missed it, DateTime.Now.ToString("yyyy"); returns "2552" in SL2 which is correct because Thai Calendar is gregorian calendar but we use different Era - which is Buddhism Era. Which means all date and time are based on international date but we choose to start year 0 at 543 years before christian era.

    So, since DateTime.Now.ToString() correctly translates the year in our calenar - isn't that mean it is the bug in calendar control?

  • MarkMonster

    MarkMonster

    Star

    7590 Points

    1497 Posts

    Re: Silverlight Calendar doesn't display Thai Year correctly

    Mar 03, 2009 08:12 PM | LINK

    Can you report the bug in here? http://silverlight.net/forums/28.aspx
    Mark Monster - Silverlight MVP - MCPD Enterprise
    Blog
    Silverlight and Expression Insiders UG

    Dont forget to click "Mark as Answer" on the post that helped you.
  • xusun

    xusun

    Participant

    1694 Points

    261 Posts

    Microsoft

    Re: Silverlight Calendar doesn't display Thai Year correctly

    Mar 03, 2009 08:23 PM | LINK

    Check this page: http://msdn.microsoft.com/en-us/library/system.globalization.gregoriancalendar.aspx 

    "The Gregorian calendar recognizes two eras: B.C. or B.C.E., and A.D. or C.E."

    The Calendar control won't do a simple DateTime.ToString() as you did in the debugger.  It fetches the available Gregorian format from the system and use that format to convert the DateTime to String. 

    Thanks,
    Xun Sun - MSFT
  • nant15

    nant15

    0 Points

    7 Posts

    Re: Silverlight Calendar doesn't display Thai Year correctly

    Mar 03, 2009 10:28 PM | LINK

    The page that you show me point me to the full framework documentation, and Full Framework have no problem with our culture - it handles things correctly.

    So, I wrote this small code, to see how SL really handles the Buddishsm era,

    CultureInfo th = new CultureInfo("th-TH");
    CultureInfo en = new CultureInfo("en-US");
    
    MessageBox.Show(th.Calendar.GetEra(DateTime.Now).ToString() + "," +
      DateTime.Now.ToString( "dddd dd MMMM yyyy", th ) + "\r\n" +
      en.Calendar.GetEra(DateTime.Now).ToString() + "," +
      DateTime.Now.ToString("dddd dd MMMM yyyy", en));

     and it turns out to be:

     

     that th-TH culture and en-US seems to be recognizing the same Era. However, the formatting made the year shows up differently.

    I obviously don't know how you made up the control internally - but i'm quite sure that those localized day/month names can be extracted from the CultureInfo class with CultureInfo.DateTimeFormat.MonthNames/DayNames properties.

    Now, What confuses me is Calendar control happily shows the localized day and month names but it cannot show the year correctly. While all other date/time formatting facilities made available to us can shows it correctly. [:S]

     

  • xusun

    xusun

    Participant

    1694 Points

    261 Posts

    Microsoft

    Re: Silverlight Calendar doesn't display Thai Year correctly

    Mar 03, 2009 11:40 PM | LINK

    Sorry for being not clear.  The reason that I post the link is to show that Thai calendar is NOT Gregorian calendar. 

     Verify by your own:   

     MessageBox.Show(String.Format("Is Thai Calendar GregorianCalendar:{0}", 
    th.Calendar is GregorianCalendar));
     

    If you use reflector to open the Calendar source code, the formatting logic is like this:

    public static DateTimeFormatInfo GetCurrentDateFormat()
    {
        if (CultureInfo.CurrentCulture.Calendar is GregorianCalendar)
        {
            return CultureInfo.CurrentCulture.DateTimeFormat;
        }
        foreach (Calendar calendar in CultureInfo.CurrentCulture.OptionalCalendars)
        {
            if (calendar is GregorianCalendar)
            {
                DateTimeFormatInfo info = new CultureInfo(CultureInfo.CurrentCulture.Name).DateTimeFormat;
                info.Calendar = calendar;
                return info;
            }
        }
        DateTimeFormatInfo dateTimeFormat = new CultureInfo(CultureInfo.InvariantCulture.Name).DateTimeFormat;
        dateTimeFormat.Calendar = new GregorianCalendar();
        return dateTimeFormat;
    }

    Here since Thai calendar is not Gregorian calendar, it will try to get the first Gregorian calendar of the OptionalCalendars.

    It will still uses the entire culture of th-Th, but use this first Gregorian calendar as the format.

    If you follow the same procedure and format your datetime with this DateTimeFormatInfo, you will get the same result as displayed in the Calendar. That's what I meant Calendar only supports Gregorian calendar now. 

     

     

    Thanks,
    Xun Sun - MSFT
  • nant15

    nant15

    0 Points

    7 Posts

    Re: Silverlight Calendar doesn't display Thai Year correctly

    Mar 04, 2009 07:35 PM | LINK

    Now you got my point - Thai Calendar is Gregorian calendar in reality but we use different era, but the way you guys model the calendar (with ThaiBuddhismCalendar class) have alienated it and made it became non-gregorian calendar in BCL. So the code is correct in programming that Thai calendar is not gregorian since it was not inherited from Gregorian Calendar, but it is totally wrong in reality! Visit Wiki pedia for more info: http://en.wikipedia.org/wiki/Thai_solar_calendar

    So the problem came down to GregorianCalendar class itself does not support any other era except those related to Christian - that's why someone has to create the ThaiBuddhismCalendar Class and probably copy all implementation of International gregorian calendar but only modify the formatting (since we can use 2009 or 2552 interchangeably but most Thai will expect 2552). I won't comment on how you guys decided to design it this way and I honor your decision as I know that there must be some reasons behind it.

    In conclusion: What I am trying to tell you that it is just a formatting issue - not with the calendar, It is just 2009 + 543 when displaying the year and we are fixed.

    So I concluded that what you are telling me is there will be no fix for this unless i found a way to tell the owner of the function that "Oh, it is okay to use Thai CultureInfo to do the formatting because thai calendar is essentially a gregorian calendar" - Am I Right? Or I will have to wait until calendar control supports my calendar (which it already supported but does not do the formatting correctly) or I have to went on and create my own???

    I have attended the MVP summit and also tried to comment this in a session yesterday but I get this exact same answer and no suggestion or any help offered - in fact, they led me to make a post here (even though i am there in person and speaking to some people from the silverlight team). I tired of giving you the comments guys - none of it went anywhere.

     

  • xusun

    xusun

    Participant

    1694 Points

    261 Posts

    Microsoft

    Re: Silverlight Calendar doesn't display Thai Year correctly

    Mar 04, 2009 08:04 PM | LINK

    Thanks for your comments.

    I agree with you that Thai Calendar is Gregorian calendar IN REALITY.  In other words, it's still not a REAL Gregorian calendar.  Therefore, it's not supported in SL2 Calendar. 

    If you look only on the Thai calendar, it seems to be only a "formatting issue".  However, from the product point of view, we need either claim that only Gregorian calendar is supported or All calendars are supported.  It would be funny to say that formal Gregorian calendar + Thai Calendar is supported.  :-)  We have to make the boundary clear here. 

    It's not the end of the game.  We may support non-gregorian calendars in future releases.  Since you are attending the MVP summit, you are welcomed to drop by the Controls team and get some info on that.

    Thanks,
    Xun Sun - MSFT
  • nant15

    nant15

    0 Points

    7 Posts

    Re: Silverlight Calendar doesn't display Thai Year correctly

    Mar 08, 2009 05:55 PM | LINK

    OK, I gave up and created my own calendar for Gregorian Calendar which supports Thai! You can find it here: http://coresharp.net/blogs/projects/archive/2009/03/08/silverlight.aspx

    I know that this problem will continue with future controls...until we finish debating whether Thai Calendar is gregorian calendar

    Anyway, while testing the control i found that Chinese, Japan, Taiwan calendars are all modeled as gregorian - which they have just switched from their traditional calendars to gregorian a while ago. More interesting case is Taiwan, where they have Gregorian as Main calendar and with Taiwan Calendar as optional calendar

    Seeing this, i would expect to see ThaiGrogorianCalendar which inherits from GregorianCalendar and MinSupportedDateTime is 1/1/1941 which is the date we decided to swtich to Gregorian Calendar and has ThaiBuddhismCalendar as the second optional calendar to handle the rest...

    And  I do everything Gregorian way just use DateTime.Format( "yyyy" ) to get my 2552 from 2009 [:P]