Changeset View
Changeset View
Standalone View
Standalone View
swh/model/model.py
Show First 20 Lines • Show All 622 Lines • ▼ Show 20 Lines | def from_iso8601(cls, s): | ||||
""" | """ | ||||
dt = iso8601.parse_date(s) | dt = iso8601.parse_date(s) | ||||
tstz = cls.from_datetime(dt) | tstz = cls.from_datetime(dt) | ||||
if dt.tzname() == "-00:00": | if dt.tzname() == "-00:00": | ||||
assert tstz.offset_bytes == b"+0000" | assert tstz.offset_bytes == b"+0000" | ||||
tstz = attr.evolve(tstz, offset_bytes=b"-0000", negative_utc=True) | tstz = attr.evolve(tstz, offset_bytes=b"-0000", negative_utc=True) | ||||
return tstz | return tstz | ||||
def offset_minutes(self): | |||||
"""Returns the offset, as a number of minutes since UTC. | |||||
>>> TimestampWithTimezone( | |||||
... Timestamp(seconds=1642765364, microseconds=0), offset_bytes=b"+0000" | |||||
... ).offset_minutes() | |||||
0 | |||||
>>> TimestampWithTimezone( | |||||
... Timestamp(seconds=1642765364, microseconds=0), offset_bytes=b"+0200" | |||||
... ).offset_minutes() | |||||
120 | |||||
>>> TimestampWithTimezone( | |||||
... Timestamp(seconds=1642765364, microseconds=0), offset_bytes=b"-0200" | |||||
... ).offset_minutes() | |||||
-120 | |||||
>>> TimestampWithTimezone( | |||||
... Timestamp(seconds=1642765364, microseconds=0), offset_bytes=b"+0530" | |||||
... ).offset_minutes() | |||||
330 | |||||
""" | |||||
return self.offset | |||||
@attr.s(frozen=True, slots=True) | @attr.s(frozen=True, slots=True) | ||||
class Origin(HashableObject, BaseModel): | class Origin(HashableObject, BaseModel): | ||||
"""Represents a software source: a VCS and an URL.""" | """Represents a software source: a VCS and an URL.""" | ||||
object_type: Final = "origin" | object_type: Final = "origin" | ||||
url = attr.ib(type=str, validator=type_validator()) | url = attr.ib(type=str, validator=type_validator()) | ||||
▲ Show 20 Lines • Show All 902 Lines • Show Last 20 Lines |