From b80c1f636417940500debdf823727b2a1b574335 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Fri, 13 Apr 2012 19:08:52 +0200 Subject: Support extended date formats Add support for appending a strftime()-style format string to "%(start)" and "%(end)". Signed-off-by: Lukas Fleischer --- src/utils.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/utils.c b/src/utils.c index e17f5bf..1c81f83 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1165,6 +1165,23 @@ parse_fs (const char **s, char *extformat) } } +/* Print a formatted date to stdout. */ +static void +print_date (long date, const char *extformat) +{ + char buf[BUFSIZ]; + + if (extformat[0] != '\0') + { + time_t t = date; + struct tm *lt = localtime ((time_t *)&t); + strftime (buf, BUFSIZ, extformat, lt); + printf ("%s", buf); + } + else + printf ("%ld", date); +} + /* Print a formatted appointment to stdout. */ void print_apoint (const char *format, long day, struct apoint *apt) @@ -1182,7 +1199,7 @@ print_apoint (const char *format, long day, struct apoint *apt) switch (parse_fs (&p, extformat)) { case FS_STARTDATE: - printf ("%ld", apt->start); + print_date (apt->start, extformat); break; case FS_STARTDATESTR: printf ("%s", str_start); @@ -1191,7 +1208,7 @@ print_apoint (const char *format, long day, struct apoint *apt) printf ("%ld", apt->dur); break; case FS_ENDDATE: - printf ("%ld", apt->start + apt->dur); + print_date (apt->start + apt->dur, extformat); break; case FS_ENDDATESTR: printf ("%s", str_end); -- cgit v1.2.3-70-g09d2