cleaned up clippy comments
This commit is contained in:
parent
933fda9b2b
commit
3dbbd5713a
1 changed files with 36 additions and 44 deletions
|
@ -41,14 +41,14 @@ pub fn run_calendar(args: &CliArgs) {
|
||||||
}
|
}
|
||||||
let value = buffer[21..].to_string();
|
let value = buffer[21..].to_string();
|
||||||
|
|
||||||
if value.starts_with("Moonrise") {
|
if let Some(time) = value.strip_prefix("Moonrise") {
|
||||||
moonrise = parse_time(value[8..].trim());
|
moonrise = parse_time(time.trim());
|
||||||
} else if value.starts_with("Moonset") {
|
} else if let Some(time) = value.strip_prefix("Moonset") {
|
||||||
moonset = parse_time(value[7..].trim());
|
moonset = parse_time(time.trim());
|
||||||
} else if value.starts_with("Moonday") {
|
} else if let Some(time) = value.strip_prefix("Moonday") {
|
||||||
moonday = parse_time(value[7..].trim());
|
moonday = parse_time(time.trim());
|
||||||
} else if value.starts_with("Moonphase") {
|
} else if let Some(phase) = value.strip_prefix("Moonphase") {
|
||||||
moonphase = match value[9..].trim()[0..2].parse::<u32>() {
|
moonphase = match phase.trim()[0..2].parse::<u32>() {
|
||||||
Ok(val) => Some(val),
|
Ok(val) => Some(val),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
if args.debug {
|
if args.debug {
|
||||||
|
@ -57,10 +57,10 @@ pub fn run_calendar(args: &CliArgs) {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} else if value.starts_with("Sunrise") {
|
} else if let Some(time) = value.strip_prefix("Sunrise") {
|
||||||
sunrise = parse_time(value[7..].trim());
|
sunrise = parse_time(time.trim());
|
||||||
} else if value.starts_with("Sunset") {
|
} else if let Some(time) = value.strip_prefix("Sunset") {
|
||||||
sunset = parse_time(value[6..].trim());
|
sunset = parse_time(time.trim());
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -83,66 +83,58 @@ pub fn run_calendar(args: &CliArgs) {
|
||||||
moonphase: 0,
|
moonphase: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
if moonphase.is_some() {
|
if let Some(moon_phase) = moonphase {
|
||||||
output_state.moonphase = moonphase.unwrap();
|
output_state.moonphase = moon_phase;
|
||||||
}
|
}
|
||||||
|
|
||||||
let now_mins = (Local::now().hour() * 60 + Local::now().minute()) as i32;
|
let now_mins = (Local::now().hour() * 60 + Local::now().minute()) as i32;
|
||||||
|
|
||||||
if sunrise.is_none() {
|
if sunrise.is_none() {
|
||||||
sunrise = Some(8 * 60 + 0);
|
sunrise = Some(8 * 60);
|
||||||
}
|
}
|
||||||
if sunset.is_none() {
|
if sunset.is_none() {
|
||||||
sunset = Some(18 * 60 + 0);
|
sunset = Some(18 * 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
let sun_rise = sunrise.clone().unwrap();
|
let sun_rise = sunrise.unwrap();
|
||||||
let sun_set = sunset.clone().unwrap();
|
let sun_set = sunset.unwrap();
|
||||||
if now_mins > sun_rise && now_mins < sun_set {
|
if now_mins > sun_rise && now_mins < sun_set {
|
||||||
// it is after sunrise, and before sunset
|
// it is after sunrise, and before sunset
|
||||||
output_state.has_bg = true;
|
output_state.has_bg = true;
|
||||||
output_state.is_sun = true;
|
output_state.is_sun = true;
|
||||||
output_state.gradient_angle_percentage =
|
output_state.gradient_angle_percentage =
|
||||||
{ (now_mins - sun_rise) as f32 / (sun_set - sun_rise) as f32 };
|
(now_mins - sun_rise) as f32 / (sun_set - sun_rise) as f32;
|
||||||
} else {
|
} else {
|
||||||
// Check if the moon is up
|
// Check if the moon is up
|
||||||
if moonrise.is_some() {
|
if let Some(moon_rise) = moonphase {
|
||||||
let moon_rise = moonrise.clone().unwrap();
|
if let Some(moon_set) = moonset {
|
||||||
if moonset.is_some() {
|
if now_mins > moon_rise as i32 && now_mins < moon_set {
|
||||||
let moon_set = moonset.clone().unwrap();
|
|
||||||
if now_mins > moon_rise && now_mins < moon_set {
|
|
||||||
// moon is up
|
// moon is up
|
||||||
output_state.has_bg = true;
|
output_state.has_bg = true;
|
||||||
output_state.is_sun = false;
|
output_state.is_sun = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else if now_mins > moon_rise as i32 {
|
||||||
if now_mins > moon_rise {
|
output_state.has_bg = true;
|
||||||
output_state.has_bg = true;
|
output_state.is_sun = false;
|
||||||
output_state.is_sun = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else if let Some(moon_set) = moonset {
|
||||||
if moonset.is_some() {
|
if now_mins < moon_set {
|
||||||
let moon_set = moonset.clone().unwrap();
|
// moon is up
|
||||||
if now_mins < moon_set {
|
output_state.has_bg = true;
|
||||||
// moon is up
|
output_state.is_sun = false;
|
||||||
output_state.has_bg = true;
|
|
||||||
output_state.is_sun = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if output_state.has_bg == true && output_state.is_sun == false {
|
if output_state.has_bg && !output_state.is_sun {
|
||||||
// moon is up, get the position
|
// moon is up, get the position
|
||||||
if moonrise.is_some() {
|
if let Some(moon_rise) = moonrise {
|
||||||
let moon_rise = moonrise.clone().unwrap();
|
let moon_day = moonday.unwrap();
|
||||||
let moon_day = moonday.clone().unwrap();
|
|
||||||
|
|
||||||
output_state.gradient_angle_percentage =
|
output_state.gradient_angle_percentage =
|
||||||
{ (now_mins - moon_rise) as f32 / moon_day as f32 };
|
(now_mins - moon_rise) as f32 / moon_day as f32;
|
||||||
} else {
|
} else {
|
||||||
let moon_set = moonset.clone().unwrap();
|
let moon_set = moonset.unwrap();
|
||||||
let moon_day = moonday.clone().unwrap();
|
let moon_day = moonday.unwrap();
|
||||||
let begin_mins: i32 = moon_set - moon_day;
|
let begin_mins: i32 = moon_set - moon_day;
|
||||||
let time_since_rise = now_mins + (begin_mins.abs());
|
let time_since_rise = now_mins + (begin_mins.abs());
|
||||||
output_state.gradient_angle_percentage = time_since_rise as f32 / moon_set as f32;
|
output_state.gradient_angle_percentage = time_since_rise as f32 / moon_set as f32;
|
||||||
|
|
Loading…
Reference in a new issue