00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 #ifndef XML_DATETIME_HPP
00075 #define XML_DATETIME_HPP
00076
00077 #include <util/XercesDefs.hpp>
00078 #include <util/XMLNumber.hpp>
00079 #include <util/XMLString.hpp>
00080 #include <util/XMLUniDefs.hpp>
00081 #include <util/SchemaDateTimeException.hpp>
00082
00083 class XMLDateTime : public XMLNumber
00084 {
00085 public:
00086
00087
00088 enum
00089 {
00090 LESS_THAN = -1,
00091 EQUAL = 0,
00092 GREATER_THAN = 1,
00093 INDETERMINATE = 2
00094 };
00095
00096 enum valueIndex
00097 {
00098 CentYear = 0,
00099 Month ,
00100 Day ,
00101 Hour ,
00102 Minute ,
00103 Second ,
00104 MiliSecond ,
00105 utc ,
00106 TOTAL_SIZE
00107 };
00108
00109 enum utcType
00110 {
00111 UTC_UNKNOWN = 0,
00112 UTC_STD ,
00113 UTC_POS ,
00114 UTC_NEG
00115 };
00116
00117
00118
00119
00120
00121 XMLDateTime();
00122
00123 XMLDateTime(const XMLCh* const);
00124
00125 ~XMLDateTime();
00126
00127 inline void setBuffer(const XMLCh* const);
00128
00129
00130
00131
00132
00133 XMLDateTime(const XMLDateTime&);
00134
00135 XMLDateTime& operator=(const XMLDateTime&);
00136
00137
00138
00139
00140
00141 virtual XMLCh* toString() const;
00142
00143 virtual int getSign() const;
00144
00145
00146
00147
00148
00149 void parseDateTime();
00150
00151 void parseDate();
00152
00153 void parseTime();
00154
00155 void parseDay();
00156
00157 void parseMonth();
00158
00159 void parseYear();
00160
00161 void parseMonthDay();
00162
00163 void parseYearMonth();
00164
00165 void parseDuration();
00166
00167
00168
00169
00170 static int compare(const XMLDateTime* const
00171 , const XMLDateTime* const);
00172
00173 static int compare(const XMLDateTime* const
00174 , const XMLDateTime* const
00175 , bool );
00176
00177 static int compareOrder(const XMLDateTime* const
00178 , const XMLDateTime* const);
00179
00180 private:
00181
00182
00183
00184
00185
00186 enum timezoneIndex
00187 {
00188 hh = 0,
00189 mm ,
00190 TIMEZONE_ARRAYSIZE
00191 };
00192
00193
00194
00195
00196 static int compareResult(short
00197 , short
00198 , bool);
00199
00200 static void addDuration(XMLDateTime* pDuration
00201 , const XMLDateTime* const pBaseDate
00202 , int index);
00203
00204
00205 static int compareResult(const XMLDateTime* const
00206 , const XMLDateTime* const
00207 , bool
00208 , int);
00209
00210 static inline int getRetVal(int, int);
00211
00212
00213
00214
00215
00216 inline void reset();
00217
00218 inline void assertBuffer() const;
00219
00220 inline void copy(const XMLDateTime&);
00221
00222
00223 inline void initParser();
00224
00225 inline bool isNormalized() const;
00226
00227
00228
00229
00230
00231 void getDate();
00232
00233 void getTime();
00234
00235 void getYearMonth();
00236
00237 void getTimeZone(const int);
00238
00239 void parseTimeZone();
00240
00241
00242
00243
00244
00245 int findUTCSign(const int start);
00246
00247 int indexOf(const int start
00248 , const int end
00249 , const XMLCh ch) const;
00250
00251 int parseInt(const int start
00252 , const int end) const;
00253
00254 int parseIntYear(const int end) const;
00255
00256
00257
00258
00259
00260 void validateDateTime() const;
00261
00262 void normalize();
00263
00264
00265
00266
00267 bool operator==(const XMLDateTime& toCompare) const;
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287 int fValue[TOTAL_SIZE];
00288 int fTimeZone[TIMEZONE_ARRAYSIZE];
00289 int fStart;
00290 int fEnd;
00291
00292 XMLCh* fBuffer;
00293
00294 };
00295
00296 inline void XMLDateTime::setBuffer(const XMLCh* const aString)
00297 {
00298 reset();
00299 fBuffer = XMLString::replicate(aString);
00300 fEnd = XMLString::stringLen(fBuffer);
00301
00302 }
00303
00304 inline void XMLDateTime::reset()
00305 {
00306 for ( int i=0; i < TOTAL_SIZE; i++ )
00307 fValue[i] = 0;
00308
00309 fTimeZone[hh] = fTimeZone[mm] = 0;
00310 fStart = fEnd = 0;
00311
00312 if (fBuffer)
00313 {
00314 delete[] fBuffer;
00315 fBuffer = 0;
00316 }
00317
00318 }
00319
00320 inline void XMLDateTime::copy(const XMLDateTime& rhs)
00321 {
00322 for ( int i = 0; i < TOTAL_SIZE; i++ )
00323 fValue[i] = rhs.fValue[i];
00324
00325 fTimeZone[hh] = rhs.fTimeZone[hh];
00326 fTimeZone[mm] = rhs.fTimeZone[mm];
00327 fStart = rhs.fStart;
00328 fEnd = rhs.fEnd;
00329
00330 if (fBuffer)
00331 {
00332 delete[] fBuffer;
00333 fBuffer = 0;
00334 }
00335
00336 if (rhs.fBuffer)
00337 fBuffer = XMLString::replicate(rhs.fBuffer);
00338
00339 }
00340
00341 inline void XMLDateTime::assertBuffer() const
00342 {
00343 if ( ( !fBuffer ) ||
00344 ( fBuffer[0] == chNull ) )
00345 {
00346 ThrowXML(SchemaDateTimeException
00347 , XMLExcepts::DateTime_Assert_Buffer_Fail);
00348 }
00349
00350 }
00351
00352 inline void XMLDateTime::initParser()
00353 {
00354 assertBuffer();
00355 fStart = 0;
00356
00357 }
00358
00359 inline bool XMLDateTime::isNormalized() const
00360 {
00361 return ( fValue[utc] == UTC_STD ? true : false );
00362 }
00363
00364 inline int XMLDateTime::getRetVal(int c1, int c2)
00365 {
00366 if ((c1 == LESS_THAN && c2 == GREATER_THAN) ||
00367 (c1 == GREATER_THAN && c2 == LESS_THAN) )
00368 {
00369 return INDETERMINATE;
00370 }
00371
00372 return ( c1 != INDETERMINATE ) ? c1 : c2;
00373 }
00374
00375 #endif