Skip to content

FlightLogging: improve date setting behaviour#221

Draft
Claudio-Chies wants to merge 2 commits intodbrgn:mainfrom
Claudio-Chies:pr-flightlogging_date_behaviour
Draft

FlightLogging: improve date setting behaviour#221
Claudio-Chies wants to merge 2 commits intodbrgn:mainfrom
Claudio-Chies:pr-flightlogging_date_behaviour

Conversation

@Claudio-Chies
Copy link
Copy Markdown
Contributor

@Claudio-Chies Claudio-Chies commented Oct 14, 2025

Issue

if logging a flight manually, the time fields were not auto-populated, meaning you had to enter a time even if you didnt care about the flight time because it was a quick afternoon glide.
also when logging a time it was a hassle because you had to set it twice, even if the flight was just a half a hour. (was more a problem on mobile with the scrolling time)

IMG_9504.mp4

Solution

  • Auto populate the Date to be Today and Time as 0:00
  • if setting a takeoff time, the landing time is set to the same time, making it much faster to log times accurately as you are already in the correct range of times (mobile scrolling)
ScreenRecording_10-14-2025.11-24-11_1.mp4

Additional

  • extracted time functionalities into an helper function with tests.
  • igc uploads overwrite manual date and time setting.

Summary by CodeRabbit

  • New Features
    • Flight form now automatically adjusts landing time if set earlier than launch time
    • IGC file uploads automatically populate flight date, times, locations, and distance from file metadata
    • Flight form defaults improved with today's date and standard time values

✏️ Tip: You can customize this high-level summary in your review settings.

@dbrgn
Copy link
Copy Markdown
Owner

dbrgn commented Dec 23, 2025

I'm currently testing CodeRabbit reviews, so don't be surprised if there are automated reviews. We'll see how well it works 🙂

@coderabbitai please review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Dec 23, 2025

@dbrgn: Thank you for trying out CodeRabbit! I'll review the changes in this PR and provide feedback on the improved date setting behavior for flight logging. Looking forward to helping with the review! 🐰

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Dec 23, 2025

Walkthrough

Introduces a new time-helpers utility module containing six functions for converting between time formats, calculating flight durations, and comparing times. Adds comprehensive test coverage for these functions and integrates them into FlightForm for flight data processing and IGC metadata handling.

Changes

Cohort / File(s) Summary
Time Helpers Implementation
frontend/src/lib/time-helpers.ts
New utility module with 6 exported functions: timeToMinutes, minutesToTime, hmsToTime, calculateFlightDuration, ymdToDateString, isTimeBefore. Includes logic for time-to-minute conversion, day rollover handling (adding 1440 minutes when end time precedes start), and rounding of seconds into minutes.
Time Helpers Tests
frontend/src/lib/time-helpers.test.ts
Comprehensive test suite covering: round-trip conversions (timeToMinutes ↔ minutesToTime), rounding behavior for seconds, day rollover scenarios, duration calculations with multiple flight patterns, date string conversion including leap year handling, and time comparisons with edge cases.
FlightForm Integration
frontend/src/routes/flights/FlightForm.svelte
Added imports for time helpers. Updated default values: launchDate defaults to today, launchTime/landingTime default to "00:00". Introduced auto-adjustment logic that updates landingTime when launchTime changes and is later than the previous landing time. Replaced manual duration calculation with calculateFlightDuration(). Modified IGC upload flow to use helper functions for formatting flight date, launch/landing times, and track distance from metadata. Removed legacy hmsToTimevalue helper.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: improving date and time setting behavior in the flight logging feature by auto-populating defaults and synchronizing landing times.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3f91f3c and 87386a3.

📒 Files selected for processing (3)
  • frontend/src/lib/time-helpers.test.ts
  • frontend/src/lib/time-helpers.ts
  • frontend/src/routes/flights/FlightForm.svelte
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Follow TypeScript coding conventions

Files:

  • frontend/src/lib/time-helpers.test.ts
  • frontend/src/lib/time-helpers.ts
frontend/**/*.{ts,tsx,svelte}

📄 CodeRabbit inference engine (AGENTS.md)

Apply Prettier code style using npm run format in the frontend

Files:

  • frontend/src/lib/time-helpers.test.ts
  • frontend/src/lib/time-helpers.ts
  • frontend/src/routes/flights/FlightForm.svelte
