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

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:00

The 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.