Project

General

Profile

Bug #8376

utc method changes original time object

Added by Arjan Diepenbroek almost 3 years ago. Updated almost 3 years ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
ruby -v:
1.8.7, 1.9.3, 2.0.0
Backport:
1.9.3: UNKNOWN, 2.0.0: UNKNOWN
[ruby-core:54848]

Description

The utc method changes the original time object when called.

For example when on a system with a CET timezone.

t = Time.new(2013)
t.zone # CET
t.utc
t.zone # UTC

History

#1 [ruby-core:54849] Updated by Yui NARUSE almost 3 years ago

  • Status changed from Open to Rejected

Time#utc is destructive method.
Use dup if you want a copy.

#2 [ruby-core:54851] Updated by Achilleas Buisman almost 3 years ago

naruse (Yui NARUSE) wrote:

Time#utc is destructive method.
Use dup if you want a copy.

That seems the point of this issue. The behaviour is inconsistent. t.utc! should be the way to destroy t in the example. This should be changed... ruby isn't PHP.

#3 [ruby-core:54852] Updated by Yukihiro Matsumoto almost 3 years ago

I admit this is a bad design, but changing it introduces incompatibility.
We don't consider it as a bug (thus we rejected).
Submit feature request instead, if you really want to change.
Maybe fixed in the future, if we can provide proper migration path.

Matz.

#4 [ruby-core:54861] Updated by Nobuyoshi Nakada almost 3 years ago

You can use Time#getutc or #getgm.

Also available in: Atom PDF