diff options
author | Marcin Zelent <marcin@zelent.net> | 2022-11-16 15:16:38 +0100 |
---|---|---|
committer | Marcin Zelent <marcin@zelent.net> | 2022-11-16 15:16:38 +0100 |
commit | f2ecc1803f3ea294a0c6b7915b61348ed0395b26 (patch) | |
tree | e8c6fb1350ae4f659b3f9ef8d17157158b974b16 /lib/util.ts | |
parent | efb64f24d6200a39870c0e8966ab4f87e07c93a9 (diff) |
Remade and extended the app using React
Diffstat (limited to 'lib/util.ts')
-rw-r--r-- | lib/util.ts | 30 |
1 files changed, 0 insertions, 30 deletions
diff --git a/lib/util.ts b/lib/util.ts deleted file mode 100644 index 5a00aed..0000000 --- a/lib/util.ts +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Converts time in seconds to HH:mm format. - * @param time Time to convert in seconds. - */ -export function secondsToTimeString(time: number): string { - const h = Math.floor(time / 3600); - const m = Math.floor((time % 3600) / 60); - - return `${h < 10 ? `0${h}` : h}:${m < 10 ? `0${m}` : m}`; -} - -/** - * Calculates distance between two geographical points. - * @param latlng1 Coordinates of the first point. - * @param latlng2 Coordinates of the second point. - */ -export function distanceBetween(latlng1: number[], latlng2: number[]): number { - const R = 6371000; - const rad = Math.PI / 180; - const lat1 = latlng1[0] * rad; - const lat2 = latlng2[0] * rad; - const sinDLat = Math.sin(((latlng2[0] - latlng1[0]) * rad) / 2); - const sinDLon = Math.sin(((latlng2[1] - latlng1[1]) * rad) / 2); - const a = sinDLat * sinDLat + Math.cos(lat1) * Math.cos(lat2) * sinDLon * sinDLon; - const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); - - return R * c; -} - -export default { secondsToTimeString, distanceBetween }; |