Time Representation
py_fort_myrmidon.Duration
- class py_fort_myrmidon.Duration
Represents an amount of nanoseconds as a signed 64-bit integer
Note
The notion of 64-bit integer does not exist natively in python, but since the mapped c++ object is, it will works like a 64-bit integer.
- Hours(self: py_fort_myrmidon.Duration) float
this Duration in hours.
- Returns:
the duration as an amount of hours
- Return type:
- Microseconds(self: py_fort_myrmidon.Duration) float
This Duration in microseconds.
- Returns:
the duration as an amount of microseconds
- Return type:
- Milliseconds(self: py_fort_myrmidon.Duration) float
This Duration in milliseconds.
- Returns:
the duration as an amount of milliseconds
- Return type:
- Minutes(self: py_fort_myrmidon.Duration) float
This Duration in minutes.
- Returns:
the duration as an amount of minutes
- Return type:
- Nanoseconds(self: py_fort_myrmidon.Duration) int
This Duration in nanoseconds.
- Returns:
the duration as an amount of nanoseconds
- Return type:
- static Parse(d: str) py_fort_myrmidon.Duration
Parses a string to a Duration.
- Parameters:
d (str) – a string in the format [amount][unit] as a duration. [amout] is a value that may contain a decimal point, and [units] could be any of ‘h’,’m’,’s’,’ms’,’us’,’ns’. The pattern can be repeated (i.e. ‘4m32s’ is valid).
- Returns:
the parsed value
- Return type:
- Raises:
RuntimeError – when the parsed amount will not hold in a 64-bit signed integer
- Seconds(self: py_fort_myrmidon.Duration) float
This Duration in seconds.
- Returns:
the duration as an amount of seconds
- Return type:
- __init__(*args, **kwargs)
Overloaded function.
__init__(self: py_fort_myrmidon.Duration, ns: int) -> None
Initialize a Duration from an amount of nanoseconds
- Parameters:
ns (int) – the number of nanosecond to represent
__init__(self: py_fort_myrmidon.Duration, ns: float) -> None
Initialize a Duration from an amount of nanoseconds
- Parameters:
ns (float) – the number of nanosecond to represent
__init__(self: py_fort_myrmidon.Duration) -> None
Initialize a zero second Duration.
py_fort_myrmidon.Time
- class py_fort_myrmidon.Time
Represents a point in time.
This object represents a point in time, potentially +/-∞. It features operation to compare or measure a Duration between two Time.
The operation manipulating Time objects never modifies the original objects, and always return new allocated object, so Time object can be considered immuable.
It also provides methods to convert to and from
datetime.datetime
object. In that case these objects are considered naïve: expressed in localtime, and ignoring any associated timezone information.It provides methods to convert to and from
time.time()
anddatetime.datetime.timestamp()
float values. However for time around 2020, these only ensure a 10us precision, but Time objects are precise to the nanosecond.- Add(self: py_fort_myrmidon.Time, d: py_fort_myrmidon.Duration) py_fort_myrmidon.Time
Adds a Duration to a Time
Note: self remains unchanged.
- Parameters:
d (Duration) – the Duration to add
- Returns:
a new Time representing self + d
- Return type:
- Raises:
RuntimeError – if the resulting Time is not representable.
- After(self: py_fort_myrmidon.Time, other: py_fort_myrmidon.Time) bool
Tests if this Time is after other
Similar to self > other. __gt__ operator is also provided.
- Before(self: py_fort_myrmidon.Time, other: py_fort_myrmidon.Time) bool
Tests if this Time is before other
Similar to self < other. __lt__ operator is also provided.
- Equals(self: py_fort_myrmidon.Time, other: py_fort_myrmidon.Time) bool
Tests if this Time is exactly equal to other
Similar to self == other. __eq__ operator is also provided.
- static Forever() py_fort_myrmidon.Time
The positive infinitie time.
- Returns:
A Time representing +∞
- Return type:
- IsForever(self: py_fort_myrmidon.Time) bool
Tests if this Time is +∞
- Returns:
True
if this time isTime.Forever()
- Return type:
- IsInfinite(self: py_fort_myrmidon.Time) bool
Tests if this Time is + or - ∞
- Returns:
True
if this time isTime.SinceEver()
orTime.Forever()
- Return type:
- IsSinceEver(self: py_fort_myrmidon.Time) bool
Tests if this Time is -∞
- Returns:
True
if this time isTime.SinceEver()
- Return type:
- static Now() py_fort_myrmidon.Time
Gets the current Time
- Returns:
the current Time
- Return type:
- static Parse(input: str) py_fort_myrmidon.Time
Parses a RFC3339 string to a Time.
Parses a RFC3339 string (i.e. ‘1970-01-01T00:00:00.000Z’) to a Time.
- Parameters:
input (str) – the string to parse
- Returns:
a Time that represent input
- Return type:
- Raises:
Error – if input is a Time that is not representable.
- Reminder(self: py_fort_myrmidon.Time, d: py_fort_myrmidon.Duration) py_fort_myrmidon.Duration
Gets the remaider Duration of self.Round(d)
- Round(self: py_fort_myrmidon.Time, d: py_fort_myrmidon.Duration) py_fort_myrmidon.Time
Rounds a Time to the closest Duration
Rounds a Time to the closest Duration. Only multiple of seconds and power of 10 of Nanosecond smaller than a second are supported.
- Parameters:
d (Duration) – a multiple of a second or a power of 10 of a nanosecond.
- Returns:
a new Time rounded to d
- Return type:
- Raises:
ValueError – if d is incorrect
- static SinceEver() py_fort_myrmidon.Time
The negative infinite time.
- Returns:
A Time representing -∞
- Return type:
- Sub(self: py_fort_myrmidon.Time, arg0: py_fort_myrmidon.Time) py_fort_myrmidon.Duration
Measure the Duration between two Time
Similar to self - other. __sub__ operator is also provided.
- Parameters:
other (Time) – the other Time to substract.
- Returns:
result of self - other
- Return type:
- Raises:
Error – if the result would not fit in a Duration (i.e. if one of the
Time.IsInfinite()
)
- ToDateTime(self: py_fort_myrmidon.Time) datetime.datetime
Converts to a
datetime.datetime
The returned object will be a naïve datetime, i.e. expressed in localtime without any timezone information.
- Returns:
a naive datetime.datetime object.
- Return type:
- ToTimestamp(self: py_fort_myrmidon.Time) float
Converts to a float as returned by
time.time()
ordatetime.datetime.timestamp()
- Returns:
an amount of second since the system’s epoch
- Return type:
- __init__(*args, **kwargs)
Overloaded function.
__init__(self: py_fort_myrmidon.Time) -> None
Initialize a Time as the epoch.
__init__(self: py_fort_myrmidon.Time, timestamp: float) -> None
Initializes a Time from a float as returned by
time.time()
ordatetime.datetime.timestamp()
.- Parameters:
timestamp (float) – an amount of second since the epoch. Could be
float('inf')
orfloat('-inf')
.
Note
timestamp are only guaranted to be precise to 10us for Time around year 2020.
__init__(self: py_fort_myrmidon.Time, dt: datetime.datetime) -> None
Initialize from a
datetime.datetime
object.Creates a Time from a
datetime.datetime
. The object will be treated as a local naive datetime, i.e. expressed in localtime and ignoring any time information.- Parameters:
dt (datetime.datetime) – a naïve
datetime.datetime
.
Warning
The dt parameter will be treated as a naïve object, disregarding any associated timezone information. Therefore one must call
datetime.datetime.astimezone()
withtz =None
to convert the object in localtime so it would be correctly converted to UTC internally, which is the default representation in fort-myrmidon and fort-studio.