File: utc_offset.rb

package info (click to toggle)
mhc 1.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,320 kB
  • ctags: 3,529
  • sloc: ruby: 12,404; lisp: 7,448; makefile: 70; sh: 69
file content (33 lines) | stat: -rw-r--r-- 1,081 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
module RiCal
  class PropertyValue
    #- ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license
    #
    class UtcOffset < PropertyValue # :nodoc:
      attr_accessor :sign, :hours, :minutes, :seconds

      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
      
      def to_seconds
        @sign * ((((hours*60) + minutes) * 60) + seconds)
      end
      
      def add_to_date_time_value(date_time_value)
        date_time_value.advance(:hours => sign * hours, :minutes => sign * minutes, :seconds => sign * minutes)
      end
      
      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
    end
  end
end