ISO 8601 date/time parser

Overview

ISO 8601 date/time parser

Travis-CI Coveralls Latest Version License

This module implements ISO 8601 date, time and duration parsing. The implementation follows ISO8601:2004 standard, and implements only date/time representations mentioned in the standard. If something is not mentioned there, then it is treated as non existent, and not as an allowed option.

For instance, ISO8601:2004 never mentions 2 digit years. So, it is not intended by this module to support 2 digit years. (while it may still be valid as ISO date, because it is not explicitly forbidden.) Another example is, when no time zone information is given for a time, then it should be interpreted as local time, and not UTC.

As this module maps ISO 8601 dates/times to standard Python data types, like date, time, datetime and timedelta, it is not possible to convert all possible ISO 8601 dates/times. For instance, dates before 0001-01-01 are not allowed by the Python date and datetime classes. Additionally fractional seconds are limited to microseconds. That means if the parser finds for instance nanoseconds it will round it to microseconds.

Documentation

Currently there are four parsing methods available.
  • parse_time:
    parses an ISO 8601 time string into a time object
  • parse_date:
    parses an ISO 8601 date string into a date object
  • parse_datetime:
    parses an ISO 8601 date-time string into a datetime object
  • parse_duration:
    parses an ISO 8601 duration string into a timedelta or Duration object.
  • parse_tzinfo:
    parses the time zone info part of an ISO 8601 string into a tzinfo object.

As ISO 8601 allows to define durations in years and months, and timedelta does not handle years and months, this module provides a Duration class, which can be used almost like a timedelta object (with some limitations). However, a Duration object can be converted into a timedelta object.

There are also ISO formatting methods for all supported data types. Each xxx_isoformat method accepts a format parameter. The default format is always the ISO 8601 expanded format. This is the same format used by datetime.isoformat:

  • time_isoformat:
    Intended to create ISO time strings with default format hh:mm:ssZ.
  • date_isoformat:
    Intended to create ISO date strings with default format yyyy-mm-dd.
  • datetime_isoformat:
    Intended to create ISO date-time strings with default format yyyy-mm-ddThh:mm:ssZ.
  • duration_isoformat:
    Intended to create ISO duration strings with default format PnnYnnMnnDTnnHnnMnnS.
  • tz_isoformat:
    Intended to create ISO time zone strings with default format hh:mm.
  • strftime:
    A re-implementation mostly compatible with Python's strftime, but supports only those format strings, which can also be used for dates prior 1900. This method also understands how to format datetime and Duration instances.

Installation:

This module can easily be installed with Python standard installation methods.

Either use python setup.py install or in case you have setuptools or distribute available, you can also use easy_install.

Limitations:

  • The parser accepts several date/time representation which should be invalid according to ISO 8601 standard.
    1. for date and time together, this parser accepts a mixture of basic and extended format. e.g. the date could be in basic format, while the time is accepted in extended format. It also allows short dates and times in date-time strings.
    2. For incomplete dates, the first day is chosen. e.g. 19th century results in a date of 1901-01-01.
    3. negative Duration and timedelta value are not fully supported yet.

Further information:

The doc strings and unit tests should provide rather detailed information about the methods and their limitations.

The source release provides a setup.py script, which can be used to run the unit tests included.

Source code is available at http://github.com/gweis/isodate.

Parse human-readable date/time strings

parsedatetime Parse human-readable date/time strings. Python 2.6 or greater is required for parsedatetime version 1.0 or greater. While we still test

Mike Taylor 651 Dec 23, 2022
A Python module that tries to figure out what your local timezone is

tzlocal This Python module returns a tzinfo object with the local timezone information under Unix and Windows. It requires either Python 3.9+ or the b

Lennart Regebro 159 Dec 16, 2022
🕟 Date and time processing language

Date Time Expression dte is a WIP date-time processing language with focus on broad interpretation. If you don't think it's intuitive, it's most likel

Marcelo 303 Dec 19, 2022
A Python library for dealing with dates

