Page MenuHomeSoftware Heritage
Paste P695

negative_utc tristate
ActivePublic

Authored by olasd on Jun 12 2020, 12:42 PM.
modified swh/model/model.py
@@ -175,7 +175,7 @@ class TimestampWithTimezone(BaseModel):
timestamp = attr.ib(type=Timestamp, validator=type_validator())
offset = attr.ib(type=int, validator=type_validator())
- negative_utc = attr.ib(type=bool, validator=type_validator())
+ negative_utc = attr.ib(type=Optional[bool], validator=type_validator())
@offset.validator
def check_offset(self, attribute, value):
@@ -188,8 +188,10 @@ class TimestampWithTimezone(BaseModel):
@negative_utc.validator
def check_negative_utc(self, attribute, value):
+ if value is None and self.offset == 0:
+ raise ValueError("negative_utc can only be unset when offset != 0")
if self.offset and value:
- raise ValueError("negative_utc can only be True is offset=0")
+ raise ValueError("negative_utc can only be True when offset == 0")
@classmethod
def from_dict(cls, obj: Union[Dict, datetime.datetime, int]):