XeOS/src/clock.rs

21 lines
559 B
Rust
Raw Normal View History

2019-10-24 15:24:17 +00:00
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<CMOS> = Mutex::new(unsafe { CMOS::new() });
}
pub fn current_time() -> DateTime<Utc> {
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());
}