Sha256: 1d3fa6635ad657c172820e6bd67f360aaa33362a8581c1da38e186a02e056158

Contents?: true

Size: 1.47 KB

Versions: 12

Compression:

Stored size: 1.47 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
  if ENV.keys.find {|env_var| env_var.match(/^TM_/)}
    def rputs(*args)
      puts( *["<pre>", args.collect {|a| CGI.escapeHTML(a.to_s)}, "</pre>"])
    end
  else
    alias_method :rputs, :puts
  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

12 entries across 12 versions & 6 rubygems

Version Path
demingfactor-ri_cal-0.10.0 spec/spec_helper.rb
demingfactor-ri_cal-0.9.0 spec/spec_helper.rb
awallis-ri_cal-0.8.8 spec/spec_helper.rb
justinsoong-ri_cal-0.8.9 spec/spec_helper.rb
justinsoong-ri_cal-0.8.8 spec/spec_helper.rb
micahwedemeyer-ri_cal-0.8.10 spec/spec_helper.rb
micahwedemeyer-ri_cal-0.8.9 spec/spec_helper.rb
ri_cal-0.8.8 spec/spec_helper.rb
ri_cal-0.8.7 spec/spec_helper.rb
ri_cal-0.8.6 spec/spec_helper.rb
miguelbaldi-ri_cal-0.1 spec/spec_helper.rb
ri_cal-0.8.5 spec/spec_helper.rb