Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add time comparison guideline #357

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

Open
pirj wants to merge 2 commits into master
base: master
Choose a base branch
Loading
from time-comparison
Open

Add time comparison guideline #357

pirj wants to merge 2 commits into master from time-comparison

Conversation

@pirj
Copy link
Member

@pirj pirj commented Jul 26, 2024
edited
Loading

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

bbenno reacted with thumbs up emoji
@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.

pirj and bbenno reacted with thumbs up emoji
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.

pirj reacted with thumbs up emoji
@pirj pirj requested review from andyw8 and koic July 29, 2024 20:02
@pirj pirj requested a review from a team July 30, 2025 16:11
README.adoc Outdated
public_release_at.future?
----

NOTE: Rails 6.0 and later also provide `before?` and `after?` methods to compare two arbitrary time objects.
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's remove since Rails 6.0 has been EOL over 2 years?

pirj reacted with thumbs up emoji
Copy link
Contributor

Choose a reason for hiding this comment

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

pirj reacted with heart emoji
It’s available all supported version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@andyw8 andyw8 andyw8 approved these changes

@koic koic Awaiting requested review from koic

Assignees

@pirj pirj

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

AltStyle によって変換されたページ (->オリジナル) /