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

Diff for /pegasus/src/Pegasus/Common/CIMDateTime.h between version 1.12 and 1.44

version 1.12, 2002/02/18 13:58:02 version 1.44, 2005/01/04 12:16:32
Line 1 
Line 1 
 //%/////////////////////////////////////////////////////////////////////////////  //%2004////////////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM  // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
   // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
   // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
   // IBM Corp.; EMC Corporation, The Open Group.
   // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
   // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
 // //
 // Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
 // of this software and associated documentation files (the "Software"), to // of this software and associated documentation files (the "Software"), to
Line 20 
Line 25 
 // //
 //============================================================================== //==============================================================================
 // //
 // Author: Mike Brasher (mbrasher@bmc.com)  
 //  
 // Modified By: Karl Schopmeyer(k.schopmeyer@opengroup.org)  
 //  
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
 #ifndef Pegasus_DateTime_h #ifndef Pegasus_DateTime_h
Line 31 
Line 32 
  
 #include <Pegasus/Common/Config.h> #include <Pegasus/Common/Config.h>
 #include <Pegasus/Common/Array.h> #include <Pegasus/Common/Array.h>
 #include <iostream>  #include <Pegasus/Common/Linkage.h>
   
  
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
 /* ATTN: P3. Several functions should be added to this class for datetime manipulation  
    including get and set each subcomponent (year, month, etc). isInterval, test for equality,  struct CIMDateTimeRep;
    create intervals from absolutes, possibly gett current time, Note that  
    the Java rep is probably tostring, not get string,  
 */  
  
 /** /**
   
     The CIMDateTime class represents the CIM datetime data type as a C++ class     The CIMDateTime class represents the CIM datetime data type as a C++ class
     CIMDateTime. A CIM datetime may contain a date or an interval. CIMDateTime      CIMDateTime. A CIM datetime may contain a time stamp or an interval. CIMDateTime
     is an intrinsic CIM data type which represents the time as a formated      is an intrinsic CIM data type that represents the time as a string with a
     fixedplength string.      fixed length.
  
     <PRE>     <PRE>
     A date has the following form:      A time stamp has the following form:
         yyyymmddhhmmss.mmmmmmsutc         yyyymmddhhmmss.mmmmmmsutc
  
     Where     Where
  
         yyyy = year (0-1999)      yyyy = year (1-9999)
         mm = month (1-12)         mm = month (1-12)
         dd = day (1-31)         dd = day (1-31)
         hh = hour (0-23)         hh = hour (0-23)
         mm = minute (0-59)         mm = minute (0-59)
         ss = second (0-59)         ss = second (0-59)
         mmmmmm = microseconds.      mmmmmm = microseconds
         s = '+' or '-' to represent the UTC sign.      s = '+' or '-' to represent the Coordinated Universal Time (UTC) sign
         utc = UTC offset (same as GMT offset).      utc = offset from Coordinated Universal Time (UTC)
           (same as Greenwich Mean Time(GMT) offset)
  
     An interval has the following form:     An interval has the following form:
  
Line 70 
Line 71 
     Where     Where
  
         dddddddd = days         dddddddd = days
         hh = hours      hh = hours (0-23)
         mm = minutes      mm = minutes (0-59)
         ss = seconds      ss = seconds (0-59)
         mmmmmm = microseconds         mmmmmm = microseconds
     </PRE>     </PRE>
  
     Note that intervals always end in ":000" (this is how they      Note: intervals always end in ":000". This distinguishes intervals from time stamps.
     are distinguished from dates).  
  
     Intervals are really durations since they do not specify a start and      CIMDateTime objects are constructed from String objects or from
     end time (as one expects when speaking about an interval). It is      other CIMDateTime objects.  Character strings must be exactly
     better to think of an interval as specifying time elapsed since      twenty-five characters in length and conform to either the time stamp or interval
     some event.      format.
   
     CIMDateTime objects are constructed from C character strings or from  
     other CIMDateTime objects. These character strings must be exactly  
     twenty-five characters and conform to one of the forms idententified  
     above.  
  
     CIMDateTime objects which are not explicitly initialized will be      CIMDateTime objects that are not explicitly initialized will be
     implicitly initialized with the null time interval:      implicitly initialized with a zero time interval:
  
         00000000000000.000000:000         00000000000000.000000:000
  
     Instances can be tested for nullness with the isNull() method.  
   
   The following table shows what arithmetic operations are allowed
   between CIMDateTime types. The entries in the last four columns define
   the type of the result when the operation, specified in the column header,
   is performed on operands, of the types specified in the first two columns.
   
   <PRE>
   LHS - left hand side    TS - time stamp  int - integer
   RHS - right hand side   IV - interval
   X - operation not allowed between types
   
   
   
   LHS     RHS    +       -       *        /
   _____________________________________________
   TS      TS     X       IV      X       X
   
   TS      IV     TS      TS      X       X
   
   TS      int    X       X       X       X
   
   IV      IV     IV      IV      X       int
   
   IV      TS     X       X       X       X
   
   IV      int    X       X       IV      IV
   
   int     TS     X       X       X       X
   
   int     IV     X       X       X       X
   
   
   </PRE>
   
   The relational operators may only operate on two operands of the same type,
   i.e. two time stamps or two intervals.
   
 */ */
   
 class PEGASUS_COMMON_LINKAGE CIMDateTime class PEGASUS_COMMON_LINKAGE CIMDateTime
 { {
 public:  
  
     enum { FORMAT_LENGTH = 25 };  public:
  
     /** Create a new CIMDateTime object with NULL DateTime definition.      /** Creates a new CIMDateTime object with a zero interval value.
     */     */
     CIMDateTime();     CIMDateTime();
  
     /** CIMDateTime - Creat a CIM CIMDateTime instance from a string      /** Creates a new CIMDateTime object from a string constant representing
         constant representing the CIM DateTime formatted datetime          the CIM DateTime formatted datetime.
         See the class documentation for CIMDateTime for the defintion of the          See the class documentation for CIMDateTime for the definition of the
         input string for absolute and interval datetime.         input string for absolute and interval datetime.
         @param str String object containing the CIM DateTime formatted string          @param str  String object containing the CIMDateTime formatted string.
           This must contain twenty-five characters.
           @exception InvalidDateTimeFormatException if the input sting  is not
           formatted correctly
     */     */
     CIMDateTime(const char* str);      CIMDateTime(const String & str);
  
     /** CIMDateTime Create a CIMDateTime instance from another      /** Creates a CIMDateTime object from another CIMDateTime object.
         CIMDateTime object          @param x  Specifies the name of the CIMDateTime object to copy.
         @param x CIMDateTime object to be copied.  
     */     */
     CIMDateTime(const CIMDateTime& x);     CIMDateTime(const CIMDateTime& x);
  
     /** DateTime Destructor. */      /** Creates a CIMDateTime object from an integer.
     ~CIMDateTime() { }          @param microSec For a time stamp, the number of microseconds since
           the epoch 0/0/0000 (12 am Jan 1, 1BCE); For an interval, the number
     /**  Assign one DateTime object to another          of microseconds in the interval.
     @param - The DateTime Object to assign          @param interval tells what type of CIMDateTime object  will be created.
     <pre>          If true an interval will be created, if false a time stamp will
           be created.
           @exception DateTimeOutOfRangeException if param microSec is grater then
           317,455,200,000,000,000 for time stamps or 8,640,000,000,000,000,000 for
           intervals.
           @exception InvalidDateTimeFormatException if CIMDateTime object was not
           formed correctly.
        */
       CIMDateTime(Uint64 microSec, Boolean interval);
   
       /** CIMDateTime destructor. */
       ~CIMDateTime();
   
       /** Assigns one instance of the CIMDateTime object to another.
           @param x  The CIMDateTime Object to assign to the CIMDateTime object.
           For example, you can assign the d1 CIMDateTime instance to the d2
           CIMDateTime instance.
           <PRE>
     CIMDateTime d1;     CIMDateTime d1;
     CIMDateTime d2 = "00000000000000.000000:000";     CIMDateTime d2 = "00000000000000.000000:000";
     d1 = d1;              d1 = d2;
     </pre>  
     */  
     CIMDateTime& operator=(const CIMDateTime& x);  
   
     /** CIMDateTime isNull method - Tests for an all zero date time. Note that  
         today this function checks for absolute datetime == zero, not interval.  
         <PRE>  
         CIMDateTime dt;  
         dt.clear();  
         assert(dt.isNull());  
         </PRE>         </PRE>
         @return This method returns true of the contents are          Therefore, d1 is assigned the same "00000000000000.000000:000" value as d2.
         "00000000000000.000000:000". Else it returns false  
     */     */
     Boolean isNull() const;      CIMDateTime& operator=(const CIMDateTime& x);
  
     /** getString - Returns the string representing the DateTime value of the      /** Returns a string representing the DateTime value of the
         CIMDateTime Object.          CIMDateTime object.
         ATTN: P3 KS.  This simply returns a string whether the datetime is a          @return String representing the DateTime value.
         real value or the NULL value.  It is up to the user to test.  Should      */
         this be modified so we do something like an interupt on NULL?      String toString () const;
     */  
     const char* getString() const;      /** Sets the date and time in the CIMDateTime object from
           the input parameter.
     /** method set - Sets the date time. Creates the CIMDateTime instance from          @param str  String constant containing the datetime
         the input string constant which must be          in the datetime format. This must conform the to formatting rules specified
         in the datetime format.          in the CIMDateTime class description.  For example, the following sets
           the date to December 24, 1999 and time to 12:00 P.M.
  
             <PRE>             <PRE>
             CIMDateTime dt;             CIMDateTime dt;
             dt.set("19991224120000.000000+360");             dt.set("19991224120000.000000+360");
             </PRE>             </PRE>
  
         @return On format error, CIMDateTime set throws the exception          @exception InvalidDateTimeFormatException if the date and time are not
         BadDateTimeFormat          formatted correctly.  See the CIMDateTime class description for the
         @exception Throws exception BadDateTimeFormat on format error.          formatting rules.
     */     */
     void set(const char* str);      void set(const String & str);
  
     /**  clear - Clears the datetime class instance. The date time is set to our      /** Clears the datetime class object.  The date time is set to
         defintion of NULL, absolute zero date time.          a zero interval value.
     */     */
     void clear();     void clear();
  
     /** CIMDateTime - ATTN: Friend operator Test for CIMDateTime      /** Receives the current time as CIMDateTime. The time is returned as the local time.
         equality          @return CIMDateTime object containing the current date and time.
     */     */
     PEGASUS_COMMON_LINKAGE friend Boolean operator==(      static CIMDateTime getCurrentDateTime();
         const CIMDateTime& x,  
         const CIMDateTime& y);      /** Computes the difference in microseconds between two CIMDateTime time stamps or
           two CIMDateTime intervals.
           @param startTime  Contains the start datetime.
           @param finishTime  Contains the finish datetime.
           @returns Integer that contains the difference between the two datetime values
           in microseconds.
           @exception InvalidDateTimeFormatException If arguments are not the same
           type of CIMDateTime.
   
       */
       static Sint64 getDifference(const CIMDateTime& startTime, const CIMDateTime& finishTime);
   
       /** Checks whether the datetime is an interval.
           @return True if the datetime is an interval; otherwise, false.
       */
       Boolean isInterval() const;
   
       /** Compares the CIMDateTime object to another CIMDateTime object for
           equality.
           @param x  CIMDateTime object to be compared.
           @returns true if the two CIMDateTime objects are equal; otherwise, false.
           @exception TypeMismatchException If arguments are of different types.
       */
       Boolean equal (const CIMDateTime & x) const;
   
       /** Converts a CIMDateTime object to its microsecond representation.
           @returns  microseconds since the epoch, for time stamps. Number of
           microseconds in span of time, for intervals
           @exception DateTimeOutOfRangeException if value overflow occurs during
           conversion to UTC (internal operation).
       */
       Uint64 toMicroSeconds();
   
        /** Adds two CIMDateTime objects and returns a CIMDateTime object that
            represents the sum.
            @param cDT operand on the RHS of the operator
            @returns a CIMDateTime object that is the result of adding the calling
            object to the RHS operand
            @exception DateTimeOutOfRangeException if overflow conditions occur.
            @exception TypeMismatchException if input and caller are not the correct
            type. (see table of operations)
       */
       CIMDateTime operator+(const CIMDateTime & cDT) const;
   
       /** Adds two CIMDateTime objects, returns the sum and changes
           the value of the calling CIMDateTime object to match the return value.
           @param cDT operand on the RHS of the operator
           @returns a CIMDateTime object that is the result of adding the calling
           object to the RHS operand
           @exception DateTimeOutOfRangeException if overflow conditions occur.
           @exception TypeMismatchException if input and caller are not the correct
           type. (see table of operations)
   
       */
       CIMDateTime & operator+=(const CIMDateTime & cDT);
   
       /** Subtracts one CIMDateTime object from another and returns a CIMDateTime object
           that represents the difference.
           @param cDT operand on the RHS of the operator
           @returns a CIMDateTime object that is the result of subtracting the
           the RHS object from the calling.
           @exception DateTimeOutOfRangeException if overflow conditions occur.
           @exception TypeMismatchException if input and caller are not the correct
           type. (see table of operations)
       */
       CIMDateTime operator-(const CIMDateTime & cDT) const;
   
       /** Subtracts one CIMDateTime object from another, returns the difference and changes
           the value of the calling CIMDateTime object to match the return value.
           @param cDT operand on the RHS of the operator
           @returns a CIMDateTime object that is the result of subtracting the object on
           the RHS from the calling object.
           @exception DateTimeOutOfRangeException if underflow conditions occur for
           result or overflow condition occurs during conversion to UTC (internal operation).
           @exception TypeMismatchException if input and caller are not the correct
           type. (see table of operations)
       */
       CIMDateTime & operator-=(const CIMDateTime & cDT);
   
       /**Multiplies a CIMDateTime object by an integer and returns a CIMDateTime
          object that represents the product.
          @param num integer operand on the RHS of the operator
          @returns a CIMDateTime object that is the result of multiplying the calling
          object by the RHS operand.
          @exception DateTimeOutOfRangeException if overflow conditions occur.
          @exception TypeMismatchException if caller is not the correct
          type. (see table of operations)
       */
       CIMDateTime operator*(Uint64 num) const;
   
       /**Multiplies a CIMDateTime object by an integer, returns the product
          and changes the value of the calling object to match the returned product.
         @param num integer operand on the RHS of the operator
         @returns a CIMDateTime object that is the result of multiplying the calling
         object by the RHS operand.
         @exception DateTimeOutOfRangeException if overflow condition occur.
         @exception TypeMismatchException if caller is not the correct
         type. (see table of operations)
      */
       CIMDateTime & operator*=(Uint64 num);
   
       /**Divides a CIMDateTime object by an integer and returns a CIMDateTime
         object that represents the quotient.
         @param num integer operand on the RHS of the operator
         @returns a CIMDateTime object that is the result of dividing the calling
         object by the RHS operand.
         @exception DateTimeOutOfRangeException if overflow condition occur.
         @exception TypeMismatchException if caller is not the correct
         type. (see table of operations)
         @exception Exception if param num is zero.
      */
       CIMDateTime operator/(Uint64 num) const;
   
       /**Divides a CIMDateTime object by an integer, returns the quotient
          and changes the value of the calling object to match the returned quotient.
         @param num integer operand on the RHS of the operator
         @returns a CIMDateTime object that is the result of dividing the calling
         object by the RHS operand
         @exception DateTimeOutOfRangeException if overflow condition
          occurs during conversion to UTC.(internal operation)
         @exception TypeMismatchException if caller is not the correct
         type. (see table of operations)
         @exception Exception if input is zero.
      */
       CIMDateTime & operator/=(Uint64 num);
   
       /**Divides a CIMDateTime object by another CIMDateTime object and returns
          an integer quotient.
         @param cdt CIMDateTime object on the RHS of the operator
         @returns an integer that is the result of dividing the number of microseconds
         represented by the calling CIMDateTime object by the
         number of microseconds represented by the CIMDateTime object on the RHS of
         the operator.
         @exception DateTimeOutOfRangeException if overflow condition
          occurs during conversion to UTC.(internal operation)
         @exception TypeMismatchException if operands are not the correct
         type. (see table of operations)
   
      */
       Uint64 operator/(const CIMDateTime & cdt) const;
   
       /**Compare two CIMDateTime objects and returns true if the LHS is
          greater then RHS.
          @param cDT operand on the RHS of the operator
          @returns true if the LHS is greater then RHS.
          @exception DateTimeOutOfRangeException if overflow condition
          occurs during conversion to UTC.(internal operation)
          @exception TypeMismatchException if operands are not of the same
          type.
        */
       Boolean operator<(const CIMDateTime & cDT) const;
   
       /**Compare two CIMDateTime objects and returns true if the LHS is
          greater then or equal to the RHS.
          @param cDT operand on the RHS of the operator
          @returns true if the LHS is greater then RHS.
          @exception DateTimeOutOfRangeException if overflow condition
          occurs during conversion to UTC.(internal operation)
          @exception TypeMismatchException if operands are not of the same
          type.
       */
       Boolean operator<=(const CIMDateTime & cDT) const;
   
       /**Compare two CIMDateTime objects and returns true if the LHS is
          less then RHS.
          @param cDT operand on the RHS of the operator
          @returns true if the LHS is less then RHS.
          @exception DateTimeOutOfRangeException if overflow condition
          occurs during conversion to UTC (internal operation).
          @exception TypeMismatchException if operands are not of the same
          type.
       */
       Boolean operator>(const CIMDateTime & cDT) const;
   
       /**Compare two CIMDateTime objects and returns true if the LHS is
          less then or equal to the RHS.
          @param cDT operand on the RHS of the operator
          @returns true if the LHS is less then RHS.
          @exception DateTimeOutOfRangeException if overflow condition
          occurs during conversion to UTC (internal operation).
          @exception TypeMismatchException if operands are not of the same
          type.
       */
       Boolean operator>=(const CIMDateTime & cDT) const;
   
       /**Compare two CIMDateTime objects and returns true if the LHS is
          not equal to the RHS.
          @param cDT operand on the RHS of the operator
          @returns true if the LHS is not equal to RHS.
          @exception DateTimeOutOfRangeException if overflow condition
          occurs during conversion to UTC (internal operation).
          @exception TypeMismatchException if operands are not of the same
          type.
       */
       Boolean operator!=(const CIMDateTime & cDT) const;
   
   
  
 private: private:
  
     Boolean _set(const char* str);      CIMDateTimeRep* _rep;
     char _rep[FORMAT_LENGTH + 1];      Boolean _set(const String & dateTimeStr);
       enum Field {ONLY_WILD_CARDS, SOME_WILD_CARDS, ONLY_DIGITS, ERR};
   
       Field fieldcheck(const String & in_p, String & rep_field);
   
       Boolean restOfFields(Uint32 start_position,const String & inStr);
   
       Uint64 _toMicroSeconds();
   
       void convertToUTC();
   
       void setUtcOffSet(Sint32 utc);
   
       void insert_WildCard(Uint32 index);
   
       Uint32 getHighestWildCardPosition(const CIMDateTime & cDT_s);
 }; };
  
 PEGASUS_COMMON_LINKAGE Boolean operator==(  /**Compares two CIMDateTime objects and returns true if they represent the
     const CIMDateTime& x,     same time or length of time.
     const CIMDateTime& y);     @param x one of the CIMDateTime objects to be compared
      @param y one of the CIMDateTime objects to be compared
 PEGASUS_COMMON_LINKAGE PEGASUS_STD(ostream)& operator<<(     @returns true if the two objects passed in represent the same time or
     PEGASUS_STD(ostream)& os,     length of time.
     const CIMDateTime& x);  */
   PEGASUS_COMMON_LINKAGE Boolean operator==( const CIMDateTime& x, const CIMDateTime& y);
  
 #define PEGASUS_ARRAY_T CIMDateTime #define PEGASUS_ARRAY_T CIMDateTime
 # include "ArrayInter.h"  # include <Pegasus/Common/ArrayInter.h>
 #undef PEGASUS_ARRAY_T #undef PEGASUS_ARRAY_T
  
   
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END
  
 #endif /* Pegasus_DateTime_h */ #endif /* Pegasus_DateTime_h */


Legend:
Removed from v.1.12  
changed lines
  Added in v.1.44

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2