Class: RiCal::PropertyValue::UtcOffset

Inherits:
RiCal::PropertyValue show all
Defined in:
lib/ri_cal/property_value/utc_offset.rb

Overview

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

Instance Attribute Summary collapse

Attributes inherited from RiCal::PropertyValue

#params, #timezone_finder, #value

Instance Method Summary collapse

Methods inherited from RiCal::PropertyValue

#==, #add_date_times_to, convert, date_or_date_time, date_or_date_time_or_period, #default_tzid, #enumerator, #equality_value, #find_timezone, #for_parent, if_valid_string, #initialize, #parms_string, #ruby_value, #to_options_hash, #to_ri_cal_property_value, #to_s, #tz_info_source?, #validate_value, #visible_params

Constructor Details

This class inherits a constructor from RiCal::PropertyValue

Instance Attribute Details

#hoursObject

:nodoc:


6
7
8
# File 'lib/ri_cal/property_value/utc_offset.rb', line 6

def hours
  @hours
end

#minutesObject

:nodoc:


6
7
8
# File 'lib/ri_cal/property_value/utc_offset.rb', line 6

def minutes
  @minutes
end

#secondsObject

:nodoc:


6
7
8
# File 'lib/ri_cal/property_value/utc_offset.rb', line 6

def seconds
  @seconds
end

#signObject

:nodoc:


6
7
8
# File 'lib/ri_cal/property_value/utc_offset.rb', line 6

def sign
  @sign
end

Instance Method Details

#add_to_date_time_value(date_time_value) ⇒ Object


23
24
25
# File 'lib/ri_cal/property_value/utc_offset.rb', line 23

def add_to_date_time_value(date_time_value)
  date_time_value.advance(:hours => sign * hours, :minutes => sign * minutes, :seconds => sign * minutes)
end

#subtract_from_date_time_value(date_time_value) ⇒ Object


27
28
29
30
# File 'lib/ri_cal/property_value/utc_offset.rb', line 27

def subtract_from_date_time_value(date_time_value)
  signum = -1 * sign
  date_time_value.advance(:hours => signum * hours, :minutes => signum * minutes, :seconds => signum * minutes)
end

#to_secondsObject


19
20
21
# File 'lib/ri_cal/property_value/utc_offset.rb', line 19

def to_seconds
  @sign * ((((hours*60) + minutes) * 60) + seconds)
end

#value=(string) ⇒ Object


8
9
10
11
12
13
14
15
16
17
# File 'lib/ri_cal/property_value/utc_offset.rb', line 8

def value=(string)
  @value = string
  parse_match = /([+-])(\d\d)(\d\d)(\d\d)?/.match(string)
  if parse_match
    @sign = parse_match[1] == "+" ? 1 : -1
    @hours = parse_match[2].to_i
    @minutes = parse_match[3].to_i
    @seconds = parse_match[4].to_i || 0
  end
end