An experimental microkernel OS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
825 B

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(2000));
return Utc
.and_hms(rtc.hour.into(), rtc.minute.into(), rtc.second.into());
use crate::{println, serial_print, serial_println};
fn test_current_time() {
serial_print!("current time... ");
let now = current_time();
println!("{:?}", now);
assert_ne!(now.month(), 0);