#include "error.h"
#include "getdate.h"
#include "getline.h"
+#include "inttostr.h"
#include "posixtm.h"
#include "posixver.h"
#include "quote.h"
int putenv ();
-static void show_date (const char *format, struct timespec when);
+static int show_date (const char *format, struct timespec when);
enum Time_spec
{
}
else
{
- show_date (format, when);
+ status |= show_date (format, when);
}
}
}
}
- show_date (format, when);
+ status |= show_date (format, when);
}
exit (status == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
/* Display the date and/or time in WHEN according to the format specified
in FORMAT, followed by a newline. If FORMAT is NULL, use the
- standard output format (ctime style but with a timezone inserted). */
+ standard output format (ctime style but with a timezone inserted).
+ Return zero if successful. */
-static void
+static int
show_date (const char *format, struct timespec when)
{
struct tm *tm;
"%Y-%m-%dT%H:%M:%S%z"
};
- tm = localtime (&when.tv_sec);
-
if (format == NULL)
{
if (rfc_format)
else if (*format == '\0')
{
printf ("\n");
- return;
+ return 0;
+ }
+
+ tm = localtime (&when.tv_sec);
+ if (! tm)
+ {
+ char buf[INT_BUFSIZE_BOUND (intmax_t)];
+ error (0, 0, _("time %s is out of range"),
+ (TYPE_SIGNED (time_t)
+ ? imaxtostr (when.tv_sec, buf)
+ : umaxtostr (when.tv_sec, buf)));
+ puts (buf);
+ return 1;
}
while (1)
printf ("%s\n", out);
free (out);
+ return 0;
}