LocalTimeRK
Data Structures | Public Member Functions | Data Fields
LocalTimeYMD Class Reference

Class for holding a year month day efficiently (4 bytes of storage) More...

#include <LocalTimeRK.h>

Data Structures

struct  YMD
 Packed structure to hold the YMD value. More...
 

Public Member Functions

 LocalTimeYMD ()
 Default contructor with an invalid date (0000-00-00) set.
 
 LocalTimeYMD (const char *s)
 Construct a YMD value from a string. More...
 
 LocalTimeYMD (const LocalTimeValue &value)
 Construct from a LocalTimeValue object. More...
 
bool isEmpty () const
 Returns true if the date is uninitialized, as from the default constructor. More...
 
int getYear () const
 Get the year as a 4-digit year, for example: 2022. More...
 
void setYear (int year)
 Set the year value. More...
 
int getMonth () const
 Get the month, 1 - 12 inclusive. More...
 
void setMonth (int month)
 Set the month, 1 - 12 inclusive. More...
 
int getDay () const
 Get the day of month, starting a 1. More...
 
void setDay (int day)
 Set the day of the month, staring at 1. More...
 
void fromTimeInfo (const struct tm *pTimeInfo)
 Copies the year, month, and day from a struct tm. More...
 
void fromLocalTimeValue (const LocalTimeValue &value)
 The LocalTimeValue to copy the year, month and day from. More...
 
void addDay (int numberOfDays=1)
 Add a number of days to the current YMD (updating month or year as necessary) More...
 
int getDayOfWeek () const
 Get the day of the week, 0 = Sunday, 1 = Monday, 2 = Tuesday, ..., 6 = Saturday. More...
 
int compareTo (const LocalTimeYMD other) const
 Compare to another LocalTimeYMD object. More...
 
bool operator== (const LocalTimeYMD other) const
 Tests if this LocalTimeYMD is equal to other. More...
 
bool operator!= (const LocalTimeYMD other) const
 Tests if this LocalTimeYMD is not equal to other. More...
 
bool operator< (const LocalTimeYMD other) const
 Tests if this LocalTimeYMD is less than other. More...
 
bool operator<= (const LocalTimeYMD other) const
 Tests if this LocalTimeYMD is less than or equal to other. More...
 
bool operator> (const LocalTimeYMD other) const
 Tests if this LocalTimeYMD is greater than other. More...
 
bool operator>= (const LocalTimeYMD other) const
 Tests if this LocalTimeYMD is greater than or equal to other. More...
 
bool parse (const char *s)
 Parse a YMD string in the format "YYYY-MD-DD". Only this format is supported! More...
 
String toString () const
 Converts the value to YYYY-MM-DD format as a String with leading zeros. More...
 

Data Fields

YMD ymd
 Packed value for year, month, and day of month (4 bytes)
 

Detailed Description

Class for holding a year month day efficiently (4 bytes of storage)

There is no method to get this object from a time_t because time_t is at UTC and this object is intended to be the YMD at local time to correspond with a LocalTimeHMS. Thus it requires a LocalTimeConvert object, and there is a method to get a LocalTimeYMD from a LocalTimeConvert, not from this object.

Constructor & Destructor Documentation

◆ LocalTimeYMD() [1/2]

LocalTimeYMD::LocalTimeYMD ( const char *  s)
inline

Construct a YMD value from a string.

Parameters
sString, must be in YYYY-MM-DD format. No other formars are allowed!

◆ LocalTimeYMD() [2/2]

LocalTimeYMD::LocalTimeYMD ( const LocalTimeValue value)
inline

Construct from a LocalTimeValue object.

Parameters
valueThe date to copy from

Member Function Documentation

◆ addDay()

void LocalTimeYMD::addDay ( int  numberOfDays = 1)

Add a number of days to the current YMD (updating month or year as necessary)

Parameters
numberOfDaysNumber of days to add (positive) or subtract (negative)

Works correctly with leap years.

