Skip to content

Commit

Permalink
bug fix #348
Browse files Browse the repository at this point in the history
  • Loading branch information
karussell committed Jul 17, 2023
1 parent d6155e8 commit 349bcd8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/Converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { GeocodingHit } from '@/api/graphhopper'

import { Coordinate } from '@/stores/QueryStore'

export function milliSecondsToText(seconds: number) {
const hours = Math.floor(seconds / 3600000)
const minutes = Math.floor((seconds % 3600000) / 60000)
export function milliSecondsToText(ms: number) {
const hours = Math.floor(ms / 3600000)
const minutes = Math.round((ms % 3600000) / 60000)

const hourText = hours > 0 ? hours + ' h' : ''
if (minutes == 0 && hourText.length > 0) return hourText
return hourText + ' ' + minutes + ' min'
return (hourText ? hourText + ' ' : '') + minutes + ' min'
}

const distanceFormat = new Intl.NumberFormat(navigator.language, { maximumFractionDigits: 1 })
Expand Down
11 changes: 9 additions & 2 deletions test/Converters.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { textToCoordinate, nominatimHitToItem, hitToItem } from '@/Converters'
import { GeocodingHit } from '@/api/graphhopper'
import { textToCoordinate, nominatimHitToItem, hitToItem, milliSecondsToText } from '@/Converters'

describe('Converters', function () {
describe('milliSecondsToText', function () {
it('should convert ms to text', function () {
expect(milliSecondsToText(59 * 1000)).toEqual('1 min')

expect(milliSecondsToText(63 * 60 * 1000)).toEqual('1 h 3 min')
})
})

describe('textToCoordinate', function () {
it('should convert 2 digits separated by ","', function () {
expect(textToCoordinate('1.2345, 2.6534')).toEqual({ lat: 1.2345, lng: 2.6534 })
Expand Down

0 comments on commit 349bcd8

Please sign in to comment.