use chrono::prelude::*; use cmos::{CMOSCenturyHandler, CMOS}; use core::convert::TryInto; use lazy_static::lazy_static; use spin::Mutex; lazy_static! { static ref CLOCK: Mutex = Mutex::new(unsafe { CMOS::new() }); } pub fn current_time() -> DateTime { let rtc = CLOCK.lock().read_rtc(CMOSCenturyHandler::CurrentYear(2019)); return Utc .ymd( rtc.year.try_into().unwrap(), rtc.month.into(), rtc.day.into(), ) .and_hms(rtc.hour.into(), rtc.minute.into(), rtc.second.into()); }