Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jrduncans committed Dec 8, 2024
1 parent 44ef382 commit 2008d84
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub enum DurationUnit {
///
/// Will return an error string if `input` cannot be parsed to a date.
pub fn run(
input: &Option<String>,
input: Option<&String>,
output_mode: &OutputMode,
extra_duration_unit: Option<DurationUnit>,
) -> Result<(), &'static str> {
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct Opt {
fn main() {
let opt: Opt = Parser::parse();

if let Err(err) = timeturner::run(&opt.input, &output_mode(&opt), opt.duration_unit) {
if let Err(err) = timeturner::run(opt.input.as_ref(), &output_mode(&opt), opt.duration_unit) {
eprintln!("{err}");
process::exit(1);
}
Expand Down
36 changes: 18 additions & 18 deletions src/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn parse_with_dateparser(input: &str) -> Option<DateTime<Utc>> {
parse_with(input, &Utc, midnight).ok()
}

pub fn parse_input(input: &Option<String>) -> Result<DateTime<Utc>, &'static str> {
pub fn parse_input(input: Option<&String>) -> Result<DateTime<Utc>, &'static str> {
input.as_ref().filter(|i| !i.trim().is_empty()).map_or_else(
|| Ok(Utc::now()),
|i| {
Expand All @@ -40,7 +40,7 @@ mod tests {
#[test]
fn missing_input() {
let now = Utc::now();
let result = parse_input(&None).unwrap();
let result = parse_input(None).unwrap();
assert!(
result.timestamp_millis() >= now.timestamp_millis(),
"Provided time {result} was not after the start of the test {now}"
Expand All @@ -55,7 +55,7 @@ mod tests {
#[test]
fn empty_input() {
let now = Utc::now();
let result = parse_input(&Some(String::from(" "))).unwrap();
let result = parse_input(Some(&String::from(" "))).unwrap();
assert!(
result.timestamp_millis() >= now.timestamp_millis(),
"Provided time {result} was not after the start of the test {now}"
Expand All @@ -69,91 +69,91 @@ mod tests {

#[test]
fn epoch_millis_input() {
let result = parse_input(&Some(String::from("1572213799747"))).unwrap();
let result = parse_input(Some(&String::from("1572213799747"))).unwrap();
assert_eq!(result, Utc.timestamp_millis_opt(1572213799747).unwrap());
}

#[test]
fn rfc3339_input() {
let result = parse_input(&Some(String::from("2019-10-27T15:03:19.747-07:00"))).unwrap();
let result = parse_input(Some(&String::from("2019-10-27T15:03:19.747-07:00"))).unwrap();
assert_eq!(result, Utc.timestamp_millis_opt(1572213799747).unwrap());
}

#[test]
fn rfc3339_input_no_partial_seconds() {
let result = parse_input(&Some(String::from("2019-10-27T15:03:19-07:00"))).unwrap();
let result = parse_input(Some(&String::from("2019-10-27T15:03:19-07:00"))).unwrap();
assert_eq!(result, Utc.timestamp_millis_opt(1572213799000).unwrap());
}

#[test]
fn rfc3339_input_zulu() {
let result = parse_input(&Some(String::from("2019-10-27T22:03:19.747Z"))).unwrap();
let result = parse_input(Some(&String::from("2019-10-27T22:03:19.747Z"))).unwrap();
assert_eq!(result, Utc.timestamp_millis_opt(1572213799747).unwrap());
}

#[test]
fn rfc3339_input_space_instead_of_t() {
let result = parse_input(&Some(String::from("2019-10-27 15:03:19.747-07:00"))).unwrap();
let result = parse_input(Some(&String::from("2019-10-27 15:03:19.747-07:00"))).unwrap();
assert_eq!(result, Utc.timestamp_millis_opt(1572213799747).unwrap());
}

#[test]
fn custom_unzoned_rfc3339_like_with_space_and_comma() {
let result = parse_input(&Some(String::from("2020-12-17 00:00:34,247"))).unwrap();
let result = parse_input(Some(&String::from("2020-12-17 00:00:34,247"))).unwrap();
assert_eq!(result, Utc.timestamp_millis_opt(1608163234247).unwrap());
}

#[test]
fn date_spelled_short_month_time_with_dot_input() {
let result = parse_input(&Some(String::from("03 Feb 2020 01:03:10.534"))).unwrap();
let result = parse_input(Some(&String::from("03 Feb 2020 01:03:10.534"))).unwrap();
assert_eq!(result, Utc.timestamp_millis_opt(1580691790534).unwrap());
}

#[test]
fn date_spelled_short_month_time_with_comma_input() {
let result = parse_input(&Some(String::from("03 Feb 2020 01:03:10,534"))).unwrap();
let result = parse_input(Some(&String::from("03 Feb 2020 01:03:10,534"))).unwrap();
assert_eq!(result, Utc.timestamp_millis_opt(1580691790534).unwrap());
}

#[test]
fn year_space_date_space_utc() {
let result = parse_input(&Some(String::from("2019-11-22 09:03:44.00 UTC"))).unwrap();
let result = parse_input(Some(&String::from("2019-11-22 09:03:44.00 UTC"))).unwrap();
assert_eq!(result, Utc.timestamp_millis_opt(1574413424000).unwrap());
}

#[test]
fn time_space_utc_space_date() {
let result = parse_input(&Some(String::from("04:10:39 UTC 2020-02-17"))).unwrap();
let result = parse_input(Some(&String::from("04:10:39 UTC 2020-02-17"))).unwrap();
assert_eq!(result, Utc.timestamp_millis_opt(1581912639000).unwrap());
}

#[test]
fn test_casssandra_zoned_no_millis() {
let result = parse_input(&Some(String::from("2015-03-07 00:59:56+0100"))).unwrap();
let result = parse_input(Some(&String::from("2015-03-07 00:59:56+0100"))).unwrap();
assert_eq!(result, Utc.timestamp_millis_opt(1425686396000).unwrap());
}

#[test]
fn test_casssandra_zoned_millis() {
let result = parse_input(&Some(String::from("2015-03-07 00:59:56.001+0100"))).unwrap();
let result = parse_input(Some(&String::from("2015-03-07 00:59:56.001+0100"))).unwrap();
assert_eq!(result, Utc.timestamp_millis_opt(1425686396001).unwrap());
}

#[test]
fn test_mysql_datetime() {
let result = parse_input(&Some(String::from("2021-01-20 18:13:37.842000"))).unwrap();
let result = parse_input(Some(&String::from("2021-01-20 18:13:37.842000"))).unwrap();
assert_eq!(result, Utc.timestamp_millis_opt(1611166417842).unwrap());
}

#[test]
fn english_input() {
let result = parse_input(&Some(String::from("May 23, 2020 12:00"))).unwrap();
let result = parse_input(Some(&String::from("May 23, 2020 12:00"))).unwrap();
assert_eq!(result, Utc.timestamp_millis_opt(1590235200000).unwrap());
}

#[test]
fn invalid_input() {
let result = parse_input(&Some(String::from("not a date"))).err();
let result = parse_input(Some(&String::from("not a date"))).err();
assert_eq!(result, Some("Input format not recognized"));
}
}

0 comments on commit 2008d84

Please sign in to comment.