Skip to content

Schedule.Timestamp KT ext - #191

Merged
mmathieum merged 3 commits into
masterfrom
mm/show_hide_rt_in_schedule_screen
Jul 30, 2026
Merged

mmathieum merged 3 commits into
masterfrom
mm/show_hide_rt_in_schedule_screen

Conversation

@mmathieum

Copy link
Copy Markdown
Member

@mmathieum mmathieum self-assigned this Jul 30, 2026
@mmathieum mmathieum changed the title Schedule timestamp KT ext Schedule.Timestamp KT ext Jul 30, 2026
@mmathieum
mmathieum marked this pull request as ready for review July 30, 2026 13:32
@mmathieum
mmathieum requested a review from Copilot July 30, 2026 13:32
@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Add Schedule.Timestamp helpers to hide real-time times/diffs

✨ Enhancement 🕐 10-20 Minutes

Grey Divider

AI Description

• Add timestamp helpers that switch between real-time and original schedule values.
• Recompute “original” arrival/departure using millisecond fields and Instant conversions.
• Add original arrival/departure diff accessors plus a hide-real-time aware diff helper.
Diagram

graph TD
  A["Schedule screen"] --> B["Hide RT flag"] --> C["ScheduleExt.kt"] --> D["Displayed times"]
  C --> E["Schedule.Timestamp"]
  F[("Schedule data")] --> E
  G{{"Real-time updates"}} --> E
  subgraph Legend
    direction LR
    _ui["UI"] ~~~ _logic["Logic"] ~~~ _db[("Data")] ~~~ _ext{{"External"}}
  end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Use a value object instead of Boolean (e.g., enum DisplayMode)
  • ➕ Improves call-site readability vs passing hideRealTime=true/false
  • ➕ Scales better if more modes are added (e.g., show both, show delta only)
  • ➖ Slightly more boilerplate and wider signature changes at call sites
2. Keep original computations in Instant space only
  • ➕ Avoids mixed representations (ms vs Instant) and reduces conversion helpers
  • ➖ Potentially less efficient if many values are computed repeatedly; may require more Instant arithmetic allocations
3. Move hide-real-time switching into UI formatting layer
  • ➕ Keeps model extensions purely about domain data, not presentation choices
  • ➖ Duplicates selection logic across call sites; risks inconsistent behavior for diff vs timestamps

Recommendation: Current approach is reasonable for centralizing the hide-real-time selection logic in one place (extensions on Schedule.Timestamp), which reduces UI duplication and keeps behavior consistent for departure/arrival and diffs. If this flag starts spreading broadly, consider switching the Boolean parameter to a DisplayMode enum for clarity and future extensibility.

Files changed (1) +12 / -2

Enhancement (1) +12 / -2
ScheduleExt.ktAdd hide-real-time aware timestamp + diff extensions +12/-2

Add hide-real-time aware timestamp + diff extensions

• Introduces helpers to return departure/arrival milliseconds based on a hideRealTime flag (original vs real-time). Refactors original departure/arrival to be derived from millisecond timestamps and delay fields with Instant conversion. Adds original arrival/departure diff accessors and a hide-real-time aware diff getter.

src/main/java/org/mtransit/android/commons/data/ScheduleExt.kt

@coderabbitai

coderabbitai Bot commented Jul 30, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@mmathieum, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 31 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 01488b26-3311-4837-a934-90ea176b6d6e

📥 Commits

Reviewing files that changed from the base of the PR and between c1c3688 and bbcd3d1.

📒 Files selected for processing (1)
  • src/main/java/org/mtransit/android/commons/data/ScheduleExt.kt
📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Corrected real-time delay application to base timing changes on the departure/arrival difference (instead of the arrival-only difference), improving accuracy for departure updates.
    • Updated stored schedule timestamps and stop-time parsing to consistently use the new departure/arrival diff representation.
  • Tests
    • Updated schedule and real-time delay test expectations to reflect the departure/arrival difference behavior.

Walkthrough

The timestamp diff model is renamed from arrival diff to departure-arrival diff across Schedule.Timestamp accessors, JSON persistence, GTFS stop-time parsing, real-time delay calculations, and related tests.

Changes

Schedule departure-arrival diff

