HowardHinnant / date

A date and time library based on the C++11/14/17 <chrono> header
Other
3.07k stars 669 forks source link

Use timezone name like "-08:00" for `locate_zone()` #823

Open PHILO-HE opened 2 months ago

PHILO-HE commented 2 months ago

In our code, we pass user-specified timezone name to date::locate_zone() to get date::time_zone*. It works well when timezone name is like "America/Los_Angeles". But when an offset timezone name is specified, e.g., "-08:00", we found it cannot be recognized by timezone database, even though these options are set: AUTO_DOWNLOAD=1, HAS_REMOTE_API=1. Is this an expected behavior? Thanks in advance!

HowardHinnant commented 2 months ago

date::locate_zone() only recognizes IANA time zone names. Here is a list of the IANA time zone names: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones

I believe you may be interested in the names that are similar to "Etc/GMT+8". Note the curious reversal in the sign of the offset. I.e. "Etc/GMT+8" has a UTC offset of -08:00.

Note that there are no IANA names that handle offsets that are not a multiple of hours. If you need such a thing, one can write custom time zones for arbitrary UTC offsets. For an example of such see "Custom time zone" at this link: https://howardhinnant.github.io/date/tz.html#Examples

PHILO-HE commented 2 months ago

date::locate_zone() only recognizes IANA time zone names. Here is a list of the IANA time zone names: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones

I believe you may be interested in the names that are similar to "Etc/GMT+8". Note the curious reversal in the sign of the offset. I.e. "Etc/GMT+8" has a UTC offset of -08:00.

Note that there are no IANA names that handle offsets that are not a multiple of hours. If you need such a thing, one can write custom time zones for arbitrary UTC offsets. For an example of such see "Custom time zone" at this link: https://howardhinnant.github.io/date/tz.html#Examples

@HowardHinnant, thanks so much for your clear reply! We may only need to handle the offset which is a multiple of hours. I guess a simplest way is to firstly convert the offset-based timezone to "Etc/GMT+x".