movermeyer / backports.datetime_fromisoformat Goto Github PK
View Code? Open in Web Editor NEWA backport of Python 3.11's `datetime.fromisoformat` methods to earlier versions of Python
License: MIT License
A backport of Python 3.11's `datetime.fromisoformat` methods to earlier versions of Python
License: MIT License
I noticed that this backport currently only provides a source distribution.
It'd be handy to have precompiled wheels to avoid having to build the C extension at install time.
Currently, compilation fails on Windows.
Work through the compilation errors and get backports.datetime_fromisoformat
working for the Windows compiler
Python 3.7 didn't only add datetime.fromisoformat
, it also added time.fromisoformat
and date.fromisoformat
.
Backport these as well.
Python 3.11 changed fromisoformat
to be able to parse a larger range of ISO 8601 timestamps
https://docs.python.org/3.11/library/datetime.html#datetime.datetime.fromisoformat
Hi,
I was wondering why the v2.0.0 is not available on conda-forge, even though the recipe was updated here.
A package I am currently creating on bioconda requires backports-datetime-fromisoformat but is not compatible with version 1.
Could you update the package retrievable via conda-forge to version 2 or do you know why it's not available?
Greetings,
Mark
Installation under python 3.8 requires compiling this package, which requires python development headers, which is annoying in CI, so please support the latest python versions with a pre-built wheel.
Is there any planned release for python 3.12 wheel?
Extend the capability of backports.datetime_fromisoformat
to allow usage within Python 2.7 projects.
Python 3.10.13, ubuntu on ARM64
In file included from backports/datetime_fromisoformat/_datetimemodule.c:66:
backports/datetime_fromisoformat/_datetimemodule.h:1:10: fatal error: Python.h: No such file or directory
1 | #include <Python.h>
| ^~~~~~~~~~
compilation terminated.
error: command '/usr/bin/aarch64-linux-gnu-gcc' failed with exit code 1
[end of output]
There is a nice invariant we can use Hypothesis to test.
datetime.fromisoformat
is the inverse of datetime.isoformat
In other words, for every datetime object, dt
, dt == datetime.fromisoformat(dt.isoformat())
Hypothesis can be used to test this invariant, using its "datetimes strategy".
python3 -m pip install --user backports.datetime_fromisoformat
from backports.datetime_fromisoformat import MonkeyPatch
ModuleNotFoundError: No module named 'backports.datetime_fromisoformat'
username@hostname:/home/username/.local/lib/python3.6/site-packages/backports $ ls -l *
-rwxrwxr-x. 1 username username 54136 Oct 5 10:47 _datetime_fromisoformat.cpython-36m-x86_64-linux-gnu.so
username@hostname:/home/username/.local/lib/python3.6/site-packages/backports $
Thanks for providing this awesome backport! Today I ran into the issue that a datetime object can't be pickled when it includes a timezone. Please find the example below:
$ python
Python 3.6.5 (default, Mar 30 2018, 06:41:53)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> import datetime
>>> from backports.datetime_fromisoformat import MonkeyPatch
>>> MonkeyPatch.patch_fromisoformat()
>>> moment = datetime.datetime.fromisoformat('2018-11-01 20:42:09.058000+00:00')
>>> pickle.dumps(moment)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
_pickle.PicklingError: Can't pickle <class 'FixedOffset_type'>: attribute lookup FixedOffset_type on builtins failed
>>> moment = datetime.datetime.fromisoformat('2018-11-01 20:42:09.058000')
>>> pickle.dumps(moment)
b'\x80\x03cdatetime\ndatetime\nq\x00C\n\x07\xe2\x0b\x01\x14*\t\x00\xe2\x90q\x01\x85q\x02Rq\x03.'
Unfortunately, I lack the skills to create a PR to resolve this.
Currently, backports.datetime_fromisoformat
only exposes a method that is equivalent to datetime.fromisoformat
.
Really, it should monkey-patch datetime
so that usage becomes something like:
from datetime import datetime
import backports.datetime_fromisoformat
backports.datetime_fromisoformat.monkey_patch()
now = datetime.utcnow().isoformat()
now_again = datetime.fromisoformat(now)
For Python 3.7+, this should be a no-op so that it doesn't change the built-in behaviour.
It would be nice if this library also worked with PyPy.
It might not be that hard to get it working.
Py_UNICODE_IS_SURROGATE
doesn't exist in PyPy
_PyUnicode_Copy
doesn't exist in PyPy
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.