summaryrefslogtreecommitdiff
path: root/src/time/mktime.c
diff options
context:
space:
mode:
authorVladimir Azarov <avm@intermediate-node.net>2024-10-01 15:47:05 +0200
committerVladimir Azarov <avm@intermediate-node.net>2024-10-01 15:47:05 +0200
commit4abab5ad6c8465a7528ccdd5f49367da05f78bbd (patch)
treeebf009bf1376a5a223a915bc27cbbd791a1316bc /src/time/mktime.c
Initial version
Diffstat (limited to 'src/time/mktime.c')
-rw-r--r--src/time/mktime.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/time/mktime.c b/src/time/mktime.c
new file mode 100644
index 0000000..bad3f07
--- /dev/null
+++ b/src/time/mktime.c
@@ -0,0 +1,28 @@
+#include "time_impl.h"
+#include <errno.h>
+
+time_t mktime(struct tm *tm)
+{
+ struct tm new;
+ long opp;
+ long long t = __tm_to_secs(tm);
+
+ __secs_to_zone(t, 1, &new.tm_isdst, &new.__tm_gmtoff, &opp, &new.__tm_zone);
+
+ if (tm->tm_isdst>=0 && new.tm_isdst!=tm->tm_isdst)
+ t -= opp - new.__tm_gmtoff;
+
+ t -= new.__tm_gmtoff;
+ if ((time_t)t != t) goto error;
+
+ __secs_to_zone(t, 0, &new.tm_isdst, &new.__tm_gmtoff, &opp, &new.__tm_zone);
+
+ if (__secs_to_tm(t + new.__tm_gmtoff, &new) < 0) goto error;
+
+ *tm = new;
+ return t;
+
+error:
+ errno = EOVERFLOW;
+ return -1;
+}