1 /* $NetBSD: chiptotime.c,v 1.3 2005/12/11 12:18:19 christos Exp $ */
5 #include <machine/prom.h>
7 #include <lib/libsa/stand.h>
11 * BCD to decimal and decimal to BCD.
13 #define FROMBCD(x) (int)((((unsigned int)(x)) >> 4) * 10 +\
14 (((unsigned int)(x)) & 0xf))
15 #define TOBCD(x) (int)((((unsigned int)(x)) / 10 * 16) +\
16 (((unsigned int)(x)) % 10))
18 #define SECDAY (24 * 60 * 60)
19 #define SECYR (SECDAY * 365)
20 #define LEAPYEAR(y) (((y) & 3) == 0)
24 * This code is defunct after 2068.
25 * Will Unix still be here then??
27 const short dayyr
[12] =
28 {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
31 chiptotime(int sec
, int min
, int hour
, int day
, int mon
, int year
)
40 year
= FROMBCD(year
) + YEAR0
;
44 /* simple sanity checks */
45 if (year
< 70 || mon
< 1 || mon
> 12 || day
< 1 || day
> 31)
48 for (yr
= 70; yr
< year
; yr
++)
49 days
+= LEAPYEAR(yr
) ? 366 : 365;
50 days
+= dayyr
[mon
- 1] + day
- 1;
51 if (LEAPYEAR(yr
) && mon
> 2)
53 /* now have days since Jan 1, 1970; the rest is easy... */
54 return days
* SECDAY
+ hour
* 3600 + min
* 60 + sec
;