class EE::System::Time

Overview

Represents a time value

EE::System::Time encapsulates a time value in a flexible way. More…

#include <time.hpp>

class Time {
public:
    // fields

    static const Time Zero;

    // methods

    static bool isValid(const std::string& str);
    static Time fromString(const std::string& str);
    constexpr double asSeconds() const;
    constexpr double asMilliseconds() const;
    constexpr Int64 asMicroseconds() const;
    std::string toString() const;
};

Detailed Documentation

Represents a time value

EE::System::Time encapsulates a time value in a flexible way. It allows to define a time value either as a number of seconds, milliseconds or microseconds. It also works the other way round: you can read a time value as either a number of seconds, milliseconds or microseconds.

By using such a flexible interface, the API doesn’t impose any fixed type or resolution for time values, and let the user choose its own favorite representation.

Time values support the usual mathematical operations: you can add or subtract two times, multiply or divide a time by a number, compare two times, etc.

Since they represent a time span and not an absolute time value, times can also be negative.

Usage example:

Time t1 = Seconds(0.1f);
double milli = t1.asMilliseconds(); // 100

Time t2 = Milliseconds(30);
Int64 micro = t2.asMicroseconds(); // 30000

Time t3 = Microseconds(-800000);
double sec = t3.asSeconds(); // -0.8
void update(Time elapsed) {
   position += speed * elapsed;
}

update(Milliseconds(100));

See also:

EE::System::Clock

Fields

static const Time Zero

Predefined “zero” time value.

Methods

constexpr double asSeconds() const

Return the time value as a number of seconds.

Returns:

Time in seconds

See also:

AsMilliseconds, AsMicroseconds

constexpr double asMilliseconds() const

Return the time value as a number of milliseconds.

Returns:

Time in milliseconds

See also:

AsSeconds, AsMicroseconds

constexpr Int64 asMicroseconds() const

Return the time value as a number of microseconds.

Returns:

Time in microseconds

See also:

asSeconds, asMilliseconds

std::string toString() const

Converts the time into a human readable string.