edelib
2.1.0
|
A class for date manipulation. More...
#include <edelib/DateTime.h>
Public Types | |
enum | Month { Jan = 1, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec, MonthNow } |
Abbreviated months. More... | |
enum | Day { DayNow = 0 } |
Current day. More... | |
enum | Year { YearNow = 0 } |
Current year. More... | |
Public Member Functions | |
Date () | |
Date (const Date &d) | |
Date & | operator= (const Date &d) |
~Date () | |
bool | set (unsigned short y, unsigned char m, unsigned char d, DateType t=DATE_LOCAL) |
bool | system_set (void) |
bool | leap_year (void) const |
unsigned char | day (void) const |
unsigned char | month (void) const |
unsigned short | year (void) const |
const char * | day_name (void) |
const char * | month_name (void) |
unsigned char | days_in_month () const |
unsigned char | day_of_week () const |
unsigned short | day_of_year () const |
Date & | operator++ () |
Date | operator++ (int) |
Date & | operator-- () |
Date | operator-- (int) |
Static Public Member Functions | |
static bool | leap_year (unsigned short y) |
static unsigned char | days_in_month (unsigned short y, unsigned char m) |
static bool | is_valid (unsigned short y, unsigned char m, unsigned char d) |
A class for date manipulation.
This class represents a calendar date. It has ability to read system date or to use and manipulate with filled year/month/day values.
Setting date is via set() member, and it accept year/month/day form. This is sample:
set() can also accept abbreviations for months or shorthands for current year/month/day (in this case will consult system date)
set() will check input, and in case of bad date (either abnormal input values or setting feb/29 in non leap year) will trigger assert.
There is a one catch using abbreviations and valid date. For example, setting:
is perfectly valid, since Date::YearNow and Date::DayNow enumerations are zero; in this case, function will behave as it was set:
Date contains operators for comparrisons, so this can be done with those:
enum Day |
enum Month |
enum Year |
Date | ( | ) |
Construct empty date. All walues will be zero. This is not valid, so is_valid() member will return false.
~Date | ( | ) |
Clear internal data
|
inline |
Return internal day value
const char* day_name | ( | void | ) |
Return day name for internal day value, eg. Monday/Tuesday/... Returned data must not be modified since is pointing to static data. You should copy it if you need to modify it.
unsigned char day_of_week | ( | ) | const |
Return day in week (1..7) calculated from internal values.
unsigned short day_of_year | ( | ) | const |
Return day of year of currently set date
unsigned char days_in_month | ( | ) | const |
Return number of days of internal year/month value
|
static |
Return number of days in given year and month. Given data must be valid date
y | is year to check |
m | is month to check |
|
static |
Validate given year/month/day values, including leap year check
y | is year |
m | is month |
d | is day |
|
inline |
Check internal year value if is leap year
References Date::leap_year().
Referenced by Date::leap_year().
|
static |
Check if given year is leap year
y | is year to check |
|
inline |
Return internal month value
const char* month_name | ( | void | ) |
Return month name for internal month value, eg. January/February/... Returned data must not be modified, since applies as for day_name().
Date& operator++ | ( | ) |
Increase current date by one. First day value is increased, then if that day is last in month, month is increased, then if that month is last in year, year is increased.
Date operator++ | ( | int | ) |
Suffix increment
Date& operator-- | ( | ) |
Reverse from operator++()
Date operator-- | ( | int | ) |
Suffix decrement
Assign previously declared value to this. Current content will be replaced
bool set | ( | unsigned short | y, |
unsigned char | m, | ||
unsigned char | d, | ||
DateType | t = DATE_LOCAL |
||
) |
Fill internal data. Data should be valid date (including leap year) or assertion will be triggered.
Input can be either in form of numbers or abbreviations for month.
y | fill with year value |
m | fill with month value; should be 1 <= m <= 12 |
d | fill with day value; should be 1 <= d <= 30 (or 31 for months this days number or 28 if is non-leap year) |
t | fill with localized or UTC date values |
bool system_set | ( | void | ) |
Tries to set system date with current values. This function will try to call settimeofday() and if not exists, it will fallback to stime(). If both functions are not present, it will return false.
Since these functions requires priviledged user, if they are present but user is not allow to set date, this function will return false too. Contrary this, it will return true if able to set date.
|
inline |
Return internal year value