Skip to content
Merged
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
32 changes: 22 additions & 10 deletions src/uu/date/src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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}");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a follow up, it should use the translate macro

}

// 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);
}
Expand All @@ -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)
Expand All @@ -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"
);
}
}
}
Expand Down
Loading