aboutsummaryrefslogtreecommitdiff
path: root/modern/src/common/converter.js
diff options
context:
space:
mode:
Diffstat (limited to 'modern/src/common/converter.js')
-rw-r--r--modern/src/common/converter.js38
1 files changed, 32 insertions, 6 deletions
diff --git a/modern/src/common/converter.js b/modern/src/common/converter.js
index e48b0760..9cdc6239 100644
--- a/modern/src/common/converter.js
+++ b/modern/src/common/converter.js
@@ -1,13 +1,39 @@
-export const speedConverter = (value, unit) => {
- let factor;
+const speedConverter = unit => {
switch (unit) {
case 'kmh':
- factor = 1.852;
+ return 1.852;
case 'mph':
- factor = 1.15078;
+ return 1.15078;
case 'kn':
default:
- factor = 1;
+ return 1;
}
- return (value * factor).toFixed(2);
};
+
+const distanceConverter = unit => {
+ switch (unit) {
+ case 'mi':
+ return 0.000621371;
+ case 'nmi':
+ return 0.000539957;
+ case 'km':
+ default:
+ return 0.001;
+ }
+}
+
+export const speedFromKnots = (value, unit) => {
+ return value * speedConverter(unit);
+}
+
+export const speedToKnots = (value, unit) => {
+ return value / speedConverter(unit);
+}
+
+export const distanceFromMeters = (value, unit) => {
+ return value * distanceConverter(unit);
+}
+
+export const distanceToMeters = (value, unit) => {
+ return value / distanceConverter(unit);
+}