Browse Source

python3.5: replaced datetime.isoformat(datespec=...) with .strftime

Fabian Peter Hammerle 3 years ago
parent
commit
5abc53b28e
2 changed files with 4 additions and 3 deletions
  1. 1 0
      CHANGELOG.md
  2. 3 3
      systemctl_mqtt/__init__.py

+ 1 - 0
CHANGELOG.md

@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
   - replaced [PEP526](https://www.python.org/dev/peps/pep-0526/#abstract)-style variable type hints
     with [PEP484](https://www.python.org/dev/peps/pep-0484/)-compatible
   - fixed `AttributeError` due to unavailable `MagicMock.assert_called_once`
+  - fixed `TypeError` when calling `datetime.datetime.isoformat(datespec=…)`
 
 ## [0.1.0] - 2020-06-16
 ### Added

+ 3 - 3
systemctl_mqtt/__init__.py

@@ -46,10 +46,10 @@ def _schedule_shutdown(action: str) -> None:
     # https://github.com/systemd/systemd/blob/v237/src/systemctl/systemctl.c#L8553
     assert action in ["poweroff", "reboot"], action
     shutdown_datetime = datetime.datetime.now() + _SHUTDOWN_DELAY
+    # datetime.datetime.isoformat(timespec=) not available in python3.5
+    # https://github.com/python/cpython/blob/v3.5.9/Lib/datetime.py#L1552
     _LOGGER.info(
-        "scheduling %s for %s",
-        action,
-        shutdown_datetime.isoformat(sep=" ", timespec="seconds"),
+        "scheduling %s for %s", action, shutdown_datetime.strftime("%Y-%m-%d %H:%M:%S"),
     )
     shutdown_epoch_usec = int(shutdown_datetime.timestamp() * 10 ** 6)
     try: