* src/show-date.{h,c}: Declaration and definition of show_date.
* src/du.c: Wse the common show_date instead of the previous local
function.
* src/date.c: Wse the common show_date via a wrapper show_date_helper.
* src/local.mk: Corresponding adjustments.
src/runcon.c
src/seq.c
src/set-fields.c
+src/show-date.c
src/shred.c
src/shuf.c
src/sleep.c
#include "parse-datetime.h"
#include "posixtm.h"
#include "quote.h"
+#include "show-date.h"
#include "stat-time.h"
-#include "fprintftime.h"
/* The official name of this program (e.g., no 'g' prefix). */
#define PROGRAM_NAME "date"
#define AUTHORS proper_name ("David MacKenzie")
-static bool show_date (char const *, struct timespec, timezone_t);
+static bool show_date_helper (char const *, struct timespec, timezone_t);
enum Time_spec
{
}
else
{
- ok &= show_date (format, when, tz);
+ ok &= show_date_helper (format, when, tz);
}
}
}
}
- ok &= show_date (format_res, when, tz);
+ ok &= show_date_helper (format_res, when, tz);
}
main_exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
}
-/* Display the date and/or time in WHEN according to the format specified
- in FORMAT, followed by a newline. Return true if successful. */
-
static bool
-show_date (char const *format, struct timespec when, timezone_t tz)
+show_date_helper (char const *format, struct timespec when, timezone_t tz)
{
- struct tm tm;
-
if (parse_datetime_flags & PARSE_DATETIME_DEBUG)
error (0, 0, _("output format: %s"), quote (format));
- if (localtime_rz (tz, &when.tv_sec, &tm))
- {
- if (format == rfc_email_format)
- setlocale (LC_TIME, "C");
- fprintftime (stdout, format, &tm, tz, when.tv_nsec);
- if (format == rfc_email_format)
- setlocale (LC_TIME, "");
- fputc ('\n', stdout);
- return true;
- }
- else
- {
- char buf[INT_BUFSIZE_BOUND (intmax_t)];
- error (0, 0, _("time %s is out of range"),
- quote (timetostr (when.tv_sec, buf)));
- return false;
- }
+ if (format == rfc_email_format)
+ setlocale (LC_TIME, "C");
+
+ bool ok = show_date (format, when, tz);
+
+ if (format == rfc_email_format)
+ setlocale (LC_TIME, "");
+
+ putchar ('\n');
+ return ok;
}
#include "assure.h"
#include "di-set.h"
#include "exclude.h"
-#include "fprintftime.h"
#include "human.h"
#include "mountlist.h"
#include "quote.h"
+#include "show-date.h"
#include "stat-size.h"
#include "stat-time.h"
#include "stdio--.h"
return inserted;
}
-/* FIXME: this code is nearly identical to code in date.c */
-/* Display the date and time in WHEN according to the format specified
- in FORMAT. */
-
-static void
-show_date (char const *format, struct timespec when, timezone_t tz)
-{
- struct tm tm;
- if (localtime_rz (tz, &when.tv_sec, &tm))
- fprintftime (stdout, format, &tm, tz, when.tv_nsec);
- else
- {
- char buf[INT_BUFSIZE_BOUND (intmax_t)];
- char *when_str = timetostr (when.tv_sec, buf);
- error (0, 0, _("time %s is out of range"), quote (when_str));
- fputs (when_str, stdout);
- }
-}
-
/* Print N_BYTES. Convert it to a readable value before printing. */
static void
if (opt_time)
{
putchar ('\t');
- show_date (time_format, pdui->tmax, localtz);
+ bool ok = show_date (time_format, pdui->tmax, localtz);
+ if (!ok)
+ {
+ /* If failed to format date, print raw seconds instead. */
+ char buf[INT_BUFSIZE_BOUND (intmax_t)];
+ fputs (timetostr (pdui->tmax.tv_sec, buf), stdout);
+ }
}
printf ("\t%s%c", string, opt_nul_terminate_output ? '\0' : '\n');
fflush (stdout);
src/prog-fprintf.h \
src/remove.h \
src/set-fields.h \
+ src/show-date.h \
src/statx.h \
src/system.h \
src/temp-stream.h \
src_coreutils_SOURCES = src/coreutils.c
src_cp_SOURCES = src/cp.c $(copy_sources) $(selinux_sources)
+src_date_SOURCES = src/date.c src/show-date.c
src_dir_SOURCES = src/ls.c src/ls-dir.c
+src_du_SOURCES = src/du.c src/show-date.c
src_env_SOURCES = src/env.c src/operand2sig.c
src_vdir_SOURCES = src/ls.c src/ls-vdir.c
src_id_SOURCES = src/id.c src/group-list.c
--- /dev/null
+#include <config.h>
+#include <stdio.h>
+
+#include "system.h"
+#include "fprintftime.h"
+#include "parse-datetime.h"
+#include "quote.h"
+#include "show-date.h"
+#include "stat-time.h"
+
+/* Display the date and/or time in WHEN according to the format specified
+ in FORMAT, followed by a newline.
+
+ If successful, return true.
+ If unsuccessful, prints an error message to STDERR and returns false.
+ If unsuccessful and ON_ERROR_PRINT_UNFORMATTED, also prints WHEN.TV_SEC
+ to STDOUT. */
+
+extern bool
+show_date (char const *format, struct timespec when, timezone_t tz)
+{
+ struct tm tm;
+
+ if (localtime_rz (tz, &when.tv_sec, &tm))
+ {
+ fprintftime (stdout, format, &tm, tz, when.tv_nsec);
+ return true;
+ }
+ else
+ {
+ char buf[INT_BUFSIZE_BOUND (intmax_t)];
+ error (0, 0, _("time %s is out of range"),
+ quote (timetostr (when.tv_sec, buf)));
+ return false;
+ }
+}
--- /dev/null
+bool show_date (char const *format, struct timespec when, timezone_t tz);