Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/postgresql/converters.py
Show First 20 Lines • Show All 132 Lines • ▼ Show 20 Lines | def date_to_db(ts_with_tz: Optional[TimestampWithTimezone]) -> Dict[str, Any]: | ||||
ts = ts_with_tz.timestamp | ts = ts_with_tz.timestamp | ||||
timestamp = datetime.datetime.fromtimestamp(ts.seconds, datetime.timezone.utc) | timestamp = datetime.datetime.fromtimestamp(ts.seconds, datetime.timezone.utc) | ||||
timestamp = timestamp.replace(microsecond=ts.microseconds) | timestamp = timestamp.replace(microsecond=ts.microseconds) | ||||
return { | return { | ||||
# PostgreSQL supports isoformatted timestamps | # PostgreSQL supports isoformatted timestamps | ||||
"timestamp": timestamp.isoformat(), | "timestamp": timestamp.isoformat(), | ||||
"offset": ts_with_tz.offset, | "offset": ts_with_tz.offset_minutes(), | ||||
"neg_utc_offset": ts_with_tz.offset == 0 | "neg_utc_offset": ts_with_tz.offset_minutes() == 0 | ||||
and ts_with_tz.offset_bytes.startswith(b"-"), | and ts_with_tz.offset_bytes.startswith(b"-"), | ||||
"offset_bytes": ts_with_tz.offset_bytes, | "offset_bytes": ts_with_tz.offset_bytes, | ||||
} | } | ||||
def revision_to_db(revision: Revision) -> Dict[str, Any]: | def revision_to_db(revision: Revision) -> Dict[str, Any]: | ||||
"""Convert a swh-model revision to its database representation. | """Convert a swh-model revision to its database representation. | ||||
""" | """ | ||||
▲ Show 20 Lines • Show All 188 Lines • Show Last 20 Lines |