FUJINAKA Tohru
2007-May-07 04:03 UTC
[iCalendar-devel] [patch] fix a bug parsing DATE turns to DATE-TIME
Hi, In the current version 0.98, formatting DATE value is OK. But parsing DATE value and formatting seems not. ical = Icalendar::Calendar.new ical.event { dtstart Date.new(2007, 5, 7) } puts ical.to_ical.match(/^dtstart\b[^\r\n]+/im) # -> DTSTART:20070507 ical = Icalendar::parse(StringIO.new(ical.to_ical), true) puts ical.to_ical.match(/^dtstart\b[^\r\n]+/im) # -> DTSTART:20070507T000000 The following patch will fix it. ---[patch begin]--- diff -c /home/trac/ruby/gem/gems/icalendar-0.98/lib/icalendar/parser.rb.orig /home/trac/ruby/gem/gems/icalendar-0.98/lib/icalendar/parser.rb *** /home/trac/ruby/gem/gems/icalendar-0.98/lib/icalendar/parser.rb.orig Wed May 2 23:26:57 2007 --- /home/trac/ruby/gem/gems/icalendar-0.98/lib/icalendar/parser.rb Mon May 7 11:58:43 2007 *************** *** 318,324 **** # NOTE: invalid dates & times will be returned as strings... def parse_datetime(name, params, value) begin ! DateTime.parse(value) rescue Exception value end --- 318,324 ---- # NOTE: invalid dates & times will be returned as strings... def parse_datetime(name, params, value) begin ! value.match(/^\d{8}$/) ? Date.Parse(value) : DateTime.parse(value) rescue Exception value end ---[patch end]--- BTW, in the file conversions.rb there are to_ical() for Date, Time and DateTime. These implementation looks a bit verbose to me. Using strftime() will make them be simple, won''t it? like: s = strftime(''%Y%m%d'') and s = strftime(''%Y%m%dT%H%M%S'') s << ''Z'' if utc? Best regards, -- FUJINAKA Tohru <tohru at nakarika.com>