βWhen analyzing time information, itβs important to never do this without specifying the time zone.
This gem of advice from this useful blogpost: Working with time zones in Ruby on Rails .
Regardless of whether you use rails or not, the time bar is always bound to the time zone. In your case, you assume that the time line has an offset of -0700, but does not pass the time zone information to the analysis method (which assumes it's UTC).
> Rails.application.config.time_zone => "Mountain Time (US & Canada)"
This is because I have the following configuration:
config.time_zone = 'Mountain Time (US & Canada)' > string = "Sunday, Oct 7 4:00pm" => "Sunday, Oct 7 4:00pm" > Time.parse(string) => 2012-10-07 16:00:00 -0600 > Time.parse(string).zone => "MDT"
It works in a similar way in a pure ruby:
> require 'time' => true > Time.local( 2012, 10, 07 ) => 2012-10-07 00:00:00 -0600 > Time.local( 2012, 10, 07 ).zone => "MDT" > string = "Sunday, Oct 7 4:00pm" => "Sunday, Oct 7 4:00pm" > Time.parse(string) => 2012-10-07 16:00:00 -0600 > Time.parse(string).zone => "MDT"
source share