diff options
author | rbuj <[email protected]> | 2022-07-25 13:14:03 +0200 |
---|---|---|
committer | Luke from DC <[email protected]> | 2023-03-15 23:08:58 +0000 |
commit | cdf61f68217ee1972818437b4513c8d991201a6b (patch) | |
tree | 0b904148905cd235247d9282c4cd30a0dc9f6b89 | |
parent | 90382856772188673317847cf0c0445012d9f403 (diff) | |
download | engrampa-cdf61f68217ee1972818437b4513c8d991201a6b.tar.bz2 engrampa-cdf61f68217ee1972818437b4513c8d991201a6b.tar.xz |
fr-command-rar: parse date & time using strptime
-rw-r--r-- | src/fr-command-rar.c | 39 |
1 files changed, 7 insertions, 32 deletions
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 <stdio.h> #include <stdlib.h> #include <string.h> @@ -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); } |