Repository: stuartmccoll/gitlab-changelog-generator

Issue:
Issue with date format
Hello,

When executing gitlab-changelog-generator, I get this issue:
`ValueError: time data '2019-04-15T08:58:4' does not match format '%Y-%m-%dT%H:%M:%S.%f'`

In DEBUG we can see the dates like:
```
'committed_date': '2019-04-15T08:58:44.000Z'
'authored_date': '2019-04-15T08:58:44.000Z'
```

Thanks for your help.

Discussion:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c592206..57d78f7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
 # CHANGELOG
 
+## v1.0.5 - 2019/06/01
+
+- Amended the way date formatting is handled - [issue](https://github.com/stuartmccoll/gitlab-changelog-generator/issues/25) raised by [smutel](https://github.com/smutel), commit(s) contributed by [smutel](https://github.com/smutel).
+
 ## v1.0.4 - 2019/03/09
 
 - Amended IP address command line argument to also require the relevant protocol (HTTP/S).
diff --git a/changelog_generator/calls.py b/changelog_generator/calls.py
index 21c184f..2546183 100644
--- a/changelog_generator/calls.py
+++ b/changelog_generator/calls.py
@@ -3,6 +3,8 @@ import logging
 import requests
 import sys
 
+from dateutil import parser
+
 
 logger = logging.getLogger(__name__)
 
@@ -45,10 +47,11 @@ def get_last_commit_date(cli_args: dict) -> str:
         response_json["committed_date"][:-6], "%Y-%m-%dT%H:%M:%S.%f"
     ) + datetime.timedelta(seconds=1)
 
-    return datetime.datetime.strftime(
-        commit_date,
-        f"%Y-%m-%dT%H:%M:%S.%f{response_json['committed_date'][-6:]}",
-    )
+    commit_date = parser.parse(
+        response_json["committed_date"]
+    ) + datetime.timedelta(microseconds=1)
+
+    return datetime.datetime.strftime(commit_date, "%Y-%m-%dT%H:%M:%S.%f")
 
 
 def get_closed_issues_for_project(cli_args: dict) -> dict:
@@ -158,7 +161,7 @@ def get_commits_since_date(date: str, cli_args: dict) -> list:
 
     return sorted(
         clean_response,
-        key=lambda x: datetime.datetime.strptime(
-            x["committed_date"][:-6], "%Y-%m-%dT%H:%M:%S.%f"
+        key=lambda x: datetime.datetime.strftime(
+            parser.parse(x["committed_date"]), "%Y-%m-%dT%H:%M:%S.%f"
         ),
     )
diff --git a/setup.py b/setup.py
index 8c4cd08..dd09982 100644
--- a/setup.py
+++ b/setup.py
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
 
 setuptools.setup(
     name="gitlab-changelog-generator",
-    version="1.0.4",
+    version="1.0.5",
     author="Stuart McColl",
     author_email="it@stuartmccoll.co.uk",
     description="A small command line utility for generating CHANGELOG.md "
@@ -18,7 +18,7 @@ setuptools.setup(
         "console_scripts": ["changegen=changelog_generator.entry_point:main"]
     },
     packages=setuptools.find_packages(),
-    install_requires=["requests"],
+    install_requires=["requests", "python-dateutil"],
     tests_require=["unittest", "mock"],
     classifiers=(
         "Environment :: Console",


Test patch:
diff --git a/changelog_generator/tests/test_calls.py b/changelog_generator/tests/test_calls.py
index 0024e2f..2147a0a 100644
--- a/changelog_generator/tests/test_calls.py
+++ b/changelog_generator/tests/test_calls.py
@@ -54,7 +54,7 @@ class TestCalls(unittest.TestCase):
         }
 
         commit_date = get_last_commit_date(cli_args)
-        self.assertEqual(commit_date, "2018-06-10T14:01:45.000000+00:00")
+        self.assertEqual(commit_date, "2018-06-10T14:01:44.000001")
 
     @mock.patch("sys.exit")
     @mock.patch("changelog_generator.calls.requests.get")