implemented month
This commit is contained in:
parent
8b88cbff75
commit
f0e0d644d2
|
@ -24,6 +24,7 @@ module Mtlstats.Format
|
|||
, left
|
||||
, right
|
||||
, centre
|
||||
, month
|
||||
) where
|
||||
|
||||
-- | Pad an 'Int' with leading zeroes to fit a certain character width
|
||||
|
@ -72,3 +73,19 @@ centre n str = let
|
|||
pLen = (n - sLen) `div` 2
|
||||
pad = replicate pLen ' '
|
||||
in take n $ pad ++ str ++ repeat ' '
|
||||
|
||||
-- | Converts a number to a three character month (e.g. @"JAN"@)
|
||||
month :: Int -> String
|
||||
month 1 = "JAN"
|
||||
month 2 = "FEB"
|
||||
month 3 = "MAR"
|
||||
month 4 = "APR"
|
||||
month 5 = "MAY"
|
||||
month 6 = "JUN"
|
||||
month 7 = "JUL"
|
||||
month 8 = "AUG"
|
||||
month 9 = "SEP"
|
||||
month 10 = "OCT"
|
||||
month 11 = "NOV"
|
||||
month 12 = "DEC"
|
||||
month _ = ""
|
||||
|
|
|
@ -31,6 +31,7 @@ spec = describe "Mtlstats.Format" $ do
|
|||
leftSpec
|
||||
rightSpec
|
||||
centreSpec
|
||||
monthSpec
|
||||
|
||||
padNumSpec :: Spec
|
||||
padNumSpec = describe "padNum" $ do
|
||||
|
@ -87,3 +88,14 @@ centreSpec = describe "centre" $ do
|
|||
context "overflow" $
|
||||
it "should truncate the text" $
|
||||
centre 2 "foo" `shouldBe` "fo"
|
||||
|
||||
monthSpec :: Spec
|
||||
monthSpec = describe "month" $ do
|
||||
|
||||
context "January" $
|
||||
it "should return \"JAN\"" $
|
||||
month 1 `shouldBe` "JAN"
|
||||
|
||||
context "invalid" $
|
||||
it "should return an empty string" $
|
||||
month 0 `shouldBe` ""
|
||||
|
|
Loading…
Reference in New Issue
Block a user