diff options
| author | Tom Smeding <tom@tomsmeding.com> | 2026-04-03 22:10:56 +0200 |
|---|---|---|
| committer | Tom Smeding <tom@tomsmeding.com> | 2026-04-03 22:10:56 +0200 |
| commit | acd9c66c663ea6b0b2fb9dd0a563897c2fae45eb (patch) | |
| tree | 03e24cb4475367e55cc613f6b0080de7cf618063 /src/Util.hs | |
| parent | 40d29ea3eef3f7fa15ab629b5f6694dab66d9b68 (diff) | |
Calendar view
Diffstat (limited to 'src/Util.hs')
| -rw-r--r-- | src/Util.hs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/Util.hs b/src/Util.hs index 1e10eec..95cc4ce 100644 --- a/src/Util.hs +++ b/src/Util.hs @@ -2,6 +2,8 @@ module Util (module Util, toList) where import Data.Foldable (toList) +import Data.Maybe (fromMaybe) +import Data.Time (Day, toGregorian) import Data.Word (Word8) @@ -32,3 +34,21 @@ pad c w val = uncurry3 :: (a -> b -> c -> d) -> (a, b, c) -> d uncurry3 f (x, y, z) = f x y z + +dropWhileEnd :: (a -> Bool) -> [a] -> [a] +dropWhileEnd p = fromMaybe [] . go + where + go [] = Nothing + go (x:xs) = + case go xs of + Nothing | p x -> Nothing + | otherwise -> Just [x] + Just xs' -> Just (x : xs') + +ymdToString :: YMD -> String +ymdToString (YMD y m d) = pad '0' 4 y ++ '-' : pad '0' 2 m ++ '-' : pad '0' 2 d + +dayToYMD :: Day -> YMD +dayToYMD day = + let (y, m, d) = toGregorian day + in YMD (fromIntegral y) (fromIntegral m) (fromIntegral d) |
