Time¶
TimeRange defines the period and output times of a run.
time_units
module-attribute
¶
time_units = {
"h": "hours",
"d": "days",
"w": "weeks",
"m": "minutes",
"s": "seconds",
"y": "years",
"H": "hours",
"D": "days",
"W": "weeks",
"M": "minutes",
"S": "seconds",
"Y": "years",
}
TimeRange
pydantic-model
¶
Bases: BaseModel
A time range object
Examples¶
from rompy import TimeRange tr = TimeRange(start="2020-01-01", end="2020-01-02") tr TimeRange(start=datetime.datetime(2020, 1, 1, 0, 0), end=datetime.datetime(2020, 1, 2, 0, 0), duration=None, interval=None, include_end=True) tr = TimeRange(start="2020-01-01", duration="1d") tr TimeRange(start=datetime.datetime(2020, 1, 1, 0, 0), end=datetime.datetime(2020, 1, 2, 0, 0), duration=timedelta(days=1), interval=None, include_end=True) tr = TimeRange(start="2020-01-01", duration="1d", interval="1h") tr TimeRange(start=datetime.datetime(2020, 1, 1, 0, 0), end=None, duration=timedelta(days=1), interval=timedelta(hours=1), include_end=True)
Config:
validate_default:True
Fields:
-
start(Optional[datetime]) -
end(Optional[datetime]) -
duration(Optional[Union[str, timedelta]]) -
interval(Optional[Union[str, timedelta]]) -
include_end(bool)
Validators:
-
valid_duration_interval→interval,duration -
validate_start_end→start,end -
validate_start_end_duration -
parse_start_end_duration
duration
pydantic-field
¶
The duration of the time range
interval
pydantic-field
¶
The frequency of the time range
include_end
pydantic-field
¶
include_end: bool = True
Determines if the end date should be included in the range
format_duration
¶
Format a timedelta object as a human-readable string.
This method formats a timedelta in a way that's suitable for display in logs and other output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
duration
|
timedelta
|
The timedelta object to format |
required |
Returns:
| Type | Description |
|---|---|
str
|
A formatted string representation of the duration |