(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.2 and 1.39.4.1

version 1.2, 2001/03/23 20:19:20 version 1.39.4.1, 2004/11/05 18:16:21
Line 1 
Line 1 
 //BEGIN_LICENSE  //%2003////////////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000 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.
   //
   // Permission is hereby granted, free of charge, to any person obtaining a copy
   // of this software and associated documentation files (the "Software"), to
   // deal in the Software without restriction, including without limitation the
   // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
   // sell copies of the Software, and to permit persons to whom the Software is
   // furnished to do so, subject to the following conditions:
   //
   // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
   // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
   // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
   // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
   // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
   // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
   // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
   // 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.
 // //
 // Permission is hereby granted, free of charge, to any person obtaining a  //%/////////////////////////////////////////////////////////////////////////////
 // copy of this software and associated documentation files (the "Software"),  
 // to deal in the Software without restriction, including without limitation  
 // the rights to use, copy, modify, merge, publish, distribute, sublicense,  
 // and/or sell copies of the Software, and to permit persons to whom the  
 // Software is furnished to do so, subject to the following conditions:  
 //  
 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  
 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  
 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL  
 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  
 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING  
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER  
 // DEALINGS IN THE SOFTWARE.  
 //  
 //END_LICENSE  
 //BEGIN_HISTORY  
 //  
 // Author:  
 //  
 // $Log$  
 // Revision 1.2  2001/03/23 20:19:20  mike  
 // Reformatted documentation. Added a couple of ATTN's  
 //  
 // Revision 1.1  2001/02/18 18:39:06  mike  
 // new  
 //  
 // Revision 1.2  2001/02/18 03:02:58  karl  
 // comment cleanup  
 //  
 // Revision 1.1  2001/02/16 02:07:06  mike  
 // Renamed many classes and headers (using new CIM prefixes).  
 //  
 // Revision 1.3  2001/02/06 17:04:03  karl  
 // add documentation  
 //  
 // Revision 1.2  2001/01/24 13:54:09  karl  
 // Add Doc++ Document Comments  
 //  
 // Revision 1.1.1.1  2001/01/14 19:50:41  mike  
 // Pegasus import  
 //  
 //  
 //END_HISTORY  
  
 #ifndef Pegasus_DateTime_h #ifndef Pegasus_DateTime_h
 #define Pegasus_DateTime_h #define Pegasus_DateTime_h
  
 #include <Pegasus/Common/Config.h> #include <Pegasus/Common/Config.h>
 #include <iostream>  #include <Pegasus/Common/Array.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 };
   
       //
       // 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 date 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 date has the following form:
Line 67 
Line 121 
  
     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 84 
Line 139 
     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 dates.
     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 date 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.  
   
     ATTN: Add inequalities.  
 */ */
 class PEGASUS_COMMON_LINKAGE CIMDateTime class PEGASUS_COMMON_LINKAGE CIMDateTime
 { {
 public: public:
  
     enum { FORMAT_LENGTH = 25 };      /** Creates a new CIMDateTime object with a zero interval value.
       */
     /// CIMDateTime CIMMethod  
     CIMDateTime();     CIMDateTime();
  
     /** CIMDateTime CIMMethod creates the CIM CIMDateTime from a string      /** Creates a new CIMDateTime object from a string constant representing
         constant.          the CIM DateTime-formatted datetime.
           See the class documentation for CIMDateTime for the definition of the
           input string for absolute and interval datetime.
       @param str  String object containing the CIM DateTime-formatted string.
           This must contain twenty-five characters.
     */     */
     CIMDateTime(const char* str);      CIMDateTime(const String & str);
  
     /** CIMDateTime CIMMethod - Creates the CIMDateTime instance from another      /** Creates a CIMDateTime object from another CIMDateTime object.
         CIMDateTime instance      @param x  Specifies the name of the CIMDateTime object to copy.
     */     */
     CIMDateTime(const CIMDateTime& x);     CIMDateTime(const CIMDateTime& x);
  
     /** CIMDateTime method again      /* Creates a CIMDateTime object from from integer.
       @pram microSec is the number of micro Seconds in the epoch 0/0/000 (12 am Jan 1, 1BCE)
       @parm interval tells what type will be created. If true an Interval will be created,
       if false a time stamp will be created.
     */     */
     CIMDateTime& operator=(const CIMDateTime& x);      CIMDateTime(Uint64 microSec, Boolean interval);
  
     /** CIMDateTime isNull method - Tests for an all zero date time      /** 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>         <PRE>
         CIMDateTime dt;              CIMDateTime d1;
         dt.clear();              CIMDateTime d2 = "00000000000000.000000:000";
         assert(dt.isNull());              d1 = d2;
         </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);
  
     /// method getString      /** Returns a string representing the DateTime value of the
     const char* getString() const;          CIMDateTime object.
           @return String representing the DateTime value.
       */
       String toString () const;
  
     /** method set - Sets the date time. Creates the CIMDateTime instance from      /** Sets the date and time in the CIMDateTime object from
         the input string constant which must be      the input parameter.
         in the datetime format.          @param str  String constant containing the datetime
       in the datetime format. This must conform the to formatting rules specified
           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 because the date and time is not
         BadDateTimeFormat          formatted correctly.  See the CIMDateTime class decscription for the
         @exception Throws exception BadDateTimeFormat on format error.          formatting rules.
     */     */
     void set(const char* str);      void set(const String & str);
  
     /// CIMDateTime method clear - Clears the datetime class instance.      /** Clears the datetime class object.  The date time is set to
           a zero interval value.
       */
     void clear();     void clear();
  
     /** CIMDateTime CIMMethod - 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);  
  
 private:      /** Computes the difference in microseconds between two CIMDateTime dates or
           two CIMDateTime intervals.
           @param startTime  Contains the start datetime.
           @param finishTime  Contains the finish datetime.
           @return Integer that contains the difference between the two datetime values
           in microseconds is the epoch (UTC).
           @exception InvalidDateTimeFormatException If one argument uses the interval
           format and the other uses the string format.
   
       *************************************************************************************
                                          Take out
  
     Boolean _set(const char* str);  
     char _rep[FORMAT_LENGTH + 1];  
 };  
  
           @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);
   
       /** 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.
           @return true if the two CIMDateTime objects are equal; otherwise, false.
       */
       Boolean equal (const CIMDateTime & x) const;
   
       /*Converts a CIMDateTime object to it's microsecond representaion*/
       Uint64 toMicroSeconds();
   
        /* Arithmetic operators
       */
       const CIMDateTime operator+(const CIMDateTime & cDT);
       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
       */
       const Boolean operator<(const CIMDateTime & cDT);
       const Boolean operator<=(const CIMDateTime & cDT);
   
       const Boolean operator>(const CIMDateTime & cDT);
       const Boolean operator>=(const CIMDateTime & cDT);
   
       const Boolean operator!=(const CIMDateTime & cDT);
   
   
   
   protected:    //commented out for testing purposes
   
       CIMDateTimeRep* _rep;
       Boolean _set(const String & dateTimeStr);
   
       /*  checks to make sure the format of a particulatr field in the DateTime string is correct.
       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
       */
       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();
   
       /* converts time stamps to thier UTC (GMT) representaion. For intervals it just retruns a copy of
       calling program
        */
       CIMDateTime normalizer();
   
       /* sets the utc offf set of the CIMDateTime object. This method does not change the value
       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);
   
   
   };
   /**
           Add documentation here.
       */
 PEGASUS_COMMON_LINKAGE Boolean operator==( PEGASUS_COMMON_LINKAGE Boolean operator==(
       /**
           Add documentation here.
       */
     const CIMDateTime& x,     const CIMDateTime& x,
       /**
           Add documentation here.
       */
     const CIMDateTime& y);     const CIMDateTime& y);
  
 PEGASUS_COMMON_LINKAGE std::ostream& operator<<(  #define PEGASUS_ARRAY_T CIMDateTime
     std::ostream& os,  # include <Pegasus/Common/ArrayInter.h>
     const CIMDateTime& x);  #undef PEGASUS_ARRAY_T
   
   
   
   
   
  
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END
  


Legend:
Removed from v.1.2  
changed lines
  Added in v.1.39.4.1

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2