Thai Calendar year is not adjusted by 543 years

Posted by: azhigimont on 27 February 2024, 6:23 am EST

  • Posted 27 February 2024, 6:23 am EST

    wijmo.Globalize.formatDate does not add 543 years to the date’s year as per Thai Calendar requirements.

    https://en.wikipedia.org/wiki/Thai_calendar

    Please see example at https://jsfiddle.net/azhigimont/g9duo2jp/4/

  • Posted 27 February 2024, 5:32 pm EST

    Hello,

    To convert the dates into Thai Calendar dates you would need to convert the dates into locale(Thai) format and then convert them back to Date objects to format them accordingly using wijmo.Globalize.formatDate. Please refer to the code snippet and sample link below for reference:

    d = new Date();
    thaiDateString = d.toLocaleDateString("th-TH")
    let [day, month, year] = thaiDateString.split('/').map(Number);
    let dateObj = new Date(year, month - 1, day); // month - 1 because JS months are zero-based
    let formattedDate = wijmo.Globalize.formatDate(dateObj, "yyyy MMMM")
    console.log(formattedDate,thaiDateString);

    Sample link: https://jsfiddle.net/fLn81ze3/

    In case you are changing between different cultures and want to dynamically update the Thai culture then you can refer to the below sample implementing the same:

    https://jscodemine.grapecity.com/share/oUiK54YU7ESTNs919Q7M7w/

    Regards

  • Posted 28 February 2024, 7:37 am EST

    Please correct me if I’m wrong but if

    toLocaleDateString
    can adjust a year correctly

    thaiDateString = d.toLocaleDateString("th-TH")

    then

    wijmo.Globalize.formatDate(d, "yyyy MMMM")

    should be able to do the same? As per example, Thai culture file is loaded and

    wijmo.Globalize.formatDate
    has the required information available.

  • Posted 28 February 2024, 6:32 pm EST

    Hello,

    The formatDate function of the Globalize class only formats a Date object into specified date format as per the .NET-style Date format string(https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings) and doesn’t change as per the current culture(local format). It gives the flexibility to convert dates into any desired format irrespective of local format or culture.

    You can refer to the below link to get more information:

    API link: https://developer.mescius.com/wijmo/api/classes/wijmo.globalize.html#formatdate

    Regards

  • Posted 29 February 2024, 6:01 am EST - Updated 29 February 2024, 9:16 am EST

    Unfortunately, the suggested approach creates the date with incorrect day of week.

    In the example below, the date 2024/3/17 is placed in Thai locale on Tuesday, instead of Sunday:

    https://jsfiddle.net/azhigimont/buxdpmhw/4/

    Meanwhile, .NET provides a correctly adjusted year in an example like this:

    DateTime aDate = new DateTime(2024, 3, 17);
     string strEn = aDate.ToString("yyyy MMMM dd dddd",
               CultureInfo.CreateSpecificCulture("en-US"));
     string strTh = aDate.ToString("yyyy MMMM dd dddd",
               CultureInfo.CreateSpecificCulture("th-TH"));


    I think it makes sense for wijmo.Globalize.formatDate to have the same behavior as .NET

    There is nothing in the doc that suggests different behavior.

  • Posted 29 February 2024, 8:29 pm EST

    Hello,

    The incorrect day is due to the ‘new Date()’. When converting the Thai date string into a date object, it retrieves the day of the corresponding year date (2567).

    The wijmo.Globalize.formatDate method converted the date object into valid date string formats (as per .NET-style Date format string). On checking your shared code snippet of .NET, it doesn’t give the day value when formatting with ‘dddd’ like ‘en-US’ culture. Can you please check it again and let us know if there is anything I missed? Below is the code snippet I used to verify the behavior.

    using System;
    using System.Globalization;
    public class HelloWorld
    {
        public static void Main(string[] args)
        {
           DateTime aDate = new DateTime(2024, 3, 17);
     string strEn = aDate.ToString("yyyy MMMM dd dddd",
               CultureInfo.CreateSpecificCulture("en-US"));
     string strTh = aDate.ToString("yyyy MMMM dd dddd",
               CultureInfo.CreateSpecificCulture("th-TH"));
                Console.WriteLine (strEn);
                Console.WriteLine (strTh);
        }
    }
    
    //Output
    2024 March 17 Sunday
    2567  17 

    In case you want to get the day, date, month, and year values as per the Thai calendar then you can write a custom function to get all the converted values. Please refer to the sample link below for the same:

    https://jsfiddle.net/q4tLho2g/

    Regards

  • Posted 1 March 2024, 6:16 am EST - Updated 1 March 2024, 6:21 am EST

    Hello,

    Online C# compilers can’t visualize Thai script. You have to build test UI app.

    Here is the output:



    And the code:

    ThaiDateLocalization.zip

    Now, the newly proposed fix will not fix the issue with date axis auto-formatting. When wijmo users zoom-in into a chart’s date/time-based axis, labels update automatically, according to a zooming ratio, and can include week days:

    I think, it will be a better solution for all Wijmo users if Mescius will provide a fix for wijmo.Globalize.formatDate as per .NET standards.

  • Posted 3 March 2024, 7:53 pm EST

    Hello,

    I apologize for the misunderstanding. You are correct. .NET is converting the dates correctly into the Thai format. Therefore, I have escalated this issue to our Dev team for further investigation with an internal tracking ID WJM-33508. We will provide you with an update as soon as I hear back from them.

    Thank you for your cooperation.

    Regards

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels