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

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

Static Public Member Functions

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

Static Public Attributes

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

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
time_stringThe string to convert to a time
is_local_timeWhether to convert to local time.
format_stringThe format for the string representation.

◆ 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()

static 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()

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

◆ SetMakeUTCFromLocalFunction()

static 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()

static 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 )

Sets the time by converting the timestamp from a string representation. https://ndevr.org/time-patterns/.

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 setYear ( const uint02 & year,
bool is_local_time )

◆ SystemTime()

static 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 file: