If I have a time string of the form "Wed, 22 Jun 2011 09:43:58 +0200"
coming from a client, I wish to store it with the time zone preserved. This is important because it's not just the absolute UTC time that is important but also the timezone.
Time.zone.parse(t)
will convert the time to whatever the zone that Time.zone
is using at the time, losing the source timezone.
Do I have to manually extract the timezone from the above string or is there an idiomatic way to do this?
I think you are looking for the following solution:
In ApplicationController:
And in a controller add around filter at the beginnig
A DateTime field can only store 'YYYY-MM-DD HH:MM:SS' (MySQL), no Time Zone info.
You should store the datetime in UTC, and the Timezone in a different field, preferably as an integer specifying the offset from UTC in minutes.
You can extract the offset like this:
EDIT:
And to round trip the excercise