Binary Logic
Binary Logic

Reputation: 1547

Setting Date.today to use Time.zone?

Since Date.today uses the system time, what's the best way possible to have it return the same thing as Time.zone.now.to_date, assuming Time.zone is set?

I know I can override the Date class, but wasn't sure if there was some other Ruby convention I'm missing since I'm sure I'm not the first person to encounter this problem.

Upvotes: 0

Views: 242

Answers (1)

Andrew Marshall
Andrew Marshall

Reputation: 96914

You’re looking for Date.current, which calls Time.zone.today if Time.zone is set. This is Date’s equivalent of Time.current (there’s also DateTime.current).

Also remember that none of these methods are in Ruby core, but are instead provided by ActiveSupport.

Upvotes: 3

Related Questions