John Hinnegan
2011-Aug-18 05:18 UTC
Please explain how Today and Tomorrow work (TimeZone?)
ruby-1.9.2-p180 :022 > range = Date.today.beginning_of_day..Date.today.end_of_day => Wed, 17 Aug 2011 00:00:00 UTC +00:00..Wed, 17 Aug 2011 23:59:59 UTC +00:00 ruby-1.9.2-p180 :023 > range = Date.tomorrow.beginning_of_day..Date.tomorrow.end_of_day => Fri, 19 Aug 2011 00:00:00 UTC +00:00..Fri, 19 Aug 2011 23:59:59 UTC +00:00 ruby-1.9.2-p180 :024 > DateTime.now => Wed, 17 Aug 2011 22:17:00 -0700 ruby-1.9.2-p180 :025 > This ... just confuses me sometimes -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/UbI1jKExZsAJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Robert Walker
2011-Aug-19 18:58 UTC
Re: Please explain how Today and Tomorrow work (TimeZone?)
John H. wrote in post #1017234:> ruby-1.9.2-p180 :023 > range > Date.tomorrow.beginning_of_day..Date.tomorrow.end_of_day > => Fri, 19 Aug 2011 00:00:00 UTC +00:00..Fri, 19 Aug 2011 23:59:59 UTC > +00:00The above statement actually makes less sense than you might think. Date.tomorrow returns an object of type Date. Date objects have no notion of time, so therefore have no notion of time zone.> Date.tomorrow=> Sat, 20 Aug 2011 Notice there is no notion of time, therefore calling beginning_of_day on Date.tomorrow is somewhat meaningless. Rails translates this to mean "midnight in whatever time zone is specified by config.time_zone = ''Eastern Time (US & Canada)'' in config/application.rb or midnight UTC if not specified." Your range above is showing> Date.tomorrow.beginning_of_day=> Sat, 20 Aug 2011 00:00:00 UTC +00:00 config.time_zone = ''Eastern Time (US & Canada)''> Date.tomorrow.beginning_of_day=> Sat, 20 Aug 2011 00:00:00 EDT -04:00 Notice these both represent midnight, but they are not the same instant in time. Looking at your example:> t = Time.now + 1.day=> 2011-08-17 22:17:00 -0700> t.utc=> 2011-08-18 05:17:00 UTC The above are both represent the same instant in time. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.