Project

General

Profile

Bug #14880

Time#localtime doesn't always seem to respect TZ

Added by ioquatix (Samuel Williams) over 1 year ago. Updated about 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:87675]

Description

In the first case, calling #localtime doesn't change the utc_offset.

$ TZ=UTC ruby -e 'ENV["TZ"]="Pacific/Auckland"; puts t=Time.new; ENV["TZ"]="UTC"; puts t.localtime'                                            
2018-06-29 16:21:36 +1200
2018-06-29 16:21:36 +1200

$ TZ=UTC ruby -e 'ENV["TZ"]="Pacific/Auckland"; puts t=Time.new; ENV["TZ"]="UTC"; puts Time.new(t.year, t.month, t.day, t.hour, t.min, t.sec, t.utc_offset).localtime'
2018-06-29 16:23:08 +1200
2018-06-29 04:23:08 +0000

In the second case, by creating new time, calling #localtime works as expected.

It seems like once a time instance is "localtime", calling #localtime a 2nd time does not have any effect.

#1

Updated by nobu (Nobuyoshi Nakada) over 1 year ago

  • Status changed from Open to Closed

Applied in changeset trunk|r63823.


time.c: [DOC] Time#localtime

  • time.c: state that Time#localtime does nothing when nothing changes. [ruby-core:87675] [Bug #14880]

Updated by ioquatix (Samuel Williams) over 1 year ago

nobu (Nobuyoshi Nakada) Isn't changing TZ enough that #localtime should do something?

Updated by nobu (Nobuyoshi Nakada) over 1 year ago

I think it should be fixed at the creation time.

Updated by ioquatix (Samuel Williams) over 1 year ago

nobu (Nobuyoshi Nakada) That doesn’t seem to align with what the documentation says:

Converts time to local time (using the local time zone in effect for this process) modifying the receiver.

Updated by nobu (Nobuyoshi Nakada) over 1 year ago

I feel it'd be better to accept a timezone object as utc_offset like [Feature #14850], than setting ENV.

Updated by ioquatix (Samuel Williams) over 1 year ago

nobu (Nobuyoshi Nakada) wrote:

I feel it'd be better to accept a timezone object as utc_offset like [Feature #14850], than setting ENV.

I completely agree but the problem is how to compute utc offset for a given time and timezone.

Right now using TZ is the only way to do it.

Updated by nagachika (Tomoyuki Chikanaga) about 1 year ago

  • Backport changed from 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN to 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: DONE

ruby_2_5 r66780 merged revision(s) 63823,63839.

Also available in: Atom PDF