Skip to content

Fix date handling, decimal-year API, and packaging - #16

Draft
dpyeates wants to merge 3 commits into
masterfrom
cursor/wmm-review-fixes-9d2c
Draft

Fix date handling, decimal-year API, and packaging#16
dpyeates wants to merge 3 commits into
masterfrom
cursor/wmm-review-fixes-9d2c

Conversation

@dpyeates

@dpyeates dpyeates commented Aug 2, 2026

Copy link
Copy Markdown
Owner

Summary

Addresses the general review findings for magvar (WMM 2025–2030).

Bugs fixed

  • magvar() now evaluates against the current UTC time on each call (no module-load freeze)
  • gregorianToJulian uses UTC (Date.UTC) so results no longer depend on process timezone
  • Altitude docs consistently specify kilometers above MSL
  • Epoch handling is decimal-year based (yearFrac = decimalYear - 2025.0), aligned with WMM
  • Warns once when the requested time is outside 2025.0–2030.0

API / architecture

  • Optional 4th argument on magvar / magneticField: Date or decimal year
  • New calculateMagVarForDecimalYear, calculateMagneticField, magneticField
  • Full field components: declination, inclination, X/Y/Z/H/F
  • Removed unused src/WMMCOF2020.js and the julianDaysNow export
  • Moved extended regression vectors out of the coefficients module into test/

Optimizations

  • Cache secular-variation coefficients while the decimal year is unchanged
  • Restrict SV update loops to m <= n
  • Drop Float32Array scratch buffers in favor of normal JS numbers

Packaging / DX

  • Version 2.1.0
  • exports + files so the npm tarball is coefficients + runtime only (~6 KB packed)
  • Jest upgraded 26 → 29 (npm audit: 0 vulnerabilities)
  • README rewritten with clear install/quick-start, input conventions, API reference, examples, migration notes, and test/reference links

Tests

  • Primary fixture: official NOAA/NCEI WMM2025_TEST_VALUES.txt checked in under test/fixtures/
  • Exact equality checks for all 12 published main-field cases (X/Y/Z/H/F/I/D)
  • API agreement across magvar / magneticField / decimal-year helpers
  • Secular-rate consistency between 2025.0 and 2027.5 pairs
  • Longitude 240° case from the official file
  • Extended 100-vector regression set spanning 2025.0–2029.5
  • Current-date behavior, Date/decimal-year inputs, Julian legacy path, UTC timezone independence, validity warning, poles
  • 149 tests passing
Open in Web Open in Cursor 

cursoragent and others added 3 commits August 2, 2026 15:44
Recompute magvar() against the current UTC time (or an optional Date /
decimal year), make Julian conversion timezone-safe, cache secular
variation, expose full field components, warn outside 2025-2030, and
drop the unused WMM 2020 coefficients from the published package.

Co-authored-by: Darren Yeates <darren@sensorworks.co.uk>
Parse the NOAA/NCEI input test document as the primary fixture, assert
exact main-field matches for all 12 published cases, cover secular-rate
consistency and API agreement, and keep the extended vector set as
regression coverage.

Co-authored-by: Darren Yeates <darren@sensorworks.co.uk>
Expand installation/quick-start guidance, document input conventions,
field components, decimal years, helpers, migration notes, and how
tests relate to the official WMM2025 test-values file.

Co-authored-by: Darren Yeates <darren@sensorworks.co.uk>
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