How do I calculate the next occurrence of a time 04:00 am EST?
datetime, ruby, ruby-on-rails, ruby-on-rails-3
Solution
Try following
time = if Time.now.hour >= 4
Time.now+1.day
else
Time.now
end
time.strftime("%Y-%m-%d 04:00:00").to_datetime
OR Just
(Time.now+(Time.now.hour >= 4 ? 1 : 0).day).strftime("%Y-%m-%d 04:00:00").to_datetime
Problem
What is an efficient way to get the next occurrence of 04:00 am EST? For example, if the date and time is 2013/11/19 01:30:00 then next occurrence would be 2013/11/19 04:00:00, however if it is 2013/11/19 17:00:00 then next occurrence would be 2013/11/20 04:00:00