Back to index

nordugrid-arc-nox  1.1.0~rc6
DateTime.h
Go to the documentation of this file.
00001 // -*- indent-tabs-mode: nil -*-
00002 
00003 #ifndef ARCLIB_TIME
00004 #define ARCLIB_TIME
00005 
00006 #include <sigc++/slot.h>
00007 
00008 #include <ctime>
00009 #include <iostream>
00010 #include <string>
00011 
00012 namespace Arc {
00013 
00015   enum TimeFormat {
00016     MDSTime,       // YYYYMMDDHHMMSSZ
00017     ASCTime,       // Day Mon DD HH:MM:SS YYYY
00018     UserTime,      // YYYY-MM-DD HH:MM:SS
00019     ISOTime,       // YYYY-MM-DDTHH:MM:SS+HH:MM
00020     UTCTime,       // YYYY-MM-DDTHH:MM:SSZ
00021     RFC1123Time    // Day, DD Mon YYYY HH:MM:SS GMT
00022   };
00023 
00024   enum PeriodBase {
00025     PeriodMiliseconds,
00026     PeriodSeconds,
00027     PeriodMinutes,
00028     PeriodHours,
00029     PeriodDays,
00030     PeriodWeeks
00031   };
00032 
00033   class Period {
00034   public:
00036     Period();
00037 
00039     Period(const time_t&);
00040 
00042     Period(const std::string&, PeriodBase base = PeriodSeconds);
00043 
00045     Period& operator=(const time_t&);
00046 
00048     Period& operator=(const Period&);
00049 
00051     void SetPeriod(const time_t&);
00052 
00054     time_t GetPeriod() const;
00055 
00057     const sigc::slot<const char*>* istr() const;
00058 
00060     operator std::string() const;
00061 
00063     bool operator<(const Period&) const;
00064 
00066     bool operator>(const Period&) const;
00067 
00069     bool operator<=(const Period&) const;
00070 
00072     bool operator>=(const Period&) const;
00073 
00075     bool operator==(const Period&) const;
00076 
00078     bool operator!=(const Period&) const;
00079 
00080   private:
00082     time_t seconds;
00083 
00085     const char* IStr() const;
00086     sigc::slot<const char*> slot;
00087     std::string is;
00088   };
00089 
00091   std::ostream& operator<<(std::ostream&, const Period&);
00092 
00093 
00094 
00096   class Time {
00097   public:
00099     Time();
00100 
00102     Time(const time_t&);
00103 
00105     Time(const std::string&);
00106 
00108     Time& operator=(const time_t&);
00109 
00111     Time& operator=(const Time&);
00112 
00114     Time& operator=(const char*);
00115     
00117     Time& operator=(const std::string&);
00118 
00120     void SetTime(const time_t&);
00121 
00123     time_t GetTime() const;
00124 
00127     operator std::string() const;
00128 
00131     std::string str(const TimeFormat& = time_format) const;
00132 
00134     static void SetFormat(const TimeFormat&);
00135 
00137     static TimeFormat GetFormat();
00138 
00140     bool operator<(const Time&) const;
00141 
00143     bool operator>(const Time&) const;
00144 
00146     bool operator<=(const Time&) const;
00147 
00149     bool operator>=(const Time&) const;
00150 
00152     bool operator==(const Time&) const;
00153 
00155     bool operator!=(const Time&) const;
00156 
00158     Time operator+(const Period&) const;
00159 
00161     Time operator-(const Period&) const;
00162 
00164     Period operator-(const Time&) const;
00165 
00166     static const int YEAR  = 31536000;
00167     static const int MONTH = 2592000;
00168     static const int WEEK  = 604800;
00169     static const int DAY   = 86400;
00170     static const int HOUR  = 3600;
00171 
00172   private:
00174     time_t gtime;
00175 
00177     static TimeFormat time_format;
00178   };
00179 
00181   std::ostream& operator<<(std::ostream&, const Time&);
00182 
00184   std::string TimeStamp(const TimeFormat& = Time::GetFormat());
00185 
00187   std::string TimeStamp(Time, const TimeFormat& = Time::GetFormat());
00188 
00189 } // namespace Arc
00190 
00191 #endif // ARCLIB_TIME