Ar Chron wrote:
> A brute force method would be to get the dates for the start of the
> month, the end of the month and step through the month from start to end
> by day.
>
> Check the day of the week for each date. Saturday or Sunday and it's
> out. Match one of your holidays, and its out.
>
> What's left are your business days.
Or create a set of all dates for the year, a set of all weekend dates
for the year, and a set of all holidays for the year. Then intersect the
three sets and you end up with business days.
Now store that set in the database (after all there are only 365/366
days/year so it's not going to be a load on the database). Now whenever
you need to iterate though business days just grab the set from the
database:
Example:
# Assume named_scope "days_in_month" on BusinessDays
business_days = BusinessDays.days_in_month("2")
business_days.each do |day|
puts day.to_s
end
Of course don't forget to regenerate your stored business days if
holidays change.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---