Skip to content

nightshade UTC check #272

@alpha-beta-soup

Description

@alpha-beta-soup

When trying to use the basemap nightshade method I noticed a bug in how basemap checks if the supplied datetime is in UTC. The relevant place in the codebase is here

# make sure date is utc.
if date.utcoffset() is not None:
    raise ValueError('datetime instance must be UTC')

However datetime objects that are in UTC and are aware of it do not pass this check:

In [1]: import datetime

In [2]: import pytz

In [3]: d = datetime.datetime.now()

In [4]: d
Out[4]: datetime.datetime(2016, 2, 29, 18, 21, 56, 388082)

In [5]: d.utcoffset() is not None
Out[5]: False

In [6]: d = d.replace(tzinfo=pytz.UTC)

In [7]: d
Out[7]: datetime.datetime(2016, 2, 29, 18, 21, 56, 388082, tzinfo=<UTC>)

In [8]: d.utcoffset() is not None
Out[8]: True

So even though my datetime has been made timezone aware (and converted from the original timezone to UTC), I have to set the timezone to None in order to pass the check for whether it is UTC... in which case it is strictly no longer UTC (just assumed to be so).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions