Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jiffy.parse ignores Z timezone suffix in ISO 8601 date/time string #281

Open
lukehutch opened this issue Jul 2, 2024 · 5 comments
Open

Comments

@lukehutch
Copy link

Describe the bug

final timestamp = '2024-07-02T08:07:50Z';

final a = DateTime.parse(timestamp);
// a = DateTime (2024-07-02 08:07:50.000Z)

final b = DateTime.parse(timestamp).toUtc();
// b = DateTime (2024-07-02 08:07:50.000Z)

final c = Jiffy.parse(timestamp).dateTime;
// c = DateTime (2024-07-02 08:07:50.000)

final d = Jiffy.parse(timestamp).dateTime.toUtc();
// d = DateTime (2024-07-02 14:07:50.000Z)

In c, the timezone is missing, even though the Z suffix is present in the string timestamp.

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.

@jama5262
Copy link
Owner

jama5262 commented Jul 3, 2024

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

@jama5262
Copy link
Owner

jama5262 commented Jul 3, 2024

Please do reopen this issue if the above solution did not solve your problem

@jama5262 jama5262 closed this as completed Jul 3, 2024
@lukehutch
Copy link
Author

@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.

@jama5262 jama5262 reopened this Jul 3, 2024
@jama5262
Copy link
Owner

jama5262 commented Jul 3, 2024

@lukehutch Understandable, yeah Jiffy should automatically detect it

Will work on a fix 👍

@lukehutch
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants