1a4f6b0b61982ed21db65ffef6c980be6fede2a2
[AXE.git] / src / date.h
1 /**************************************************************************
2 **  (c) Copyright 1999, Andromeda Technology & Automation
3 ***************************************************************************
4 ** MODULE INFORMATION *
5 ***********************
6 **      FILE NAME      : date.h
7 **      SYSTEM NAME    : AXE - Andromeda X-windows Encapsulation
8 **      VERSION NUMBER : $Revision: 1.1 $
9 **
10 **  DESCRIPTION      :  
11 **
12 **  EXPORTED OBJECTS : 
13 **  LOCAL    OBJECTS : 
14 **  MODULES  USED    :
15 ***************************************************************************
16 **  ADMINISTRATIVE INFORMATION *
17 ********************************
18 **      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
19 **      CREATION DATE   : Feb 06, 1998
20 **      LAST UPDATE     : Oct 16, 1999
21 **      MODIFICATIONS   : 
22 **************************************************************************/
23
24 /*****************************
25    $Log: date.h,v $
26    Revision 1.1  2002-07-25 08:01:26  arjen
27    First checkin, AXE release 0.2
28
29 *****************************/
30
31 /* static const char *RCSID = "$Id: date.h,v 1.1 2002-07-25 08:01:26 arjen Exp $"; */
32
33 #ifndef AXE_DATE_H
34 #define AXE_DATE_H
35
36 #include "String.h"
37
38 class date
39 {
40    unsigned char  month, day;
41    short year;
42
43    long julian();
44    date add(date D);
45    date add(unsigned long days);
46
47    date subtract(unsigned long days);
48
49 public:
50
51    date()
52    {
53       month = 0;
54       day   = 0;
55       year  = 0;
56    }       
57    
58    date(unsigned  d, unsigned  m=0, short y=0)
59    {
60       day   = d;
61       month = m;
62       year  = y;
63    }
64
65    date(String s);
66
67    friend date operator+(date, date);
68    friend date operator+(unsigned long,  date);
69    friend date operator+(date,  unsigned long);
70
71    date operator += (date D)
72    {
73       return add(D);
74    }
75
76    date operator += (unsigned long l)
77    {
78       return add(l);
79    }
80
81    friend date operator-(unsigned long,  date);
82    friend date operator-(date,  unsigned long);
83    friend long operator-(date&, date&);
84
85    date operator -= (unsigned long l)
86    {
87       return subtract(l);
88    }
89
90 //   long(date);        // Calculate nr. of days since...
91
92    int operator==(date d)
93    {
94       register int cm;
95       
96       cm = this->year - d.year;
97       cm = (cm != 0) ? cm : this->month - d.month;
98       cm = (cm != 0) ? cm : this->day   - d.day;
99       
100       return cm == 0;
101    }
102
103    int operator!=(date d)
104    {
105       register int cm;
106       
107       cm = this->year - d.year;
108       cm = (cm != 0) ? cm : this->month - d.month;
109       cm = (cm != 0) ? cm : this->day   - d.day;
110       
111       return cm != 0;
112    }             
113    
114    int operator<=(date d)
115    {
116       register int cm;
117       
118       cm = this->year - d.year;
119       cm = (cm != 0) ? cm : this->month - d.month;
120       cm = (cm != 0) ? cm : this->day   - d.day;
121       
122       return cm <= 0;
123    }             
124    
125    int operator>=(date d)
126    {
127       register int cm;
128       
129       cm = this->year - d.year;
130       cm = (cm != 0) ? cm : this->month - d.month;
131       cm = (cm != 0) ? cm : this->day   - d.day;
132       
133       return cm >= 0;
134    }             
135    
136    int operator>(date d)
137    {
138       register int cm;
139       
140       cm = this->year - d.year;
141       cm = (cm != 0) ? cm : this->month - d.month;
142       cm = (cm != 0) ? cm : this->day   - d.day;
143       
144       return cm > 0;
145    }             
146    
147    int operator<(date d)
148    {
149       register int cm;
150       
151       cm = this->year - d.year;
152       cm = (cm != 0) ? cm : this->month - d.month;
153       cm = (cm != 0) ? cm : this->day   - d.day;
154       
155       return cm < 0;
156    }
157
158    //  Attributes.
159
160    unsigned Day()
161    {
162       return day;
163    }
164
165    unsigned Month()
166    {
167       return month;
168    }
169
170    String MonthName(void);
171
172    int Year()
173    {
174       return year;
175    }
176    //  Operations.
177
178    int Leap(void);
179    unsigned DaysInMonth();
180
181 //   date operator*(double)
182 //   date& operator*=(double)
183 //   date operator/(double)
184 //   date& operator/=(double)
185
186    friend ostream& operator<<(ostream&, const date&);
187    friend istream& operator>>(istream&, date&);
188
189    String format(const char *fmt = "%x");
190 };
191
192 date today(void); 
193
194 class hour
195 {
196    int   hours;
197    short minutes, seconds;
198
199 public:
200
201    hour()
202    {
203       hours = 0;
204       minutes = 0;
205       seconds = 0;
206    }
207
208    hour(int hr, short minute, short sec)
209    {
210       hours = hr;
211       minutes = minute;
212       seconds = sec;
213    }
214
215    hour(String s);
216
217    friend hour operator+(hour &, hour &);
218    hour operator += (hour h);
219    friend hour operator-(hour &, hour &);
220
221    friend ostream& operator<<(ostream &, const hour &);
222 };
223
224 class UTC
225 {
226    hour  t;
227    date  d;
228
229 public:
230
231    UTC()
232    {
233    }
234 };
235
236 #endif /* AXE_DATE_H */