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 kumpf 1.28 /* ATTN: P3 KS. This simply returns a string whether the datetime is a
156 real value or the NULL value. It is up to the user to test. Should
157 this be modified so we do something like an interupt on NULL?
158 */
|
159 karl 1.12 /** getString - Returns the string representing the DateTime value of the
160 CIMDateTime Object.
161 */
|
162 mike 1.10 const char* getString() const;
163
164 /** method set - Sets the date time. Creates the CIMDateTime instance from
165 the input string constant which must be
166 in the datetime format.
167
168 <PRE>
169 CIMDateTime dt;
170 dt.set("19991224120000.000000+360");
171 </PRE>
172
173 @return On format error, CIMDateTime set throws the exception
174 BadDateTimeFormat
175 @exception Throws exception BadDateTimeFormat on format error.
176 */
177 void set(const char* str);
178
|
179 karl 1.12 /** clear - Clears the datetime class instance. The date time is set to our
180 defintion of NULL, absolute zero date time.
181 */
|
182 mike 1.10 void clear();
183
|
184 kumpf 1.24 /** Makes a deep copy (clone) of the given object. */
185 CIMDateTime clone() const;
186
|
187 kumpf 1.14 /**
|
188 kumpf 1.23 Get current time as CIMDateTime. The time returned is the local time.
|
189 kumpf 1.14
190 @return CIMDateTime Contains the current datetime as a CIMDateTime object.
191
192 Note: Original code was taken from OperationSystem::getLocalDateTime()
193 */
194 static CIMDateTime getCurrentDateTime();
195
196 /**
|
197 kumpf 1.22 Get the difference between two CIMDateTimes. This function computes the
198 difference between two datetimes or between two intervals. The result
199 is truncated and returned as the number of seconds.
|
200 kumpf 1.14
201 @param startTime Contains the start time.
202
203 @param finishTime Contains the finish time.
204
205 @return difference Difference between the two datetimes in seconds.
206
207 @throws BadFormat
208
209 */
|
210 kumpf 1.22 static Sint64 getDifference(CIMDateTime startTime, CIMDateTime finishTime);
|
211 kumpf 1.14
212 /**
213 Checks whether the datetime is an interval.
214
215 @return isInterval True if the datetime is an interval, else false
216 */
217 Boolean isInterval();
218
|
219 kumpf 1.17 private:
|
220 kumpf 1.21
|
221 kumpf 1.24 CIMDateTimeRep* _rep;
|
222 kumpf 1.21
|
223 mike 1.10 Boolean _set(const char* str);
|
224 kumpf 1.14
225 /**
226 This function extracts the different components of the date and time
227 from the string passed and assigns it to the tm structure.
228
229 @param dateTimeStr Contains the string to be assigned.
230
231 @param tm Contains the tm structure to be updated.
232 */
|
233 mday 1.20 static void formatDateTime(char* dateTime, tm* tm);
|
234 kumpf 1.17
|
235 kumpf 1.28 // ATTN
236 /** CIMDateTime - Friend operator Test for CIMDateTime
|
237 kumpf 1.17 equality
238 */
239 PEGASUS_COMMON_LINKAGE friend Boolean operator==(
240 const CIMDateTime& x,
241 const CIMDateTime& y);
|
242 mike 1.10 };
243
244 PEGASUS_COMMON_LINKAGE Boolean operator==(
245 const CIMDateTime& x,
246 const CIMDateTime& y);
247
|
248 kumpf 1.17 #ifdef PEGASUS_INTERNALONLY
|
249 mike 1.10 PEGASUS_COMMON_LINKAGE PEGASUS_STD(ostream)& operator<<(
250 PEGASUS_STD(ostream)& os,
251 const CIMDateTime& x);
|
252 kumpf 1.17 #endif
|
253 mike 1.10
254 #define PEGASUS_ARRAY_T CIMDateTime
|
255 kumpf 1.25 # include <Pegasus/Common/ArrayInter.h>
|
256 mike 1.10 #undef PEGASUS_ARRAY_T
257
258 PEGASUS_NAMESPACE_END
259
260 #endif /* Pegasus_DateTime_h */
|