From 026a88acb81e668ee362386e54f40c2a98e701e3 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 31 Mar 2022 19:40:05 +0200 Subject: [PATCH] fix comparation datas put both in utc time --- ereuse_devicehub/resources/action/models.py | 3 ++- ereuse_devicehub/resources/action/schemas.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ereuse_devicehub/resources/action/models.py b/ereuse_devicehub/resources/action/models.py index 09f17025..92805ab5 100644 --- a/ereuse_devicehub/resources/action/models.py +++ b/ereuse_devicehub/resources/action/models.py @@ -17,6 +17,7 @@ from datetime import datetime, timedelta, timezone from decimal import ROUND_HALF_EVEN, ROUND_UP, Decimal from typing import Optional, Set, Union from uuid import uuid4 +from dateutil.tz import tzutc import inflection import teal.db @@ -273,7 +274,7 @@ class Action(Thing): super().__init__(**kwargs) def __lt__(self, other): - return self.end_time < other.end_time + return self.end_time.replace(tzinfo=tzutc()) < other.end_time.replace(tzinfo=tzutc()) def __str__(self) -> str: return '{}'.format(self.severity) diff --git a/ereuse_devicehub/resources/action/schemas.py b/ereuse_devicehub/resources/action/schemas.py index 15e1a972..5c8f2d5f 100644 --- a/ereuse_devicehub/resources/action/schemas.py +++ b/ereuse_devicehub/resources/action/schemas.py @@ -73,10 +73,10 @@ class Action(Thing): @validates_schema def validate_times(self, data: dict): unix_time = datetime.fromisoformat("1970-01-02 00:00:00+00:00") - if 'end_time' in data and data['end_time'] < unix_time: + if 'end_time' in data and data['end_time'].replace(tzinfo=tzutc()) < unix_time: data['end_time'] = unix_time - if 'start_time' in data and data['start_time'] < unix_time: + if 'start_time' in data and data['start_time'].replace(tzinfo=tzutc()) < unix_time: data['start_time'] = unix_time if data.get('end_time') and data.get('start_time'):