Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/uu/date/src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#[cfg(feature = "i18n-datetime")]
use uucore::i18n::datetime::{localize_format_string, should_use_icu_locale};
use uucore::translate;
use uucore::translate_text;
use uucore::{format_usage, show};
#[cfg(windows)]
use windows_sys::Win32::{Foundation::SYSTEMTIME, System::SystemInformation::SetSystemTime};
Expand All @@ -35,10 +36,10 @@

/// OHOS helper: pass through the system time zone ID returned by
/// TimeService (OH_TimeService_GetTimeZone, e.g. "Asia/Shanghai") and
/// resolve it against the embedded IANA tzdata (jiff-tzdb) so that

Check warning on line 39 in src/uu/date/src/date.rs

View workflow job for this annotation

GitHub Actions / Style/spelling (ubuntu-latest, feat_os_unix)

WARNING: `cspell`: Unknown word 'tzdb' (file:'src/uu/date/src/date.rs', line:39)
/// historial DST rules and transitions are preserved. jiff's

Check warning on line 40 in src/uu/date/src/date.rs

View workflow job for this annotation

GitHub Actions / Style/spelling (ubuntu-latest, feat_os_unix)

WARNING: `cspell`: Unknown word 'historial' (file:'src/uu/date/src/date.rs', line:40)
/// `try_system()` is useless on OHOS because both `/etc/localtime` and
/// the zoneinfo dirs are absent.

Check warning on line 42 in src/uu/date/src/date.rs

View workflow job for this annotation

GitHub Actions / Style/spelling (ubuntu-latest, feat_os_unix)

WARNING: `cspell`: Unknown word 'zoneinfo' (file:'src/uu/date/src/date.rs', line:42)
#[cfg(target_env = "ohos")]
fn ohos_system_zone() -> jiff::tz::TimeZone {
use core::ffi::{CStr, c_char};
Expand All @@ -55,7 +56,7 @@
let id = unsafe { CStr::from_ptr(buf.as_ptr() as *const c_char) }
.to_string_lossy()
.into_owned();
if let Some((name, tzif)) = jiff_tzdb::get(&id) {

Check warning on line 59 in src/uu/date/src/date.rs

View workflow job for this annotation

GitHub Actions / Style/spelling (ubuntu-latest, feat_os_unix)

WARNING: `cspell`: Unknown word 'tzif' (file:'src/uu/date/src/date.rs', line:59)
if let Ok(tz) = jiff::tz::TimeZone::tzif(name, tzif) {
return tz;
}
Expand Down Expand Up @@ -91,9 +92,9 @@
Write(std::io::Error),
#[error("{}", translate!("date-error-extra-operand", "operand" => .operand))]
ExtraOperand { operand: String },
#[error("{}", translate!("date-error-invalid-date", "date" => .date))]
#[error("{}", translate_text!("date-error-invalid-date", "date" => .date))]
InvalidDate { date: String },
#[error("{}", translate!("date-error-format-missing-plus", "arg" => .arg))]
#[error("{}", translate_text!("date-error-format-missing-plus", "arg" => .arg))]
FormatMissingPlus { arg: String },
#[error("{}", translate!("date-error-expected-file-got-directory", "path" => .path))]
ExpectedFileGotDirectory { path: String },
Expand Down
18 changes: 18 additions & 0 deletions tests/by-util/test_date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,24 @@ fn test_date_set_invalid() {
assert!(result.stderr_str().starts_with("date: invalid date "));
}

#[test]
fn test_date_error_echoes_input_verbatim() {
// Error messages echo what the user typed: numeric-looking input must
// not be reformatted as a Fluent number (#14669, #14670).
for input in ["1e9", "+1e-2", "+9.e-0", "9.", "-0"] {
new_ucmd!()
.arg("-d")
.arg(input)
.fails()
.stderr_is(format!("date: invalid date '{input}'\n"));
}
// Same for the missing '+' message, which echoes the argument too.
new_ucmd!()
.args(&["--date", "1996-01-31", "1e9"])
.fails_with_code(1)
.stderr_contains("the argument 1e9 lacks a leading '+'");
}

#[test]
#[cfg(all(unix, not(any(target_vendor = "apple", target_os = "android"))))]
fn test_date_set_permissions_error() {
Expand Down
Loading