How do you infer time zone name from timestamp strings with only offsets? #181
-
Suppose we have a timestamp like "2019-01-30T10:33:38.186520297-05:00" How can we convert this to Zoned if we don't necessarily know if the IANA time zone name is America/New_York or America/Chicago ? I'm assuming there are only small numbers of times where it's ambiguous (right around the changing of daylight savings time) Would it be possible to pass a list of options as an argument to a function, and if exactly one of the options matches that offset on that date, use that? My workaround is to push "[UTC]" onto the string and parsing it to Zoned, and just work with UTC for everything, but then we're losing local source offset information, and sometimes this changes the dates, which could be problematic in cases where API owners pass dates as datetimes at midnight (quite common). I realize it's impossible to cover all edge cases, but what would be the best practice to parse datetimes with offsets but missing / unknown time zone names? (I did already email the source API owner to request they add [{tz}]) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Good question. Someone else asked a very similar question (if not identical) here: #112 (comment) I then forwarded this question to the Temporal folks (from which this behavior of Jiff was inspired): tc39/proposal-temporal#2930 Basically, Jiff should probably provide some way to extract the offset here or some way to produce a One thing that came out of the conversation above was that it would be good to better understand the use case. Since you have a timestamp without any knowledge of what time zone it's in, why do you want to keep the offset around? As in, why do you see using
Can you give an example of how this might work? |
Beta Was this translation helpful? Give feedback.
All righty, I've published
jiff 0.1.20
which has the newjiff::fmt::temporal::Pieces
type in it. It doesn't provide the high level function you want, but I wrote a case study on how to approach the problem with example code. Let me know if that helps!