Friday, August 19, 2011

[Rails] 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: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.

--
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate