1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
use std::ops::Add;
use chrono::{DateTime, Duration, Timelike, Local};

const CLOCKS: [&str; 24] = [
    "🕛", "🕧", "🕐", "🕜", "🕑", "🕝", "🕒", "🕞", "🕓", "🕟", "🕔", "🕠",
    "🕕", "🕡", "🕖", "🕢", "🕗", "🕣", "🕘", "🕤", "🕙", "🕥", "🕚", "🕦"
];
const DURATION: usize = 60 * 30;

pub fn get_emoji(time: &Option<DateTime<Local>>) -> &'static str {
    let time = time.unwrap_or_else(Local::now);
    let time = time.add(Duration::minutes(15));
    let seconds = time.time().num_seconds_from_midnight() as usize;
    let index = seconds / DURATION;

    CLOCKS[index % CLOCKS.len()]
}

#[allow(dead_code)]
fn main() {
    println!("{}", get_emoji(&None));
}