Feature request: Modify TimeWithZone#as_json to take in an option to exclude decimal fractions

Currently the TimeWithZone#as_json always returns 3 decimal points. However, the ISO 8601 standard also supports no decimal point format.

It would be great to add an option to the as_json method to not include decimals. This would have several advantages.

  • By default, it still returns 3 decimal points. This is the widely used (e.g. by major browsers, Chrome, FF, Safari) option.
  • It would support the no decimal point format part of the ISO 8601 standard.
  • It allows Rails can communicate with APIs that is expecting no decimal formats when needed.

This appears to be possible on an application-wide basis as of 4.1.0:


—Matt Jones