vdk 2.4.0
|
00001 /* 00002 * =========================== 00003 * VDK Visual Development Kit 00004 * Version 0.4 00005 * October 1998 00006 * =========================== 00007 * 00008 * Copyright (C) 1998, Mario Motta 00009 * Developed by Mario Motta <mmotta@guest.net> 00010 * 00011 * This library is free software; you can redistribute it and/or 00012 * modify it under the terms of the GNU Library General Public 00013 * License as published by the Free Software Foundation; either 00014 * version 2 of the License, or (at your option) any later version. 00015 * 00016 * This library is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 * Library General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Library General Public 00022 * License along with this library; if not, write to the Free Software 00023 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00024 * 02111-130 00025 */ 00026 00027 #ifndef VDKDATE_H 00028 #define VDKDATE_H 00029 00030 #include <math.h> 00031 //#include <iostream.h> 00032 00033 #ifndef CALDATEDEBUG 00034 #define Assert(condition) /* do nothing */ 00035 #else 00036 #include <assert.h> 00037 #define Assert(condition) assert(condition) 00038 #endif 00039 00040 /* gregorian calendar adopted on oct 15, 1582 */ 00041 #define IGREG (15L+31L*(10L+12L*1582L)) 00042 enum { ddmmyyyy,mmddyyyy }; 00043 /* 00044 =================== 00045 CALENDAR DATE CLASS 00046 =================== 00047 */ 00052 class calendardate 00053 { 00054 protected: 00055 int day,month,year; 00056 long julian; 00057 long Julian(void); 00058 void Caldate(void); 00059 //friend ostream& operator<<(ostream& os, calendardate& d); 00060 char* InternalBuffer(); 00061 int mode; 00062 public: 00069 calendardate(int mode = mmddyyyy); 00079 calendardate(int day, int month, int year, int mode = mmddyyyy): 00080 day(day),month(month),year(year),mode(mode) 00081 { 00082 julian = Julian(); 00083 } 00091 calendardate(long julian, int mode = mmddyyyy) : 00092 julian(julian),mode(mode) 00093 { 00094 Caldate(); 00095 } 00104 calendardate(char* s, int mode = mmddyyyy, char* sep =".-/"); 00108 virtual ~calendardate() {} 00109 00111 operator long() { return julian; } 00114 int DayIndex() { return (julian+1) % 7; } 00118 int Day() { return day; } 00122 int Month() { return month; } 00126 int Year() { return year; } 00133 char* CalendarDate(); 00137 calendardate operator+(long d) 00138 { return calendardate(julian+d); } 00139 calendardate operator-(long d) 00140 { return calendardate(julian-d); } 00141 long operator-(calendardate& d) 00142 { return julian - d.julian; } 00143 calendardate& operator+=(long d) 00144 { *this = calendardate (julian+d); return *this; } 00145 calendardate& operator-=(long d) 00146 { *this = calendardate (julian-d); return *this; } 00152 operator char*(); 00157 char* AsString(); 00159 bool Valid() { return julian >= 0; } 00163 bool operator==(calendardate& d) 00164 { return julian == d.julian; } 00165 bool operator<(calendardate& d) 00166 { return julian < d.julian; } 00167 bool operator!=(calendardate& d) 00168 { return julian != d.julian; } 00169 bool operator>(calendardate& d) 00170 { return julian > d.julian; } 00171 bool operator>=(calendardate& d) 00172 { return julian >= d.julian; } 00173 bool operator<=(calendardate& d) 00174 { return julian <= d.julian; } 00175 }; 00176 /* ! 00177 leap year 00178 */ 00179 inline bool Leap(int y) 00180 { return !(y%4) && ( y%100 || !(y%400)); } 00186 calendardate MakeDate(char* s, int mode = mmddyyyy); 00187 00188 #endif 00189