Time.now vs Time.current vs DateTime.now

I always use UTC anywhere except decorators and view. Time zone is overthinking in logic. It must be implemented in view or decorator.

2 Likes

I find this makes it easier to understand. If Time.now was suddenly time zone aware that would throw me off. I would not change this.

We moved the server’s time zone to local time since we’re fully located in one city, and we can run queries on data with dates (e.g. inside Rails console connected with a read-only connection to production) and get back the actual times that things happened. That might just be what we’re used to (and every so often we get bit by the difference between what’s in the DB and what Rails gets out of it) but on the whole it makes it easier, especially for new devs.

1 Like

On a related note, anybody find themselves wishing that Rails’ default DateTime formats were commented out in app/config/initializers/time_formats.rb for easy reference?

3 Likes

@ferngus I would be delighted if you submitted a PR for that, I can’t count the number of times I’ve googled that.

I’ll do that :slight_smile:

https://github.com/rails/rails/pull/39484

For date formatting, I wrote this Ruby gem based on Go’s date formatting Date By Example, and I like it quite a bit.

1 Like