Open lukehutch opened 4 months ago
Hey @lukehutch , that's correct. By default, Jiffy parses the timestamp as local time. To parse a UTC string as UTC, you need to tell Jiffy
that the string you are parsing is a UTC by setting the isUtc
variable to true
, like this:
final timestampUtc = '2024-07-02T08:07:50Z';
final c = Jiffy.parse(timestampUtc, isUtc: true);
print(c.isUtc); // this will print true
You can find more info about string parsing here https://github.com/jama5262/jiffy/tree/master/doc#string-formatting
Hope this solves your issue
Please do reopen this issue if the above solution did not solve your problem
@jama5262 then Jiffy does not conform to even a useful subset of the ISO 8601 standard! And the user does not even get a warning that their date was parsed wrongly. The Z
is the correct way to specify a UTC date, not a Boolean argument! The boolean argument is only necessary if there is some non-confoemant system that does not specify the Z
. The Z
should not be silently ignored!
I don't have a way to reopen this, but it needs to be reopened. This is a horrible bug, and the "solution" is not a solution.
If you insist that Jiffy should not detect the Z
(which would be a very, very bad idea), then at least please throw an exception if the date ends in Z
, otherwise you are going to create really bad bugs in user code. It took days to find the source of this bug in my own system.
@lukehutch Understandable, yeah Jiffy should automatically detect it
Will work on a fix 👍
ISO 8601 is a large standard, but this is an important part of it.
Since you agreed to work on a fix (thank you), the other important part is to parse the +
/-
timezone suffix. That really needs to be done too.
Describe the bug
In
c
, the timezone is missing, even though theZ
suffix is present in the stringtimestamp
.Consequently, the
DateTime
is created in the local timezone (by the looks of it). This leads to conversion to UTC being wrong (d
).Jiffy 6.3.1.