Converting time when timezone is in "windows" terms

141 views
Skip to first unread message

drac...@gmail.com

unread,
May 19, 2020, 11:25:02 AM5/19/20
to Noda Time
The title doesn't quite make this clear.

Given that I have a time, and a timezone, I need to convert to UTC. However, the timezone is only given in windows term or generic terms. So for instance, I have "Eastern Standard Time" or "Pacific Daylight Time". How do I find the right NodaTime timezone that matches those?

Thanks
-Steffen

Jon Skeet

unread,
May 19, 2020, 11:30:20 AM5/19/20
to Noda Time
If you actually had the Windows system time zone ID, it would be reasonably straightforward. But "Pacific Daylight Time" isn't a Windows system time zone ID... it's possibly the result of TimeZoneInfo.DaylightName.

Where does this value actually come from? Do you have any guarantee about what it would match in a TimeZoneInfo?

--

---
You received this message because you are subscribed to the Google Groups "Noda Time" group.
To unsubscribe from this group and stop receiving emails from it, send an email to noda-time+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/noda-time/cc25ae06-6abf-4050-b8c2-5f5a9b52f179%40googlegroups.com.

Steffen Froehlich

unread,
May 19, 2020, 11:36:23 AM5/19/20
to noda...@googlegroups.com
A little bit of background. We have code that we're porting from full framework to dotnet core so that we can run on linux.

The timezone names come from log files and are in the format I described. On Windows, using TimeZoneInfo, we can use the TimeZoneInfo.StandardName to find the right timezone. On Linux, this doesn't work as well because a lot of different TimeZoneInfo objects have the same StandardName and not all have the same UTC offset. I'm investigating using NodaTime so that we can at least test to see if there are TimeZone objects (either TimeZoneInfo or NodaTime version of it) of a timezone that has different offsets and not have to rely on the customer OS to be updated.

So to circle back. I need to convert times that have timezones like "Eastern Standard Time" or "Pacific Daylight Time" and I need to convert consistently on Windows and Linux.

Does that make sense?

-Steffen


You received this message because you are subscribed to a topic in the Google Groups "Noda Time" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/noda-time/ViHwX6SMbCs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to noda-time+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/noda-time/CA%2B5fHt%2BBSJG%2BUNB%2Bnk2ePYPjHAi6xPXjVG8haaBJ%2B6oweG9gNg%40mail.gmail.com.

Jon Skeet

unread,
May 19, 2020, 11:39:58 AM5/19/20
to Noda Time
It doesn't help very much, because you haven't really described the format. What code produced these log files to start with?

Note that NodaTime contains an embedded database of Windows time zone IDs and how they map to IANA time zone IDs, but it doesn't contain a mapping of "localized standard and daylight names for every Windows time zone".

Steffen Froehlich

unread,
May 19, 2020, 11:46:51 AM5/19/20
to noda...@googlegroups.com
The timezones come from from a log files, for a product we don't have control over. We need to do the best job possible to convert human readable time + timezone to UTC. We know that the log files are always in english and are not localized. From what I can tell, the log files are always the TImeZoneInfo.Display name. 

The mapping Windows IDs to IANA timezone ID might be what I need. Can I access this mapping?

-Steffen


Jon Skeet

unread,
May 19, 2020, 11:57:17 AM5/19/20
to Noda Time
> The mapping Windows IDs to IANA timezone ID might be what I need.

No, it's not. At least, not directly. You'll need a mapping from display name to system time zone ID first. You may be able to generate that yourself - just iterate over all the system TimeZoneInfos and create a dictionary mapping both StandardName and DaylightName to Id. Check for collisions as you go.
After that, you can use TzdbDateTimeZoneSource.WindowsMapping to get at the Windows IDs. There's simpler functionality coming here in 3.0 (which should be out at the end of the week).

Steffen Froehlich

unread,
May 19, 2020, 12:00:02 PM5/19/20
to noda...@googlegroups.com
Great, that's what I needed to know. 

Good to hear that 3.0 should be out soon :)

Thanks for your help!

-Steffen


Reply all
Reply to author
Forward
0 new messages