Layer / File(s) Summary
Timestamp diff contract and accessors
src/main/java/org/mtransit/android/commons/data/Schedule.java, src/main/java/org/mtransit/android/commons/data/ScheduleExt.kt
Stores and exposes departureArrivalDiff, derives arrival times from it, and updates equality, hashing, and string output.
Timestamp diff JSON persistence
src/main/java/org/mtransit/android/commons/data/Schedule.java
Reads and writes the renamed departure-arrival diff JSON field.
GTFS stop-time diff parsing
src/main/java/org/mtransit/android/commons/provider/gtfs/GTFSStatusProvider.java
Uses the renamed stop-time column index and variables when parsing positive departure-arrival differences.
Real-time delay calculations
src/main/java/org/mtransit/android/commons/provider/status/GTFSRealTimeTripUpdatesProviderExt.kt, src/test/java/org/mtransit/android/commons/data/ScheduleExtTests.kt, src/test/java/org/mtransit/android/commons/provider/status/GTFSRealTimeTripUpdatesProviderTests.kt
Uses departureArrivalDiff when applying delays and updates affected test assertions and delay inputs.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant GTFSStatusProvider
  participant ScheduleTimestamp
  participant GTFSRealTimeTripUpdatesProvider
  GTFSStatusProvider->>ScheduleTimestamp: parse departure-arrival diff
  GTFSRealTimeTripUpdatesProvider->>ScheduleTimestamp: read departureArrivalDiff
  GTFSRealTimeTripUpdatesProvider->>GTFSRealTimeTripUpdatesProvider: apply delay using diff
  ScheduleTimestamp->>ScheduleTimestamp: derive arrival timestamp
Loading
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is related, but it is too vague to clearly convey the main change. Use a descriptive title like “Rename Schedule.Timestamp diff helpers to departure/arrival diff”.
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The description is related to the change set by referencing the corresponding upstream PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch mm/show_hide_rt_in_schedule_screen

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/main/java/org/mtransit/android/commons/data/ScheduleExt.kt (1)

125-129: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add coverage for both hideRealTime branches.

The existing tests cover original Instant derivation, but not departureMs(hideRealTime) or arrivalMs(hideRealTime). Add assertions for both true and false after a real-time update.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main/java/org/mtransit/android/commons/data/ScheduleExt.kt` around lines
125 - 129, Add test coverage for Schedule.Timestamp.departureMs and arrivalMs
after a real-time update, asserting the original millisecond values when
hideRealTime is true and the updated real-time values when it is false. Extend
the existing original Instant derivation test or its surrounding test fixture
without changing the production extensions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/main/java/org/mtransit/android/commons/data/ScheduleExt.kt`:
- Around line 172-175: Update Schedule.Timestamp.originalArrivalDiffMs so the
original arrival difference is clamped consistently with arrivalDiff, preventing
negative values when originalArrivalMs exceeds originalDepartureMs. Preserve
getArrivalDiff’s existing hideRealTime selection while ensuring both branches
return the same non-negative duration contract.

---

Nitpick comments:
In `@src/main/java/org/mtransit/android/commons/data/ScheduleExt.kt`:
- Around line 125-129: Add test coverage for Schedule.Timestamp.departureMs and
arrivalMs after a real-time update, asserting the original millisecond values
when hideRealTime is true and the updated real-time values when it is false.
Extend the existing original Instant derivation test or its surrounding test
fixture without changing the production extensions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 0e52c675-7c29-451b-a801-2bea1373f4d3

📥 Commits

Reviewing files that changed from the base of the PR and between ad79423 and 8f76f2b.

📒 Files selected for processing (1)
  • src/main/java/org/mtransit/android/commons/data/ScheduleExt.kt

ghost left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Not ready to approve

A newly introduced “original arrival diff” path can return negative durations (unlike the existing clamped arrivalDiff), which can lead to inconsistent behavior when hideRealTime=true.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Pull request overview

Adds Kotlin extension helpers on Schedule.Timestamp to work with “original” (non-real-time) vs real-time values, including millisecond-based accessors and diff utilities, likely to support a “hide real-time” display/logic mode consistently across the app.

