    -- |
    -- Module      : Data.Hourglass.Utils
    -- License     : BSD-style
    -- Maintainer  : Vincent Hanquez <vincent@snarc.org>
    -- Stability   : experimental
    -- Portability : unknown
    --
    -- some padding / formatting functions
    --
    module Data.Hourglass.Utils where

    -- | pad a number to 2 digits
    pad2 :: (Show a, Ord a, Num a, Integral a) => a -> String
    pad2 :: a -> String
    pad2 v :: a
    v | a
    v a -> a -> Bool
    forall a. Ord a => a -> a -> Bool
    >= 100   = a -> String
    forall a. (Show a, Ord a, Num a, Integral a) => a -> String
    pad2 (a
    v a -> a -> a
    forall a. Integral a => a -> a -> a
    `mod` 100)
           | a
    v a -> a -> Bool
    forall a. Ord a => a -> a -> Bool
    >= 10    = a -> String
    forall a. Show a => a -> String
    show a
    v
           | Bool
    otherwise  = '0' Char -> String -> String
    forall a. a -> [a] -> [a]
    : a -> String
    forall a. Show a => a -> String
    show a
    v

    -- | pad a number to 4 digits
    pad4 :: (Show a, Ord a, Num a, Integral a) => a -> String
    pad4 :: a -> String
    pad4 v :: a
    v | a
    v a -> a -> Bool
    forall a. Ord a => a -> a -> Bool
    >= 1000  = a -> String
    forall a. Show a => a -> String
    show a
    v
           | a
    v a -> a -> Bool
    forall a. Ord a => a -> a -> Bool
    >= 100   = '0' Char -> String -> String
    forall a. a -> [a] -> [a]
    : a -> String
    forall a. Show a => a -> String
    show a
    v
           | a
    v a -> a -> Bool
    forall a. Ord a => a -> a -> Bool
    >= 10    = '0'Char -> String -> String
    forall a. a -> [a] -> [a]
    :'0' Char -> String -> String
    forall a. a -> [a] -> [a]
    : a -> String
    forall a. Show a => a -> String
    show a
    v
           | Bool
    otherwise  = '0'Char -> String -> String
    forall a. a -> [a] -> [a]
    :'0'Char -> String -> String
    forall a. a -> [a] -> [a]
    :'0'Char -> String -> String
    forall a. a -> [a] -> [a]
    : a -> String
    forall a. Show a => a -> String
    show a
    v

    -- | Pad a number to at least N digits.
    --
    -- if the number is greater, no truncation happens.
    padN :: (Show a, Ord a, Num a, Integral a) => Int -> a -> String
    padN :: Int -> a -> String
    padN n :: Int
    n v :: a
    v
        | Int
    vlen Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    >= Int
    n = String
    vs
        | Bool
    otherwise = Int -> Char -> String
    forall a. Int -> a -> [a]
    replicate (Int
    n Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    vlen) '0' String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ String
    vs
      where vs :: String
    vs = a -> String
    forall a. Show a => a -> String
    show a
    v
            vlen :: Int
    vlen = String -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    length String
    vs