Module: IERS::LeapSecond
- Defined in:
- lib/iers/leap_second.rb
Defined Under Namespace
Classes: Entry
Class Method Summary collapse
- .all ⇒ Array<Entry>
-
.at(input = nil, jd: nil, mjd: nil) ⇒ Integer
TAI−UTC in seconds.
- .clear_cached! ⇒ void
- .next_scheduled ⇒ Entry?
Class Method Details
.all ⇒ Array<Entry>
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/iers/leap_second.rb', line 15 def all @mutex.synchronize do @all ||= IERS::Data.leap_second_entries.map do |parser_entry| Entry.new( effective_date: parser_entry.date, tai_utc: parser_entry.tai_utc ) end.freeze end end |
.at(input = nil, jd: nil, mjd: nil) ⇒ Integer
Returns TAI−UTC in seconds.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/iers/leap_second.rb', line 44 def at(input = nil, jd: nil, mjd: nil) query_mjd = TimeScale.to_mjd(input, jd: jd, mjd: mjd) parser_entries = IERS::Data.leap_second_entries first_mjd = parser_entries.first.mjd last_mjd = parser_entries.last.mjd if query_mjd < first_mjd raise OutOfRangeError.new( "Requested MJD #{query_mjd} is before the first leap second " \ "entry (MJD #{first_mjd})", requested_mjd: query_mjd, available_range: first_mjd..last_mjd ) end index = parser_entries.bsearch_index { |e| e.mjd > query_mjd } if index.nil? parser_entries.last.tai_utc else parser_entries[index - 1].tai_utc end end |
.clear_cached! ⇒ void
This method returns an undefined value.
27 28 29 30 31 |
# File 'lib/iers/leap_second.rb', line 27 def clear_cached! @mutex.synchronize do @all = nil end end |
.next_scheduled ⇒ Entry?
34 35 36 37 |
# File 'lib/iers/leap_second.rb', line 34 def next_scheduled today = Date.today all.find { |entry| entry.effective_date > today } end |