Permalink
Browse files

works for most formats for month

  • Loading branch information...
1 parent 06680bc commit 6b3990248a2122f032c08049295f731110e1bfdb Krishnaprasad T Nair committed Dec 21, 2012
Showing with 6 additions and 8 deletions.
  1. +6 −8 lib/by_star/by_month.rb
View
@@ -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.