From 508c4c4993581d5a364a36daf84a5199a1436db0 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 20 Dec 2019 12:42:06 +0100 Subject: Remove dead code Signed-off-by: Matthias Beyer --- src/utils/dateutil.rs | 16 +--------------- src/utils/fileutil.rs | 50 +------------------------------------------------- src/utils/misc.rs | 18 ------------------ 3 files changed, 2 insertions(+), 82 deletions(-) diff --git a/src/utils/dateutil.rs b/src/utils/dateutil.rs index bc70c02..7d3146a 100644 --- a/src/utils/dateutil.rs +++ b/src/utils/dateutil.rs @@ -59,7 +59,7 @@ pub fn now() -> DateTime { *crate::testing::data::NOW_TEST } -pub fn week_from_str_end(date_str: &str) -> Result, String> { +fn week_from_str_end(date_str: &str) -> Result, String> { let now = Local::now(); if date_str == "toweek" || date_str == "thisweek" { return Ok(Local.isoywd(now.year(), now.iso_week().week(), Weekday::Sun)); @@ -75,13 +75,6 @@ pub fn week_from_str_end(date_str: &str) -> Result, String> { Err("Could not parse '{}' as week".to_string()) } -pub fn datetime_from_timestamp(timestamp: &str) -> Option> { - let timestamp_i64 = timestamp.parse::().ok()?; - let naive_datetime = NaiveDateTime::from_timestamp_opt(timestamp_i64, 0)?; - let utc_time: DateTime = DateTime::from_utc(naive_datetime, Utc); - Some(utc_time.with_timezone(&Local)) -} - #[cfg(test)] mod tests { use super::*; @@ -141,11 +134,4 @@ mod tests { week_from_str_end("nonsense").unwrap(); } - #[test] - fn test_datetime_from_timestamp() { - let timestamp = "1547234687"; - let dt_from_ts = datetime_from_timestamp(timestamp).unwrap(); - let dt = Utc.ymd(2019, 01, 11).and_hms(19, 24, 47); - assert_eq!(dt, dt_from_ts); - } } diff --git a/src/utils/fileutil.rs b/src/utils/fileutil.rs index aac3ab6..052b72f 100644 --- a/src/utils/fileutil.rs +++ b/src/utils/fileutil.rs @@ -1,55 +1,7 @@ -use std::fs::OpenOptions; use std::io::prelude::*; -use std::io::{BufRead, BufReader}; -use std::path::{Path, PathBuf}; +use std::path::Path; use std::{fs, io}; -pub fn file_iter(dir: &Path) -> impl Iterator { - use walkdir::WalkDir; - - WalkDir::new(dir) - .follow_links(true) - .into_iter() - .filter_map(|e| e.ok()) - .filter(|e| e.file_type().is_file()) - .map(|entry| entry.into_path()) -} - -pub fn dir_iter(dir: &Path) -> impl Iterator { - use walkdir::WalkDir; - - let dir = dir.to_path_buf(); - WalkDir::new(&dir) - .follow_links(true) - .into_iter() - .filter_map(|e| e.ok()) - .filter(|e| e.file_type().is_dir()) - .filter(move |f| f.path() != dir) - .map(|entry| entry.into_path()) -} - -pub fn write_file(filepath: &Path, contents: &str) -> io::Result<()> { - let mut file = fs::File::create(filepath)?; - file.write_all(contents.as_bytes()) -} - -pub fn append_file(filepath: &Path, contents: &str) -> io::Result<()> { - let mut file = OpenOptions::new() - .append(true) - .create(true) - .open(filepath)?; - file.write_all(contents.as_bytes()) -} - -pub fn read_lines_from_file( - filepath: &Path, -) -> io::Result> { - let f = fs::File::open(filepath)?; - let f = BufReader::new(f); - let lines: Result, io::Error> = f.lines().collect(); - lines.map(|result| result.into_iter()) -} - pub fn read_file_to_string(path: &Path) -> io::Result { let mut file = fs::File::open(&path)?; let mut contents = String::new(); diff --git a/src/utils/misc.rs b/src/utils/misc.rs index f02ddeb..d5b0551 100644 --- a/src/utils/misc.rs +++ b/src/utils/misc.rs @@ -1,4 +1,3 @@ -use chrono::prelude::*; use std::fmt::Display; use std::time; @@ -19,23 +18,6 @@ pub fn format_duration(duration: &time::Duration) -> impl Display { duration.as_millis() } -pub fn get_bucket_for_date(date: Date) -> String { - date.format("%G-W%V").to_string() -} - -#[cfg(not(test))] -pub fn make_new_uid() -> String { - use uuid::Uuid; - - let suffix = "@khaleesi"; - format!("{}{}", Uuid::new_v4().to_hyphenated_ref(), suffix) -} - -#[cfg(test)] -pub fn make_new_uid() -> String { - "11111111-2222-3333-4444-444444444444@khaleesi".to_string() -} - #[cfg(test)] mod tests { use super::*; -- cgit v1.2.3