I have a default time zone setup for the rails application. And an instance of the Date object.
How can I get make Date#beginning_of_day to return the beginning of the day in the specified time zone, but not my local timezone.
Is there any other method to get beginning of the day time in the specified timezone for the given date?
date = Date.new(2014,10,29)
zone = ActiveSupport::TimeZone.new('CET')
date.foo(zone) # should return "Wed, 29 Oct 2014 00:00:00 CET +01:00"
zone = ActiveSupport::TimeZone.new('UTC')
date.foo(zone) # should return "Wed, 29 Oct 2014 00:00:00 UTC +00:00"
As Leonid Shevtsov mentioned,
Date.beginning_of_day
does not honorTime.zone
in ActiveSupport 2.3An alternative I used, if your stuck using Rails 4.0 or ActiveSupport 2.3, and you need to use a custom date:
Results:
My original failed model scope using .beginning_of_day to .end_of_day failed to work:
And, this is what fixed it, since I could not upgrade to Rails 4.0