use anyhow::Result; use chrono::{DateTime, Datelike, Local}; use std::path::{Path, PathBuf}; use std::time::SystemTime; pub fn to_snail_case(from: impl Into) -> String { from.into().replace(' ', "_").to_lowercase() } // pub fn to_title_case(from: &str) -> String { // from.to_string().split(|c| c ==' ' || c == '_').map(|s| {if s.len() >= 1 {s[0 as usize] = s[0 as usize].to_uppercase()}}).collect() // } pub fn get_current_semester() -> String { let today = DateTime::::from(SystemTime::now()) .date() .naive_local(); let (part, year) = if today.month() >= 4 && today.month() < 10 { ("SS", today.year()) } else { ( "WS", if today.month() >= 10 { today.year() } else { today.year() - 1 }, ) }; format!("{}{}", part, year - 2000) } pub fn glob_paths, S: AsRef>(path: P, pattern: S) -> Result> { let mut paths = vec![]; let pattern = [ (*(path.as_ref())).canonicalize()?.to_str().unwrap(), pattern.as_ref(), ] .concat(); for entry in glob::glob(pattern.as_str())? { let path = entry?; paths.push(path); } Ok(paths) }