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

Date.hxx

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

Generated on Wed Apr 25 11:18:06 2007 for Talos by  doxygen 1.4.2