0

aye aye good people, I'm really confused about the behavior of DateTime.parse();

on dartpad this works

void main() {
      const String _iso8601 = '2019-04-01T08:30:00';
      final DateTime _date = DateTime.parse(_iso8601);
        print(_date.toIso8601String());
}

but in flutter doesn't, but this does

      const String _iso8601 = '2019-04-01T08:30:00.000';
      final DateTime _date = DateTime.parse(_iso8601);

I'm now in aqueduct and neither of those works including this

String _iso8601 = '2019-04-01T08:30:00Z';

please note that with "didn't work" I don't mean that it returns an error, but just a null.

[edit: correction

when I mock the string instead of mapping it from the body of a request it returns

Exception has occurred. FormatException (null)

but then again I'm using Iso8601]

If you have some experience with this situation I could use some help.

[edit: note that aqueduct runs on dart 2.0]

Thank you in advance, Francesco

Francesco Iapicca
  • 2,618
  • 5
  • 40
  • 85

1 Answers1

0

Examples of accepted strings:

"2012-02-27 13:27:00"
"2012-02-27 13:27:00.123456z"
"2012-02-27 13:27:00,123456z"
"20120227 13:27:00"
"20120227T132700"
"20120227"
"+20120227"
"2012-02-27T14Z"
"2012-02-27T14+00:00"
"-123450101 00:00:00 Z": in the year -12345.
"2002-02-27T14:00:00-0500": Same as "2002-02-27T19:00:00Z"
user3907398
  • 16
  • 1
  • 2
  • yeah, it doesn't seams to be the problem, I've looked at the docs, the closest to what I get from the API is the last one I tred with a "Z" at the end, I've tried with ".000" milliseconds... nothing changes – Francesco Iapicca Apr 18 '19 at 11:29
  • do the opposite create a date in flutter and print toIso8601String to see what it looks like – user3907398 Apr 18 '19 at 12:09
  • in flutter and dartpad returns this "'2019-04-01T08:30:00.000'" which is consistent with the behavior observed in flutter (darpad is even more flexible, for reasn that I don't understand); I haven't check on aqueduct but I'm assuming that should return the same... but since doen't parse it I might take a look – Francesco Iapicca Apr 18 '19 at 12:20