Skip to content

Commit 1272bfc

Browse files
committed
du: Add support for +FORMAT time-style
Also add to error text, which... GNU coreutils doesn't do for some reason.
1 parent fc08fa1 commit 1272bfc

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

src/uu/du/locales/en-US.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ du-error-invalid-time-style = invalid argument { $style } for 'time style'
5252
- 'full-iso'
5353
- 'long-iso'
5454
- 'iso'
55+
- +FORMAT (e.g., +%H:%M) for a 'date'-style format
5556
Try '{ $help }' for more information.
5657
du-error-invalid-time-arg = 'birth' and 'creation' arguments for --time are not supported on this platform.
5758
du-error-invalid-glob = Invalid exclude syntax: { $error }

src/uu/du/locales/fr-FR.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ du-error-invalid-time-style = argument invalide { $style } pour 'style de temps'
5252
- 'full-iso'
5353
- 'long-iso'
5454
- 'iso'
55+
- +FORMAT (e.g., +%H:%M) pour un format de type 'date'
5556
Essayez '{ $help }' pour plus d'informations.
5657
du-error-invalid-time-arg = les arguments 'birth' et 'creation' pour --time ne sont pas supportés sur cette plateforme.
5758
du-error-invalid-glob = Syntaxe d'exclusion invalide : { $error }

src/uu/du/src/du.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,10 @@ fn parse_time_style(s: Option<&str>) -> UResult<&str> {
761761
"full-iso" => Ok("%Y-%m-%d %H:%M:%S.%f %z"),
762762
"long-iso" => Ok("%Y-%m-%d %H:%M"),
763763
"iso" => Ok("%Y-%m-%d"),
764-
_ => Err(DuError::InvalidTimeStyleArg(s.into()).into()),
764+
_ => match s.chars().next().unwrap() {
765+
'+' => Ok(&s[1..]),
766+
_ => Err(DuError::InvalidTimeStyleArg(s.into()).into()),
767+
},
765768
},
766769
None => Ok("%Y-%m-%d %H:%M"),
767770
}

tests/by-util/test_du.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,56 @@ fn test_du_time() {
626626
.succeeds();
627627
result.stdout_only("0\t2016-06-16 00:00\tdate_test\n");
628628

629+
// long-iso (same as default)
630+
let result = ts
631+
.ucmd()
632+
.env("TZ", "UTC")
633+
.arg("--time")
634+
.arg("--time-style=long-iso")
635+
.arg("date_test")
636+
.succeeds();
637+
result.stdout_only("0\t2016-06-16 00:00\tdate_test\n");
638+
639+
// full-iso
640+
let result = ts
641+
.ucmd()
642+
.env("TZ", "UTC")
643+
.arg("--time")
644+
.arg("--time-style=full-iso")
645+
.arg("date_test")
646+
.succeeds();
647+
result.stdout_only("0\t2016-06-16 00:00:00.000000000 +0000\tdate_test\n");
648+
649+
// iso
650+
let result = ts
651+
.ucmd()
652+
.env("TZ", "UTC")
653+
.arg("--time")
654+
.arg("--time-style=iso")
655+
.arg("date_test")
656+
.succeeds();
657+
result.stdout_only("0\t2016-06-16\tdate_test\n");
658+
659+
// custom +FORMAT
660+
let result = ts
661+
.ucmd()
662+
.env("TZ", "UTC")
663+
.arg("--time")
664+
.arg("--time-style=+%Y__%H")
665+
.arg("date_test")
666+
.succeeds();
667+
result.stdout_only("0\t2016__00\tdate_test\n");
668+
669+
// ls has special handling for new line in format, du doesn't.
670+
let result = ts
671+
.ucmd()
672+
.env("TZ", "UTC")
673+
.arg("--time")
674+
.arg("--time-style=+%Y_\n_%H")
675+
.arg("date_test")
676+
.succeeds();
677+
result.stdout_only("0\t2016_\n_00\tdate_test\n");
678+
629679
for argument in ["--time=atime", "--time=atim", "--time=a"] {
630680
let result = ts
631681
.ucmd()

0 commit comments

Comments
 (0)