summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-10-07 21:00:12 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-10-07 21:00:12 +0000
commita8178c69bee18250aa022bb270390279487a8618 (patch)
tree1f1d6cf8f9e256110d1305cf5e16467f12b16cfa
parent9410e7e00ca1c43619ad202595b668358cf1c389 (diff)
* lib/time.rb (Time.strptime): Time.strptime('0', '%s') returns local
time Time object as Ruby 2.0 and before. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43191 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--lib/time.rb7
-rw-r--r--test/test_time.rb2
3 files changed, 11 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index bbd0b902e4..3f79d3b777 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Tue Oct 8 05:58:12 2013 Tanaka Akira <akr@fsij.org>
+
+ * lib/time.rb (Time.strptime): Time.strptime('0', '%s') returns local
+ time Time object as Ruby 2.0 and before.
+
Tue Oct 8 05:40:37 2013 Eric Hodel <drbrain@segment7.net>
* .travis.yml: Rebuild Travis CI's "ruby-head" version on successful
diff --git a/lib/time.rb b/lib/time.rb
index 2b3ebd1b40..0b55480334 100644
--- a/lib/time.rb
+++ b/lib/time.rb
@@ -393,8 +393,11 @@ class Time
d = Date._strptime(date, format)
raise ArgumentError, "invalid strptime format - `#{format}'" unless d
if seconds = d[:seconds]
- offset = d[:offset] || 0
- Time.at(seconds).localtime(offset)
+ if offset = d[:offset]
+ Time.at(seconds).localtime(offset)
+ else
+ Time.at(seconds)
+ end
else
year = d[:year]
year = yield(year) if year && block_given?
diff --git a/test/test_time.rb b/test/test_time.rb
index 1c95370df6..582e60b8ae 100644
--- a/test/test_time.rb
+++ b/test/test_time.rb
@@ -400,7 +400,7 @@ 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(false, Time.strptime('0', '%s').utc?)
assert_equal(3600, Time.strptime('0 +0100', '%s %z').utc_offset)
end