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>
This commit is contained in:
parent
68b26ff854
commit
b80c1f6364
21
src/utils.c
21
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. */
|
/* Print a formatted appointment to stdout. */
|
||||||
void
|
void
|
||||||
print_apoint (const char *format, long day, struct apoint *apt)
|
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))
|
switch (parse_fs (&p, extformat))
|
||||||
{
|
{
|
||||||
case FS_STARTDATE:
|
case FS_STARTDATE:
|
||||||
printf ("%ld", apt->start);
|
print_date (apt->start, extformat);
|
||||||
break;
|
break;
|
||||||
case FS_STARTDATESTR:
|
case FS_STARTDATESTR:
|
||||||
printf ("%s", str_start);
|
printf ("%s", str_start);
|
||||||
@ -1191,7 +1208,7 @@ print_apoint (const char *format, long day, struct apoint *apt)
|
|||||||
printf ("%ld", apt->dur);
|
printf ("%ld", apt->dur);
|
||||||
break;
|
break;
|
||||||
case FS_ENDDATE:
|
case FS_ENDDATE:
|
||||||
printf ("%ld", apt->start + apt->dur);
|
print_date (apt->start + apt->dur, extformat);
|
||||||
break;
|
break;
|
||||||
case FS_ENDDATESTR:
|
case FS_ENDDATESTR:
|
||||||
printf ("%s", str_end);
|
printf ("%s", str_end);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user