riverrun / phauxth_installer

No longer maintained - Installer for the Phauxth authentication library
13 stars 4 forks source link

Avoid ">" operator for datetimes? #15

Closed michaeljones closed 4 years ago

michaeljones commented 4 years ago

I've been using Phauxth on my project and one of the auto-generated session tests started failing today. This one:

https://github.com/riverrun/phauxth_installer/blob/master/phauxth_new/templates/sessions_test.exs#L18-L21

And it seems that it is possibly because of this line:

https://github.com/riverrun/phauxth_installer/blob/master/phauxth_new/templates/sessions.ex#L18

I'm a beginner but it seems from some reading that it is preferable to use DateTime.compare for dates rather than > as the normal comparison operators do date-unaware struct comparisons on the DateTime structs and produce confusing results.

I guess it is possible to write this as:

      Enum.filter(sessions, &(DateTime.compare(&1.expires_at, DateTime.utc_now()) == :gt))

Instead? Or possibly move the expiry check into an Ecto query?

mtrudel commented 4 years ago

I get this too. I'll whip up a quick PR.

mtrudel commented 4 years ago

See https://github.com/riverrun/phauxth_installer/pull/16