Instant & Duration¶
Time representation for the simulation. Instant is a point in time, Duration is a span.
Time representation with nanosecond precision.
This module provides two distinct time concepts:
- Instant: A point in time (e.g., "the event occurs at T=5s")
- Duration: A length of time (e.g., "the operation takes 100ms")
Both use nanoseconds internally to avoid floating-point precision issues that can cause non-deterministic behavior when comparing event times.
Special values: - Instant.Epoch: Time zero (start of simulation) - Instant.Infinity: Represents unbounded time (for auto-termination) - Duration.ZERO: Zero-length duration
Duration ¶
Immutable duration value with nanosecond precision.
Represents a length of time, not a point in time. Use for latencies, timeouts, intervals, and other measurements of elapsed time.
Stores time as an integer number of nanoseconds to avoid floating-point errors. Supports arithmetic with other Durations or float seconds.
Attributes:
| Name | Type | Description |
|---|---|---|
nanoseconds |
The duration in nanoseconds. |
Create a Duration from nanoseconds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nanoseconds
|
int
|
Duration in nanoseconds. |
required |
from_seconds
classmethod
¶
Create a Duration from a seconds value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seconds
|
int | float
|
Duration in seconds (int or float). |
required |
Returns:
| Type | Description |
|---|---|
Duration
|
New Duration representing the given length of time. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If seconds is not int or float. |
__add__ ¶
Add two durations or a duration and seconds.
__sub__ ¶
Subtract durations or seconds from a duration.
__repr__ ¶
Return a human-readable duration string.
Format: D{hours}:{minutes}:{seconds}.{microseconds} Examples: D00:00:01.500000, D01:23:45.678901
Instant ¶
Immutable time point with nanosecond precision.
Represents a specific point in time, not a duration. Use for event timestamps, scheduling times, and absolute time references.
Stores time as an integer number of nanoseconds to avoid floating-point errors. Supports arithmetic with Durations or float seconds.
Attributes:
| Name | Type | Description |
|---|---|---|
nanoseconds |
The time value in nanoseconds since epoch. |
Create an Instant from nanoseconds since epoch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nanoseconds
|
int
|
Time in nanoseconds since simulation start. |
required |
from_seconds
classmethod
¶
Create an Instant from a seconds value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seconds
|
int | float
|
Time in seconds (int or float). |
required |
Returns:
| Type | Description |
|---|---|
Instant
|
New Instant representing the given point in time. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If seconds is not int or float. |
__add__ ¶
Add a duration to an instant, producing a new instant.
Instant + Duration = Instant (a point in time shifted by a duration) Instant + float = Instant (float interpreted as seconds)
__sub__ ¶
Subtract from an instant.
Instant - Instant = Duration (the time between two points) Instant - Duration = Instant (a point in time shifted backwards) Instant - float = Instant (float interpreted as seconds)
__repr__ ¶
Return a human-readable ISO-like time string with microsecond precision.
Format: T{hours}:{minutes}:{seconds}.{microseconds} Examples: T00:00:01.500000, T01:23:45.678901