|
|
|
@ -5,7 +5,7 @@ pub mod libdit {
|
|
|
|
|
pub struct Dit {
|
|
|
|
|
pub deca: u16,
|
|
|
|
|
pub decim: u16,
|
|
|
|
|
pub desec: u16
|
|
|
|
|
pub desec: u16,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl FromStr for Dit {
|
|
|
|
@ -15,14 +15,14 @@ pub mod libdit {
|
|
|
|
|
return Ok(Dit {
|
|
|
|
|
deca: u16::from_str_radix(&dit[0..1], 10)?,
|
|
|
|
|
decim: u16::from_str_radix(&dit[2..4], 10)?,
|
|
|
|
|
desec: u16::from_str_radix(&dit[5..7], 10)?
|
|
|
|
|
desec: u16::from_str_radix(&dit[5..7], 10)?,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Returns relative progress in the day, between 0 and 1 corresponding to `unix`
|
|
|
|
|
pub fn unix_to_dit(unix: f64) -> f64 {
|
|
|
|
|
return (unix - (12.0*3600.0)) % 86400.0 / 86400.0;
|
|
|
|
|
return (unix - (12.0 * 3600.0)) % 86400.0 / 86400.0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Returns a struct containing deca, decim and desec corresponding to `unix`
|
|
|
|
@ -31,7 +31,7 @@ pub mod libdit {
|
|
|
|
|
return Dit {
|
|
|
|
|
deca: (dit * 10.0 % 10.0) as u16,
|
|
|
|
|
decim: (dit * 1000.0 % 100.0) as u16,
|
|
|
|
|
desec: (dit * 100000.0 % 100.0) as u16
|
|
|
|
|
desec: (dit * 100000.0 % 100.0) as u16,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -45,6 +45,11 @@ pub mod libdit {
|
|
|
|
|
/// ```
|
|
|
|
|
pub fn unix_to_dit_string(unix: f64) -> String {
|
|
|
|
|
let dit = unix_to_dit_struct(unix);
|
|
|
|
|
return format!("{}.{}.{}", dit.deca, format!("{:0>2}", dit.decim), format!("{:0>2}", dit.desec));
|
|
|
|
|
return format!(
|
|
|
|
|
"{}.{}.{}",
|
|
|
|
|
dit.deca,
|
|
|
|
|
format!("{:0>2}", dit.decim),
|
|
|
|
|
format!("{:0>2}", dit.desec)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|