dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.28k stars 1.58k forks source link

timeZoneName returns unexpected value ("+07") for certain countries #59577

Closed icecrao2 closed 10 hours ago

icecrao2 commented 1 day ago

Hello Dart Team,

I have encountered an unexpected behavior in the DateTime class's timeZoneName property and would like to report it.

Problem Description The timeZoneName property of the DateTime class returns values in the format +07 instead of a proper timezone name (e.g., Asia/Ho_Chi_Minh or ICT) for certain countries like Vietnam. This behavior is unexpected and can lead to issues in applications that rely on accurate timezone names.

Steps to Reproduce Here is a simple code snippet to reproduce the issue:

void main() {
  final now = DateTime.now();
  print(now.timeZoneName); // Expected: "Asia/Ho_Chi_Minh" or "ICT"
                           // Actual: "+07"
}

Environment Information Dart Version : 3.5.3 Operating System: iOS

Expected Behavior The timeZoneName property should return a standard timezone name such as "Asia/Ho_Chi_Minh" or "ICT" instead of a numeric offset like "+07".

Additional Notes This issue might be related to the loading of timezone data in certain environments. Clarification on the intended behavior of the timeZoneName property in such cases would be highly appreciated.

Thank you for looking into this matter. I look forward to your feedback and resolution!

Best regards,

dart-github-bot commented 1 day ago

Summary: timeZoneName returns numeric offsets (e.g., "+07") instead of IANA timezone names (e.g., "Asia/Ho_Chi_Minh") on iOS, causing unexpected behavior in applications. Needs investigation into timezone data loading.

lrhn commented 1 day ago

The timeZoneName getter asks the operating system for the name, and returns that string verbatim. There is no post-processing other that returning an empty string if the OS call failed. The code is here, and it uses localtime_r to get the name.

If you get "+07", then it's because your operating system's localtime implementation returns that string.