Skip to content

Instantly share code, notes, and snippets.

View pmkroeker's full-sized avatar

Peter pmkroeker

View GitHub Profile
use std::convert::TryInto;
use chrono::prelude::*; // 0.4.11
pub struct Mondays {}
impl Mondays {
pub fn count(birth: chrono::NaiveDate, curr_date: chrono::NaiveDate) -> i64 {
// start work at age 22
let start_work = birth + chrono::Duration::days(22 * 365);
// retire at age 78
// https://dev.to/thepracticaldev/daily-challenge-29-xs-and-os-12mj
pub fn xo (value: &str) -> bool {
let value = value.to_lowercase();
let count_x = value.matches("x").count();
let count_o = value.matches("o").count();
count_x == count_o
}
#[cfg(test)]
pub fn ccbreaker (value: &str) -> String {
value.chars()
.into_iter()
.map(|c| if c.is_uppercase() { format!(" {}", c.to_lowercase()) } else { c.to_string() })
.collect::<String>()
}
#[cfg(test)]
mod tests {
use super::*;
// Convert number to hex string.
pub fn to_hex (value: i32) -> String {
let value = if value > 255 { 255 } else if value < 0 { 0 } else { value };
format!("{:02X}", value)
}
// Join all hex strings together from rgb input.
pub fn rgb (r: i32, g: i32, b: i32) -> String {
format!("{}{}{}", to_hex(r), to_hex(g), to_hex(b))
}