While writing an app with lots of DateTime manipulations, I noticed that adjust is very annoying to use, because of the Maybe return type. I don't think this is a very practical design, similarly to how (+) :: Int -> Int -> Maybe Int wouldn't be. There is often not much you can do on failure, other than just skip the operation. Needless to say, that doesn't help with correctness.
I think that saturating semantics would make more sense. Something like this:
-- | Like `adjust`, but saturates on out-of-bounds results.
shift :: forall d. Duration d => d -> DateTime -> DateTime
shift d dt = case adjust d dt of
Nothing -> if fromDuration d > mempty then top else bottom
Just d' -> d'
Does this sound like a good idea? I can make it into a PR, but wanted to get some feedback first.
While writing an app with lots of
DateTimemanipulations, I noticed thatadjustis very annoying to use, because of theMaybereturn type. I don't think this is a very practical design, similarly to how(+) :: Int -> Int -> Maybe Intwouldn't be. There is often not much you can do on failure, other than just skip the operation. Needless to say, that doesn't help with correctness.I think that saturating semantics would make more sense. Something like this:
Does this sound like a good idea? I can make it into a PR, but wanted to get some feedback first.