about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-12-25 01:27:33 -0800
committerEric Wong <normalperson@yhbt.net>2010-12-25 01:27:33 -0800
commit8492f6bbc56d42e3068f25ca233faa78884d5a77 (patch)
treee3251b26ed9789e078425cd54fe1d2375172fec1
parent66a5374e724612cd16f270f43102a6ed347208d7 (diff)
It was totally broken but nobody uses uses it, so it
went unnoticed since the beginning of time.
-rw-r--r--lib/clogger/pure.rb2
-rw-r--r--test/test_clogger.rb20
2 files changed, 21 insertions, 1 deletions
diff --git a/lib/clogger/pure.rb b/lib/clogger/pure.rb
index 452e232..4146cce 100644
--- a/lib/clogger/pure.rb
+++ b/lib/clogger/pure.rb
@@ -143,7 +143,7 @@ private
         time_format(t.to_i, (t - t.to_i) * 1000000, op[1], op[2])
       when OP_TIME
         t = Time.now
-        time_format(t.sec, t.usec, op[1], op[2])
+        time_format(t.to_i, t.usec, op[1], op[2])
       when OP_COOKIE
         (env['rack.request.cookie_hash'][op[1]] rescue "-") || "-"
       else
diff --git a/test/test_clogger.rb b/test/test_clogger.rb
index 47387bb..58d38e8 100644
--- a/test/test_clogger.rb
+++ b/test/test_clogger.rb
@@ -241,32 +241,52 @@ class TestClogger < Test::Unit::TestCase
     str = StringIO.new
     app = lambda { |env| [ 200, {}, [] ] }
     cl = Clogger.new(app, :logger => str, :format => '$msec')
+    a = Time.now.to_f - 0.001
     status, header, bodies = cl.call(@req)
     assert_match %r(\A\d+\.\d{3}\n\z), str.string
+    b = Time.now.to_f + 0.001
+    logged = str.string.to_f
+    assert logged >= a, "#{logged} >= #{a}"
+    assert logged <= b, "#{logged} <= #{b}"
   end
 
   def test_usec
     str = StringIO.new
     app = lambda { |env| [ 200, {}, [] ] }
     cl = Clogger.new(app, :logger => str, :format => '$usec')
+    a = Time.now.to_f - 0.000001
     status, header, bodies = cl.call(@req)
     assert_match %r(\A\d+\.\d{6}\n\z), str.string
+    b = Time.now.to_f + 0.000001
+    logged = str.string.to_f
+    assert logged >= a, "#{logged} >= #{a}"
+    assert logged <= b, "#{logged} <= #{b}"
   end
 
   def test_time_0
     str = StringIO.new
     app = lambda { |env| [ 200, {}, [] ] }
     cl = Clogger.new(app, :logger => str, :format => '$time{0}')
+    a = Time.now.to_f - 1
     status, header, bodies = cl.call(@req)
     assert_match %r(\A\d+\n\z), str.string
+    b = Time.now.to_f + 1
+    logged = str.string.to_f
+    assert logged >= a, "#{logged} >= #{a}"
+    assert logged <= b, "#{logged} <= #{b}"
   end
 
   def test_time_1
     str = StringIO.new
     app = lambda { |env| [ 200, {}, [] ] }
     cl = Clogger.new(app, :logger => str, :format => '$time{1}')
+    a = Time.now.to_f - 0.5
     status, header, bodies = cl.call(@req)
     assert_match %r(\A\d+\.\d\n\z), str.string
+    b = Time.now.to_f + 0.5
+    logged = str.string.to_f
+    assert logged >= a, "#{logged} >= #{a}"
+    assert logged <= b, "#{logged} <= #{b}"
   end
 
   def test_request_length