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

Don't strip microseconds in JSON output. #4256

Merged
merged 1 commit into from
Jul 11, 2016

Conversation

tomchristie
Copy link
Member

Closes #4255.

@tomchristie tomchristie added this to the 3.4.0 Release milestone Jul 11, 2016
@codecov-io
Copy link

Current coverage is 91.23%

Merging #4256 into master will increase coverage by 0.03%

@@             master      #4256   diff @@
==========================================
  Files            52         52          
  Lines          5778       5776     -2   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
  Hits           5270       5270          
+ Misses          508        506     -2   
  Partials          0          0          

Powered by Codecov. Last updated by 7bfa5a9...9164c3b

@tomchristie tomchristie merged commit 549210b into master Jul 11, 2016
@tomchristie tomchristie deleted the millisecond-json-representation branch July 11, 2016 13:34
@kevin-brown
Copy link
Member

There was a relevant comment in the original patch about why the microseconds are being truncated. It appears to have been lost throughout the years.

For Date Time string spec, see ECMA 262
http://ecma-international.org/ecma-262/5.1/#sec-15.9.1.15

Which appears to have been copied out of the Django JSON serializer.

In ECMA 262, the datetime string format is defined as YYYY-MM-DDTHH:mm:ss.sssZ, with only 3 decimal precision.

@tomchristie
Copy link
Member Author

The JSON spec has no guidance on datetime formatting. https://tools.ietf.org/html/rfc7159

The current default is for DateTimeField to coerce to strings, so .ssssss is our current behavior unless you explicitly return a datetime, or unless you've set DATETIME_FORMAT to None in the settings.

This change ensures that we're consistent throughout. Users can still set DATETIME_FORMAT if they want a different behavior.

@tomchristie
Copy link
Member Author

But yes, very much wasn't sure on that when you re-raised. And there is the reading should be that JSON should be a subset of ECMA, but that seems pretty loose, stated as a design goal rather than a requirement. (and it's also not quite a subset)

xordoquy added a commit that referenced this pull request Feb 14, 2017
carltongibson added a commit to carltongibson/django-rest-framework that referenced this pull request Sep 22, 2017
Closes encode#4749.

This is the matching commit to the fix for `datetime` in encode#4256
carltongibson added a commit that referenced this pull request Sep 25, 2017
Closes #4749.

This is the matching commit to the fix for `datetime` in #4256
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants