Class: Horologium::Representations::ModifiedJulianDate

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

Overview

The Modified Julian Date: the Julian Date counted from midnight on 17 November 1858 instead of noon on 1 January 4713 BC, so that a modern date is a five-digit number and a day begins at midnight. Geodesy and Earth orientation data are published in it.

It is the same instant, written smaller, and the smaller number is worth something: a Float spends fewer of its digits on the day count, so about 2 microseconds are left for the fraction of a day where a Julian Date has about 40. The lossless shapes of JulianDate.parse are still the way to give one exactly.

Examples:

instant = Horologium::Instant.from_modified_julian_date(
  60_796.0,
  scale: :tai
)
instant.as(:julian_date, scale: :tai)           # => 2460796.5
instant.as(:modified_julian_date, scale: :tai)  # => 60796.0

Constant Summary collapse

DAYS_AFTER_JULIAN_DATE_ORIGIN =

The days between the two origins: the Modified Julian Date origin falls this many days after the Julian Date origin, so a Modified Julian Date is the Julian Date minus this.

Returns:

  • (Rational)
Rational(4_800_001, 2)
OFFSETS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The offset at each precision, built once, so a reading does not build it again every time.

Returns:

Numeric::Precision::NAMES.map do |precision|
  [
    precision,
    Numeric::Precision.build(DAYS_AFTER_JULIAN_DATE_ORIGIN, precision)
  ]
end.to_h.freeze

Class Method Summary collapse

Class Method Details

.parse(value, low, scale, precision) ⇒ Horologium::Numeric::TwoPartFloat, Horologium::Numeric::Exact

A Modified Julian Date as it was given, as a Julian Date in days, at the precision asked for. It takes the shapes JulianDate.parse takes, and adds the days between the two origins.

Examples:

Horologium::Representations::ModifiedJulianDate.parse(
  "60796.052272",
  nil,
  Horologium::Scales::TAI,
  :exact
)

Parameters:

  • value (String, Rational, Integer, Float)

    the Modified Julian Date, in days, or its high part when a low part follows

  • low (Float, Integer, nil)

    the low part, in days

  • scale (Class)

    the scale the value is read in, passed on to JulianDate.parse, which does not use it

  • precision (Symbol)

    :standard or :exact

Returns:

Raises:

  • (ParseError)

    when a String does not spell a Modified Julian Date

  • (ArgumentError)

    when it is none of the shapes above

  • (UnknownPrecisionError)

    when the precision is not recognised



85
86
87
88
89
90
# File 'lib/horologium/representations/modified_julian_date.rb', line 85

def parse(value, low, scale, precision)
  Numeric::Precision.add(
    JulianDate.parse(value, low, scale, precision),
    offset(precision)
  )
end

.render(reading, output) ⇒ Float, ...

The Modified Julian Date, in the type asked for. The types are the ones a Julian Date comes out as, JulianDate::OUTPUTS, and they mean the same here.

Parameters:

Returns:

Raises:



52
53
54
55
56
57
58
59
60
# File 'lib/horologium/representations/modified_julian_date.rb', line 52

def render(reading, output)
  JulianDate.render_value(
    Numeric::Precision.subtract(
      reading.value,
      offset(reading.precision)
    ),
    output
  )
end