Skip to content

Conversation

@roelandvanbatenburg
Copy link
Contributor

Similar to #14147

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:

elixir
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?/2` and `before?/2`), I suggest mentioning them alongside `compare/2`.

@josevalim josevalim merged commit 9256143 into elixir-lang:main Jan 7, 2025
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

@roelandvanbatenburg roelandvanbatenburg deleted the mention_alternatives_to_compare branch January 7, 2025 07:18
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.

3 participants