Search Issue Tracker

By Design

Votes

0

Found in

2021.1.19f1

2021.2

2022.1

Issue ID

1379941

Regression

Yes

[Android][IL2CPP] DateTime.Now property prints incorrect year when using Thai language on a device

IL2CPP

-

Reproduction steps:
1. Open the attached Unity project "DateIssue.zip"
2. Go to File > Build Settings
3. Build and Run the app on an Android device
4. Open Language Settings on the device and activate the "Thai" language
5. Restart the app on the device
6. Open the app, press the "DateTime.Now.ToString()" button, and observe

Expected result: The text prints "DateTime.Now.ToString():15/12/2021"
Actual result: The text prints "DateTime.Now.ToString():15/12/2564"

Reproducible with: 2021.1.19f1, 2021.1.28f1, 2021.2.7f1, 2022.1.0b1
Not reproducible with: 2019.4.34f1
Could not test with: 2020.3.25f1 (Text does not print date when Scripting Backend is set to IL2CPP)

Reproduces with these devices:
VLNQA00121 - Samsung Galaxy S9 (SM-G960F), OS: 9.0.0, CPU: Exynos 9 Series 9810, GPU: Mali-G72
VLNQA00147 - Razer Phone (Cheryl), OS: 8.1.0, CPU: Snapdragon 835 MSM8998, GPU: Adreno 540
VLNQA00277 - Asus ROG Phone (ASUS_Z01QD), OS: 9.0.0, CPU: Snapdragon 845 SDM845, GPU: Adreno 630
VLNQA00404 - Galaxy Z Flip3 5G (SM-F711B), OS: 11, CPU: Snapdragon 888, GPU: Adreno 660
VLNQA00006 - Samsung Galaxy S7 (SM-G930F), OS: 8.0.0, CPU: Exynos 8 Octa (8890), GPU: Mali-T880
VLNQA00263 - Google Pixel 3 (Pixel 3), OS: 10.0.0, CPU: Snapdragon 845, GPU: Adreno 630

Not reproducible with these devices:
VLNQA00219 - Samsung Galaxy Note9 USA (SM-N960U), OS: 8.1.0, CPU: Snapdragon 845 SDM845, GPU: Adreno 630
VLNQA00410 - Galaxy Z Fold3 5G (SM-F926U), OS: 11, CPU: Snapdragon 888, GPU: Adreno 660
VLNQA00358 - iPhone 12, 14.1 iOS
VLNQA00310 - iPad Pro 12.9", 13.4.1 iOS
VLNQA00392 - iPad (9th generation), 15.0 iOS

Notes:
- Issue is not reproducible with the English, Lithuanian, Latvian, Russian, Deutsch, and Portugues languages when following the same steps
- Issue is not reproducible for Mac Standalone when language is set to Thai and region is set to Thailand
- Issue is not reproducible when using Mono Scripting Backend
- When opening Unity 2020.3.25f1 .apk build and following the same steps, the text does not print date, but an error is thrown in the Android Logcat:
Error Unity ArgumentOutOfRangeException: Not a valid calendar for the given culture.
Error Unity Parameter name: value
Error Unity at System.Globalization.DateTimeFormatInfo.set_Calendar (System.Globalization.Calendar value) [0x00000] in <00000000000000000000000000000000>:0
Error Unity at System.Globalization.CultureInfo.get_DateTimeFormat () [0x00000] in <00000000000000000000000000000000>:0
Error Unity at System.Globalization.CultureInfo.GetFormat (System.Type formatType) [0x00000] in <00000000000000000000000000000000>:0
Error Unity at System.Globalization.DateTimeFormatInfo.get_CurrentInfo () [0x00000] in <00000000000000000000000000000000>:0
Error Unity at System.DateTime.ToString () [0x00000] in <00000000000000000000000000000000>:0
Error Unity at LZ_Test.atostring () [0x00000] in <00000000000000000000000000000000>:0
Error Unity at UnityEngine.Events.UnityAction.Invoke () [0x00000] in <00000000000000000000000000000000>:0
Error Unity at UnityEngine.Events.UnityEvent.Invoke () [0x00000] in <00000000000000000000000000000000>:0

  1. Resolution Note:

    As stated in https://docs.microsoft.com/en-us/dotnet/api/system.globalization.thaibuddhistcalendar?view=net-6.0 Thai calendar calculates years differently.

    "The date January 1, 2001 A.D. in the Gregorian calendar is equivalent to the first day of January in the year 2544 of the current era in the Thai Buddhist calendar."

    If you like, you can override current culture, by calling
    CultureInfo.CurrentCulture = new CultureInfo("en-US");

    Which will force ToString functions to work according to english culture rules.

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.