Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
PHILO-HE opened this issue Apr 16, 2024 · 2 comments
Open

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

PHILO-HE opened this issue Apr 16, 2024 · 2 comments

Comments

@PHILO-HE
Copy link

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
Copy link
Owner

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
Copy link
Author

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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants