Skip to main content

A simple and fast date parsing library. Uses dateutil for timezone offset support.

Project description

Note: This package is in the dangerous land of 0.x.y versions and may be subject to breaking changes with minor version increments.

nr.parsing.date

This package provides a fast parser for fixed format date strings with support for timezone offsets. The goal of this package is to

  1. bring support for timezone offsets to Python 2.7
  2. be faster than dateutil.parser.parse()

You can control the regex backend with the PYTHON_NR_DATE_REGEX_BACKEND environment variable. The default is re. You can use this variable to make it use the regex module instead.

Currently supported format options are:

  • %Y – 4 digit year
  • %m – 2 digit month
  • %d – 2 digit day
  • %H – 2 digit hour
  • %M – 2 digit minute
  • %S – 2 digit second
  • %f – arbitrary precision milliseconds
  • %z – timezone offset ([+-]\d\d:?\d\d offset or Z for UTC)

The date formats are extensible by using the register_format_option() function or creating a new FormatOptionSet.

API

BaseFormatOption()

Base class for format options.

FormatOption(char, dest, regex, parser, render)

Useful class for creating a new format options.

TimezoneFormatOption()

Special format option implementation for matching timezone offset.

FormatOptionSet()

Represents a set of BaseFormatOption objects. Use the create_date_format() method to create a DateFormat object from this set and a format string.

DateFormat(string, option_set=None)

Creates a new parser and formatter for dates from a template string. It is recommendable to use FormatOptionSet.create_date_format() instead to make use of caching.

DateFormatSet(name, formats)

A collection of DateFormat objects that can be parsed successively until a first match is found. The format() method will use the first format in the set.

root_option_set

A global FormatOptionSet.

register_format_option()

Add a new format option to the root_option_set. This is the same as calling root_option_set.add().

parse_date(string, fmt)

Parses the date string using the specified fmt into a datetime.datetime object.

format_date(date, fmt)

Formats the date using the specified fmt into a string.

create_format_set(name, formats)

Creates a new DateFormatSet with the specified formats.

Iso8601()

Iso8601.parse(s)

Iso8601.format(dt)

JavaOffsetDatetime(require_timezone=True)

JavaOffsetDatetime.parse(s)

JavaOffsetDatetime.format(dt)

Benchmarks

TODO

Future

  • Vendor dateutil.tz module?

Changelog

v0.1.0 (2020-03-19)

  • ISO_8601 and JAVA_OFFSET_DATETIME renamed to Iso8601 and JavaOffsetDatetime
  • Iso8601 and JavaOffsetDatetime are now classes
  • JavaOffsetDatetime() can now be instantiated passing require_timezone=False to make the timezone specified in the date optional.
  • TimezoneFormatOption now raises an error if datetime.tzinfo is None

v0.0.1 (2020-02-24)

  • Initial version

Copyright © 2020 Niklas Rosenstein

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

nr.parsing.date-0.4.3.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

nr.parsing.date-0.4.3-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file nr.parsing.date-0.4.3.tar.gz.

File metadata

  • Download URL: nr.parsing.date-0.4.3.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.3

File hashes

Hashes for nr.parsing.date-0.4.3.tar.gz
Algorithm Hash digest
SHA256 540b926a6e9b5d0f2b042b614c094ca08d6445227e2769d0ca5581fb459b3cd3
MD5 84079dab5677e5d16835f78a673a74af
BLAKE2b-256 d84e9a069660c575dbb6dc7212d98ae6c9b67de6c26f0e46027d2c3699257f98

See more details on using hashes here.

File details

Details for the file nr.parsing.date-0.4.3-py3-none-any.whl.

File metadata

  • Download URL: nr.parsing.date-0.4.3-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.3

File hashes

Hashes for nr.parsing.date-0.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 899ee068883ce43cd6502915121b6667470b9cad10d4753f74db6d7ca23ac5b3
MD5 7a0c717d40693d1e7f247ae5820152b5
BLAKE2b-256 07ca62eade0241d1aa6c197934cf4295034a8783f54cd6b5fa6b890088de9fef

See more details on using hashes here.

Supported by

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