Skip to content

Fractional seconds dropped in DDMMSS.ss, and DDDMM.mm longitudes of 100° or more misread #12

Open

Description

@trackoor

Two issues occur with the packed formats documented in the README (400722.8N740722.8W, 402505.994N743828.008W, and 4025.0999N7438.4668W):

const Coordinates = require('coordinate-parser');

for (const s of ['400722.8N740722.8W', '402505.994N743828.008W', '3723.2475N 12158.3416W']) {
  const p = new Coordinates(s);
  console.log(s, p.getLatitude(), p.getLongitude());
}

Command: node repro.js

Actual:

400722.8N740722.8W 40.12277777777778 -74.12277777777777
402505.994N743828.008W 40.418055555555554 -74.64111111111112
3723.2475N 12158.3416W 37.387458333333335 -1.3661111111111113

Expected:

400722.8N740722.8W 40.123 -74.123
402505.994N743828.008W 40.41833166666667 -74.64111333333334
3723.2475N 12158.3416W 37.387458333333335 -121.97236
  1. In CoordinateNumber.degreesAsDegreesMinutesAndSeconds, this.seconds is computed with Math.floor, truncating fractional seconds in DDMMSS.xxxx inputs (so 22.8" becomes 22").
  2. degreesCanBeDegreesMinutesAndSeconds checks this.degrees > 9090, which matches any DDDMM.xxxx longitude of 90°50.0001' or more (such as 12158.3416W) and parses it as DDMMSS instead of DDDMM.xxxx (similar to the > 909090 threshold in DMS formats not all supported #9).

Tested with coordinate-parser 1.0.7 (npm) and master (69b6c32) on Node.js v26.13.0.

Credit: https://ucsbplse.github.io/

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions