Project

General

Profile

Backport #6656

Time#strftime('%Z') should return 'UTC' instead of 'GMT'

Added by stomar (Marcus Stollsteimer) about 7 years ago. Updated 2 months ago.

Status:
Closed
Priority:
Normal
Assignee:
-
[ruby-core:45916]

Description

=begin
Time#strftime('%Z') should return 'UTC' instead of 'GMT',
as in Time#to_s and Time#zone. This is also the behaviour of Ruby 1.9.3.

irb(main):001:0> Time.utc(2012, 6, 27).to_s
=> "Wed Jun 27 00:00:00 UTC 2012"
irb(main):002:0> Time.utc(2012, 6, 27).zone
=> "UTC"
irb(main):003:0> Time.utc(2012, 6, 27).strftime('%Z')
=> "GMT"
=end

History

Updated by akr (Akira Tanaka) about 7 years ago

2012/6/27 stomar (Marcus Stollsteimer) redmine@ruby-lang.org:

Issue #6656 has been reported by stomar (Marcus Stollsteimer).

Time#strftime('%Z') should return 'UTC' instead of 'GMT',
as in Time#to_s and Time#zone. This is also the behaviour of Ruby 1.9.3.

irb(main):001:0> Time.utc(2012, 6, 27).to_s
=> "Wed Jun 27 00:00:00 UTC 2012"
irb(main):002:0> Time.utc(2012, 6, 27).zone
=> "UTC"
irb(main):003:0> Time.utc(2012, 6, 27).strftime('%Z')
=> "GMT"

Ruby 1.8 uses strftime() in libc.

Ruby 1.9 uses own strftime() which %Z should produce UTC.

% ruby-1.8.7p357 -ve 'p Time.utc(2012, 6, 27).strftime("%Z")'
ruby 1.8.7 (2011-12-28 patchlevel 357) [x86_64-linux]
"GMT"
% ruby-1.9.3p194 -ve 'p Time.utc(2012, 6, 27).strftime("%Z")'
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
"UTC"

Do you really sure that it returns "GMT" with Ruby 1.9.3?
--
Tanaka Akira

Updated by stomar (Marcus Stollsteimer) about 7 years ago

Am 28.06.2012 02:29, schrieb Tanaka Akira:

2012/6/27 stomar (Marcus Stollsteimer) redmine@ruby-lang.org:

Issue #6656 has been reported by stomar (Marcus Stollsteimer).

Time#strftime('%Z') should return 'UTC' instead of 'GMT',
as in Time#to_s and Time#zone. This is also the behaviour of Ruby 1.9.3.

irb(main):001:0> Time.utc(2012, 6, 27).to_s
=> "Wed Jun 27 00:00:00 UTC 2012"
irb(main):002:0> Time.utc(2012, 6, 27).zone
=> "UTC"
irb(main):003:0> Time.utc(2012, 6, 27).strftime('%Z')
=> "GMT"

Ruby 1.8 uses strftime() in libc.

Ruby 1.9 uses own strftime() which %Z should produce UTC.

% ruby-1.8.7p357 -ve 'p Time.utc(2012, 6, 27).strftime("%Z")'
ruby 1.8.7 (2011-12-28 patchlevel 357) [x86_64-linux]
"GMT"
% ruby-1.9.3p194 -ve 'p Time.utc(2012, 6, 27).strftime("%Z")'
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
"UTC"

Do you really sure that it returns "GMT" with Ruby 1.9.3?

Sorry, what I meant is:

The desired behavior would be that "UTC" is used consistently
in all 3 methods, as is already the case in Ruby 1.9.3.

At the moment, strftime('%Z') behaves differently in versions 1.8.7
and 1.9.3 and additionally even behaves in an unexpected and
most inconsistent way within 1.8.7: #strftime('%Z') and #zone
should output the same time zone name.

rdoc for Time#zone (1.8.7):

Returns the name of the time zone used for time.
As of Ruby 1.8, returns “UTC” rather than “GMT” for UTC times.

rdoc for strftime with '%Z' (1.8.7):

%Z - Time zone name

Marcus

--
https://github.com/stomar/

Updated by akr (Akira Tanaka) about 7 years ago

2012/6/28 Marcus Stollsteimer sto.mar@web.de:

The desired behavior would be that "UTC" is used consistently
in all 3 methods, as is already the case in Ruby 1.9.3.

I see. I misunderstood.

However Ruby 1.8's %Z behavior is intended behavior because
Ruby 1.8 uses just a strftime() in libc.

So, this issue is a new feature request.
I guess it is difficult to implement, discuss and accept for Ruby 1.8.7
until the next (and last) Ruby 1.8.7 release.
--
Tanaka Akira

Updated by stomar (Marcus Stollsteimer) about 7 years ago

Am 28.06.2012 15:08, schrieb Tanaka Akira:

However Ruby 1.8's %Z behavior is intended behavior because
Ruby 1.8 uses just a strftime() in libc.
So, this issue is a new feature request.

I disagree.

A programmer should not have to worry about the implementation of
the method. Furthermore, in the documentation #strftime is not marked
as a mere wrapper for the C library's strftime().

The different behavior of strftime('%Z') and #zone / #to_s
is unexpected and seems even contradictory to the statement
in the #zone documentation, that "UTC" is used since 1.8.

Regards,
Marcus

--
https://github.com/stomar/

Updated by akr (Akira Tanaka) about 7 years ago

2012/6/29 sto.mar@web.de:

A programmer should not have to worry about the implementation of
the method. Furthermore, in the documentation #strftime is not marked
as a mere wrapper for the C library's strftime().

Hm. It may be possible to consider it a documentation bug.
--
Tanaka Akira

#6

Updated by ayumin (Ayumu AIZAWA) about 7 years ago

  • Project changed from Ruby master to Ruby 1.8
#7

Updated by jeremyevans0 (Jeremy Evans) 2 months ago

  • ruby -v deleted (ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-linux])
  • Project changed from Ruby 1.8 to Backport186
  • Tracker changed from Bug to Backport
#8

Updated by jeremyevans0 (Jeremy Evans) 2 months ago

  • Backport set to 2.5: UNKNOWN, 2.6: UNKNOWN
  • Status changed from Open to Closed
  • Project changed from Backport186 to Ruby master
  • Tracker changed from Backport to Bug
#9

Updated by jeremyevans0 (Jeremy Evans) 2 months ago

  • Backport deleted (2.5: UNKNOWN, 2.6: UNKNOWN)
  • Project changed from Ruby master to Backport187
  • Tracker changed from Bug to Backport

Also available in: Atom PDF