fix(termidentifier): rational not working use derived day instances instead
This commit is contained in:
parent
621444829e
commit
ecdb22aa61
@ -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
|
||||
|
||||
Reference in New Issue
Block a user