diff options
-rw-r--r-- | src/modbuslog.c | 13 |
1 files changed, 9 insertions, 4 deletions
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]; |