Skip to content

Build instants from a Julian Date read in a scale#12

Merged
rhannequin merged 2 commits into
mainfrom
from-julian-date-in-a-scale
Jul 21, 2026
Merged

Build instants from a Julian Date read in a scale#12
rhannequin merged 2 commits into
mainfrom
from-julian-date-in-a-scale

Conversation

@rhannequin

Copy link
Copy Markdown
Owner

This replaces from_tai_julian_date with from_julian_date, which reads the Julian Date in a scale and stores the instant in TAI. An instant given in one scale can then be read back in another.

instant = Horologium::Instant.from_julian_date(2_443_144.5, scale: :tai)

instant.to(:tt).as(:julian_date)
# => 2443144.5003725

The Julian Date can be given in several shapes. A String and a Rational give it exactly, a high and a low Float give it to about twice what one Float holds, and a single Float is worth about 40 microseconds at a modern date. A String must be written as digits with an optional decimal fraction and anything else raises the new ParseError.

Horologium::Instant.from_julian_date("2456463.052272", scale: :tt)
Horologium::Instant.from_julian_date(2_456_463.0, 0.052272, scale: :tt)

from_modified_julian_date builds an instant from the Modified Julian Date, the Julian Date counted from a later origin. It takes the same shapes. Representations::ModifiedJulianDate reads an instant back in it.

instant = Horologium::Instant.from_modified_julian_date(60_796.0, scale: :tai)

instant.as(:modified_julian_date, scale: :tai)
# => 60796.0

This replaces `from_tai_julian_date` with `from_julian_date`, which reads
the Julian Date in a scale and stores the instant in TAI. A point given in
one scale can then be read back in another.

```rb
instant = Horologium::Instant.from_julian_date(2_443_144.5, scale: :tai)

instant.to(:tt).as(:julian_date)
# => 2443144.5003725
```

The Julian Date can be given in several shapes. A String and a Rational
give it exactly, a high and a low Float give it to about twice what one
Float holds, and a single Float is the lossy one, worth about 40
microseconds at a modern date. A String must be written as digits with an
optional decimal fraction, and anything else raises the new `ParseError`.

```rb
Horologium::Instant.from_julian_date("2456463.052272", scale: :tt)
Horologium::Instant.from_julian_date(2_456_463.0, 0.052272, scale: :tt)
```

`from_modified_julian_date` builds an instant from the Modified Julian
Date, the Julian Date counted from a later origin. It takes the same
shapes, and `Representations::ModifiedJulianDate` reads an instant back out
in it.

```rb
instant = Horologium::Instant.from_modified_julian_date(60_796.0, scale: :tai)

instant.as(:modified_julian_date, scale: :tai)
# => 60796.0
```

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates Horologium’s Instant construction APIs to accept Julian Date inputs expressed in an explicit scale (while storing internally in TAI), adds strict parsing for string inputs (with a new ParseError), and introduces Modified Julian Date support as both an input and an output representation.

Changes:

  • Replace Instant.from_tai_julian_date usage with Instant.from_julian_date(..., scale:), enabling cross-scale round-tripping.
  • Add strict Julian Date parsing for String/Rational/two-part floats, raising Horologium::ParseError for invalid strings.
  • Introduce Modified Julian Date (from_modified_julian_date + Representations::ModifiedJulianDate) and expose it via ScaleReading#as.

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
test/test_scale_reading.rb Updates scale reading tests to use from_julian_date and adds MJD readout coverage.
test/test_instant.rb Expands Instant construction tests for multi-shape Julian Date inputs, strict parsing, and MJD support.
test/test_error.rb Adds coverage that ParseError descends from Horologium::Error.
test/test_configuration.rb Updates configuration tests to build instants via from_julian_date(..., scale: :tai).
test/scales/test_tai.rb Updates TAI scale tests to use the new constructor.
test/representations/test_modified_julian_date.rb Adds new test suite for Modified Julian Date rendering/parsing.
test/representations/test_julian_date.rb Adds parsing tests for new Julian Date input shapes and error cases.
sig/horologium/scale_reading.rbs Extends representation map typing to include ModifiedJulianDate.
sig/horologium/representations/modified_julian_date.rbs Adds RBS signatures for the new MJD representation.
sig/horologium/representations/julian_date.rbs Extends RBS to include parsing API and helpers (needs type tightening for private helpers).
sig/horologium/instant.rbs Replaces old constructor signature with from_julian_date / from_modified_julian_date and shared types.
sig/horologium.rbs Adds ParseError to the public type surface.
README.md Updates public docs/examples to the new constructors and adds MJD examples + input-shape guidance.
lib/horologium/scales/tt.rb Updates TT docs/examples to use from_julian_date(..., scale:).
lib/horologium/scales/tai.rb Updates TAI docs/examples to use from_julian_date(..., scale:).
lib/horologium/scale_reading.rb Adds :modified_julian_date as a supported ScaleReading#as representation.
lib/horologium/representations/modified_julian_date.rb Implements Modified Julian Date render/parse and precision-specific offsets.
lib/horologium/representations/julian_date.rb Adds strict string parsing + multi-shape parsing entrypoint and shared render_value.
lib/horologium/instant.rb Introduces scale-aware from_julian_date and from_modified_julian_date constructors via a shared helper.
lib/horologium/error.rb Adds ParseError definition and documentation.
lib/horologium.rb Requires the new Modified Julian Date representation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/horologium/representations/julian_date.rb Outdated
Comment thread lib/horologium/representations/julian_date.rb Outdated
Comment thread lib/horologium/representations/julian_date.rb Outdated
Comment thread lib/horologium/instant.rb Outdated
Comment thread lib/horologium/instant.rb Outdated
Comment thread lib/horologium/instant.rb Outdated
Comment thread lib/horologium/representations/modified_julian_date.rb Outdated
Comment thread sig/horologium/representations/julian_date.rbs
@rhannequin
rhannequin merged commit 9238d03 into main Jul 21, 2026
44 checks passed
@rhannequin
rhannequin deleted the from-julian-date-in-a-scale branch July 21, 2026 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants