Skip to content
Snippets Groups Projects
Commit a8806fbb authored by Jenkins for Software Heritage's avatar Jenkins for Software Heritage
Browse files

New upstream version 4.2.0

parents a0b08bc3 56460e1d
No related branches found
Tags debian/upstream/4.2.0
No related merge requests found
Metadata-Version: 2.1
Name: swh.model
Version: 4.1.0
Version: 4.2.0
Summary: Software Heritage data model
Home-page: https://forge.softwareheritage.org/diffusion/DMOD/
Author: Software Heritage developers
......
Metadata-Version: 2.1
Name: swh.model
Version: 4.1.0
Version: 4.2.0
Summary: Software Heritage data model
Home-page: https://forge.softwareheritage.org/diffusion/DMOD/
Author: Software Heritage developers
......
......@@ -96,29 +96,6 @@ def format_date(date: model.Timestamp) -> bytes:
return float_value.rstrip("0").encode()
@lru_cache()
def format_offset(offset: int, negative_utc: Optional[bool] = None) -> bytes:
"""Convert an integer number of minutes into an offset representation.
The offset representation is [+-]hhmm where:
- hh is the number of hours;
- mm is the number of minutes.
A null offset is represented as +0000.
"""
if offset < 0 or offset == 0 and negative_utc:
sign = "-"
else:
sign = "+"
hours = abs(offset) // 60
minutes = abs(offset) % 60
t = "%s%02d%02d" % (sign, hours, minutes)
return t.encode()
def normalize_timestamp(time_representation):
"""Normalize a time representation for processing by Software Heritage
......@@ -291,9 +268,8 @@ def format_author_data(
if date_offset is not None:
date_f = format_date(date_offset.timestamp)
offset_f = format_offset(date_offset.offset, date_offset.negative_utc)
ret.extend([b" ", date_f, b" ", offset_f])
ret.extend([b" ", date_f, b" ", date_offset.offset_bytes])
return b"".join(ret)
......
......@@ -41,20 +41,10 @@ class UtilityFunctionsDateOffset(unittest.TestCase):
b"1448210036.12": {"seconds": 1448210036, "microseconds": 120000,},
}
self.offsets = {
0: b"+0000",
-630: b"-1030",
800: b"+1320",
}
def test_format_date(self):
for date_repr, date in self.dates.items():
self.assertEqual(git_objects.format_date(date), date_repr)
def test_format_offset(self):
for offset, res in self.offsets.items():
self.assertEqual(git_objects.format_offset(offset), res)
content_example = {
"status": "visible",
......
......@@ -468,6 +468,16 @@ def test_timestampwithtimezone():
assert tstz.negative_utc is True
assert tstz.offset_bytes == b"-0000"
tstz = TimestampWithTimezone(timestamp=ts, offset=-630, negative_utc=False)
attr.validate(tstz)
assert tstz.negative_utc is False
assert tstz.offset_bytes == b"-1030"
tstz = TimestampWithTimezone(timestamp=ts, offset=800, negative_utc=False)
attr.validate(tstz)
assert tstz.negative_utc is False
assert tstz.offset_bytes == b"+1320"
with pytest.raises(AttributeTypeError):
TimestampWithTimezone(
timestamp=datetime.datetime.now(), offset=0, negative_utc=False
......
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