1 /**************************************************************************
2 ** (c) Copyright 1999, Andromeda Technology & Automation
3 ***************************************************************************
4 ** MODULE INFORMATION *
5 ***********************
6 ** FILE NAME : date.cpp
7 ** SYSTEM NAME : AXE - Andromeda X-windows Encapsulation
8 ** VERSION NUMBER : $Revision: 1.1 $
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 **************************************************************************/
23 /*****************************
25 Revision 1.1 2002-07-25 08:01:26 arjen
26 First checkin, AXE release 0.2
28 *****************************/
30 static const char *RCSID = "$Id: date.cpp,v 1.1 2002-07-25 08:01:26 arjen Exp $";
35 #include "parsedate.h"
37 static unsigned short mon[] =
45 static char * abr_month_name[] =
48 "Jan", "Feb", "Mar", "Apr",
49 "May", "Jun", "Jul", "Aug",
50 "Sep", "Oct", "Nov", "Dec"
55 struct parseddate *pd;
71 leap--; // But not every century
73 leap++; // except every 4th century
78 unsigned date::DaysInMonth(void)
82 if (month < 1 || month > 12)
90 if (month == 2 && Leap()) // Februari
99 date date::add(date D)
109 while (day > DaysInMonth())
111 day -= DaysInMonth();
123 date date::add(unsigned long days)
125 // Calculate the date <days> days in the future
128 while (days > DaysInMonth())
130 days -= DaysInMonth();
143 date date::subtract(unsigned long days)
145 // Calculate the date <days> days in the past
170 date operator+(date d1, date d2)
176 date operator+(unsigned long l, date d)
182 date operator+(date d, unsigned long l)
188 date operator-(unsigned long l, date d)
194 date operator-(date d, unsigned long l)
206 tp = localtime(&clock);
208 return date(tp->tm_mday, tp->tm_mon+1, tp->tm_year+1900);
211 /*=========================================================================
212 ** NAME : date::julian
217 ** DESCRIPTION : Return the number of days since the base date of the
227 **=========================================================================
230 long date::julian(void)
233 register int yr, mn, dy;
250 return (146097 * cent >> 2) + (1461 * yr >> 2) +
251 (153 * mn + 2) / 5 + dy + 1721119;
255 long operator-(date &d1, date &d2)
257 return d1.julian() - d2.julian();
260 ostream &operator<<(ostream &s, const date &d)
265 s << int(d.day) << "-";
268 s << int(d.month) << "-";
274 istream &operator>>(istream &s, date &d)
279 s >> D >> c >> M >> c >> Y;
295 String date::MonthName(void)
299 return String(abr_month_name[month]);
303 return String("xxx");
307 String date::format(const char *fmt)
317 s = String(int(day)) + String(" ") + MonthName() + String(" ") + String(year);
318 //strftime(buf, 40, fmt, &t);