summaryrefslogtreecommitdiff
path: root/src/time/__tm_to_secs.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2013-07-17 05:24:50 -0400
committerRich Felker <dalias@aerifal.cx>2013-07-17 05:24:50 -0400
commit1cc81f5cb0df2b66a795ff0c26d7bbc4d16e13c6 (patch)
treed8839fbfd8cb1fb5658394cad6a6a06688ab6a1b /src/time/__tm_to_secs.c
parentf1292e3d28309bbc81f61671164843cec4319bfa (diff)
downloadmusl-1cc81f5cb0df2b66a795ff0c26d7bbc4d16e13c6.tar.gz
the big time handling overhaul
this commit has two major user-visible parts: zoneinfo-format time zones are now supported, and overflow handling is intended to be complete in the sense that all functions return a correct result if and only if the result fits in the destination type, and otherwise return an error. also, some noticable bugs in the way DST detection and normalization worked have been fixed, and performance may be better than before, but it has not been tested.
Diffstat (limited to 'src/time/__tm_to_secs.c')
-rw-r--r--src/time/__tm_to_secs.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/time/__tm_to_secs.c b/src/time/__tm_to_secs.c
new file mode 100644
index 00000000..c29fa985
--- /dev/null
+++ b/src/time/__tm_to_secs.c
@@ -0,0 +1,24 @@
+#include "time_impl.h"
+
+long long __tm_to_secs(const struct tm *tm)
+{
+ int is_leap;
+ long long year = tm->tm_year;
+ int month = tm->tm_mon;
+ if (month >= 12 || month < 0) {
+ int adj = month / 12;
+ month %= 12;
+ if (month < 0) {
+ adj--;
+ month += 12;
+ }
+ year += adj;
+ }
+ long long t = __year_to_secs(year, &is_leap);
+ t += __month_to_secs(month, is_leap);
+ t += 86400LL * (tm->tm_mday-1);
+ t += 3600LL * tm->tm_hour;
+ t += 60LL * tm->tm_min;
+ t += tm->tm_sec;
+ return t;
+}