mirror of
https://github.com/storytold/lightcraft.git
synced 2026-10-27 19:47:35 -06:00
LR-LIB-CULL: a gap past an hour shows its seconds, so its text reads back the same gap (#2275)
fmt_gap wrote whole minutes past an hour, which only drag values could hit before; with the culling value fields taking any gap up to a day, a typed 3601 s showed as "1 h 0 min" and editing that text gave 3600 s. Past an hour it now writes "1 h 0 min 1 s" when there are seconds left (the Auto-Stack slider shares the formatter). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
6b3cc777c1
commit
54df21cb08
@@ -1664,7 +1664,9 @@ pub fn fmt_gap(v: f64) -> String {
|
||||
60..3600 if v.is_multiple_of(60) => format!("{} min", v / 60),
|
||||
60..3600 => format!("{} min {} s", v / 60, v % 60),
|
||||
3600..86400 if v.is_multiple_of(3600) => format!("{} h", v / 3600),
|
||||
3600..86400 => format!("{} h {} min", v / 3600, v % 3600 / 60),
|
||||
3600..86400 if v.is_multiple_of(60) => format!("{} h {} min", v / 3600, v % 3600 / 60),
|
||||
// the seconds too, so editing the text reads back the same gap
|
||||
3600..86400 => format!("{} h {} min {} s", v / 3600, v % 3600 / 60, v % 60),
|
||||
_ => crate::i18n::tr("1 day").into(),
|
||||
}
|
||||
}
|
||||
@@ -2409,8 +2411,7 @@ mod gap_tests {
|
||||
|
||||
#[test]
|
||||
fn gap_text_reads_back_what_it_shows() {
|
||||
for v in [0.0, 1.0, 12.0, 59.0, 60.0, 90.0, 600.0, 3599.0, 3600.0, 3900.0, 86340.0] {
|
||||
// past an hour the text shows whole minutes
|
||||
for v in [0.0, 1.0, 12.0, 59.0, 60.0, 90.0, 600.0, 3599.0, 3600.0, 3601.0, 3661.0, 3900.0, 7325.0, 86340.0, 86399.0] {
|
||||
assert_eq!(parse_gap(&fmt_gap(v)), Some(v), "{}", fmt_gap(v));
|
||||
}
|
||||
assert_eq!(parse_gap("1 day"), Some(86400.0));
|
||||
@@ -2431,7 +2432,7 @@ mod gap_tests {
|
||||
#[test]
|
||||
fn gaps_past_the_slider_read_back_too() {
|
||||
// the Assisted Culling slider drags to 10 min; its value field takes up to a day
|
||||
for (v, text) in [(1800.0, "30 min"), (5400.0, "1 h 30 min"), (86400.0, "1 day")] {
|
||||
for (v, text) in [(1800.0, "30 min"), (5400.0, "1 h 30 min"), (3601.0, "1 h 0 min 1 s"), (86400.0, "1 day")] {
|
||||
assert_eq!(fmt_gap(v), text);
|
||||
assert_eq!(parse_gap(text), Some(v), "{text}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user