1

I have following data: geographical coordinates of the place and local date and time, not necessarily current, may point to some moment many years ago. I also may have non-DST time zone effective currently, at present time (but not necessarily correct for the date and time of interest). I want to find out whether DST was in effect in that location at that local time using Python. Any ideas how to do that? I was reading about package pytz, but could not find anything suitable in it to complete that.

ivan.ukr
  • 2,853
  • 1
  • 23
  • 41

2 Answers2

2

I'm assuming you've already resolved the time zone itself - if not, there are really two problems in this one question:

  • Finding a time zone ID from coordinates
  • Determining if DST was in effect in a time zone at an arbitrary date/time

I'm not very familiar with Python, but given this documentation I believe you want the tzinfo.dst(dt) function, which will return timedelta(0) in standard time, and the difference between the standard offset and the wall offset in DST. You pass in the datetime you want to find the offset for.

Note that in the pytz library, there's an additional is_dst parameter which you can specify to resolve ambiguities, where a given local time occurs twice due to a "fall back" transition.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
2

You'll need one of the solutions in How to get a time zone from a location using latitude and longitude coordinates? to identify the timezone that the given coordinates belongs to.

Once you have the timezone you can then use the solution at Is a specific timezone using DST right now? to determine if DST is effective given the timezone and the date/time.

blhsing
  • 91,368
  • 6
  • 71
  • 106