Skip to content

Datetime timezone handling.#39

Closed
JNRowe wants to merge 9 commits intomasterfrom
5438e41d9c390f53089ed3fa0842831fafc73d8e
Closed

Datetime timezone handling.#39
JNRowe wants to merge 9 commits intomasterfrom
5438e41d9c390f53089ed3fa0842831fafc73d8e

Conversation

@JNRowe
Copy link
Collaborator

@JNRowe JNRowe commented Jun 20, 2011

Feeble brainstorming session...

I've just been bitten quite badly by the lack of timezone handling, the cause is the use of naive datetime objects in the 'GitHub' timezone(America/Los_Angeles). While processing some tasks that span the PST/PDT changeover the ordering of events is broken.

Options are:

  1. Leave alone and try to process the datetime objects externally, somewhat easy but not a good solution as it requires duplication in each project that requires accurate date handling
  2. Start producing non-naive datetime objects, breaks any caller who is not prepared for it.
  3. Introduce a setting to toggle naive object availability, defaulting to naive objects to maintain backwards compatibility

python-dateutil makes handling option 1 quite easy, and also simplifies the handling of option 3 at the cost of another external dependency. Option 2 is just pure evil, or pure stupidity depending on point of view.

Option 3 results in a parsing using something like the following entirely untested code:

datetime_ = parser.parse(github_date)
if NAIVE:
    datetime_.replace(tzinfo=None)
return datetime_

And similarly producing GitHub compatible date strings would require handling of naive formats with equally untested code such as:

if NAIVE:
    datetime_ = datetime_.replace(tz.gettz("America/Los_Angeles"))
return datetime_.strftime("%Y/%m/%d %H:%M:%S %z")

@JNRowe
Copy link
Collaborator Author

JNRowe commented Apr 18, 2011

The lack of timezone handling also exhibits itself for any consumers who use a timedelta to convert to local time for the duration of any gap between GitHub's switch to DST and their own. On the order of 2-4 weeks a year for regions that I personally care about ;)

@JNRowe
Copy link
Collaborator Author

JNRowe commented Apr 30, 2011

First-run implementation of option 3 from above. Works, but needs some refactoring.

@JNRowe
Copy link
Collaborator Author

JNRowe commented May 29, 2011

With the pull request merge there is a new issue of handling timezones because pull requests don't use the "GitHub timezone".

@JNRowe
Copy link
Collaborator Author

JNRowe commented Jun 20, 2011

The mostly new commits now listed in this pull request(JNRowe/python-github2 feat/timezone_support) are what I'm planning to merge RSN.

@JNRowe JNRowe closed this in 3e39abe Jun 23, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant