Repository: zopefoundation/DateTime (language: python)

Issue:
DateTime 4.5 unit test incompatible with Windows
In the process of updating the DateTime version pin for Zope and running the CI tests I discovered that a recent change is incompatible with Windows. The tests fail with this traceback:

```python
Error in test test_format (DateTime.tests.test_datetime.DateTimeTests)
Traceback (most recent call last):
  File "c:\hostedtoolcache\windows\python\3.6.8\x64\lib\unittest\case.py", line 59, in testPartExecutor
    yield
  File "c:\hostedtoolcache\windows\python\3.6.8\x64\lib\unittest\case.py", line 605, in run
    testMethod()
  File "d:\a\zope\zope\.tox\py36\eggs\datetime-4.5-py3.6.egg\DateTime\tests\test_datetime.py", line 690, in test_format
    result = dt.strftime(fmt)
  File "d:\a\zope\zope\.tox\py36\eggs\datetime-4.5-py3.6.egg\DateTime\DateTime.py", line 1566, in strftime
    microseconds).strftime(format)
ValueError: Invalid format string
```

The corresponding code is part of #37.
DateTime 4.5 unit test incompatible with Windows
In the process of updating the DateTime version pin for Zope and running the CI tests I discovered that a recent change is incompatible with Windows. The tests fail with this traceback:

```python
Error in test test_format (DateTime.tests.test_datetime.DateTimeTests)
Traceback (most recent call last):
  File "c:\hostedtoolcache\windows\python\3.6.8\x64\lib\unittest\case.py", line 59, in testPartExecutor
    yield
  File "c:\hostedtoolcache\windows\python\3.6.8\x64\lib\unittest\case.py", line 605, in run
    testMethod()
  File "d:\a\zope\zope\.tox\py36\eggs\datetime-4.5-py3.6.egg\DateTime\tests\test_datetime.py", line 690, in test_format
    result = dt.strftime(fmt)
  File "d:\a\zope\zope\.tox\py36\eggs\datetime-4.5-py3.6.egg\DateTime\DateTime.py", line 1566, in strftime
    microseconds).strftime(format)
ValueError: Invalid format string
```

The corresponding code is part of #37.


Discussion / hints:
I have updated the CI configuration here so it tests for Windows as well: https://github.com/zopefoundation/DateTime/actions/runs/3020975789
I have updated the CI configuration here so it tests for Windows as well: https://github.com/zopefoundation/DateTime/actions/runs/3020975789

Fix patch:
diff --git a/.meta.toml b/.meta.toml
index 0420bbd..a861c8d 100644
--- a/.meta.toml
+++ b/.meta.toml
@@ -22,3 +22,9 @@ additional-rules = [
 
 [tox]
 use-flake8 = true
+testenv-commands = [
+    "{envdir}/bin/test {posargs:-cv}",
+    ]
+coverage-command = [
+    "coverage run {envdir}/bin/test {posargs:-cv}",
+    ]
diff --git a/CHANGES.rst b/CHANGES.rst
index ef8081c..2b7d535 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -4,7 +4,8 @@ Changelog
 4.6 (unreleased)
 ----------------
 
-- Nothing changed yet.
+- Fix ``__format__`` method for DateTime objects
+  (`#39 <https://github.com/zopefoundation/DateTime/issues/39>`)
 
 
 4.5 (2022-07-04)
diff --git a/tox.ini b/tox.ini
index a4c0cc3..d5fde78 100644
--- a/tox.ini
+++ b/tox.ini
@@ -24,7 +24,7 @@ commands_pre =
     py27,py35: {envbindir}/buildout -nc {toxinidir}/buildout4.cfg buildout:directory={envdir} buildout:develop={toxinidir} install test
     !py27-!py35: {envbindir}/buildout -nc {toxinidir}/buildout.cfg buildout:directory={envdir} buildout:develop={toxinidir} install test
 commands =
-    {envbindir}/test {posargs:-cv}
+    {envdir}/bin/test {posargs:-cv}
 
 [testenv:lint]
 basepython = python3
@@ -67,7 +67,7 @@ deps =
     coverage-python-version
 commands =
     mkdir -p {toxinidir}/parts/htmlcov
-    coverage run {envbindir}/test {posargs:-cv}
+    coverage run {envdir}/bin/test {posargs:-cv}
     coverage html
     coverage report -m --fail-under=88
 


Test patch:
diff --git a/src/DateTime/tests/test_datetime.py b/src/DateTime/tests/test_datetime.py
index 49c31b6..ead77b5 100644
--- a/src/DateTime/tests/test_datetime.py
+++ b/src/DateTime/tests/test_datetime.py
@@ -686,10 +686,10 @@ def test_security(self):
     @unittest.skipUnless(PY3K, 'format method is Python 3 only')
     def test_format(self):
         dt = DateTime(1968, 3, 10, 23, 45, 0, 'Europe/Vienna')
-        fmt = '%-d.%-m.%Y %H:%M'
+        fmt = '%d.%m.%Y %H:%M'
         result = dt.strftime(fmt)
         unformatted_result = '1968/03/10 23:45:00 Europe/Vienna'
-        self.assertEqual(result, '{:%-d.%-m.%Y %H:%M}'.format(dt))
+        self.assertEqual(result, '{:%d.%m.%Y %H:%M}'.format(dt))
         self.assertEqual(unformatted_result, '{:}'.format(dt))
         self.assertEqual(unformatted_result, '{}'.format(dt))
         eval("self.assertEqual(result, f'{dt:{fmt}}')")