**/*.{rs,ts,tsx,svelte}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{rs,ts,tsx,svelte}: Avoid deeply nested logic by using early returns for error cases
Write clean, high-quality code with concise comments and clear variable names

Files:

  • frontend/src/lib/time-helpers.test.ts
  • frontend/src/lib/time-helpers.ts
  • frontend/src/routes/flights/FlightForm.svelte
🧬 Code graph analysis (1)
frontend/src/lib/time-helpers.test.ts (1)
frontend/src/lib/time-helpers.ts (6)
  • timeToMinutes (10-13)
  • minutesToTime (20-24)
  • hmsToTime (31-39)
  • calculateFlightDuration (47-64)
  • ymdToDateString (71-76)
  • isTimeBefore (84-86)
🔇 Additional comments (11)
frontend/src/lib/time-helpers.test.ts (5)

12-28: LGTM! Comprehensive edge case coverage.

The parameterized tests cover all important time boundaries effectively.


30-46: LGTM! Good symmetric testing.

These tests effectively validate the inverse operation of timeToMinutes.


78-126: LGTM! Excellent coverage of duration calculation.

The tests comprehensively cover same-day flights, day rollover, empty inputs, and formatting edge cases.


128-142: LGTM! Good date conversion coverage.

The tests include leap year handling, which is important for date validation.


144-173: LGTM! Clear documentation of same-day limitation.

The test at lines 169-172 usefully documents that isTimeBefore doesn't handle day rollover, which is important context for its usage in FlightForm.

frontend/src/routes/flights/FlightForm.svelte (4)

9-14: LGTM! Clean imports.

All imported helpers are actively used throughout the form logic.


56-60: LGTM! Good UX improvement.

Auto-populating date to today and times to '00:00' for new flights addresses the PR objective of reducing manual entry. The logic correctly preserves existing flight data when editing.


179-182: LGTM! Clean integration of helper function.

Using calculateFlightDuration consolidates the duration logic in a testable utility.


265-287: LGTM! IGC metadata integration is well-implemented.

The intentional overwrite behavior (as noted in comments and PR description) ensures IGC data takes precedence over manual entries, which is the correct approach for accuracy. The use of helpers is consistent and clean.

frontend/src/lib/time-helpers.ts (2)

47-64: LGTM! Robust duration calculation.

The function correctly handles empty inputs, day rollover, and formats durations appropriately for display.


84-86: LGTM! Simple and correct for same-day comparison.

The function is well-suited for its use case, with the same-day limitation documented in the test suite.

Comment on lines +65 to +67
it('handles hour overflow when rounding seconds at 23:59', () => {
expect(hmsToTime([23, 59, 30])).to.equal('24:00');
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Consider handling 24:00 edge case.

The test expects hmsToTime([23, 59, 30]) to produce '24:00', which is technically outside the standard time range (00:00-23:59). This could cause issues if downstream code or UI components expect valid time strings.

Consider wrapping to '00:00' or capping at '23:59' to maintain standard time format compliance.

🔎 Suggested fix

If wrapping to next day is desired:

 it('handles hour overflow when rounding seconds at 23:59', () => {
-    expect(hmsToTime([23, 59, 30])).to.equal('24:00');
+    expect(hmsToTime([23, 59, 30])).to.equal('00:00');
 });

Corresponding implementation fix would be needed in time-helpers.ts.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In frontend/src/lib/time-helpers.test.ts around lines 65–67, the test asserts
hmsToTime([23, 59, 30]) returns '24:00' which is outside the standard
00:00–23:59 range; update the implementation in time-helpers.ts to handle second
rounding overflow by either wrapping to '00:00' (increment day rollover) or
capping to '23:59', then update this test to assert the chosen behavior (e.g.,
expect '00:00' if wrapping, or '23:59' if capping) and add a comment explaining
the chosen policy so downstream consumers know the format guarantee.

Comment on lines +31 to +39
export function hmsToTime(hms: [number, number, number]): string {
let hours = hms[0];
let minutes = Math.round(hms[1] + hms[2] / 60);
if (minutes === 60) {
minutes = 0;
hours += 1;
}
return minutesToTime(hours * 60 + minutes);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Address hour overflow to prevent invalid time format.

The function can produce '24:00' or higher when rounding seconds causes hour overflow (e.g., [23, 59, 30]'24:00'). Standard time format requires hours in the 0-23 range.

Consider wrapping hours to maintain valid time format:

🔎 Proposed fix
 export function hmsToTime(hms: [number, number, number]): string {
     let hours = hms[0];
     let minutes = Math.round(hms[1] + hms[2] / 60);
     if (minutes === 60) {
         minutes = 0;
         hours += 1;
     }
+    // Wrap hours to 0-23 range to maintain valid time format
+    hours = hours % 24;
     return minutesToTime(hours * 60 + minutes);
 }

Also update the test expectation in time-helpers.test.ts line 66 from '24:00' to '00:00'.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export function hmsToTime(hms: [number, number, number]): string {
let hours = hms[0];
let minutes = Math.round(hms[1] + hms[2] / 60);
if (minutes === 60) {
minutes = 0;
hours += 1;
}
return minutesToTime(hours * 60 + minutes);
}
export function hmsToTime(hms: [number, number, number]): string {
let hours = hms[0];
let minutes = Math.round(hms[1] + hms[2] / 60);
if (minutes === 60) {
minutes = 0;
hours += 1;
}
// Wrap hours to 0-23 range to maintain valid time format
hours = hours % 24;
return minutesToTime(hours * 60 + minutes);
}
🤖 Prompt for AI Agents
In frontend/src/lib/time-helpers.ts around lines 31 to 39, hmsToTime can produce
hours >=24 when seconds round up (e.g., [23,59,30] -> "24:00"); clamp or wrap
the hour value into 0-23 after incrementing (hours = hours % 24) before calling
minutesToTime so the result stays a valid 00:00–23:59 time, and update the test
expectation in time-helpers.test.ts line 66 from "24:00" to "00:00".

Comment on lines +109 to +119
// When user changes launch time and landing is earlier, update landing to match launch
let previousLaunchTime = launchTime;
function adjustLandingTime(): void {
if (launchTime !== previousLaunchTime && launchTime !== '' && landingTime !== '') {
if (isTimeBefore(landingTime, launchTime)) {
landingTime = launchTime;
}
}
previousLaunchTime = launchTime;
}
$: reactive(adjustLandingTime, [launchTime]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Day rollover not handled in landing time adjustment.

When launch time changes, if landing time appears earlier (e.g., launch 23:00, landing 01:00 for next-day landing), the function will incorrectly "fix" landing to match launch because isTimeBefore doesn't account for day rollover.

While calculateFlightDuration correctly handles rollover for display, users would need to re-enter the correct landing time after changing launch time in midnight-crossing scenarios.

🔎 Potential fix approach

Consider using calculateFlightDuration to detect if the current duration is valid/reasonable before auto-adjusting:

function adjustLandingTime(): void {
  if (launchTime !== previousLaunchTime && launchTime !== '' && landingTime !== '') {
    const duration = calculateFlightDuration(launchTime, landingTime);
    // Only adjust if landing is truly before launch (not a rollover scenario)
    // For example, if duration would be > 12 hours, it's likely an issue
    if (duration && parseInt(duration.substring(1)) > 12 * 60) {
      landingTime = launchTime;
    }
  }
  previousLaunchTime = launchTime;
}

Note: This is optional given that most flights don't cross midnight.

🤖 Prompt for AI Agents
frontend/src/routes/flights/FlightForm.svelte around lines 109-119: The
adjustLandingTime currently treats any earlier landing time as an error and
overwrites it without accounting for next-day rollovers; change
adjustLandingTime to call calculateFlightDuration(launchTime, landingTime) and
only auto-set landingTime = launchTime when the computed duration indicates an
unlikely/erroneous value (e.g., parsed duration in minutes > 12 * 60) or when
the duration is missing/invalid; otherwise do not adjust so valid next-day
landings are preserved; keep the previousLaunchTime update and reactive
invocation intact.

@dbrgn
Copy link
Copy Markdown
Owner

dbrgn commented Dec 23, 2025

@Claudio-Chies note: Before handling the review comments, I would first want to revisit #74, I think that would be the better solution (instead of working around the time requirement).

@Claudio-Chies
Copy link
Copy Markdown
Contributor Author

@dbrgn sounds good, i can also try to give that a shot. And then we could keep the part where if you set start-time the endtime is autopopulated to the same time, to then make it easyer to adjust.

@dbrgn
Copy link
Copy Markdown
Owner

dbrgn commented Dec 24, 2025

Before you do that, I'll give it a stab myself in the coming days. The change has various implications, so thinking it through and implementing it myself is almost easier than thoroughly reviewing a PR 🙂

@dbrgn dbrgn added the on hold label Dec 24, 2025
@Claudio-Chies Claudio-Chies marked this pull request as draft December 24, 2025 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants