Date expressed in year, month, and day More...

#include <tntdb/cxxtools/date.h>

Public Types

enum  Month {
  Jan = 1, Feb, Mar, Apr,
  May, Jun, Jul, Aug,
  Sep, Oct, Nov, Dec
}
enum  WeekDay {
  Sun = 0, Mon, Tue, Wed,
  Thu, Fri, Sat
}

Public Member Functions

 Date ()
 Default constructor.
 Date (const std::string &d, const std::string &fmt="%Y-%m-%d")
 create Date from string using format
 Date (int y, unsigned m, unsigned d)
 Constructs a Date from given values.
 Date (unsigned julianDays)
 Constructs a Date from a julian day.
void setJulian (unsigned d)
 Sets the Date to a julian day.
unsigned julian () const
 Returns the Date as a julian day.
void set (int year, unsigned month, unsigned day)
 Sets the date to a year, month and day.
void get (int &year, unsigned &month, unsigned &day) const
 Gets the year, month and day.
unsigned day () const
 Returns the day-part of the date.
unsigned month () const
 Returns the month-part of the date.
int year () const
 Returns the year-part of the date.
unsigned dayOfWeek () const
 Return day of the week, starting with sunday (=0)
unsigned daysInMonth () const
 Returns the days of the month of the date.
unsigned dayOfYear () const
 Returns the day of the year.
bool leapYear () const
 Returns true if the date is in a leap year.
Dateoperator= (const Date &date)
 Assignment operator.
Dateoperator+= (int days)
 Add days to the date.
Dateoperator-= (int days)
 Subtract days from the date.
Dateoperator++ ()
 Increments the date by one day.
Dateoperator-- ()
 Decrements the date by one day.
bool operator== (const Date &date) const
 Returns true if the dates are equal.
bool operator!= (const Date &date) const
 Returns true if the dates are not equal.
bool operator< (const Date &date) const
 Less-than comparison operator.
bool operator<= (const Date &date) const
 Less-than-equal comparison operator.
bool operator> (const Date &date) const
 Greater-than comparison operator.
bool operator>= (const Date &date) const
 Greater-than-equal comparison operator.
std::string toString (const std::string &fmt="%Y-%m-%d") const
 format Date into a string using a format string
std::string toIsoString () const
 Returns the date in ISO-format.

Static Public Member Functions

static Date fromIsoString (const std::string &s)
 Interprets a string as a date-string in ISO-format.
static bool isValid (int y, int m, int d)
 Returns true if values describe a valid date.
static bool leapYear (int year)
 Returns true if the year is in a leap year.

Static Public Attributes

static const unsigned DaysPerYear = 365
 The number of days of an ordinary year.
static const unsigned DaysPerLeapYear = 366
 The number of days of a leap year.
static const unsigned DaysOfJan = 31
 The number of days of a January.
static const unsigned DaysOfFeb = 28
 The number of days of a February.
static const unsigned DaysOfLeapFeb = 29
 The number of days of a February in a leap year.
static const unsigned DaysOfMar = 31
 The number of days of a March.
static const unsigned DaysOfApr = 30
 The number of days of a April.
static const unsigned DaysOfMay = 31
 The number of days of a May.
static const unsigned DaysOfJun = 30
 The number of days of a June.
static const unsigned DaysOfJul = 31
 The number of days of a July.
static const unsigned DaysOfAug = 31
 The number of days of a August.
static const unsigned DaysOfSep = 30
 The number of days of a September.
static const unsigned DaysOfOct = 31
 The number of days of a October.
static const unsigned DaysOfNov = 30
 The number of days of a November.
static const unsigned DaysOfDec = 31
 The number of days of a December.

Friends

Date operator+ (const Date &d, int days)
Date operator+ (int days, const Date &d)
Days operator- (const Date &a, const Date &b)

Detailed Description

Date expressed in year, month, and day

Member Enumeration Documentation

Enumerator:
Jan 
Feb 
Mar 
Apr 
May 
Jun 
Jul 
Aug 
Sep 
Oct 
Nov 
Dec 
Enumerator:
Sun 
Mon 
Tue 
Wed 
Thu 
Fri 
Sat 

Constructor & Destructor Documentation

cxxtools::Date::Date ( )
inline

Default constructor.

The default constructed date is undefined.

cxxtools::Date::Date ( const std::string &  d,
const std::string &  fmt = "%Y-%m-%d" 
)
explicit

create Date from string using format

Valid format codes are:

Y 4 digit year y 2 digit year m month (1-12) %2m month (01-12) d day (1-31) %2d day (01-31) ? arbitrary character skip non digit characters

cxxtools::Date::Date ( int  y,
unsigned  m,
unsigned  d 
)
inline

Constructs a Date from given values.

Sets the date to a new year, month and day. InvalidDate is thrown if any of the values is out of range

cxxtools::Date::Date ( unsigned  julianDays)
inlineexplicit

Constructs a Date from a julian day.

Member Function Documentation

unsigned cxxtools::Date::day ( ) const
inline

Returns the day-part of the date.

