date: Remove eprintln! to avoid 2>/dev/full abort (#11228)

This commit is contained in:
oech3
2026-03-08 21:06:05 +09:00
committed by GitHub
parent 005cf50a1a
commit 995c9e04a6
+22 -10
View File
@@ -15,7 +15,7 @@ use jiff::{Timestamp, Zoned};
use std::borrow::Cow;
use std::collections::HashMap;
use std::fs::File;
use std::io::{BufRead, BufReader, BufWriter, Read, Write};
use std::io::{BufRead, BufReader, BufWriter, Read, Write, stderr};
use std::path::PathBuf;
use std::sync::OnceLock;
use uucore::display::Quotable;
@@ -436,7 +436,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
format!("{date_part} 00:00 {offset}")
};
if settings.debug {
eprintln!("date: warning: using midnight as starting time: 00:00:00");
let _ = writeln!(
stderr(),
"date: warning: using midnight as starting time: 00:00:00"
);
}
parse_date(composed, &now, DebugOptions::new(settings.debug, false))
} else if let Some((total_hours, day_delta)) = military_tz_with_offset {
@@ -895,22 +898,25 @@ fn parse_date<S: AsRef<str> + Clone>(
let input_str = s.as_ref();
if dbg_opts.debug {
eprintln!("date: input string: {input_str}");
let _ = writeln!(stderr(), "date: input string: {input_str}");
}
// First, try to parse any timezone abbreviations
if let Some(zoned) = try_parse_with_abbreviation(input_str, now) {
if dbg_opts.debug {
eprintln!(
let mut err = stderr().lock();
let _ = writeln!(
err,
"date: parsed date part: (Y-M-D) {}",
strtime::format("%Y-%m-%d", &zoned).unwrap_or_default()
);
eprintln!(
let _ = writeln!(
err,
"date: parsed time part: {}",
strtime::format("%H:%M:%S", &zoned).unwrap_or_default()
);
let tz_display = zoned.time_zone().iana_name().unwrap_or("system default");
eprintln!("date: input timezone: {tz_display}");
let _ = writeln!(err, "date: input timezone: {tz_display}");
}
return Ok(zoned);
}
@@ -922,17 +928,20 @@ fn parse_date<S: AsRef<str> + Clone>(
let result = date.timestamp().to_zoned(now.time_zone().clone());
if dbg_opts.debug {
// Show final parsed date and time
eprintln!(
let mut err = stderr().lock();
let _ = writeln!(
err,
"date: parsed date part: (Y-M-D) {}",
strtime::format("%Y-%m-%d", &result).unwrap_or_default()
);
eprintln!(
let _ = writeln!(
err,
"date: parsed time part: {}",
strtime::format("%H:%M:%S", &result).unwrap_or_default()
);
// Show timezone information
eprintln!("date: input timezone: system default");
let _ = writeln!(err, "date: input timezone: system default");
// Check if time component was specified, if not warn about midnight usage
// Only warn for date-only inputs (no time specified), but not for epoch formats (@N)
@@ -941,7 +950,10 @@ fn parse_date<S: AsRef<str> + Clone>(
// Input likely didn't specify a time, so midnight was assumed
let time_str = strtime::format("%H:%M:%S", &result).unwrap_or_default();
if time_str == "00:00:00" {
eprintln!("date: warning: using midnight as starting time: 00:00:00");
let _ = writeln!(
err,
"date: warning: using midnight as starting time: 00:00:00"
);
}
}
}