Main Page | User's Guide | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members

Date.hxx

00001 // Copyright (C) 2004-2007, Vivien Mallet
00002 //
00003 // This file is part of Talos library, which provides miscellaneous tools to
00004 // make up for C++ lacks and to ease C++ programming.
00005 //
00006 // Talos is free software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the Free Software
00008 // Foundation; either version 2 of the License, or (at your option) any later
00009 // version.
00010 //
00011 // Talos is distributed in the hope that it will be useful, but WITHOUT ANY
00012 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00013 // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
00014 // details.
00015 //
00016 // For more information, visit the Talos home page:
00017 //     http://vivienmallet.net/lib/talos/
00018 
00019 
00020 #ifndef TALOS_FILE_DATE_HXX
00021 
00022 
00023 namespace Talos
00024 {
00025 
00027   class Date
00028   {
00029   private:
00031     int year_;
00033     int month_;
00035     int day_;
00037     int hour_;
00039     int minutes_;
00041     double seconds_;
00043     vector<int> month_lengths_;
00044 
00045     void LeapYearAdjust();
00046     bool IsValid();
00047     void Adjust();
00048 
00049   public:
00050     Date();
00051     Date(const Date& date);
00052     Date(string date);
00053     Date(int yyyymmdd);
00054     Date(int yyyy, int mm, int dd = 1,
00055          int hh = 0, int mn = 0, double sc = 0);
00056 
00057     Date& operator=(const Date&);
00058     Date& operator=(string date);
00059     void SetDate(string date);
00060     void SetDate(int yyyymmdd);
00061     void SetDate(int yyyy, int mm, int dd = 1,
00062                  int hh = 0, int mn = 0, double sc = 0);
00063 
00064     bool LeapYear(int year) const;
00065     bool LeapYear() const;
00066 
00067     int GetDate() const;
00068     
00069     string GetDate(const string& format) const;
00070     template <class T>
00071     void GetDate(const string& format, T& date) const;
00072 
00073     int GetYear() const;
00074     int GetMonth() const;
00075     int GetDay() const;
00076     int GetHour() const;
00077     int GetMinutes() const;
00078     double GetSeconds() const;
00079 
00080     void AddYears(int nb_yy);
00081     void AddMonths(int nb_mm);
00082     void AddDays(int nb_dd);
00083     void AddHours(int nb_hh);
00084     void AddMinutes(int nb_mn);
00085     void AddSeconds(double nb_sc);
00086 
00087     void SetYear(int yyyy);
00088     void SetMonth(int mm);
00089     void SetDay(int dd);
00090     void SetHour(int hh);
00091     void SetMinutes(int mn);
00092     void SetSeconds(double sc);
00093 
00094     int GetOrdinalDay() const;
00095     int GetDayNumber() const;
00096     int GetNumberOfDays() const;
00097     int GetDaysFrom(Date date) const;
00098     double GetSecondsFrom(Date date) const;
00099 
00100     int GetNumberOfHours() const;
00101     int GetNumberOfMinutes() const;
00102     double GetNumberOfSeconds() const;
00103 
00104     int GetWeekDay() const;
00105   };
00106 
00107   // Comparisons.
00108   bool operator < (const Date& first_date, const Date& second_date);
00109   bool operator <= (const Date& first_date, const Date& second_date);
00110   bool operator > (const Date& first_date, const Date& second_date);
00111   bool operator >= (const Date& first_date, const Date& second_date);
00112   bool operator == (const Date& first_date, const Date& second_date);
00113   bool operator != (const Date& first_date, const Date& second_date);
00114 
00115   // Redirection.
00116   ostream& operator << (ostream& out, const Date& d);
00117 
00118 }  // namespace Talos.
00119 
00120 
00121 #define TALOS_FILE_DATE_HXX
00122 #endif

Generated on Tue Oct 23 14:06:14 2007 for Talos by  doxygen 1.4.2