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

  1 mike  1.10 //%/////////////////////////////////////////////////////////////////////////////
  2            //
  3 kumpf 1.26 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
  4            // The Open Group, Tivoli Systems
  5 mike  1.10 //
  6            // Permission is hereby granted, free of charge, to any person obtaining a copy
  7 kumpf 1.26 // of this software and associated documentation files (the "Software"), to
  8            // deal in the Software without restriction, including without limitation the
  9            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 10 mike  1.10 // sell copies of the Software, and to permit persons to whom the Software is
 11            // furnished to do so, subject to the following conditions:
 12            // 
 13 kumpf 1.26 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 14 mike  1.10 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 15            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 16 kumpf 1.26 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 17            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 18            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 19 mike  1.10 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 20            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 21            //
 22            //==============================================================================
 23            //
 24            // Author: Mike Brasher (mbrasher@bmc.com)
 25            //
 26 karl  1.12 // Modified By: Karl Schopmeyer(k.schopmeyer@opengroup.org)
 27 kumpf 1.17 //              Sushma Fernandes, Hewlett Packard Company 
 28            //                  (sushma_fernandes@hp.com)
 29            //              Roger Kumpf, Hewlett Packard Company (roger_kumpf@hp.com)
 30 kumpf 1.14 //
 31 mike  1.10 //%/////////////////////////////////////////////////////////////////////////////
 32            
 33            #ifndef Pegasus_DateTime_h
 34            #define Pegasus_DateTime_h
 35            
 36            #include <Pegasus/Common/Config.h>
 37            #include <Pegasus/Common/Array.h>
 38 mday  1.20 #include <time.h>
 39 kumpf 1.17 #ifdef PEGASUS_INTERNALONLY
 40 mike  1.10 #include <iostream>
 41 kumpf 1.17 #endif
 42 kumpf 1.14 
 43 mike  1.10 PEGASUS_NAMESPACE_BEGIN
 44            
 45 karl  1.16 /* ATTN: P3. KS Several functions should be added to this class for datetime manipulation
 46 kumpf 1.14    including get and set each subcomponent (year, month, etc), test for equality,
 47 karl  1.12    create intervals from absolutes, possibly gett current time, Note that
 48               the Java rep is probably tostring, not get string, 
 49            */
 50            
 51 kumpf 1.24 class CIMDateTimeRep;
 52            
 53 mike  1.10 /**
 54                The CIMDateTime class represents the CIM datetime data type as a C++ class 
 55                CIMDateTime. A CIM datetime may contain a date or an interval. CIMDateTime 
 56                is an intrinsic CIM data type which represents the time as a formated 
 57                fixedplength string.
 58            
 59                <PRE>
 60                A date has the following form:
 61            	yyyymmddhhmmss.mmmmmmsutc
 62            
 63                Where
 64            
 65            	yyyy = year (0-1999)
 66            	mm = month (1-12)
 67            	dd = day (1-31)
 68            	hh = hour (0-23)
 69            	mm = minute (0-59)
 70            	ss = second (0-59)
 71            	mmmmmm = microseconds.
 72            	s = '+' or '-' to represent the UTC sign.
 73            	utc = UTC offset (same as GMT offset).
 74 mike  1.10 
 75                An interval has the following form:
 76            
 77            	ddddddddhhmmss.mmmmmm:000
 78            
 79                Where
 80            
 81            	dddddddd = days
 82 kumpf 1.13 	hh = hours (0-23)
 83            	mm = minutes (0-59)
 84            	ss = seconds (0-59)
 85 mike  1.10 	mmmmmm = microseconds
 86                </PRE>
 87            
 88                Note that intervals always end in ":000" (this is how they
 89                are distinguished from dates).
 90            
 91                Intervals are really durations since they do not specify a start and
 92                end time (as one expects when speaking about an interval). It is
 93                better to think of an interval as specifying time elapsed since
 94                some event.
 95            
 96                CIMDateTime objects are constructed from C character strings or from
 97                other CIMDateTime objects. These character strings must be exactly
 98                twenty-five characters and conform to one of the forms idententified
 99                above.
100            
101                CIMDateTime objects which are not explicitly initialized will be
102                implicitly initialized with the null time interval:
103            
104            	00000000000000.000000:000
105            
106 mike  1.10     Instances can be tested for nullness with the isNull() method.
107            */
108            class PEGASUS_COMMON_LINKAGE CIMDateTime
109            {
110            public:
111            
112 karl  1.12     /** Create a new CIMDateTime object with NULL DateTime definition.
113                */
114 mike  1.10     CIMDateTime();
115            
116 karl  1.12     /** CIMDateTime - Creat a CIM CIMDateTime instance from a string 
117 mike  1.10 	constant representing the CIM DateTime formatted datetime
118 karl  1.12         See the class documentation for CIMDateTime for the defintion of the
119                    input string for absolute and interval datetime.
120 mike  1.10 	@param str String object containing the CIM DateTime formatted string
121                */
122                CIMDateTime(const char* str);
123            
124 karl  1.12     /** CIMDateTime Create a CIMDateTime instance from another 
125 mike  1.10 	CIMDateTime object
126            	@param x CIMDateTime object to be copied.
127                */
128                CIMDateTime(const CIMDateTime& x);
129            
130 karl  1.12     /** DateTime Destructor. */
131 kumpf 1.17     ~CIMDateTime();
132 mike  1.10 
133 karl  1.12     /**  Assign one DateTime object to another
134                @param - The DateTime Object to assign
135                <pre>
136                CIMDateTime d1;
137                CIMDateTime d2 = "00000000000000.000000:000";
138                d1 = d1;
139                </pre>
140 mike  1.10     */
141                CIMDateTime& operator=(const CIMDateTime& x);
142            
143 karl  1.12     /** CIMDateTime isNull method - Tests for an all zero date time. Note that
144                    today this function checks for absolute datetime == zero, not interval.
145 mike  1.10 	<PRE>
146            	CIMDateTime dt;
147            	dt.clear();
148                	assert(dt.isNull());
149                	</PRE>
150            	@return This method returns true of the contents are
151            	"00000000000000.000000:000". Else it returns false
152                */
153                Boolean isNull() const;
154            
155 karl  1.12     /** getString - Returns the string representing the DateTime value of the
156                    CIMDateTime Object.
157                    ATTN: P3 KS.  This simply returns a string whether the datetime is a
158                    real value or the NULL value.  It is up to the user to test.  Should
159                    this be modified so we do something like an interupt on NULL?
160                */
161 mike  1.10     const char* getString() const;
162            
163                /** method set - Sets the date time. Creates the CIMDateTime instance from 
164            	the input string constant which must be
165            	in the datetime format.
166            
167            	    <PRE>
168            	    CIMDateTime dt;
169            	    dt.set("19991224120000.000000+360");
170            	    </PRE>
171            
172            	@return On format error, CIMDateTime set throws the exception 
173            	BadDateTimeFormat
174            	@exception Throws exception BadDateTimeFormat on format error.
175                */
176                void set(const char* str);
177            
178 karl  1.12     /**  clear - Clears the datetime class instance. The date time is set to our
179                    defintion of NULL, absolute zero date time.
180                */
181 mike  1.10     void clear();
182            
183 kumpf 1.24     /** Makes a deep copy (clone) of the given object. */
184                CIMDateTime clone() const;
185            
186 kumpf 1.14     /**
187 kumpf 1.23     Get current time as CIMDateTime. The time returned is the local time.
188 kumpf 1.14 
189                @return CIMDateTime   Contains the current datetime as a CIMDateTime object.
190            
191                Note: Original code was taken from OperationSystem::getLocalDateTime()
192                */
193                static CIMDateTime getCurrentDateTime();
194            
195                /**
196 kumpf 1.22     Get the difference between two CIMDateTimes. This function computes the 
197                difference between two datetimes or between two intervals. The result 
198                is truncated and returned as the number of seconds.
199 kumpf 1.14 
200                @param startTime     Contains the start time.
201            
202                @param finishTime    Contains the finish time.
203            
204                @return difference   Difference between the two datetimes in seconds.
205                
206                @throws BadFormat
207            
208                */
209 kumpf 1.22     static Sint64 getDifference(CIMDateTime startTime, CIMDateTime finishTime);
210 kumpf 1.14  
211                /**
212                Checks whether the datetime is an interval.
213            
214                @return isInterval  True if the datetime is an interval, else false
215                */
216                Boolean isInterval();
217            
218 kumpf 1.17 private:
219 kumpf 1.21 
220 kumpf 1.24     CIMDateTimeRep* _rep;
221 kumpf 1.21 
222 mike  1.10     Boolean _set(const char* str);
223 kumpf 1.14 
224                /**
225                   This function extracts the different components of the date and time
226                   from the string passed and assigns it to the tm structure.
227            
228                   @param dateTimeStr  Contains the string to be assigned.
229            
230                   @param tm           Contains the tm structure to be updated.
231                */
232 mday  1.20     static void formatDateTime(char* dateTime, tm* tm);
233 kumpf 1.17 
234                /** CIMDateTime - ATTN: Friend operator Test for CIMDateTime 
235            	equality
236                */
237                PEGASUS_COMMON_LINKAGE friend Boolean operator==(
238            	const CIMDateTime& x,
239            	const CIMDateTime& y);
240 mike  1.10 };
241            
242            PEGASUS_COMMON_LINKAGE Boolean operator==(
243                const CIMDateTime& x, 
244                const CIMDateTime& y);
245            
246 kumpf 1.17 #ifdef PEGASUS_INTERNALONLY
247 mike  1.10 PEGASUS_COMMON_LINKAGE PEGASUS_STD(ostream)& operator<<(
248                PEGASUS_STD(ostream)& os, 
249                const CIMDateTime& x);
250 kumpf 1.17 #endif
251 mike  1.10 
252            #define PEGASUS_ARRAY_T CIMDateTime
253 kumpf 1.25 # include <Pegasus/Common/ArrayInter.h>
254 mike  1.10 #undef PEGASUS_ARRAY_T
255            
256            PEGASUS_NAMESPACE_END
257            
258            #endif /* Pegasus_DateTime_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2