Skip to content

Commit

Permalink
fix(sample_project): fix countdown
Browse files Browse the repository at this point in the history
Closes: #992
  • Loading branch information
b1rger committed Jun 24, 2024
1 parent 719931c commit 31b05b0
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions sample_project/templatetags/sample_project.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import datetime
from datetime import datetime, time, date, timedelta, UTC
import pathlib
from django import template

Expand All @@ -12,6 +12,16 @@ def password():

@register.simple_tag
def teardown():
date = datetime.datetime.fromisoformat(pathlib.Path("/tmp/startup.txt").read_text())
until = date + datetime.timedelta(hours=6)
return until
init_date = datetime.combine(date.today(), time(0, 30, 0), tzinfo=UTC)
# create timetsamps for today
timestamps = [
init_date,
init_date.replace(hour=6),
init_date.replace(hour=12),
init_date.replace(hour=18),
]
# create timestamps for tomorrow
timestamps += list(map(lambda x: x + timedelta(hours=24), timestamps))
# filter timestamps that are after now
timestamps = list(filter(lambda x: x > datetime.now(UTC), timestamps))
return timestamps[0]

0 comments on commit 31b05b0

Please sign in to comment.