[Groonga-commit] droonga/fluent-plugin-droonga at 54fce54 [master] Show micro seconds information for time value

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Dec 27 17:13:19 JST 2013


Kouhei Sutou	2013-12-27 17:13:19 +0900 (Fri, 27 Dec 2013)

  New Revision: 54fce54795660d6c43b4422ac93509a2846b4a0b
  https://github.com/droonga/fluent-plugin-droonga/commit/54fce54795660d6c43b4422ac93509a2846b4a0b

  Message:
    Show micro seconds information for time value

  Copied files:
    lib/droonga/time_formatter.rb
      (from lib/droonga/message_pack_packer.rb)
    test/unit/test_time_formatter.rb
      (from test/unit/test_message_pack_packer.rb)
  Modified files:
    lib/droonga/message_pack_packer.rb
    lib/droonga/searcher.rb
    test/unit/test_message_pack_packer.rb

  Modified: lib/droonga/message_pack_packer.rb (+5 -1)
===================================================================
--- lib/droonga/message_pack_packer.rb    2013-12-27 10:18:59 +0900 (539f0b5)
+++ lib/droonga/message_pack_packer.rb    2013-12-27 17:13:19 +0900 (3c15f0d)
@@ -17,6 +17,8 @@
 
 require "msgpack"
 
+require "droonga/time_formatter"
+
 module Droonga
   class MessagePackPacker
     class << self
@@ -27,6 +29,8 @@ module Droonga
       end
     end
 
+    MICRO_SECONDS_DECIMAL_PLACE = 6
+
     def initialize
       @packer = MessagePack::Packer.new
     end
@@ -45,7 +49,7 @@ module Droonga
           pack(value)
         end
       when Time
-        @packer.write(object.utc.iso8601)
+        @packer.write(TimeFormatter.format(object))
       else
         @packer.write(object)
       end

  Modified: lib/droonga/searcher.rb (+3 -1)
===================================================================
--- lib/droonga/searcher.rb    2013-12-27 10:18:59 +0900 (1d819ad)
+++ lib/droonga/searcher.rb    2013-12-27 17:13:19 +0900 (08ccf61)
@@ -19,6 +19,8 @@ require "English"
 require "tsort"
 require "groonga"
 
+require "droonga/time_formatter"
+
 module Droonga
   class Searcher
     class MissingSourceParameter < BadRequest
@@ -535,7 +537,7 @@ module Droonga
       end
 
       def format_start_time
-        @result.start_time.iso8601
+        TimeFormatter.format(@result.start_time)
       end
 
       def format_elapsed_time

  Copied: lib/droonga/time_formatter.rb (+10 -31) 52%
===================================================================
--- lib/droonga/message_pack_packer.rb    2013-12-27 10:18:59 +0900 (539f0b5)
+++ lib/droonga/time_formatter.rb    2013-12-27 17:13:19 +0900 (0d6325d)
@@ -1,5 +1,3 @@
-# -*- coding: utf-8 -*-
-#
 # Copyright (C) 2013 Droonga Project
 #
 # This library is free software; you can redistribute it and/or
@@ -15,44 +13,25 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-require "msgpack"
+require "time"
 
 module Droonga
-  class MessagePackPacker
+  class TimeFormatter
     class << self
-      def pack(object)
-        packer = new
-        packer.pack(object)
-        packer.to_s
+      def format(object)
+        formatter = new(object)
+        formatter.format
       end
     end
 
-    def initialize
-      @packer = MessagePack::Packer.new
-    end
+    MICRO_SECONDS_DECIMAL_PLACE = 6
 
-    def pack(object)
-      case object
-      when Array
-        @packer.write_array_header(object.size)
-        object.each do |element|
-          pack(element)
-        end
-      when Hash
-        @packer.write_map_header(object.size)
-        object.each do |key, value|
-          pack(key)
-          pack(value)
-        end
-      when Time
-        @packer.write(object.utc.iso8601)
-      else
-        @packer.write(object)
-      end
+    def initialize(time)
+      @time = time
     end
 
-    def to_s
-      @packer.to_s
+    def format
+      @time.utc.iso8601(MICRO_SECONDS_DECIMAL_PLACE)
     end
   end
 end

  Modified: test/unit/test_message_pack_packer.rb (+1 -1)
===================================================================
--- test/unit/test_message_pack_packer.rb    2013-12-27 10:18:59 +0900 (e8f201c)
+++ test/unit/test_message_pack_packer.rb    2013-12-27 17:13:19 +0900 (aba2210)
@@ -25,7 +25,7 @@ class MessagePackPackerTest < Test::Unit::TestCase
   end
 
   def test_time
-    w3c_dtf_time = "2013-11-29T08:00:00Z"
+    w3c_dtf_time = "2013-11-29T08:00:00.000000Z"
     time = Time.parse(w3c_dtf_time)
     assert_equal(w3c_dtf_time, unpack(pack(time)))
   end

  Copied: test/unit/test_time_formatter.rb (+7 -29) 53%
===================================================================
--- test/unit/test_message_pack_packer.rb    2013-12-27 10:18:59 +0900 (e8f201c)
+++ test/unit/test_time_formatter.rb    2013-12-27 17:13:19 +0900 (f2cef00)
@@ -13,39 +13,17 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-require "droonga/message_pack_packer"
+require "droonga/time_formatter"
 
-class MessagePackPackerTest < Test::Unit::TestCase
-  def test_integer
-    assert_equal(29, unpack(pack(29)))
-  end
-
-  def test_string
-    assert_equal("Droonga", unpack(pack("Droonga")))
-  end
-
-  def test_time
-    w3c_dtf_time = "2013-11-29T08:00:00Z"
+class TimeFormatterTest < Test::Unit::TestCase
+  def test_fraction
+    w3c_dtf_time = "2013-11-29T08:00:00.292929Z"
     time = Time.parse(w3c_dtf_time)
-    assert_equal(w3c_dtf_time, unpack(pack(time)))
-  end
-
-  def test_hash
-    hash = {"key" => "value"}
-    assert_equal(hash, unpack(pack(hash)))
-  end
-
-  def test_array
-    array = ["Groonga", "Rroonga", "Droonga"]
-    assert_equal(array, unpack(pack(array)))
+    assert_equal(w3c_dtf_time, format(time))
   end
 
   private
-  def pack(object)
-    Droonga::MessagePackPacker.pack(object)
-  end
-
-  def unpack(msgpack)
-    MessagePack.unpack(msgpack)
+  def format(time)
+    Droonga::TimeFormatter.format(time)
   end
 end
-------------- next part --------------
HTML����������������������������...
下载 



More information about the Groonga-commit mailing list
Back to archive index