Compare commits
5 Commits
1.4.0
...
3b37f2c3f0
Author | SHA1 | Date | |
---|---|---|---|
3b37f2c3f0 | |||
4517ff2b5a | |||
884ce13e26 | |||
dd219bae9d | |||
60d29090a1 |
@ -44,7 +44,7 @@ def format_duration(
|
|||||||
# timestamps where end is before start
|
# timestamps where end is before start
|
||||||
if seconds_total < 0:
|
if seconds_total < 0:
|
||||||
seconds_total = 0
|
seconds_total = 0
|
||||||
days = hours = minutes = seconds = 0
|
days = hours = hours_float = minutes = seconds = 0
|
||||||
remainder = seconds = seconds_total
|
remainder = seconds = seconds_total
|
||||||
if "%d" in format_string:
|
if "%d" in format_string:
|
||||||
days, remainder = divmod(seconds_total, day_seconds)
|
days, remainder = divmod(seconds_total, day_seconds)
|
||||||
@ -55,7 +55,7 @@ def format_duration(
|
|||||||
minutes, seconds = divmod(remainder, minute_seconds)
|
minutes, seconds = divmod(remainder, minute_seconds)
|
||||||
literals = {
|
literals = {
|
||||||
"d": str(days),
|
"d": str(days),
|
||||||
"H": str(hours),
|
"H": str(hours) if "m" not in format_string else str(hours_float),
|
||||||
"m": str(minutes),
|
"m": str(minutes),
|
||||||
"s": str(seconds),
|
"s": str(seconds),
|
||||||
"r": str(seconds_total),
|
"r": str(seconds_total),
|
||||||
|
@ -11,7 +11,6 @@ urlpatterns = [
|
|||||||
name="list_sessions_recent",
|
name="list_sessions_recent",
|
||||||
),
|
),
|
||||||
path("add-game/", views.add_game, name="add_game"),
|
path("add-game/", views.add_game, name="add_game"),
|
||||||
path("add-game-unified/", views.add_game_unified, name="add_game_unified"),
|
|
||||||
path("add-platform/", views.add_platform, name="add_platform"),
|
path("add-platform/", views.add_platform, name="add_platform"),
|
||||||
path("add-session/", views.add_session, name="add_session"),
|
path("add-session/", views.add_session, name="add_session"),
|
||||||
path(
|
path(
|
||||||
|
@ -380,9 +380,15 @@ def stats(request, year: int = 0):
|
|||||||
"spent_per_game": int(
|
"spent_per_game": int(
|
||||||
safe_division(total_spent, this_year_purchases_without_refunded.count())
|
safe_division(total_spent, this_year_purchases_without_refunded.count())
|
||||||
),
|
),
|
||||||
"all_finished_this_year": purchases_finished_this_year,
|
"all_finished_this_year": purchases_finished_this_year.order_by(
|
||||||
"this_year_finished_this_year": purchases_finished_this_year_released_this_year,
|
"date_finished"
|
||||||
"purchased_this_year_finished_this_year": purchased_this_year_finished_this_year,
|
),
|
||||||
|
"this_year_finished_this_year": purchases_finished_this_year_released_this_year.order_by(
|
||||||
|
"date_finished"
|
||||||
|
),
|
||||||
|
"purchased_this_year_finished_this_year": purchased_this_year_finished_this_year.order_by(
|
||||||
|
"date_finished"
|
||||||
|
),
|
||||||
"total_sessions": this_year_sessions.count(),
|
"total_sessions": this_year_sessions.count(),
|
||||||
"unique_days": unique_days["dates"],
|
"unique_days": unique_days["dates"],
|
||||||
"unique_days_percent": int(unique_days["dates"] / 365 * 100),
|
"unique_days_percent": int(unique_days["dates"] / 365 * 100),
|
||||||
@ -477,7 +483,12 @@ def add_edition(request, game_id=None):
|
|||||||
if game_id:
|
if game_id:
|
||||||
game = Game.objects.get(id=game_id)
|
game = Game.objects.get(id=game_id)
|
||||||
form = EditionForm(
|
form = EditionForm(
|
||||||
initial={"game": game, "name": game.name, "sort_name": game.sort_name}
|
initial={
|
||||||
|
"game": game,
|
||||||
|
"name": game.name,
|
||||||
|
"sort_name": game.sort_name,
|
||||||
|
"year_released": game.year_released,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
form = EditionForm()
|
form = EditionForm()
|
||||||
|
@ -83,6 +83,16 @@ class FormatDurationTest(unittest.TestCase):
|
|||||||
result = format_duration(delta, "%r seconds")
|
result = format_duration(delta, "%r seconds")
|
||||||
self.assertEqual(result, "0 seconds")
|
self.assertEqual(result, "0 seconds")
|
||||||
|
|
||||||
|
def test_specific(self):
|
||||||
|
delta = timedelta(hours=2, minutes=40)
|
||||||
|
result = format_duration(delta, "%H:%m")
|
||||||
|
self.assertEqual(result, "2:40")
|
||||||
|
|
||||||
|
def test_specific_precise_if_unncessary(self):
|
||||||
|
delta = timedelta(hours=2, minutes=40)
|
||||||
|
result = format_duration(delta, "%02.0H:%02.0m")
|
||||||
|
self.assertEqual(result, "02:40")
|
||||||
|
|
||||||
def test_all_at_once(self):
|
def test_all_at_once(self):
|
||||||
delta = timedelta(days=50, hours=10, minutes=34, seconds=24)
|
delta = timedelta(days=50, hours=10, minutes=34, seconds=24)
|
||||||
result = format_duration(
|
result = format_duration(
|
||||||
|
Reference in New Issue
Block a user