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

tiempo.hpp

Go to the documentation of this file.
00001 #ifndef TIEMPO_H
00002 #define TIEMPO_H
00003 
00004 #include <time.h>
00005 #include <string>
00006 
00007 namespace UTIL
00008 {
00009 
00011 // DifTiempo and Tiempo
00012 
00013 class DifTiempo
00014 {
00015 public:
00016 
00017         DifTiempo(time_t time)
00018                 {
00019                         m_timeSpan = time ; 
00020                 }
00021         DifTiempo(long lDays, int nHours , int nMins , int nSecs )      
00022                 { 
00023                         m_timeSpan = nSecs + 60* (nMins + 60* (nHours + 24* lDays)); 
00024                 }
00025         DifTiempo(const DifTiempo& timeSpanSrc)
00026                 {
00027                         m_timeSpan = timeSpanSrc.m_timeSpan; 
00028                 }
00029         const DifTiempo& operator=(const DifTiempo& timeSpanSrc)
00030                 {
00031                         m_timeSpan = timeSpanSrc.m_timeSpan; return *this;
00032                 }
00033 // Attributes
00034         // extract parts
00035         long GetDays() const 
00036         {
00037                 return m_timeSpan / (24*3600L); 
00038         }
00039         long GetTotalHours() const
00040         { 
00041                 return m_timeSpan/3600; 
00042         }
00043         int GetHours() const
00044         { 
00045                 return (int)(GetTotalHours() - GetDays()*24); 
00046         }
00047         long GetTotalMinutes() const
00048         {
00049                 return m_timeSpan/60;
00050         }
00051         int GetMinutes() const
00052         {
00053                 return (int)(GetTotalMinutes() - GetTotalHours()*60); 
00054         }
00055         long GetTotalSeconds() const
00056         { 
00057                 return m_timeSpan; 
00058         }
00059         int GetSeconds() const
00060         { 
00061                 return (int)(GetTotalSeconds() - GetTotalMinutes()*60); 
00062         }
00063         DifTiempo operator-(DifTiempo timeSpan) const
00064         { 
00065                 return DifTiempo(m_timeSpan - timeSpan.m_timeSpan); 
00066         }
00067 
00068         DifTiempo operator+(DifTiempo timeSpan) const
00069         { 
00070                 return DifTiempo(m_timeSpan + timeSpan.m_timeSpan); 
00071         }
00072         const DifTiempo& operator+=(DifTiempo timeSpan)
00073         { 
00074                  m_timeSpan += timeSpan.m_timeSpan; return *this; 
00075         }
00076         const DifTiempo& operator-=(DifTiempo timeSpan)
00077         { 
00078                 m_timeSpan -= timeSpan.m_timeSpan; return *this; 
00079         }
00080         bool operator==(DifTiempo timeSpan) const
00081         { 
00082                 return m_timeSpan == timeSpan.m_timeSpan; 
00083         }
00084         bool operator!=(DifTiempo timeSpan) const
00085         { 
00086                 return m_timeSpan != timeSpan.m_timeSpan; 
00087         }
00088         bool  operator<(DifTiempo timeSpan) const
00089         { 
00090                 return m_timeSpan < timeSpan.m_timeSpan; 
00091         }
00092         bool operator>(DifTiempo timeSpan) const
00093         { 
00094                 return m_timeSpan > timeSpan.m_timeSpan; 
00095         }
00096         bool operator<=(DifTiempo timeSpan) const
00097         { 
00098                 return m_timeSpan <= timeSpan.m_timeSpan; 
00099         }
00100         bool operator>=(DifTiempo timeSpan) const
00101         { 
00102                 return m_timeSpan >= timeSpan.m_timeSpan; 
00103         }
00104         std::string Format(char *pFormat) const;
00105 
00106 private:
00107         time_t m_timeSpan;
00108         friend class Tiempo;
00109 };
00110 
00111 //-----------------------------------------------------------------------------
00112 
00113 class Tiempo
00114 {
00115 public:
00116 
00117  Tiempo()
00118         { 
00119         }
00120 
00121  Tiempo(int nYear, int nMonth, int nDay, int nHour=0, int nMin=0, int nSec=0);
00122 
00123  Tiempo(time_t time)
00124         { 
00125                 m_time = time; 
00126         }
00127   Tiempo(struct tm * ptm)
00128         { 
00129                 if (!ptm) m_time = mktime (ptm); 
00130         }
00131 
00132  Tiempo(const Tiempo& timeSrc)
00133         { 
00134                 m_time = timeSrc.m_time; 
00135         }
00136  const Tiempo& operator=(const Tiempo& timeSrc)
00137         { 
00138                 m_time = timeSrc.m_time; return *this; 
00139         }
00140  const Tiempo& operator=(time_t t)
00141         { 
00142                 m_time = t; return *this; 
00143         }
00144  time_t GetTime() const
00145         { 
00146                 return m_time; 
00147         }
00148  int GetYear() const
00149         { 
00150                 return localtime(&m_time)->tm_year + 1900; 
00151         }
00152  int GetMonth() const
00153         { 
00154                 return localtime(&m_time)->tm_mon + 1; 
00155         }
00156  int GetDay() const
00157         { 
00158                 return localtime(&m_time)->tm_mday; 
00159         }
00160  int GetHour() const
00161         { 
00162                 return localtime(&m_time)->tm_hour; 
00163         }
00164  int GetMinute() const
00165         { 
00166                 return localtime(&m_time)->tm_min; 
00167         }
00168  int GetSecond() const
00169         { 
00170                 return localtime(&m_time)->tm_sec; 
00171         }
00172  int GetDayOfWeek() const
00173         { 
00174                 return localtime(&m_time)->tm_wday + 1; 
00175         }
00176 
00177  int GetMinutesFromMidnight()
00178   {
00179      return GetHour() * 60 + GetMinute();
00180   }
00181 
00182  DifTiempo operator-(Tiempo time) const
00183         { 
00184                 return DifTiempo(m_time - time.m_time); 
00185         }
00186  Tiempo operator-(DifTiempo timeSpan) const
00187         { 
00188                 return Tiempo(m_time - timeSpan.m_timeSpan); 
00189         }
00190  Tiempo operator-(long day) const
00191         { 
00192          return Tiempo::operator-(DifTiempo(day,0,0,0)); 
00193         }
00194 
00195  Tiempo operator+(DifTiempo timeSpan) const
00196         { 
00197                 return Tiempo(m_time + timeSpan.m_timeSpan); 
00198         }
00199  Tiempo operator+(long day) const
00200         { 
00201          return Tiempo::operator+(DifTiempo(day,0,0,0)); 
00202         }
00203 
00204  const Tiempo& operator+=(DifTiempo timeSpan)
00205         { 
00206                 m_time += timeSpan.m_timeSpan; return *this; 
00207         }
00208  const Tiempo& operator-=(DifTiempo timeSpan)
00209         { 
00210                 m_time -= timeSpan.m_timeSpan; return *this; 
00211         }
00212  bool operator==(Tiempo time) const
00213         { 
00214                 return m_time == time.m_time; 
00215         }
00216  bool operator!=(Tiempo time) const
00217         { 
00218                 return m_time != time.m_time; 
00219         }
00220  bool operator<(Tiempo time) const
00221         { 
00222                 return m_time < time.m_time; 
00223         }
00224  bool operator>(Tiempo time) const
00225         { 
00226                 return m_time > time.m_time; 
00227         }
00228  bool operator<=(Tiempo time) const
00229         { 
00230                 return m_time <= time.m_time; 
00231         }
00232  bool operator>=(Tiempo time) const
00233         { 
00234                 return m_time >= time.m_time; 
00235         }
00236 
00237         friend time_t Ahora();
00238         
00239         friend time_t AhoraGmt0();
00240 
00241 // Attributes
00242 
00243 // Operations
00244 
00245         // formatting using "C" strftime
00246         std::string Format(void) const;
00247 
00248 protected:
00249         time_t m_time;
00250 };
00251 
00252 } /* TIEMPO */
00253 
00254 #endif
00255 

Generated on Wed Mar 5 21:31:47 2003 for JIC by doxygen1.3-rc3