mtrudel/machete

Feature request: ISO 8601 naive date time matcher support

axelson opened this issue · 0 comments

Machete has two DateTime matchers for structs:

  • Machete.DateTimeMatcher
  • Machete.NaiveDateTimeMatcher

But only one for strings:

  • Machete.ISO8601DateTimeMatcher

Thus if you have a string like "2024-04-18 18:16:12.481210" then you can't use a machete matcher on it. If we're following the same pattern then we'd want to introduce a Machete.ISO8601NaiveDateTimeMatcher that can parse ""2024-04-18 18:16:12.481210".

Although instead of creating a whole new matcher it also might make sense to consider extending Machete.ISO8601DateTimeMatcher to match ISO8601 strings without a timezone so this could match, right now this is the behavior Machete has:

iex(8)> NaiveDateTime.to_iso8601(NaiveDateTime.utc_now()) ~>> Machete.ISO8601DateTimeMatcher.iso8601_datetime(roughly: :now)
[
  %Machete.Mismatch{
    path: [],
    message: "\"2024-04-20T19:37:31.381743\" is not a parseable ISO8601 datetime"
  }
]

Instead I'm proposing this:

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