Time.now vs Time.current vs DateTime.now

I am not sure about blanket advice here. Time.now can be fine provided your config is config.time_zone = 'UTC' and don’t need ActiveSupport::TimeWithZone . At Discourse for example everything on the server is UTC and client side is in charge of per user time zones like this control for example: 2020-02-11T23:58:00Z

We have made some progress around getting away without TimeWithZone at https://bugs.ruby-lang.org/issues/14850

@Andrew_White any more advice here?

An interesting aside is that we find databases losing fidelity to be a far more annoying issue, in fact we have a custom rubocop rule just to make sure we do time comparisons the right way https://github.com/discourse/rubocop-discourse/blob/master/lib/rubocop/cop/discourse/time_eq_matcher.rb

7 Likes