diff options
| author | Bruno Haible <bruno@clisp.org> | 2025-07-17 16:29:05 +0200 |
|---|---|---|
| committer | Pádraig Brady <P@draigBrady.com> | 2025-07-21 21:16:03 +0100 |
| commit | c3cea90de3634803fae46650ea74af1c3825e36b (patch) | |
| tree | eb535a800c8ce2464c0e633e184c0bc9726fb0ad | |
| parent | tests: sort: add a test for equivalent floats (diff) | |
| download | coreutils-c3cea90de3634803fae46650ea74af1c3825e36b.tar.gz coreutils-c3cea90de3634803fae46650ea74af1c3825e36b.zip | |
date: force a Gregorian calendar for options --iso-8601 and --rfc-3339
* src/date.c (show_date_helper): Add a use_c_locale parameter.
(batch_convert): Add a format_in_c_locale parameter.
(main): Set format_in_c_locale to true if any of the options --rfc-3339,
--iso-8601, -R is seen.
| -rw-r--r-- | src/date.c | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/date.c b/src/date.c index b55aba757..953962820 100644 --- a/src/date.c +++ b/src/date.c @@ -37,7 +37,7 @@ #define AUTHORS proper_name ("David MacKenzie") -static bool show_date_helper (char const *, struct timespec, timezone_t); +static bool show_date_helper (char const *, bool, struct timespec, timezone_t); enum Time_spec { @@ -336,7 +336,8 @@ adjust_resolution (char const *format) Return true if successful. */ static bool -batch_convert (char const *input_filename, char const *format, +batch_convert (char const *input_filename, + char const *format, bool format_in_c_locale, timezone_t tz, char const *tzstring) { bool ok; @@ -381,7 +382,7 @@ batch_convert (char const *input_filename, char const *format, } else { - ok &= show_date_helper (format, when, tz); + ok &= show_date_helper (format, format_in_c_locale, when, tz); } } @@ -402,6 +403,7 @@ main (int argc, char **argv) struct timespec when; bool set_date = false; char const *format = nullptr; + bool format_in_c_locale = false; bool get_resolution = false; char *batch_file = nullptr; char *reference = nullptr; @@ -451,6 +453,7 @@ main (int argc, char **argv) XARGMATCH ("--rfc-3339", optarg, time_spec_string + 2, time_spec + 2); new_format = rfc_3339_format[i]; + format_in_c_locale = true; break; } case 'I': @@ -468,6 +471,7 @@ main (int argc, char **argv) ? XARGMATCH ("--iso-8601", optarg, time_spec_string, time_spec) : TIME_SPEC_DATE); new_format = iso_8601_format[i]; + format_in_c_locale = true; break; } case 'r': @@ -475,6 +479,7 @@ main (int argc, char **argv) break; case 'R': new_format = rfc_email_format; + format_in_c_locale = true; break; case 's': if (set_datestr) @@ -578,7 +583,8 @@ main (int argc, char **argv) timezone_t tz = tzalloc (tzstring); if (batch_file != nullptr) - ok = batch_convert (batch_file, format_res, tz, tzstring); + ok = batch_convert (batch_file, format_res, format_in_c_locale, + tz, tzstring); else { bool valid_date = true; @@ -643,24 +649,25 @@ main (int argc, char **argv) } } - ok &= show_date_helper (format_res, when, tz); + ok &= show_date_helper (format_res, format_in_c_locale, when, tz); } main_exit (ok ? EXIT_SUCCESS : EXIT_FAILURE); } static bool -show_date_helper (char const *format, struct timespec when, timezone_t tz) +show_date_helper (char const *format, bool use_c_locale, + struct timespec when, timezone_t tz) { if (parse_datetime_flags & PARSE_DATETIME_DEBUG) error (0, 0, _("output format: %s"), quote (format)); - if (format == rfc_email_format) + if (use_c_locale) setlocale (LC_TIME, "C"); bool ok = show_date (format, when, tz); - if (format == rfc_email_format) + if (use_c_locale) setlocale (LC_TIME, ""); putchar ('\n'); |
