Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bell and minute rollover, add test case #15

Merged
merged 3 commits into from
Sep 11, 2024
Merged
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
4 changes: 2 additions & 2 deletions EorzeaEnv/eorzea_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def bell(self, value):
self._bell += 24
self.sun = self.sun - 1

while self._bell > 24:
while self._bell >= 24:
self._bell -= 24
self.sun = self.sun + 1

Expand All @@ -121,7 +121,7 @@ def minute(self, value):
self._minute += 60
self.bell = self.bell - 1

while self._minute > 60:
while self._minute >= 60:
self._minute -= 60
self.bell = self.bell + 1

Expand Down
68 changes: 58 additions & 10 deletions test/test_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,64 @@ def test_time_operator(self):
assert t1 != 1
assert not t1 == 1

def test_positive_rollover(self):
et = EorzeaTime()
et.minute = 59
et.bell = 23
et.sun = 32
et.moon = 12
et.year = 999

et.minute += 1

assert et.minute == 0
assert et.bell == 0
assert et.sun == 1
assert et.moon == 1
assert et.year == 1000

et.minute += 121

assert et.minute == 1
assert et.bell == 2

et.bell += 49

assert et.bell == 3
assert et.sun == 3

def test_negative_rollover(self):
et = EorzeaTime()
et.minute = 0
et.bell = 0
et.sun = 1
et.moon = 2
et.year = 1000

et.minute -= 1

assert et.minute == 59
assert et.bell == 23
assert et.sun == 32
assert et.moon == 1

et.minute -= 119

assert et.minute == 0
assert et.bell == 22

et.bell -= 48

assert et.minute == 0
assert et.bell == 22
assert et.sun == 30
assert et.moon == 1

et.moon -= 11

assert et.moon == 2
assert et.year == 999

def test_property(self):
ts = 12700000
et = EorzeaTime(ts)
Expand All @@ -73,16 +131,6 @@ def test_property(self):
assert et.moon_phase == 0.50
assert et.moon_name == "Sixth Embral Moon"

et = EorzeaTime()
et.moon += 13
et.sun += 33
et.bell += 26
et.minute += 65
et.moon -= 13
et.sun -= 33
et.bell -= 26
et.minute -= 65

def test_repr(self):
et = EorzeaTime.now()
assert repr(et) == f"EorzeaTime({et.get_unix_time()})"
Expand Down
Loading