formatcoords icon indicating copy to clipboard operation
formatcoords copied to clipboard

rounding off to the nearest seconds doesn't push you up to the next minute

Open alex028502 opened this issue 8 years ago • 0 comments

This is demonstrated in the tests in this branch https://github.com/alex028502/formatcoords/tree/roundoff-issue

briefly this is the problem:

const coord = formatcoords(1 + 59.9 / 60 / 60, 0);
expect(coord.format({decimalPlaces: 0})).to.equal('1° 1′ 00″ N 0° 0′ 0″ E');
// -1° 0′ 60″ N 0° 0′ 0″ W
// +1° 1′ 00″ N 0° 0′ 0″ E

This is a little harder to deal with since this library rounds off (when moment js seems to truncate).

If you like I can try to fix it and send a pull request... either by switching the library to truncate instead of rounding off or by making the minutes and degrees turn over as needed. The second is a little more complicated, but doable as long as everybody is ok with this:

const coord = formatcoords(1 + 59.9 / 60 / 60, 0);
expect(coord.format('D-M', {decimalPlaces: 0})).to.equal('1-1');
expect(coord.format('D-M')).to.equal('1-0')

alex028502 avatar Dec 01 '17 12:12 alex028502