diff --git a/requirements.txt b/requirements.txt --- a/requirements.txt +++ b/requirements.txt @@ -3,6 +3,5 @@ # dependency lines, see https://pip.readthedocs.org/en/1.1/requirements.html click iso8601 -python-dateutil subvertpy >= 0.9.4 typing-extensions diff --git a/swh/loader/svn/converters.py b/swh/loader/svn/converters.py --- a/swh/loader/svn/converters.py +++ b/swh/loader/svn/converters.py @@ -6,17 +6,17 @@ import datetime from typing import Dict, Optional, Sequence, Tuple -import dateutil +import iso8601 from swh.model.model import Person, Revision, RevisionType, TimestampWithTimezone -def svn_date_to_swh_date(strdate: Optional[str]) -> TimestampWithTimezone: +def svn_date_to_swh_date(strdate: Optional[bytes]) -> TimestampWithTimezone: """Convert a string date to an swh one. Args: strdate: A string representing a date with format like - 'YYYY-mm-DDTHH:MM:SS.800722Z' + ``b'YYYY-mm-DDTHH:MM:SS.800722Z'`` Returns: An swh date format @@ -25,8 +25,7 @@ if not strdate: # either None or empty string dt = datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc) else: - # TODO: Migrate to iso8601 if possible - dt = dateutil.parser.parse(strdate) + dt = iso8601.parse_date(strdate.decode("ascii")) assert dt.tzinfo is not None, strdate return TimestampWithTimezone.from_datetime(dt) diff --git a/swh/loader/svn/svn.py b/swh/loader/svn/svn.py --- a/swh/loader/svn/svn.py +++ b/swh/loader/svn/svn.py @@ -110,7 +110,7 @@ return msg return msg.encode("utf-8") - def convert_commit_date(self, date: str) -> TimestampWithTimezone: + def convert_commit_date(self, date: bytes) -> TimestampWithTimezone: """Convert the message commit date into a timestamp in swh format. The precision is kept. diff --git a/swh/loader/svn/tests/test_converters.py b/swh/loader/svn/tests/test_converters.py --- a/swh/loader/svn/tests/test_converters.py +++ b/swh/loader/svn/tests/test_converters.py @@ -97,7 +97,7 @@ """ assert converters.svn_date_to_swh_date( - "2011-05-31T06:04:39.500900Z" + b"2011-05-31T06:04:39.500900Z" ) == TimestampWithTimezone( timestamp=Timestamp(seconds=1306821879, microseconds=500900), offset=0, @@ -105,7 +105,7 @@ ) assert converters.svn_date_to_swh_date( - "2011-05-31T06:04:39.800722Z" + b"2011-05-31T06:04:39.800722Z" ) == TimestampWithTimezone( timestamp=Timestamp(seconds=1306821879, microseconds=800722), offset=0,