From 03f23c43399beef3fa8f4e183a5ba0f8948878c0 Mon Sep 17 00:00:00 2001 From: kichikuou Date: Sun, 8 May 2022 14:20:13 +0900 Subject: [PATCH] Fix date/time getter functions Values returned by SACT2.System_GetDate etc. should correspond to the Windows SYSTEMTIME structure, not struct tm. This also fixes a bug where get_time() returns a value greater than 60 for `sec`. --- src/hll/File.c | 2 +- src/util.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hll/File.c b/src/hll/File.c index a68f2f4..5c86488 100644 --- a/src/hll/File.c +++ b/src/hll/File.c @@ -175,7 +175,7 @@ static int File_GetTime(struct string *filename, struct page **page) } date[0].i = tm->tm_year + 1900; - date[1].i = tm->tm_mon; + date[1].i = tm->tm_mon + 1; date[2].i = tm->tm_mday; date[3].i = tm->tm_hour; date[4].i = tm->tm_min; diff --git a/src/util.c b/src/util.c index 8e307ca..6a58456 100644 --- a/src/util.c +++ b/src/util.c @@ -152,8 +152,8 @@ void get_date(int *year, int *month, int *mday, int *wday) time_t t = time(NULL); struct tm *tm = localtime(&t); - *year = tm->tm_year; - *month = tm->tm_mon; + *year = tm->tm_year + 1900; + *month = tm->tm_mon + 1; *mday = tm->tm_mday; *wday = tm->tm_wday; } @@ -167,6 +167,6 @@ void get_time(int *hour, int *min, int *sec, int *ms) *hour = tm->tm_hour; *min = tm->tm_min; - *sec = ts.tv_sec; + *sec = tm->tm_sec; *ms = ts.tv_nsec / 1000000; }