1 mike 1.10 //%/////////////////////////////////////////////////////////////////////////////
2 //
|
3 kumpf 1.26 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
4 // The Open Group, Tivoli Systems
|
5 mike 1.10 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 kumpf 1.26 // of this software and associated documentation files (the "Software"), to
8 // deal in the Software without restriction, including without limitation the
9 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
10 mike 1.10 // sell copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
|
13 kumpf 1.26 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
14 mike 1.10 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
15 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
16 kumpf 1.26 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
19 mike 1.10 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 //
22 //==============================================================================
23 //
24 // Author: Mike Brasher (mbrasher@bmc.com)
25 //
|
26 karl 1.12 // Modified By: Karl Schopmeyer(k.schopmeyer@opengroup.org)
|
27 kumpf 1.17 // Sushma Fernandes, Hewlett Packard Company
28 // (sushma_fernandes@hp.com)
29 // Roger Kumpf, Hewlett Packard Company (roger_kumpf@hp.com)
|
30 kumpf 1.14 //
|
31 mike 1.10 //%/////////////////////////////////////////////////////////////////////////////
32
33 #ifndef Pegasus_DateTime_h
34 #define Pegasus_DateTime_h
35
36 #include <Pegasus/Common/Config.h>
37 #include <Pegasus/Common/Array.h>
|
38 kumpf 1.29 #include <Pegasus/Common/Linkage.h>
|
39 mday 1.32.2.1 #include <time.h>
40 #ifdef PEGASUS_INTERNALONLY
41 #include <iostream>
42 #endif
|
43 kumpf 1.14
|
44 mike 1.10 PEGASUS_NAMESPACE_BEGIN
45
|
46 karl 1.16 /* ATTN: P3. KS Several functions should be added to this class for datetime manipulation
|
47 kumpf 1.14 including get and set each subcomponent (year, month, etc), test for equality,
|
48 karl 1.12 create intervals from absolutes, possibly gett current time, Note that
49 the Java rep is probably tostring, not get string,
50 */
51
|
52 kumpf 1.24 class CIMDateTimeRep;
53
|
54 mike 1.10 /**
55 The CIMDateTime class represents the CIM datetime data type as a C++ class
56 CIMDateTime. A CIM datetime may contain a date or an interval. CIMDateTime
|
57 mday 1.32.2.1 is an intrinsic CIM data type which represents the time as a formated
58 fixedplength string.
|
59 mike 1.10
60 <PRE>
61 A date has the following form:
62 yyyymmddhhmmss.mmmmmmsutc
63
64 Where
65
|
66 mday 1.32.2.1 yyyy = year (0-1999)
|
67 mike 1.10 mm = month (1-12)
68 dd = day (1-31)
69 hh = hour (0-23)
70 mm = minute (0-59)
71 ss = second (0-59)
|
72 mday 1.32.2.1 mmmmmm = microseconds.
73 s = '+' or '-' to represent the UTC sign.
74 utc = UTC offset (same as GMT offset).
|
75 mike 1.10
76 An interval has the following form:
77
78 ddddddddhhmmss.mmmmmm:000
79
80 Where
81
82 dddddddd = days
|
83 kumpf 1.13 hh = hours (0-23)
84 mm = minutes (0-59)
85 ss = seconds (0-59)
|
86 mike 1.10 mmmmmm = microseconds
87 </PRE>
88
89 Note that intervals always end in ":000" (this is how they
90 are distinguished from dates).
91
92 Intervals are really durations since they do not specify a start and
93 end time (as one expects when speaking about an interval). It is
94 better to think of an interval as specifying time elapsed since
95 some event.
96
|
97 mday 1.32.2.1 CIMDateTime objects are constructed from C character strings or from
98 other CIMDateTime objects. These character strings must be exactly
99 twenty-five characters and conform to one of the forms idententified
|
100 mike 1.10 above.
101
|
102 mday 1.32.2.1 CIMDateTime objects which are not explicitly initialized will be
103 implicitly initialized with the null time interval:
|
104 mike 1.10
105 00000000000000.000000:000
106
|
107 mday 1.32.2.1 Instances can be tested for nullness with the isNull() method.
|
108 mike 1.10 */
109 class PEGASUS_COMMON_LINKAGE CIMDateTime
110 {
111 public:
112
|
113 mday 1.32.2.1 /** Create a new CIMDateTime object with NULL DateTime definition.
|
114 karl 1.12 */
|
115 mike 1.10 CIMDateTime();
116
|
117 mday 1.32.2.1 /** CIMDateTime - Creat a CIM CIMDateTime instance from a string
118 constant representing the CIM DateTime formatted datetime
119 See the class documentation for CIMDateTime for the defintion of the
|
120 karl 1.12 input string for absolute and interval datetime.
|
121 mday 1.32.2.1 @param str String object containing the CIM DateTime formatted string
|
122 mike 1.10 */
|
123 mday 1.32.2.1 CIMDateTime(const char* str);
|
124 mike 1.10
|
125 karl 1.12 /** CIMDateTime Create a CIMDateTime instance from another
|
126 mike 1.10 CIMDateTime object
127 @param x CIMDateTime object to be copied.
128 */
129 CIMDateTime(const CIMDateTime& x);
130
|
131 karl 1.12 /** DateTime Destructor. */
|
132 kumpf 1.17 ~CIMDateTime();
|
133 mike 1.10
|
134 karl 1.12 /** Assign one DateTime object to another
135 @param - The DateTime Object to assign
136 <pre>
137 CIMDateTime d1;
138 CIMDateTime d2 = "00000000000000.000000:000";
139 d1 = d1;
140 </pre>
|
141 mike 1.10 */
142 CIMDateTime& operator=(const CIMDateTime& x);
143
|
144 mday 1.32.2.1 /** CIMDateTime isNull method - Tests for an all zero date time. Note that
145 today this function checks for absolute datetime == zero, not interval.
146 <PRE>
147 CIMDateTime dt;
148 dt.clear();
149 assert(dt.isNull());
150 </PRE>
151 @return This method returns true of the contents are
152 "00000000000000.000000:000". Else it returns false
153 */
154 Boolean isNull() const;
155
156 /* ATTN: P3 KS. This simply returns a string whether the datetime is a
157 real value or the NULL value. It is up to the user to test. Should
158 this be modified so we do something like an interupt on NULL?
159 */
160 /** getString - Returns the string representing the DateTime value of the
|
161 karl 1.12 CIMDateTime Object.
162 */
|
163 mday 1.32.2.1 const char* getString() const;
|
164 mike 1.10
165 /** method set - Sets the date time. Creates the CIMDateTime instance from
166 the input string constant which must be
167 in the datetime format.
168
169 <PRE>
170 CIMDateTime dt;
171 dt.set("19991224120000.000000+360");
172 </PRE>
173
|
174 mday 1.32.2.1 @return On format error, CIMDateTime set throws the exception
175 BadDateTimeFormat
176 @exception Throws exception BadDateTimeFormat on format error.
|
177 mike 1.10 */
|
178 mday 1.32.2.1 void set(const char* str);
|
179 mike 1.10
|
180 mday 1.32.2.1 /** clear - Clears the datetime class instance. The date time is set to our
181 defintion of NULL, absolute zero date time.
|
182 karl 1.12 */
|
183 mike 1.10 void clear();
184
|
185 mday 1.32.2.1 /** Makes a deep copy (clone) of the given object. */
186 CIMDateTime clone() const;
187
|
188 kumpf 1.14 /**
|
189 kumpf 1.23 Get current time as CIMDateTime. The time returned is the local time.
|
190 kumpf 1.14
191 @return CIMDateTime Contains the current datetime as a CIMDateTime object.
|
192 mday 1.32.2.1
193 Note: Original code was taken from OperationSystem::getLocalDateTime()
|
194 kumpf 1.14 */
195 static CIMDateTime getCurrentDateTime();
196
197 /**
|
198 mday 1.32.2.1 Get the difference between two CIMDateTimes. This function computes the
199 difference between two datetimes or between two intervals. The result
200 is truncated and returned as the number of seconds.
|
201 kumpf 1.14
|
202 mday 1.32.2.1 @param startTime Contains the start time.
|
203 kumpf 1.14
|
204 mday 1.32.2.1 @param finishTime Contains the finish time.
|
205 kumpf 1.14
|
206 mday 1.32.2.1 @return difference Difference between the two datetimes in seconds.
|
207 kumpf 1.14
|
208 mday 1.32.2.1 @throws BadFormat
209
|
210 kumpf 1.14 */
|
211 kumpf 1.22 static Sint64 getDifference(CIMDateTime startTime, CIMDateTime finishTime);
|
212 kumpf 1.14
213 /**
214 Checks whether the datetime is an interval.
215
216 @return isInterval True if the datetime is an interval, else false
217 */
218 Boolean isInterval();
219
|
220 kumpf 1.17 private:
|
221 kumpf 1.21
|
222 kumpf 1.24 CIMDateTimeRep* _rep;
|
223 kumpf 1.21
|
224 mday 1.32.2.1 Boolean _set(const char* str);
225
226 /**
227 This function extracts the different components of the date and time
228 from the string passed and assigns it to the tm structure.
229
230 @param dateTimeStr Contains the string to be assigned.
231
232 @param tm Contains the tm structure to be updated.
233 */
234 static void formatDateTime(char* dateTime, tm* tm);
235
236 // ATTN
237 /** CIMDateTime - Friend operator Test for CIMDateTime
238 equality
239 */
240 PEGASUS_COMMON_LINKAGE friend Boolean operator==(
241 const CIMDateTime& x,
242 const CIMDateTime& y);
|
243 mike 1.10 };
244
245 PEGASUS_COMMON_LINKAGE Boolean operator==(
246 const CIMDateTime& x,
247 const CIMDateTime& y);
|
248 mday 1.32.2.1
249 #ifdef PEGASUS_INTERNALONLY
250 PEGASUS_COMMON_LINKAGE PEGASUS_STD(ostream)& operator<<(
251 PEGASUS_STD(ostream)& os,
252 const CIMDateTime& x);
253 #endif
|
254 mike 1.10
255 #define PEGASUS_ARRAY_T CIMDateTime
|
256 kumpf 1.25 # include <Pegasus/Common/ArrayInter.h>
|
257 mike 1.10 #undef PEGASUS_ARRAY_T
258
259 PEGASUS_NAMESPACE_END
260
261 #endif /* Pegasus_DateTime_h */
|