| # Gaudi Framework, version v20r3
Generated: 24 Nov 2008

# Time.h

Go to the documentation of this file.

    00001 // $Id: Time.h,v 1.3 2006/01/25 16:02:48 hmd Exp $
    00002 #ifndef GAUDIKERNEL_TIME_H
    00003 #define GAUDIKERNEL_TIME_H 1
    00004
    00005 // Include files
    00006 //   for the architecture independent int64 definition (longlong)
    00007 #include "GaudiKernel/Kernel.h"
    00008 #include "GaudiKernel/StreamBuffer.h"
    00009 #include "GaudiKernel/GaudiException.h"
    00010
    00021 class TimeException: public GaudiException {
    00022 public:
    00023   // Standard constructor
    00024   TimeException( const std::string& Message = "unspecified exception",
    00025                  const std::string& Tag = "*Gaudi::Time*",
    00026                  const StatusCode & Code = StatusCode::FAILURE ):
    00027     GaudiException(Message,Tag,Code) {}
    00029   virtual ~TimeException() throw () {}
    00031   virtual TimeException* clone() const { return new TimeException(*this); }
    00032 };
    00033
    00034 struct tm;
    00035 # ifdef WIN32
    00036 typedef struct _FILETIME FILETIME;
    00037 # endif
    00038
    00039 namespace Gaudi {
    00040
    00041   class Time;
    00042   class TimeSpan;
    00043
    00059   class TimeSpan {
    00060     friend class Time;
    00061   public:
    00062     typedef longlong ValueType;
    00063
    00064     TimeSpan (void);
    00065     TimeSpan (Time t);
    00066     TimeSpan (ValueType nsecs);
    00067     TimeSpan (ValueType secs, int nsecs);
    00068     TimeSpan (int days, int hours, int mins, int secs, int nsecs);
    00069
    00070     int  days (void) const;
    00071     int  hours (void) const;
    00072     int  minutes (void) const;
    00073     ValueType  seconds (void) const;
    00074
    00075     int  lastHours (void) const;
    00076     int  lastMinutes (void) const;
    00077     int  lastSeconds (void) const;
    00078     int  lastNSeconds (void) const;
    00079
    00080     TimeSpan &  operator+= (const TimeSpan &x);
    00081     TimeSpan &  operator-= (const TimeSpan &x);
    00082     TimeSpan &  operator*= (const TimeSpan &n);
    00083     TimeSpan &  operator/= (const TimeSpan &n);
    00084     TimeSpan &  operator%= (const TimeSpan &n);
    00085
    00086     ValueType  ns (void) const;
    00087
    00088   private:
    00089     ValueType  m_nsecs; //< The span length.
    00090   };
    00091
    00092
    00216   class Time {
    00217     friend class TimeSpan;
    00218   public:
    00219     typedef longlong ValueType;
    00220
    00222     enum Months {
    00223       January  = 0,
    00224       February = 1,
    00225       March  = 2,
    00226       April  = 3,
    00227       May  = 4,
    00228       June  = 5,
    00229       July  = 6,
    00230       August  = 7,
    00231       September = 8,
    00232       October  = 9,
    00233       November = 10,
    00234       December = 11
    00235     };
    00236
    00238     static const int SECS_PER_DAY = 86400;
    00239
    00241     static const int SECS_PER_HOUR = 3600;
    00242
    00244     static const ValueType SEC_NSECS = 1000000000;
    00245
    00246     Time (void);
    00247     Time (TimeSpan ts);
    00248     Time (ValueType nsecs);
    00249     Time (ValueType secs, int nsecs);
    00250     Time (int year, int month, int day, int hour, int min, int sec,
    00251           ValueType nsecs, bool local = true);
    00252     // implicit copy constructor
    00253     // implicit assingment operator
    00254     // implicit destructor
    00255
    00257     static Time epoch   (void);
    00259     static Time max     (void);
    00261     static Time  current (void);
    00262 # ifdef WIN32
    00263     static Time  from    (const FILETIME *systime);
    00264 # endif
    00265     static Time  build   (bool local, const tm &base, TimeSpan diff = 0);
    00266
    00267     tm   split   (bool local, int *nsecpart = 0) const;
    00268     tm   utc     (int *nsecpart = 0) const;
    00269     tm   local   (int *nsecpart = 0) const;
    00270
    00271     int       year    (bool local) const;
    00272     int       month   (bool local) const;
    00273     int       day     (bool local) const;
    00274     int       hour    (bool local) const;
    00275     int       minute  (bool local) const;
    00276     int       second  (bool local) const;
    00277     int       nsecond (void) const;
    00278     int       weekday (bool local) const;
    00279     bool      isdst   (bool local) const;
    00280
    00281     ValueType  utcoffset (int *daylight = 0) const;
    00282     const char * timezone (int *daylight = 0) const;
    00283
    00284     Time &  operator+= (const TimeSpan &x);
    00285     Time &  operator-= (const TimeSpan &x);
    00286
    00287     ValueType  ns (void) const;
    00288
    00289     std::string  format (bool local, const std::string &spec) const;
    00290     std::string  nanoformat (int minwidth = 1, int maxwidth = 9) const;
    00291
    00292     static bool  isLeap (int year);
    00293
    00294     // Conversion helpers
    00295     static unsigned toDosDate (Time time);
    00296     static Time  fromDosDate (unsigned dosDate);
    00297
    00298   private:
    00299     ValueType  m_nsecs; //< Time value as nsecs from #epoch().
    00300
    00301     inline void TimeAssert(bool cond, const std::string &msg = "time assertion failed") const {
    00302       if (!cond) throw TimeException(msg);
    00303     }
    00304
    00305   };
    00306
    00307 }
    00308
    00309 #include "GaudiKernel/Time.icpp"
    00310
    00311 #endif // GAUDIKERNEL_TIME_H