summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Pamment <apamment@yandex.com>2019-05-07 15:28:29 +1000
committerAndrew Pamment <apamment@yandex.com>2019-05-07 15:28:29 +1000
commite99533e6892e0f9c2875e594138a6ecec026214b (patch)
treefc46f3d55e43b41f0047847037cfc508d47953d4
parentfcd59f0ab4084c7c069b256987e507812e945a7d (diff)
Try to get correct UTC time
-rw-r--r--utils/qwknet/qwkscan.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/utils/qwknet/qwkscan.c b/utils/qwknet/qwkscan.c
index ae95e3f..79d5d76 100644
--- a/utils/qwknet/qwkscan.c
+++ b/utils/qwknet/qwkscan.c
@@ -13,6 +13,8 @@
#include "../../deps/jamlib/jam.h"
#include "../../src/inih/ini.h"
+#define TM_YEAR_ORIGIN 1900
+
char *outbound_path;
char *message_base_path;
char *temp_dir;
@@ -21,6 +23,20 @@ char *config_file;
char *hostid;
int format;
+static long difftm(struct tm *a, struct tm *b) {
+ int ay = a->tm_year + (TM_YEAR_ORIGIN - 1);
+ int by = b->tm_year + (TM_YEAR_ORIGIN - 1);
+ long days = (a->tm_yday - b->tm_yday + ((ay >> 2) - (by >> 2)) - (ay / 100 - by / 100) + ((ay / 100 >> 2) - (by / 100 >> 2)) + (long)(ay - by) * 365);
+
+ return (60 * (60 * (24 * days + (a->tm_hour - b->tm_hour)) + (a->tm_min - b->tm_min)) + (a->tm_sec - b->tm_sec));
+}
+
+long gmtoff(time_t value) {
+ struct tm gmt = *gmtime(&value);
+ return difftm(localtime(&value), &gmt);
+}
+
+
int bases_exists = 0;
struct msg_bases {
@@ -314,7 +330,7 @@ int export_messages(int baseno, char *basefilename, int qwkidx) {
memset(qh.Msgnum, ' ', 7);
memcpy(qh.Msgnum, buffer, strlen(buffer));
- datewritten = jmh.DateWritten;
+ datewritten = jmh.DateWritten - gmtoff(jmh.DateWritten);
gmtime_r(&datewritten, &msgtm);