API Documentation
Loading...
Searching...
No Matches
Time Class Reference

Represents a timestamp with utilities for manipulation and conversion. More...

#include <Time.h>

Public Types

enum  Months {
  JANUARY = 1 , FEBRUARY , MARCH , APRIL ,
  MAY , JUNE , JULY , AUGUST ,
  SEPTEMBER , OCTOBER , NOVEMBER , DECEMBER
}
 Enumerates the months of the year. More...
 

Public Member Functions

constexpr Time ()
 Default constructor initializing an invalid timestamp.
 
constexpr Time (const uint08 &time)
 Constructor initializing the timestamp with a specific value.
 
NDEVR_BASE_API 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.
 
NDEVR_BASE_API Time (const String &time_string, bool is_local_time, const String &format_string)
 Constructs a Time from a string representation. https://ndevr.org/time-patterns/.
 
NDEVR_BASE_API Time (const char *time_string, bool is_local_time, const String &format_string)
 
NDEVR_BASE_API void setTime (const uint08 &time)
 Sets the internal timestamp.
 
NDEVR_BASE_API String toString (bool get_local_time, const String &format_string) const
 Converts the timestamp to a string representation. https://ndevr.org/time-patterns/.
 
NDEVR_BASE_API void setTimeFromString (const String &time_string, bool is_local_time, const String &format_string)
 Converts the timestamp from a string representation. https://ndevr.org/time-patterns/.
 
NDEVR_BASE_API void setHour (const uint01 &hour, bool is_local_time)
 
NDEVR_BASE_API void setMinute (const uint01 &minute, bool is_local_time)
 
NDEVR_BASE_API void setSecond (const uint01 &second, bool is_local_time)
 
NDEVR_BASE_API void setMillisecond (const uint02 &millisecond)
 
NDEVR_BASE_API void setYear (const uint02 &year, bool is_local_time)
 
NDEVR_BASE_API void setMonth (const uint01 &month, bool is_local_time)
 
NDEVR_BASE_API void setMonthDay (const uint01 &day, bool is_local_time)
 
NDEVR_BASE_API void setDayOfYear (const uint02 &day, bool is_local_time)
 
NDEVR_BASE_API fltp08 julianDay (bool is_local_time) const
 
NDEVR_BASE_API uint02 year (bool is_local_time) const
 Retrieves the year component of the timestamp.
 
NDEVR_BASE_API uint02 month (bool is_local_time) const
 Retrieves the month component of the timestamp.
 
NDEVR_BASE_API uint02 monthDay (bool is_local_time) const
 
NDEVR_BASE_API uint02 yearDay (bool is_local_time) const
 
NDEVR_BASE_API uint01 hour (bool is_local_time) const
 Retrieves the hour component of the timestamp.
 
NDEVR_BASE_API uint01 minute (bool is_local_time) const
 
NDEVR_BASE_API uint01 second (bool is_local_time) const
 
NDEVR_BASE_API uint02 millisecond () const
 
constexpr uint08 getNanoSeconds () const
 Gets the timestamp in nanoseconds.
 
uint08 getMilliseconds () const
 Gets the timestamp in milliseconds.
 
NDEVR_BASE_API uint08 unixTime () const
 Converts the timestamp to a UNIX time representation.
 
NDEVR_BASE_API uint08 leapYearConstant () const
 
NDEVR_BASE_API uint08 daysConstant () const
 
NDEVR_BASE_API uint08 monthsConstant () const
 
bool operator== (const Time &time) const
 
bool operator!= (const Time &time) const
 
bool operator< (const Time &time) const
 
bool operator<= (const Time &time) const
 
bool operator> (const Time &time) const
 
bool operator>= (const Time &time) const
 

Static Public Member Functions

static NDEVR_BASE_API Time SystemTime ()
 Retrieves the current system time.
 
static NDEVR_BASE_API void SetSystemTime (const Time &time)
 Sets the application's system clock to a specified Time. Note: Does not affect OS Time.
 
static NDEVR_BASE_API void SetMakeUTCFromLocalFunction (const std::function< uint08(const tm &tm)> &function)
 
static NDEVR_BASE_API void SetMakeLocalFromUTCFunction (const std::function< uint08(const tm &tm)> &function)
 
static NDEVR_BASE_API void SetClockErrorCallback (const std::function< void(const Exception &error)> &function)
 

Static Public Attributes

static constexpr uint08 NANOSECOND = 1
 
static constexpr uint08 MICROSECOND = 1000 * NANOSECOND
 
static constexpr uint08 MILLISECOND = 1000000
 
static constexpr uint08 SECOND = 1000000000
 
static constexpr uint08 MINUTE = SECOND * 60
 
static constexpr uint08 HOUR = MINUTE * 60
 
static constexpr uint08 DAY = HOUR * 24
 
static constexpr uint08 WEEK = DAY * 7
 
static constexpr uint08 YEAR = DAY * 365
 
static constexpr uint08 LEAP_YEAR = DAY * 366
 

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.

Member Enumeration Documentation

◆ Months

enum Months

Enumerates the months of the year.

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

Enumerator
JANUARY 
FEBRUARY 
MARCH 
APRIL 
MAY 
JUNE 
JULY 
AUGUST 
SEPTEMBER 
OCTOBER 
NOVEMBER 
DECEMBER 

Constructor & Destructor Documentation

◆ Time() [1/5]

Time ( )
inlineconstexpr

Default constructor initializing an invalid timestamp.

