Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6600e30

Browse files
committedJul 4, 2024·
Use humanize module
1 parent 36b4f1a commit 6600e30

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed
 

Diff for: ‎oioioi/statistics/views.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from django.urls import reverse
1010
from django.utils.translation import gettext_lazy as _
1111
from django.db.models import F
12+
from humanize import naturaldelta
1213

1314
from oioioi.base.menu import menu_registry
1415
from oioioi.base.permissions import enforce_condition
@@ -198,13 +199,13 @@ def get_rounds_info(request):
198199
for round_, rt in rounds_times(request, request.contest).items():
199200
round_time_info = {'name': str(round_), 'start': rt.start or _("Not set")}
200201
if rt.start:
201-
round_time_info['start_relative'] = str(rt.start - request.timestamp)[:-7] if rt.is_future(
202+
round_time_info['start_relative'] = naturaldelta(rt.start - request.timestamp) if rt.is_future(
202203
request.timestamp) else _("Started")
203204
else:
204205
round_time_info['start_relative'] = _("Not set")
205206
round_time_info['end'] = rt.end or _("Not set")
206207
if rt.end:
207-
round_time_info['end_relative'] = str(rt.end - request.timestamp)[:-7] if not rt.is_past(
208+
round_time_info['end_relative'] = naturaldelta(rt.end - request.timestamp) if not rt.is_past(
208209
request.timestamp) else _("Finished")
209210
else:
210211
round_time_info['end_relative'] = _("Not set")
@@ -217,7 +218,7 @@ def get_attachments_info(request):
217218
for attachment in attachments:
218219
pub_date_relative = None
219220
if attachment.pub_date:
220-
pub_date_relative = str(attachment.pub_date - request.timestamp)[:-7] \
221+
pub_date_relative = naturaldelta(attachment.pub_date - request.timestamp) \
221222
if attachment.pub_date > request.timestamp else _("Published")
222223
setattr(attachment, 'pub_date_relative', pub_date_relative)
223224
return attachments

Diff for: ‎setup.py

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
# A library allowing to nest inlines in django admin.
6464
# Used in quizzes module for adding new quizzes.
6565
"django-nested-admin>=4.0,<4.1",
66+
# Library for parsing dates and timedelta
67+
"humanize<=4.9.0"
6668
# SIO2 dependencies:
6769
"filetracker>=2.1,<3.0",
6870
"django-simple-captcha>=0.5,<=0.5.18",

0 commit comments

Comments
 (0)
Please sign in to comment.