Skip to content

Commit

Permalink
Switch from String to Int for degree, #249.
Browse files Browse the repository at this point in the history
  • Loading branch information
philderbeast committed Mar 16, 2019
1 parent 2b4a725 commit b2ce6fa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
4 changes: 2 additions & 2 deletions igc/library/Flight/Igc/Parse.hs
Expand Up @@ -48,7 +48,7 @@ timeHHMMSS = do
-- 33° 21.354' S
lat :: ParsecT Void String Identity Lat
lat = do
degs <- Degree <$> count 2 digitChar
degs <- Degree . read <$> count 2 digitChar
mins <- Minute <$> count 5 digitChar
f <- const LatN <$> char 'N' <|> const LatS <$> char 'S'
return $ f degs mins
Expand All @@ -58,7 +58,7 @@ lat = do
-- 147° 56.057' E
lng :: ParsecT Void String Identity Lng
lng = do
degs <- Degree <$> count 3 digitChar
degs <- Degree . read <$> count 3 digitChar
mins <- Minute <$> count 5 digitChar
f <- const LngW <$> char 'W' <|> const LngE <$> char 'E'
return $ f degs mins
Expand Down
27 changes: 15 additions & 12 deletions igc/library/Flight/Igc/Record.hs
Expand Up @@ -45,7 +45,7 @@ newtype Second = Second Int
deriving (Eq, Ord)

-- | A whole degree of angle. May have leading zeros. Has no decimal part.
newtype Degree = Degree String
newtype Degree = Degree Int
deriving (Eq, Ord)

-- | A time with hours, minutes and seconds.
Expand Down Expand Up @@ -240,28 +240,31 @@ addHoursIgc :: Hour -> IgcRecord -> IgcRecord
addHoursIgc h x@B{hms} = x{hms = addHoursHms h hms}
addHoursIgc _ x = x

showDegree :: String -> String
showDegree d = d ++ "°"
showDegreeOfLat :: Degree -> String
showDegreeOfLat (Degree d) = printf "%02d°" d

showDegreeOfLng :: Degree -> String
showDegreeOfLng (Degree d) = printf "%03d°" d

showMinute :: String -> String
showMinute (m0 : m1 : m) = [m0, m1] ++ "." ++ m ++ "'"
showMinute m = m
showMinute m = m

showHMS :: HMS -> String
showHMS (HMS (Hour hh) (Minute mm) (Second ss)) =
printf "%02d:%02d:%02d" hh (read mm :: Int) ss

showLat :: Lat -> String
showLat (LatN (Degree d) (Minute m)) =
showDegree d ++ " " ++ showMinute m ++ " N"
showLat (LatS (Degree d) (Minute m)) =
showDegree d ++ " " ++ showMinute m ++ " S"
showLat (LatN d (Minute m)) =
showDegreeOfLat d ++ " " ++ showMinute m ++ " N"
showLat (LatS d (Minute m)) =
showDegreeOfLat d ++ " " ++ showMinute m ++ " S"

showLng :: Lng -> String
showLng (LngW (Degree d) (Minute m)) =
showDegree d ++ " " ++ showMinute m ++ " W"
showLng (LngE (Degree d) (Minute m)) =
showDegree d ++ " " ++ showMinute m ++ " E"
showLng (LngW d (Minute m)) =
showDegreeOfLng d ++ " " ++ showMinute m ++ " W"
showLng (LngE d (Minute m)) =
showDegreeOfLng d ++ " " ++ showMinute m ++ " E"

ltrimZero :: String -> String
ltrimZero ('-' : s) =
Expand Down

0 comments on commit b2ce6fa

Please sign in to comment.