CalendarGrid 1.0
I'm pleased to announce my first open source project, called CalendarGrid.
CalendarGrid lets you build output like a calendar, with padding days at the beginning and end of months. It sports a flexible data structure so you can format it any way you want. You can also provide a 'plugin' to each day to give it extra knowledge. For example, this code was originally created for a booking system, so each day knew whether it was booked or not.
Find out more in the API docs-grid.rubyforge.org/.
Installation
Install with gems - gem install calendar_grid
Download from the official home at RubyForge
Sample usage
require 'calendar_grid' cal = CalendarGrid.build puts "Calendar from #{cal.first.strftime("%D")} to #{cal.last.strftime("%D")}" cal.years.each do |y| puts y.year y.months.each do |m| puts m.strftime("%B") s = m.weeks.collect do |w| w.collect { |day| "#{(day.proxy?) ? '* ' : day.strftime("%d")}" }.join(" ") end puts s puts end end
Output
Calendar from 06/01/05 to 05/31/06 2005 June * * 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 * * * ...
Thanks to Graham Arrowsmith for letting me build it, and then release it to the community.
CalendarGrid 1.0.1
CalendarGrid 1.0.1 is a major bugfix to 1.0. Please upgrade now. If you tried 1.0 and were utterly disappointed, I apologize.
Note to Rails users. Never ever rely on the nifty date math methods for real date calculation. Try this:
Um, what?
Lesson learned. Be careful with dates. This all came about because I switched from using
DatetoTimefor everything internal.Just in case anyone doesn't know how slow (but accurate!) Date is...
user system total real Date.today 0.420000 0.010000 0.430000 ( 0.452072) Time.now 0.000000 0.000000 0.000000 ( 0.003978)Thanks to Ben Bleything for the heads up!