File tree Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ module Data.Date
7
7
, day
8
8
, weekday
9
9
, diff
10
+ , isLeapYear
10
11
, module Data.Date.Component
11
12
) where
12
13
@@ -76,6 +77,12 @@ diff :: forall d. Duration d => Date -> Date -> d
76
77
diff (Date y1 m1 d1) (Date y2 m2 d2) =
77
78
toDuration $ runFn6 calcDiff y1 (fromEnum m1) d1 y2 (fromEnum m2) d2
78
79
80
+ -- | Is this year a leap year according to the proleptic Gregorian calendar?
81
+ isLeapYear :: Year -> Boolean
82
+ isLeapYear y = (mod y' 4 == 0 ) && ((mod y' 400 == 0 ) || not (mod y' 100 == 0 ))
83
+ where
84
+ y' = fromEnum y
85
+
79
86
-- TODO: these could (and probably should) be implemented in PS
80
87
foreign import canonicalDateImpl :: Fn4 (Year -> Int -> Day -> Date ) Year Int Day Date
81
88
foreign import calcWeekday :: Fn3 Year Int Day Int
Original file line number Diff line number Diff line change @@ -98,6 +98,12 @@ main = do
98
98
log " Check that diff behaves as expected"
99
99
assert $ Date .diff d2 d1 == Duration.Days 29.0
100
100
101
+ let unsafeYear = unsafePartial fromJust <<< toEnum
102
+ log " Check that isLeapYear behaves as expected"
103
+ assert $ not $ Date .isLeapYear (unsafeYear 2017 )
104
+ assert $ Date .isLeapYear (unsafeYear 2016 )
105
+
106
+
101
107
-- datetime ----------------------------------------------------------------
102
108
103
109
let dt1 = DateTime.DateTime d1 t1
You can’t perform that action at this time.
0 commit comments