unsigned cxxtools::Date::dayOfWeek ( ) const
inline

Return day of the week, starting with sunday (=0)

unsigned cxxtools::Date::dayOfYear ( ) const
inline

Returns the day of the year.

unsigned cxxtools::Date::daysInMonth ( ) const
inline

Returns the days of the month of the date.

static Date cxxtools::Date::fromIsoString ( const std::string &  s)
inlinestatic

Interprets a string as a date-string in ISO-format.

Interprets a string as a date-string in ISO-format (yyyy-mm-dd) and returns a Date-object. When the string is not in ISO-format, an exception is thrown.

Parameters
sIso formated date string.
Returns
Date result
Exceptions
IllegalArgument
void cxxtools::Date::get ( int &  year,
unsigned &  month,
unsigned &  day 
) const
inline

Gets the year, month and day.

static bool cxxtools::Date::isValid ( int  y,
int  m,
int  d 
)
static

Returns true if values describe a valid date.

unsigned cxxtools::Date::julian ( ) const
inline

Returns the Date as a julian day.

bool cxxtools::Date::leapYear ( ) const
inline

Returns true if the date is in a leap year.

bool cxxtools::Date::leapYear ( int  year)
inlinestatic

Returns true if the year is in a leap year.

unsigned cxxtools::Date::month ( ) const
inline

Returns the month-part of the date.

bool cxxtools::Date::operator!= ( const Date date) const
inline

Returns true if the dates are not equal.

Date& cxxtools::Date::operator++ ( )
inline

Increments the date by one day.

Date& cxxtools::Date::operator+= ( int  days)
inline

Add days to the date.

Date& cxxtools::Date::operator-- ( )
inline

Decrements the date by one day.

Date& cxxtools::Date::operator-= ( int  days)
inline

Subtract days from the date.

bool cxxtools::Date::operator< ( const Date date) const
inline

Less-than comparison operator.

bool cxxtools::Date::operator<= ( const Date date) const
inline

Less-than-equal comparison operator.

Date& cxxtools::Date::operator= ( const Date date)
inline

Assignment operator.

bool cxxtools::Date::operator== ( const Date date) const
inline

Returns true if the dates are equal.

bool cxxtools::Date::operator> ( const Date date) const
inline

Greater-than comparison operator.

bool cxxtools::Date::operator>= ( const Date date) const
inline

Greater-than-equal comparison operator.

void cxxtools::Date::set ( int  year,
unsigned  month,
unsigned  day 
)
inline

Sets the date to a year, month and day.

Sets the date to a new year, month and day. InvalidDate is thrown if any of the values is out of range

void cxxtools::Date::setJulian ( unsigned  d)
inline

Sets the Date to a julian day.

std::string cxxtools::Date::toIsoString ( ) const
inline

Returns the date in ISO-format.

Converts the date in ISO-format (yyyy-mm-dd).

Returns
Date as iso formated string.
std::string cxxtools::Date::toString ( const std::string &  fmt = "%Y-%m-%d") const

format Date into a string using a format string

Valid format codes are:

d day (01-31) %1d day (1-31) m month (01-12) %1m month (1-12) Y 4 digit year y 2 digit year w day of week (0-6 sunday=6) W day of week (1-7 sunday=7)

int cxxtools::Date::year ( ) const
inline

Returns the year-part of the date.

Friends And Related Function Documentation

Date operator+ ( const Date d,
int  days 
)
friend
Date operator+ ( int  days,
const Date d 
)
friend
Days operator- ( const Date a,
const Date b 
)
friend

Member Data Documentation

const unsigned cxxtools::Date::DaysOfApr = 30
static

The number of days of a April.

const unsigned cxxtools::Date::DaysOfAug = 31
static

The number of days of a August.

const unsigned cxxtools::Date::DaysOfDec = 31
static

The number of days of a December.

const unsigned cxxtools::Date::DaysOfFeb = 28
static

The number of days of a February.

const unsigned cxxtools::Date::DaysOfJan = 31
static

The number of days of a January.

const unsigned cxxtools::Date::DaysOfJul = 31
static

The number of days of a July.

const unsigned cxxtools::Date::DaysOfJun = 30
static

The number of days of a June.

const unsigned cxxtools::Date::DaysOfLeapFeb = 29
static

The number of days of a February in a leap year.

const unsigned cxxtools::Date::DaysOfMar = 31
static

The number of days of a March.

const unsigned cxxtools::Date::DaysOfMay = 31
static

The number of days of a May.

const unsigned cxxtools::Date::DaysOfNov = 30
static

The number of days of a November.

const unsigned cxxtools::Date::DaysOfOct = 31
static

The number of days of a October.

const unsigned cxxtools::Date::DaysOfSep = 30
static

The number of days of a September.

const unsigned cxxtools::Date::DaysPerLeapYear = 366
static

The number of days of a leap year.

const unsigned cxxtools::Date::DaysPerYear = 365
static

The number of days of an ordinary year.


The documentation for this class was generated from the following file:
  • include/tntdb/cxxtools/date.h