Rubyã§iCalendarãå©ç¨ãã
Rubyã§iCalendarå½¢å¼ã使ãããã¦ãã¡ãã£ã¨èª¿ã¹ãããã£ã±ãããã¾ããã
Rubyç¨iCalendarã©ã¤ãã©ãªâª->http://icalendar.rubyforge.org/
ã¤ã³ã¹ãã¼ã«ããiCalendarã©ã¤ãã©ãªã®ãã¼ã¸ã§ã³ã¯0.98ã§ãã
gemã§ä¸çºã¤ã³ã¹ãã¼ã«
$ gem install icalendar
ãµã³ãã«(READMEãã)
require 'rubygems' require 'icalendar' # Create a calendar with an event (standard method) cal = Icalendar::Calendar.new cal.event do dtstart Date.new(2005, 04, 29) dtend Date.new(2005, 04, 28) summary "Meeting with the man." description "Have a long lunch meeting and decide nothing..." klass "PRIVATE" end
ãã便å©âª
ãã ãã¡ãã£ã¨ããã£ã¦ããã©ããtimezoneããã°ã£ã¦ãã¿ããã§ãã
timezoneã使ã£ã¦ãç¶æ
ã§ãto_icalã¡ã½ãããå©ç¨ããã¨ãã¨ã©ã¼ãåºãã¾ãã
ããããã¡ãã£ã¨èª¿ã¹ãããパッチãããã¾ããã
timezoneç¨ããã
---[patch begin]--- diff -c /home/trac/ruby/gem/gems/icalendar-0.98/lib/icalendar/component/timezone.rb.org /home/trac/ruby/gem/gems/icalendar-0.98/lib/icalendar/component/timezone.rb *** /home/trac/ruby/gem/gems/icalendar-0.98/lib/icalendar/component/timezone.rb.org Wed May 2 13:45:15 2007 --- /home/trac/ruby/gem/gems/icalendar-0.98/lib/icalendar/component/timezone.rb Mon May 7 08:40:32 2007 *************** *** 49,58 **** # Also need a custom to_ical because typically it iterates over an array # of components. def to_ical ! print_component do |s| @components.each_value do |comp| s << comp.to_ical end end end --- 49,60 ---- # Also need a custom to_ical because typically it iterates over an array # of components. def to_ical ! print_component do ! s = "" @components.each_value do |comp| s << comp.to_ical end + s end end ---[patch end]---
ããã§ãä¸å¿to_icalã¡ã½ãããéãããã«ã¯ãªããã§ããã©ã
cal = Icaledar::Calendar.new cal.timezone do tzid 'Asia/Tokyo' standard do tzoffsetfrom '+0900' tzoffsetto '+0900' dtstart '19700101T000000' tzname 'JST' end end
ã¨ããæãã§ãstandardã使ã£ã¦ããä¸ååå¿ãã¦ããã¾ããããªãã§ï½¥ï½¥ï½¥
ã½ã¼ã¹è¦ã¦ãã¶ã£ã¡ããããããããªããã§ã
ã¨ããããã図書館で借りた本の返却日をGoogle Calendarに反映する その3 - Action!!ãåèã«timezoneé¨åãä½æã
cal = Icalendar::Calendar.new # STANDARD ã³ã³ãã¼ãã³ããçæ standard_component = Icalendar::Component.new('STANDARD') standard_component.custom_property('dtstart', '19700101T000000') standard_component.custom_property('tzoffsetfrom', '+0900') standard_component.custom_property('tzoffsetto', '+0900') standard_component.custom_property('tzname', 'JST') # VTIMEZONE ã³ã³ãã¼ãã³ããçæ vtimezone_component = Icalendar::Component.new('VTIMEZONE') vtimezone_component.custom_property('tzid', 'Asia/Tokyo') vtimezone_component.add(standard_component) cal.add(vtimezone_component)
ã¡ãªã¿ã«ãcustom_propertyã®ç¬¬ä¸å¼æ°ã¯ãèªåçã«å¤§æåã«ãªãã¾ãã
ãã§ãããã使ã£ã¦ãiCalendarã®ãµã³ãã«ã¯ä»¥ä¸ã®ããã«ãªãã¾ãã
iCalendarã®ãµã³ãã«
require 'rubygems' require 'icalendar' require 'kconv' cal = Icalendar::Calendar.new # ã¤ãã³ããä½æ cal.event do dtstart DateTime.new(2007, 07, 02, 10) dtend DateTime.new(2005, 07, 02, 20) summary "Meeting with the man." description "Have a long lunch meeting and decide nothing..." klass "PRIVATE" end # STANDARD ã³ã³ãã¼ãã³ããçæ standard_component = Icalendar::Component.new('STANDARD') standard_component.custom_property('dtstart', '19700101T000000') standard_component.custom_property('tzoffsetfrom', '+0900') standard_component.custom_property('tzoffsetto', '+0900') standard_component.custom_property('tzname', 'JST') # VTIMEZONE ã³ã³ãã¼ãã³ããçæ vtimezone_component = Icalendar::Component.new('VTIMEZONE') vtimezone_component.custom_property('tzid', 'Asia/Tokyo') vtimezone_component.add(standard_component) cal.add(vtimezone_component) File.open("sample.ics", "w+b") { |f| f.write(cal.to_ical.toutf8) }
ã¨ãããããã§ãåºæ¬çãªiCalendarå½¢å¼ã®ãã¡ã¤ã«(sample.ics)ãçæããããã§ããã
ãããGoogle Calendarã«ã¤ã³ãã¼ããã¦ã¿ããããªãããæå»ããã¾ãããã¾ããã
ããã¦ããããã試ããçµæã以ä¸ã®ããã«ããããã§ãã¾ããã
iCalendarã®ãµã³ãã«æ¹(Google Calendarã§ã¤ã³ãã¼ãå¯è½)
require 'rubygems' require 'icalendar' require 'kconv' cal = Icalendar::Calendar.new # ã¤ãã³ããä½æ cal.event do dtstart DateTime.new(2007, 07, 02, 10), {'TZID' => 'Asia/Tokyo'} # å¤æ´ç®æ dtend DateTime.new(2005, 07, 02, 20), {'TZID' => 'Asia/Tokyo'} # å¤æ´ç®æ summary "Meeting with the man." description "Have a long lunch meeting and decide nothing..." klass "PRIVATE" end # STANDARD ã³ã³ãã¼ãã³ããçæ standard_component = Icalendar::Component.new('STANDARD') standard_component.custom_property('dtstart', '19700101T000000') standard_component.custom_property('tzoffsetfrom', '+0900') standard_component.custom_property('tzoffsetto', '+0900') standard_component.custom_property('tzname', 'JST') # VTIMEZONE ã³ã³ãã¼ãã³ããçæ vtimezone_component = Icalendar::Component.new('VTIMEZONE') vtimezone_component.custom_property('tzid', 'Asia/Tokyo') vtimezone_component.add(standard_component) cal.add(vtimezone_component) File.open("sample.ics", "w+b") { |f| f.write(cal.to_ical.toutf8) }
ã¨ããæãã§ãã
ã©ããDTSTARTã¨DTENDã«ããTZIDãè¨å®ãããã¨ãéè¦ãªããã§ãã
ã¤ã¾ãã
DTSTART:20070702T100000 DTEND:20070702T200000
ã§ã¯ãªãã
DTSTART;TZID=Asia/Tokyo:20070702T100000 DTEND;TZID=Asia/Tokyo:20070702T200000
ã¨ãªã£ã¦ãªãã¨ãGoogle Calendarã§ã¯èªèãã¦ãããªãã¿ããã§ãã