From 653adfe5fca5a001a6002917ec8f55bfe12ba921 Mon Sep 17 00:00:00 2001 From: Rhiannon Morris Date: Sat, 1 Aug 2020 02:27:24 +0200 Subject: [PATCH] redo formatDate so i can have 12th --- make-pages/SinglePage.hs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/make-pages/SinglePage.hs b/make-pages/SinglePage.hs index 923215b..3648c00 100644 --- a/make-pages/SinglePage.hs +++ b/make-pages/SinglePage.hs @@ -10,7 +10,7 @@ import Control.Monad import Data.Maybe (fromMaybe) import qualified Data.Text as Strict 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.List as List import System.FilePath (joinPath, splitPath) @@ -125,10 +125,6 @@ makeDesc nsfw desc nsfwDesc = [b|@4 desc' = fromMaybe "" desc 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 title images = case length images of @@ -201,3 +197,21 @@ extLink (Link {title, url}) = [b|@6 $*title |] + +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"