edelib 2.1.0

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

Public Types | Public Member Functions | Static Public Member Functions | List of all members
Date Class Reference

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)

## Detailed Description

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:

Date mydate;
mydate.set(2006, 1, 1);
// following will be true
mydate.day() == 1;
mydate.month() == 1;
mydate.year() == 1;

set() can also accept abbreviations for months or shorthands for current year/month/day (in this case will consult system date)

...
mydate.set(2006, Date::Jun, 10);
// or use curren date
mydate.set(Date::YearNow, Date::MonthNow, Date::DayNow);

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:

mydate.set(0,1,0)

is perfectly valid, since Date::YearNow and Date::DayNow enumerations are zero; in this case, function will behave as it was set:

mydate.set(Date::YearNow, Date::Jan, Date::DayNow);

Date contains operators for comparrisons, so this can be done with those:

Date d1,d2;
d1.set(2007, 1, 1);
d2.set(2007, 2, 1);
d1 != d2; // will be true
d1 <= d2; // also true
d2 = d1; // assign d1 values
d1 == d2; // true
...

## Member Enumeration Documentation

enum Day

Current day.

Enumerator
DayNow | Current system date.

enum Month

Abbreviated months.

Enumerator
Jan | January.
Feb | February.
Mar | March.
Apr | April.
May | May.
Jun | June.
Jul | July.
Aug | August.
Sep | September.
Oct | October.
Nov | November.
Dec | December.
MonthNow | Current system month.

enum Year

Current year.

Enumerator
YearNow | Current system year.

## Constructor & Destructor Documentation

Date | ( |  | ) |

Construct empty date. All walues will be zero. This is not valid, so is_valid() member will return false.

Date | ( | const Date & | d | ) |

Construct date via previously declared value

~Date | ( |  | ) |

Clear internal data

## Member Function Documentation

unsigned char day | ( | void |  | ) | const
| 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.

Note
  Values are in Western format, so 1 == Sunday, 2 == Monday, ...

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 unsigned char days_in_month | ( | unsigned short | y,
|  | unsigned char | m
| ) |  |
| static

Return number of days in given year and month. Given data must be valid date

Returns
  number of days for given year/month

Parameters

  y | is year to check
  m | is month to check

static bool is_valid | ( | unsigned short | y,
|  | unsigned char | m,
|  | unsigned char | d
| ) |  |
| static

Validate given year/month/day values, including leap year check

Returns
  true if date is correct, or false if not

Parameters

  y | is year
  m | is month
  d | is day

bool leap_year | ( | void |  | ) | const
| inline

Check internal year value if is leap year

References Date::leap_year().

Referenced by Date::leap_year().

static bool leap_year | ( | unsigned short | y | ) |
| static

Check if given year is leap year

Returns
  true if it is or false if not

Parameters

  y | is year to check

unsigned char month | ( | void |  | ) | const
| 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

Date& operator= | ( | const Date & | d | ) |

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.

Todo:
  it can accept set(0,1,0); leave this or... (possible bugs ?)

Returns
  todo

Parameters

  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.

Todo:
  This should be probably a static function

unsigned short year | ( | void |  | ) | const
| inline

Return internal year value

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

- edelib/DateTime.h