openelections / clarify

Discover and parse results for jurisdictions that use Clarity-based election systems.
MIT License
38 stars 21 forks source link

UnknownTimezoneWarning #36

Open Kirkman opened 4 years ago

Kirkman commented 4 years ago

Recently, when I use clarify, Python has been spitting out this warning:

UnknownTimezoneWarning: tzname
CDT identified but not understood.  
Pass "tzinfos" argument in order to correctly return a timezone-aware datetime. 
In a future version, this will raise an exception.

I think it's from this line in clarify: https://github.com/openelections/clarify/blob/12b4eb5ff19bbd7641395d1b7f035eed45a9abd6/clarify/parser.py#L67

Anyway, it's not an exception yet, but I wanted to bring that to your attention. I don't know if something like this might be a solution, though obviously that specific answer is overkill.

dwillis commented 4 years ago

@Kirkman Hmm, yeah. That's weird, and thanks for raising it. Will see if there's something we can do.

GPHemsley commented 4 years ago

Here's the documentation for dateutil.parser.parse: https://dateutil.readthedocs.io/en/stable/parser.html#dateutil.parser.parse

I've been unable to locate any example that does better than a hardcoded list of mappings, but dateutil.tz.gettz may be of some use: https://dateutil.readthedocs.io/en/stable/tz.html#dateutil.tz.gettz

Python is notoriously bad at dealing with time and timezones, but perhaps knowledge of the source material will help here.

I'm guessing this will need to be passed something like:

{
    "AST": "America/Puerto_Rico",
    "EST": "EST5EDT",  # or "America/New_York"
    "EDT": "EST5EDT",  # or "America/New_York"
    "CST": "CST6CDT",  # or "America/Chicago"
    "CDT": "CST6CDT",  # or "America/Chicago"
    "MST": "MST7MDT",  # or "America/Denver"
    "MDT": "MST7MDT",  # or "America/Denver"
    "PST": "PST8PDT",  # or "America/Los_Angeles"
    "PDT": "PST8PDT",  # or "America/Los_Angeles"
    "AKST": "America/Anchorage",
    "AKDT": "America/Anchorage",
    "HAST": "America/Adak",
    "HADT": "America/Adak",
    "HST": "Pacific/Honolulu",
    "SST": "Pacific/Pago_Pago",
    "ChST": "Pacific/Guam",
    "CHST": "Pacific/Guam",
}