00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00022
00023
00024
00025
00026
00027
00028
00029
00051
00052 #ifndef DATE_INCLUDED
00053 #define DATE_INCLUDED
00054
00055 #include <time.h>
00056 #include <math.h>
00057 #include <stdarg.h>
00058 #include <stdio.h>
00059 #include <limits.h>
00060 #include <string.h>
00061 #include <stdlib.h>
00062 #include <iostream>
00063
00064 #include "Data.h"
00065 #include "Number.h"
00066
00067
00068
00069
00070 class Date : public Data {
00071 public:
00072
00073
00074
00075
00076
00077
00078 enum CALENDAR{ GREGORIAN, BUDDHIST_GREGORIAN, HIJRI };
00079
00080 const static Date MISSING;
00081
00082 private:
00083
00084 const static int _daysInMonth[12];
00085
00086 static bool _displayRangeMeans;
00087 static bool _displayDelimiters;
00088
00089
00090 const static long _IGREG=(15+31L*(10+12L*1582));
00091 const static long _IGREGJULIAN = 2299161;
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 const static long _IHIJRIJULIAN = 1948438;
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 const static unsigned int _DATESTRINGLENGTH=72;
00116 const static double _DAYSINYEAR;
00117 static std::set<std::string> _dateMissingValue;
00118
00119
00120 bool _isMissing;
00121 bool _isApproximate;
00122 bool _isRange;
00123 long _julian;
00124 long _highEndJulian;
00125
00126
00127 static CALENDAR _calendarDisplayType;
00128
00130
00131
00132
00134
00135
00136
00137
00138
00139 long _yearMonthDayToJulian(int yyyy,int mm, int dd);
00140
00141
00142
00143
00144 bool _isLeapYear(int year);
00145
00146
00147
00148 int _getLastDayOfMonth(int year, int month);
00149
00150
00151
00152 void _getYearMonthDay(const long julian, int *yyyy,int *mm,int *dd) const;
00153
00155
00156
00157
00158
00159
00160
00161
00162
00164
00165
00166
00167
00168 long _islamicYearMonthDayToJulian( int yyyy, int mm, int dd) const ;
00169
00170
00171
00172
00173 bool _isIslamicLeapYear(int year) const;
00174
00175
00176
00177
00178 int _lastDayOfIslamicMonth(int year, int month) const ;
00179
00180
00181
00182
00183
00184
00185 void _getIslamicYearMonthDay(const long julian, int *yyyy, int *mm, int *dd) const;
00186
00187 bool _intersectionIsNotNull(const Date& b) const;
00188
00190
00191
00192
00195
00196
00197
00199 bool _hasASCIIDateDelimiter(const char **position);
00200 bool _hasApproximationIndicator(const char **position);
00201 bool _hasCJKCharacterForYear(const char **position);
00202 bool _hasCJKCharacterForMonth(const char **position);
00203 bool _hasCJKCharacterForDay(const char **position);
00204 bool _hasCJKCharacterForArrive(const char **position);
00205 bool _hasCJKCharacterForFullStop(const char **position);
00206 bool _hasCJKCharacterForForwardSlash(const char **position);
00207 bool _hasCJKCharacterForDash(const char **position);
00208 bool _hasCJKCharacterForOpeningSquareBracket(const char **position);
00209 bool _hasCJKCharacterForClosingSquareBracket(const char **position);
00210 bool _hasUnicodeRightArrow(const char **position);
00211 bool _hasKoreanHangulForYear(const char **position);
00212 bool _hasKoreanHangulForMonth(const char **position);
00213 bool _hasKoreanHangulForDay(const char **position);
00214
00215
00216
00217 bool _hasUTF8Character(const char **position,const char *UTF8Character);
00219
00220
00221
00223 bool _hasRangeDelimiter(const char **position,bool startBracketFound);
00224 bool _hasCJKVersionOfGenericDateDelimiter(const char **position);
00225 bool _hasYearDelimiter(const char **position, bool *isProperCJKDate);
00226 bool _hasMonthDelimiter(const char **position);
00227 bool _hasDayDelimiter(const char **position);
00228 bool _hasOpeningBracket(const char **position);
00229 bool _hasClosingBracket(const char **position);
00230 int _getValue(const char **position);
00231 void _skipWhiteSpace(const char **position);
00232
00234
00235
00236
00238
00239
00240
00242
00243
00244
00246 void _readDateString(const char *s);
00247
00249
00250
00251
00253 bool _yearIsValid(int year , const char *dateString );
00254 bool _monthIsValid(int month , const char *dateString );
00255 bool _dayIsValid(int year, int month, int day , const char *dateString );
00256
00257 public:
00258
00259
00260
00261 static void addDateMissingValue(std::string value){ _dateMissingValue.insert(value); }
00262 static bool isMissingValue(std::string value);
00263
00264 Date() { setMissing(); }
00265 Date(const char *d ) { set(d); }
00266 Date(const std::string &d){ set(d.c_str()); }
00267 Date(const Date *d);
00268
00269
00270 bool isMissing( void ) const;
00271 void setMissing( void );
00272 void set(const char *dateString);
00273 void set(const std::string &dateString);
00274 const std::string get( void ) const;
00275
00276
00277 Date& operator++();
00278 Date operator++( int );
00279
00280 Date& operator--();
00281 Date operator--( int );
00282
00283 Date& operator+=( const Number & b );
00284 Date& operator-=( const Number & b );
00285
00286 Date operator+( const Number & b ) const;
00287 Date operator-( const Number & b ) const;
00288 Number operator-( const Date & b ) const;
00289 bool operator<(const Data& b) const;
00290 bool operator==(const Data& b) const;
00291 bool isApproximate( void ) const { return _isApproximate; }
00292 const DATATYPE getDataType( void ) const { return DATE; }
00293 virtual Date* clone() const;
00294
00295
00296 static bool isA(const std::string& s);
00297 static double getDaysInYear(void) { return _DAYSINYEAR; }
00298
00299 static void displayRangeMeans(bool displayThem);
00300 static void displayDelimiters(bool displayThem);
00301 };
00302
00303
00304
00305
00306 std::ostream& operator<<(std::ostream& s,const Date& d);
00307
00308 #endif
00309