Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

Dv::Util::Date Class Reference

A simple Date class. More...

#include <date.h>

List of all members.

Public Member Functions

 Date ()
 Default constructor, initializes to ``now''.
 Date (time_t secs)
 Date(time_t t) assumes that t is number of seconds since Jan 1, 1970.
 Date (unsigned int year, unsigned int month, unsigned int day, unsigned int hrs=0, unsigned int min=0, unsigned int sec=0)
 Initialize Date, note that january = 0.
 Date (const std::string &s) throw (DateError)
 The string s is parsed as a date.
std::string str (const char *fmt=0) const
 Produce a string representing the date, according to format.
std::string gmt (const char *fmt=0) const
 Like str() but formats in GMT time zone, e.g. 03:00 MET DST is 02:00 GMT.
void yday (unsigned short yday)
 Set date to date with this yday in same year.
time_t time () const
 Returns number of secs since 1/1/1970.
void time (time_t time)
 Set time.
Dateoperator+= (const Duration &)
 Add a duration to a Date.
unsigned short year () const
 Return number of years.
unsigned short month () const
 Return month of date, january = 0.
unsigned short day () const
 Return day in month (1..31).
unsigned short hours () const
 Return hour of day, between 00 and 23.
unsigned short minutes () const
 Return minutes in the hour, between 0 and 59.
unsigned short seconds () const
 Return seconds in the minute, between 0 and 59.
unsigned short wday () const
 Return weekday, sunday = 0, monday = 1, ..
unsigned short yday () const
 Return day in year, between 0 and 365.
unsigned short yweek () const
 Return number of week (0..53) in year, week 1 starts with first monday,.
void year (unsigned short yr)
 Set year, month, day-in-month, hours, minutes or seconds.
void month (unsigned short mo)
 Set year, month, day-in-month, hours, minutes or seconds.
void day (unsigned short day)
 Set year, month, day-in-month, hours, minutes or seconds.
void hours (unsigned short hrs)
 Set year, month, day-in-month, hours, minutes or seconds.
void minutes (unsigned short mins)
 Set year, month, day-in-month, hours, minutes or seconds.
void seconds (unsigned short secs)
 Set year, month, day-in-month, hours, minutes or seconds.
bool operator< (const Date &d) const
bool operator== (const Date &d) const
bool operator> (const Date &d) const
bool operator!= (const Date &d) const
bool operator>= (const Date &d) const
bool operator<= (const Date &d) const

Private Attributes

time_t time_


Detailed Description

A simple Date class.

It provides a convenient interface to system functions such as locatime_r() etc. Its only data member is a time_t value. Note that only dates since Jan 1, 1970 can be represented.

The default copy constructor and assignment operations are available.

Definition at line 36 of file date.h.


Constructor & Destructor Documentation

Dv::Util::Date::Date  ) 
 

Default constructor, initializes to ``now''.

Dv::Util::Date::Date time_t  secs  ) 
 

Date(time_t t) assumes that t is number of seconds since Jan 1, 1970.

Dv::Util::Date::Date unsigned int  year,
unsigned int  month,
unsigned int  day,
unsigned int  hrs = 0,
unsigned int  min = 0,
unsigned int  sec = 0
 

Initialize Date, note that january = 0.

Dv::Util::Date::Date const std::string &  s  )  throw (DateError)
 

The string s is parsed as a date.

This constructor uses the gnu getdate parsing function which accepts a number of formats, e.g.

	1970-09-17           # ISO 8601.
  	70-9-17              # This century assumed by default.
  	70-09-17             # Leading zeros are ignored.
  	9/17/72              # Common U.S. writing.
  	24 September 1972
  	24 Sept 72           # September has a special abbreviation.
  	24 Sep 72            # Three-letter abbreviations always allowed.
  	Sep 24, 1972
  	24-sep-72
  	24sep72

        20:02:0
        20:02
  	8:02pm
  	20:02-0500		# In EST (Eastern U.S. Standard Time)
      

and many others (see the gnu filutils documentation)


Member Function Documentation

std::string Dv::Util::Date::str const char *  fmt = 0  )  const
 

Produce a string representing the date, according to format.

The format is any string acceptable to strftime. If fmt=0, the default is "\%a \%b \%d \%H:\%M:\%S \%Y" e.g.

                "Wed Aug 12 18:38:10 1998"
The default format is acceptable to the parser.

std::string Dv::Util::Date::gmt const char *  fmt = 0  )  const
 

Like str() but formats in GMT time zone, e.g. 03:00 MET DST is 02:00 GMT.

unsigned short Dv::Util::Date::year  )  const
 

Return number of years.

Inspection functions that return a part of the Date object.

unsigned short Dv::Util::Date::month  )  const
 

Return month of date, january = 0.

unsigned short Dv::Util::Date::day  )  const
 

Return day in month (1..31).

unsigned short Dv::Util::Date::hours  )  const
 

Return hour of day, between 00 and 23.

unsigned short Dv::Util::Date::minutes  )  const
 

Return minutes in the hour, between 0 and 59.

unsigned short Dv::Util::Date::seconds  )  const
 

Return seconds in the minute, between 0 and 59.

unsigned short Dv::Util::Date::wday  )  const
 

Return weekday, sunday = 0, monday = 1, ..

unsigned short Dv::Util::Date::yday  )  const
 

Return day in year, between 0 and 365.

unsigned short Dv::Util::Date::yweek  )  const
 

Return number of week (0..53) in year, week 1 starts with first monday,.

void Dv::Util::Date::year unsigned short  yr  ) 
 

Set year, month, day-in-month, hours, minutes or seconds.

Functions that set part of the Date object. Values that are too large will be converted, e.g. to e.g. next day. E.g.

      Date d("Mon Jan 01 23:00:00 CET 2001");
      d.hours(36);
      cout<< d.str();
will print "Tue Jan 02 12:00:00 CET 2001".

void Dv::Util::Date::month unsigned short  mo  ) 
 

Set year, month, day-in-month, hours, minutes or seconds.

Functions that set part of the Date object. Values that are too large will be converted, e.g. to e.g. next day. E.g.

      Date d("Mon Jan 01 23:00:00 CET 2001");
      d.hours(36);
      cout<< d.str();
will print "Tue Jan 02 12:00:00 CET 2001".

void Dv::Util::Date::day unsigned short  day  ) 
 

Set year, month, day-in-month, hours, minutes or seconds.

Functions that set part of the Date object. Values that are too large will be converted, e.g. to e.g. next day. E.g.

      Date d("Mon Jan 01 23:00:00 CET 2001");
      d.hours(36);
      cout<< d.str();
will print "Tue Jan 02 12:00:00 CET 2001".

void Dv::Util::Date::hours unsigned short  hrs  ) 
 

Set year, month, day-in-month, hours, minutes or seconds.

Functions that set part of the Date object. Values that are too large will be converted, e.g. to e.g. next day. E.g.

      Date d("Mon Jan 01 23:00:00 CET 2001");
      d.hours(36);
      cout<< d.str();
will print "Tue Jan 02 12:00:00 CET 2001".

void Dv::Util::Date::minutes unsigned short  mins  ) 
 

Set year, month, day-in-month, hours, minutes or seconds.

Functions that set part of the Date object. Values that are too large will be converted, e.g. to e.g. next day. E.g.

      Date d("Mon Jan 01 23:00:00 CET 2001");
      d.hours(36);
      cout<< d.str();
will print "Tue Jan 02 12:00:00 CET 2001".

void Dv::Util::Date::seconds unsigned short  secs  ) 
 

Set year, month, day-in-month, hours, minutes or seconds.

Functions that set part of the Date object. Values that are too large will be converted, e.g. to e.g. next day. E.g.

      Date d("Mon Jan 01 23:00:00 CET 2001");
      d.hours(36);
      cout<< d.str();
will print "Tue Jan 02 12:00:00 CET 2001".

void Dv::Util::Date::yday unsigned short  yday  ) 
 

Set date to date with this yday in same year.

time_t Dv::Util::Date::time  )  const [inline]
 

Returns number of secs since 1/1/1970.

Definition at line 131 of file date.h.

References time_.

Referenced by operator<(), and operator==().

void Dv::Util::Date::time time_t  time  ) 
 

Set time.

bool Dv::Util::Date::operator< const Date d  )  const [inline]
 

Date comparison respects chronological order. Definition at line 138 of file date.h.

References time().

bool Dv::Util::Date::operator== const Date d  )  const [inline]
 

Date comparison respects chronological order. Definition at line 139 of file date.h.

References time().

bool Dv::Util::Date::operator> const Date d  )  const [inline]
 

Date comparison respects chronological order. Definition at line 140 of file date.h.

bool Dv::Util::Date::operator!= const Date d  )  const [inline]
 

Date comparison respects chronological order. Definition at line 141 of file date.h.

bool Dv::Util::Date::operator>= const Date d  )  const [inline]
 

Date comparison respects chronological order. Definition at line 142 of file date.h.

bool Dv::Util::Date::operator<= const Date d  )  const [inline]
 

Date comparison respects chronological order. Definition at line 143 of file date.h.

Date& Dv::Util::Date::operator+= const Duration  ) 
 

Add a duration to a Date.


Member Data Documentation

time_t Dv::Util::Date::time_ [private]
 

Definition at line 149 of file date.h.

Referenced by time().


The documentation for this class was generated from the following file:
dvutil-0.13.15 [30 December, 2004]