Build instants from a Julian Date read in a scale#12
Merged
Conversation
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
```
There was a problem hiding this comment.
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_dateusage withInstant.from_julian_date(..., scale:), enabling cross-scale round-tripping. - Add strict Julian Date parsing for
String/Rational/two-part floats, raisingHorologium::ParseErrorfor invalid strings. - Introduce Modified Julian Date (
from_modified_julian_date+Representations::ModifiedJulianDate) and expose it viaScaleReading#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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This replaces
from_tai_julian_datewithfrom_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.The Julian Date can be given in several shapes. A
Stringand aRationalgive it exactly, ahighand alowFloatgive it to about twice what oneFloatholds, and a singleFloatis worth about 40 microseconds at a modern date. AStringmust be written as digits with an optional decimal fraction and anything else raises the newParseError.from_modified_julian_datebuilds an instant from the Modified Julian Date, the Julian Date counted from a later origin. It takes the same shapes.Representations::ModifiedJulianDatereads an instant back in it.