◆ Time() [2/5]

Time ( const uint08 & time)
inlineexplicitconstexpr

Constructor initializing the timestamp with a specific value.

Parameters
timeTimestamp in nanoseconds.

◆ Time() [3/5]

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.

◆ Time() [4/5]

Time ( const String & time_string,
bool is_local_time,
const String & format_string )

Constructs a Time from a string representation. https://ndevr.org/time-patterns/.

Parameters
get_local_timeWhether to convert to local time.
format_stringThe format for the string representation.
Returns
A formatted string representing the timestamp.

◆ Time() [5/5]

Time ( const char * time_string,
bool is_local_time,
const String & format_string )

Member Function Documentation

◆ daysConstant()

uint08 daysConstant ( ) const
nodiscard

◆ getMilliseconds()

uint08 getMilliseconds ( ) const
inlinenodiscard

Gets the timestamp in milliseconds.

Returns
Timestamp in milliseconds.

◆ getNanoSeconds()

uint08 getNanoSeconds ( ) const
inlinenodiscardconstexpr

Gets the timestamp in nanoseconds.

Returns
Timestamp in nanoseconds.

◆ hour()

uint01 hour ( bool is_local_time) const

Retrieves the hour component of the timestamp.

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

◆ julianDay()

fltp08 julianDay ( bool is_local_time) const

◆ leapYearConstant()

uint08 leapYearConstant ( ) const
nodiscard

◆ millisecond()

uint02 millisecond ( ) const

◆ minute()

uint01 minute ( bool is_local_time) const

◆ month()

uint02 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 2-byte unsigned integer.

◆ monthDay()

uint02 monthDay ( bool is_local_time) const

◆ monthsConstant()

uint08 monthsConstant ( ) const
nodiscard

◆ operator!=()

bool operator!= ( const Time & time) const
inline

◆ operator<()

bool operator< ( const Time & time) const
inline

◆ operator<=()

bool operator<= ( const Time & time) const
inline

◆ operator==()

bool operator== ( const Time & time) const
inline

◆ operator>()

bool operator> ( const Time & time) const
inline

◆ operator>=()

bool operator>= ( const Time & time) const
inline

◆ second()

uint01 second ( bool is_local_time) const

◆ SetClockErrorCallback()

void SetClockErrorCallback ( const std::function< void(const Exception &error)> & function)
static

◆ setDayOfYear()

void setDayOfYear ( const uint02 & day,
bool is_local_time )

◆ setHour()

void setHour ( const uint01 & hour,
bool is_local_time )

◆ SetMakeLocalFromUTCFunction()

void SetMakeLocalFromUTCFunction ( const std::function< uint08(const tm &tm)> & function)
static

◆ SetMakeUTCFromLocalFunction()

void SetMakeUTCFromLocalFunction ( const std::function< uint08(const tm &tm)> & function)
static

◆ setMillisecond()

void setMillisecond ( const uint02 & millisecond)

◆ setMinute()

void setMinute ( const uint01 & minute,
bool is_local_time )

◆ setMonth()

void setMonth ( const uint01 & month,
bool is_local_time )

◆ setMonthDay()

void setMonthDay ( const uint01 & day,
bool is_local_time )

◆ setSecond()

void setSecond ( const uint01 & second,
bool is_local_time )

◆ SetSystemTime()

NDEVR_BASE_API void 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.

◆ setTime()

void setTime ( const uint08 & time)

Sets the internal timestamp.

Parameters
timeTimestamp in nanoseconds.

◆ setTimeFromString()

void setTimeFromString ( const String & time_string,
bool is_local_time,
const String & format_string )

Converts the timestamp from a string representation. https://ndevr.org/time-patterns/.

Parameters
get_local_timeWhether to convert to local time.
format_stringThe format for the string representation.
Returns
A formatted string representing the timestamp.

◆ setYear()

void setYear ( const uint02 & year,
bool is_local_time )

◆ SystemTime()

Time SystemTime ( )
static

Retrieves the current system time.

Returns
The current system time as a Time object.

◆ toString()

String toString ( bool get_local_time,
const String & format_string ) const

Converts the timestamp to a string representation. https://ndevr.org/time-patterns/.

Parameters
get_local_timeWhether to convert to local time.
format_stringThe format for the string representation.
Returns
A formatted string representing the timestamp.

◆ unixTime()

uint08 unixTime ( ) const

Converts the timestamp to a UNIX time representation.

Returns
UNIX timestamp in nanoseconds.

◆ year()

uint02 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.

◆ yearDay()

uint02 yearDay ( bool is_local_time) const

Member Data Documentation

◆ DAY

uint08 DAY = HOUR * 24
staticconstexpr

◆ HOUR

uint08 HOUR = MINUTE * 60
staticconstexpr

◆ LEAP_YEAR

uint08 LEAP_YEAR = DAY * 366
staticconstexpr

◆ MICROSECOND

uint08 MICROSECOND = 1000 * NANOSECOND
staticconstexpr

◆ MILLISECOND

uint08 MILLISECOND = 1000000
staticconstexpr

◆ MINUTE

uint08 MINUTE = SECOND * 60
staticconstexpr

◆ NANOSECOND

uint08 NANOSECOND = 1
staticconstexpr

◆ SECOND

uint08 SECOND = 1000000000
staticconstexpr

◆ WEEK

uint08 WEEK = DAY * 7
staticconstexpr

◆ YEAR

uint08 YEAR = DAY * 365
staticconstexpr

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