新增減去和比較天數

給定 Day,我們可以執行簡單的算術和比較,例如新增:

import Data.Time

addDays 1 (fromGregorian 2000 1 1)
-- 2000-01-02
addDays 1 (fromGregorian 2000 12 31)
-- 2001-01-01

減去:

addDays (-1) (fromGregorian 2000 1 1)
-- 1999-12-31

addDays (-1) (fromGregorian 0 1 1)
-- -0001-12-31
-- wat

甚至找到差異:

diffDays (fromGregorian 2000 12 31) (fromGregorian 2000 1 1)
365

請注意,訂單很重要:

diffDays (fromGregorian 2000 1 1) (fromGregorian 2000 12 31)
-365