(I am in Spain - CET - and running on OS X with the correct timezone)
The Time.now correctly gives me the time, and the correct UTC offset
of 2 hours. It is the summer, so we are 2 hours ahead of UTC. We are
still one hour ahead of London, but London itself is an hour ahead as
they too switch to a summer time (BST).
ruby tells me that my utc_offset is 7200 - which is correct. But…
when I pull out the timezone it gives me the wrong one. Athens is 3
hours ahead of UTC, not 2 (at this time of year). So, when I convert a
time using the timezone it gives me it is an hour out!
I had hoped that time zone woes were behind me after switching to RoR
from Java. But it still seems to be a problem.
Time.zone will give you the time zone currently set in Rails 2.1
You should set the time zone of your environment in the
environment.db:
config.time_zone = ‘Amsterdam’
You can ask the users of your application to select their time zone
(that’s something they’ll have to tell you, it’s not possible for
Rails to guess :-)), save it in the user table as time_zone variable
and set it for your current user in a before_filter: Time.zone = @current_user.time_zone.
Hi,
Thanks for that, but it completely misses the point in that I can not
even get the proper time zone conversion inside the server.
I am not bringing a user’s timezone into the equation!
I can’t go back and forth inside the same instance and get reliable
results:
Time.now and Time.now.in_time_zone(TimeZone[Time.now.utc_offset])
should give me the same times back! it doesn’t.
Anyway, I think I found another bug listed for this, so I will trust
that someone more clever than I will figure it out.
The thing I was trying to say is that it’s just not possible for Rails
to really know in which time zone you are. So when you call
TimeZone[some_offset], it can only make a guess about the time zone,
because it doesn’t know if you’re in a time zone with or without DST.
Again, in Rails 2.1, you should set your time zone via the
config.time_zone command so that Rails knows in which time zone is
your server. And you retrieve your time zone (that was your question,
right?) using
Time.zone
So not using TimeZone.[] class method.
Thanks,
You are correct in that I should use Time.zone for server time, but I
have a value coming from the client that is there offset to gmt (from
a javascript call)… oh well!
Thanks,
You are correct in that I should use Time.zone for server time, but I
have a value coming from the client that is there offset to gmt (from
a javascript call)… oh well!
Hello Phil,
Having quite a similar problem. Any idea how could I get a TimeZone
instance for a given offset with disabled DST? Did you solve your
problem with the offset?
Regards,
KIR
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.