Term2days #186

Merged
savau merged 9 commits from term2days into master 2021-10-28 13:13:42 +02:00
Showing only changes of commit ecdb22aa61 - Show all commits

View File

@ -29,7 +29,7 @@ import Data.Aeson.Types as Aeson
newtype TermIdentifier = TermIdentifier { getTermDay :: Day }
deriving (Show, Read, Eq, Ord, Generic, Typeable, Enum)
deriving newtype (Binary, ISO8601)
deriving newtype (Binary, ISO8601, PersistField, PersistFieldSql)
deriving anyclass (NFData)
-- ought to be equivalent to deriving stock (Show, Read, Eq, Ord, Generic, Typeable, Enum, Binary, NFData)
@ -102,6 +102,7 @@ termToRational = (dayOffset +) . (/ daysPerYear) . fromIntegral . fromEnum
termFromRational :: Rational -> TermIdentifier
termFromRational = toEnum . round . (daysPerYear *) . subtract dayOffset
{- -- For newtype Day, PersistField instance can be derived automatically
instance PersistField TermIdentifier where
toPersistValue = PersistRational . termToRational
fromPersistValue (PersistRational t) = Right $ termFromRational t
@ -109,6 +110,7 @@ instance PersistField TermIdentifier where
instance PersistFieldSql TermIdentifier where
sqlType _ = SqlNumeric 9 5 -- total significant digits; significant digits after decimal point
-}
instance ToHttpApiData TermIdentifier where
toUrlPiece = termToText