Fast date parsing with timezone offset support.
Project description
nr.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.
ISO_8601
JAVA_OFFSET_DATETIME
Benchmarks
TODO
Future
- Vendor
dateutil.tz
module?
Changelog
v1.1.0 (2019-04-16)
- Fix microsecond (
%f
) formatting - Fix parsing of timezone offset with colon (
%z
) - Use
pkgutil
instead ofpkg_resources
namespace packages
v1.0.0 (2019-04-06)
- Initial release
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
File details
Details for the file nr.date-1.1.0.tar.gz
.
File metadata
- Download URL: nr.date-1.1.0.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | af94e350c9b3a5b45717533a4b513bd8380d662505f6c05e8a02181e56581ea2 |
|
MD5 | 9c09c6b0562944f6f53d1a5a418dce08 |
|
BLAKE2b-256 | b0e9501a285c227f674f1c7aa424fbd6b039dd7afd3310ce0cd840c37d34b645 |