time_machine
time_machine copied to clipboard
Error when parsing date with timezone offset
Hello! I'm trying to parse date time with timezone offset:
await TimeMachine.initialize({'rootBundle': rootBundle});
var localClone =
ZonedDateTimePattern.createWithInvariantCulture('yyyy-MM-ddTHH:mm z')
.parse("2024-01-31T06:13 +02:00");
And get the following error:
E/flutter (13788): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: The specified time zone identifier is not recognized. Value being parsed: '2024-01-31T06:13 ^+02:00'. (^ indicates error position.)
E/flutter (13788): #0 ParseResult.getValueOrThrow (package:time_machine/src/text/parse_result.dart:62:5)
E/flutter (13788): #1 ParseResult.value (package:time_machine/src/text/parse_result.dart:36:18)
E/flutter (13788): #2 main (package:alean_travel/main.dart:45:20)
E/flutter (13788): <asynchronous suspension>
What a proper way to parse date with offset?
This should work:
final localClone = OffsetDateTimePattern.createWithInvariantCulture(
"uuuu'-'MM'-'dd'T'HH':'mm o<Z+HH':'mm>",
).parse("2024-01-31T06:13 +02:00");