From 22ccecd5caafe80f8670a9cceded41b268d3dda4 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sat, 24 Oct 2015 19:53:52 -0200 Subject: datetime-parser: improve error handling --- src/renderer.c | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) (limited to 'src/renderer.c') diff --git a/src/renderer.c b/src/renderer.c index 47a5f87..c5b3e9f 100644 --- a/src/renderer.c +++ b/src/renderer.c @@ -10,13 +10,11 @@ #include #endif /* HAVE_CONFIG_H */ -#ifdef HAVE_TIME_H -#include -#endif /* HAVE_TIME_H */ - #include #include #include "utils/utils.h" +#include "datetime-parser.h" +#include "error.h" #include "loader.h" #include "source-parser.h" #include "template-parser.h" @@ -46,25 +44,15 @@ blogc_format_date(const char *date, b_trie_t *global, b_trie_t *local) return NULL; if (date_format == NULL) return b_strdup(date); -#ifdef HAVE_TIME_H - struct tm tm; - memset(&tm, 0, sizeof(struct tm)); - if (NULL == strptime(date, "%Y-%m-%d %H:%M:%S", &tm)) { - fprintf(stderr, "blogc: warning: Failed to parse DATE variable: %s\n", - date); - return b_strdup(date); - } - char tmp[1024]; - if (0 == strftime(tmp, sizeof(tmp), date_format, &tm)) { - fprintf(stderr, "blogc: warning: Failed to format DATE variable, " - "FORMAT is too long: %s\n", date_format); + + blogc_error_t *err = NULL; + char *rv = blogc_convert_datetime(date, date_format, &err); + if (err != NULL) { + blogc_error_print(err); + blogc_error_free(err); return b_strdup(date); } - return b_strdup(tmp); -#else - fprintf(stderr, "blogc: warning: Can't pre-process DATE variable.\n"); - return NULL; -#endif + return rv; } -- cgit v1.2.3-18-g5258