Class: TZInfo::TZDataTime
- Inherits:
-
Object
- Object
- TZInfo::TZDataTime
- Defined in:
- lib/tzinfo/tzdataparser.rb
Overview
A tz data time definition - an hour, minute, second and reference. Reference is either :utc, :standard or :wall_clock.
Instance Attribute Summary collapse
-
#hour ⇒ Object
readonly
:nodoc:.
-
#minute ⇒ Object
readonly
Returns the value of attribute minute.
-
#ref ⇒ Object
readonly
Returns the value of attribute ref.
-
#second ⇒ Object
readonly
Returns the value of attribute second.
Instance Method Summary collapse
-
#initialize(spec) ⇒ TZDataTime
constructor
A new instance of TZDataTime.
-
#to_utc(utc_offset, std_offset, year, month, day) ⇒ Object
Converts the time to UTC given a utc_offset and std_offset.
Constructor Details
#initialize(spec) ⇒ TZDataTime
Returns a new instance of TZDataTime.
942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 |
# File 'lib/tzinfo/tzdataparser.rb', line 942 def initialize(spec) raise "Invalid time: #{spec}" if spec !~ /^([0-9]+)(:([0-9]+)(:([0-9]+))?)?([wguzs])?$/ @hour = $1.to_i @minute = $3.nil? ? 0 : $3.to_i @second = $5.nil? ? 0 : $5.to_i if $6 == 's' @ref = :standard elsif $6 == 'g' || $6 == 'u' || $6 == 'z' @ref = :utc else @ref = :wall_clock end end |
Instance Attribute Details
#hour ⇒ Object (readonly)
:nodoc:
937 938 939 |
# File 'lib/tzinfo/tzdataparser.rb', line 937 def hour @hour end |
#minute ⇒ Object (readonly)
Returns the value of attribute minute.
938 939 940 |
# File 'lib/tzinfo/tzdataparser.rb', line 938 def minute @minute end |
#ref ⇒ Object (readonly)
Returns the value of attribute ref.
940 941 942 |
# File 'lib/tzinfo/tzdataparser.rb', line 940 def ref @ref end |
#second ⇒ Object (readonly)
Returns the value of attribute second.
939 940 941 |
# File 'lib/tzinfo/tzdataparser.rb', line 939 def second @second end |
Instance Method Details
#to_utc(utc_offset, std_offset, year, month, day) ⇒ Object
Converts the time to UTC given a utc_offset and std_offset.
959 960 961 962 963 964 965 |
# File 'lib/tzinfo/tzdataparser.rb', line 959 def to_utc(utc_offset, std_offset, year, month, day) result = DateTime.new(year, month, day, @hour, @minute, @second) offset = 0 offset = offset + utc_offset if @ref == :standard || @ref == :wall_clock offset = offset + std_offset if @ref == :wall_clock result - Rational(offset, 86400) end |