dt
Timer ¶
Timer(*, ms: bool = True)
A simple timer class that keeps track of all the stops.
stop ¶
stop(label: str | None = None) -> TimerStop
Stop the timer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label |
str | None
|
Label for the stop. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
TimerStop |
TimerStop
|
The stop data |
Source code in stdl/dt.py
taken_seconds ¶
reset ¶
datetime_fmt ¶
datetime_fmt(d: str | float | int | None | datetime = None, fmt: str = 'Ymd', dsep: str = '-', tsep: str = ':', *, ms: bool = False, utc: bool = True) -> str
Format date and time
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d |
str | float | None | datetime
|
Input datetime. Defaults to current date and time. |
None
|
fmt |
str
|
Date format. |
'Ymd'
|
dsep |
str
|
Date values separator. |
'-'
|
tsep |
str
|
Time values separator. |
':'
|
ms |
bool
|
include miliseconds. |
False
|
utc |
bool
|
Use the UTC timezone when building a datetime object from a timestamp. |
True
|
Raises:
| Type | Description |
|---|---|
TypeError
|
Raises TypeError if the type of |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Formated date and time. |
Example
Source code in stdl/dt.py
time_fmt ¶
time_fmt(t: float | datetime | int | None = None, sep: str = ':', *, ms: bool = False, utc: bool = True) -> str
Format time
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t |
float | datetime | int | None
|
Input time. Defaults to current time. |
None
|
sep |
str
|
Character(s) that separates hours, minutes, seconds... |
':'
|
ms |
bool
|
include miliseconds. |
False
|
utc |
bool
|
Use the UTC timezone when building a time object from a timestamp. |
True
|
Raises:
| Type | Description |
|---|---|
TypeError
|
Raises TypeError if the type of |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Formated time. |
Source code in stdl/dt.py
date_fmt ¶
Format date
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d |
float | date | datetime | int | None
|
Input date. Defaults to current date. |
None
|
fmt |
str
|
Date format. |
'Ymd'
|
sep |
str
|
Character(s) that separates days, months and years. |
'-'
|
Raises:
| Type | Description |
|---|---|
TypeError
|
Raises TypeError if the type of |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Formated date. |
Example
Source code in stdl/dt.py
date_range ¶
Returns a generator for dates between start and end
Example
Source code in stdl/dt.py
sleep ¶
Sleeps for a random duration within a specified range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lo |
float
|
The lower bound of the sleep duration range (inclusive). |
required |
hi |
float
|
The upper bound of the sleep duration range (inclusive). If not provided, the function will sleep for the exact duration specified by |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The actual sleep duration. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |