OSDN Git Service

Backported 87d145bd1f1a14a33f5f6fbc78b63a1952f1ca90 and 2df8c798aeb7f0e77735e893fd137... 20121229
authorDaigo Moriwaki <beatles@users.sourceforge.jp>
Sun, 30 Dec 2012 08:24:33 +0000 (17:24 +0900)
committerDaigo Moriwaki <beatles@users.sourceforge.jp>
Sun, 30 Dec 2012 08:24:33 +0000 (17:24 +0900)
  shogi_server/floodgate.rb: Generating next time around the new
  year day by reading configuration files did not work correctly.
  This issue has been fixed.

changelog
shogi_server/league/floodgate.rb
test/TC_floodgate_next_time_generator.rb

index 9af0f52..e2b3ab5 100644 (file)
--- a/changelog
+++ b/changelog
@@ -4,6 +4,11 @@
          - Backported a5c94012656902e73e00f46e7a4c7004b24d4578:
            test/TC_logger.rb depeneded on a specific directory where it was
            running on. This issues has been fixed.
+         - Backported 87d145bd1f1a14a33f5f6fbc78b63a1952f1ca90 and
+           2df8c798aeb7f0e77735e893fd1370c2c6f15c4d:
+           shogi_server/floodgate.rb: Generating next time around the new
+           year day by reading configuration files did not work correctly.
+           This issue has been fixed.
 
 2012-12-28  Daigo Moriwaki <daigo at debian dot org>
 
index f721d3a..b5478b9 100644 (file)
@@ -120,7 +120,7 @@ class League
             next if dow_index.nil?
             next unless (0..23).include?(hour)
             next unless (0..59).include?(minute)
-            time = DateTime::commercial(now.year, now.cweek, dow_index, hour, minute) rescue next
+            time = DateTime::commercial(now.cwyear, now.cweek, dow_index, hour, minute) rescue next
             time += 7 if time <= now 
             candidates << time
           end
index 4bfe20e..a52c6c2 100644 (file)
@@ -85,6 +85,11 @@ class TestNextTimeGenerator_900_0 < Test::Unit::TestCase
     now = Time.mktime(2009,12,31,23,50)
     assert_equal(Time.mktime(2010,1,1,0,0), @next.call(now))
   end
+
+  def test_50_min_new_year
+    now = Time.mktime(2012,1,1,0,0)
+    assert_equal(Time.mktime(2012,1,1,0,30), @next.call(now))
+  end
 end
 
 class TestNextTimeGenerator_3600_0 < Test::Unit::TestCase
@@ -126,6 +131,11 @@ class TestNextTimeGenerator_3600_0 < Test::Unit::TestCase
     now = Time.mktime(2009,12,31,23,30)
     assert_equal(Time.mktime(2010,1,1,1,0), @next.call(now))
   end
+
+  def test_new_year
+    now = Time.mktime(2012,1,1,0,0)
+    assert_equal(Time.mktime(2012,1,1,1,0), @next.call(now))
+  end
 end
 
 class TestNextTimeGeneratorConfig < Test::Unit::TestCase
@@ -153,6 +163,30 @@ class TestNextTimeGeneratorConfig < Test::Unit::TestCase
     assert_equal Time.parse("17-06-2010 20:00"), ntc.call(now)
   end
 
+  def test_next_year01
+    now = DateTime.new(2011, 12, 30, 21, 20, 15) # Fri
+    ntc = ShogiServer::League::Floodgate::NextTimeGeneratorConfig.new ["Sun 00:00"]
+    assert_equal Time.parse("01-01-2012 00:00"), ntc.call(now)
+    ntc = ShogiServer::League::Floodgate::NextTimeGeneratorConfig.new ["Sun 01:00"]
+    assert_equal Time.parse("01-01-2012 01:00"), ntc.call(now)
+  end
+
+  def test_next_year02
+    now = DateTime.new(2011, 12, 30, 21, 20, 15) # Fri
+    ntc = ShogiServer::League::Floodgate::NextTimeGeneratorConfig.new ["Mon 00:00"]
+    assert_equal Time.parse("02-01-2012 00:00"), ntc.call(now)
+    ntc = ShogiServer::League::Floodgate::NextTimeGeneratorConfig.new ["Mon 01:00"]
+    assert_equal Time.parse("02-01-2012 01:00"), ntc.call(now)
+  end
+
+  def test_new_year
+    now = DateTime.new(2012, 1, 1, 1) # Sun; cwyear=2011, cweek=52
+    ntc = ShogiServer::League::Floodgate::NextTimeGeneratorConfig.new ["Mon 00:00"]
+    assert_equal Time.parse("02-01-2012 00:00"), ntc.call(now)
+    ntc = ShogiServer::League::Floodgate::NextTimeGeneratorConfig.new ["Sat 00:00"]
+    assert_equal Time.parse("07-01-2012 00:00"), ntc.call(now)
+  end
+
   def test_read_time
     now = Time.mktime(2010, 6, 10, 21, 20, 15)
     ntc = ShogiServer::League::Floodgate::NextTimeGeneratorConfig.new "Thu 22:00"