Skip to content

Conversation

@roelandvanbatenburg
Copy link
Contributor

During our upgrade to Elixir 1.18 we got some compile warnings about the usage of == on DateTime structs. https://hexdocs.pm/elixir/1.18.1/DateTime.html suggested using compare/2 which led to replacing

  if user.password_reset_token_sent_at > oldest_allowed_token_datetime do

with

  if DateTime.compare(user.password_reset_token_sent_at, oldest_allowed_token_datetime) == :gt do

However, a far better solution is:

  if DateTime.after?(user.password_reset_token_sent_at, oldest_allowed_token_datetime) do

To make it easier for developers to think of these functions (after? and before?), I suggest mentioning them alongside compare/2.

@josevalim josevalim merged commit 13baeb5 into elixir-lang:main Jan 6, 2025
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

@josevalim
Copy link
Member

This may also apply to the docs in Date, Time, and NaiveDateTime. If that's the case, please submit a PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants