ruby on rails - Set timezone for incoming xml data -
i'm getting datetime field api not explicitly set timezone. when place database it's assuming datetime must in gmt, timezone in chicago time. (i chicago time, because i'm still unsure if api factors in dst.) best way me convert time gmt before adding database?
here xml sample of 1 of nodes i'm referring to:
<fromdatetime>2011-03-17 08:00:00</fromdatetime>
in ruby, i'm using add record database.
:starttime => datetime.parse(row.at_xpath("fromdatetime/text()").to_s),
i think need add difference in hours between cst , gmt last ruby call, right? how that?
thanks!
could use time instead? datetime not daylight savings time aware. time automatically sets local gmt offset given date/time , set dst if needed.
irb(main):014:0> require 'time' irb(main):015:0> time.parse('2011-03-17 08:00:00') => thu mar 17 08:00:00 -0400 2011 irb(main):022:0> time.parse('2011-03-17 08:00:00').dst? => true
here case standard time (i in est)
irb(main):025:0> time.parse('2011-01-17 08:00:00') => mon jan 17 08:00:00 -0500 2011 irb(main):023:0> time.parse('2011-01-17 08:00:00').dst? => false
if using activesupport http://api.rubyonrails.org/classes/datetime.html can set arbitrary time zone:
irb(main):039:0> time.zone = 'america/chicago' => "america/chicago" irb(main):040:0> time.parse('2011-03-17 08:00:00') => thu mar 17 08:00:00 -0400 2011
Comments
Post a Comment