Skip to content

Commit

Permalink
parse iso datetime in constest.yaml for start/stop
Browse files Browse the repository at this point in the history
  • Loading branch information
Virv12 authored and wil93 committed Oct 5, 2024
1 parent 1a687a4 commit a7d4643
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions cmscontrib/loaders/italy_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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"])

Expand Down

0 comments on commit a7d4643

Please sign in to comment.