Changes:

  • Added departureMs(hideRealTime) / arrivalMs(hideRealTime) helpers to return either original or real-time timestamps in milliseconds.
  • Introduced originalDepartureMs / originalArrivalMs and refactored originalDeparture / originalArrival to derive from those ms values.
  • Added originalArrivalDiff* extensions plus getArrivalDiff(hideRealTime) to mirror existing arrivalDiff behavior.
File summaries
File Description
src/main/java/org/mtransit/android/commons/data/ScheduleExt.kt Adds ms-based timestamp helpers and “original vs real-time” diff utilities for Schedule.Timestamp.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Low

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

@qodo-code-review

ghost commented Jul 30, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Negative original arrival diff ✓ Resolved 🐞 Bug ≡ Correctness
Description
Schedule.Timestamp.originalArrivalDiff is exposed without the non-negative clamping used by
arrivalDiff, so it can return a negative Duration when arrival is after departure (invalid data
or inconsistent updates). Any caller using getArrivalDiff(hideRealTime = true) may then receive a
negative interval, diverging from the established arrivalDiff >= 0 invariant used elsewhere in the
codebase.
Code

src/main/java/org/mtransit/android/commons/data/ScheduleExt.kt[R172-175]

+val Schedule.Timestamp.originalArrivalDiffMs get() = originalDepartureMs - originalArrivalMs
+val Schedule.Timestamp.originalArrivalDiff get() = originalArrivalDiffMs.milliseconds
+
+fun Schedule.Timestamp.getArrivalDiff(hideRealTime: Boolean) = if (hideRealTime) originalArrivalDiff else arrivalDiff
Relevance

●●● Strong

Team often accepts small correctness/invariant fixes; no close rejection precedent for clamping
negative diffs.

PR-#189
PR-#81

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The codebase already treats arrival/departure diff as non-negative by clamping arrivalDiff to
Duration.ZERO. However, Schedule.Timestamp allows an arrival timestamp later than departure
because setArrivalT() stores arrivalDiffMs = departure - arrival (which becomes negative if
arrival > departure). The PR introduces originalArrivalDiff and returns it directly (no clamping),
so the new getArrivalDiff(hideRealTime = true) path can surface a negative duration where callers
expect the arrivalDiff invariant.

src/main/java/org/mtransit/android/commons/data/ScheduleExt.kt[159-175]
src/main/java/org/mtransit/android/commons/data/Schedule.java[507-529]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`originalArrivalDiff` is currently returned as a raw `Duration` from a millisecond subtraction that can be negative. This is inconsistent with `arrivalDiff`, which clamps to `>= 0`, and can leak negative values via `getArrivalDiff(hideRealTime = true)`.

### Issue Context
- `arrivalDiff` already enforces a non-negative invariant.
- `Timestamp.setArrivalT()` stores `arrivalDiffMs = departure - arrival`, which can be negative if arrival > departure, so negative diffs are possible.

### Fix Focus Areas
- src/main/java/org/mtransit/android/commons/data/ScheduleExt.kt[172-175]

### Suggested change
Make `originalArrivalDiff` mirror `arrivalDiff` behavior, e.g.:
- `val Schedule.Timestamp.originalArrivalDiff get() = originalArrivalDiffMs.milliseconds.coerceAtLeast(Duration.ZERO)`

Optionally, also clamp at the millisecond level:
- `val Schedule.Timestamp.originalArrivalDiffMs get() = (originalDepartureMs - originalArrivalMs).coerceAtLeast(0L)`

(Choose one approach; clamping at the `Duration` level matches the existing `arrivalDiff` pattern.)

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

To customize comments, go to the Qodo configuration screen, or learn more in the docs.

Qodo Logo

Mathieu Méa added 2 commits July 30, 2026 09:48

ghost left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Not ready to approve

ScheduleExt.kt currently accesses a protected Java member for departureArrivalDiff, which will not compile from the Kotlin extension as written.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Review details
  • Files reviewed: 6/6 changed files
  • Comments generated: 1
  • Review effort level: Low

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

@mmathieum
mmathieum merged commit 1ffe9f4 into master Jul 30, 2026
@mmathieum
mmathieum deleted the mm/show_hide_rt_in_schedule_screen branch July 30, 2026 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants