![]() |
NDEVR
API Documentation
|
Represents a timestamp with utilities for manipulation and conversion. More...
Public Types | |
| enum | Month : uint01 |
| Enumerates the months of the year. More... | |
Public Member Functions | |
| constexpr | Time () |
| Default constructor initializing an invalid timestamp. | |
| Time (const StringView &time_string, bool is_local_time, const StringView &format_string) | |
| Constructs a Time from a string representation. | |
| constexpr | Time (const uint08 &time) |
| Constructor initializing the timestamp with a specific value. | |
| Time (uint04 year, uint04 month, uint04 day, uint04 hour=0, uint04 minute=0, uint04 second=0, bool is_local_time=false) | |
| Constructs a Time object using date and time components. | |
| StringAllocatingView | getAsString (bool get_local_time, const StringView &format_string) const |
| Converts the timestamp to a string representation. | |
| uint08 | getMilliseconds () const |
| Gets the timestamp in milliseconds since 1970. | |
| constexpr uint08 | getNanoSeconds () const |
| Gets the time in nanoseconds since 1970. | |
| uint01 | hour (bool is_local_time) const |
| Retrieves the hour of the day, 0-23. | |
| fltp08 | julianDay (bool is_local_time) const |
| Julian dates (abbreviated JD) are simply a continuous count of days and fractions since noon Universal Time on January 1, 4713 BC (on the Julian calendar). | |
| uint02 | millisecond () const |
| Retrieves the millisecond part of a second, from 0-999. | |
| uint01 | minute (bool is_local_time) const |
| Retrieves the minute of the hour, from 0-59. | |
| Month | month (bool is_local_time) const |
| Retrieves the month component of the timestamp. | |
| uint01 | monthDay (bool is_local_time) const |
| Retrieves the day of the month, 1-31. | |
| uint01 | second (bool is_local_time) const |
| Retrieves the second of the minute, from 0-59 (60 if ultra-rare leap second). | |
| void | setDayOfYear (const uint02 &day, bool is_local_time) |
| Sets the day of the year (1-365 or 366 on leap years). | |
| void | setHour (const uint01 &hour, bool is_local_time) |
| Sets the hour of the day, 0-23. | |
| void | setMillisecond (const uint02 &millisecond) |
| Sets the millisecond of the second, 0-999. | |
| void | setMinute (const uint01 &minute, bool is_local_time) |
| Sets the minute of the hour, 0-59. | |
| void | setMonth (const Month &month, bool is_local_time) |
| Sets the month (1-12). | |
| void | setMonthDay (const uint01 &day, bool is_local_time) |
| Sets the day of the month (1-31). | |
| void | setSecond (const uint01 &second, bool is_local_time) |
| Sets the second of the minute, 0-59. | |
| void | setTime (const uint08 &time) |
| Sets the internal timestamp. | |
| void | setTimeFromString (const StringView &time_string, bool is_local_time, const StringView &format_string) |
| Sets the time by converting the timestamp from a string representation. | |
| void | setYear (const uint02 &year, bool is_local_time) |
| Sets the year (1970-2106). | |
| uint08 | unixTime () const |
| Converts the timestamp to a UNIX time representation, or seconds since 1970. | |
| uint02 | year (bool is_local_time) const |
| Retrieves the year component of the timestamp. | |
| uint02 | yearDay (bool is_local_time) const |
| Retrieves the day of the year, 1-365(366 on leap year). | |
Static Public Member Functions | |
| static void | SetSystemTime (const Time &time) |
| Sets the application's system clock to a specified Time. | |
| static Time | SystemTime () |
| Retrieves the current system time which is a combination of std::chrono::steady_clock to ensure smooth time motion and std::chrono::system_clock. | |
Represents a timestamp with utilities for manipulation and conversion.
The Time class provides a framework for working with timestamps. It supports various time operations such as getting and setting components (year, month, day, hour, etc.), formatting, and conversions between time zones.
This class is designed for flexibility, making it suitable for a variety of applications, including scheduling, logging, and time-based calculations. It is small, consuming only 8 bytes of space but can represent nanoseconds over the range of January 1, 1970 at 00:00:00 UTC to February 7, 2106 at 06:28:15 UTC.
| enum Time::Month : uint01 |
|
inlineexplicitconstexpr |
| Time::Time | ( | uint04 | year, |
| uint04 | month, | ||
| uint04 | day, | ||
| uint04 | hour = 0, | ||
| uint04 | minute = 0, | ||
| uint04 | second = 0, | ||
| bool | is_local_time = false ) |
Constructs a Time object using date and time components.
| Time::Time | ( | const StringView & | time_string, |
| bool | is_local_time, | ||
| const StringView & | format_string ) |
Constructs a Time from a string representation.
See https://ndevr.org/time-patterns/ \thows TimeFormatException if the format_string cannot be used to parse the time_string
| time_string | The string to convert to a time |
| is_local_time | Whether to convert to local time. |
| format_string | The format for the string representation. |
| StringAllocatingView Time::getAsString | ( | bool | get_local_time, |
| const StringView & | format_string ) const |
Converts the timestamp to a string representation.
https://ndevr.org/time-patterns/
| get_local_time | Whether to convert to local time, otherwise time will be utc. |
| format_string | The format for the string representation. |
Referenced by JSONNode::operator=().
|
inlinenodiscard |
Gets the timestamp in milliseconds since 1970.
Definition at line 275 of file Time.h.
Referenced by NtpTimestamp::NtpTimestamp(), and ProgressWidgetDemo::UpdateWidgetDemo().
|
inlinenodiscardconstexpr |
Gets the time in nanoseconds since 1970.
This is also the internal storage unit of this class
Definition at line 267 of file Time.h.
Referenced by operator%(), and TimeSpan::setEndTime().
| uint01 Time::hour | ( | bool | is_local_time | ) | const |
| fltp08 Time::julianDay | ( | bool | is_local_time | ) | const |
Julian dates (abbreviated JD) are simply a continuous count of days and fractions since noon Universal Time on January 1, 4713 BC (on the Julian calendar).
Almost 2.5 million days have transpired since this date. Julian dates are widely used as time variables within astronomical software.
| uint02 Time::millisecond | ( | ) | const |
Retrieves the millisecond part of a second, from 0-999.
Referenced by setMillisecond().
| uint01 Time::minute | ( | bool | is_local_time | ) | const |
Retrieves the minute of the hour, from 0-59.
| is_local_time | Indicates whether the time is local or UTC. |
Referenced by Time(), and setMinute().
| Month Time::month | ( | bool | is_local_time | ) | const |
Retrieves the month component of the timestamp.
| is_local_time | Indicates whether the time is local or UTC. |
Referenced by Time(), and setMonth().
| uint01 Time::monthDay | ( | bool | is_local_time | ) | const |
Retrieves the day of the month, 1-31.
| is_local_time | Indicates whether the time is local or UTC. |
| uint01 Time::second | ( | bool | is_local_time | ) | const |
Retrieves the second of the minute, from 0-59 (60 if ultra-rare leap second).
| is_local_time | Indicates whether the time is local or UTC. |
Referenced by Time(), and setSecond().
| void Time::setDayOfYear | ( | const uint02 & | day, |
| bool | is_local_time ) |
Sets the day of the year (1-365 or 366 on leap years).
| day | a 2-byte unsigned integer. |
| is_local_time | Indicates whether the time is local or UTC. |
| void Time::setHour | ( | const uint01 & | hour, |
| bool | is_local_time ) |
| void Time::setMillisecond | ( | const uint02 & | millisecond | ) |
Sets the millisecond of the second, 0-999.
| millisecond | a 2-byte unsigned integer. |
References millisecond().
| void Time::setMinute | ( | const uint01 & | minute, |
| bool | is_local_time ) |
| void Time::setMonth | ( | const Month & | month, |
| bool | is_local_time ) |
| void Time::setMonthDay | ( | const uint01 & | day, |
| bool | is_local_time ) |
Sets the day of the month (1-31).
| day | a 1-byte unsigned integer. |
| is_local_time | Indicates whether the time is local or UTC. |
| void Time::setSecond | ( | const uint01 & | second, |
| bool | is_local_time ) |
|
static |
Sets the application's system clock to a specified Time.
Note: Does not affect OS Time
| time | The Time object to set as the system time. |
References Time().
Referenced by RealSenseServer::checkRecieve().
| void Time::setTime | ( | const uint08 & | time | ) |
Sets the internal timestamp.
| time | Timestamp in nanoseconds. |
| void Time::setTimeFromString | ( | const StringView & | time_string, |
| bool | is_local_time, | ||
| const StringView & | format_string ) |
Sets the time by converting the timestamp from a string representation.
https://ndevr.org/time-patterns/ \thows TimeFormatException if the format_string cannot be used to parse the time_string
| time_string | The string to convert to a time |
| is_local_time | Whether to convert to local time. |
| format_string | The format for the string representation. |
| void Time::setYear | ( | const uint02 & | year, |
| bool | is_local_time ) |
|
static |
Retrieves the current system time which is a combination of std::chrono::steady_clock to ensure smooth time motion and std::chrono::system_clock.
to ensure correct global time. If SetSystemTime is used, this will be modified based on that given time.
References Time().
Referenced by TableChange::TableChange(), RealSensePositionSensor::addDeploymentSegment(), DeviCounterSimulatorIO::bytesAvailable(), HardwareCommandQueue< t_type >::cancelCommand(), RealSenseServer::checkRecieve(), HardwareCommandQueue< t_type >::finishCommand(), TableColumnString::insertIndices(), TableVectorType< 1, T >::insertIndices(), DeviCounterSimulatorIO::peek(), HardwareCommandQueue< t_type >::popCommandAndExecute(), TableColumnString::removeIndices(), TableVectorType< 1, T >::removeIndices(), TableVectorType< 1, T >::removeIndices(), NtpClient::replyReceived(), DeviCounterSimulatorIO::rx(), NtpClient::sendRequest(), DesignObjectResourceCache::setModelToDefaults(), RealSenseMotor::setSpeed(), DesignObject::updateDesignModifiedTime(), Geometry::updateGeometryTime(), Model::updateGeometryTime(), Geometry::updateModifiedTime(), Material::updateModifiedTime(), Model::updateModifiedTime(), ProgressWidgetDemo::UpdateWidgetDemo(), and DeviCounterSimulatorIO::waitForReadyRead().
| uint08 Time::unixTime | ( | ) | const |
Converts the timestamp to a UNIX time representation, or seconds since 1970.
References Time().
| uint02 Time::year | ( | bool | is_local_time | ) | const |
| uint02 Time::yearDay | ( | bool | is_local_time | ) | const |
Retrieves the day of the year, 1-365(366 on leap year).
| is_local_time | Indicates whether the time is local or UTC. |