Open Thomasillo opened 1 month ago
import datetime datetime.datetime.strptime("2024-03-21T15:49:51", '%Y-%m-%dT%H:%M:%S%z')
will fail with ValueError: time data '2024-03-21T15:49:51' does not match format '%Y-%m-%dT%H:%M:%S%z'
ValueError: time data '2024-03-21T15:49:51' does not match format '%Y-%m-%dT%H:%M:%S%z'
From the documentation for strptime, empty string should be allowed here.
NB: strftime behaves correctly.
>>> datetime.datetime.strftime(datetime.datetime(2024, 3, 21, 15, 49, 51), '%Y-%m-%dT%H:%M:%S%z') '2024-03-21T15:49:51'
So strptime(strftime(datetime.datetime(2024, 3, 21, 15, 49, 51), '%Y-%m-%dT%H:%M:%S%z'), '%Y-%m-%dT%H:%M:%S%z') would fail.
strptime(strftime(datetime.datetime(2024, 3, 21, 15, 49, 51), '%Y-%m-%dT%H:%M:%S%z'), '%Y-%m-%dT%H:%M:%S%z')
CPython 3.12.4, WSL2 (Ubuntu 20.04)
3.12
Linux
Similar to:
Linked a PR where I made %z allow an optional utc offset instead of mandating a utc offset, would appreciate it if someone could take a look, thanks!
https://github.com/python/cpython/pull/122829
Bug report
Bug description:
will fail with
ValueError: time data '2024-03-21T15:49:51' does not match format '%Y-%m-%dT%H:%M:%S%z'
From the documentation for strptime, empty string should be allowed here.
NB: strftime behaves correctly.
So
strptime(strftime(datetime.datetime(2024, 3, 21, 15, 49, 51), '%Y-%m-%dT%H:%M:%S%z'), '%Y-%m-%dT%H:%M:%S%z')
would fail.CPython 3.12.4, WSL2 (Ubuntu 20.04)
CPython versions tested on:
3.12
Operating systems tested on:
Linux
Linked PRs