Zoidberg
Zoidberg

Reputation: 428

datetime.strptime failure in CI

I have the following error which happens only in CI:

ValueError: time data '09.30.2019 17:50 EDT' does not match format '%m.%d.%Y %H:%M %Z'

Here's my test:

def test_extract_time_from_page(pjm_html):
    expected_time = datetime.strptime("09.30.2019 17:50 EDT", "%m.%d.%Y %H:%M %Z")
    res = demand.extract_time_from_page(pjm_html)

    assert res == expected_time

It passes locally. I'm not sure how this could be different running in a CI environment

Edit: I can reproduce this by changing my machine timezone to something other than EDT. Can you not use a timezone different than your current timezone with datetime.strptime?

Upvotes: 2

Views: 55

Answers (2)

benvc
benvc

Reputation: 15120

This is a known issue with the %Z directive. The current documentation is confusing and there is a pending request to have the documentation revised. The pending documentation change explains the issue you are experiencing:

Note that strptime only accepts certain values for %Z: UTC and GMT, and what is defined in time.tzname for your own locales. It will return a ValueError for any invalid strings. For example, someone living in Japan will have UTC, GMT and JST as valid values, but probably not EST.

Upvotes: 2

makozaki
makozaki

Reputation: 4366

Might be a problem with pytz lib. Compare pytz libs on your CI worker and locally. Here you can find an explanation which points to wikipedia list of timezones which says that EDT is a deprecated timezone. You can try updating your pytz lib on CI worker.

Upvotes: 0

Related Questions