Feature Requests: Browse | Submit New | Admin

[#4134] Return Times and DateTimes with appropriate Zone/Offset information

Date:
2006-04-17 14:16
Priority:
3
Submitted By:
Philip Ross (psross)
Assigned To:
Philip Ross (psross)
Category:
Timezone
State:
Open
Summary:
Return Times and DateTimes with appropriate Zone/Offset information

Detailed description
Times and DateTimes returned by utc_to_local are always returned as UTC times that should be interpreted as local time.
For example,

Timezone.get('America/New_York').utc_to_local(Time.utc(2006,4,17,15,8,0)).to_s

returns "Mon Apr 17 11:08:00 UTC 2006" to represent 11:08:00 EDT.

It would be helpful if Times and DateTimes returned by utc_to_local would contain the appropriate offset and zone identifier.
This would allow the times to be converted back to UTC and make the job of formatting them for display and including
the zone identifier easier.

For DateTimes, the new_offset function can be used to construct a new DateTime with the correct offset. For Times, this
is likely to be more difficult as the zone information appears to always be read straight from the system.

Add A Comment: Notepad

Please login


Followup

Message
Date: 2006-11-20 17:42
Sender: Philip Ross

The problem is that the Ruby Time class doesn't allow the offset
to be set arbitrarily. The time is either in UTC or in the local
timezone. TZInfo currently always returns UTC Times regardless
of the timezone.

If all you are interested in is displaying an identifier for
the timezone, you can obtain an instance of TimezonePeriod
(with Timezone#period_for_local, Timezone#period_for_utc,
Timezone#current_period or Timezone#current_time_and_period)
and then call the abbreviation method.

>> TZInfo::Timezone.get('US/Pacific').current_period.abbrev
iation
=> :PST

TimezonePeriod also gives you information about what the timezone
offset to UTC is and whether daylight savings time is in effect.
See http://tzinfo.rubyforge.org/doc/classes/TZInfo/TimezonePeriod.html
for more details.
Date: 2006-11-18 14:26
Sender: David Welton

Any ideas about how to fix this, or at least a workaround?

irb(main):012:0> TZInfo::Timezone.get('US/Pacific').now.zone
=> "UTC"

is pretty wrong looking to me.  

Attached Files:

Name Description Download
No Files Currently Attached

Changes:

No Changes Have Been Made to This Item