Skip to content

Commit a61756e

Browse files
committed
merge revision(s) 49788,49790: [Backport ruby#10904]
* lib/time.rb (strptime): Support %s.%N. [ruby-core:68301] [Bug ruby#10904] Patch by Sadayuki Furuhashi. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@51599 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 7766666 commit a61756e

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Mon Aug 17 16:24:10 2015 Tanaka Akira <[email protected]>
2+
3+
* lib/time.rb (strptime): Support %s.%N.
4+
[ruby-core:68301] [Bug #10904] Patch by Sadayuki Furuhashi.
5+
16
Mon Aug 17 16:22:28 2015 Nobuyoshi Nakada <[email protected]>
27

38
* transcode.c (load_transcoder_entry): fix transcoder loading race

lib/time.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,16 @@ def strptime(date, format, now=self.now)
393393
d = Date._strptime(date, format)
394394
raise ArgumentError, "invalid strptime format - `#{format}'" unless d
395395
if seconds = d[:seconds]
396+
if sec_fraction = d[:sec_fraction]
397+
usec = sec_fraction * 1000000
398+
usec *= -1 if seconds < 0
399+
else
400+
usec = 0
401+
end
396402
if offset = d[:offset]
397-
Time.at(seconds).localtime(offset)
403+
Time.at(seconds, usec).localtime(offset)
398404
else
399-
Time.at(seconds)
405+
Time.at(seconds, usec)
400406
end
401407
else
402408
year = d[:year]

test/test_time.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,17 @@ def test_strptime
404404
assert_equal(3600, Time.strptime('0 +0100', '%s %z').utc_offset)
405405
end
406406

407+
def test_strptime_s_N
408+
assert_equal(Time.at(1, 500000), Time.strptime("1.5", "%s.%N"))
409+
assert_equal(Time.at(-2, 500000), Time.strptime("-1.5", "%s.%N"))
410+
t = Time.strptime("1.000000000001", "%s.%N")
411+
assert_equal(1, t.to_i)
412+
assert_equal(Rational("0.000000000001"), t.subsec)
413+
t = Time.strptime("-1.000000000001", "%s.%N")
414+
assert_equal(-2, t.to_i)
415+
assert_equal(1-Rational("0.000000000001"), t.subsec)
416+
end
417+
407418
def test_nsec
408419
assert_equal(123456789, Time.xmlschema("2000-01-01T00:00:00.123456789+00:00").tv_nsec)
409420
assert_equal(123456789, Time.parse("2000-01-01T00:00:00.123456789+00:00").tv_nsec)

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#define RUBY_VERSION "2.1.7"
22
#define RUBY_RELEASE_DATE "2015-08-17"
3-
#define RUBY_PATCHLEVEL 382
3+
#define RUBY_PATCHLEVEL 383
44

55
#define RUBY_RELEASE_YEAR 2015
66
#define RUBY_RELEASE_MONTH 8

0 commit comments

Comments
 (0)