1 /* $NetBSD: chiptotime.c,v 1.7 2014/11/20 16:34:25 christos Exp $ */
2
3 #include <sys/types.h>
4 #include <dev/clock_subr.h>
5
6 #include <machine/prom.h>
7
8 #include <lib/libsa/stand.h>
9 #include "libsa.h"
10
11 #define YEAR0 68
12
13 /*
14 * This code is defunct after 2068.
15 * Will Unix still be here then??
16 */
17 const short dayyr[12] =
18 {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
19
20 u_long
chiptotime(int sec,int min,int hour,int day,int mon,int year)21 chiptotime(int sec, int min, int hour, int day, int mon, int year)
22 {
23 int days, yr;
24
25 sec = bcdtobin(sec);
26 min = bcdtobin(min);
27 hour = bcdtobin(hour);
28 day = bcdtobin(day);
29 mon = bcdtobin(mon);
30 year = bcdtobin(year) + YEAR0;
31 if (year < 70)
32 year = 70;
33
34 /* simple sanity checks */
35 if (year < 70 || mon < 1 || mon > 12 || day < 1 || day > 31)
36 return (0);
37 days = 0;
38 for (yr = 70; yr < year; yr++)
39 days += days_per_year(yr);
40 days += dayyr[mon - 1] + day - 1;
41 if (is_leap_year(yr) && mon > 2)
42 days++;
43 /* now have days since Jan 1, 1970; the rest is easy... */
44 return days * SECS_PER_DAY + hour * SECS_PER_HOUR
45 + min * SECS_PER_MINUTE + sec;
46 }
47