1 /**************************************************************************
2 ** (c) Copyright 1999, Andromeda Technology & Automation
3 ***************************************************************************
4 ** MODULE INFORMATION *
5 ***********************
7 ** SYSTEM NAME : AXE - Andromeda X-windows Encapsulation
8 ** VERSION NUMBER : $Revision: 1.3 $
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
22 **************************************************************************/
24 /*****************************
26 Revision 1.3 2002-09-28 06:58:45 arjen
27 Bugfix: conversion of an empty string to a date or hour object
28 now makes the values of such an object 0 (null) instead of giving
30 The class UTC combines the date and hour classes. The most basic
31 functions of the UTC class are now implemented.
32 These include constructors and conversion to and from String objects.
33 New functions: date::proper(), hour::proper() and UTC::proper().
34 Return true if the object holds a proper clock time and/or calendar
35 date; false if at least one value is out of range.
37 Revision 1.2 2002/09/02 06:18:20 arjen
38 Fixed some date and time conversion functions
40 Revision 1.1 2002/07/25 08:01:26 arjen
41 First checkin, AXE release 0.2
43 *****************************/
45 /* static const char *RCSID = "$Id: date.h,v 1.3 2002-09-28 06:58:45 arjen Exp $"; */
54 unsigned char month, day;
59 date add(unsigned long days);
61 date subtract(unsigned long days);
74 date(unsigned d, unsigned m=0, short y=0)
83 bool proper(); // Check wether this is a proper calendar date
85 friend date operator+(date, date);
86 friend date operator+(unsigned long, date);
87 friend date operator+(date, unsigned long);
89 date operator += (date D)
94 date operator += (unsigned long l)
99 date operator ++ () // prefix
104 date operator ++ (int) // postfix
109 friend date operator-(unsigned long, date);
110 friend date operator-(date, unsigned long);
111 friend long operator-(date&, date&);
113 date operator -= (unsigned long l)
118 date operator -- () // prefix
123 date operator -- (int) // postfix
128 // long(date); // Calculate nr. of days since...
130 int operator==(date d)
134 cm = this->year - d.year;
135 cm = (cm != 0) ? cm : this->month - d.month;
136 cm = (cm != 0) ? cm : this->day - d.day;
141 int operator!=(date d)
145 cm = this->year - d.year;
146 cm = (cm != 0) ? cm : this->month - d.month;
147 cm = (cm != 0) ? cm : this->day - d.day;
152 int operator<=(date d)
156 cm = this->year - d.year;
157 cm = (cm != 0) ? cm : this->month - d.month;
158 cm = (cm != 0) ? cm : this->day - d.day;
163 int operator>=(date d)
167 cm = this->year - d.year;
168 cm = (cm != 0) ? cm : this->month - d.month;
169 cm = (cm != 0) ? cm : this->day - d.day;
174 int operator>(date d)
178 cm = this->year - d.year;
179 cm = (cm != 0) ? cm : this->month - d.month;
180 cm = (cm != 0) ? cm : this->day - d.day;
185 int operator<(date d)
189 cm = this->year - d.year;
190 cm = (cm != 0) ? cm : this->month - d.month;
191 cm = (cm != 0) ? cm : this->day - d.day;
208 String MonthName(void);
217 unsigned DaysInMonth();
221 return julian() % 7 + 1;
223 // TODO:YearDay WeekDay WeekNumber DayName
225 // date operator*(double)
226 // date& operator*=(double)
227 // date operator/(double)
228 // date& operator/=(double)
230 friend std::ostream& operator<<(std::ostream&, const date&);
231 friend std::istream& operator>>(std::istream&, date&);
233 String format(const char *fmt = "%F");
236 date today(bool localtime = true);
241 short minutes, seconds;
249 cm = this->hours - h.hours;
250 cm = (cm != 0) ? cm : this->minutes - h.minutes;
251 cm = (cm != 0) ? cm : this->seconds - h.seconds;
268 hour(int hr, short minute, short sec)
278 minutes = sec / 60 % 60;
284 bool proper(); // Check wether this is a proper clock time
303 bool operator==(hour h)
305 return compare(h) == 0;
308 bool operator!=(hour h)
310 return compare(h) != 0;
313 bool operator<(hour h)
315 return compare(h) < 0;
318 bool operator>(hour h)
320 return compare(h) > 0;
323 bool operator<=(hour h)
325 return compare(h) <= 0;
328 bool operator>=(hour h)
330 return compare(h) >= 0;
333 friend hour operator+(hour, hour);
334 friend hour operator+(hour, long);
335 hour operator += (hour h);
337 hour operator ++ () // prefix
342 hour operator ++ (int) // postfix
347 friend hour operator-(hour, hour);
348 friend hour operator-(hour, long);
349 hour operator -= (hour h);
351 hour operator -- () // prefix
356 hour operator -- (int) // postfix
362 friend std::ostream& operator<<(std::ostream &, const hour &);
363 friend std::istream& operator>>(std::istream &, hour &);
365 String format(const char *fmt = "%T");
368 hour now(bool localtime = true);
379 /* Leave everything to the default hour and date constructors */
383 UTC(date dt, hour tm)
401 return d.proper() && t.proper();
404 bool operator==(UTC u)
406 return d == u.d && t == u.t;
409 bool operator!=(UTC u)
411 return d != u.d || t != u.t;
414 bool operator<=(UTC u)
426 bool operator<(UTC u)
438 bool operator>=(UTC u)
450 bool operator>(UTC u)
462 friend UTC operator+(UTC &, UTC &);
463 UTC operator += (UTC h);
465 friend std::ostream& operator<<(std::ostream &, const UTC &);
466 friend std::istream& operator>>(std::istream &, UTC &);
468 String format(const char *fmt = "%F %T");
471 UTC Now(bool localtime = true);
473 #endif /* AXE_DATE_H */