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

Add time comparison guideline #357

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add time comparison guideline #357

wants to merge 1 commit into from

Conversation

pirj
Copy link
Member

@pirj pirj commented Jul 26, 2024

past?/future?

Noteable offenders:

- if reminder_at < Time.zone.now
+ if reminder_at.past?
- sleep 1 if alarm_at > Time.zone.now
+ sleep 1 if alarm_at.future?

Rails docs:

Secondary, informative section:

Introduction of before?/after? in Rails 6.0.

before?/after? didn't make to this guideline due to insufficient use, and it would go against our:

A style guide that reflects real-world usage gets used, and a style guide that holds to an ideal that has been rejected by the people it is supposed to help risks not getting used at all - no matter how good it is.

- last_archival_attempt_at + backoff < Time.current
+ last_archival_attempt_at.before? backoff.from_now

@pirj pirj self-assigned this Jul 26, 2024
README.adoc Outdated
[source,ruby]
----
# bad
created_at < 5.minutes.ago
Copy link
Contributor

Choose a reason for hiding this comment

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

A concern I have is that people are used to < in a SQL query involving dates, and so it feels natural to use it in Rails too.

I agree that before?/after? is a better and more natural API but it might be a step too far to mandate this.

README.adoc Outdated
shutdown_at.after?(1.minute.from_now)
----

Use `past?` and `future?` when comparing with the current time.
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 totally agree with this part.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm fine with doing the prime time for past?/future?, and just briefly mentioning before?/after? below the main section with no guidance to use. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed.

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.

2 participants