2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Convert a human understandable date to a machine form.
10 /*****************************************************************************
13 #include <utility/date.h>
14 #include <proto/utility.h>
16 AROS_LH1(ULONG
, Date2Amiga
,
19 AROS_LHA(struct ClockData
*, date
, A0
),
22 struct UtilityBase
*, UtilityBase
, 21, Utility
)
25 Converts the information given in the struct ClockData *date, into
26 the number of seconds that have past since the 1st of January 1978.
29 date - Contains the information about the time.
32 The number of seconds since 1.1.1978
41 Amiga2Date(), CheckDate()
44 Bit of a hack in the leap year handling.
47 29-10-95 digulla automatically created from
48 utility_lib.fd and clib/utility_protos.h
50 *****************************************************************************/
54 /* This array contains the number of days that have been in the year
55 up to the start of the month. Does not take into account leap years.
57 static const UWORD dayspermonth
[12] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
62 year
= date
->year
- 1978;
64 time
= date
->sec
+ (date
->min
* 60) + (date
->hour
* 3600);
65 time
+= ((date
->mday
- 1) + dayspermonth
[date
->month
- 1]) * 86400;
66 time
+= year
* 31536000;
68 /* How do we calculate leap years? That is a very good question.
69 The year 1978 is NOT a leap year, but 1980 is...
71 I want to arrange it so that the last year of any four year group
72 is a leap year. So the first year I can really deal with is either
73 1977 or 1981. So I choose 1977 (the year I was born in :)
75 Then, to get the number of leap years I divide by 4.
76 However, if year is a year which is a leap year, then this year
77 will not be counted, so I have to check for this.
79 If year % 4 == 3, then we are in a leap year, and if the month
80 is after February, then I can add a leap year.
84 /* stegerg: based on dos.library/strtodate */
88 if (((year
% 400) == 0) || (((year
% 4) == 0) && !((year
% 100) == 0)))
90 /* data->year is a leap year. So dayspermonth table was wrong if
93 if (date
->month
>= 3) time
+= 86400;
98 leaps
= ((year
/ 4) - (year
/ 100) + (year
/ 400) - (494 - 19 + 4));
100 time
+= leaps
* 86400;
105 if( (year
% 4 == 3) && (date
->month
> 2))
108 /* If the year is greater than the year 2100, or it is the
109 year 2100 and after February, then we also have to subtract
110 a leap year, as the year 2100 is NOT a leap year.
112 if( ( year
> 123) || ((year
== 123) && (date
->month
> 2)) )
115 time
+= leaps
* 86400;