avoid some bugs if we simulate way past 24 hours

This commit is contained in:
Dustin Carlino 2020-01-09 12:01:12 -06:00
parent 53f33a31e4
commit 0a5d945f20
2 changed files with 10 additions and 9 deletions

View File

@ -398,7 +398,8 @@ impl TimePanel {
let width = 300.0;
let y1 = 5.0;
let height = Distance::meters(15.0);
let percent = ui.primary.sim.time().to_percent(Time::END_OF_DAY);
// Just clamp past 24 hours
let percent = ui.primary.sim.time().to_percent(Time::END_OF_DAY).min(1.0);
// TODO rounded
batch.push(

View File

@ -49,14 +49,14 @@ impl Time {
pub fn ampm_tostring(self) -> String {
let (mut hours, minutes, seconds, remainder) = self.get_parts();
let suffix = if hours < 12 {
"AM"
} else if hours < 24 {
"PM"
let next_day = if hours >= 24 {
let days = hours / 24;
hours = hours % 24;
format!(" (+{} days)", days)
} else {
// Give up on the AM/PM distinction I guess. This shouldn't be used much.
"(+1 day)"
"".to_string()
};
let suffix = if hours < 12 { "AM" } else { "PM" };
if hours == 0 {
hours = 12;
} else if hours >= 24 {
@ -66,8 +66,8 @@ impl Time {
}
format!(
"{:02}:{:02}:{:02}.{:01} {}",
hours, minutes, seconds, remainder, suffix
"{:02}:{:02}:{:02}.{:01} {}{}",
hours, minutes, seconds, remainder, suffix, next_day
)
}