Use cargo fmt
This commit is contained in:
parent
7767e5e561
commit
d92d2f5932
|
@ -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;
|
pub use libdit::libdit::unix_to_dit_string;
|
||||||
|
use libdit::libdit::Dit;
|
||||||
pub use libstardit::libstardit::unix_to_stardit;
|
pub use libstardit::libstardit::unix_to_stardit;
|
||||||
|
use std::str::FromStr;
|
||||||
|
pub use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
/*
|
/*
|
||||||
let code: &str = &r"0.12.34";
|
let code: &str = &r"0.12.34";
|
||||||
match Dit::from_str(code) {
|
match Dit::from_str(code) {
|
||||||
Ok(dit) => {
|
Ok(dit) => {
|
||||||
println!(
|
println!(
|
||||||
r"Dit: deca: {} decim: {} desec: {}",
|
r"Dit: deca: {} decim: {} desec: {}",
|
||||||
dit.deca, dit.decim, dit.desec
|
dit.deca, dit.decim, dit.desec
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
println!("{} is not a valid DIT!", code);
|
println!("{} is not a valid DIT!", code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
let current_timestamp = SystemTime::now()
|
let current_timestamp = SystemTime::now()
|
||||||
.duration_since(UNIX_EPOCH)
|
.duration_since(UNIX_EPOCH)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -26,5 +26,11 @@ fn main() {
|
||||||
|
|
||||||
let stardit = unix_to_stardit(current_timestamp);
|
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
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ pub mod libdit {
|
||||||
pub struct Dit {
|
pub struct Dit {
|
||||||
pub deca: u16,
|
pub deca: u16,
|
||||||
pub decim: u16,
|
pub decim: u16,
|
||||||
pub desec: u16
|
pub desec: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for Dit {
|
impl FromStr for Dit {
|
||||||
|
@ -15,14 +15,14 @@ pub mod libdit {
|
||||||
return Ok(Dit {
|
return Ok(Dit {
|
||||||
deca: u16::from_str_radix(&dit[0..1], 10)?,
|
deca: u16::from_str_radix(&dit[0..1], 10)?,
|
||||||
decim: u16::from_str_radix(&dit[2..4], 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`
|
/// Returns relative progress in the day, between 0 and 1 corresponding to `unix`
|
||||||
pub fn unix_to_dit(unix: f64) -> f64 {
|
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`
|
/// Returns a struct containing deca, decim and desec corresponding to `unix`
|
||||||
|
@ -31,7 +31,7 @@ pub mod libdit {
|
||||||
return Dit {
|
return Dit {
|
||||||
deca: (dit * 10.0 % 10.0) as u16,
|
deca: (dit * 10.0 % 10.0) as u16,
|
||||||
decim: (dit * 1000.0 % 100.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 {
|
pub fn unix_to_dit_string(unix: f64) -> String {
|
||||||
let dit = unix_to_dit_struct(unix);
|
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)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
extern crate chrono;
|
extern crate chrono;
|
||||||
|
|
||||||
pub mod libstardit {
|
pub mod libstardit {
|
||||||
use chrono::{TimeZone, Datelike, LocalResult};
|
use chrono::{Datelike, LocalResult, TimeZone};
|
||||||
|
|
||||||
pub struct StarDIT {
|
pub struct StarDIT {
|
||||||
pub year: u16,
|
pub year: u16,
|
||||||
pub weekade: u16,
|
pub weekade: u16,
|
||||||
pub day_name: String,
|
pub day_name: String,
|
||||||
pub day: u16
|
pub day: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unix_to_stardit(unix: f64) -> StarDIT {
|
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,
|
LocalResult::Single(date) => date,
|
||||||
_ => panic!("Incorrect timestamp_millis"),
|
_ => panic!("Incorrect timestamp_millis"),
|
||||||
};
|
};
|
||||||
|
@ -31,7 +31,8 @@ pub mod libstardit {
|
||||||
8 => "octidi",
|
8 => "octidi",
|
||||||
9 => "nonidi",
|
9 => "nonidi",
|
||||||
_ => "?",
|
_ => "?",
|
||||||
}.to_string(),
|
}
|
||||||
|
.to_string(),
|
||||||
day: day,
|
day: day,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
hard_tabs = true
|
|
@ -1,5 +1,5 @@
|
||||||
pub use std::time::{SystemTime,UNIX_EPOCH};
|
|
||||||
pub use libstardit::libstardit::unix_to_stardit;
|
pub use libstardit::libstardit::unix_to_stardit;
|
||||||
|
pub use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let current_timestamp = SystemTime::now()
|
let current_timestamp = SystemTime::now()
|
||||||
|
@ -52,5 +52,5 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_leap_year(year: i32) -> bool {
|
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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue