(file) Return to CIMDateTime.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2