Forum: Ruby Time zone abbreviation

1b6ad9c0f97db72c943070e5569788c8?d=identicon&s=25 Jon A. Lambert (Guest)
on 2014-04-30 05:58
(Received via mailing list)
From Ruby Core documentation:
--------------------------------------
zone ? string
Returns the name of the time zone used for time. As of Ruby 1.8, returns
“UTC” rather than “GMT” for UTC times.

t = Time.gm(2000, "jan", 1, 20, 15, 1)
t.zone   #=> "UTC"
t = Time.local(2000, "jan", 1, 20, 15, 1)
t.zone   #=> "CST"

--------------------------------------
strftime( string ) ? string
...
Time zone:
...
  %Z - Time zone abbreviation name


C:\>ruby -v
ruby 2.0.0p353 (2013-11-22) [x64-mingw32]
C:\>irb
DL is deprecated, please use Fiddle
irb(main):001:0> Time.now
=> 2014-04-29 23:45:52 -0400
irb(main):002:0> Time.now.strftime('%Z')
=> "Eastern Daylight Time"
irb(main):003:0> Time.now.zone
=> "Eastern Daylight Time"
irb(main):004:0>


Is the documentation is wrong?
How do I get time zone abbreviation, "EDT" or "EST" instead of "Eastern
Daylight Time" or "Eastern Standard Time"?

Thanks
620676bac4e81aae46ba1f252dbc76ce?d=identicon&s=25 Rylee Fowler (Guest)
on 2014-04-30 06:16
(Received via mailing list)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Cannot reproduce on Debian 7 Testing (see [1]). This appears to be an
issue with Windows naming of timezones.


====
[1]
- ----
irb(main):005:0> Time.now.zone
=> "EDT"
irb(main):006:0> "#{RUBY_VERSION}p#{RUBY_PATCHLEVEL}"
=> "2.0.0p457"
- ----

On 4/29/2014 23:58, Jon A. Lambert wrote:
>
> "Eastern Standard Time"?
>
> Thanks
>

- --
Rylee Fowler
rylee@rylee.me
https://www.rylee.me
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (MingW32)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBCgAGBQJTYHj0AAoJEAWmNCH2N+MzDCkH/1jLvywsFVITFLjBfKwozYf7
H9CdzTuRq2UDNoYxRGtksXqAxIXU8tMtr9Fr4IVUYrLH7tiLXslD996z+uPs8BNh
WFlCunFogv9vtf2amJTqgRKHhQZn+g4oOY38ElQ+LBv692Xv4f2yt3eV/Ml3vHHr
GL/Iw3hG3SkLLOhLj3zLEBEElp/qemXYMNEkaXGv+ukMshVyeWcGGf7v1eAHAaLC
7oXBXlyfP5NcuE3KWpSqvc+05MjXaSWtT7qQ57ucELMHKzNQ8AmqXgpVY7trEKJ8
MblDnzM7AM4lWYGeENpHXr8v2AOP9y+tMnmLKjU3YKza+HCWbkO9qnTDjeYfs0A=
=wmgq
-----END PGP SIGNATURE-----
5a837592409354297424994e8d62f722?d=identicon&s=25 Ryan Davis (Guest)
on 2014-04-30 08:42
(Received via mailing list)
On Apr 29, 2014, at 21:15, Rylee Fowler <rylee@rylee.me> wrote:

> Cannot reproduce on Debian 7 Testing (see [1]). This appears to be an
> issue with Windows naming of timezones.

Agreed:

10001 % irb
>> Time.now.zone
=> "PDT"
>> Time.now.strftime "%Z"
=> "PDT"
>>

(osx)

Maybe look at your OS's settings for your locale.
75eb154a2d05884a8a6a8e54b6eb3deb?d=identicon&s=25 Wayne Brissette (Guest)
on 2014-04-30 11:41
(Received via mailing list)
On Apr 30, 2014, at 1:42, Ryan Davis <ryand-ruby@zenspider.com> wrote:

> => "PDT"
>>> Time.now.strftime "%Z"
> => "PDT"
>>>
>
> (osx)
>
> Maybe look at your OS's settings for your locale.
>


I just ran this both on Mac OS X and Windows and Jon is right.

Windows:

irb(main):001:0> Time.now.zone
=> "Central Daylight Time"

Mac OS X:

2.1.0 :003 > Time.now.zone
 => "CDT

I looked but didnt find any setting in Windows that allowed this, but
cant help but wonder if this isnt due to how the OS is relaying the
information back.

Wayne
1b6ad9c0f97db72c943070e5569788c8?d=identicon&s=25 Jon A. Lambert (Guest)
on 2014-05-03 04:57
(Received via mailing list)
Wayne Brissette wrote:
> I looked but didn?t find any setting in Windows that allowed this, but can?t
> help but wonder if this isn?t
> due to how the OS is relaying the information back.
>

I noticed if you set TZ environment variable to the below format, you
get
the abbreviation.
---------------------------------
C:\>set TZ=EST-5EDT
C:\>irb
irb(main):001:0> Time.now.zone
=> "EDT"
irb(main):002:0>
------------------------------

The TZ environment variable is not set on Windows by default.
If TZ is not set it's apparently retrieved from registry under the
following
key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time
Zones

Curiously Cygwin's default bash/cshell exports 'TZ = America/New_York',
using a program (tzset),
and Cygwin's ruby does show 'Time.now.zone' => 'EDT'.
I assume there's a zone lookup table in Cygwin that its NEWLIB is using,
but not in MSys (rather... MSys is probably using MSVCRTL.DLL).

I'm guessing the only way to make it work exactly the same on all
platforms
is to include
a platform independent strftime() (or whatever is used) in ruby core
with
its own zone
abbreviation table.

Jon
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.