Sha256: 2281c4be98383180ca768cc6f720d6a15e8eddcc60a2d928e2dbb6fb7f20b5a7

Contents?: true

Size: 1.4 KB

Versions: 41

Compression:

Stored size: 1.4 KB

Contents

#- ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license

require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib ri_cal]))
require 'cgi'
require 'tzinfo'

module Kernel
  def rputs(*args)
    puts *["<pre>", args.collect {|a| CGI.escapeHTML(a.to_s)}, "</pre>"] #if RiCal.debug
    # puts *args
  end
end

def date_time_with_zone(date_time, tzid = "US/Eastern")
  date_time.dup.set_tzid(tzid)
end

def dt_prop(date_time, tzid = "US/Eastern")
  RiCal::PropertyValue::DateTime.convert(nil, date_time_with_zone(date_time, tzid))
end

def offset_for_tzid(year, month, day, hour, min, sec, tzid, alternate)
  tz = TZInfo::Timezone.get(tzid) rescue nil
  if tz
    Rational(tz.period_for_local(DateTime.civil(year, month, day, hour, min, sec)).utc_total_offset, 86400)
  else
    provided_offset
  end
end

def rectify_ical(string)
  string.gsub(/^\s+/, "")
end

if RiCal::TimeWithZone
  def result_time_in_zone(year, month, day, hour, min, sec, tzid, alternate_offset = nil)
    DateTime.civil(year, month, day, hour, min, sec, 
       offset_for_tzid(year, month, day, hour, min, sec, tzid, alternate_offset)).in_time_zone(tzid)
  end
else
  def result_time_in_zone(year, month, day, hour, min, sec, tzid, alternate_offset = nil)
    DateTime.civil(year, month, day, hour, min, sec, 
    offset_for_tzid(year, month, day, hour, min, sec, tzid, alternate_offset)).set_tzid(tzid)
  end
end

Version data entries

41 entries across 41 versions & 3 rubygems

Version Path
ebeigarts-ri_cal-0.8.1 spec/spec_helper.rb
rubyredrick-ri_cal-0.0.10 spec/spec_helper.rb
rubyredrick-ri_cal-0.0.11 spec/spec_helper.rb
rubyredrick-ri_cal-0.5.0 spec/spec_helper.rb
rubyredrick-ri_cal-0.5.1 spec/spec_helper.rb
rubyredrick-ri_cal-0.5.2 spec/spec_helper.rb
rubyredrick-ri_cal-0.5.3 spec/spec_helper.rb
rubyredrick-ri_cal-0.6.0 spec/spec_helper.rb
rubyredrick-ri_cal-0.6.1 spec/spec_helper.rb
rubyredrick-ri_cal-0.6.2 spec/spec_helper.rb
rubyredrick-ri_cal-0.6.3 spec/spec_helper.rb
rubyredrick-ri_cal-0.7.0 spec/spec_helper.rb
rubyredrick-ri_cal-0.7.1 spec/spec_helper.rb
rubyredrick-ri_cal-0.7.2 spec/spec_helper.rb
rubyredrick-ri_cal-0.7.4 spec/spec_helper.rb
rubyredrick-ri_cal-0.7.5 spec/spec_helper.rb
rubyredrick-ri_cal-0.7.7 spec/spec_helper.rb
rubyredrick-ri_cal-0.8.0 spec/spec_helper.rb
rubyredrick-ri_cal-0.8.1 spec/spec_helper.rb
rubyredrick-ri_cal-0.8.2 spec/spec_helper.rb