'%s' is meant to imply UTC, however:
Time.strptime('0', '%s')
=> 1969-12-31 18:00:00 -0600
After this patch:
Time.strptime('0', '%s')
=> 1970-01-01 00:00:00 +0000
In addition, '%s %z' is parsed correctly:
Time.strptime('0 +0100', '%s %z').strftime('%s %z')
=> "0 -0600"
Now:
Time.strptime('0 +0100', '%s %z').strftime('%s %z')
=> "0 +0100"
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
···
---
lib/time.rb | 3 ++-
test/test_time.rb | 2 ++
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/lib/time.rb b/lib/time.rb
index 91b5b54..4474f27 100644
--- a/lib/time.rb
+++ b/lib/time.rb
@@ -393,7 +393,8 @@ class Time
d = Date._strptime(date, format)
raise ArgumentError, "invalid strptime format - `#{format}'" unless d
if seconds = d[:seconds]
- Time.at(seconds)
+ offset = d[:offset] || 0
+ Time.at(seconds).localtime(offset)
else
year = d[:year]
year = yield(year) if year && block_given?
diff --git a/test/test_time.rb b/test/test_time.rb
index 0a4e8a7..1c95370 100644
--- a/test/test_time.rb
+++ b/test/test_time.rb
@@ -400,6 +400,8 @@ class TestTimeExtension < Test::Unit::TestCase # :nodoc:
def test_strptime
assert_equal(Time.utc(2005, 8, 28, 06, 54, 20), Time.strptime("28/Aug/2005:06:54:20 +0000", "%d/%b/%Y:%T %z"))
assert_equal(Time.at(1).localtime, Time.strptime("1", "%s"))
+ assert_equal(0, Time.strptime('0', '%s').utc_offset)
+ assert_equal(3600, Time.strptime('0 +0100', '%s %z').utc_offset)
end
def test_nsec
--
1.8.4-fc