Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Date.h

Go to the documentation of this file.
00001 //  ======================================================================== //
00002 //                                                                           //
00003 //    File      : Date.h                                                     //
00004 //    Purpose   :                                                            //
00005 //    Time-stamp: <Wed Dec/26/2001 14:02 MET Coder@ReallySoft.de>            //
00006 //                                                                           //
00007 //    (C) December 2001 by Ralf Westram                                      //
00008 //                                                                           //
00009 //    Permission to use, copy, modify, distribute and sell this software     //
00010 //    and its documentation for any purpose is hereby granted without fee,   //
00011 //    provided that the above copyright notice appear in all copies and      //
00012 //    that both that copyright notice and this permission notice appear      //
00013 //    in supporting documentation.                                           //
00014 //                                                                           //
00015 //    Ralf Westram makes no representations about the suitability of this    //
00016 //    software for any purpose.  It is provided "as is" without express or   //
00017 //    implied warranty.                                                      //
00018 //                                                                           //
00019 //  ======================================================================== //
00020 
00021 #ifndef DATE_H
00022 #define DATE_H
00023 
00024 #ifndef CTIME
00025 #include <ctime>
00026 #endif
00027 
00028 namespace rs {
00029 
00032     namespace date {
00033 
00034         // --------------------
00035         //      class Date
00036         // --------------------
00038         class Date {
00039         private:
00040             std::time_t time;
00041             std::tm     date;
00042             bool        valid;
00043 
00044             void init(const std::time_t& time_);
00045             void init(const std::tm& date_);
00046             void init(int day, int month, int year);
00047 
00048             void correct();
00049 
00050         public:
00052             Date() { std::time(&time); init(time); }
00053 
00055             Date(int day_, int month_, int year_) { init(day_, month_, year_); }
00056 
00058             Date(const std::tm& date_) { init(date_); }
00059 
00061             Date(const Date& other) {
00062                 time  = other.time;
00063                 date  = other.date;
00064                 valid = other.valid;
00065             }
00066 
00068             Date& operator = (const Date& other) {
00069                 if (&other != this) {
00070                     time  = other.time;
00071                     date  = other.date;
00072                     valid = other.valid;
00073                 }
00074                 return *this;
00075             }
00076 
00077             virtual ~Date() {}
00078 
00080             bool is_valid() const { return valid; }
00081 
00083             const std::tm& get_Date() const { return date; }
00084 
00086             int is_Feiertag() const;
00087 
00091             void inc(int offset = 1) { date.tm_mday += offset; correct(); }
00095             void dec(int offset = 1) { date.tm_mday -= offset; correct(); }
00096 
00098             int year() const { return get_Date().tm_year+1900; }
00100             int month() const { return get_Date().tm_mon+1; }
00102             int day() const { return get_Date().tm_mday; }
00103 
00105             int dayOfWeek() const { return get_Date().tm_wday; }
00106         };
00107 
00108         // some useful date functions :
00109 
00113         inline bool is_leap_year(int year) { return Date(29, 2, year).is_valid(); }
00114 
00118         const char *name_of_Feiertag(int feiertag_idx);
00119 
00123         bool is_catholic(int feiertag_idx);
00124 
00125     }; // end of namespace date
00126 }; // end of namespace rs
00127 
00128 #else
00129 #error Date.h included twice
00130 #endif // DATE_H
00131 

Contact me in case of errors or questions.
This documentation is powered by Doxygen.
(C) 2000-2002 Doxygen