redo formatDate so i can have 12th

This commit is contained in:
Rhiannon Morris 2020-08-01 02:27:24 +02:00
parent fc2185e622
commit 653adfe5fc

View file

@ -10,7 +10,7 @@ import Control.Monad
import Data.Maybe (fromMaybe) import Data.Maybe (fromMaybe)
import qualified Data.Text as Strict import qualified Data.Text as Strict
import qualified Data.Text.Lazy as Lazy import qualified Data.Text.Lazy as Lazy
import Data.Time (formatTime, defaultTimeLocale) import qualified Data.Time.Calendar as Time
import qualified Data.Char as Char import qualified Data.Char as Char
import qualified Data.List as List import qualified Data.List as List
import System.FilePath (joinPath, splitPath) import System.FilePath (joinPath, splitPath)
@ -125,10 +125,6 @@ makeDesc nsfw desc nsfwDesc = [b|@4
desc' = fromMaybe "" desc desc' = fromMaybe "" desc
nsfwDesc' = fromMaybe "" $ guard nsfw *> nsfwDesc nsfwDesc' = fromMaybe "" $ guard nsfw *> nsfwDesc
formatDate :: Day -> Builder
formatDate d =
let str = formatTime defaultTimeLocale "%e %#B %Y" d in [b|$@str|]
makeButtonBar :: Strict.Text -> [Image] -> Builder makeButtonBar :: Strict.Text -> [Image] -> Builder
makeButtonBar title images = makeButtonBar title images =
case length images of case length images of
@ -201,3 +197,21 @@ extLink (Link {title, url}) = [b|@6
$*title $*title
</a> </a>
|] |]
formatDate :: Day -> Builder
formatDate date = [b|$*week $day $*month $^year|] where
(year, month', day') = Time.toGregorian date
week' = Time.dayOfWeek date
day = nth day'
month = Strict.words "january february march april may june july \
\august september october november december"
!! (month' - 1)
week = Strict.words "mon tue wed thu fri sat sun" !! (fromEnum week' - 1)
nth :: Int -> Builder
nth n = [b|$^n$suf|] where
suf | n >= 10, n <= 19 = "th"
| n `mod` 10 == 1 = "st"
| n `mod` 10 == 2 = "nd"
| n `mod` 10 == 3 = "rd"
| otherwise = "th"