Skip to content

Add Astronoby::Duration#281

Merged
rhannequin merged 2 commits into
mainfrom
add-duration-value-object
Jun 26, 2026
Merged

Add Astronoby::Duration#281
rhannequin merged 2 commits into
mainfrom
add-duration-value-object

Conversation

@rhannequin

Copy link
Copy Markdown
Owner

Durations show up in the library here and there, but until now they were handed back to the caller as raw integers of seconds. Every other physical quantity Astronoby returns already has its own value object (Angle, Distance, Velocity, AngularVelocity), so a length of time coming back as a bare Integer was the odd one out.

This introduces a new value object for handling durations: Astronoby::Duration.

It can be initialized with seconds, minutes, hours and days, while the duration is always stored in seconds, the international unit for time. A reader is available for each unit (#seconds, #minutes, #hours, #days), so the call site can ask for whatever unit reads best.

As a regular value object, it is immutable, handles comparison with other Astronoby::Duration objects, and can be used in some arithmetic operations with the + and - operators. It also has #abs, #positive?, #negative? and #zero?, which are handy for signed durations like the equation of time.

In the library, the two places that returned a length of time have been converted to this new value object, with breaking changes:

  • Astronoby::EclipsePhase#duration now returns a Astronoby::Duration
  • Astronoby::Sun#equation_of_time now returns a Astronoby::Duration

Both used to return an Integer of seconds, so a caller relying on that now needs .seconds to get the same value back.

I deliberately kept it to these two. The orbital, synodic and lunar periods, the Delta T offset and the various time-scale conversions are durations conceptually too, but they are internal constants and implementation details that get divided and reciprocated in the math, never handed back to a user. Wrapping them would only add ceremony in hot loops, so they stay raw numbers.

one_minute = Astronoby::Duration.from_minutes(1)
ninety_seconds = Astronoby::Duration.from_seconds(90)

one_minute < ninety_seconds
# => true

sum = one_minute + ninety_seconds
sum.seconds
# => 150

sum.minutes
# => 2.5

And how it reads at the call sites now:

eclipse.total.duration.minutes
# => 65.5

sun.equation_of_time.seconds
# => -185

@rhannequin rhannequin self-assigned this Jun 24, 2026
@rhannequin
rhannequin force-pushed the add-lunar-eclipses branch from 78cfcf9 to b264d73 Compare June 24, 2026 14:15
@rhannequin
rhannequin force-pushed the add-duration-value-object branch from ba7f9b6 to 4980a42 Compare June 24, 2026 14:15
@rhannequin rhannequin mentioned this pull request Jun 24, 2026
Base automatically changed from add-lunar-eclipses to main June 26, 2026 08:31
@rhannequin
rhannequin force-pushed the add-duration-value-object branch from 838cb90 to 78719e7 Compare June 26, 2026 08:34
@rhannequin
rhannequin merged commit 4182759 into main Jun 26, 2026
44 checks passed
@rhannequin
rhannequin deleted the add-duration-value-object branch June 26, 2026 08:37
rhannequin added a commit that referenced this pull request Jun 26, 2026
## 0.10.0 - 2026-06-26

_If you are upgrading: please see [UPGRADING.md]._

### Bug fixes

* Fix constant name typo ([#245])
* Fix matrix multiplication order in Apparent frame ([#250])
* Remove spurious N·P from observer ECEF-to-TOD transformation ([#251])
* Apply aberration in GCRS before precession/nutation rotation ([#253])
* Fix Moon magnitude ([#254])
* Fix astrometric position for Deep Sky Objects ([#272])

### Features

* Defer Solar System body computations lazily ([#244])
* Integrate `iers` gem for Delta T and GMST ([#249])
* Add IERS polar motion correction to observer ECEF-to-TOD transformation ([#252])
* Fall back to polynomial GMST for dates outside IERS EOP range ([#255])
* Add ICRS frame bias to precession matrix ([#257])
* Extract `EarthRotation` class from `Observer` ([#260])
* Add TEME reference frame for satellite tracking ([#261])
* Add ECEF to geodetic conversion (WGS-84) ([#262])
* Memoize per-instant conversions on `Instant` ([#268])
* Add `ReferenceFrame#separation_from` for angular separation ([#269])
* Introduce `Center`, `Body` and `Position` domain objects ([#270])
* Add planetary phenomena ([#271])
* Add lunar libration, position angle of axis and bright limb ([#273])
* Add `Astronoby::Orientation` for arcsecond lunar libration ([#279])
* Add Lunar eclipses ([#280])
* Add `Astronoby::Duration` ([#281])

### Improvements

* Optimize nutation loop by eliminating array allocations ([#246])
* Reuse single Nutation instance in observer matrix computation ([#247])
* Memoize Observer geodetic computation methods ([#248])
* Update documentation with recent values ([#256])
* Update referential frames documentation ([#258])
* YARD documentation update ([#259])
* Update zlib, JSON and ERB for security reasons
* Add references to README
* Bump actions/checkout from 5 to 7 by @dependabot ([#239], [#276])
* Bump rubyzip from 3.2.1 to 3.4.0 by @dependabot ([#237], [#267], [#275])
* Bump irb from 1.15.2 to 1.17.0 by @dependabot ([#242])
* Bump standard from 1.51.1 to 1.55.0 by @dependabot ([#243], [#274])
* Bump rake from 13.3.1 to 13.4.2 by @dependabot ([#264])
* Bump ephem from 0.4.1 to 0.5.0 by @dependabot ([#278])
* Upgrade default Ruby to 4.0.5 ([#277])

### Backward-incompatible changes

* Minimum Ruby version bumped to 3.2.0 ([#249])
* Delta T and GMST now use IERS data ([#249])
* Defer Solar System body computations lazily ([#244])
* `SolarSystemBody#ephem` is now publicly accessible ([#244])
* `ReferenceFrame#center_identifier` replaced by `#center` ([#270])
* `Sun#equation_of_time` now returns a `Duration` ([#281])

**Full Changelog**: v0.9.0...v0.10.0

[#237]: #237
[#239]: #239
[#242]: #242
[#243]: #243
[#244]: #244
[#245]: #245
[#246]: #246
[#247]: #247
[#248]: #248
[#249]: #249
[#250]: #250
[#251]: #251
[#252]: #252
[#253]: #253
[#254]: #254
[#255]: #255
[#256]: #256
[#257]: #257
[#258]: #258
[#259]: #259
[#260]: #260
[#261]: #261
[#262]: #262
[#264]: #264
[#267]: #267
[#268]: #268
[#269]: #269
[#270]: #270
[#271]: #271
[#272]: #272
[#273]: #273
[#274]: #274
[#275]: #275
[#276]: #276
[#277]: #277
[#278]: #278
[#279]: #279
[#280]: #280
[#281]: #281
[UPGRADING.md]: https://github.com/rhannequin/astronoby/blob/main/UPGRADING.md
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.

1 participant