(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.39.4.1 and 1.43

version 1.39.4.1, 2004/11/05 18:16:21 version 1.43, 2004/12/16 13:21:16
Line 1 
Line 1 
 //%2003////////////////////////////////////////////////////////////////////////  //%2004////////////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000, 2001, 2002  BMC Software, Hewlett-Packard Development  // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
 // Company, L. P., IBM Corp., The Open Group, Tivoli Systems.  // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.; // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
 // IBM Corp.; EMC Corporation, The Open Group. // 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 22 
Line 24 
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 // //
 //============================================================================== //==============================================================================
 // Author: Mike Brasher (mbrasher@bmc.com)  
 //  
 // Modified By:Willis White (whiwill@ibm.com) PEP #192 - changed CIMDateTimeRep,  
 //                      added CIMDateTime::toMicroSeconds() and added sub-classes  
 //                      dtInterval and dtTimeStamp.  
 // //
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
Line 36 
Line 33 
 #include <Pegasus/Common/Config.h> #include <Pegasus/Common/Config.h>
 #include <Pegasus/Common/Array.h> #include <Pegasus/Common/Array.h>
 #include <Pegasus/Common/Linkage.h> #include <Pegasus/Common/Linkage.h>
 #include <math.h>  
 //#include <Pegasus/Common/XmlWriter.h>  
  
  
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
 /* the CIMDateTimeRep class holds the data for the CIMDateTime class as it's protected  
 data members.It also allows for "setting" and "getting" of individual components of  
 date time.  
 */  
 class CIMDateTimeRep  
 {  
 public:  
     String microSec;  
     String seconds;  
     String minutes;  
     String hours;  
     String days;  
     String month;  
     String year;  
     String utcOffSet;  
   
 public:  
     enum { FORMAT_LENGTH = 25 };  
  
     //  struct CIMDateTimeRep;
     // Length of the string required to store only the date and time without  
     // the UTC sign and UTC offset.  
     // Format is yyyymmddhhmmss.  
     // Note : The size does not include the null byte.  
     //  
     enum { DATE_TIME_LENGTH = 14 };  
  
     //  /**
     // Length of the string required to store the  formatted date and time  
     // Format is yyyy:mm:dd:hh:mm:ss.  
     //  
     enum { FORMATTED_DATE_TIME = 20 };  
   
     //char buffer_day [5];  
     //    sprintf(yearbuf, "%4d", (days_rem+1));   // day of the month is never 0 (1-31)  
     //    ye_mo_da = ye_mo.append(buffer_day);  
   
   
     char data[FORMAT_LENGTH + 1];  
   
   
     Uint64 getMicroSec();  
     Uint64 getSeconds();  
     Uint64 getMinutes();  
     Uint64 getHours();  
     Uint64 getDays();  
     Uint64 getMonth();  
     Uint64 getYear();  
     Uint64 getUtcOffSet();  
   
     Uint16 set_microSec(String & mS);  
     void set_seconds(String sec);  
     void set_minutes(String min);  
     void set_hours(String ho);  
     void set_days(String da);  
     void set_month(String mon);  
     void set_year(String ye);  
     Boolean set_utcOffSet(String uOff);  
     void set_data(String vlaue, Uint32 index, Uint32 size);  
   
     void copy(CIMDateTimeRep * cTR);  
   
  };  
   
   
   
 /****************************************************************************  
  
     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 that represents the time as a string with a     is an intrinsic CIM data type that represents the time as a string with a
     fixed length.     fixed length.
  
     <PRE>     <PRE>
     A date has the following form:      A time stamp has the following form:
     yyyymmddhhmmss.mmmmmmsutc     yyyymmddhhmmss.mmmmmmsutc
  
     Where     Where
Line 145 
Line 77 
     mmmmmm = microseconds     mmmmmm = microseconds
     </PRE>     </PRE>
  
     Note: Intervals always end in ":000". This distinguishes intervals from dates.      Note: intervals always end in ":000". This distinguishes intervals from time stamps.
  
     CIMDateTime objects are constructed from String objects or from     CIMDateTime objects are constructed from String objects or from
     other CIMDateTime objects.  Character strings must be exactly     other CIMDateTime objects.  Character strings must be exactly
     twenty-five characters in length and conform to either the date or interval      twenty-five characters in length and conform to either the time stamp or interval
     format.     format.
  
     CIMDateTime objects that are not explicitly initialized will be     CIMDateTime objects that are not explicitly initialized will be
Line 157 
Line 89 
  
     00000000000000.000000:000     00000000000000.000000:000
  
   
   
   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: public:
  
     /** Creates a new CIMDateTime object with a zero interval value.     /** Creates a new CIMDateTime object with a zero interval value.
Line 167 
Line 139 
     CIMDateTime();     CIMDateTime();
  
     /** Creates a new CIMDateTime object from a string constant representing     /** Creates a new CIMDateTime object from a string constant representing
         the CIM DateTime-formatted datetime.          the CIM DateTime formatted datetime.
         See the class documentation for CIMDateTime for the definition 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.         This must contain twenty-five characters.
           @exception InvalidDateTimeFormatException if the input sting  is not
           formatted correctly
     */     */
     CIMDateTime(const String & str);     CIMDateTime(const String & str);
  
Line 180 
Line 154 
     */     */
     CIMDateTime(const CIMDateTime& x);     CIMDateTime(const CIMDateTime& x);
  
     /* Creates a CIMDateTime object from from integer.      /** Creates a CIMDateTime object from an integer.
     @pram microSec is the number of micro Seconds in the epoch 0/0/000 (12 am Jan 1, 1BCE)          @param microSec For a time stamp, the number of microseconds since
     @parm interval tells what type will be created. If true an Interval will be created,          the epoch 0/0/0000 (12 am Jan 1, 1BCE); For an interval, the number
     if false a time stamp will be created.          of microseconds in the interval.
           @param interval tells what type of CIMDateTime object  will be created.
           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(const Uint64 microSec, Boolean interval);
  
     /** CIMDateTime destructor. */     /** CIMDateTime destructor. */
     ~CIMDateTime();     ~CIMDateTime();
Line 221 
Line 203 
         dt.set("19991224120000.000000+360");         dt.set("19991224120000.000000+360");
         </PRE>         </PRE>
  
     @exception InvalidDateTimeFormatException because the date and time is not          @exception InvalidDateTimeFormatException if the date and time are not
         formatted correctly.  See the CIMDateTime class decscription for the          formatted correctly.  See the CIMDateTime class description for the
         formatting rules.         formatting rules.
     */     */
     void set(const String & str);     void set(const String & str);
Line 237 
Line 219 
     */     */
     static CIMDateTime getCurrentDateTime();     static CIMDateTime getCurrentDateTime();
  
     /** Computes the difference in microseconds between two CIMDateTime dates or      /** Computes the difference in microseconds between two CIMDateTime time stamps or
         two CIMDateTime intervals.         two CIMDateTime intervals.
         @param startTime  Contains the start datetime.         @param startTime  Contains the start datetime.
         @param finishTime  Contains the finish datetime.         @param finishTime  Contains the finish datetime.
         @return Integer that contains the difference between the two datetime values          @returns Integer that contains the difference between the two datetime values
         in microseconds is the epoch (UTC).          in microseconds.
         @exception InvalidDateTimeFormatException If one argument uses the interval          @exception InvalidDateTimeFormatException If arguments are not the same
         format and the other uses the string format.          type of CIMDateTime.
   
     *************************************************************************************  
                                        Take out  
   
   
         @exception DateTimeOutOfRangeException If differance is negative.  
   
  
         Note: The behavior on HP-UX and Windows platform is to throw an exception  
         when the dates are out of range. Red Hat Linux platform normalizes the  
         dates when they are outside their legal interval and will not throw an  
         exception.  
   
         Allowed Date Range:  
         The mktime (3C) man page on HP-UX does not document the allowed range.  
         The approximate range of dates allowed on HP-UX is between  
         1901 and 2038.  
   
         On Windows platform, the approximate range is between 1970 to 2038.  
   
         On Red Hat Linux platform the approximate range is between 1901 and 2038.  
       *************************************************************************************  
     */     */
     static Sint64 getDifference(const CIMDateTime& startTime, const CIMDateTime& finishTime);     static Sint64 getDifference(const CIMDateTime& startTime, const CIMDateTime& finishTime);
  
Line 278 
Line 239 
     /** Compares the CIMDateTime object to another CIMDateTime object for     /** Compares the CIMDateTime object to another CIMDateTime object for
         equality.         equality.
         @param x  CIMDateTime object to be compared.         @param x  CIMDateTime object to be compared.
         @return true if the two CIMDateTime objects are equal; otherwise, false.          @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;     Boolean equal (const CIMDateTime & x) const;
  
     /*Converts a CIMDateTime object to it's microsecond representaion*/      /** Converts a CIMDateTime object to its microsecond representation.
     Uint64 toMicroSeconds();          @returns  microseconds since the epoch, for time stamps. Number of
           microseconds in span of time, for intervals
      /* Arithmetic operators          @exception DateTimeOutOfRangeException if value overflow occurs during
           conversion to UTC (internal operation).
     */     */
     const CIMDateTime operator+(const CIMDateTime & cDT);      Uint64 toMicroSeconds();
     void operator+=(const CIMDateTime & cDT);  
   
     const CIMDateTime operator-(const CIMDateTime & cDT);  
     void operator-=(const CIMDateTime & cDT);  
   
     const CIMDateTime operator*(Uint64 num);  
     void operator*=(Uint64 num);  
   
   
     const CIMDateTime operator/(Uint64 num);  
     void operator/=(Uint64 num);  
   
     Uint64 operator/(const CIMDateTime & cdt);  
  
     /* Relational operators       /** 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.
     */     */
     const Boolean operator<(const CIMDateTime & cDT);      Boolean operator!=(const CIMDateTime & cDT) const;
     const Boolean operator<=(const CIMDateTime & cDT);  
   
     const Boolean operator>(const CIMDateTime & cDT);  
     const Boolean operator>=(const CIMDateTime & cDT);  
  
     const Boolean operator!=(const CIMDateTime & cDT);  
  
  
   private:
 protected:    //commented out for testing purposes  
  
     CIMDateTimeRep* _rep;     CIMDateTimeRep* _rep;
     Boolean _set(const String & dateTimeStr);     Boolean _set(const String & dateTimeStr);
       enum Field {ONLY_WILD_CARDS, SOME_WILD_CARDS, ONLY_DIGITS, ERR};
  
     /*  checks to make sure the format of a particulatr field in the DateTime string is correct.      Field fieldcheck(const String & in_p, String & rep_field);
     Returns  
         0 - field contains all wild cards  
         1 - field contains some wild cards (error)  
         2 - field contains only digits  
     */  
     Uint64 fieldcheck(String & in_p, String & rep_field);  
  
     /* check the micro Seconds field for format errors      Boolean restOfFields(Uint32 start_position,const String & inStr);
     */  
     Uint64 CIMDateTime::microSecheck(String & in_p);  
   
     /* if a field has a wild card then all the fields with lower significance should have wild cards. This  
     method makes sure of this.  
     */  
     Boolean restOfFields(Uint32 start_position,const String inStr);  
  
     Uint64 _toMicroSeconds();     Uint64 _toMicroSeconds();
  
     /* converts time stamps to thier UTC (GMT) representaion. For intervals it just retruns a copy of      void convertToUTC();
     calling program  
      */  
     CIMDateTime normalizer();  
  
     /* sets the utc offf set of the CIMDateTime object. This method does not change the value      void setUtcOffSet(Sint32 utc);
     of object, it only converts the representaion form UTC (GMT) to the time zonne spcified.  
     @parm cdt TimeStamp object that will be converted  
     @parm uct uct offset in minutes that represents the time zone  to be converted to  
     Retruns a copy of the calling object modified to represent the same time in a differnet time zone.  
     */  
     CIMDateTime  setUctOffSet(Sint32 utc);  
   
     /*inserts wild cards into CIMDateTime object.  
     @parm index - position to start placing wild card charicters  
     @parm cdt - object to be modified  
     Returns a copy of calling object with wild cards starting at position index  
     @exception InvalidDateTimeFormatException because of invalid index (see rules for wild cards)  
     */  
     CIMDateTime insert_WildCard(Uint32 index);  
   
     Uint32 getHighestWildCardPosition(CIMDateTime & cDT_s);  
  
       void insert_WildCard(Uint32 index);
  
       Uint32 getHighestWildCardPosition(const CIMDateTime & cDT_s);
 }; };
 /**  
         Add documentation here.  /**Compares two CIMDateTime objects and returns true if they represent the
     */     same time or length of time.
 PEGASUS_COMMON_LINKAGE Boolean operator==(     @param x one of the CIMDateTime objects to be compared
     /**     @param y one of the CIMDateTime objects to be compared
         Add documentation here.     @returns true if the two objects passed in represent the same time or
     */     length of time.
     const CIMDateTime& x,  
     /**  
         Add documentation here.  
     */     */
     const CIMDateTime& y);  PEGASUS_COMMON_LINKAGE Boolean operator==( const CIMDateTime& x, const CIMDateTime& y);
  
 #define PEGASUS_ARRAY_T CIMDateTime #define PEGASUS_ARRAY_T CIMDateTime
 # include <Pegasus/Common/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.39.4.1  
changed lines
  Added in v.1.43

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2