diff --git a/src/Data/EventTime/Local.hs b/src/Data/EventTime/Local.hs new file mode 100644 index 0000000..9ef0ee3 --- /dev/null +++ b/src/Data/EventTime/Local.hs @@ -0,0 +1,64 @@ +{- This file is part of Vervis. + - + - Written in 2016 by fr33domlover . + - + - ♡ Copying is an act of love. Please copy, reuse and share. + - + - The author(s) have dedicated all copyright and related and neighboring + - rights to this software to the public domain worldwide. This software is + - distributed without any warranty. + - + - You should have received a copy of the CC0 Public Domain Dedication along + - with this software. If not, see + - . + -} + +module Data.EventTime.Local + ( TimeUnit (..) + , TimeAgo (..) + , EventTime (..) + , showEventTime + ) +where + +import Prelude + +import Data.Text (Text, snoc) + +import qualified Formatting as F + +data TimeUnit = Second | Minute | Hour | Day | Week | Month | Year + +showSingle :: TimeUnit -> Text +showSingle tu = + case tu of + Second -> "second" + Minute -> "minute" + Hour -> "hour" + Day -> "day" + Week -> "week" + Month -> "month" + Year -> "year" + +showPlural :: TimeUnit -> Text +showPlural tu = showSingle tu `snoc` 's' + +showTimeUnit :: TimeUnit -> Int -> Text +showTimeUnit tu 1 = showSingle tu +showTimeUnit tu _ = showPlural tu + +data TimeAgo = TimeAgo + { taUnit :: TimeUnit + , taCount :: Int + } + +showTimeAgo :: TimeAgo -> Text +showTimeAgo (TimeAgo u n) = + F.sformat (F.int F.% " " F.% F.stext F.% " ago") n (showTimeUnit u n) + +data EventTime = Now | Ago TimeAgo | Never + +showEventTime :: EventTime -> Text +showEventTime Now = "Now" +showEventTime (Ago ta) = showTimeAgo ta +showEventTime Never = "Never" diff --git a/vervis.cabal b/vervis.cabal index 98a8c41..fb4fafc 100644 --- a/vervis.cabal +++ b/vervis.cabal @@ -38,6 +38,7 @@ library Data.ByteString.Char8.Local Data.ByteString.Local Data.Char.Local + Data.EventTime.Local Data.Git.Local Data.List.Local Network.SSH.Local