From dd425c8ef8952d3a8553029dbbc7d89abd0908df Mon Sep 17 00:00:00 2001 From: Jonathan McCrohan Date: Mon, 2 Apr 2012 01:12:52 +0100 Subject: modbuslog: use time.h functions to manipulate date Fixes issue that became apparent after switch to DST --- src/modbuslog.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/modbuslog.c b/src/modbuslog.c index 43d102d..d967e4a 100644 --- a/src/modbuslog.c +++ b/src/modbuslog.c @@ -156,7 +156,9 @@ int main(int argc, char *argv[]) { select(0, NULL, NULL, NULL, NULL); time_t t = time(NULL); - time_t unixtime_min = (((int) t) / 60 * 60); + struct tm unixtime_min_time_t = *gmtime (&t); + unixtime_min_time_t.tm_sec = 0; + time_t unixtime_min = mktime(&unixtime_min_time_t); //int unixtime = (int) t; //printf("%d\n", unixtime); @@ -281,9 +283,12 @@ int main(int argc, char *argv[]) { //MODBUS_SET_INT16_TO_INT8(tab_int8, index, value); // round forward to next midnight - time_t unixtime_day = ((((int) t) / 86400 * 86400) + 86400); - - struct tm midnight = *localtime(&unixtime_day); + struct tm midnight = *localtime(&t); + midnight.tm_hour = 0; + midnight.tm_min = 0; + midnight.tm_sec = 0; + midnight.tm_mday += 1; + mktime (&midnight); char log_filename[50]; -- cgit v1.2.3