Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: Time information lacks timezone info #525

Open
encukou opened this Issue Feb 16, 2019 · 7 comments

Comments

Projects
None yet
2 participants
@encukou
Copy link
Member

encukou commented Feb 16, 2019

Currently, the API assumes the Czech timezone. This doesn't scale.
Update all time information in the API to include the timezone.

@encukou

This comment has been minimized.

Copy link
Member Author

encukou commented Feb 16, 2019

The format should go from %Y-%m-%d %H:%M:%S to %Y-%m-%d %H:%M:%S%z (in terms of Python strftime).

@messa

This comment has been minimized.

Copy link
Contributor

messa commented Feb 17, 2019

I'd prefer ISO 8601: %Y-%m-%dT%H:%M:%SZ

For example 2019-02-17T01:44:15Z

The letter Z should be capital.

@messa

This comment has been minimized.

Copy link
Contributor

messa commented Feb 17, 2019

In this use case there are two challenges:

  1. provide the datetime value in an unambiguous way
    • for example Meetup.com API provides time: UTC start time of the event, in milliseconds since the epoch
    • but I think the ISO 8601 datetime (always using UTC, or at least UTC offset) is better alternative than (milli)seconds since epoch
  2. identify local timezone to correctly display start/end times for humans
    • could be timezone name e.g. Europe/Prague
    • for example Meetup.com API provides utc_offset: The local offset from UTC time, in milliseconds
@encukou

This comment has been minimized.

Copy link
Member Author

encukou commented Feb 17, 2019

ISO 8601 is a big standard :) %Y-%m-%d %H:%M:%S%z is a ISO 8601 datetime. It's also what Python's isoformat() gives you and (importantly) what the 3.7+ fromisoformat() can parse (unlike Z).
I also like the fact that if the session starts at six, it would actually show up as 18:00+blabla in the API.

I like the suggestion of separate timezone info. Let's add that as well, maybe for the whole course? It has info about daylight savings time, which isn't present in the UTC offset.

@messa

This comment has been minimized.

Copy link
Contributor

messa commented Feb 17, 2019

Oh, I did not see the %z in the format, I thought it is just z.

Anyway, Python isoformat() gives you the format with T separator:

>>> datetime.utcnow().isoformat()
'2019-02-17T13:18:56.509684'
>>> pytz.utc.localize(datetime.utcnow()).isoformat()
'2019-02-17T13:19:03.630694+00:00'

It can also be parsed with fromisoformat() - it doesn't support Z (although it is apparently part of the ISO 8601), but at least supports +00:00:

>>> datetime.fromisoformat('2019-02-17T13:19:03.630694+00:00')
datetime.datetime(2019, 2, 17, 13, 19, 3, 630694, tzinfo=datetime.timezone.utc)
>>> datetime.fromisoformat('2019-02-17T13:19:03+00:00')
datetime.datetime(2019, 2, 17, 13, 19, 3, tzinfo=datetime.timezone.utc)

OK, let's use localized datetimes:

>>> pytz.timezone('Europe/Prague').localize(datetime.now().replace(microsecond=0)).isoformat()
'2019-02-17T14:24:04+01:00'
@messa

This comment has been minimized.

Copy link
Contributor

messa commented Mar 8, 2019

I hope I haven't disturbed anything too much :) Any format that includes + or Z is OK in the end. Should I help with anything?

@encukou

This comment has been minimized.

Copy link
Member Author

encukou commented Mar 10, 2019

Not needed, just keep it in mind. I want to do this before API 1.0, but it's not really blocking anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.