From f21dcde54b09913550036e6501cca935278597d9 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Sun, 29 Mar 2026 23:25:10 +0200 Subject: Initial --- src/Util.hs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/Util.hs (limited to 'src/Util.hs') diff --git a/src/Util.hs b/src/Util.hs new file mode 100644 index 0000000..ca31258 --- /dev/null +++ b/src/Util.hs @@ -0,0 +1,31 @@ +{-# LANGUAGE DeriveFoldable #-} +module Util (module Util, toList) where + +import Data.Foldable (toList) +import Data.Word (Word8) + + +data Snoc a = SnocNil | Snoc (Snoc a) a + deriving (Show, Foldable) + +-- | Time-of-day, in unspecified time zone +data YMDHMS = YMDHMS {-# UNPACK #-} !YMD + {-# UNPACK #-} !HMS + deriving (Show) + +-- | Calendar day +data YMD = YMD {-# UNPACK #-} !Int + {-# UNPACK #-} !Word8 -- ^ 1-based + {-# UNPACK #-} !Word8 + deriving (Show) + +-- | Time-of-day in seconds, in unspecified time zone +data HMS = HMS {-# UNPACK #-} !Word8 + {-# UNPACK #-} !Word8 + {-# UNPACK #-} !Word8 + deriving (Show) + +pad :: Show a => Char -> Int -> a -> String +pad c w val = + let s = show val + in replicate (w - length s) c ++ s -- cgit v1.3