[Proposal][Feature Request] Human-readable DateTime comparisons

26 views
Skip to first unread message

Andrew Allen

unread,
Sep 29, 2016, 4:31:01 PM9/29/16
to Ruby on Rails: Core
Hi there,

For some reason, comparing dates/times with < and > confuses my brain and has resulted in me second-guessing my code, and accidently inverting my time comparison logic.

What I was looking for was a method on DateTime so that I could do comparisons like: some_time.more_recent_than?(another_time) or some_time.comes_after?(another_time).

Since there were no methods like that in ActiveSupport, I created a gem: https://github.com/allenan/human_time. It's already helped me a lot in my code, and I've gotten positive feedback on it on GitHub (113 stars and 1 contribution to date) and on Twitter.

I'd be happy to submit a PR that adds some of those methods to ActiveSupport if that would be a valuable addition.

Andrew

Xavier Noria

unread,
Sep 30, 2016, 3:53:39 AM9/30/16
to rubyonrails-core
Wouldn't put this in AS, really.

Albeit I understand that you find comparing dates and times confusing, the arrow of time from left to right is intuitive and matches the ordering defined in the classes quite naturally I'd say. Also, it is the ordering for these kind of data types you find in SQL and virtually anywhere else.

Not saying you should not find it confusing, not at all, that is very personal, only explaining why I don't see it in AS. A gem is better here in my view.

Reply all
Reply to author
Forward
0 new messages