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