From: Felipe Contreras Date: 2013-10-07T17:08:19-05:00 Subject: [ruby-core:57715] Re: [PATCH 1/2] time: fix strptime '%s' On Mon, Oct 7, 2013 at 4:19 PM, Tanaka Akira wrote: > 2013/10/8 Felipe Contreras : > >> It doesn't really say '%s' is UTC, but that it's the seconds since the >> Epoch (which is UTC). > > The Epoch is usually described in UTC but it doesn't mean it is UTC. > > The Epoch can be described as 1970-01-001 00:00:00 UTC, > 1970-01-01 09:00:00 +0900 and others. > > %s format itself doesn't contain the information for offset from UTC. > > So I think it is not good idea to change the behavior > (and possibly breaks compatibility) for Time.strptime('0', '%s') returns > UTC Time object instead of local time Time object. I don't feel strongly either way. How about this? --- a/lib/time.rb +++ b/lib/time.rb @@ -393,7 +393,7 @@ class Time d = Date._strptime(date, format) raise ArgumentError, "invalid strptime format - `#{format}'" unless d if seconds = d[:seconds] - Time.at(seconds) + Time.at(seconds).localtime(d[:offset]) else year = d[:year] year = yield(year) if year && block_given? '%s' remains the same, but '%s %z' is fixed: Time.strptime('0', '%s') => 1969-12-31 18:00:00 -0600 Time.strptime('0 +0100', '%s %z') => 1970-01-01 01:00:00 +0100 Time.strptime('0 +0100', '%s %z').strftime('%s %z') => "0 +0100" -- Felipe Contreras