2 * Copyright 2001-2009 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @file xmltooling/util/DateTime.h
20 * Manipulation of XML date/time data.
23 #ifndef __xmltool_datetime_h__
24 #define __xmltool_datetime_h__
26 #include <xmltooling/base.h>
28 #if defined (_MSC_VER)
29 #pragma warning( push )
30 #pragma warning( disable : 4244 )
33 #include <xercesc/util/XMLDateTime.hpp>
35 #if defined (_MSC_VER)
36 #pragma warning( pop )
42 * Class for manipulating XML date/time information.
44 * This is mostly copied from Xerces-C, but they haven't produced a usable date/time
45 * class, so we had to incorporate a version of it for now. It can't be inherited
46 * since the fields needed are private.
48 class XMLTOOL_API DateTime
53 DateTime(const XMLCh* const);
54 DateTime(time_t epoch, bool duration=false);
55 DateTime(const DateTime&);
56 DateTime& operator=(const DateTime&);
59 void setBuffer(const XMLCh* const);
61 const XMLCh* getRawData() const;
62 const XMLCh* getFormattedString() const;
65 XMLCh* getDateTimeCanonicalRepresentation() const;
66 XMLCh* getTimeCanonicalRepresentation() const;
75 void parseYearMonth();
78 static int compare(const DateTime* const, const DateTime* const);
79 static int compare(const DateTime* const, const DateTime* const, bool);
80 static int compareOrder(const DateTime* const, const DateTime* const);
82 int getYear() const {return fValue[CentYear];}
83 int getMonth() const {return fValue[Month];}
84 int getDay() const {return fValue[Day];}
85 int getHour() const {return fValue[Hour];}
86 int getMinute() const {return fValue[Minute];}
87 int getSecond() const {return fValue[Second];}
88 time_t getEpoch(bool duration=false) const;
99 MiliSecond , //not to be used directly
106 UTC_STD , // set in parse() or normalize()
107 UTC_POS , // set in parse()
108 UTC_NEG // set in parse()
117 static int compareResult(int, int, bool);
118 static void addDuration(DateTime* pDuration, const DateTime* const pBaseDate, int index);
119 static int compareResult(const DateTime* const, const DateTime* const, bool, int);
120 static int getRetVal(int, int);
123 //inline void assertBuffer() const;
124 void copy(const DateTime&);
127 bool isNormalized() const;
132 void getTimeZone(const int);
133 void parseTimeZone();
135 int findUTCSign(const int start);
136 int indexOf(const int start, const int end, const XMLCh ch) const;
137 int parseInt(const int start, const int end) const;
138 int parseIntYear(const int end) const;
139 double parseMiliSecond(const int start, const int end) const;
141 void validateDateTime() const;
143 void fillString(XMLCh*& ptr, valueIndex ind, int expLen) const;
144 int fillYearString(XMLCh*& ptr, valueIndex ind) const;
145 void searchMiliSeconds(XMLCh*& miliStartPtr, XMLCh*& miliEndPtr) const;
147 bool operator==(const DateTime& toCompare) const;
149 static const int DATETIMES[][TOTAL_SIZE];
150 int fValue[TOTAL_SIZE];
151 int fTimeZone[TIMEZONE_ARRAYSIZE];
162 #endif /* __xmltool_datetime_h__ */