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.

Hour

the value for an hour

Type:

Duration

Minute

the value for a minute

Type:

Duration

Second

the value for a second

Type:

Duration

Millisecond

the value for a millisecond

Type:

Duration

Microsecond

the value for a microsecond

Type:

Duration

Hours(self: py_fort_myrmidon.Duration) float

this Duration in hours.

Returns:

the duration as an amount of hours

Return type:

float

Microseconds(self: py_fort_myrmidon.Duration) float

This Duration in microseconds.

Returns:

the duration as an amount of microseconds

Return type:

float

Milliseconds(self: py_fort_myrmidon.Duration) float

This Duration in milliseconds.

Returns:

the duration as an amount of milliseconds

Return type:

float

Minutes(self: py_fort_myrmidon.Duration) float

This Duration in minutes.

Returns:

the duration as an amount of minutes

Return type:

float

Nanoseconds(self: py_fort_myrmidon.Duration) int

This Duration in nanoseconds.

Returns:

the duration as an amount of nanoseconds

Return type:

int

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:

Duration

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:

float

__init__(*args, **kwargs)

Overloaded function.

  1. __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

  1. __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

  1. __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() and datetime.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:

Time

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.

Parameters:

other (Time) – the other Time to test.

Returns:

result of self > other

Return type:

bool

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.

Parameters:

other (Time) – the other Time to test.

Returns:

result of self < other

Return type:

bool

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.

Parameters:

other (Time) – the other Time to test.

Returns:

result of self == other

Return type:

bool

static Forever() py_fort_myrmidon.Time

The positive infinitie time.

Returns:

A Time representing +∞

Return type:

Time

IsForever(self: py_fort_myrmidon.Time) bool

Tests if this Time is +∞

Returns:

True if this time is Time.Forever()

Return type:

bool

IsInfinite(self: py_fort_myrmidon.Time) bool

Tests if this Time is + or - ∞

Returns:

True if this time is Time.SinceEver() or Time.Forever()

Return type:

bool

IsSinceEver(self: py_fort_myrmidon.Time) bool

Tests if this Time is -∞

Returns:

True if this time is Time.SinceEver()

Return type:

bool

static Now() py_fort_myrmidon.Time

Gets the current Time

Returns:

the current Time

Return type:

Time

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:

py_fort_myrmidon.Time

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)

Parameters:

d (Duration) – the duration to round to.

Returns:

the reminder of Round(d)()

Return type:

Duration

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:

Time

Raises:

ValueError – if d is incorrect

static SinceEver() py_fort_myrmidon.Time

The negative infinite time.

Returns:

A Time representing -∞

Return type:

Time

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:

bool

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:

datetime.datetime

ToTimestamp(self: py_fort_myrmidon.Time) float

Converts to a float as returned by time.time() or datetime.datetime.timestamp()

Returns:

an amount of second since the system’s epoch

Return type:

float

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: py_fort_myrmidon.Time) -> None

Initialize a Time as the epoch.

  1. __init__(self: py_fort_myrmidon.Time, timestamp: float) -> None

Initializes a Time from a float as returned by time.time() or datetime.datetime.timestamp().

Parameters:

timestamp (float) – an amount of second since the epoch. Could be float('inf') or float('-inf').

Note

timestamp are only guaranted to be precise to 10us for Time around year 2020.

  1. __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() with tz =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.