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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2