Use dos.library/CreateNewProc() instead of alib/CreateNewProcTags()
[tangerine.git] / compiler / clib / mktime.c
blob3e27089af046204d5e5d3410899e6ad0d91e743c
1 /*
2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
3 $Id$
5 Convert a broken-down time into calendar time.
6 */
9 static char monthtable[] =
11 /* JanFebMarAprMayJunJulAugSepOktNov */
12 31,28,31,30,31,30,31,31,30,31,30
15 /*****************************************************************************
17 NAME */
18 #include <time.h>
20 time_t mktime (
22 /* SYNOPSIS */
23 struct tm * utim)
25 /* FUNCTION
26 The mktime() function converts the broken-down time utim to
27 calendar time representation.
29 INPUTS
30 utim - The broken-down time to convert
32 RESULT
33 The converted calendar time
35 NOTES
37 EXAMPLE
38 time_t tt;
39 struct tm * tm;
41 //Computation which results in a tm
42 tm = ...
44 // and convert it
45 tt = mktime (tm);
47 BUGS
48 At the moment sanity check is not performed nor a normalization on the
49 structure is done
51 SEE ALSO
52 time(), ctime(), asctime(), localtime(), gmtime()
54 INTERNALS
55 Rules for leap-years:
57 1. every 4th year is a leap year
59 2. every 100th year is none
61 3. every 400th is one
63 4. 1900 was none, 2000 is one
65 ******************************************************************************/
67 time_t tt;
68 int leapyear,
69 days,
70 year,
73 #warning TODO: Add struct tm normalization code here
75 /* Compute number of days in the years before this year and after 1970.
76 * 1972 is the first leapyear
78 year = utim->tm_year-1;
79 days = 365*(year-69) + (year-68)/4 - year/100 + (year+300)/400;
81 /* Add the day of the months before this month */
82 for (i=0; i<utim->tm_mon; i++)
84 days += monthtable[i];
87 /* Is this a leapyear ? */
88 year = utim->tm_year;
89 leapyear = year%4==0 && (year%100!=0 || (year+300)%400==0);
90 if (leapyear && utim->tm_mon>1) days++;
92 /* Add day in the current month */
93 days += utim->tm_mday - 1;
95 tt = ( (days*24+utim->tm_hour)*60 + utim->tm_min )*60 + utim->tm_sec;
97 return tt;
98 } /* mktime */