TzTime buglet

I like to use strftime() to format the output time in various ways, each
which needs to have the time zone appended if it differs from the
user’s timezone. However, using %Z in a strftime() call failed to do
what I
expected: = TimeZone[‘Central Time (US & Canada)’]
=> #<TzinfoTimezone:0x9883228 @name=“Central Time (US & Canada)”,
@tzinfo=#<TZInfo::DataTimezone: America/Chicago>, @utc_offset=-21600>
=> 2007-10-08 21:14:20 CDT"%H:%M:%S %Z")
=> “16:16:23 UTC”

Hmm, well, that sucks. So, I wrote a quick little hack for

def strftime(format)
format.gsub!(/%Z/, period.abbreviation.to_s)
# XXXMLG should handle %z here too, of course, but…

Now, this should be done better, but oh well. It works:"%H:%M:%S %Z")
=> “16:18:48 CDT”

Some comments on the tzinfo library that sort of tweaked me a bit:

(1) I dislike the concept of a “default timezone” that is used
If the whole system wants a default one, that’s great, but setting it
using seems like a hack. Additionally, #at, and all the others,
should probably take an optional time zone that can be used to set the
zone from the user’s values. After all, when sending 100 mail messages,
not certain it’s thread-safe to set it globally…

(2) It’s unfortunate it doesn’t play well with rails 1.2.3, but I can
and just put in a temporary hack.


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs