Class: Tai64::Label
Instance Method Summary collapse
- #format_string ⇒ Object
-
#initialize(str) ⇒ Label
constructor
A new instance of Label.
- #tai_attosecond ⇒ Object
- #tai_nanosecond ⇒ Object
- #tai_parts ⇒ Object
- #tai_reference ⇒ Object
- #tai_second ⇒ Object
- #to_s ⇒ Object
-
#to_time ⇒ Object
Warning, this will probably lose accuracy - Ruby does not support the same level of timing accuracy as TAI64N and TA64NA can provide.
- #utc_attosecond ⇒ Object
- #utc_nanosecond ⇒ Object
- #utc_reference ⇒ Object
- #utc_second ⇒ Object
Methods included from Fudge
Constructor Details
#initialize(str) ⇒ Label
Returns a new instance of Label.
84 85 86 |
# File 'lib/tai64.rb', line 84 def initialize str self.str = str.gsub /^@/, '' end |
Instance Method Details
#format_string ⇒ Object
135 136 137 138 139 140 141 142 |
# File 'lib/tai64.rb', line 135 def format_string fmt = "%016x" return fmt if tai_nanosecond.nil? fmt << "%08x" return fmt if tai_attosecond.nil? fmt << "%08x" return fmt end |
#tai_attosecond ⇒ Object
120 121 122 123 124 |
# File 'lib/tai64.rb', line 120 def tai_attosecond part = str.scan(/^(?:\@)?[0-9abcdef]{16}[0-9a-f]{8}([0-9a-f]{8})/i)[0][0] part.to_i(16).to_f rescue end |
#tai_nanosecond ⇒ Object
109 110 111 112 113 |
# File 'lib/tai64.rb', line 109 def tai_nanosecond part = str.scan(/^(?:\@)?[0-9abcdef]{16}([0-9a-f]{8})/i)[0][0] part.to_i(16).to_f rescue end |
#tai_parts ⇒ Object
131 132 133 |
# File 'lib/tai64.rb', line 131 def tai_parts [ tai_second, tai_nanosecond, tai_attosecond ].compact end |
#tai_reference ⇒ Object
151 152 153 154 155 156 |
# File 'lib/tai64.rb', line 151 def tai_reference tai_time = tai_second tai_time += tai_nanosecond / (10 ** 9) unless tai_nanosecond.nil? tai_time += tai_attosecond / (10 ** 18) unless tai_attosecond.nil? tai_time end |
#tai_second ⇒ Object
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/tai64.rb', line 92 def tai_second s = str.scan(/^\@?([0-9abcdef]{16})/i)[0][0].to_i(16) if s.between? 0, EPOCH - 1 return EPOCH - s elsif s.between? EPOCH, MAXIMUM return s - EPOCH else raise "I don't know how to deal with s=#{s}" end end |
#to_s ⇒ Object
88 89 90 |
# File 'lib/tai64.rb', line 88 def to_s "@#{str}" % tai_parts end |
#to_time ⇒ Object
Warning, this will probably lose accuracy - Ruby does not support the same level of timing accuracy as TAI64N and TA64NA can provide.
160 161 162 163 |
# File 'lib/tai64.rb', line 160 def to_time t = ::Time.at utc_reference Time.new t.utc end |
#utc_attosecond ⇒ Object
126 127 128 129 |
# File 'lib/tai64.rb', line 126 def utc_attosecond tai_attosecond rescue end |
#utc_nanosecond ⇒ Object
115 116 117 118 |
# File 'lib/tai64.rb', line 115 def utc_nanosecond tai_nanosecond - nano_second_fudge rescue end |
#utc_reference ⇒ Object
144 145 146 147 148 149 |
# File 'lib/tai64.rb', line 144 def utc_reference utc_time = utc_second utc_time += utc_nanosecond / (10 ** 9) unless utc_nanosecond.nil? utc_time += utc_attosecond / (10 ** 18) unless utc_attosecond.nil? utc_time end |
#utc_second ⇒ Object
103 104 105 106 107 |
# File 'lib/tai64.rb', line 103 def utc_second # UTC was 10 seconds behind TAI when the International Earth Rotation # Service started adding leap seconds tai_second - 10 end |