(file) Return to datetime.h CVS log (file) (dir) Up to [OMI] / omi / micxx

  1 mike  1.1 /*
  2           **==============================================================================
  3           **
  4           ** Open Management Infrastructure (OMI)
  5           **
  6           ** Copyright (c) Microsoft Corporation
  7           ** 
  8           ** Licensed under the Apache License, Version 2.0 (the "License"); you may not 
  9           ** use this file except in compliance with the License. You may obtain a copy 
 10           ** of the License at 
 11           **
 12           **     http://www.apache.org/licenses/LICENSE-2.0 
 13           **
 14           ** THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15           ** KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 
 16           ** WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 
 17           ** MERCHANTABLITY OR NON-INFRINGEMENT. 
 18           **
 19           ** See the Apache 2 License for the specific language governing permissions 
 20           ** and limitations under the License.
 21           **
 22 mike  1.1 **==============================================================================
 23           */
 24           
 25           #ifndef _micxx_datetime_h
 26           #define _micxx_datetime_h
 27           
 28           #include <MI.h>
 29           #include <string.h>
 30           #include <stdio.h>
 31           #include "linkage.h"
 32           
 33           MI_BEGIN_NAMESPACE
 34           
 35           class MICXX_LINKAGE Datetime
 36           {
 37           public:
 38           
 39               // Default constructor (initializes the zero-interval).
 40               Datetime();
 41           
 42               // Initialize from MI_Datetime.
 43 mike  1.1     Datetime(const MI_Datetime& x);
 44           
 45               // Initialize a timestamp:
 46               Datetime(
 47                   MI_Uint32 year,
 48                   MI_Uint32 month,
 49                   MI_Uint32 day,
 50                   MI_Uint32 hour,
 51                   MI_Uint32 minute,
 52                   MI_Uint32 second,
 53                   MI_Uint32 microseconds,
 54                   MI_Sint32 utc);
 55           
 56               // Initialize an interval:
 57               Datetime(
 58                   MI_Uint32 days,
 59                   MI_Uint32 hours,
 60                   MI_Uint32 minutes,
 61                   MI_Uint32 seconds,
 62                   MI_Uint32 microseconds);
 63           
 64 mike  1.1     // Copy constructor.
 65               Datetime(const Datetime& x);
 66           
 67               // Assignment operator.
 68               Datetime& operator=(const Datetime& x);
 69           
 70               // Destructor.
 71               ~Datetime();
 72           
 73               // Get reference to representation:
 74               const MI_Datetime& GetData() const;
 75           
 76               // Return true if a timestamp.
 77               bool IsTimestamp() const;
 78           
 79               // Clear (to zero interval)
 80               void Clear();
 81           
 82               // Set timestamp:
 83               bool Set(
 84                   MI_Uint32 year,
 85 mike  1.1         MI_Uint32 month,
 86                   MI_Uint32 day,
 87                   MI_Uint32 hour,
 88                   MI_Uint32 minute,
 89                   MI_Uint32 second,
 90                   MI_Uint32 microseconds,
 91                   MI_Sint32 utc);
 92           
 93               // Set interval:
 94               bool Set(
 95                   MI_Uint32 days,
 96                   MI_Uint32 hours,
 97                   MI_Uint32 minutes,
 98                   MI_Uint32 seconds,
 99                   MI_Uint32 microseconds);
100           
101               // Set form a string:
102               bool Set(const MI_Char* str);
103           
104               // Set to timestamp for current date and time.
105               bool SetCurrent();
106 mike  1.1 
107               // Get timestamp (return false if not a timestamp)
108               bool Get(
109                   MI_Uint32& year,
110                   MI_Uint32& month,
111                   MI_Uint32& day,
112                   MI_Uint32& hour,
113                   MI_Uint32& minute,
114                   MI_Uint32& second,
115                   MI_Uint32& microseconds,
116                   MI_Sint32& utc) const;
117           
118               // Get interval (return false if not a interval)
119               bool Get(
120                   MI_Uint32& days,
121                   MI_Uint32& hours,
122                   MI_Uint32& minutes,
123                   MI_Uint32& seconds,
124                   MI_Uint32& microseconds) const;
125           
126               // Convert to string.
127 mike  1.1     void ToString(MI_Char buffer[26]) const;
128           
129               // Return true if the two objects are equivalent.
130               bool Equal(const Datetime& x) const;
131           
132               // Print the datetime to the given output stream.
133               void Print(FILE* os = stdout) const;
134           
135               // Get datetime object with current time.
136               static Datetime Now();
137           
138           private:
139               MI_Datetime _rep;
140           };
141           
142           inline Datetime::Datetime()
143           {
144               memset(&_rep, 0, sizeof(_rep));
145           }
146           
147           inline Datetime::Datetime(const MI_Datetime& x)
148 mike  1.1 {
149               memcpy(&_rep, &x, sizeof(MI_Datetime));
150           }
151           
152           inline Datetime::Datetime(const Datetime& x)
153           {
154               memcpy(&_rep, &x._rep, sizeof(_rep));
155           }
156           
157           inline Datetime& Datetime::operator=(const Datetime& x)
158           {
159               if (this != &x)
160                   memcpy(&_rep, &x._rep, sizeof(_rep));
161           
162               return *this;
163           }
164           
165           inline Datetime::~Datetime()
166           {
167           }
168           
169 mike  1.1 inline bool Datetime::IsTimestamp() const
170           {
171               return _rep.isTimestamp ? true : false;
172           }
173           
174           inline void Datetime::Clear()
175           {
176               memset(&_rep, 0, sizeof(_rep));
177           }
178           
179           inline const MI_Datetime& Datetime::GetData() const 
180           {
181               return _rep; 
182           }
183           
184           inline bool operator==(const Datetime& x, const Datetime& y)
185           {
186               return x.Equal(y);
187           }
188           
189           inline bool operator!=(const Datetime& x, const Datetime& y)
190 mike  1.1 {
191               return !x.Equal(y);
192           }
193           
194           MI_END_NAMESPACE
195           
196           #endif /* _micxx_datetime_h */

ViewCVS 0.9.2