A simple and fast date parsing library. Uses dateutil for timezone offset support.
Project description
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
- bring support for timezone offsets to Python 2.7
- 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 orZ
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
andJAVA_OFFSET_DATETIME
renamed toIso8601
andJavaOffsetDatetime
Iso8601
andJavaOffsetDatetime
are now classesJavaOffsetDatetime()
can now be instantiated passingrequire_timezone=False
to make the timezone specified in the date optional.TimezoneFormatOption
now raises an error ifdatetime.tzinfo
isNone
v0.0.1 (2020-02-24)
- Initial version
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file nr.parsing.date-0.2.0.tar.gz
.
File metadata
- Download URL: nr.parsing.date-0.2.0.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4bb1a36d6ad3d8786af554027fa47a9ef86ece500b960fe9ed518c18813edefe |
|
MD5 | 51e923fadf257be8719672e0d3329262 |
|
BLAKE2b-256 | 479617d89a98d842f3a038f493feed94f1355950f1ad511574b53913d8370c42 |
File details
Details for the file nr.parsing.date-0.2.0-py2.py3-none-any.whl
.
File metadata
- Download URL: nr.parsing.date-0.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1f22d58243fc77921ea409534f3310b5a3a20b11f7f0fb22b09e9577ab7ce03 |
|
MD5 | 2455c8893d8f90d7c785b8dcd4f3da22 |
|
BLAKE2b-256 | 75332d94b108430bc515ffe8df9b900c39990b679cd74e0d80a57bc45d4d6395 |