use embassy_time::Instant;

// TODO: Is this right?
#[allow(non_camel_case_types)]
pub type time_t = i64;

#[unsafe(no_mangle)]
pub unsafe extern "C" fn __spre_time(time: *mut time_t) -> time_t {
    // TODO: This currently measures the time since boot,
    // but it should actually measure the time since the unix epoch.
    let duration = Instant::now().duration_since(Instant::MIN);
    let seconds_since_epoch = duration.as_secs() as time_t;

    if !time.is_null() {
        unsafe {
            *time = seconds_since_epoch;
        }
    }

    seconds_since_epoch
}
