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

Full list of TimeZoneInfos #49

Open
cocowalla opened this issue Oct 10, 2018 · 5 comments
Open

Full list of TimeZoneInfos #49

cocowalla opened this issue Oct 10, 2018 · 5 comments
Assignees

Comments

@cocowalla
Copy link

I'm sure I'm missing something really obvious here, but is there a way to get a list of TimeZoneInfos for all canonical IANA timezone IDs that are valid as of a given date?

@mattjohnsonpint
Copy link
Owner

Not sure exactly what you mean exactly. Can you provide an example of what you'd expect?

TimeZoneConverter has a TZConvert.KnownWindowsTimeZoneIds collection, if that's what you mean. Though it is always the current fully-up-to-date list. I don't track history of when the different time zones were made available (yet).

@cocowalla
Copy link
Author

What I'm looking for is TZConvert.KnownWindowsTimeZoneIds, but:

  1. Filtered to only include canonical time zones and
  2. Filtered to only include timezones valid from a specified threshold (that is, they are not deprecated)

@mattjohnsonpint
Copy link
Owner

I assume you are referencing the format column in this Wikipedia page? One thing to keep in mind is that "deprecated" zones there really just mean that they aren't in the prefered area/locality format, so they should be generally removed from a pick-list. I assume that is your use case?

But that doesn't mean they don't work any more. In general, once a time zone id is introduced, it doesn't tend to go away. There has been one exception (Canada/East-Saskatchewan discussed here), but I know of no others.

Also, I don't this status in these libraries presently. I will consider it for the future and leave this issue open to remind me, but I make no promises. Thanks.

@cocowalla
Copy link
Author

Yes, this is basically for allowing users to select their timezone from a dropdown, and it seems prudent to prune the (rather large) list by removing ones that are no longer in use. Since GetTimeZonesForCountry has a threshold parameter, I just assumed there was some simple way to do this for all timezones... other than calling GetLanguageCodes and feeding the result into GetCountryNames, then feeding the result of that into GetTimeZonesForCountry :)

@mattjohnsonpint
Copy link
Owner

mattjohnsonpint commented Oct 11, 2018

Oh, I'm sorry - I misunderstood. I see what you mean now.

Yes, today you can build this list like so:

var threshold = DateTimeOffset.Now;
var ids = TZNames.GetCountryNames("en").Keys
    .SelectMany(code => TZNames.GetTimeZoneIdsForCountry(code, threshold))
    .Concat(TZNames.GetFixedTimeZoneIds())
    .Distinct()
    .OrderBy(x => x);

And yes, I agree this should be built in as a simpler single function. Thanks for the suggestion.

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

No branches or pull requests

2 participants