◆ compareTo()

int LocalTimeYMD::compareTo ( const LocalTimeYMD  other) const

Compare to another LocalTimeYMD object.

Parameters
other
Returns
int -1 if this is < other, 0 if this == other, or 1 if this > other.

◆ fromLocalTimeValue()

void LocalTimeYMD::fromLocalTimeValue ( const LocalTimeValue value)

The LocalTimeValue to copy the year, month and day from.

Parameters
valueSource of the year, month, and day values

Since LocalTimeValue contains a struct tm, this uses fromTimeInfo internally.

◆ fromTimeInfo()

void LocalTimeYMD::fromTimeInfo ( const struct tm *  pTimeInfo)

Copies the year, month, and day from a struct tm.

Parameters
pTimeInfoThe pointer to a struct tm to copy the year, month, and day from.

The tm should be in local time.

◆ getDay()

int LocalTimeYMD::getDay ( ) const
inline

Get the day of month, starting a 1.

Returns
int

◆ getDayOfWeek()

int LocalTimeYMD::getDayOfWeek ( ) const

Get the day of the week, 0 = Sunday, 1 = Monday, 2 = Tuesday, ..., 6 = Saturday.

Returns
int the day of the week

◆ getMonth()

int LocalTimeYMD::getMonth ( ) const
inline

Get the month, 1 - 12 inclusive.

Returns
int month

◆ getYear()

int LocalTimeYMD::getYear ( ) const
inline

Get the year as a 4-digit year, for example: 2022.

Returns
int The year, 4-digit

◆ isEmpty()

bool LocalTimeYMD::isEmpty ( ) const
inline

Returns true if the date is uninitialized, as from the default constructor.

Returns
true
false

◆ operator!=()

bool LocalTimeYMD::operator!= ( const LocalTimeYMD  other) const
inline

Tests if this LocalTimeYMD is not equal to other.

Parameters
other
Returns
true
false

◆ operator<()

bool LocalTimeYMD::operator< ( const LocalTimeYMD  other) const
inline

Tests if this LocalTimeYMD is less than other.

Parameters
other
Returns
true
false

◆ operator<=()

bool LocalTimeYMD::operator<= ( const LocalTimeYMD  other) const
inline

Tests if this LocalTimeYMD is less than or equal to other.

Parameters
other
Returns
true
false

◆ operator==()

bool LocalTimeYMD::operator== ( const LocalTimeYMD  other) const
inline

Tests if this LocalTimeYMD is equal to other.

Parameters
other
Returns
true
false

◆ operator>()

bool LocalTimeYMD::operator> ( const LocalTimeYMD  other) const
inline

Tests if this LocalTimeYMD is greater than other.

Parameters
other
Returns
true
false

◆ operator>=()

bool LocalTimeYMD::operator>= ( const LocalTimeYMD  other) const
inline

Tests if this LocalTimeYMD is greater than or equal to other.

Parameters
other
Returns
true
false

◆ parse()

bool LocalTimeYMD::parse ( const char *  s)

Parse a YMD string in the format "YYYY-MD-DD". Only this format is supported!

Parameters
s
Returns
true
false

Do not use this function with other date formats like "mm/dd/yyyy"!

◆ setDay()

void LocalTimeYMD::setDay ( int  day)
inline

Set the day of the month, staring at 1.

Parameters
day

This method does not validate the date value, but you should avoid setting invalid date values since the results can be unpredictable.

◆ setMonth()

void LocalTimeYMD::setMonth ( int  month)
inline

Set the month, 1 - 12 inclusive.

Parameters
monthMonth value

◆ setYear()

void LocalTimeYMD::setYear ( int  year)
inline

Set the year value.

Parameters
yearYear to set, can be several different values but typically is 4-digit year (2022, for example)

◆ toString()

String LocalTimeYMD::toString ( ) const
inline

Converts the value to YYYY-MM-DD format as a String with leading zeros.

Returns
String

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