Use cargo fmt

This commit is contained in:
Miraty 2023-02-21 15:48:27 +01:00
parent 7767e5e561
commit d92d2f5932
5 changed files with 42 additions and 29 deletions

View File

@ -1,24 +1,24 @@
pub use std::time::{SystemTime,UNIX_EPOCH};
use libdit::libdit::Dit;
use std::str::FromStr;
pub use libdit::libdit::unix_to_dit_string;
use libdit::libdit::Dit;
pub use libstardit::libstardit::unix_to_stardit;
use std::str::FromStr;
pub use std::time::{SystemTime, UNIX_EPOCH};
fn main() {
/*
let code: &str = &r"0.12.34";
match Dit::from_str(code) {
Ok(dit) => {
println!(
r"Dit: deca: {} decim: {} desec: {}",
dit.deca, dit.decim, dit.desec
);
}
Err(_) => {
println!("{} is not a valid DIT!", code);
}
}
*/
/*
let code: &str = &r"0.12.34";
match Dit::from_str(code) {
Ok(dit) => {
println!(
r"Dit: deca: {} decim: {} desec: {}",
dit.deca, dit.decim, dit.desec
);
}
Err(_) => {
println!("{} is not a valid DIT!", code);
}
}
*/
let current_timestamp = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
@ -26,5 +26,11 @@ fn main() {
let stardit = unix_to_stardit(current_timestamp);
println!("{}\n{}, décade {}, {}", unix_to_dit_string(current_timestamp), stardit.year, stardit.weekade, stardit.day_name);
println!(
"{}\n{}, décade {}, {}",
unix_to_dit_string(current_timestamp),
stardit.year,
stardit.weekade,
stardit.day_name
);
}

View File

@ -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)
);
}
}

View File

@ -1,17 +1,17 @@
extern crate chrono;
pub mod libstardit {
use chrono::{TimeZone, Datelike, LocalResult};
use chrono::{Datelike, LocalResult, TimeZone};
pub struct StarDIT {
pub year: u16,
pub weekade: u16,
pub day_name: String,
pub day: u16
pub day: u16,
}
pub fn unix_to_stardit(unix: f64) -> StarDIT {
let date = match chrono::Utc.timestamp_millis_opt(((unix as i64) - 12*3600) * 1000) {
let date = match chrono::Utc.timestamp_millis_opt(((unix as i64) - 12 * 3600) * 1000) {
LocalResult::Single(date) => date,
_ => panic!("Incorrect timestamp_millis"),
};
@ -31,7 +31,8 @@ pub mod libstardit {
8 => "octidi",
9 => "nonidi",
_ => "?",
}.to_string(),
}
.to_string(),
day: day,
};
}

1
rustfmt.toml Normal file
View File

@ -0,0 +1 @@
hard_tabs = true

View File

@ -1,5 +1,5 @@
pub use std::time::{SystemTime,UNIX_EPOCH};
pub use libstardit::libstardit::unix_to_stardit;
pub use std::time::{SystemTime, UNIX_EPOCH};
fn main() {
let current_timestamp = SystemTime::now()
@ -52,5 +52,5 @@ fn main() {
}
fn is_leap_year(year: i32) -> bool {
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
}