Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

more date functions

  • Loading branch information...
commit 6b38dfc77587f8bc0e0660d7823fbe6f62188b79 1 parent 8712697
Eric Wilson authored
Showing with 19 additions and 2 deletions.
  1. +19 −2 019.hs
21 019.hs
View
@@ -29,8 +29,25 @@ daysInMonth date
m = month date
y = year date
-dayShiftFromYearChange :: Year -> Year -> Int
-dayShiftFromYearChange start end = mod7 (sum $ map daysInYear [start..end-1])
+epoch :: Date
+epoch = Date 1900 1 1
+
+daysInPreviousYearsSinceEpoch :: Year -> Int
+daysInPreviousYearsSinceEpoch currentYear = sum $ map daysInYear [year epoch..currentYear-1]
+
+daysInPreviousMonthsInCurrentYear :: Date -> Int
+daysInPreviousMonthsInCurrentYear date = sum $ map daysInMonth (previousMonths date)
+
+previousMonths :: Date -> [Date]
+previousMonths date = [ Date (year date) m 1 | m <- [1..(month date)-1]]
+
+daysSinceEpoch :: Date -> Int
+daysSinceEpoch date = daysInPreviousYearsSinceEpoch (year date)
+ + daysInPreviousMonthsInCurrentYear date
+ + (day date - 1)
+monthsInYears :: Year -> Year -> [Date]
+monthsInYears start end = [ Date y m 1 | y <- [start..end], m<-[1..12] ]
+
mod7 :: Int -> Int
mod7 n = mod n 7
Please sign in to comment.
Something went wrong with that request. Please try again.