add support for approx dates
This commit is contained in:
parent
1cfb65eae9
commit
8d4ff29e56
8 changed files with 141 additions and 65 deletions
|
@ -7,9 +7,10 @@ module Info
|
|||
readArtistFilter, matchArtist, readNsfwFilter, matchNsfw, matchFilters,
|
||||
NoThumb (..), getThumb, thumbFile, pageFile,
|
||||
-- ** Reexports
|
||||
Day (..), Text)
|
||||
Date (..), Day (..), Text)
|
||||
where
|
||||
|
||||
import Date
|
||||
import Records
|
||||
|
||||
import Control.Applicative
|
||||
|
@ -27,21 +28,19 @@ import Data.Ord (comparing)
|
|||
import Data.String (IsString)
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text as Text
|
||||
import Data.Time.Calendar (Day (..), toGregorian)
|
||||
import Data.YAML (FromYAML (..), (.:), (.:?), (.!=))
|
||||
import qualified Data.YAML as YAML
|
||||
import System.FilePath ((</>), takeBaseName, takeExtension, splitExtension)
|
||||
import Text.Read (readMaybe)
|
||||
|
||||
|
||||
data Info =
|
||||
Info {
|
||||
date :: !Day,
|
||||
date :: !Date,
|
||||
-- extra sort key after date
|
||||
-- e.g. multiple things on the same day might have a,b,c in @sortEx@ to
|
||||
-- put them in the right order in the gallery
|
||||
sortEx :: !Text,
|
||||
updates :: !(Map Day Text),
|
||||
updates :: !(Map Date Text),
|
||||
title :: !Text,
|
||||
artist :: !(Maybe Artist), -- nothing = me, obv
|
||||
nsfwOnly :: !Bool,
|
||||
|
@ -105,17 +104,11 @@ instance HasField "thumb" Info (Maybe FilePath) where
|
|||
instance HasField "mine" Info Bool where getField = isNothing . #artist
|
||||
instance HasField "notMine" Info Bool where getField = isJust . #artist
|
||||
|
||||
instance HasField "dmy" Info (Integer, Int, Int) where
|
||||
getField = toGregorian . #date
|
||||
instance HasField "year" Info Integer where getField = #first . #dmy
|
||||
instance HasField "month" Info Int where getField = #second . #dmy
|
||||
instance HasField "day" Info Int where getField = #third . #dmy
|
||||
|
||||
instance HasField "latestDate" Info Day where
|
||||
instance HasField "latestDate" Info Date where
|
||||
getField (Info {date, updates}) = maximum (date : Map.keys updates)
|
||||
|
||||
instance HasField "latestYear" Info Integer where
|
||||
getField = #first . toGregorian . #latestDate
|
||||
instance HasField "latestYear" Info Int where
|
||||
getField = #year . #latestDate
|
||||
|
||||
|
||||
instance HasField "updated" Info Bool where getField = not . Map.null . #updates
|
||||
|
@ -328,12 +321,6 @@ instance (FromYAML a, FromYAML b) => FromYAML (Pair a b) where
|
|||
_ -> fail "expected exactly one pair"
|
||||
|
||||
|
||||
instance FromYAML Day where
|
||||
parseYAML = YAML.withStr "date" \str ->
|
||||
case readMaybe $ Text.unpack str of
|
||||
Just d -> pure d
|
||||
Nothing -> fail $ "couldn't parse date " ++ show str
|
||||
|
||||
instance {-# OVERLAPPING #-} FromYAML String where
|
||||
parseYAML y = Text.unpack <$> parseYAML y
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue