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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2