Class: Horologium::Scales::Base Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/horologium/scales/base.rb,
sig/horologium/scales/base.rbs

Overview

This class is abstract.

Implement Base.from_reference and Base.to_reference in a subclass.

The two methods a time scale implements. One reads a TAI Julian Date in the scale, the other reads a Julian Date in the scale back in TAI. Every scale converts to and from TAI, so a scale does not need to know about the other scales.

The values are Julian Dates in days. They come at the precision of the instant, a Numeric::TwoPartFloat at :standard and a Numeric::Exact at :exact. A scale keeps that precision, and builds what it adds at the precision it is given.

Examples:

A scale one minute ahead of TAI

class MyScale < Horologium::Scales::Base
  OFFSET = Rational(60, 86_400)

  class << self
    def from_reference(value, precision)
      Horologium::Numeric::Precision.add(
        value,
        Horologium::Numeric::Precision.build(OFFSET, precision)
      )
    end

    def to_reference(value, precision)
      Horologium::Numeric::Precision.subtract(
        value,
        Horologium::Numeric::Precision.build(OFFSET, precision)
      )
    end
  end
end

Direct Known Subclasses

TAI, TDB, TT, UTC

Class Method Summary collapse

Class Method Details

.from_reference(_value, _precision) ⇒ Horologium::Numeric::TwoPartFloat, Horologium::Numeric::Exact

A TAI Julian Date, read in this scale.

Parameters:

Returns:

Raises:

  • (NotImplementedError)

    until a subclass implements it



50
51
52
# File 'lib/horologium/scales/base.rb', line 50

def from_reference(_value, _precision)
  raise NotImplementedError, "#{self} must implement .from_reference"
end

.provenance(_value) ⇒ Symbol

A continuous scale is :measured everywhere, its conversions resting on constants and models rather than revised data. UTC is the exception; see UTC.provenance.

Parameters:

Returns:

  • (Symbol)

    :measured



112
113
114
# File 'lib/horologium/scales/base.rb', line 112

def provenance(_value)
  :measured
end

.seconds_in_day(_day_number) ⇒ Integer

The seconds the clock counts in a day of this scale, on the day at day_number. A day is 86,400 seconds in every scale the library reads by continuous time. UTC is the exception: a day that holds a leap second is 86,401 seconds long, so UTC overrides this. A representation asks the scale this to map a fraction of a day to a time of day, and to know whether a 61-second final minute is legal.

Parameters:

  • _day_number (Integer)

    the Julian Day Number of the day

  • day_number (Integer)

Returns:

  • (Integer)

    the seconds in that day



77
78
79
# File 'lib/horologium/scales/base.rb', line 77

def seconds_in_day(_day_number)
  Duration::SECONDS_PER_DAY
end

.si_seconds_in_day(day_number) ⇒ Integer, Rational

The SI seconds a day of this scale spans, on the day at day_number. It matches seconds_in_day everywhere the day counts whole seconds: 86,400 in a continuous scale, 86,401 on a UTC leap second day. The one place they part is UTC's pre-1972 drift, where the clock still counts 86,400 seconds but each is fractionally longer, so the day spans a little more SI time. A numeric ISO 8601 offset counts against this, so it shifts by SI seconds on every day.

Parameters:

  • day_number (Integer)

    the Julian Day Number of the day

Returns:

  • (Integer, Rational)

    the SI seconds in that day



91
92
93
# File 'lib/horologium/scales/base.rb', line 91

def si_seconds_in_day(day_number)
  seconds_in_day(day_number)
end

.to_reference(_value, _precision) ⇒ Horologium::Numeric::TwoPartFloat, Horologium::Numeric::Exact

A Julian Date in this scale, read back in TAI. It undoes from_reference. Calling one after the other returns the value given.

Parameters:

Returns:

Raises:

  • (NotImplementedError)

    until a subclass implements it



64
65
66
# File 'lib/horologium/scales/base.rb', line 64

def to_reference(_value, _precision)
  raise NotImplementedError, "#{self} must implement .to_reference"
end

.zone_designatorString

The ISO 8601 zone designator this scale writes. Empty for a continuous scale, where the string carries no scale of its own and a bare time is a coordinate in the scale it was read in. UTC writes "Z", where a zero offset is a real thing.

Returns:

  • (String)


101
102
103
# File 'lib/horologium/scales/base.rb', line 101

def zone_designator
  ""
end