Class: TZInfo::Data::TZDataTime

Inherits:
Object
  • Object
show all
Defined in:
lib/tzinfo/data/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

Instance Method Summary collapse

Constructor Details

#initialize(spec) ⇒ TZDataTime

Returns a new instance of TZDataTime.



1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
# File 'lib/tzinfo/data/tzdataparser.rb', line 1032

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

#hourObject (readonly)

:nodoc:



1027
1028
1029
# File 'lib/tzinfo/data/tzdataparser.rb', line 1027

def hour
  @hour
end

#minuteObject (readonly)

Returns the value of attribute minute.



1028
1029
1030
# File 'lib/tzinfo/data/tzdataparser.rb', line 1028

def minute
  @minute
end

#refObject (readonly)

Returns the value of attribute ref.



1030
1031
1032
# File 'lib/tzinfo/data/tzdataparser.rb', line 1030

def ref
  @ref
end

#secondObject (readonly)

Returns the value of attribute second.



1029
1030
1031
# File 'lib/tzinfo/data/tzdataparser.rb', line 1029

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.



1049
1050
1051
1052
1053
1054
1055
# File 'lib/tzinfo/data/tzdataparser.rb', line 1049

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