Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

more date functions

  • Loading branch information...
commit 6b38dfc77587f8bc0e0660d7823fbe6f62188b79 1 parent 8712697
Eric Wilson authored

Showing 1 changed file with 19 additions and 2 deletions. Show diff stats Hide diff stats

  1. +19 2 019.hs
21 019.hs
@@ -29,8 +29,25 @@ daysInMonth date
29 29 m = month date
30 30 y = year date
31 31
32   -dayShiftFromYearChange :: Year -> Year -> Int
33   -dayShiftFromYearChange start end = mod7 (sum $ map daysInYear [start..end-1])
  32 +epoch :: Date
  33 +epoch = Date 1900 1 1
  34 +
  35 +daysInPreviousYearsSinceEpoch :: Year -> Int
  36 +daysInPreviousYearsSinceEpoch currentYear = sum $ map daysInYear [year epoch..currentYear-1]
  37 +
  38 +daysInPreviousMonthsInCurrentYear :: Date -> Int
  39 +daysInPreviousMonthsInCurrentYear date = sum $ map daysInMonth (previousMonths date)
  40 +
  41 +previousMonths :: Date -> [Date]
  42 +previousMonths date = [ Date (year date) m 1 | m <- [1..(month date)-1]]
  43 +
  44 +daysSinceEpoch :: Date -> Int
  45 +daysSinceEpoch date = daysInPreviousYearsSinceEpoch (year date)
  46 + + daysInPreviousMonthsInCurrentYear date
  47 + + (day date - 1)
34 48
  49 +monthsInYears :: Year -> Year -> [Date]
  50 +monthsInYears start end = [ Date y m 1 | y <- [start..end], m<-[1..12] ]
  51 +
35 52 mod7 :: Int -> Int
36 53 mod7 n = mod n 7

0 comments on commit 6b38dfc

Please sign in to comment.
Something went wrong with that request. Please try again.