1 karl 1.50 //%2006////////////////////////////////////////////////////////////////////////
|
2 mike 1.10 //
|
3 karl 1.41 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
|
6 karl 1.35 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.41 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
|
9 karl 1.45 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 karl 1.50 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 mike 1.10 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
15 kumpf 1.26 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
18 mike 1.10 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
|
20 karl 1.41 //
|
21 kumpf 1.26 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
22 mike 1.10 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
24 kumpf 1.26 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
27 mike 1.10 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
|
30 karl 1.45 //==============================================================================
|
31 mike 1.10 //
32 //%/////////////////////////////////////////////////////////////////////////////
33
34 #ifndef Pegasus_DateTime_h
35 #define Pegasus_DateTime_h
36
37 #include <Pegasus/Common/Config.h>
|
38 kumpf 1.48 #include <Pegasus/Common/Array.h>
|
39 kumpf 1.29 #include <Pegasus/Common/Linkage.h>
|
40 kumpf 1.14
|
41 mike 1.10 PEGASUS_NAMESPACE_BEGIN
42
|
43 w.white 1.46 class CIMDateTimeRep;
|
44 kumpf 1.24
|
45 mike 1.10 /**
|
46 karl 1.36 The CIMDateTime class represents the CIM datetime data type as a C++ class
|
47 kumpf 1.48 CIMDateTime. A CIM datetime may contain a time stamp or an interval.
48 CIMDateTime is an intrinsic CIM data type that represents the time as a
49 string with a fixed length.
|
50 mike 1.10
51 <PRE>
|
52 w.white 1.42 A time stamp has the following form:
|
53 karl 1.36 yyyymmddhhmmss.mmmmmmsutc
|
54 mike 1.10
55 Where
56
|
57 karl 1.36 yyyy = year (1-9999)
58 mm = month (1-12)
59 dd = day (1-31)
60 hh = hour (0-23)
61 mm = minute (0-59)
62 ss = second (0-59)
63 mmmmmm = microseconds
64 s = '+' or '-' to represent the Coordinated Universal Time (UTC) sign
65 utc = offset from Coordinated Universal Time (UTC)
66 (same as Greenwich Mean Time(GMT) offset)
|
67 mike 1.10
68 An interval has the following form:
69
|
70 karl 1.36 ddddddddhhmmss.mmmmmm:000
|
71 mike 1.10
72 Where
73
|
74 karl 1.36 dddddddd = days
75 hh = hours (0-23)
76 mm = minutes (0-59)
77 ss = seconds (0-59)
78 mmmmmm = microseconds
|
79 mike 1.10 </PRE>
80
|
81 kumpf 1.48 Note: Intervals always end in ":000". This distinguishes intervals from
82 time stamps.
|
83 mike 1.10
|
84 kumpf 1.31 CIMDateTime objects are constructed from String objects or from
|
85 karl 1.36 other CIMDateTime objects. Character strings must be exactly
|
86 kumpf 1.48 twenty-five characters in length and conform to either the time stamp
87 or interval format.
|
88 mike 1.10
|
89 kumpf 1.31 CIMDateTime objects that are not explicitly initialized will be
90 implicitly initialized with a zero time interval:
|
91 mike 1.10
|
92 karl 1.36 00000000000000.000000:000
|
93 mike 1.10
|
94 w.white 1.42
|
95 kumpf 1.48 The following table shows what arithmetic operations are allowed
96 between CIMDateTime types. The entries in the last four columns define
97 the type of the result when the operation, specified in the column header,
98 is performed on operands, of the types specified in the first two columns.
|
99 w.white 1.42
|
100 kumpf 1.48 <PRE>
101 LHS - left hand side TS - time stamp int - integer
102 RHS - right hand side IV - interval
103 X - operation not allowed between types
104
105 LHS RHS + - * /
106 _____________________________________________
107 TS TS X IV X X
108 TS IV TS TS X X
109 TS int X X X X
110 IV IV IV IV X int
111 IV TS X X X X
112 IV int X X IV IV
113 int TS X X X X
114 int IV X X X X
115 </PRE>
116
117 The relational operators may only operate on two operands of the same type,
118 i.e. two time stamps or two intervals.
|
119 mike 1.10 */
120 class PEGASUS_COMMON_LINKAGE CIMDateTime
121 {
122 public:
123
|
124 kumpf 1.34 /** Creates a new CIMDateTime object with a zero interval value.
|
125 karl 1.12 */
|
126 mike 1.10 CIMDateTime();
127
|
128 karl 1.36 /** Creates a new CIMDateTime object from a string constant representing
|
129 w.white 1.42 the CIM DateTime formatted datetime.
|
130 kumpf 1.31 See the class documentation for CIMDateTime for the definition of the
|
131 karl 1.12 input string for absolute and interval datetime.
|
132 kumpf 1.48 @param str String object containing the CIMDateTime formatted string.
|
133 karl 1.36 This must contain twenty-five characters.
|
134 kumpf 1.48 @exception InvalidDateTimeFormatException If the input string is not
135 formatted correctly.
|
136 mike 1.10 */
|
137 kumpf 1.31 CIMDateTime(const String & str);
|
138 mike 1.10
|
139 kumpf 1.34 /** Creates a CIMDateTime object from another CIMDateTime object.
|
140 w.white 1.42 @param x Specifies the name of the CIMDateTime object to copy.
|
141 mike 1.10 */
142 CIMDateTime(const CIMDateTime& x);
143
|
144 w.white 1.42 /** Creates a CIMDateTime object from an integer.
|
145 kumpf 1.48 @param microSec For a time stamp, the number of microseconds since
146 the epoch 0/0/0000 (12 am Jan 1, 1BCE); For an interval, the number
147 of microseconds in the interval.
148 @param interval Specifies whether the CIMDateTime object is to be
149 created as an interval value (true) or a time stamp (false).
150 @exception DateTimeOutOfRangeException If the microSec value is too
151 large (greater than 317,455,200,000,000,000 for a time stamps or
152 8,640,000,000,000,000,000 for an interval).
153 @exception InvalidDateTimeFormatException If the CIMDateTime object is
154 not formed correctly.
155 */
|
156 w.white 1.44 CIMDateTime(Uint64 microSec, Boolean interval);
|
157 w.white 1.42
|
158 a.arora 1.39 /** CIMDateTime destructor. */
159 ~CIMDateTime();
160
|
161 karl 1.36 /** Assigns one instance of the CIMDateTime object to another.
162 @param x The CIMDateTime Object to assign to the CIMDateTime object.
163 For example, you can assign the d1 CIMDateTime instance to the d2
164 CIMDateTime instance.
|
165 kumpf 1.34 <PRE>
166 CIMDateTime d1;
167 CIMDateTime d2 = "00000000000000.000000:000";
|
168 karl 1.36 d1 = d2;
|
169 kumpf 1.34 </PRE>
|
170 karl 1.36 Therefore, d1 is assigned the same "00000000000000.000000:000" value as d2.
|
171 mike 1.10 */
172 CIMDateTime& operator=(const CIMDateTime& x);
173
|
174 kumpf 1.34 /** Returns a string representing the DateTime value of the
|
175 karl 1.36 CIMDateTime object.
|
176 kumpf 1.34 @return String representing the DateTime value.
|
177 karl 1.12 */
|
178 kumpf 1.48 String toString() const;
|
179 mike 1.10
|
180 kumpf 1.48 /** Sets the datetime value from the input parameter.
181 @param str String containing the new value in the datetime format
182 (specified in the CIMDateTime class description). For example, the
183 following sets the date to December 24, 1999 and time to 12:00 P.M.
184 EST.
|
185 mike 1.10
|
186 karl 1.36 <PRE>
187 CIMDateTime dt;
|
188 kumpf 1.48 dt.set("19991224120000.000000-300");
|
189 karl 1.36 </PRE>
|
190 mike 1.10
|
191 kumpf 1.48 @exception InvalidDateTimeFormatException If the datetime String is not
192 formatted correctly.
|
193 mike 1.10 */
|
194 kumpf 1.31 void set(const String & str);
|
195 mike 1.10
|
196 karl 1.36 /** Clears the datetime class object. The date time is set to
|
197 kumpf 1.34 a zero interval value.
|
198 karl 1.12 */
|
199 mike 1.10 void clear();
200
|
201 kumpf 1.48 /** Returns the current local time in a CIMDateTime object.
202 @return CIMDateTime object containing the current local date and time.
|
203 kumpf 1.14 */
204 static CIMDateTime getCurrentDateTime();
205
|
206 kumpf 1.48 /** Computes the difference in microseconds between two CIMDateTime time
207 stamps or two CIMDateTime intervals.
|
208 kumpf 1.34 @param startTime Contains the start datetime.
209 @param finishTime Contains the finish datetime.
|
210 kumpf 1.48 @return An integer that contains the difference between the two
211 datetime values (in microseconds).
|
212 w.white 1.42 @exception InvalidDateTimeFormatException If arguments are not the same
213 type of CIMDateTime.
|
214 kumpf 1.14 */
|
215 kumpf 1.48 static Sint64 getDifference(CIMDateTime startTime, CIMDateTime finishTime);
216
217 /** Checks whether the datetime is an interval.
218 @return True if the datetime is an interval value, false otherwise.
219 */
|
220 kumpf 1.49 Boolean isInterval() const;
|
221 kumpf 1.48 Boolean isInterval();
|
222 karl 1.36
223 /** Compares the CIMDateTime object to another CIMDateTime object for
|
224 kumpf 1.34 equality.
225 @param x CIMDateTime object to be compared.
|
226 kumpf 1.48 @return true if the two CIMDateTime objects are equal, false otherwise
|
227 w.white 1.42 @exception TypeMismatchException If arguments are of different types.
|
228 kumpf 1.31 */
|
229 kumpf 1.48 Boolean equal(const CIMDateTime & x) const;
|
230 kumpf 1.31
|
231 w.white 1.42 /** Converts a CIMDateTime object to its microsecond representation.
|
232 kumpf 1.48 @return Number of microseconds since the epoch (for time stamps) or
233 in a span of time (for intervals).
234 @exception DateTimeOutOfRangeException If conversion to UTC (an
235 internal operation) causes an overflow condition.
|
236 w.white 1.42 */
|
237 w.white 1.47 Uint64 toMicroSeconds() const;
|
238 w.white 1.42
|
239 kumpf 1.48 /** Adds two CIMDateTime objects and returns a CIMDateTime object that
240 represents the sum.
241 @param cDT operand on the RHS of the operator
242 @return A CIMDateTime object that is the result of adding the calling
243 object to the RHS operand
244 @exception DateTimeOutOfRangeException If the operation causes an
245 overflow condition.
246 @exception TypeMismatchException If the operands are not type
247 compatible (see table of operations).
|
248 w.white 1.42 */
|
249 kumpf 1.48 CIMDateTime operator+(const CIMDateTime& cDT) const;
|
250 w.white 1.42
251 /** Adds two CIMDateTime objects, returns the sum and changes
252 the value of the calling CIMDateTime object to match the return value.
253 @param cDT operand on the RHS of the operator
|
254 kumpf 1.48 @return A CIMDateTime object that is the result of adding the calling
255 object to the RHS operand
256 @exception DateTimeOutOfRangeException If the operation causes an
257 overflow condition.
258 @exception TypeMismatchException If the operands are not type
259 compatible (see table of operations).
|
260 w.white 1.42 */
|
261 kumpf 1.48 CIMDateTime & operator+=(const CIMDateTime& cDT);
|
262 w.white 1.42
|
263 kumpf 1.48 /** Subtracts one CIMDateTime object from another and returns a
264 CIMDateTime object that represents the difference.
|
265 w.white 1.42 @param cDT operand on the RHS of the operator
|
266 kumpf 1.48 @return A CIMDateTime object that is the result of subtracting the
|
267 w.white 1.42 the RHS object from the calling.
|
268 kumpf 1.48 @exception DateTimeOutOfRangeException If the operation causes an
269 underflow condition or conversion to UTC (an internal operation)
270 causes an overflow condition.
271 @exception TypeMismatchException If the operands are not type
272 compatible (see table of operations).
273 */
274 CIMDateTime operator-(const CIMDateTime& cDT) const;
275
276 /** Subtracts one CIMDateTime object from another, returns the difference
277 and changes the value of the calling CIMDateTime object to match the
278 return value.
|
279 w.white 1.42 @param cDT operand on the RHS of the operator
|
280 kumpf 1.48 @return A CIMDateTime object that is the result of subtracting the
281 object on the RHS from the calling object.
282 @exception DateTimeOutOfRangeException If the operation causes an
283 underflow condition or conversion to UTC (an internal operation)
284 causes an overflow condition.
285 @exception TypeMismatchException If the operands are not type
286 compatible (see table of operations).
287 */
288 CIMDateTime & operator-=(const CIMDateTime& cDT);
289
290 /** Multiplies a CIMDateTime object by an integer and returns a CIMDateTime
291 object that represents the product.
292 @param num integer operand on the RHS of the operator
293 @return A CIMDateTime object that is the result of multiplying the
294 calling object by the RHS operand.
295 @exception DateTimeOutOfRangeException If the operation causes an
296 overflow condition.
297 @exception TypeMismatchException If the operands are not type
298 compatible (see table of operations).
|
299 w.white 1.42 */
300 CIMDateTime operator*(Uint64 num) const;
301
|
302 kumpf 1.48 /** Multiplies a CIMDateTime object by an integer, returns the product
303 and changes the value of the calling object to match the returned
304 product.
305 @param num integer operand on the RHS of the operator
306 @return A CIMDateTime object that is the result of multiplying the
307 calling object by the RHS operand.
308 @exception DateTimeOutOfRangeException If the operation causes an
309 overflow condition.
310 @exception TypeMismatchException If the operands are not type
311 compatible (see table of operations).
312 */
|
313 w.white 1.42 CIMDateTime & operator*=(Uint64 num);
|
314 kumpf 1.48
315 /** Divides a CIMDateTime object by an integer and returns a CIMDateTime
316 object that represents the quotient.
317 @param num integer operand on the RHS of the operator
318 @return A CIMDateTime object that is the result of dividing the calling
319 object by the RHS operand.
320 @exception DateTimeOutOfRangeException If conversion to UTC (an
321 internal operation) causes an overflow condition.
322 @exception TypeMismatchException If the CIMDateTime object does not
323 hold an interval value (see table of operations).
324 @exception Exception if param num is zero.
325 */
|
326 w.white 1.42 CIMDateTime operator/(Uint64 num) const;
327
|
328 kumpf 1.48 /** Divides a CIMDateTime object by an integer, returns the quotient
329 and changes the value of the calling object to match the returned
330 quotient.
331 @param num integer operand on the RHS of the operator
332 @return A CIMDateTime object that is the result of dividing the calling
333 object by the RHS operand.
334 @exception DateTimeOutOfRangeException If conversion to UTC (an
335 internal operation) causes an overflow condition.
336 @exception TypeMismatchException If the CIMDateTime object does not
337 hold an interval value (see table of operations).
338 @exception Exception if param num is zero.
339 */
|
340 w.white 1.42 CIMDateTime & operator/=(Uint64 num);
341
|
342 kumpf 1.48 /** Divides a CIMDateTime object by another CIMDateTime object and returns
343 an integer quotient.
344 @param cdt CIMDateTime object on the RHS of the operator
345 @return An integer that is the result of dividing the number of
346 microseconds represented by the calling CIMDateTime object by the
347 number of microseconds represented by the CIMDateTime object on the
348 RHS of the operator.
349 @exception DateTimeOutOfRangeException If conversion to UTC (an
350 internal operation) causes an overflow condition.
351 @exception TypeMismatchException If the operands are not type
352 compatible (see table of operations).
353 */
354 Uint64 operator/(const CIMDateTime& cdt) const;
355
356 /** Compare two CIMDateTime objects and returns true if the LHS is
357 less than the RHS.
358 @param cDT operand on the RHS of the operator
359 @return true if the LHS is less than the RHS, false otherwise.
360 @exception DateTimeOutOfRangeException If conversion to UTC (an
361 internal operation) causes an overflow condition.
362 @exception TypeMismatchException if operands are not of the same
363 kumpf 1.48 type.
|
364 w.white 1.42 */
|
365 kumpf 1.48 Boolean operator<(const CIMDateTime& cDT) const;
|
366 w.white 1.42
|
367 kumpf 1.48 /** Compare two CIMDateTime objects and returns true if the LHS is
368 less than or equal to the RHS.
369 @param cDT operand on the RHS of the operator
370 @return true if the LHS is less than or equal to the RHS, false
371 otherwise.
372 @exception DateTimeOutOfRangeException If conversion to UTC (an
373 internal operation) causes an overflow condition.
374 @exception TypeMismatchException if operands are not of the same
375 type.
376 */
377 Boolean operator<=(const CIMDateTime& cDT) const;
378
379 /** Compare two CIMDateTime objects and returns true if the LHS is
380 greater than the RHS.
381 @param cDT operand on the RHS of the operator
382 @return true if the LHS is greater than the RHS, false otherwise.
383 @exception DateTimeOutOfRangeException If conversion to UTC (an
384 internal operation) causes an overflow condition.
385 @exception TypeMismatchException if operands are not of the same
386 type.
|
387 w.white 1.42 */
388 Boolean operator>(const CIMDateTime & cDT) const;
389
|
390 kumpf 1.48 /** Compare two CIMDateTime objects and returns true if the LHS is
391 greater than or equal to the RHS.
392 @param cDT operand on the RHS of the operator
393 @return true if the LHS is greater than or equal to the RHS, false
394 otherwise.
395 @exception DateTimeOutOfRangeException If conversion to UTC (an
396 internal operation) causes an overflow condition.
397 @exception TypeMismatchException if operands are not of the same
398 type.
|
399 w.white 1.42 */
400 Boolean operator>=(const CIMDateTime & cDT) const;
401
|
402 kumpf 1.48 /** Compare two CIMDateTime objects and returns true if the LHS is
403 not equal to the RHS.
404 @param cDT operand on the RHS of the operator
405 @return true if the LHS is not equal to RHS, false otherwise.
406 @exception DateTimeOutOfRangeException If conversion to UTC (an
407 internal operation) causes an overflow condition.
408 @exception TypeMismatchException if operands are not of the same
409 type.
|
410 w.white 1.42 */
411 Boolean operator!=(const CIMDateTime & cDT) const;
412
|
413 kumpf 1.48 private:
|
414 kumpf 1.21
|
415 a.arora 1.39 CIMDateTimeRep* _rep;
|
416 kumpf 1.31 Boolean _set(const String & dateTimeStr);
|
417 w.white 1.42 enum Field {ONLY_WILD_CARDS, SOME_WILD_CARDS, ONLY_DIGITS, ERR};
418
419 Field fieldcheck(const String & in_p, String & rep_field);
420
421 Boolean restOfFields(Uint32 start_position,const String & inStr);
|
422 kumpf 1.48
|
423 w.white 1.42 Uint64 _toMicroSeconds();
424
425 void convertToUTC();
426
427 void setUtcOffSet(Sint32 utc);
428
429 void insert_WildCard(Uint32 index);
|
430 kumpf 1.48
|
431 w.white 1.42 Uint32 getHighestWildCardPosition(const CIMDateTime & cDT_s);
|
432 mike 1.10 };
|
433 w.white 1.42
|
434 kumpf 1.48 /** Compares two CIMDateTime objects and returns true if they represent the
435 same time or length of time.
436 @param x one of the CIMDateTime objects to be compared
437 @param y one of the CIMDateTime objects to be compared
438 @return true if the two objects passed in represent the same time or
439 length of time, false otherwise.
|
440 w.white 1.42 */
|
441 kumpf 1.48 PEGASUS_COMMON_LINKAGE Boolean operator==(
442 const CIMDateTime& x,
443 const CIMDateTime& y);
|
444 mike 1.10
445 #define PEGASUS_ARRAY_T CIMDateTime
|
446 kumpf 1.25 # include <Pegasus/Common/ArrayInter.h>
|
447 mike 1.10 #undef PEGASUS_ARRAY_T
448
|
449 w.white 1.42
|
450 mike 1.10 PEGASUS_NAMESPACE_END
451
452 #endif /* Pegasus_DateTime_h */
|