module Data.Time.Calendar.Private where import Data.Fixed data PadOption = Pad Int Char | NoPad showPadded :: PadOption -> String -> String showPadded :: PadOption -> String -> String showPadded NoPad s :: String s = String s showPadded (Pad i :: Int i c :: Char c) s :: String s = Int -> Char -> String forall a. Int -> a -> [a] replicate (Int i Int -> Int -> Int forall a. Num a => a -> a -> a - String -> Int forall (t :: * -> *) a. Foldable t => t a -> Int length String s) Char c String -> String -> String forall a. [a] -> [a] -> [a] ++ String s class (Num t,Ord t,Show t) => ShowPadded t where showPaddedNum :: PadOption -> t -> String instance ShowPadded Integer where showPaddedNum :: PadOption -> Integer -> String showPaddedNum NoPad i :: Integer i = Integer -> String forall a. Show a => a -> String show Integer i showPaddedNum pad :: PadOption pad i :: Integer i | Integer i Integer -> Integer -> Bool forall a. Ord a => a -> a -> Bool < 0 = '-'Char -> String -> String forall a. a -> [a] -> [a] :(PadOption -> Integer -> String forall t. ShowPadded t => PadOption -> t -> String showPaddedNum PadOption pad (Integer -> Integer forall a. Num a => a -> a negate Integer i)) showPaddedNum pad :: PadOption pad i :: Integer i = PadOption -> String -> String showPadded PadOption pad (String -> String) -> String -> String forall a b. (a -> b) -> a -> b $ Integer -> String forall a. Show a => a -> String show Integer i instance ShowPadded Int where showPaddedNum :: PadOption -> Int -> String showPaddedNum NoPad i :: Int i = Int -> String forall a. Show a => a -> String show Int i showPaddedNum _pad :: PadOption _pad i :: Int i | Int i Int -> Int -> Bool forall a. Eq a => a -> a -> Bool == Int forall a. Bounded a => a minBound = Int -> String forall a. Show a => a -> String show Int i showPaddedNum pad :: PadOption pad i :: Int i | Int i Int -> Int -> Bool forall a. Ord a => a -> a -> Bool < 0 = '-'Char -> String -> String forall a. a -> [a] -> [a] :(PadOption -> Int -> String forall t. ShowPadded t => PadOption -> t -> String showPaddedNum PadOption pad (Int -> Int forall a. Num a => a -> a negate Int i)) showPaddedNum pad :: PadOption pad i :: Int i = PadOption -> String -> String showPadded PadOption pad (String -> String) -> String -> String forall a b. (a -> b) -> a -> b $ Int -> String forall a. Show a => a -> String show Int i show2Fixed :: Pico -> String show2Fixed :: Pico -> String show2Fixed x :: Pico x | Pico x Pico -> Pico -> Bool forall a. Ord a => a -> a -> Bool < 10 = '0'Char -> String -> String forall a. a -> [a] -> [a] :(Bool -> Pico -> String forall a. HasResolution a => Bool -> Fixed a -> String showFixed Bool True Pico x) show2Fixed x :: Pico x = Bool -> Pico -> String forall a. HasResolution a => Bool -> Fixed a -> String showFixed Bool True Pico x show2 :: (ShowPadded t) => t -> String show2 :: t -> String show2 = PadOption -> t -> String forall t. ShowPadded t => PadOption -> t -> String showPaddedNum (PadOption -> t -> String) -> PadOption -> t -> String forall a b. (a -> b) -> a -> b $ Int -> Char -> PadOption Pad 2 '0' show3 :: (ShowPadded t) => t -> String show3 :: t -> String show3 = PadOption -> t -> String forall t. ShowPadded t => PadOption -> t -> String showPaddedNum (PadOption -> t -> String) -> PadOption -> t -> String forall a b. (a -> b) -> a -> b $ Int -> Char -> PadOption Pad 3 '0' show4 :: (ShowPadded t) => t -> String show4 :: t -> String show4 = PadOption -> t -> String forall t. ShowPadded t => PadOption -> t -> String showPaddedNum (PadOption -> t -> String) -> PadOption -> t -> String forall a b. (a -> b) -> a -> b $ Int -> Char -> PadOption Pad 4 '0' mod100 :: (Integral i) => i -> i mod100 :: i -> i mod100 x :: i x = i -> i -> i forall a. Integral a => a -> a -> a mod i x 100 div100 :: (Integral i) => i -> i div100 :: i -> i div100 x :: i x = i -> i -> i forall a. Integral a => a -> a -> a div i x 100 clip :: (Ord t) => t -> t -> t -> t clip :: t -> t -> t -> t clip a :: t a _ x :: t x | t x t -> t -> Bool forall a. Ord a => a -> a -> Bool < t a = t a clip _ b :: t b x :: t x | t x t -> t -> Bool forall a. Ord a => a -> a -> Bool > t b = t b clip _ _ x :: t x = t x clipValid :: (Ord t) => t -> t -> t -> Maybe t clipValid :: t -> t -> t -> Maybe t clipValid a :: t a _ x :: t x | t x t -> t -> Bool forall a. Ord a => a -> a -> Bool < t a = Maybe t forall a. Maybe a Nothing clipValid _ b :: t b x :: t x | t x t -> t -> Bool forall a. Ord a => a -> a -> Bool > t b = Maybe t forall a. Maybe a Nothing clipValid _ _ x :: t x = t -> Maybe t forall a. a -> Maybe a Just t x quotBy :: (Real a,Integral b) => a -> a -> b quotBy :: a -> a -> b quotBy d :: a d n :: a n = Rational -> b forall a b. (RealFrac a, Integral b) => a -> b truncate ((a -> Rational forall a. Real a => a -> Rational toRational a n) Rational -> Rational -> Rational forall a. Fractional a => a -> a -> a / (a -> Rational forall a. Real a => a -> Rational toRational a d)) remBy :: Real a => a -> a -> a remBy :: a -> a -> a remBy d :: a d n :: a n = a n a -> a -> a forall a. Num a => a -> a -> a - (Integer -> a forall a. Num a => Integer -> a fromInteger Integer f) a -> a -> a forall a. Num a => a -> a -> a * a d where f :: Integer f = a -> a -> Integer forall a b. (Real a, Integral b) => a -> a -> b quotBy a d a n quotRemBy :: (Real a,Integral b) => a -> a -> (b,a) quotRemBy :: a -> a -> (b, a) quotRemBy d :: a d n :: a n = let f :: b f = a -> a -> b forall a b. (Real a, Integral b) => a -> a -> b quotBy a d a n in (b f,a n a -> a -> a forall a. Num a => a -> a -> a - (b -> a forall a b. (Integral a, Num b) => a -> b fromIntegral b f) a -> a -> a forall a. Num a => a -> a -> a * a d)