2 * Licensed to the University Corporation for Advanced Internet
3 * Development, Inc. (UCAID) under one or more contributor license
4 * agreements. See the NOTICE file distributed with this work for
5 * additional information regarding copyright ownership.
7 * UCAID licenses this file to you under the Apache License,
8 * Version 2.0 (the "License"); you may not use this file except
9 * in compliance with the License. You may obtain a copy of the
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17 * either express or implied. See the License for the specific
18 * language governing permissions and limitations under the License.
22 * @file xmltooling/util/DateTime.h
24 * Manipulation of XML date/time data.
27 #ifndef __xmltool_datetime_h__
28 #define __xmltool_datetime_h__
30 #include <xmltooling/base.h>
32 #if defined (_MSC_VER)
33 #pragma warning( push )
34 #pragma warning( disable : 4244 )
38 #include <xercesc/util/XMLDateTime.hpp>
40 #if defined (_MSC_VER)
41 #pragma warning( pop )
47 * Class for manipulating XML date/time information.
49 * This is mostly copied from Xerces-C, but they haven't produced a usable date/time
50 * class, so we had to incorporate a version of it for now. It can't be inherited
51 * since the fields needed are private.
53 class XMLTOOL_API DateTime
58 DateTime(const XMLCh* const);
59 DateTime(time_t epoch, bool duration=false);
60 DateTime(const DateTime&);
61 DateTime& operator=(const DateTime&);
64 void setBuffer(const XMLCh* const);
66 const XMLCh* getRawData() const;
67 const XMLCh* getFormattedString() const;
70 XMLCh* getDateTimeCanonicalRepresentation() const;
71 XMLCh* getTimeCanonicalRepresentation() const;
80 void parseYearMonth();
83 static int compare(const DateTime* const, const DateTime* const);
84 static int compare(const DateTime* const, const DateTime* const, bool);
85 static int compareOrder(const DateTime* const, const DateTime* const);
87 int getYear() const {return fValue[CentYear];}
88 int getMonth() const {return fValue[Month];}
89 int getDay() const {return fValue[Day];}
90 int getHour() const {return fValue[Hour];}
91 int getMinute() const {return fValue[Minute];}
92 int getSecond() const {return fValue[Second];}
93 time_t getEpoch(bool duration=false) const;
104 MiliSecond , //not to be used directly
111 UTC_STD , // set in parse() or normalize()
112 UTC_POS , // set in parse()
113 UTC_NEG // set in parse()
122 static int compareResult(int, int, bool);
123 static void addDuration(DateTime* pDuration, const DateTime* const pBaseDate, int index);
124 static int compareResult(const DateTime* const, const DateTime* const, bool, int);
125 static int getRetVal(int, int);
128 //inline void assertBuffer() const;
129 void copy(const DateTime&);
132 bool isNormalized() const;
137 void getTimeZone(const int);
138 void parseTimeZone();
140 int findUTCSign(const int start);
141 int indexOf(const int start, const int end, const XMLCh ch) const;
142 int parseInt(const int start, const int end) const;
143 int parseIntYear(const int end) const;
144 double parseMiliSecond(const int start, const int end) const;
146 void validateDateTime() const;
148 void fillString(XMLCh*& ptr, valueIndex ind, int expLen) const;
149 int fillYearString(XMLCh*& ptr, valueIndex ind) const;
150 void searchMiliSeconds(XMLCh*& miliStartPtr, XMLCh*& miliEndPtr) const;
152 bool operator==(const DateTime& toCompare) const;
154 static const int DATETIMES[][TOTAL_SIZE];
155 int fValue[TOTAL_SIZE];
156 int fTimeZone[TIMEZONE_ARRAYSIZE];
167 #endif /* __xmltool_datetime_h__ */