Skip to content

fix: use UTC date for LST calculation - #312

Merged
ClutchplateDude merged 1 commit into
developfrom
lst-fix
Oct 13, 2026
Merged

ClutchplateDude merged 1 commit into
developfrom
lst-fix

Conversation

@intercipere

Copy link
Copy Markdown
Member

Problem

LST is off by about 4 minutes (≈1° in RA) for |UTC offset| hours every day, whenever the local date and the UTC date differ:

  • East of UTC (e.g. Europe), from local midnight until UTC midnight: LST is about +3m50s too high (e.g. 00:00–02:00 in Central European Summer Time).
  • West of UTC (the Americas), every evening once the UTC date has rolled over: LST is about −4m03s too low (e.g. after 19:00/20:00 on the US East Coast, after 16:00/17:00 on the West Coast).
  • Never at UTC+0.

LST and _zeroPosRA are only computed when time/date/offset/longitude are set (i.e. on connect), on :SHP and on park. So a connect, park or set-home inside that window leaves the mount ~1° off in RA until the next one. Plate-solve centering usually hides it.

Cause

Mount::calculateLst() passes the local date (getLocalDate()) together with the UTC time (getUtcTime()) to Sidereal::calculateByDateAndTime(). When the two dates differ, the formula's day count is off by one, which is one day of sidereal drift (0.985647°/day ≈ 3m56.6s).

Fix

New pure helper core::localToUtcDate(localDate, localSecondsOfDay, utcOffsetHours) in core/CalendarMath. It works out the day shift (−1/0/+1) from the local time of day minus the UTC offset and applies it with the existing core::addDays(). calculateLst() now passes that UTC date. The GPS path (calculateByGPS) already uses the UTC date and is unchanged.

Testing

  • 9 new unit tests in unit_tests/test_core/test_calendar.cpp: east/west of UTC inside and outside the window, UTC+0, exactly at UTC midnight, both year boundaries, and a leap day.

  • Bench, ESP32 (OAE V1), site and time set the way ASCOM/OATControl set them (:Sg/:SG/:SC/:SL), :XGL# compared with IAU GMST at longitude 0:

    Local time Before (V1.13.18) After
    UTC+2, 2026-10-14 01:30 +229 s −7 s
    UTC+2, 2026-10-14 03:30 (control) −7 s −7 s
    UTC−5, 2026-10-13 20:00 −244 s −7 s
    UTC−5, 2026-10-13 18:00 (control) −7 s −7 s
    UTC+10, 2027-01-01 05:00 +230 s −7 s

    The remaining −7 s is a constant offset of the existing sidereal formula and not part of this change.

  • Builds for oaeboardv1 and ramps.

🤖 Generated with Claude Code

@ClutchplateDude
ClutchplateDude merged commit 034b190 into develop Oct 13, 2026
8 checks passed
@ClutchplateDude
ClutchplateDude deleted the lst-fix branch October 13, 2026 22:13
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