Module: IERS::LeapSecond

Defined in:
lib/iers/leap_second.rb

Defined Under Namespace

Classes: Entry

Class Method Summary collapse

Class Method Details

.allArray<Entry>

Returns:



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, Rational

TAI−UTC covers 1961-01-01 onward. From 1972 the value is a whole number of seconds read from Leap_Second.dat and returned as an Integer. Between 1961 and 1972 UTC was steered by rate adjustments rather than whole leap seconds, so the value is a fraction of a second returned as a Rational.

Parameters:

  • input (Time, Date, DateTime, nil) (defaults to: nil)
  • jd (Float, nil) (defaults to: nil)

    Julian Date

  • mjd (Float, nil) (defaults to: nil)

    Modified Julian Date

Returns:

  • (Integer, Rational)

    TAI−UTC in seconds

Raises:



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/iers/leap_second.rb', line 68

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
    return TaiUtcDrift.at(query_mjd) if TaiUtcDrift.covers?(query_mjd)

    raise OutOfRangeError.new(
      "Requested MJD #{query_mjd} is before TAI−UTC was defined " \
      "(MJD #{TaiUtcDrift::FIRST_MJD}, 1961-01-01; no published UTC " \
      "before then)",
      requested_mjd: query_mjd,
      available_range: TaiUtcDrift::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

.expired?(as_of: Date.today) ⇒ Boolean

Parameters:

  • as_of (Date) (defaults to: Date.today)

Returns:

  • (Boolean)


40
41
42
43
44
45
# File 'lib/iers/leap_second.rb', line 40

def expired?(as_of: Date.today)
  expiry = expires_on
  return false if expiry.nil?

  as_of > expiry
end

.expires_onDate?

Returns:

  • (Date, nil)


34
35
36
# File 'lib/iers/leap_second.rb', line 34

def expires_on
  IERS::Data..expires_on
end

.next_scheduledEntry?

Returns:



53
54
55
56
# File 'lib/iers/leap_second.rb', line 53

def next_scheduled
  today = Date.today
  all.find { |entry| entry.effective_date > today }
end

.updated_throughString?

Returns:

  • (String, nil)


48
49
50
# File 'lib/iers/leap_second.rb', line 48

def updated_through
  IERS::Data..updated_through
end