Skip to content
Snippets Groups Projects
Commit a654060b authored by vlorentz's avatar vlorentz
Browse files

Add method 'TimestampWithTimezone.offset_minutes'

A future commit will remove the 'offset' attribute, and rename
'offset_bytes' to 'offset'.

Modules using the `.offset` attribute will need to switch to this new
method to keep working.
parent f43f9ac9
No related branches found
Tags v4.4.0
No related merge requests found
......@@ -628,6 +628,28 @@ class TimestampWithTimezone(BaseModel):
tstz = attr.evolve(tstz, offset_bytes=b"-0000", negative_utc=True)
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)
class Origin(HashableObject, BaseModel):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment