question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ISO8601 time string with a Z comes out with +00:00 after load and then dump

See original GitHub issue

When using the fields.DateTime and a value "2018-07-25T00:00:00Z". Loading and then dumping that data should result in the exact same value for that field. But it doesn’t. What is dumped back out is "2018-07-25T00:00:00+00:00". This is not technically a different time, but I think I should be able to serialize/deserialize data and not have it be altered from the voyage.

datetime strings are really difficult with python. My sympathies.

I’m going to try to make a subclass of field that does only what I want for tz-aware iso8601 strings and isn’t as broad as fields.DateTime. I’ll post it back for reference.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
deckar01commented, Jul 25, 2018

Loading and then dumping that data should result in the exact same value for that field. But it doesn’t.

It is the same value with different encodings. Z and +00:00 are equivalent.

import dateutil

dt = dateutil.parser.parse('2018-07-25T00:00:00Z')
dt.tzinfo()
# tzutc()
dt.isoformat()
# 2018-07-25T00:00:00+00:00

dateutil’s parser is passing the timezone correctly and datetime.isoformat() is allowed to represent Z as +00:00. If you are interfacing with a system that doesn’t accept +00:00 as a timezone, it probably isn’t compliant. Otherwise it is a personal preference that can be achieved with a custom format.

0reactions
sloriacommented, Jul 14, 2019

Given the current design, there isn’t a good way outside of passing format to DateTime that ensures that the input and output format are exactly the same. If you need more complex logic that format, a custom field is the way to go.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ISO 8601 date-time format combining 'Z' and offset of '+0000'
No, not OK. No, the Z is an offset-from-UTC so it should not be combined redundantly with a numerical offset of +00:00 or...
Read more >
TO_UTC_TIMESTAMP_TZ - Oracle Help Center
The SQL function TO_UTC_TIMESTAMP_TZ takes an ISO 8601 date format string as the varchar input and returns an ... Z specifies UTC time...
Read more >
Class: Time (Ruby 2.6.3)
It can be an offset from UTC, given either as a string such as “+09:00” or as a number of seconds such as...
Read more >
A simple PHP API extension for DateTime. - Carbon
Carbon - A simple PHP API extension for DateTime.
Read more >
strptime: Date-time Conversion Functions to and from Character
A character string specifying the time zone to be used for the conversion. ... exception strings such as 24:00:00 are accepted for input,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found