Skip to content

Commit

Permalink
works for most formats for month
Browse files Browse the repository at this point in the history
  • Loading branch information
Krishnaprasad T Nair committed Dec 21, 2012
1 parent 06680bc commit 6b39902
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lib/by_star/by_month.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,18 @@ def by_month_Time(time, options={})
end

def by_month_String_or_Fixnum(month, options={})
if valid_month?(month)
begin
year = options[:year] || Time.zone.now.year
by_month_Time("#{year}-#{month}-01".to_time, options)
else
date = Date.parse("#{year}-#{month}-01").to_time
by_month_Time(date, options)

rescue
raise ParseError, "Month must be a number between 1 and 12 or the full month name (e.g. 'January', 'Feburary', etc.)"
end
end

alias_method :by_month_String, :by_month_String_or_Fixnum
alias_method :by_month_Fixnum, :by_month_String_or_Fixnum


def valid_month?(month)
(1..12).include?(month) || Date::MONTHNAMES.include?(month)
end

end
end

0 comments on commit 6b39902

Please sign in to comment.