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 #include <iostream>
00024 #include <algorithm>
00025 #include <string>
00026 #include <fstream>
00027 #include <sstream>
00028 #include <vector>
00029 #include <stdexcept>
00030 
00031 
00032 namespace Talos
00033 {
00034 
00035   using namespace std;
00036 
00038   class Date
00039   {
00040   private:
00042     int year_;
00044     int month_;
00046     int day_;
00048     int hour_;
00050     int minutes_;
00052     double seconds_;
00054     vector<int> month_lengths_;
00055 
00056     void LeapYearAdjust();
00057     bool IsValid();
00058     void Adjust();
00059 
00060   public:
00061     Date();
00062     Date(const Date& date);
00063     Date(string date);
00064     Date(int yyyymmdd);
00065     Date(int yyyy, int mm, int dd = 1,
00066          int hh = 0, int mn = 0, double sc = 0);
00067 
00068 #ifndef SWIG
00069     Date& operator=(const Date&);
00070     Date& operator=(string date);
00071 #endif
00072     void SetDate(string date);
00073     void SetDate(int yyyymmdd);
00074     void SetDate(int yyyy, int mm, int dd = 1,
00075                  int hh = 0, int mn = 0, double sc = 0);
00076 
00077     bool LeapYear(int year) const;
00078     bool LeapYear() const;
00079 
00080     int GetDate() const;
00081     
00082     string GetDate(const string& format) const;
00083     template <class T>
00084     void GetDate(const string& format, T& date) const;
00085 
00086     int GetYear() const;
00087     int GetMonth() const;
00088     int GetDay() const;
00089     int GetHour() const;
00090     int GetMinutes() const;
00091     double GetSeconds() const;
00092 
00093     void AddYears(int nb_yy);
00094     void AddMonths(int nb_mm);
00095     void AddDays(int nb_dd);
00096     void AddHours(int nb_hh);
00097     void AddMinutes(int nb_mn);
00098     void AddSeconds(double nb_sc);
00099 
00100     void SetYear(int yyyy);
00101     void SetMonth(int mm);
00102     void SetDay(int dd);
00103     void SetHour(int hh);
00104     void SetMinutes(int mn);
00105     void SetSeconds(double sc);
00106 
00107     int GetOrdinalDay() const;
00108     int GetDayNumber() const;
00109     int GetNumberOfDays() const;
00110     int GetDaysFrom(Date date) const;
00111     double GetSecondsFrom(Date date) const;
00112 
00113     int GetNumberOfHours() const;
00114     int GetNumberOfMinutes() const;
00115     double GetNumberOfSeconds() const;
00116 
00117     int GetWeekDay() const;
00118   };
00119 
00120   // Comparisons.
00121   bool operator < (const Date& first_date, const Date& second_date);
00122   bool operator <= (const Date& first_date, const Date& second_date);
00123   bool operator > (const Date& first_date, const Date& second_date);
00124   bool operator >= (const Date& first_date, const Date& second_date);
00125   bool operator == (const Date& first_date, const Date& second_date);
00126   bool operator != (const Date& first_date, const Date& second_date);
00127 
00128 #ifndef SWIG
00129   // Redirection.
00130   ostream& operator << (ostream& out, const Date& d);
00131 #endif
00132 
00133 }  // namespace Talos.
00134 
00135 
00136 #define TALOS_FILE_DATE_HXX
00137 #endif

Generated on Mon Nov 17 18:20:41 2008 for Talos by  doxygen 1.5.1