LocalTimeRK
|
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) | |
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.
|
inline |
Construct a YMD value from a string.
s | String, must be in YYYY-MM-DD format. No other formars are allowed! |
|
inline |
Construct from a LocalTimeValue object.
value | The date to copy from |
void LocalTimeYMD::addDay | ( | int | numberOfDays = 1 | ) |
Add a number of days to the current YMD (updating month or year as necessary)
numberOfDays | Number of days to add (positive) or subtract (negative) |
Works correctly with leap years.
int LocalTimeYMD::compareTo | ( | const LocalTimeYMD | other | ) | const |
Compare to another LocalTimeYMD object.
other |
void LocalTimeYMD::fromLocalTimeValue | ( | const LocalTimeValue & | value | ) |
The LocalTimeValue to copy the year, month and day from.
value | Source of the year, month, and day values |
Since LocalTimeValue contains a struct tm, this uses fromTimeInfo internally.
void LocalTimeYMD::fromTimeInfo | ( | const struct tm * | pTimeInfo | ) |
Copies the year, month, and day from a struct tm.
pTimeInfo | The pointer to a struct tm to copy the year, month, and day from. |
The tm should be in local time.
|
inline |
Get the day of month, starting a 1.
int LocalTimeYMD::getDayOfWeek | ( | ) | const |
Get the day of the week, 0 = Sunday, 1 = Monday, 2 = Tuesday, ..., 6 = Saturday.
|
inline |
Get the month, 1 - 12 inclusive.
|
inline |
Get the year as a 4-digit year, for example: 2022.
|
inline |
Returns true if the date is uninitialized, as from the default constructor.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
bool LocalTimeYMD::parse | ( | const char * | s | ) |
Parse a YMD string in the format "YYYY-MD-DD". Only this format is supported!
s |
Do not use this function with other date formats like "mm/dd/yyyy"!
|
inline |
Set the day of the month, staring at 1.
day |
This method does not validate the date value, but you should avoid setting invalid date values since the results can be unpredictable.
|
inline |
Set the month, 1 - 12 inclusive.
month | Month value |
|
inline |
Set the year value.
year | Year to set, can be several different values but typically is 4-digit year (2022, for example) |
|
inline |
Converts the value to YYYY-MM-DD format as a String with leading zeros.