aboutsummaryrefslogtreecommitdiffstats
path: root/src/renderer.c
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2015-10-24 19:53:52 -0200
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2015-10-24 19:53:52 -0200
commit22ccecd5caafe80f8670a9cceded41b268d3dda4 (patch)
tree14fc883fcb4ffa98d805088f3c8bdc8cf126fc4b /src/renderer.c
parentb27251f29dbf35b2580df0586779bc3366cf2dad (diff)
downloadblogc-22ccecd5caafe80f8670a9cceded41b268d3dda4.tar.gz
blogc-22ccecd5caafe80f8670a9cceded41b268d3dda4.tar.bz2
blogc-22ccecd5caafe80f8670a9cceded41b268d3dda4.zip
datetime-parser: improve error handling
Diffstat (limited to 'src/renderer.c')
-rw-r--r--src/renderer.c30
1 files changed, 9 insertions, 21 deletions
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 <config.h>
#endif /* HAVE_CONFIG_H */
-#ifdef HAVE_TIME_H
-#include <time.h>
-#endif /* HAVE_TIME_H */
-
#include <stdio.h>
#include <string.h>
#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;
}