Class: RiCal::PropertyValue::UtcOffset

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

Overview

:nodoc:

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

Returns the value of attribute hours.



4
5
6
# File 'lib/ri_cal/property_value/utc_offset.rb', line 4

def hours
  @hours
end

#minutesObject

Returns the value of attribute minutes.



4
5
6
# File 'lib/ri_cal/property_value/utc_offset.rb', line 4

def minutes
  @minutes
end

#secondsObject

Returns the value of attribute seconds.



4
5
6
# File 'lib/ri_cal/property_value/utc_offset.rb', line 4

def seconds
  @seconds
end

#signObject

Returns the value of attribute sign.



4
5
6
# File 'lib/ri_cal/property_value/utc_offset.rb', line 4

def sign
  @sign
end

Instance Method Details

#add_to_date_time_value(date_time_value) ⇒ Object



21
22
23
# File 'lib/ri_cal/property_value/utc_offset.rb', line 21

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



25
26
27
28
# File 'lib/ri_cal/property_value/utc_offset.rb', line 25

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



17
18
19
# File 'lib/ri_cal/property_value/utc_offset.rb', line 17

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

#value=(string) ⇒ Object



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

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