Skip to content

Commit 42b7c27

Browse files
authored
Fix time adjustment buttons after copying from previous waypoint (#297)
* handle small bug, multiples of 5 for copying times from previous wp * fix time adjustment button logic after copying from previous wp
1 parent de9508d commit 42b7c27

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

src/virtualship/cli/_plan.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,15 @@ def copy_from_previous(self) -> None:
872872
prev = schedule_editor.query_one(f"#wp{self.index - 1}_{comp}")
873873
curr = self.query_one(f"#wp{self.index}_{comp}")
874874
if prev and curr:
875-
curr.value = prev.value
875+
if (
876+
comp == "minute"
877+
): # special handle minute, round to nearest 5 for compatibility with options
878+
minute_value = prev.value
879+
if minute_value % 5 != 0:
880+
minute_value = 5 * round(minute_value / 5)
881+
curr.value = minute_value
882+
else:
883+
curr.value = prev.value
876884

877885
for instrument in [
878886
inst for inst in InstrumentType if not inst.is_underway
@@ -885,6 +893,17 @@ def copy_from_previous(self) -> None:
885893
)
886894
if prev_switch and curr_switch:
887895
curr_switch.value = prev_switch.value
896+
897+
# hard update self.waypoint.time to match new values as shown in UI
898+
year = int(self.query_one(f"#wp{self.index}_year").value)
899+
month = int(self.query_one(f"#wp{self.index}_month").value)
900+
day = int(self.query_one(f"#wp{self.index}_day").value)
901+
hour = int(self.query_one(f"#wp{self.index}_hour").value)
902+
minute = int(self.query_one(f"#wp{self.index}_minute").value)
903+
self.waypoint.time = datetime.datetime(
904+
year, month, day, hour, minute, 0
905+
)
906+
888907
except Exception as e:
889908
raise UnexpectedError(unexpected_msg_compose(e)) from None
890909

0 commit comments

Comments
 (0)