diff options
author | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-09-28 08:43:44 +0000 |
---|---|---|
committer | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-09-28 08:43:44 +0000 |
commit | 275b38937e8d89a625351be13d66b4fcb82333db (patch) | |
tree | 8619e9b02aad1f6087f3f329d884d563fa3490a0 | |
parent | 040ae9104055d7a4789b46ead215287d5d6ff305 (diff) | |
download | ruby-275b38937e8d89a625351be13d66b4fcb82333db.tar.gz |
* lib/net/ftp.rb (mtime): use usec instead of fractions to parse
decimal fractions of a second correctly when the number of digits
is not 6.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51964 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | lib/net/ftp.rb | 3 | ||||
-rw-r--r-- | test/net/ftp/test_ftp.rb | 11 |
3 files changed, 18 insertions, 2 deletions
@@ -1,3 +1,9 @@ +Mon Sep 28 17:40:17 2015 Shugo Maeda <shugo@ruby-lang.org> + + * lib/net/ftp.rb (mtime): use usec instead of fractions to parse + decimal fractions of a second correctly when the number of digits + is not 6. + Mon Sep 28 16:07:08 2015 Shugo Maeda <shugo@ruby-lang.org> * lib/net/ftp.rb (mtime): parse decimal fractions of a second as diff --git a/lib/net/ftp.rb b/lib/net/ftp.rb index 795e1cbdc3..9ce161b7e7 100644 --- a/lib/net/ftp.rb +++ b/lib/net/ftp.rb @@ -895,8 +895,7 @@ module Net raise FTPProtoError, "invalid time-val: #{value}" end usec = fractions.to_i * 10 ** (6 - fractions.to_s.size) - Time.send(local ? :local : :utc, - year, month, day, hour, min, sec, fractions) + Time.send(local ? :local : :utc, year, month, day, hour, min, sec, usec) } FACT_PARSERS = Hash.new(CASE_DEPENDENT_PARSER) FACT_PARSERS["size"] = DECIMAL_PARSER diff --git a/test/net/ftp/test_ftp.rb b/test/net/ftp/test_ftp.rb index c84dbda10f..ba076dd779 100644 --- a/test/net/ftp/test_ftp.rb +++ b/test/net/ftp/test_ftp.rb @@ -1108,6 +1108,10 @@ EOF commands.push(sock.gets) sock.print("213 20150910161739.123456\r\n") commands.push(sock.gets) + sock.print("213 20150910161739.123\r\n") + commands.push(sock.gets) + sock.print("213 20150910161739.123456789\r\n") + commands.push(sock.gets) sock.print("213 2015091016173\r\n") } begin @@ -1119,12 +1123,19 @@ EOF ftp.mtime("foo.txt", true)) assert_equal(Time.utc(2015, 9, 10, 16, 17, 39, 123456), ftp.mtime("bar.txt")) + assert_equal(Time.utc(2015, 9, 10, 16, 17, 39, 123000), + ftp.mtime("bar.txt")) + assert_equal(Time.utc(2015, 9, 10, 16, 17, 39, + Rational(123456789, 1000)), + ftp.mtime("bar.txt")) assert_raise(Net::FTPProtoError) do ftp.mtime("quux.txt") end assert_match("MDTM foo.txt\r\n", commands.shift) assert_match("MDTM foo.txt\r\n", commands.shift) assert_match("MDTM bar.txt\r\n", commands.shift) + assert_match("MDTM bar.txt\r\n", commands.shift) + assert_match("MDTM bar.txt\r\n", commands.shift) assert_match("MDTM quux.txt\r\n", commands.shift) assert_equal(nil, commands.shift) ensure |