maint: distinguish EOVERFLOW vs ERANGE better
[coreutils.git] / src / show-date.c
blobffa3d02b7cb4ca7b8140e250ae93c3e00d06fe4a
1 #include <config.h>
2 #include <stdio.h>
4 #include "system.h"
5 #include "fprintftime.h"
6 #include "parse-datetime.h"
7 #include "quote.h"
8 #include "show-date.h"
9 #include "stat-time.h"
11 /* Display the date and/or time in WHEN according to the format specified
12 in FORMAT, followed by a newline.
14 If successful, return true.
15 If unsuccessful, prints an error message to STDERR and returns false.
16 If unsuccessful and ON_ERROR_PRINT_UNFORMATTED, also prints WHEN.TV_SEC
17 to STDOUT. */
19 extern bool
20 show_date (char const *format, struct timespec when, timezone_t tz)
22 struct tm tm;
24 if (localtime_rz (tz, &when.tv_sec, &tm))
26 fprintftime (stdout, format, &tm, tz, when.tv_nsec);
27 return true;
29 else
31 char buf[INT_BUFSIZE_BOUND (intmax_t)];
32 error (0, 0, _("time %s is out of range"),
33 quote (timetostr (when.tv_sec, buf)));
34 return false;