-
Notifications
You must be signed in to change notification settings - Fork 23
Open
Description
Constructing some wrong Dates I have managed to reach a segmentation fault error. While I guess building correct dates is a user duty, it seems to me a bit too much to have segmentation fault for these cases.
Attached an example to reproduce.
import Chronos
import Data.Int
validDate =
Date
(Year 2025)
(Month 0) -- valid month January
(DayOfMonth 10)
validDay = dateToDay validDate
-- λ> validDay
-- Day {getDay = 60685}
brokenDate =
Date
(Year 2025)
(Month (-1)) -- clearly not a valid month
(DayOfMonth 10)
bangDay = dateToDay brokenDate
-- λ> bangDay
-- Day {getDay = Segmentation fault (core dumped)
alsoBrokenDate =
Date
(Year 2025)
(Month 13) -- also clearly not a valid month
(DayOfMonth 10)
alsoBangDay = dateToDay alsoBrokenDate
-- λ> alsoBangDay
-- Day {getDay = Segmentation fault (core dumped)
brokenButNotQuiteDate =
Date
(Year 2025)
(Month 12) -- not a valid month 0..11
(DayOfMonth 10)
notBangButShoudlBangDay = dateToDay brokenButNotQuiteDate
-- λ> notBangButShoudlBangDay
-- Day {getDay = 61040}
what = (dayToDate . dateToDay) brokenButNotQuiteDate
-- λ> what
-- Date { dateYear = Year {getYear = 2025}
-- , dateMonth = Month {getMonth = 11}
-- , dateDay = DayOfMonth {getDayOfMonth = 31}
-- }As s bonus the roundtrip for Dates on the thirteenth month just does not make sense.
Metadata
Metadata
Assignees
Labels
No labels