From armand at nl.envida.net Tue Sep 7 14:08:40 2010 From: armand at nl.envida.net (Armand A. Verstappen) Date: Tue, 7 Sep 2010 20:08:40 +0200 Subject: [iCalendar-devel] trouble parsing timezone data In-Reply-To: <20100827193713.GD31173@orion.vi.c> References: <20100827193713.GD31173@orion.vi.c> Message-ID: <20100907180840.GF25609@orion.vi.c> Hi Rick, For some reason, I did not receive your reply to the list, I just ran into it in the list archive. Thank you for your answer, it confirms my suspicions. I'll make sure to have a look at ri_cal, as indeed I'm not really interested in the timezones, I just want the event time to be presented to me in local time format, while most of the icalendar requests I receive originate from a different timezone. Timezone parsing took 95% of my code lines, the remainder was spent doing what I actually wanted to do in the first place. From what you say, ri_cal may be much more accomodating to my needs. Cheers, -- Armand. On Fri, Aug 27, 2010 at 21:37:13 +0200, Armand A. Verstappen wrote: > Hi, > > I recently started playing with the ruby icalendar module, and I'm running into some trouble. This may very well be cause by ruby being far from my native language, on the other hand I may have hit a bug. > > >From what I've learned so far from reading examples, I believe I should be able to do > > ... > cals = Icalendar.parse($<) > cals.each do |cal| > cal.timezones.earch do |tz| > puts "timezone id is: #{tz.tzid}" > puts "standard offset from is: #{tz.standard.tzoffsetfrom}" > end > end > ... > > With stock icalendar 1.1.5, the tz.standard.tzoffsetfrom is allway empty. While debugging, I came to believe this being cause by: > > ... > # Allow block syntax for declaration of standard and daylight components of timezone > def standard(&block) > e = Standard.new > self.add_component e > > e.instance_eval &block if block > > e > end > > def daylight(&block) > e = Daylight.new > self.add_component e > > e.instance_eval &block if block > > e > end > ... > > in lib/icalendar/component/timezone.rb > > At least, renaming those functions to add_standard and add_daylight will leave me with properly populated standard and daylight objects/components when parsing .ics files. I am of course sure that in renaming those functions, I have broken just about everything on the creation of ical files. Not a real problem for me, as my use case only involves parsing, but I'd like to have my solution work with an unpatched version of icalendar of course. Looking at my problem, I see two possible causes: > > a) I have completely misguessed the proper way to access the 'standard' and 'daylight' components of the timezone object/component, thus overwriting the properly parsed versions with empty versions when hitting the 'e=Standard.new' and 'e=Daylight.new' lines above. > b) There's a bug in icalendar, where the daylight and standard methods are designed for creating new components/objects, but accidently block calling of their methods and the retrieval of their attributes. > > As this is the first time I jump into ruby, and I have only taken half the time to breeze through a ruby introduction tutorial, I'm not equipped to decide whether a) or b) is the case, and certainly not to produce a patch should it turn out to be b). > > I would really appreciate if someone could tell me if a) or b) is the case, as is a nice pointer to documentation that would have allowed me to produce the answer myself. > > best regards, > > -- > Armand A. Verstappen > _______________________________________________ > icalendar-devel mailing list > icalendar-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/icalendar-devel From hartct at gmail.com Mon Sep 20 22:50:59 2010 From: hartct at gmail.com (Christopher Hart) Date: Mon, 20 Sep 2010 22:50:59 -0400 Subject: [iCalendar-devel] Question about using iCalendar in rake tasks Message-ID: First, thanks for making iCalendar - I can't imagine having to do this from scratch! I have a question I was hoping someone can help me with. I use iCalendar in one of my Rails models to generate iCalendar files when certain types of objects are created. This works fine within my Rails application, but I recently had the need to invoke one of the finders in the model through a rake task. The method called by the rake task never uses any iCalendar functionality, but when I invoke the task, I get the following error: $ rake appointment:upcoming_reminder --trace (in /Users/chris/dev/ss) ** Invoke appointment:upcoming_reminder (first_time) ** Invoke environment (first_time) ** Execute environment ** Execute appointment:upcoming_reminder rake aborted! undefined method `all' for Icalendar::Event:Class /Users/chris/dev/ss/app/models/event.rb:57:in `findEventsTomorrowForEmail' /Users/chris/dev/ss/lib/tasks/notification.rake:6 /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in `call' ... The referenced line of the event model file is the invocation of a custom finder. Also within that model I require and include icalendar. Is it possible that somehow the include of Icalendar is causing this rake problem? Is there a way around it? Any suggestions are appreciated! Thanks, Chris I'm relatively new to creating rake tasks so I'm at a bit of a loss as to why this is happening. Could it have something to do with the -------------- next part -------------- An HTML attachment was scrubbed... URL: From sean at dague.net Tue Sep 21 08:54:53 2010 From: sean at dague.net (Sean Dague) Date: Tue, 21 Sep 2010 08:54:53 -0400 Subject: [iCalendar-devel] Question about using iCalendar in rake tasks In-Reply-To: References: Message-ID: <4C98AB1D.1070302@dague.net> That's a new one that I've not seen before, can you share the code that is triggering this? My guess it that something is empty or nil that you aren't expecting, and that's causing the issue. -Sean On 09/20/2010 10:50 PM, Christopher Hart wrote: > First, thanks for making iCalendar - I can't imagine having to do this > from scratch! > > I have a question I was hoping someone can help me with. I use iCalendar > in one of my Rails models to generate iCalendar files when certain types > of objects are created. This works fine within my Rails application, but > I recently had the need to invoke one of the finders in the model > through a rake task. The method called by the rake task never uses any > iCalendar functionality, but when I invoke the task, I get the following > error: > > $ rake appointment:upcoming_reminder --trace > (in /Users/chris/dev/ss) > ** Invoke appointment:upcoming_reminder (first_time) > ** Invoke environment (first_time) > ** Execute environment > ** Execute appointment:upcoming_reminder > rake aborted! > undefined method `all' for Icalendar::Event:Class > /Users/chris/dev/ss/app/models/event.rb:57:in `findEventsTomorrowForEmail' > /Users/chris/dev/ss/lib/tasks/notification.rake:6 > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in > `call' > ... > > The referenced line of the event model file is the invocation of a > custom finder. Also within that model I require and include icalendar. > Is it possible that somehow the include of Icalendar is causing this > rake problem? Is there a way around it? > > Any suggestions are appreciated! > > Thanks, > Chris > > I'm relatively new to creating rake tasks so I'm at a bit of a loss as > to why this is happening. Could it have something to do with the > > > > _______________________________________________ > icalendar-devel mailing list > icalendar-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/icalendar-devel -- __________________________________________________________________ Sean Dague Learn about the Universe with the sean at dague dot net Mid-Hudson Astronomical Association http://dague.net http://midhudsonastro.org There is no silver bullet. Plus, werewolves make better neighbors than zombies, and they tend to keep the vampire population down. __________________________________________________________________ From hartct at gmail.com Tue Sep 21 11:48:12 2010 From: hartct at gmail.com (Christopher Hart) Date: Tue, 21 Sep 2010 11:48:12 -0400 Subject: [iCalendar-devel] Question about using iCalendar in rake tasks In-Reply-To: <4C98AB1D.1070302@dague.net> References: <4C98AB1D.1070302@dague.net> Message-ID: Sure Sean. My model code (with a couple model names made generic by find/replace): require 'rubygems' require 'icalendar' require 'date' class Event < ActiveRecord::Base include Icalendar belongs_to :model1 belongs_to :model2 belongs_to :model3 belongs_to :model4 attr_accessible :model4 after_save :sendIcalEmail def sendIcalEmail logger.debug "in sendIcalEmail" if (!self.customer.nil? && self.customer.emailReminders == true) #icalEvent = Icalender::Event.new #icalEvent.start = DateTime.parse(self[:startTime]) #icalEvent.summary = summary "Appointment with " + self[:model3].fullName + " for " + self[:model4].description evstart = startTime.to_datetime evend = endTime.to_datetime evsummary = "Appointment at " + self.name cal = Calendar.new cal.event do dtstart evstart dtend evend summary evsummary location alarm do action "DISPLAY" # This line isn't necessary, it's the default summary evsummary trigger "-P1DT0H0M0S" # 1 day before end end #cal.add_event(icalEvent) #logger.debug cal.to_ical CustomerNotifier.deliver_eventNotification(self.customer.email, cal.to_ical) logger.debug cal.to_ical end end def self.findEventsTomorrow tomorrow = Time.now.strftime("%Y-%m-%d") Event.all :joins => [:model1, :model2, :model3, :model4], :conditions => ["startTime LIKE ?", "#{tomorrow}%"] end def self.findEventsTomorrowForEmail tomorrow = Time.now.strftime("%Y-%m-%d") nextDay = (Time.now + 1).strftime("%Y-%m-%d") #Event.all :joins => [:model1, :model2, :model3, :model4], :conditions => ["startTime > #{tomorrow} and endTime < #{nextDay} and emailReminders = 1" ] end def self.findEventsTomorrowForSMS tomorrow = Time.now.strftime("%Y-%m-%d") nextDay = (Time.now + 1).strftime("%Y-%m-%d") Event.all :joins => [:model1, :model2, :model3, :model4], :conditions => ["startTime > #{tomorrow} and endTime < #{nextDay} and smsReminders = 1" ] end end And the rake task: namespace :appointment do desc "Sends upcoming appointment reminders to clients" task :upcoming_reminder => :environment do events = Event.findEventsTomorrowForEmail print "Sending upcoming appointment reminders" events.each do |e| print e.startTime + " " + e.endTime + " " + e.customer.email end end end Thanks for your help, Chris On Tue, Sep 21, 2010 at 8:54 AM, Sean Dague wrote: > That's a new one that I've not seen before, can you share the code that is > triggering this? My guess it that something is empty or nil that you aren't > expecting, and that's causing the issue. > > -Sean > > > On 09/20/2010 10:50 PM, Christopher Hart wrote: > >> First, thanks for making iCalendar - I can't imagine having to do this >> from scratch! >> >> I have a question I was hoping someone can help me with. I use iCalendar >> in one of my Rails models to generate iCalendar files when certain types >> of objects are created. This works fine within my Rails application, but >> I recently had the need to invoke one of the finders in the model >> through a rake task. The method called by the rake task never uses any >> iCalendar functionality, but when I invoke the task, I get the following >> error: >> >> $ rake appointment:upcoming_reminder --trace >> (in /Users/chris/dev/ss) >> ** Invoke appointment:upcoming_reminder (first_time) >> ** Invoke environment (first_time) >> ** Execute environment >> ** Execute appointment:upcoming_reminder >> rake aborted! >> undefined method `all' for Icalendar::Event:Class >> /Users/chris/dev/ss/app/models/event.rb:57:in `findEventsTomorrowForEmail' >> /Users/chris/dev/ss/lib/tasks/notification.rake:6 >> >> /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in >> `call' >> ... >> >> The referenced line of the event model file is the invocation of a >> custom finder. Also within that model I require and include icalendar. >> Is it possible that somehow the include of Icalendar is causing this >> rake problem? Is there a way around it? >> >> Any suggestions are appreciated! >> >> Thanks, >> Chris >> >> I'm relatively new to creating rake tasks so I'm at a bit of a loss as >> to why this is happening. Could it have something to do with the >> >> >> >> _______________________________________________ >> icalendar-devel mailing list >> icalendar-devel at rubyforge.org >> http://rubyforge.org/mailman/listinfo/icalendar-devel >> > > > -- > __________________________________________________________________ > > Sean Dague Learn about the Universe with the > sean at dague dot net Mid-Hudson Astronomical Association > http://dague.net http://midhudsonastro.org > > There is no silver bullet. Plus, werewolves make better neighbors > than zombies, and they tend to keep the vampire population down. > __________________________________________________________________ > > _______________________________________________ > icalendar-devel mailing list > icalendar-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/icalendar-devel > -------------- next part -------------- An HTML attachment was scrubbed... URL: From hartct at gmail.com Thu Sep 23 09:47:39 2010 From: hartct at gmail.com (Christopher Hart) Date: Thu, 23 Sep 2010 09:47:39 -0400 Subject: [iCalendar-devel] Question about using iCalendar in rake tasks In-Reply-To: References: <4C98AB1D.1070302@dague.net> Message-ID: I may have found a clue on this. If I change the methods in the model to "self.find" or "self.all" instead of using the model name (Event.find/Event.all), it works fine. I'm relatively new to Ruby so I'm not exactly sure why this matters. (Either work fine if I comment out 'include Icalendar'.) Is it possible that methods invoked with Event.* are somehow getting picked up by the Icalendar module due to the include? Thinking that this may be the case, I tried adding the following to the Icalendar module but that didn't solve the problem: def self.included(base) base.extend(ClassMethods) end I'm glad I have a workaround, but I'd still like to understand why this happened. If anyone has any ideas, I'd appreciate it. Thanks! Chris On Tue, Sep 21, 2010 at 11:48 AM, Christopher Hart wrote: > Sure Sean. My model code (with a couple model names made generic by > find/replace): > > require 'rubygems' > require 'icalendar' > require 'date' > > class Event < ActiveRecord::Base > include Icalendar > > belongs_to :model1 > belongs_to :model2 > belongs_to :model3 > belongs_to :model4 > > attr_accessible :model4 > > after_save :sendIcalEmail > > def sendIcalEmail > logger.debug "in sendIcalEmail" > if (!self.customer.nil? && self.customer.emailReminders == true) > #icalEvent = Icalender::Event.new > #icalEvent.start = DateTime.parse(self[:startTime]) > #icalEvent.summary = summary "Appointment with " + > self[:model3].fullName + " for " + self[:model4].description > evstart = startTime.to_datetime > evend = endTime.to_datetime > evsummary = "Appointment at " + self.name > cal = Calendar.new > cal.event do > dtstart evstart > dtend evend > summary evsummary > location > alarm do > action "DISPLAY" # This line isn't necessary, it's > the default > summary evsummary > trigger "-P1DT0H0M0S" # 1 day before > end > > end > > > #cal.add_event(icalEvent) > #logger.debug cal.to_ical > CustomerNotifier.deliver_eventNotification(self.customer.email, > cal.to_ical) > logger.debug cal.to_ical > end > end > > > def self.findEventsTomorrow > tomorrow = Time.now.strftime("%Y-%m-%d") > Event.all :joins => [:model1, :model2, :model3, :model4], :conditions > => ["startTime LIKE ?", "#{tomorrow}%"] > end > > def self.findEventsTomorrowForEmail > tomorrow = Time.now.strftime("%Y-%m-%d") > nextDay = (Time.now + 1).strftime("%Y-%m-%d") > #Event.all :joins => [:model1, :model2, :model3, :model4], :conditions > => ["startTime > #{tomorrow} and endTime < #{nextDay} and emailReminders = > 1" ] > end > > def self.findEventsTomorrowForSMS > tomorrow = Time.now.strftime("%Y-%m-%d") > nextDay = (Time.now + 1).strftime("%Y-%m-%d") > Event.all :joins => [:model1, :model2, :model3, :model4], :conditions > => ["startTime > #{tomorrow} and endTime < #{nextDay} and smsReminders = 1" > ] > end > > end > > And the rake task: > > namespace :appointment do > desc "Sends upcoming appointment reminders to clients" > task :upcoming_reminder => :environment do > events = Event.findEventsTomorrowForEmail > print "Sending upcoming appointment reminders" > events.each do |e| > print e.startTime + " " + e.endTime + " " + e.customer.email > end > end > end > > Thanks for your help, > Chris > > On Tue, Sep 21, 2010 at 8:54 AM, Sean Dague wrote: > >> That's a new one that I've not seen before, can you share the code that is >> triggering this? My guess it that something is empty or nil that you aren't >> expecting, and that's causing the issue. >> >> -Sean >> >> >> On 09/20/2010 10:50 PM, Christopher Hart wrote: >> >>> First, thanks for making iCalendar - I can't imagine having to do this >>> from scratch! >>> >>> I have a question I was hoping someone can help me with. I use iCalendar >>> in one of my Rails models to generate iCalendar files when certain types >>> of objects are created. This works fine within my Rails application, but >>> I recently had the need to invoke one of the finders in the model >>> through a rake task. The method called by the rake task never uses any >>> iCalendar functionality, but when I invoke the task, I get the following >>> error: >>> >>> $ rake appointment:upcoming_reminder --trace >>> (in /Users/chris/dev/ss) >>> ** Invoke appointment:upcoming_reminder (first_time) >>> ** Invoke environment (first_time) >>> ** Execute environment >>> ** Execute appointment:upcoming_reminder >>> rake aborted! >>> undefined method `all' for Icalendar::Event:Class >>> /Users/chris/dev/ss/app/models/event.rb:57:in >>> `findEventsTomorrowForEmail' >>> /Users/chris/dev/ss/lib/tasks/notification.rake:6 >>> >>> /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in >>> `call' >>> ... >>> >>> The referenced line of the event model file is the invocation of a >>> custom finder. Also within that model I require and include icalendar. >>> Is it possible that somehow the include of Icalendar is causing this >>> rake problem? Is there a way around it? >>> >>> Any suggestions are appreciated! >>> >>> Thanks, >>> Chris >>> >>> I'm relatively new to creating rake tasks so I'm at a bit of a loss as >>> to why this is happening. Could it have something to do with the >>> >>> >>> >>> _______________________________________________ >>> icalendar-devel mailing list >>> icalendar-devel at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/icalendar-devel >>> >> >> >> -- >> __________________________________________________________________ >> >> Sean Dague Learn about the Universe with the >> sean at dague dot net Mid-Hudson Astronomical Association >> http://dague.net http://midhudsonastro.org >> >> There is no silver bullet. Plus, werewolves make better neighbors >> than zombies, and they tend to keep the vampire population down. >> __________________________________________________________________ >> >> _______________________________________________ >> icalendar-devel mailing list >> icalendar-devel at rubyforge.org >> http://rubyforge.org/mailman/listinfo/icalendar-devel >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: