class TSparser::AribTime

Public Class Methods

new(binary) click to toggle source
# File lib/definition/arib_time.rb, line 6
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

Public Instance Methods

convert_mjd_to_date(mjd) click to toggle source

ARIB STD-B10 2, appendix-C

# File lib/definition/arib_time.rb, line 18
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
date() click to toggle source
# File lib/definition/arib_time.rb, line 13
def date
  return @date ||= convert_mjd_to_date(@mjd)
end
date_str() click to toggle source
# File lib/definition/arib_time.rb, line 28
def date_str
  return sprintf("%02d/%02d/%02d", date.year, date.month, date.day)
end
to_s() click to toggle source
# File lib/definition/arib_time.rb, line 32
def to_s
  return sprintf("%s %02d:%02d:%02d +0900", date_str, @hour, @min, @sec)
end
to_time() click to toggle source
# File lib/definition/arib_time.rb, line 36
def to_time
  return Time.parse(to_s)
end