Move init multipliers into constants so we can reuse them

This commit is contained in:
Winni Neessen 2023-06-23 16:42:06 +02:00
parent 5dee24573a
commit a697b13970
Signed by: wneessen
GPG key ID: 5F3AF39B820C119D

View file

@ -10,6 +10,15 @@ import (
"time"
)
const (
// MultiplierKnots is the multiplier for converting the base unit to knots
MultiplierKnots = 1.9438444924
// MultiplierKPH is the multiplier for converting the base unit to kilometers per hour
MultiplierKPH = 3.6
// MultiplierMPH is the multiplier for converting the base unit to miles per hour
MultiplierMPH = 2.236936
)
// Speed is a type wrapper of an WeatherData for holding speed
// values in WeatherData
type Speed WeatherData
@ -50,7 +59,7 @@ func (s Speed) Source() Source {
// KMH returns the Speed value in km/h
func (s Speed) KMH() float64 {
return s.fv * 3.6
return s.fv * MultiplierKPH
}
// KMHString returns the Speed value as formatted string in km/h
@ -60,7 +69,7 @@ func (s Speed) KMHString() string {
// Knots returns the Speed value in kn
func (s Speed) Knots() float64 {
return s.fv * 1.9438444924
return s.fv * MultiplierKnots
}
// KnotsString returns the Speed value as formatted string in kn
@ -70,7 +79,7 @@ func (s Speed) KnotsString() string {
// MPH returns the Speed value in mi/h
func (s Speed) MPH() float64 {
return s.fv * 2.236936
return s.fv * MultiplierMPH
}
// MPHString returns the Speed value as formatted string in mi/h