From 87d1fc190046a3dc5c0b63dc892bdc9a6679abb7 Mon Sep 17 00:00:00 2001 From: Filippo Casarin Date: Tue, 7 May 2024 19:04:03 +0200 Subject: [PATCH] parse iso datetime in constest.yaml for start/stop --- cmscontrib/loaders/italy_yaml.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/cmscontrib/loaders/italy_yaml.py b/cmscontrib/loaders/italy_yaml.py index bd9448258..f307522f9 100644 --- a/cmscontrib/loaders/italy_yaml.py +++ b/cmscontrib/loaders/italy_yaml.py @@ -27,7 +27,7 @@ import os import os.path import sys -from datetime import timedelta +from datetime import datetime, timedelta, timezone from copy import deepcopy import yaml @@ -40,7 +40,6 @@ from cmscommon.constants import \ SCORE_MODE_MAX, SCORE_MODE_MAX_SUBTASK, SCORE_MODE_MAX_TOKENED_LAST from cmscommon.crypto import build_password -from cmscommon.datetime import make_datetime from cmscontrib import touch from .base_loader import ContestLoader, TaskLoader, UserLoader, TeamLoader, LANGUAGE_MAP @@ -125,6 +124,12 @@ def load(src, dst, src_name, dst_name=None, conv=lambda i: i): return conv(res) +def parse_datetime(val): + if isinstance(val, (int, float)): + return datetime.fromtimestamp(val, timezone.utc) + return datetime.fromisoformat(val) + + def make_timedelta(t): return timedelta(seconds=t) @@ -214,8 +219,8 @@ def get_contest(self): if args["token_gen_interval"].total_seconds() == 0: args["token_gen_interval"] = timedelta(minutes=1) - load(conf, args, ["start", "inizio"], conv=make_datetime) - load(conf, args, ["stop", "fine"], conv=make_datetime) + load(conf, args, ["start", "inizio"], conv=parse_datetime) + load(conf, args, ["stop", "fine"], conv=parse_datetime) load(conf, args, ["per_user_time"], conv=make_timedelta) load(conf, args, ["timezone"])