| 71 |
theseven |
1 |
/***************************************************************************
|
|
|
2 |
* __________ __ ___.
|
|
|
3 |
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
4 |
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
5 |
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
6 |
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
7 |
* \/ \/ \/ \/ \/
|
|
|
8 |
* $Id: mktime.c 25850 2010-05-06 21:04:40Z kugel $
|
|
|
9 |
*
|
|
|
10 |
* Copyright (C) 2002 by Linus Nielsen Feltzing
|
|
|
11 |
*
|
|
|
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.
|
|
|
16 |
*
|
|
|
17 |
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
18 |
* KIND, either express or implied.
|
|
|
19 |
*
|
|
|
20 |
****************************************************************************/
|
|
|
21 |
|
|
|
22 |
|
|
|
23 |
#include "global.h"
|
|
|
24 |
#include <time.h>
|
|
|
25 |
|
|
|
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)
|
|
|
30 |
{
|
|
|
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};
|
|
|
35 |
|
|
|
36 |
month = t->tm_mon;
|
|
|
37 |
year = t->tm_year + month / 12 + 1900;
|
|
|
38 |
month %= 12;
|
|
|
39 |
if (month < 0)
|
|
|
40 |
{
|
|
|
41 |
year -= 1;
|
|
|
42 |
month += 12;
|
|
|
43 |
}
|
|
|
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);
|
|
|
60 |
}
|
|
|
61 |
#endif
|