Evidently when using DateTime objects in ASP.NET core, JSON.Net serializes them out with 7 digits of accuracy.
Example:
"registrationDate": "2019-05-30T09:21:05.1676144-04:00",
or
"registrationDate": "2019-05-30T15:34:04.0929048Z",
In Dart pad:
var t = DateTime.parse('2019-05-30T15:34:04.0929048Z');
yields:
Uncaught exception:
FormatException: Invalid date format
2019-05-30T15:34:04.0929048Z
but when I trim the last digit (an '8'):
var t = DateTime.parse('2019-05-30T15:34:04.092904Z');
yields:
2019-05-30 15:34:04.093Z
When consuming them in Dart from an API, Dart only accepts six digits of accuracy and throws an error when it encounters the 7th digit.
Here's the link to the Dart docs: https://api.dartlang.org/stable/2.3.1/dart-core/DateTime/parse.html
Here's the relevant code from their docs:
int parseMilliAndMicroseconds(String matched) {
if (matched == null) return 0;
int length = matched.length;
assert(length >= 1);
assert(length <= 6);
It's unlikely there'll be a fix any time soon on the Dart side, as it's a pretty fundamental library.
So, can anyone tell me how to have my ASP.NET Core API reduce the accuracy by one digit? These dates are everywhere in the system, and it would be really great if I could just change the formatted output from one spot.
I guess an alternative would be to write a JsonConverter
but I really don't want to do that for every class.
Ideas?
TIA