Date time
Utility functions related to date and time operations
koheesio.utils.date_time.extract_dt_interval
module-attribute
#
extract_dt_interval = compile(
"\n (?P<years>\\d+)\\s+years?\\s*|\n (?P<months>\\d+)\\s+months?\\s*|\n (?P<weeks>\\d+)\\s+weeks?\\s*|\n (?P<days>\\d+)\\s+days?\\s*|\n (?P<hours>\\d+)\\s+hours?\\s*|\n (?P<minutes>\\d+)\\s+(?:minutes?|mins?)\\s*|\n (?P<seconds>\\d+)\\s+(?:seconds?|secs?)\\s*|\n (?P<milliseconds>\\d+)\\s+(?:milliseconds?|millis?)\\s*|\n (?P<microseconds>\\d+)\\s+(?:microseconds?|micros?)\\s*\n",
VERBOSE,
)
koheesio.utils.date_time.DTInterval #
A class to define date and time intervals using human-readable strings or individual time components.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
interval
|
str
|
A human-readable string specifying the duration of the interval, broken down into years, months, weeks, days, hours, minutes, seconds, milliseconds, and microseconds. |
required |
years
|
int
|
Number of years in the interval. |
0
|
months
|
int
|
Number of months in the interval. |
0
|
weeks
|
int
|
Number of weeks in the interval. |
0
|
days
|
int
|
Number of days in the interval. |
0
|
hours
|
int
|
Number of hours in the interval. |
0
|
minutes
|
int
|
Number of minutes in the interval. |
0
|
seconds
|
int
|
Number of seconds in the interval. |
0
|
milliseconds
|
int
|
Number of milliseconds in the interval. |
0
|
microseconds
|
int
|
Number of microseconds in the interval. |
0
|
Examples:
Creating an instance with time components:
751 days, 12:00:00Creating an instance from a string:
print(
DTInterval(
interval="1 year 2 months 3 weeks 4 days 5 hours 100 minutes 200 seconds 300 milliseconds 400 microseconds"
).to_timedelta
)
Methods:
Name | Description |
---|---|
to_timedelta |
Converts the DTInterval instance to a timedelta object, aggregating all specified time components. |
calculate_days #
calculate_days() -> DTInterval
Years and months are not supported in timedelta, so we need to convert them to days
Source code in src/koheesio/utils/date_time.py
process_interval #
Processes the input interval string and extracts the time components