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

Support ISO8601 without timezone #31

Merged
merged 3 commits into from
Apr 22, 2024

Conversation

axelson
Copy link
Contributor

@axelson axelson commented Apr 20, 2024

Extends Machete.ISO8601DateTimeMatcher to support ISO8601 timestamps without a timezone (such as those that NaiveDateTime.to_iso8601/1 creates.

Fixes #30

After this PR this is the behavior we get:

NaiveDateTime.to_iso8601(NaiveDateTime.utc_now()) ~>>
  Machete.ISO8601DateTimeMatcher.iso8601_datetime(roughly: :now) == []

Comment on lines 96 to 100
_ ->
case NaiveDateTime.from_iso8601(b) do
{:ok, naive_datetime_b} -> naive_datetime_b ~>> naive_datetime(a.datetime_opts)
_ -> mismatch("#{inspect(b)} is not a parseable ISO8601 datetime")
end
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ends up possibly matching naive 8601s when you otherwise may not have meant to (TBH, I'd never realized 8601s were valid without a timezone until you brought it up!). I agree that this belongs in this matcher, but maybe hidden behind a flag? 8601 calls that last component an 'offset', so maybe something like offset_required, defaulting to true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that makes sense, I've now added it as an option 👍

@mtrudel
Copy link
Owner

mtrudel commented Apr 22, 2024

Looks great! Thanks Jason!

@mtrudel mtrudel merged commit 19dbb54 into mtrudel:main Apr 22, 2024
9 checks passed
@mtrudel
Copy link
Owner

mtrudel commented Apr 22, 2024

Published as 0.3.1

@axelson axelson deleted the iso8601-without-timezone branch April 22, 2024 15:21
@axelson
Copy link
Contributor Author

axelson commented Apr 22, 2024

Awesome, thanks!

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

Successfully merging this pull request may close these issues.

Feature request: ISO 8601 naive date time matcher support
2 participants