module System.Cron.Internal.Describe.Time where

import System.Cron.Internal.Describe.Types

newtype Minute = Minute Int
newtype Hour   = Hour Int

format :: TimeFormat -> Minute -> Hour -> String
format :: TimeFormat -> Minute -> Hour -> String
format TimeFormat
t (Minute Int
m) (Hour Int
h) = Int -> String
forall {a}. (Ord a, Num a, Show a) => a -> String
leftPad (TimeFormat -> Int
hour TimeFormat
t) String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
":" String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> String
forall {a}. (Ord a, Num a, Show a) => a -> String
leftPad Int
m String -> String -> String
forall a. [a] -> [a] -> [a]
++ TimeFormat -> String
suffix TimeFormat
t
  where leftPad :: a -> String
leftPad a
n
          | a
n a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
10    = String
"0" String -> String -> String
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show a
n
          | Bool
otherwise = a -> String
forall a. Show a => a -> String
show a
n
        suffix :: TimeFormat -> String
suffix TimeFormat
Hour24 = String
""
        suffix TimeFormat
Hour12
          | Int
h Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
12    = String
" AM"
          | Bool
otherwise = String
" PM"
        hour :: TimeFormat -> Int
hour TimeFormat
Hour24 = Int
h
        hour TimeFormat
Hour12
          | Int
h Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
12 = Int
h Int -> Int -> Int
forall a. Integral a => a -> a -> a
`mod` Int
12
          | Bool
otherwise = Int
h