From cdf61f68217ee1972818437b4513c8d991201a6b Mon Sep 17 00:00:00 2001 From: rbuj Date: Mon, 25 Jul 2022 13:14:03 +0200 Subject: fr-command-rar: parse date & time using strptime --- src/fr-command-rar.c | 39 +++++++-------------------------------- 1 file changed, 7 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/fr-command-rar.c b/src/fr-command-rar.c index 7794510..0565eca 100644 --- a/src/fr-command-rar.c +++ b/src/fr-command-rar.c @@ -20,6 +20,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#define _XOPEN_SOURCE 700 + #include #include #include @@ -112,40 +114,13 @@ static time_t mktime_from_string (const char *date_s, const char *time_s) { - struct tm tm = {0, }; - char **fields; + struct tm tm = {0, }; + char *date_time_s; tm.tm_isdst = -1; - - /* date */ - - fields = g_strsplit (date_s, "-", 3); - if (fields[0] != NULL) { - if (date_newstyle) - tm.tm_year = atoi (fields[0]) - 1900; - else - tm.tm_mday = atoi (fields[0]); - if (fields[1] != NULL) { - tm.tm_mon = atoi (fields[1]) - 1; - if (fields[2] != NULL) { - if (date_newstyle) - tm.tm_mday = atoi (fields[2]); - else - tm.tm_year = 100 + atoi (fields[2]); - } - } - } - g_strfreev (fields); - - /* time */ - - fields = g_strsplit (time_s, ":", 2); - if (fields[0] != NULL) { - tm.tm_hour = atoi (fields[0]); - if (fields[1] != NULL) - tm.tm_min = atoi (fields[1]); - } - g_strfreev (fields); + date_time_s = g_strjoin (" ", date_s, time_s, NULL); + strptime (date_time_s, date_newstyle ? "%Y-%m-%d %H:%M" : "%d-%m-%y %H:%M", &tm); + g_free (date_time_s); return mktime (&tm); } -- cgit v1.2.1