Parse common datetime formats and a custom relative time format into a Pendulum object.
Project description
datetime-parser
datetime can be many different formats and often we want to express a time relative
to the current time, such as 10 minutes ago
. This module is able to handle all datetime formats
as well as our custom relative time format.
Relative datetime format:
For the current time:
now
Any other time:
(+/-)(integer) (milliseconds|seconds|minutes|days|weeks|months|years)
examples:
now
-1 months
+3 days
-123 seconds
Parse Datetime
To parse a datetime (not including relative time), you can use the try_parse_dt
function. This
will return a pendulum object
from datetime_parser import try_parse_dt
example = "2020-02-02 10:10:10"
example_obj = try_parse_datetime(example)
Parse Relavite Time
To parse a datetime or relative datetime, use is_datetime
.
from datetime_parser import is_datetime
example = "-5 minutes"
example_obj = is_datetime(example)
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
datetime-parser-1.0.1.tar.gz
(5.7 kB
view hashes)
Built Distribution
Close
Hashes for datetime_parser-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a33fc20785112040889a98af4dfb1b7880856bb53dddd7164c0e43278aa498bc |
|
MD5 | 8378ebea0ceb2a94a7efe0ec0d2f2d6d |
|
BLAKE2b-256 | 02d703a951ece36617d8d505b7d9e76f8fc48468e625360dae81246be549e3d6 |