implemented Mtlstats.Report.date

This commit is contained in:
Jonathan Lamothe 2019-09-07 00:26:15 -04:00
parent e0dd80079d
commit 27867ba69d
3 changed files with 59 additions and 6 deletions

View File

@ -19,7 +19,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
-}
module Mtlstats.Report (report) where
module Mtlstats.Report (report, date) where
import Data.Maybe (fromMaybe)
import Lens.Micro ((^.))
@ -40,6 +40,7 @@ report width s = unlines $ fromMaybe [] $ do
db = s^.database
gs = s^.progMode.gameStateL
gNum = db^.dbGames
gDate = date gs
hTeam = homeTeam gs
aTeam = awayTeam gs
hStats = db^.dbHomeGameStats
@ -47,17 +48,13 @@ report width s = unlines $ fromMaybe [] $ do
tStats = addGameStats hStats aStats
hScore <- gs^.homeScore
aScore <- gs^.awayScore
month <- month <$> gs^.gameMonth
day <- padNum 2 <$> gs^.gameDay
year <- show <$> gs^.gameYear
let date = month ++ " " ++ day ++ " " ++ year
Just
[ overlay
("GAME NUMBER " ++ padNum 2 gNum)
(centre width
$ aTeam ++ " " ++ show aScore ++ " AT "
++ hTeam ++ " " ++ show hScore)
, date
, gDate
, centre width "STANDINGS"
, ""
, centre width
@ -81,6 +78,13 @@ report width s = unlines $ fromMaybe [] $ do
++ showStats tStats
]
date :: GameState -> String
date gs = fromMaybe "" $ do
year <- show <$> gs^.gameYear
month <- month <$> gs^.gameMonth
day <- padNum 2 <$> gs^.gameDay
Just $ month ++ " " ++ day ++ " " ++ year
showStats :: GameStats -> String
showStats gs
= right 2 (show $ gmsGames gs)

47
test/ReportSpec.hs Normal file
View File

@ -0,0 +1,47 @@
{-
mtlstats
Copyright (C) 2019 Rhéal Lamothe
<rheal.lamothe@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or (at
your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-}
module ReportSpec (spec) where
import Lens.Micro ((&), (?~), (%~))
import Test.Hspec (Spec, context, describe, it, shouldBe)
import Mtlstats.Report
import Mtlstats.Types
spec :: Spec
spec = describe "Mtlstats.Report"
dateSpec
dateSpec :: Spec
dateSpec = describe "date" $ do
context "valid date" $
it "should format the date" $ let
gs = newGameState
& gameYear ?~ 1980
& gameMonth ?~ 6
& gameDay ?~ 25
in date gs `shouldBe` "JUN 25 1980"
context "invalid date" $
it "should return an empty string" $
date newGameState `shouldBe` ""

View File

@ -24,6 +24,7 @@ import Test.Hspec (hspec)
import qualified ActionsSpec as Actions
import qualified FormatSpec as Format
import qualified HandlersSpec as Handlers
import qualified ReportSpec as Report
import qualified TypesSpec as Types
main :: IO ()
@ -32,3 +33,4 @@ main = hspec $ do
Actions.spec
Format.spec
Handlers.spec
Report.spec