Skip to main content

Backport of Python 3.7's datetime.fromisoformat

Project description

https://circleci.com/gh/movermeyer/backports.datetime_fromisoformat.svg?style=svg

A backport of Python 3.7’s datetime.fromisoformat methods to earlier versions of Python 3. Tested against Python 3.4, 3.5 and 3.6.

Current Status

backports.datetime_fromisoformat is under active development, and should be considered pre-alpha.

Quick Start

Installation:

pip install backports-datetime-fromisoformat

Usage:

>>> from datetime import date, datetime, time
>>> from backports.datetime_fromisoformat import MonkeyPatch
>>> MonkeyPatch.patch_fromisoformat()

>>> datetime.fromisoformat("2014-01-09T21:48:00-05:30")
datetime.datetime(2014, 1, 9, 21, 48, tzinfo=-05:30)

>>> date.fromisoformat("2014-01-09")
datetime.date(2014, 1, 9)

>>> time.fromisoformat("21:48:00-05:30")
datetime.time(21, 48, tzinfo=-05:30)

Explanation

In Python 3.7, datetime.fromisoformat was added. It is the inverse of datetime.isoformat. Similar methods were added to the date and time types as well. For those who need to support earlier versions of Python, a backport of these methods was needed.

backports.datetime_fromisoformat is a C implementation of fromisoformat based on the upstream cPython 3.7 code. For timezone objects, it uses a custom timezone C implementation (originally from Pendulum).

Usage in Python 3.7+

NOTE: in Python 3.7 and later, the fromisoformat methods exist in the stdlib, and installing this package has NO EFFECT.

Goal / Project Scope

The purpose of this project is to provide a perfect backport of the fromisoformat methods to earlier versions of Python, while still providing comparable performance.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

backports-datetime-fromisoformat-0.0.2.tar.gz (10.7 kB view details)

Uploaded Source

File details

Details for the file backports-datetime-fromisoformat-0.0.2.tar.gz.

File metadata

  • Download URL: backports-datetime-fromisoformat-0.0.2.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.6

File hashes

Hashes for backports-datetime-fromisoformat-0.0.2.tar.gz
Algorithm Hash digest
SHA256 2e567e85b645874c376a2018cb48f7e813d4458f417433838528039fb33314c4
MD5 86b0b68f8c601e6ae7ffbf28605f6eed
BLAKE2b-256 e4c16c953f561c15e4d37b4b206f411346f620dd43ffb5e88037a6db7c6c867e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page