Class: TSparser::AribTime

Inherits:
Object
  • Object
show all
Defined in:
lib/definition/arib_time.rb

Instance Method Summary collapse

Constructor Details

#initialize(binary) ⇒ AribTime

Returns a new instance of AribTime.



7
8
9
10
11
12
# File 'lib/definition/arib_time.rb', line 7

def initialize(binary)
  @mjd  = binary.read_byte_as_integer(2)
  @hour = binary.read_bit_as_integer(4) * 10 + binary.read_bit_as_integer(4)
  @min  = binary.read_bit_as_integer(4) * 10 + binary.read_bit_as_integer(4)
  @sec  = binary.read_bit_as_integer(4) * 10 + binary.read_bit_as_integer(4)
end

Instance Method Details

#convert_mjd_to_date(mjd) ⇒ Object

ARIB STD-B10 2, appendix-C



19
20
21
22
23
24
25
26
27
# File 'lib/definition/arib_time.rb', line 19

def convert_mjd_to_date(mjd)
  y_ = ((mjd - 15078.2) / 365.25).to_i
  m_ = ((mjd - 14956.1 - (y_ * 365.25).to_i) / 30.6001).to_i
  d  = mjd - 14956 - (y_ * 365.25).to_i - (m_ * 30.6001).to_i
  k  = (m_ == 14 || m_ == 15) ? 1 : 0
  y  = y_ + k
  m  = m_ - 1 - k * 12
  return Date.new(1900 + y, m, d)
end

#dateObject



14
15
16
# File 'lib/definition/arib_time.rb', line 14

def date
  return @date ||= convert_mjd_to_date(@mjd)
end

#date_strObject



29
30
31
# File 'lib/definition/arib_time.rb', line 29

def date_str
  return sprintf("%02d/%02d/%02d", date.year, date.month, date.day)
end

#to_sObject



33
34
35
# File 'lib/definition/arib_time.rb', line 33

def to_s
  return sprintf("%s %02d:%02d:%02d +0900", date_str, @hour, @min, @sec)
end

#to_timeObject



37
38
39
# File 'lib/definition/arib_time.rb', line 37

def to_time
  return Time.parse(to_s)
end