moment A Python library for dealing with dates/times. Inspired by Moment.js and Kenneth Reitz's Requests library. Ideas were also taken from the Times

Zach Williams 709 Dec 09, 2022
Jalali (Shamsi) date and datetime (based on python datetime's module)

PersianTools Jalali (Shamsi) date and datetime (based on python datetime's module) Convert Jalali to Gregorian date/datetime and vice versa Support co

Majid Hajiloo 66 Dec 18, 2022
Python datetimes made easy

Pendulum Python datetimes made easy. Supports Python 2.7 and 3.4+. import pendulum now_in_paris = pendulum.now('Europe/Paris') now_in_par

Sébastien Eustace 5.3k Jan 06, 2023
Make Python datetime formatting human readable

Make Python datetime formatting human readable

James Timmins 0 Oct 03, 2021
Delorean: Time Travel Made Easy

Delorean: Time Travel Made Easy Delorean is a library for clearing up the inconvenient truths that arise dealing with datetimes in Python. Understandi

Mahdi Yusuf 1.8k Dec 20, 2022
A Python 3 library for parsing human-written times and dates

Chronyk A small Python 3 library containing some handy tools for handling time, especially when it comes to interfacing with those pesky humans. Featu

Felix Wiegand 339 Dec 19, 2022
Better dates & times for Python

Arrow: Better dates & times for Python Arrow is a Python library that offers a sensible and human-friendly approach to creating, manipulating, formatt

Arrow 8.2k Jan 05, 2023
🏹 Better dates & times for Python

Arrow: Better dates & times for Python Arrow is a Python library that offers a sensible and human-friendly approach to creating, manipulating, formatt

Arrow 8.2k Jan 09, 2023
UNIX time from NTP or short UtfN is a simple CLI tool to set the time from an NTP-Server.

UNIX ⌚ from NTP UNIX time from NTP or short UtfN is a simple CLI tool to set the time from an NTP-Server. Sets time and date using the date command pr

Alexander 1 Jan 02, 2022
pytz Python historical timezone library and database

pytz Brings the IANA tz database into Python. This library allows accurate and cross platform timezone calculations. pytz contains generated code, and

Stub 236 Jan 03, 2023
⌚️Internet Time reference and (eventually) converter site, for planning things with your internet friends who aren't (yet) obsessed with Internet Time 😉

Internet-Ti.me Internet Time reference and (eventually) converter site, for planning things with your internet friends who aren't (yet) obsessed with

Jessica Stokes 17 Nov 02, 2022
The Terasic DECA board as a mandelbrot acceleerator

deca-mandelbrot The Terasic DECA board as a mandelbrot accelerator. This is a hobby project to explore parallel computation/pipelining on a FPGA. curr

Hans Baier 11 Aug 29, 2022
E-Ink Magic Calendar that automatically syncs to Google Calendar and runs off a battery powered Raspberry Pi Zero

E-Ink Magic Calendar that automatically syncs to Google Calendar and runs off a battery powered Raspberry Pi Zero

2.8k Jan 06, 2023
A datetime parser in Python by Ari24-cb24 and NekoFantic

datetimeparser A datetime parser in Python by Ari24-cb24 and NekoFantic V 1.0 Erinnerung für den Parser Auf falsche Eingaben überprüfen Liste an Event

AriDevelopment 13 Dec 30, 2022
python parser for human readable dates

Python parser for human readable dates Key Features • How To Use • Installation • Common use cases • You may also like... • License Key Features Suppo

Scrapinghub 2.2k Jan 08, 2023
Generate and work with holidays in Python

python-holidays A fast, efficient Python library for generating country, province and state specific sets of holidays on the fly. It aims to make dete

Maurizio Montel 881 Dec 29, 2022
An python based Timer and Digital Clock

Python-based-Timer- An python based Timer and Digital Clock How to contribute to this repo ❓ Step 1: Fork the this repository Step 2: Clone your fork

Bauddhik-Geeks 3 Sep 16, 2022