Sane C++ Libraries
C++ Platform Abstraction Libraries
Time

🟨 Time handling (relative, absolute, high resolution)

Library contains classes to measure time and compute or measure time intervals.

Features

Class Description
SC::Time::Absolute Absolute time as realtime or monotonically increasing clock.
SC::Time::Monotonic Represent monotonically increasing time (use Monotonic::now for current time)
SC::Time::Realtime Represents a realtime clock in milliseconds since epoch (use Realtime::now for current time)
SC::Time::Relative Interval of time represented with 64 bit double precision float.
SC::Time::HighResolutionCounter An high resolution time counter.

Status

🟨 MVP
This library is in MVP state but it doesn't have a clear roadmap.

Description

SC::Time::Absolute

Absolute time as realtime or monotonically increasing clock.

See also
Monotonic
Realtime

SC::Time::Absolute::parseLocal

Parses local time to a Parsed structure.

Parameters
[out]resultThe Parsed structure holding current date / time
Returns
true if time has been parsed successfully
Example:
Time::Absolute::ParseResult local;
SC_TEST_EXPECT(Time::Realtime::now().parseLocal(local));
SC_TEST_EXPECT(local.year > 2022);
report.console.print("{} {:02}/{:02}/{} {:02}:{:02}:{:02} {}", local.getDay(), local.dayOfMonth, local.getMonth(),
local.year, local.hour, local.minutes, local.seconds,
local.isDaylightSaving ? "DAYLIGHT SAVING" : "NO DAYLIGHT SAVING");
#define SC_TEST_EXPECT(e)
Records a test expectation (eventually aborting or breaking o n failed test)
Definition: Testing.h:113

SC::Time::Monotonic

Represent monotonically increasing time (use Monotonic::now for current time)

SC::Time::Monotonic::now

Obtain time according to monotonic clock.

SC::Time::Realtime

Represents a realtime clock in milliseconds since epoch (use Realtime::now for current time)

SC::Time::Realtime::now

Obtain time according to realtime clock.

SC::Time::Relative

Interval of time represented with 64 bit double precision float.

SC::Time::HighResolutionCounter

An high resolution time counter.

SC::Time::HighResolutionCounter::snap

Sets HighResolutionCounter to current instant
Example:

Time::HighResolutionCounter start, end;
start.snap();
Thread::Sleep(100);
end.snap();
Time::Milliseconds elapsed = end.subtractExact(start).toMilliseconds();
SC_TEST_EXPECT(elapsed < 300_ms and elapsed > 0_ms);

SC::Time::HighResolutionCounter::subtractApproximate

Subtracts another HighResolutionCounter from this one, returning an approximate Relative.

Parameters
otherThe HighResolutionCounter to be subtracted
Returns
A Relative holding the time interval between the two HighResolutionCounter
Example:
Time::HighResolutionCounter start, end;
start.snap();
end = start.offsetBy(Time::Milliseconds(321));
Time::Milliseconds elapsed = end.subtractExact(start).toMilliseconds();
SC_TEST_EXPECT(elapsed == 321_ms);

SC::Time::HighResolutionCounter::isLaterThanOrEqualTo

Check if this HighResolutionCounter is later or equal to another HighResolutionCounter.

Parameters
otherThe HighResolutionCounter to be used in the comparison
Returns
true if this HighResolutionCounter is later or equal to another HighResolutionCounter
Example:
Time::HighResolutionCounter start;
start.snap();
const Time::HighResolutionCounter end = start.offsetBy(123_ms);
SC_TEST_EXPECT(end.isLaterThanOrEqualTo(start));
SC_TEST_EXPECT(not start.isLaterThanOrEqualTo(end));

Blog

Some relevant blog posts are:

Roadmap

🟩 Usable

  • No Plan

🟦 Complete Features:

  • No Plan

💡 Unplanned Features:

  • No Plan