Skip to content

Commit 64565ba

Browse files
committed
du: convert to use uucore time formatting function
Indirectly switches to jiff, which conveniently doesn't crash on large timestamps. Also correctly prints timestamp for time far in the future or past. Removes chrono dependency.
1 parent 72d172d commit 64565ba

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/uu/du/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ workspace = true
1818
path = "src/du.rs"
1919

2020
[dependencies]
21-
chrono = { workspace = true }
2221
# For the --exclude & --exclude-from options
2322
glob = { workspace = true }
2423
clap = { workspace = true }
25-
uucore = { workspace = true, features = ["format", "parser"] }
24+
uucore = { workspace = true, features = ["format", "parser", "time"] }
2625
thiserror = { workspace = true }
2726

2827
[target.'cfg(target_os = "windows")'.dependencies]

src/uu/du/src/du.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
// For the full copyright and license information, please view the LICENSE
44
// file that was distributed with this source code.
55

6-
use chrono::{DateTime, Local};
76
use clap::{Arg, ArgAction, ArgMatches, Command, builder::PossibleValue};
87
use glob::Pattern;
98
use std::collections::{HashMap, HashSet};
109
use std::env;
1110
#[cfg(not(windows))]
1211
use std::fs::Metadata;
1312
use std::fs::{self, DirEntry, File};
14-
use std::io::{BufRead, BufReader};
13+
use std::io::{BufRead, BufReader, stdout};
1514
#[cfg(not(windows))]
1615
use std::os::unix::fs::MetadataExt;
1716
#[cfg(windows)]
@@ -576,13 +575,13 @@ impl StatPrinter {
576575
}
577576

578577
fn print_stat(&self, stat: &Stat, size: u64) -> UResult<()> {
578+
print!("{}\t", self.convert_size(size));
579+
579580
if let Some(time) = self.time {
580581
let secs = get_time_secs(time, stat)?;
581-
let tm = DateTime::<Local>::from(UNIX_EPOCH + Duration::from_secs(secs));
582-
let time_str = tm.format(&self.time_format).to_string();
583-
print!("{}\t{time_str}\t", self.convert_size(size));
584-
} else {
585-
print!("{}\t", self.convert_size(size));
582+
let time = UNIX_EPOCH + Duration::from_secs(secs);
583+
uucore::time::format_system_time(&mut stdout(), time, &self.time_format)?;
584+
print!("\t");
586585
}
587586

588587
print_verbatim(&stat.path).unwrap();

0 commit comments

Comments
 (0)