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
Modify TimeWithZone#as_json to return 3DP of sub-second accuracy. #9128
Conversation
…efault, since it's allowed by the spec and is very useful.
Modify TimeWithZone#as_json to return 3DP of sub-second accuracy.
And improve AS changelog a bit [ci skip]
* master: Skip schema dumper extensions test if connection does not support it active_record: Quote numeric values compared to string columns. Run schema dumper extensions without creating real extensions Do not print anything related to extensions when they don't none exist Add blank line after extensions to separate from tables in schema Fix indentation of extensions in schema Call super to use the abstract adapter implementation instead Add changelog entry for #9203 about schema dumper with db extensions add ActiveRecord::AbstractAdapter#extensions and ActiveRecord::ConnectionAdapters::PostgreSQLAdapter#extensions to allow dumping of enabled extensions to schema.rb, add ActiveRecord::SchemaDumper#extensions to dump extensions to schema.rb improve tests to check for existence of extensions method, and skip testing dumped extensions if they are unsupported by the database Add some tests to enumerate how extensions should be stored in the schema output Update changelog from #9128 with author name Update actionpack/CHANGELOG.md ruby constant syntax is not supported as routing `:controller` option. Fix article for generator name Update .gitignore Enable hstore extensions on tests if it is not enabled and database supports it Ignore .ruby-version Modify TimeWithZone#as_json to return 3DP of sub-second accuracy by default, since it's allowed by the spec and is very useful.
|
If the extra 3 decimal places is optional why is rails making it default? Seems like something that should be optional based on the ISO8601 spec. |
|
Because if the object in question has sub-second accuracy, then it would make sense to serialize it, rather than lose data. |
|
It is odd that only https://github.com/rails/rails/blob/master/activesupport/lib/active_support/json/encoding.rb#L319 I suggest that it be configurable and consistent across all the time types. |
|
+1 to having some way of excluding the milliseconds. We have to monkey patch this as we have clients that are expecting to parse the output that doesn't have milliseconds. |
|
Please do not comment on PRs that were closed months ago, or add +1 comments in general. They do not give anything to the community nor will they cause changes to occur. Feature requests should be made on the rails-core mailing list |
The ISO8601 spec says that decimal fractions may be added for the seconds (actually any) value. The default in recent versions of Firefox, Chrome and Safari (that I have tested) all return 3 decimal places of accuracy for seconds for their default serialisation:
I ran into this in an app using rails-api/active_model_serializers, and initially intended to submit a PR there, but soon discovered that it uses ActiveSupport's default JSON encodings.
It's a very simple change, so I've updated the one test for this method and added a changelog entry. Tests pass on my machine. Please let me know if there's anything I've missed and I'll clean it up immediately.