Skip to content
This repository was archived by the owner on Jun 8, 2026. It is now read-only.
This repository was archived by the owner on Jun 8, 2026. It is now read-only.

Convert query start and end time to UTC #16

Closed

Description

@dentarg

The API uses UTC, so we can help the user by converting the supplied start_time and end_time to UTC, so the user doesn't have to think about it.

References

Activity

  1. self-assigned this
    on Feb 22, 2016
  2. roback commented on Feb 22, 2016

    @roback
    Member

    Python has two "types" of datetime objects, one with and one without timezone information. The one without timezone seems to be the default:

    >>> print datetime.datetime.strptime("2016-01-01 10:11:50 UTC", "%Y-%m-%d %H:%M:%S %Z").tzinfo
    None
    >>> print datetime.datetime.now().tzinfo
    None

    How should we treat datetimes without timezone? Issue a warning and interpret it as UTC?

  3. dentarg commented on Feb 22, 2016

    @dentarg
    ContributorAuthor

    I think we should require the timezone information, so we can make a correct conversion. I don't think we have that many (if any) users of this client yet, so we won't be breaking anyones expectations.

  4. dentarg commented on Feb 22, 2016

    @dentarg
    ContributorAuthor

    This is kinda strange though

    >>> print datetime.datetime.utcnow().tzinfo
    None

    Is it a lot of work to use date and time with timezone information in Python? Hmm... we also want it to be easy to use the client, but by requiring timezone info we might make it harder.

  5. roback commented on Feb 22, 2016

    @roback
    Member

    I think the first of my tests above is weird too. I explicitly added UTC to the date, but .tzinfo is None.

  6. dentarg commented on Feb 22, 2016

    @dentarg
    ContributorAuthor

    https://docs.python.org/2/library/datetime.html#datetime.tzinfo is a good read

    An object of type time or datetime may be naive or aware.

    Good distinction. Now on to how to use it...

    datetime.now([tz]) can take "an instance of a class tzinfo subclass" as argument...

    ...but it seems like you have to create that class yourself, see examples at https://docs.python.org/2/library/datetime.html#tzinfo-objects. So it seems like you have to work a bit.

    http://stackoverflow.com/questions/17976063/how-to-create-tzinfo-when-i-have-utc-offset suggests

    If you can, take a look at the excellent dateutil package instead of implementing this yourself.

    Could be worth looking into. Perhaps it's enough having examples using dateutil.

  7. dentarg commented on Feb 22, 2016

    @dentarg
    ContributorAuthor

    Perhaps it's enough having examples using dateutil.

    And our tests :)

  8. roback commented on Feb 22, 2016

    @roback
    Member

    I saw that pytz was mentioned in a few places too.

  9. dentarg commented on Feb 22, 2016

    @dentarg
    ContributorAuthor

    Yeah, that seems good too, looks like that's what django uses. I guess these library creates general Python objects so the user could choose to use any of them?

  10. roback commented on Feb 22, 2016

    @roback
    Member

    We have to add one of the above packages as a dependency since we should include the timezone in Post#published and Post#indexed:

    self.published = datetime.datetime.strptime(params['published'], '%Y-%m-%d %H:%M:%SZ')
    self.indexed = datetime.datetime.strptime(params['indexed'], '%Y-%m-%d %H:%M:%SZ')

  11. dentarg commented on Feb 22, 2016

    @dentarg
    ContributorAuthor

    Yeah, that's true.

  12. added a commit that references this issue on Feb 23, 2016
    eefc478
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions