Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

date.h

Go to the documentation of this file.
00001 #ifndef DV_DATE_H
00002 #define DV_DATE_H
00003 // $Id: date_h-source.html,v 1.1 2001/04/16 17:42:58 dvermeir Exp $
00004 #include        <sys/time.h>
00005 
00006 #include        <stdexcept>
00007 #include        <iostream>
00008 #include        <string>
00009 
00015 
00016 class DateError: public runtime_error {
00017 public:
00019   static const string NAME;
00021   DateError(const string& message): runtime_error(NAME+": "+message) {}
00022 };
00023 
00025 
00031 class Date {
00032 public:
00034   Date();
00036   Date(time_t secs);    // Date(0) is NULL date
00038   Date(unsigned int year, unsigned int month, unsigned int day, 
00039        unsigned int hrs=0, unsigned int min=0, unsigned int sec=0); 
00040 
00042 
00065   Date(const string& s) throw (DateError);
00066 
00068 
00076   string                str(const char*fmt=0) const;
00078   string                gmt(const char*fmt=0) const;
00080 
00082 
00083   unsigned short        year() const;
00085   unsigned short        month() const;
00087   unsigned short        day() const;
00089   unsigned short        hours() const;
00091   unsigned short        minutes() const;
00093   unsigned short        seconds() const;
00095   unsigned short        wday() const;
00097   unsigned short        yday() const;
00099 
00101 
00102 
00112   void  year(unsigned short yr);
00113   void  month(unsigned short mo);
00114   void  day(unsigned short day);
00115   void  hours(unsigned short hrs);
00116   void  minutes(unsigned short mins);
00117   void  seconds(unsigned short secs);
00119 
00120 
00122   long          time() const    { return time_; }
00124   void          time(long time);
00125 
00127 
00129   bool operator<(const Date& d) const   { return (time() < d.time()); }
00130   bool operator==(const Date& d) const  { return (time() == d.time()); }
00132 
00133 private:
00134   time_t                time_;  // nr of secs since Jan 1, 1970
00135 };
00136 
00137 #endif

httpstats-stage04 [ 7 April, 2001]