vdk 2.4.0
vdkdate.h
1/*
2 * ===========================
3 * VDK Visual Development Kit
4 * Version 0.4
5 * October 1998
6 * ===========================
7 *
8 * Copyright (C) 1998, Mario Motta
9 * Developed by Mario Motta <mmotta@guest.net>
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details.
20 *
21 * You should have received a copy of the GNU Library General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24 * 02111-130
25 */
26
27#ifndef VDKDATE_H
28#define VDKDATE_H
29
30#include <math.h>
31//#include <iostream.h>
32
33#ifndef CALDATEDEBUG
34#define Assert(condition) /* do nothing */
35#else
36#include <assert.h>
37#define Assert(condition) assert(condition)
38#endif
39
40/* gregorian calendar adopted on oct 15, 1582 */
41#define IGREG (15L+31L*(10L+12L*1582L))
42enum { ddmmyyyy,mmddyyyy };
43/*
44 ===================
45 CALENDAR DATE CLASS
46 ===================
47 */
53{
54protected:
55 int day,month,year;
56 long julian;
57 long Julian(void);
58 void Caldate(void);
59 //friend ostream& operator<<(ostream& os, calendardate& d);
60 char* InternalBuffer();
61 int mode;
62public:
69 calendardate(int mode = mmddyyyy);
79 calendardate(int day, int month, int year, int mode = mmddyyyy):
80 day(day),month(month),year(year),mode(mode)
81 {
82 julian = Julian();
83 }
91 calendardate(long julian, int mode = mmddyyyy) :
92 julian(julian),mode(mode)
93 {
94 Caldate();
95 }
104 calendardate(char* s, int mode = mmddyyyy, char* sep =".-/");
108 virtual ~calendardate() {}
109
111 operator long() { return julian; }
114 int DayIndex() { return (julian+1) % 7; }
118 int Day() { return day; }
122 int Month() { return month; }
126 int Year() { return year; }
133 char* CalendarDate();
138 { return calendardate(julian+d); }
139 calendardate operator-(long d)
140 { return calendardate(julian-d); }
141 long operator-(calendardate& d)
142 { return julian - d.julian; }
143 calendardate& operator+=(long d)
144 { *this = calendardate (julian+d); return *this; }
145 calendardate& operator-=(long d)
146 { *this = calendardate (julian-d); return *this; }
152 operator char*();
157 char* AsString();
159 bool Valid() { return julian >= 0; }
164 { return julian == d.julian; }
165 bool operator<(calendardate& d)
166 { return julian < d.julian; }
167 bool operator!=(calendardate& d)
168 { return julian != d.julian; }
169 bool operator>(calendardate& d)
170 { return julian > d.julian; }
171 bool operator>=(calendardate& d)
172 { return julian >= d.julian; }
173 bool operator<=(calendardate& d)
174 { return julian <= d.julian; }
175};
176/* !
177 leap year
178 */
179inline bool Leap(int y)
180{ return !(y%4) && ( y%100 || !(y%400)); }
186calendardate MakeDate(char* s, int mode = mmddyyyy);
187
188#endif
189
provides a date object
Definition: vdkdate.h:53
calendardate operator+(long d)
Definition: vdkdate.h:137
char * CalendarDate()
Definition: vdkdate.cc:221
int Day()
Definition: vdkdate.h:118
calendardate(long julian, int mode=mmddyyyy)
Definition: vdkdate.h:91
int DayIndex()
Definition: vdkdate.h:114
int Month()
Definition: vdkdate.h:122
virtual ~calendardate()
Definition: vdkdate.h:108
calendardate(int mode=mmddyyyy)
Definition: vdkdate.cc:132
bool operator==(calendardate &d)
Definition: vdkdate.h:163
bool Valid()
Definition: vdkdate.h:159
int Year()
Definition: vdkdate.h:126
calendardate(int day, int month, int year, int mode=mmddyyyy)
Definition: vdkdate.h:79
char * AsString()
Definition: vdkdate.cc:215