Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Date.current and Date.today?

They both seem to do the same thing. I'm just worried that one uses timezones differently to the other.

like image 533
Anon Avatar asked Jul 09 '11 14:07

Anon


2 Answers

See Rails code, line 40 here.

# Returns Time.zone.today when <tt>Time.zone</tt> or <tt>config.time_zone</tt> are     set, otherwise just returns Date.today.   def current     ::Time.zone ? ::Time.zone.today : ::Date.today   end 

So If you defined a timezone, you'll get a zoned Date otherwise you'll get Date.today.

BTW there is no Date.now

like image 153
apneadiving Avatar answered Oct 13 '22 07:10

apneadiving


If you're doing comparisons you should always use Date.current

This is because if you're in a timezone that could be in a different day than UTC, and your timezone isn't set then you can have the situation where Date.today == Date.tomorrow

like image 26
Sean Avatar answered Oct 13 '22 08:10

Sean