summaryrefslogtreecommitdiff
path: root/firmware/common/timefuncs.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/common/timefuncs.c')
-rw-r--r--firmware/common/timefuncs.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/firmware/common/timefuncs.c b/firmware/common/timefuncs.c
index fb16f0c253..e48aadd0a2 100644
--- a/firmware/common/timefuncs.c
+++ b/firmware/common/timefuncs.c
@@ -130,3 +130,38 @@ int set_time(const struct tm *tm)
130 return 0; 130 return 0;
131#endif 131#endif
132} 132}
133
134/* mktime() code taken from lynx-2.8.5 source, written
135 by Philippe De Muyter <phdm@macqel.be> */
136time_t mktime(struct tm *t)
137{
138 short month, year;
139 time_t result;
140 static int m_to_d[12] =
141 {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
142
143 month = t->tm_mon;
144 year = t->tm_year + month / 12 + 1900;
145 month %= 12;
146 if (month < 0)
147 {
148 year -= 1;
149 month += 12;
150 }
151 result = (year - 1970) * 365 + (year - 1969) / 4 + m_to_d[month];
152 result = (year - 1970) * 365 + m_to_d[month];
153 if (month <= 1)
154 year -= 1;
155 result += (year - 1968) / 4;
156 result -= (year - 1900) / 100;
157 result += (year - 1600) / 400;
158 result += t->tm_mday;
159 result -= 1;
160 result *= 24;
161 result += t->tm_hour;
162 result *= 60;
163 result += t->tm_min;
164 result *= 60;
165 result += t->tm_sec;
166 return(result);
167}