Thanks Jeremy!

On May 12, 6:31 pm, Jeremy Olliver <[email protected]> wrote:
> Hi,
>
> The time zone is encoded in the string at the end e.g
>
> Mon, 11 May 2009 18:24:37 +1200
> Is in a time zone that's +12 (12 hours ahead of utc)
> DateTime.parse or Time.parse will read this correctly.
>
> So what you're doing is using a js date picker that gives you a string
> like "Mon May 11 18:24:37 2009"
> You just need to append the time zone difference to "Mon May 11
> 18:24:37 2009 +1200" etc before parsing.
>
> I handle storing dates in the db a little differently than you, but if
> you know what you're doing don't worry about changing that part.
> I usually store dates in the db in utc format (I think you can
> configure this in environment.rb from memory), and you can easily set
> the user's timezone in a filter in application controller
> Time.zone = user.time_zone
> which will handle all of the conversions for you.
>
> Cheers,
> Jeremy
>
> On May 12, 10:57 am, Randall <[email protected]> wrote:
>
>
>
> > Seems like there should be an easy solution to this problem, yet I
> > can't seem to find one.
>
> > Here is the issue:
> > How do you assign a time zone to a Time object that results from a
> > parsed date/time string?
>
> > Example:
> > - I receive a date time string from a date picker widget that does not
> > include time zone info (i.e. "Mon May 11 18:24:37 2009").
> > - Time zone for this date is known and may be different than what's
> > local to the user
> > - date/time is stored in the DB as unix time (i.e. 1242075962)
> > - time zone is stored in the DB in tz format i(i.e. 'America/
> > New_York')
> > - I would like to be able to take a given date with its known time
> > zone and calculate the equivalent unix time value.
>
> > >> now = Time.now
>
> > => Mon May 11 18:24:37 -0400 2009>> now.to_i
>
> > => 1242080677
>
> > >> parsed = DateTime.parse("Mon May 11 18:24:37 2009")
>
> > => Mon, 11 May 2009 18:24:37 +0000>> parsed.to_time
>
> > => Mon May 11 18:24:37 UTC 2009>> parsed.to_time.to_i
> > => 1242066277
> > >> Time.at 1242066277
>
> > => Mon May 11 14:24:37 -0400 2009
>
> > It seems there should be a way to append the time zone to the string
> > before it is parsed or to associate the parsed time with a time zone
> > (without converting the time to the zone), however I can't seem to
> > find an answer.
>
> > Any help would be greatly appreciated
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to