Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions chess/pgn.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,8 @@ def set_clock(self, seconds: Optional[float]) -> None:
"""
clk = ""
if seconds is not None:
seconds = max(0, seconds)
# nearest ms, otherwise 59.9996 becomes an invalid :60
seconds = round(max(0, seconds), 3)
hours = int(seconds // 3600)
minutes = int(seconds % 3600 // 60)
seconds = seconds % 3600 % 60
Expand Down Expand Up @@ -595,7 +596,8 @@ def set_emt(self, seconds: Optional[float]) -> None:
"""
emt = ""
if seconds is not None:
seconds = max(0, seconds)
# nearest ms, otherwise 59.9996 becomes an invalid :60
seconds = round(max(0, seconds), 3)
hours = int(seconds // 3600)
minutes = int(seconds % 3600 // 60)
seconds = seconds % 3600 % 60
Expand Down
16 changes: 16 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2970,6 +2970,14 @@ def test_float_emt(self):
self.assertEqual(game.comments, ["[%emt 0:00:00]"]) # Clamped
self.assertEqual(game.emt(), 0)

game.set_emt(59.9996)
self.assertEqual(game.comments, ["[%emt 0:01:00]"])
self.assertEqual(game.emt(), 60)

game.set_emt(3599.9999)
self.assertEqual(game.comments, ["[%emt 1:00:00]"])
self.assertEqual(game.emt(), 3600)

def test_float_clk(self):
game = chess.pgn.Game()
game.comments = ["[%clk 0:00:01.234]"]
Expand All @@ -2983,6 +2991,14 @@ def test_float_clk(self):
self.assertEqual(game.comments, ["[%clk 0:00:00]"]) # Clamped
self.assertEqual(game.clock(), 0)

game.set_clock(59.9996)
self.assertEqual(game.comments, ["[%clk 0:01:00]"])
self.assertEqual(game.clock(), 60)

game.set_clock(3599.9999)
self.assertEqual(game.comments, ["[%clk 1:00:00]"])
self.assertEqual(game.clock(), 3600)

def test_node_turn(self):
game = chess.pgn.Game()
self.assertEqual(game.turn(), chess.WHITE)
Expand Down
Loading