ruby-changes:39883
From: shugo <ko1@a...>
Date: Mon, 28 Sep 2015 17:44:15 +0900 (JST)
Subject: [ruby-changes:39883] shugo:r51964 (trunk): * lib/net/ftp.rb (mtime): use usec instead of fractions to parse
shugo 2015-09-28 17:43:44 +0900 (Mon, 28 Sep 2015) New Revision: 51964 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51964 Log: * 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. Modified files: trunk/ChangeLog trunk/lib/net/ftp.rb trunk/test/net/ftp/test_ftp.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 51963) +++ ChangeLog (revision 51964) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Sep 28 17:40:17 2015 Shugo Maeda <shugo@r...> + + * 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@r...> * lib/net/ftp.rb (mtime): parse decimal fractions of a second as Index: lib/net/ftp.rb =================================================================== --- lib/net/ftp.rb (revision 51963) +++ lib/net/ftp.rb (revision 51964) @@ -895,8 +895,7 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L895 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 Index: test/net/ftp/test_ftp.rb =================================================================== --- test/net/ftp/test_ftp.rb (revision 51963) +++ test/net/ftp/test_ftp.rb (revision 51964) @@ -1108,6 +1108,10 @@ EOF https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L1108 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 https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L1123 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/