Time¶
Functions for working with time.
from_isoformat_8601 ¶
from_isoformat_8601(iso8601_str)
Convert ISO Format datetime string into a datetime object
Example Strings
- 2022-06-09T06:58:14
- 2022-06-09T06:58:14Z
- 2022-06-09T06:58:14+11:00
- 2022-06-09T06:58:14.000
- 2022-06-09T06:58:14.000Z
- 2022-06-09T06:58:14.000+11:00
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iso8601_str
|
str
|
datetime string |
required |
Returns:
| Type | Description |
|---|---|
datetime
|
dt.datetime |
Source code in src/aibs_informatics_core/utils/time.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
get_current_time ¶
get_current_time(tz=None)
Return the current time as a timezone-aware datetime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tz
|
timezone | None
|
Timezone to use. Defaults to UTC. |
None
|
Returns:
| Type | Description |
|---|---|
datetime
|
The current |
Source code in src/aibs_informatics_core/utils/time.py
15 16 17 18 19 20 21 22 23 24 | |
get_duration_in_secs ¶
get_duration_in_secs(start, stop=None)
Calculate the duration between two datetimes in seconds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
datetime
|
Start datetime. |
required |
stop
|
datetime | None
|
End datetime. Defaults to the current time. |
None
|
Returns:
| Type | Description |
|---|---|
int
|
The rounded number of seconds between |
Source code in src/aibs_informatics_core/utils/time.py
27 28 29 30 31 32 33 34 35 36 37 | |
to_zulu_isoformat_8601 ¶
to_zulu_isoformat_8601(value, naive_handling='coerce')
Convert a datetime object or ISO 8601 string to a Zulu ISO 8601 formatted string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
datetime | str
|
The datetime object or ISO 8601 string to convert. |
required |
naive_handling
|
Literal['coerce', 'error']
|
How to handle naive (timezone-unaware) datetimes.
|
'coerce'
|
Returns:
| Type | Description |
|---|---|
str
|
The Zulu ISO 8601 formatted string. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If naive_handling is |
Source code in src/aibs_informatics_core/utils/time.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |