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 represented with milliseconds since epoch.
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 represented with milliseconds since epoch.

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::Absolute::now().parseLocal(local));
SC_TEST_EXPECT(local.year > 2022);
report.console.print("{:02}/{:02}/{} {:02}:{:02}:{:02} {}", local.dayOfMonth, local.month, 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::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::Relative elapsed = end.subtractApproximate(start);
SC_TEST_EXPECT(elapsed.inRoundedUpperMilliseconds().ms < 300 and elapsed.inRoundedUpperMilliseconds().ms > 0);

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::Relative elapsed = end.subtractApproximate(start);
SC_TEST_EXPECT(elapsed.inRoundedUpperMilliseconds().ms == 321);

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(Time::Milliseconds(123));
SC_TEST_EXPECT(end.isLaterThanOrEqualTo(start));
SC_TEST_EXPECT(not start.isLaterThanOrEqualTo(end));

Roadmap

🟩 Usable

  • No Plan

🟦 Complete Features:

  • No Plan

💡 Unplanned Features:

  • No Plan