Skip to content

Commit 6092e16

Browse files
author
Rick Hull
committed
do more month num validation
1 parent d8863cf commit 6092e16

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

lib/compsci/date.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def self.leap_days(year)
6565

6666
# perform lookup by month number and year, one-indexed, with leap days
6767
def self.month_days(month, year)
68+
raise(InvalidMonth, month.inspect) unless (1..12).cover?(month)
6869
(month == 2 and self.leap_year?(year)) ?
6970
MON29 : MONTH_DAYS.fetch(month - 1)
7071
end
@@ -77,6 +78,7 @@ def self.guess_month(days)
7778

7879
# perform lookup by month number and year, one-indexed, with leap days
7980
def self.cumulative_days(month, year)
81+
raise(InvalidMonth, month.inspect) unless (1..12).cover?(month)
8082
days = CUMULATIVE_DAYS.fetch(month - 1)
8183
(month > 2 and self.leap_year?(year)) ? (days + 1) : days
8284
end
@@ -167,6 +169,7 @@ def self.month_number(name)
167169

168170
# perform lookup of month name by month number, one-indexed
169171
def self.month_name(number)
172+
raise(InvalidMonth, number.inspect) unless (1..12).cover?(number)
170173
MONTH_NAMES.fetch(number - 1)
171174
end
172175

0 commit comments

Comments
 (0)