Skip to content

Commit

Permalink
Refactor calculation of leap years
Browse files Browse the repository at this point in the history
  • Loading branch information
mlopes committed May 12, 2019
1 parent 8613e25 commit 4b9990c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main/scala/wen/datetime/Date.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ final case class Date private (day: Day, month: Month, year: Year)

final object Date {
def safe(day: Day, month: Month, year: Year): Option[Date] = {
def isLeapYear(y: Year): Boolean =
(y.year.value % 4 == 0 && y.year.value % 100 != 0) || y.year.value % 400 == 0
def isLeapYear: Year => Boolean = {
case Year(year, _) =>
(year.value % 4 == 0 && year.value % 100 != 0) || year.value % 400 == 0
}

month match {
case February
Expand Down

0 comments on commit 4b9990c

Please sign in to comment.