Closed folsen closed 6 years ago
Wouldn't it be simpler to pattern match on the IntDate
? That way you can use
currentTime <- getPOSIXTime
let IntDate iat' = iat
if abs (iat' - currentTime) < 30
...
It's a matter of preference I suppose, I just thought it made sense that IntDate would have a Num
instance since it's a newtype over a Num
type.
If I remember, the only reason for adding that type was to avoid an orphan instance for ToJSON and FromJSON for POSIXTime. I don't really like it much and it's something I'd like to be able to change easily in future with minimal impact, so I'd prefer to avoid encouraging its use much beyond encoding and decoding. Pattern-matching as above seems more or less as straightforward as your original code.
Since
IntDate
is a newtype ofPOSIXTime
andPOSIXTime
has theNum
class, I think you should deriveNum
forIntDate
as well.My use case is I want to be able to compare times like this (
iat
is within 30 seconds of now):but since there's no
Num
forIntDate
, I have to do this: