Class: M2TSParser::Appendix::AribTime

Inherits:
BinaryParser::TemplateBase
  • Object
show all
Defined in:
lib/m2ts_parser/appendix/arib_time.rb

Instance Method Summary collapse

Instance Method Details

#content_descriptionObject



41
42
43
# File 'lib/m2ts_parser/appendix/arib_time.rb', line 41

def content_description
  to_s
end

#convert_mjd_to_date(mjd) ⇒ Object

ARIB STD-B10 2, appendix-C



19
20
21
22
23
24
25
26
27
# File 'lib/m2ts_parser/appendix/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/m2ts_parser/appendix/arib_time.rb', line 14

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

#date_strObject



29
30
31
# File 'lib/m2ts_parser/appendix/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/m2ts_parser/appendix/arib_time.rb', line 33

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

#to_timeObject



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

def to_time
  return Time.parse(to_s)
end