Duration
A Duration stores a time duration with nanosecond precision. It supports parsing from human-readable strings (including compound formats like "1h30m") and provides properties for converting to common time units.
Duration is a Python dataclass.
Fields
| Field | Type | Description |
|---|---|---|
elapsed | int | The duration in nanoseconds. |
Constructor
| Parameter | Type | Description |
|---|---|---|
elapsed | int | The duration in nanoseconds. |
Static Methods
Duration.parse()
Parses a duration from a string or integer value. String values support SurrealDB duration syntax, including compound durations.
| Parameter | Type | Description |
|---|---|---|
value | str | int | A duration string (e.g. "1h30m", "500ms") or an integer in nanoseconds. |
nanoseconds | int | Additional nanoseconds to add. Defaults to 0. |
Returns: Duration
Examples
Properties
All unit properties return a float.
| Property | Type | Description |
|---|---|---|
nanoseconds | float | Duration in nanoseconds. |
microseconds | float | Duration in microseconds. |
milliseconds | float | Duration in milliseconds. |
seconds | float | Duration in seconds. |
minutes | float | Duration in minutes. |
hours | float | Duration in hours. |
days | float | Duration in days. |
weeks | float | Duration in weeks. |
years | float | Duration in years (365-day). |
Methods
to_string()
Returns the duration as a human-readable string.
Returns: str
to_compact()
Returns the duration as a compact list of integer values.
Returns: list[int]
Usage
See Also
Data Types — All SDK data types
Datetime — Datetime wrapper