Skip to content

Commit

Permalink
Check ticks and times for 4 tracklogs, show Second as HH:MM:SS, #249.
Browse files Browse the repository at this point in the history
  • Loading branch information
philderbeast committed Mar 16, 2019
1 parent e0f5a12 commit 42d8a3c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
24 changes: 24 additions & 0 deletions igc/library/Flight/Igc/Fix.hs
Expand Up @@ -101,12 +101,36 @@ stamp (Year yy, Month mm, Day dd) (HMS (Hour hr) (MinuteOfTime minute) (Second s
-- |
-- >>> let xs = markTimes markGordon fixesGordon in xs == sort xs
-- True
--
-- >>> let xs = markTimes markSasha fixesSasha in (head xs, head $ reverse xs)
-- (2018-01-03 03:13:00 UTC,2018-01-03 06:57:50 UTC)
--
-- >>> let xs = markTimes markBrad fixesBrad in (head xs, head $ reverse xs)
-- (2018-01-03 04:05:47 UTC,2018-01-03 06:13:55 UTC)
--
-- >>> let xs = markTimes markScott fixesScott in (head xs, head $ reverse xs)
-- (2017-04-08 02:37:56 UTC,2017-04-08 06:49:57 UTC)
--
-- >>> let xs = markTimes markGordon fixesGordon in (head xs, head $ reverse xs)
-- (2018-01-02 00:44:29 UTC,2018-01-02 09:07:43 UTC)
markTimes :: IgcRecord -> [IgcRecord] -> [UTCTime]
markTimes = mark unStampTime

-- |
-- >>> let xs = markTicks markGordon fixesGordon in xs == sort xs
-- True
--
-- >>> let xs = markTicks markSasha fixesSasha in (head xs, head $ reverse xs)
-- (00:00:00,03:44:50)
--
-- >>> let xs = markTicks markBrad fixesBrad in (head xs, head $ reverse xs)
-- (00:00:00,02:08:08)
--
-- >>> let xs = markTicks markScott fixesScott in (head xs, head $ reverse xs)
-- (00:00:00,04:12:01)
--
-- >>> let xs = markTicks markGordon fixesGordon in (head xs, head $ reverse xs)
-- (00:00:00,08:23:14)
markTicks :: IgcRecord -> [IgcRecord] -> [Second]
markTicks = mark unStampTick

Expand Down
14 changes: 13 additions & 1 deletion igc/library/Flight/Igc/Record.hs
Expand Up @@ -22,7 +22,7 @@ module Flight.Igc.Record
, isFix
) where

import Prelude hiding (readFile)
import Prelude hiding (readFile, min)
import Text.Printf (printf)
import Data.List (partition)
import Test.Tasty.QuickCheck (Arbitrary(..), frequency, oneof)
Expand All @@ -47,6 +47,18 @@ newtype MinuteOfAngle = MinuteOfAngle {unThousandths :: Int}
newtype Second = Second Int
deriving (Eq, Ord)

instance Show Second where
show (Second s) = showHmsForSecs s

showHmsForSecs :: Int -> String
showHmsForSecs sec =
show2i hr' ++ ":" ++ show2i min' ++ ":" ++ show2i sec'
where
show2i = printf "%02d"
(hr', min) = sec `divMod` 3600
(min', sec') = min `divMod` 60


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

0 comments on commit 42d8a3c

Please sign in to comment.