diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2019-12-20 12:42:06 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2019-12-20 12:48:26 +0100 |
commit | 508c4c4993581d5a364a36daf84a5199a1436db0 (patch) | |
tree | 7aeef971aafd0c27d26630ca6b9be0a43fc398e7 | |
parent | 2612eefb2a71444d3a45f21de9782f756111bd3e (diff) |
Remove dead code
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r-- | src/utils/dateutil.rs | 16 | ||||
-rw-r--r-- | src/utils/fileutil.rs | 50 | ||||
-rw-r--r-- | 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<Utc> { *crate::testing::data::NOW_TEST } -pub fn week_from_str_end(date_str: &str) -> Result<Date<Local>, String> { +fn week_from_str_end(date_str: &str) -> Result<Date<Local>, 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<Date<Local>, String> { Err("Could not parse '{}' as week".to_string()) } -pub fn datetime_from_timestamp(timestamp: &str) -> Option<DateTime<Local>> { - let timestamp_i64 = timestamp.parse::<i64>().ok()?; - let naive_datetime = NaiveDateTime::from_timestamp_opt(timestamp_i64, 0)?; - let utc_time: DateTime<Utc> = 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<Item = PathBuf> { - 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<Item = PathBuf> { - 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<impl DoubleEndedIterator<Item = String>> { - let f = fs::File::open(filepath)?; - let f = BufReader::new(f); - let lines: Result<Vec<String>, io::Error> = f.lines().collect(); - lines.map(|result| result.into_iter()) -} - pub fn read_file_to_string(path: &Path) -> io::Result<String> { 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<Local>) -> 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::*; |