diff options
author | Lukas Fleischer <calcurse@cryptocrack.de> | 2012-04-13 19:08:52 +0200 |
---|---|---|
committer | Lukas Fleischer <calcurse@cryptocrack.de> | 2012-04-17 11:10:11 +0200 |
commit | b80c1f636417940500debdf823727b2a1b574335 (patch) | |
tree | aa40aaf09eece6165713114a670ace8931645bf3 | |
parent | 68b26ff85415ee687b082fbd5150de58cdce0935 (diff) | |
download | calcurse-b80c1f636417940500debdf823727b2a1b574335.zip |
Support extended date formats
Add support for appending a strftime()-style format string to "%(start)"
and "%(end)".
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
-rw-r--r-- | src/utils.c | 21 |
1 files 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); |