git-annex/Annex/MetaData/StandardFields.hs

64 lines
1.4 KiB
Haskell
Raw Normal View History

{- git-annex metadata, standard fields
-
- Copyright 2014 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU AGPL version 3 or higher.
-}
{-# LANGUAGE OverloadedStrings #-}
module Annex.MetaData.StandardFields (
tagMetaField,
yearMetaField,
monthMetaField,
dayMetaField,
isDateMetaField,
lastChangedField,
2014-03-19 23:10:35 +00:00
mkLastChangedField,
isLastChangedField
) where
import Types.MetaData
import qualified Data.Text as T
2019-01-18 18:09:35 +00:00
import Data.Monoid
import Prelude
tagMetaField :: MetaField
tagMetaField = mkMetaFieldUnchecked "tag"
yearMetaField :: MetaField
yearMetaField = mkMetaFieldUnchecked "year"
monthMetaField :: MetaField
monthMetaField = mkMetaFieldUnchecked "month"
dayMetaField :: MetaField
dayMetaField = mkMetaFieldUnchecked "day"
isDateMetaField :: MetaField -> Bool
isDateMetaField f
| f == yearMetaField = True
| f == monthMetaField = True
| f == dayMetaField = True
| otherwise = False
2014-03-19 23:10:35 +00:00
lastChangedField :: MetaField
lastChangedField = mkMetaFieldUnchecked lastchanged
mkLastChangedField :: MetaField -> MetaField
mkLastChangedField f = mkMetaFieldUnchecked (fromMetaField f <> lastchangedSuffix)
isLastChangedField :: MetaField -> Bool
2014-03-19 23:10:35 +00:00
isLastChangedField f
| f == lastChangedField = True
| otherwise = lastchanged `T.isSuffixOf` s && s /= lastchangedSuffix
where
s = fromMetaField f
lastchanged :: T.Text
2014-03-19 23:10:35 +00:00
lastchanged = "lastchanged"
lastchangedSuffix :: T.Text
2014-03-19 23:10:35 +00:00
lastchangedSuffix = "-lastchanged"