Search code examples
timezoneoffset

Can I infer time zone from offset AND a datetime?


I know that I can't get a time zone purely from its offset, as mentioned in the wiki page for the time zone tag here.

What if I also had the datetime though? That would narrow things down to where I don't have to worry about daylight savings time.

I'm not looking for a locale. Just the time zone. I think this question is relevant because everything I've found online indicates clearly that you cannot get time zone from offset, but nothing clearly states that you can't get time zone from offset+datetime.


Solution

  • What if I also had the datetime though?

    No, it still doesn't give you enough information.

    It's entirely possible for two time zones to have the same local time at the same instant right now, but to diverge a minute later. Just knowing the date/time and offset does not give you a time zone - at least not in general. In many cases it might - for any given situation, you could look through all the time zones and check how many of them have that UTC offset at that instant in time... but you should definitely expect there to be cases where the answer is "more than one time zone matches".

    As a concrete example, consider 2022-05-16T17:33:00+01:00. That matches Africa/Casablanca and Europe/London at least - but those are definitely very different time zones with different rules.