Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

CascadeTime.h

Go to the documentation of this file.
00001 //
00002 // CascadeTime.h - header file for class CascadeTime
00003 //
00004 // Copyright (c) 2002, Roku, LLC.  All rights reserved.
00005 //
00008 
00009 #ifndef _ROKU_INCLUDE_CASCADE_UTIL_CASCADETIME_H
00010 #define _ROKU_INCLUDE_CASCADE_UTIL_CASCADETIME_H
00011 
00012 #include <cascade/CascadeObject.h>
00013 #include <cascade/util/CascadeString.h>
00014 
00026 class CascadeTime : public CascadeObject
00027 {
00028 #ifndef DOXY_SKIP
00029 public:
00030     struct DateStruct;
00031 #endif
00032 
00033 public:
00034         CascadeTime();
00035         CascadeTime(const CascadeTime & that);
00036         CascadeTime(const DateStruct & dateStruct);
00037         virtual ~CascadeTime();
00038         
00039 public:
00040     struct TimeBase
00041     {
00042     public:
00043         u64 m_nUptimeNanoseconds;
00044         u64 m_nGMTNanosecondOffsetFrom1970;
00045     };
00046     
00047     struct DateStruct
00048     {
00049     public:
00050         u16 m_nYear;
00051         u16 m_nMonth;
00052         u16 m_nDay;
00053         u16 m_nHour;
00054         u16 m_nMinute;
00055         u16 m_nSecond;
00056         u16 m_nMilliseconds;
00057         u16 m_nWeekday;
00058     };
00059     
00060     struct TimeZone
00061     {
00062     public:
00063         const char * m_pZoneID;
00064         const char * m_pZoneData;
00065         const char * m_pAbbreviationSTD;
00066         const char * m_pAbbreviationDST;
00067         const char * m_pNameSTD;
00068         const char * m_pNameDST;
00069         const char * m_pNameGeneric;
00070         const char * m_pOlsonReferent;
00071         const char * m_pDescription;
00072     };
00073     
00074 public:
00075     static u64 GetUptimeMilliseconds();
00076         // returns the number of milliseconds elapsed since system boot
00077     static u64 GetUptimeNanoseconds();
00078         // returns the number of nanoseconds elapsed since system boot
00079         
00080     static void GetSystemClockTimeBase(TimeBase & timeBaseToSet);
00081         // This is the time base the system clock is based on.
00082         // It tells you what the uptime was the last time the system clock
00083         // was set, and what the GMT was the last time the system clock was set
00084         // All time functions are based on this system clock time base.
00085         // NOTE: This time base doesn't actually tell you 'when' the system clock
00086         // what set, but rather the timebase (GMT + uptime) used to set the system clock.
00087     static bool SetSystemClockTimeBase(const TimeBase & timeBase);
00088         // Sets the system clock time base
00089     static void GetPresentTimeBase(TimeBase & timeBaseToSet);
00090         // sets timeBaseToSet with a time base containing the current uptime and
00091         // the current GMT calculated using the current uptime and the system clock time base
00092     static bool SetSystemTimeGMT(const u64 & nGMTNanosecondOffsetFrom1970);
00093         // makes a timebase with the current uptime and this GMT value passed in and
00094         // sets the system clock time base with it
00095     static void GetSystemTimeZoneID(CascadeString & timeZoneIDToSet);
00096     static bool SetSystemTimeZoneID(const char * pTimeZoneID);
00097     static bool GetTimeZoneFromID(const char * pTimeZoneID, TimeZone & timeZoneToSet);
00098     typedef bool (TimeZoneEnumProc)(const TimeZone & timeZone, void * pClientData);
00099     static bool EnumerateTimeZones(TimeZoneEnumProc * pEnumProc, void * pClientData);
00100 
00101 protected:
00102     u64 m_nNanoseconds;
00103     
00104 public:
00105     void GetTimeGMT();
00106     bool GetTimeLocal(const char * pTimeZoneID = NULL);
00107         
00108     bool GMT2Local(const char * pTimeZoneID = NULL);
00109     bool Local2GMT(const char * pTimeZoneID = NULL);
00110 
00111     void GetDateStruct(DateStruct & dateStructToSet) const;
00112     bool SetDateStruct(const DateStruct & dateStruct);
00113     
00114     bool IsDaylightSavingsTime(const char * pTimeZoneID = NULL) const;
00115         // this must represent a local time in the time zone represented
00116         // by pTimeZoneID
00117     
00118     inline u64  GetSeconds() const                         { return (m_nNanoseconds / (u64)1000000000); }
00119     inline u64  GetMilliseconds() const                    { return (m_nNanoseconds / (u64)1000000); }
00120     inline u64  GetMicroseconds() const                    { return (m_nNanoseconds / (u64)1000); }
00121     inline u64  GetNanoseconds() const                     { return m_nNanoseconds; }
00122     inline void SetSeconds(u64 nSeconds)                   { SetNanoseconds(nSeconds * (u64)1000000000); }
00123     inline void SetMilliseconds(u64 nMilliseconds)         { SetNanoseconds(nMilliseconds * (u64)1000000); }
00124     inline void SetMicroseconds(u64 nMicroseconds)         { SetNanoseconds(nMicroseconds * (u64)1000); }
00125     inline void SetNanoseconds(u64 nNanoseconds)           { m_nNanoseconds = nNanoseconds; }
00126     inline void AddSeconds(u64 nSeconds)                   { AddNanoseconds(nSeconds * (u64)1000000000); }
00127     inline void AddMilliseconds(u64 nMilliseconds)         { AddNanoseconds(nMilliseconds * (u64)1000000); }
00128     inline void AddMicroseconds(u64 nMicroseconds)         { AddNanoseconds(nMicroseconds * (u64)1000); }
00129     inline void AddNanoseconds(u64 nNanoSeconds)           { m_nNanoseconds += nNanoSeconds; }
00130     inline void SubtractSeconds(u64 nSeconds)              { SubtractNanoseconds(nSeconds * (u64)1000000000); }
00131     inline void SubtractMilliseconds(u64 nMilliseconds)    { SubtractNanoseconds(nMilliseconds * (u64)1000000); }
00132     inline void SubtractMicroseconds(u64 nMicroseconds)    { SubtractNanoseconds(nMicroseconds * (u64)1000); }
00133     inline void SubtractNanoseconds(u64 nNanoseconds)      { if (nNanoseconds <= m_nNanoseconds) m_nNanoseconds -= nNanoseconds; else m_nNanoseconds = 0; }
00134     inline bool operator < (const CascadeTime & that) const { return m_nNanoseconds < that.m_nNanoseconds; }
00135     inline bool operator > (const CascadeTime & that) const { return m_nNanoseconds > that.m_nNanoseconds; }
00136     inline bool operator <= (const CascadeTime & that) const { return m_nNanoseconds <= that.m_nNanoseconds; }
00137     inline bool operator >= (const CascadeTime & that) const { return m_nNanoseconds >= that.m_nNanoseconds; }
00138     inline bool operator == (const CascadeTime & that) const { return m_nNanoseconds == that.m_nNanoseconds; }
00139 };
00140 
00141 #endif // #ifndef _ROKU_INCLUDE_CASCADE_CASCADETIME_H
00142 
00144 //  LOG
00146 //  20-Dec-02   dwoodward       created
00147 //  20-Jan-03   dwoodward       1.0 STATUS: about 50% complete - needs functions
00148 //                          and operators
00149 //  08-Mar-04   dwoodward   will I ever implement this class? Enquiring minds want to know.
00150 //                          added GetUptimeMilliseconds() and GetUptimeNanoseconds()
00151 //  27-Mar-05   dwoodward   changed GetUptimeMilliseconds to return a u64
00152 //  18-May-05   dwoodward   enquiring minds should now be satisfied
00153 //  01-Jun-05   dwoodward   updated struct TimeZone
00154 

Generated on Sun Jul 24 14:27:17 2005 for Cascade Library by  doxygen 1.4.1