Skip to content
This repository was archived by the owner on Dec 8, 2022. It is now read-only.

Commit 4fa4958

Browse files
committed
fix clock to show correct countdown to next day
1 parent 28ae266 commit 4fa4958

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

CodeChallenge/core.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from datetime import datetime, timezone, timedelta, time
1+
from datetime import datetime, timezone, timedelta
22

33
from flask import current_app
44
from sqlalchemy import func
@@ -20,7 +20,11 @@ def day_number() -> int:
2020
return -1
2121

2222
delta = now - start
23-
return 1 if delta.days == 0 else delta.days
23+
24+
if delta.days == 0:
25+
return 1
26+
27+
return delta.days + 1
2428

2529

2630
def current_rank() -> int:
@@ -42,16 +46,8 @@ def time_until_next_rank() -> str:
4246
epoch = int(current_app.config["CODE_CHALLENGE_START"])
4347
start = datetime.fromtimestamp(epoch, timezone.utc)
4448
now = datetime.now(timezone.utc)
45-
46-
if start > now:
47-
diff = datetime.combine(start, time.min, now.tzinfo) - now
48-
return str(diff)
49-
50-
tomorrow = now + timedelta(days=1)
51-
52-
diff = datetime.combine(tomorrow, time.min, now.tzinfo) - now
53-
54-
return str(diff)
49+
next_date = start + timedelta(days=day_number())
50+
return str(next_date - now)
5551

5652

5753
def friendly_starts_on() -> str:

0 commit comments

Comments
 (0)