More nice apostrophes
[kugel-rb.git] / firmware / libc / mktime.c
bloba52381ede583bb0cdef53981397f12d9cb7648ee
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
23 #include <time.h>
24 #include "config.h"
26 #if CONFIG_RTC
27 /* mktime() code taken from lynx-2.8.5 source, written
28 by Philippe De Muyter <phdm@macqel.be> */
29 time_t mktime(struct tm *t)
31 short month, year;
32 time_t result;
33 static int m_to_d[12] =
34 {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
36 month = t->tm_mon;
37 year = t->tm_year + month / 12 + 1900;
38 month %= 12;
39 if (month < 0)
41 year -= 1;
42 month += 12;
44 result = (year - 1970) * 365 + (year - 1969) / 4 + m_to_d[month];
45 result = (year - 1970) * 365 + m_to_d[month];
46 if (month <= 1)
47 year -= 1;
48 result += (year - 1968) / 4;
49 result -= (year - 1900) / 100;
50 result += (year - 1600) / 400;
51 result += t->tm_mday;
52 result -= 1;
53 result *= 24;
54 result += t->tm_hour;
55 result *= 60;
56 result += t->tm_min;
57 result *= 60;
58 result += t->tm_sec;
59 return(result);
61 #endif