NDEVR
API Documentation
Time

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.

Detailed Description

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.

Note
Unlike many other time classes which represent a local time, this class is designed to store a distinct point in time, common across all reference time zones. Thus the struct is internally always set to UTC time. Most functions have the ability to use local time, which uses the time zone of the system the software is running on.

Definition at line 61 of file Time.h.

Member Enumeration Documentation

◆ Month

Enumerates the months of the year.

Values range from JANUARY (1) to DECEMBER (12) for easy reference in operations involving months.

Definition at line 70 of file Time.h.

Constructor & Destructor Documentation

◆ Time() [1/3]

Time::Time ( const uint08 & time)
inlineexplicitconstexpr

Constructor initializing the timestamp with a specific value.

Can be used with constants such as NANOSECOND, or MILLISECOND for times relative to 1970.

Parameters
timeTimestamp in nanoseconds.

Definition at line 113 of file Time.h.

◆ Time() [2/3]

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.

Parameters
yearYear component.
monthMonth component (1-12).
dayDay of the month.
hourHour of the day (default is 0).
minuteMinute of the hour (default is 0).
secondSecond of the minute (default is 0).
is_local_timeIndicates whether the time is local or UTC.

References hour(), minute(), month(), second(), and year().

◆ Time() [3/3]

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

Parameters
time_stringThe string to convert to a time
is_local_timeWhether to convert to local time.
format_stringThe format for the string representation.

Member Function Documentation

◆ getAsString()

StringAllocatingView Time::getAsString ( bool get_local_time,
const StringView & format_string ) const

Converts the timestamp to a string representation.

https://ndevr.org/time-patterns/

Parameters
get_local_timeWhether to convert to local time, otherwise time will be utc.
format_stringThe format for the string representation.
Returns
A formatted string representing the timestamp.

Referenced by JSONNode::operator=().

◆ getMilliseconds()

uint08 Time::getMilliseconds ( ) const
inlinenodiscard

Gets the timestamp in milliseconds since 1970.

Returns
Timestamp in milliseconds since 1970.

Definition at line 275 of file Time.h.

Referenced by NtpTimestamp::NtpTimestamp(), and ProgressWidgetDemo::UpdateWidgetDemo().

◆ getNanoSeconds()

uint08 Time::getNanoSeconds ( ) const
inlinenodiscardconstexpr

Gets the time in nanoseconds since 1970.

This is also the internal storage unit of this class

Returns
Timestamp in nanoseconds since 1970.

Definition at line 267 of file Time.h.

Referenced by operator%(), and TimeSpan::setEndTime().

◆ hour()

uint01 Time::hour ( bool is_local_time) const

Retrieves the hour of the day, 0-23.

Parameters
is_local_timeIndicates whether the time is local or UTC.
Returns
Hour as a 1-byte unsigned integer.

Referenced by Time(), and setHour().

◆ julianDay()

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.

◆ millisecond()

uint02 Time::millisecond ( ) const

Retrieves the millisecond part of a second, from 0-999.

Returns
Milliseconds as a 2-byte unsigned integer.

Referenced by setMillisecond().

◆ minute()

uint01 Time::minute ( bool is_local_time) const

Retrieves the minute of the hour, from 0-59.

Parameters
is_local_timeIndicates whether the time is local or UTC.
Returns
Minute as a 1-byte unsigned integer.

Referenced by Time(), and setMinute().

◆ month()

Month Time::month ( bool is_local_time) const

Retrieves the month component of the timestamp.

Parameters
is_local_timeIndicates whether the time is local or UTC.
Returns
Month as a 1-byte unsigned integer, where 1 = January.

Referenced by Time(), and setMonth().

◆ monthDay()

uint01 Time::monthDay ( bool is_local_time) const

Retrieves the day of the month, 1-31.

Parameters
is_local_timeIndicates whether the time is local or UTC.
Returns
the month day as a 1-byte unsigned integer.

◆ second()

uint01 Time::second ( bool is_local_time) const

Retrieves the second of the minute, from 0-59 (60 if ultra-rare leap second).

Parameters
is_local_timeIndicates whether the time is local or UTC.
Returns
Second as a 1-byte unsigned integer.

Referenced by Time(), and setSecond().

◆ setDayOfYear()

void Time::setDayOfYear ( const uint02 & day,
bool is_local_time )

Sets the day of the year (1-365 or 366 on leap years).

Parameters
daya 2-byte unsigned integer.
is_local_timeIndicates whether the time is local or UTC.

◆ setHour()

void Time::setHour ( const uint01 & hour,
bool is_local_time )

Sets the hour of the day, 0-23.

Parameters
houra 1-byte unsigned integer.
is_local_timeIndicates whether the time is local or UTC.

References hour().

◆ setMillisecond()

void Time::setMillisecond ( const uint02 & millisecond)

Sets the millisecond of the second, 0-999.

Parameters
milliseconda 2-byte unsigned integer.

References millisecond().

◆ setMinute()

void Time::setMinute ( const uint01 & minute,
bool is_local_time )

Sets the minute of the hour, 0-59.

Parameters
minutea 1-byte unsigned integer.
is_local_timeIndicates whether the time is local or UTC.

References minute().

◆ setMonth()

void Time::setMonth ( const Month & month,
bool is_local_time )

Sets the month (1-12).

Parameters
montha 1-byte unsigned integer.
is_local_timeIndicates whether the time is local or UTC.

References month().

◆ setMonthDay()

void Time::setMonthDay ( const uint01 & day,
bool is_local_time )

Sets the day of the month (1-31).

Parameters
daya 1-byte unsigned integer.
is_local_timeIndicates whether the time is local or UTC.

◆ setSecond()

void Time::setSecond ( const uint01 & second,
bool is_local_time )

Sets the second of the minute, 0-59.

Parameters
seconda 1-byte unsigned integer.
is_local_timeIndicates whether the time is local or UTC.

References second().

◆ SetSystemTime()

void Time::SetSystemTime ( const Time & time)
static

Sets the application's system clock to a specified Time.

Note: Does not affect OS Time

Parameters
timeThe Time object to set as the system time.

References Time().

Referenced by RealSenseServer::checkRecieve().

◆ setTime()

void Time::setTime ( const uint08 & time)

Sets the internal timestamp.

Parameters
timeTimestamp in nanoseconds.

◆ setTimeFromString()

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

Parameters
time_stringThe string to convert to a time
is_local_timeWhether to convert to local time.
format_stringThe format for the string representation.

◆ setYear()

void Time::setYear ( const uint02 & year,
bool is_local_time )

Sets the year (1970-2106).

Parameters
yeara 1-byte unsigned integer.
is_local_timeIndicates whether the time is local or UTC.

References year().

◆ SystemTime()

◆ unixTime()

uint08 Time::unixTime ( ) const

Converts the timestamp to a UNIX time representation, or seconds since 1970.

Returns
UNIX timestamp in nanoseconds.

References Time().

◆ year()

uint02 Time::year ( bool is_local_time) const

Retrieves the year component of the timestamp.

Parameters
is_local_timeIndicates whether the time is local or UTC.
Returns
Year as a 2-byte unsigned integer.

Referenced by Time(), and setYear().

◆ yearDay()

uint02 Time::yearDay ( bool is_local_time) const

Retrieves the day of the year, 1-365(366 on leap year).

Parameters
is_local_timeIndicates whether the time is local or UTC.
Returns
the day of the year

The documentation for this class was generated from the following file: