Skip to content
Closed
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
8 changes: 7 additions & 1 deletion src/uu/date/src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// spell-checker:ignore (chrono) Datelike Timelike ; (format) DATEFILE MMDDhhmm ; (vars) datetime datetimes

use chrono::format::{Item, StrftimeItems};
use chrono::{DateTime, FixedOffset, Local, Offset, TimeDelta, Utc};
use chrono::{DateTime, FixedOffset, Local, NaiveDate, Offset, TimeDelta, Utc};
#[cfg(windows)]
use chrono::{Datelike, Timelike};
use clap::{crate_version, Arg, ArgAction, Command};
Expand Down Expand Up @@ -222,6 +222,12 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
// Iterate over all dates - whether it's a single date or a file.
Copy link
Contributor

Choose a reason for hiding this comment

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

please run rustfmt

let dates: Box<dyn Iterator<Item = _>> = match settings.date_source {
DateSource::Custom(ref input) => {

let input = NaiveDate::parse_from_str(input, "%Y-%m-%d")
.expect(format!("invalid date {}", input).as_str())
.format("%Y-%m-%d")
.to_string();

let date = parse_date(input.clone());
let iter = std::iter::once(date);
Box::new(iter)
Expand Down
8 changes: 8 additions & 0 deletions tests/by-util/test_date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,14 @@ fn test_invalid_date_string() {
.stderr_contains("invalid date");
}

#[test]
fn test_date_set_check_valid_format() {
new_ucmd!()
.arg("-d")
.arg("2000-1-4")
.succeeds();
}

#[test]
fn test_date_one_digit_date() {
new_ucmd!()
Expand Down