siderust-js 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +166 -0
- package/.gitmodules +9 -0
- package/CHANGELOG.md +26 -0
- package/LICENSE +661 -0
- package/README.md +138 -0
- package/package.json +12 -0
- package/qtty-js/.github/workflows/ci.yml +151 -0
- package/qtty-js/.gitmodules +3 -0
- package/qtty-js/CHANGELOG.md +31 -0
- package/qtty-js/LICENSE +661 -0
- package/qtty-js/README.md +132 -0
- package/qtty-js/package.json +20 -0
- package/qtty-js/qtty/.github/workflows/ci.yml +155 -0
- package/qtty-js/qtty/CHANGELOG.md +120 -0
- package/qtty-js/qtty/Cargo.lock +1462 -0
- package/qtty-js/qtty/Cargo.toml +12 -0
- package/qtty-js/qtty/LICENSE +661 -0
- package/qtty-js/qtty/README.md +9 -0
- package/qtty-js/qtty/qtty/Cargo.toml +41 -0
- package/qtty-js/qtty/qtty/README.md +8 -0
- package/qtty-js/qtty/qtty/examples/angles.rs +14 -0
- package/qtty-js/qtty/qtty/examples/astronomy.rs +17 -0
- package/qtty-js/qtty/qtty/examples/dimensional_arithmetic.rs +83 -0
- package/qtty-js/qtty/qtty/examples/python_integration.rs +61 -0
- package/qtty-js/qtty/qtty/examples/quickstart.rs +15 -0
- package/qtty-js/qtty/qtty/examples/ratios.rs +12 -0
- package/qtty-js/qtty/qtty/examples/serde_with_unit.rs +234 -0
- package/qtty-js/qtty/qtty/examples/serialization.rs +141 -0
- package/qtty-js/qtty/qtty/examples/serialization_advanced.rs +155 -0
- package/qtty-js/qtty/qtty/src/f32.rs +108 -0
- package/qtty-js/qtty/qtty/src/f64.rs +30 -0
- package/qtty-js/qtty/qtty/src/i128.rs +111 -0
- package/qtty-js/qtty/qtty/src/i16.rs +111 -0
- package/qtty-js/qtty/qtty/src/i32.rs +111 -0
- package/qtty-js/qtty/qtty/src/i64.rs +111 -0
- package/qtty-js/qtty/qtty/src/i8.rs +111 -0
- package/qtty-js/qtty/qtty/src/lib.rs +238 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std/Cargo.lock +83 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std/Cargo.toml +10 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std/src/lib.rs +7 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std-alloc/Cargo.lock +83 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std-alloc/Cargo.toml +10 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std-alloc/src/lib.rs +7 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-std/Cargo.lock +83 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-std/Cargo.toml +10 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-std/src/lib.rs +5 -0
- package/qtty-js/qtty/qtty/tests/integration_tests.rs +529 -0
- package/qtty-js/qtty/qtty/tests/qtty_vec_feature_matrix.rs +58 -0
- package/qtty-js/qtty/qtty-core/Cargo.toml +41 -0
- package/qtty-js/qtty/qtty-core/README.md +8 -0
- package/qtty-js/qtty/qtty-core/examples/diesel_integration.rs +145 -0
- package/qtty-js/qtty/qtty-core/examples/quantity_db_serde.rs +215 -0
- package/qtty-js/qtty/qtty-core/src/dimension.rs +249 -0
- package/qtty-js/qtty/qtty-core/src/feature_diesel.rs +318 -0
- package/qtty-js/qtty/qtty-core/src/feature_pyo3.rs +27 -0
- package/qtty-js/qtty/qtty-core/src/feature_serde.rs +203 -0
- package/qtty-js/qtty/qtty-core/src/feature_tiberius.rs +28 -0
- package/qtty-js/qtty/qtty-core/src/lib.rs +744 -0
- package/qtty-js/qtty/qtty-core/src/macros.rs +93 -0
- package/qtty-js/qtty/qtty-core/src/quantity.rs +810 -0
- package/qtty-js/qtty/qtty-core/src/scalar.rs +1742 -0
- package/qtty-js/qtty/qtty-core/src/unit.rs +332 -0
- package/qtty-js/qtty/qtty-core/src/units/angular.rs +1228 -0
- package/qtty-js/qtty/qtty-core/src/units/area.rs +243 -0
- package/qtty-js/qtty/qtty-core/src/units/frequency.rs +179 -0
- package/qtty-js/qtty/qtty-core/src/units/length.rs +1270 -0
- package/qtty-js/qtty/qtty-core/src/units/mass.rs +488 -0
- package/qtty-js/qtty/qtty-core/src/units/mod.rs +26 -0
- package/qtty-js/qtty/qtty-core/src/units/power.rs +324 -0
- package/qtty-js/qtty/qtty-core/src/units/time.rs +667 -0
- package/qtty-js/qtty/qtty-core/src/units/unitless.rs +212 -0
- package/qtty-js/qtty/qtty-core/src/units/velocity.rs +210 -0
- package/qtty-js/qtty/qtty-core/src/units/volume.rs +269 -0
- package/qtty-js/qtty/qtty-core/tests/core.rs +628 -0
- package/qtty-js/qtty/qtty-core/tests/diesel.rs +461 -0
- package/qtty-js/qtty/qtty-core/tests/integers.rs +632 -0
- package/qtty-js/qtty/qtty-core/tests/no_cross_unit_ops.rs +35 -0
- package/qtty-js/qtty/qtty-core/tests/pyo3.rs +334 -0
- package/qtty-js/qtty/qtty-core/tests/quantity_f32.rs +276 -0
- package/qtty-js/qtty/qtty-core/tests/scalar_decimal.rs +258 -0
- package/qtty-js/qtty/qtty-core/tests/scalar_f32.rs +286 -0
- package/qtty-js/qtty/qtty-core/tests/scalar_f64_real.rs +287 -0
- package/qtty-js/qtty/qtty-core/tests/scalar_rational.rs +260 -0
- package/qtty-js/qtty/qtty-core/tests/serde.rs +256 -0
- package/qtty-js/qtty/qtty-core/tests/tiberius.rs +208 -0
- package/qtty-js/qtty/qtty-derive/Cargo.toml +23 -0
- package/qtty-js/qtty/qtty-derive/README.md +8 -0
- package/qtty-js/qtty/qtty-derive/src/lib.rs +340 -0
- package/qtty-js/qtty/qtty-ffi/ARCHITECTURE.md +3 -0
- package/qtty-js/qtty/qtty-ffi/Cargo.toml +31 -0
- package/qtty-js/qtty/qtty-ffi/README.md +9 -0
- package/qtty-js/qtty/qtty-ffi/build.rs +326 -0
- package/qtty-js/qtty/qtty-ffi/cbindgen.toml +105 -0
- package/qtty-js/qtty/qtty-ffi/include/qtty_ffi.h +1126 -0
- package/qtty-js/qtty/qtty-ffi/src/ffi.rs +1251 -0
- package/qtty-js/qtty/qtty-ffi/src/ffi_serde.rs +294 -0
- package/qtty-js/qtty/qtty-ffi/src/helpers.rs +310 -0
- package/qtty-js/qtty/qtty-ffi/src/lib.rs +229 -0
- package/qtty-js/qtty/qtty-ffi/src/macros.rs +121 -0
- package/qtty-js/qtty/qtty-ffi/src/registry.rs +274 -0
- package/qtty-js/qtty/qtty-ffi/src/types.rs +620 -0
- package/qtty-js/qtty/qtty-ffi/tests/integration_tests.rs +842 -0
- package/qtty-js/qtty/qtty-ffi/units.csv +156 -0
- package/qtty-js/qtty/qtty-ffi/units.csv.md +3 -0
- package/qtty-js/qtty-node/.prettierignore +6 -0
- package/qtty-js/qtty-node/.prettierrc.json +6 -0
- package/qtty-js/qtty-node/README.md +250 -0
- package/qtty-js/qtty-node/c8.config.json +11 -0
- package/qtty-js/qtty-node/eslint.config.js +31 -0
- package/qtty-js/qtty-node/examples/arithmetic.mjs +64 -0
- package/qtty-js/qtty-node/examples/astronomy.mjs +90 -0
- package/qtty-js/qtty-node/examples/quickstart.mjs +36 -0
- package/qtty-js/qtty-node/examples/serialization.mjs +125 -0
- package/qtty-js/qtty-node/examples/unit_factories.mjs +74 -0
- package/qtty-js/qtty-node/index.d.ts +219 -0
- package/qtty-js/qtty-node/index.js +323 -0
- package/qtty-js/qtty-node/lib/DerivedQuantity.js +122 -0
- package/qtty-js/qtty-node/lib/Quantity.js +151 -0
- package/qtty-js/qtty-node/lib/backend.js +25 -0
- package/qtty-js/qtty-node/native.cjs +306 -0
- package/qtty-js/qtty-node/package-lock.json +3223 -0
- package/qtty-js/qtty-node/package.json +70 -0
- package/qtty-js/qtty-node/units.d.ts +299 -0
- package/qtty-js/qtty-node/units.js +210 -0
- package/qtty-js/qtty-web/Cargo.lock +767 -0
- package/qtty-js/qtty-web/Cargo.toml +21 -0
- package/qtty-js/qtty-web/index.d.ts +140 -0
- package/qtty-js/qtty-web/index.js +20 -0
- package/qtty-js/qtty-web/lib/DerivedQuantity.js +58 -0
- package/qtty-js/qtty-web/lib/Quantity.js +75 -0
- package/qtty-js/qtty-web/lib/backend.js +80 -0
- package/qtty-js/qtty-web/package.json +45 -0
- package/qtty-js/qtty-web/src/lib.rs +111 -0
- package/qtty-js/scripts/ci.sh +73 -0
- package/scripts/ci.sh +123 -0
- package/siderust-core/Cargo.lock +787 -0
- package/siderust-core/Cargo.toml +18 -0
- package/siderust-core/DEDUPLICATION.md +124 -0
- package/siderust-core/src/body.rs +120 -0
- package/siderust-core/src/events.rs +184 -0
- package/siderust-core/src/lib.rs +20 -0
- package/siderust-core/src/observer.rs +55 -0
- package/siderust-core/src/position.rs +213 -0
- package/siderust-node/.prettierignore +7 -0
- package/siderust-node/.prettierrc.json +6 -0
- package/siderust-node/Cargo.lock +906 -0
- package/siderust-node/Cargo.toml +29 -0
- package/siderust-node/README.md +109 -0
- package/siderust-node/__test__/index.test.mjs +248 -0
- package/siderust-node/build.rs +5 -0
- package/siderust-node/c8.config.json +3 -0
- package/siderust-node/eslint.config.js +31 -0
- package/siderust-node/examples/01_basic_coordinates.mjs +24 -0
- package/siderust-node/examples/02_coordinate_transformations.mjs +25 -0
- package/siderust-node/examples/03_all_frames_conversions.mjs +26 -0
- package/siderust-node/examples/04_all_center_conversions.mjs +24 -0
- package/siderust-node/examples/05_target_tracking.mjs +22 -0
- package/siderust-node/examples/06_night_events.mjs +18 -0
- package/siderust-node/examples/07_moon_properties.mjs +21 -0
- package/siderust-node/examples/08_solar_system.mjs +19 -0
- package/siderust-node/examples/09_star_observability.mjs +22 -0
- package/siderust-node/examples/10_time_periods.mjs +9 -0
- package/siderust-node/examples/11_serialization.mjs +31 -0
- package/siderust-node/examples/12_runtime_ephemeris.mjs +27 -0
- package/siderust-node/examples/13_coordinate_operations.mjs +20 -0
- package/siderust-node/index.d.ts +623 -0
- package/siderust-node/index.js +79 -0
- package/siderust-node/lib/Observer.js +112 -0
- package/siderust-node/lib/Star.js +118 -0
- package/siderust-node/lib/backend.js +63 -0
- package/siderust-node/lib/wrappers.js +566 -0
- package/siderust-node/main.js +20 -0
- package/siderust-node/native.cjs +360 -0
- package/siderust-node/package-lock.json +3261 -0
- package/siderust-node/package.json +71 -0
- package/siderust-node/src/body.rs +74 -0
- package/siderust-node/src/coordinates.rs +372 -0
- package/siderust-node/src/ephemeris.rs +462 -0
- package/siderust-node/src/events.rs +577 -0
- package/siderust-node/src/lib.rs +43 -0
- package/siderust-node/src/observer.rs +132 -0
- package/siderust-node/src/phase.rs +218 -0
- package/siderust-node/src/position.rs +292 -0
- package/siderust-node/src/star.rs +200 -0
- package/siderust-web/Cargo.lock +855 -0
- package/siderust-web/Cargo.toml +34 -0
- package/siderust-web/README.md +100 -0
- package/siderust-web/__test__/index.test.mjs +118 -0
- package/siderust-web/examples/github-pages/README.md +31 -0
- package/siderust-web/examples/github-pages/index.html +135 -0
- package/siderust-web/index.d.ts +311 -0
- package/siderust-web/index.js +66 -0
- package/siderust-web/lib/Observer.js +103 -0
- package/siderust-web/lib/Star.js +116 -0
- package/siderust-web/lib/backend.js +400 -0
- package/siderust-web/lib/wrappers.js +512 -0
- package/siderust-web/package.json +55 -0
- package/siderust-web/src/body.rs +69 -0
- package/siderust-web/src/coordinates.rs +302 -0
- package/siderust-web/src/ephemeris.rs +456 -0
- package/siderust-web/src/events.rs +520 -0
- package/siderust-web/src/lib.rs +51 -0
- package/siderust-web/src/observer.rs +117 -0
- package/siderust-web/src/phase.rs +190 -0
- package/siderust-web/src/position.rs +291 -0
- package/siderust-web/src/star.rs +178 -0
- package/tempoch-js/.github/workflows/ci.yml +142 -0
- package/tempoch-js/.gitmodules +3 -0
- package/tempoch-js/CHANGELOG.md +25 -0
- package/tempoch-js/LICENSE +661 -0
- package/tempoch-js/README.md +126 -0
- package/tempoch-js/package.json +20 -0
- package/tempoch-js/scripts/ci.sh +73 -0
- package/tempoch-js/tempoch/.github/workflows/ci.yml +113 -0
- package/tempoch-js/tempoch/CHANGELOG.md +82 -0
- package/tempoch-js/tempoch/Cargo.lock +947 -0
- package/tempoch-js/tempoch/Cargo.toml +3 -0
- package/tempoch-js/tempoch/LICENSE +661 -0
- package/tempoch-js/tempoch/README.md +76 -0
- package/tempoch-js/tempoch/tempoch/Cargo.toml +27 -0
- package/tempoch-js/tempoch/tempoch/examples/periods.rs +45 -0
- package/tempoch-js/tempoch/tempoch/examples/quickstart.rs +13 -0
- package/tempoch-js/tempoch/tempoch/src/lib.rs +49 -0
- package/tempoch-js/tempoch/tempoch/tests/integration.rs +57 -0
- package/tempoch-js/tempoch/tempoch-core/Cargo.toml +24 -0
- package/tempoch-js/tempoch/tempoch-core/src/delta_t.rs +345 -0
- package/tempoch-js/tempoch/tempoch-core/src/instant.rs +811 -0
- package/tempoch-js/tempoch/tempoch-core/src/julian_date_ext.rs +142 -0
- package/tempoch-js/tempoch/tempoch-core/src/lib.rs +81 -0
- package/tempoch-js/tempoch/tempoch-core/src/period.rs +1168 -0
- package/tempoch-js/tempoch/tempoch-core/src/scales.rs +779 -0
- package/tempoch-js/tempoch/tempoch-ffi/Cargo.lock +889 -0
- package/tempoch-js/tempoch/tempoch-ffi/Cargo.toml +26 -0
- package/tempoch-js/tempoch/tempoch-ffi/build.rs +24 -0
- package/tempoch-js/tempoch/tempoch-ffi/cbindgen.toml +30 -0
- package/tempoch-js/tempoch/tempoch-ffi/src/error.rs +19 -0
- package/tempoch-js/tempoch/tempoch-ffi/src/lib.rs +82 -0
- package/tempoch-js/tempoch/tempoch-ffi/src/period.rs +101 -0
- package/tempoch-js/tempoch/tempoch-ffi/src/time.rs +711 -0
- package/tempoch-js/tempoch/tempoch-ffi/tests/ffi.rs +265 -0
- package/tempoch-js/tempoch-node/.prettierignore +6 -0
- package/tempoch-js/tempoch-node/.prettierrc.json +6 -0
- package/tempoch-js/tempoch-node/Cargo.lock +496 -0
- package/tempoch-js/tempoch-node/Cargo.toml +29 -0
- package/tempoch-js/tempoch-node/README.md +265 -0
- package/tempoch-js/tempoch-node/__test__/index.test.mjs +598 -0
- package/tempoch-js/tempoch-node/build.rs +5 -0
- package/tempoch-js/tempoch-node/c8.config.json +3 -0
- package/tempoch-js/tempoch-node/eslint.config.js +31 -0
- package/tempoch-js/tempoch-node/examples/periods.mjs +79 -0
- package/tempoch-js/tempoch-node/examples/quickstart.mjs +71 -0
- package/tempoch-js/tempoch-node/examples/timescales.mjs +92 -0
- package/tempoch-js/tempoch-node/index.d.ts +280 -0
- package/tempoch-js/tempoch-node/index.js +32 -0
- package/tempoch-js/tempoch-node/lib/JulianDate.js +176 -0
- package/tempoch-js/tempoch-node/lib/ModifiedJulianDate.js +156 -0
- package/tempoch-js/tempoch-node/lib/Period.js +133 -0
- package/tempoch-js/tempoch-node/lib/backend.js +38 -0
- package/tempoch-js/tempoch-node/lib/qttyCompat.js +92 -0
- package/tempoch-js/tempoch-node/native.cjs +317 -0
- package/tempoch-js/tempoch-node/package-lock.json +3223 -0
- package/tempoch-js/tempoch-node/package.json +56 -0
- package/tempoch-js/tempoch-node/src/lib.rs +573 -0
- package/tempoch-js/tempoch-web/Cargo.toml +23 -0
- package/tempoch-js/tempoch-web/index.d.ts +95 -0
- package/tempoch-js/tempoch-web/index.js +27 -0
- package/tempoch-js/tempoch-web/lib/JulianDate.js +170 -0
- package/tempoch-js/tempoch-web/lib/ModifiedJulianDate.js +145 -0
- package/tempoch-js/tempoch-web/lib/Period.js +121 -0
- package/tempoch-js/tempoch-web/lib/backend.js +118 -0
- package/tempoch-js/tempoch-web/package.json +46 -0
- package/tempoch-js/tempoch-web/src/lib.rs +184 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
+
// Copyright (C) 2026 Vallés Puig, Ramon
|
|
3
|
+
|
|
4
|
+
//! Julian Date (`Time<JD>`) specific extensions.
|
|
5
|
+
|
|
6
|
+
use qtty::*;
|
|
7
|
+
use std::ops::Add;
|
|
8
|
+
|
|
9
|
+
use super::instant::Time;
|
|
10
|
+
use super::scales::{JD, MJD};
|
|
11
|
+
|
|
12
|
+
impl Time<JD> {
|
|
13
|
+
/// J2000.0 epoch: 2000-01-01T12:00:00 TT (JD 2 451 545.0).
|
|
14
|
+
pub const J2000: Self = Self::new(2_451_545.0);
|
|
15
|
+
|
|
16
|
+
/// One Julian year expressed in days.
|
|
17
|
+
pub const JULIAN_YEAR: Days = Days::new(365.25);
|
|
18
|
+
|
|
19
|
+
/// One Julian century expressed in days.
|
|
20
|
+
pub const JULIAN_CENTURY: Days = Days::new(36_525.0);
|
|
21
|
+
|
|
22
|
+
/// One Julian millennium expressed in days.
|
|
23
|
+
pub const JULIAN_MILLENNIUM: Days = Days::new(365_250.0);
|
|
24
|
+
|
|
25
|
+
/// Julian millennia since J2000.0 (used by VSOP87).
|
|
26
|
+
#[inline]
|
|
27
|
+
pub fn julian_millennias(&self) -> Millennia {
|
|
28
|
+
Millennia::new(
|
|
29
|
+
((*self - Self::J2000) / Self::JULIAN_MILLENNIUM)
|
|
30
|
+
.simplify()
|
|
31
|
+
.value(),
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/// Julian centuries since J2000.0 (used by nutation, precession, sidereal time).
|
|
36
|
+
#[inline]
|
|
37
|
+
pub fn julian_centuries(&self) -> Centuries {
|
|
38
|
+
Centuries::new(
|
|
39
|
+
((*self - Self::J2000) / Self::JULIAN_CENTURY)
|
|
40
|
+
.simplify()
|
|
41
|
+
.value(),
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/// Julian years since J2000.0.
|
|
46
|
+
#[inline]
|
|
47
|
+
pub fn julian_years(&self) -> JulianYears {
|
|
48
|
+
JulianYears::new(
|
|
49
|
+
((*self - Self::J2000) / Self::JULIAN_YEAR)
|
|
50
|
+
.simplify()
|
|
51
|
+
.value(),
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/// Converts JD(TT) → JD(TDB) using the Fairhead & Bretagnon (1990)
|
|
56
|
+
/// expression for `TDB − TT`.
|
|
57
|
+
///
|
|
58
|
+
/// The dominant term has an amplitude of ≈1.658 ms. This implementation
|
|
59
|
+
/// includes the four largest periodic terms plus a secular component,
|
|
60
|
+
/// matching the formula recommended by USNO Circular 179 (Kaplan 2005)
|
|
61
|
+
/// and consistent with IAU 2006 Resolution B3.
|
|
62
|
+
///
|
|
63
|
+
/// Accuracy: better than 30 μs for dates within ±10 000 years of J2000.
|
|
64
|
+
///
|
|
65
|
+
/// ## References
|
|
66
|
+
/// * Fairhead & Bretagnon (1990), A&A 229, 240
|
|
67
|
+
/// * USNO Circular 179, eq. 2.6
|
|
68
|
+
/// * SOFA `iauDtdb` (full implementation has hundreds of terms)
|
|
69
|
+
pub fn tt_to_tdb(jd_tt: Self) -> Self {
|
|
70
|
+
jd_tt + super::scales::tdb_minus_tt_days(jd_tt.quantity())
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/// Convenience: MJD value corresponding to this JD.
|
|
74
|
+
///
|
|
75
|
+
/// Kept as a convenience wrapper for `self.to::<MJD>()`.
|
|
76
|
+
#[inline]
|
|
77
|
+
pub fn to_mjd(&self) -> Time<MJD> {
|
|
78
|
+
self.to::<MJD>()
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// ── From / Into conversions for qtty time quantities (on JD only) ────────
|
|
83
|
+
|
|
84
|
+
impl Add<Years> for Time<JD> {
|
|
85
|
+
type Output = Self;
|
|
86
|
+
fn add(self, years: Years) -> Self {
|
|
87
|
+
// Treat `Years` here as Julian years for JD arithmetic stability.
|
|
88
|
+
self + Days::new(years.value() * Self::JULIAN_YEAR.value())
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
impl From<JulianYears> for Time<JD> {
|
|
93
|
+
fn from(years: JulianYears) -> Self {
|
|
94
|
+
Self::J2000 + years.to::<Day>()
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
impl From<Time<JD>> for JulianYears {
|
|
99
|
+
fn from(jd: Time<JD>) -> Self {
|
|
100
|
+
jd.julian_years()
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
impl From<Centuries> for Time<JD> {
|
|
105
|
+
fn from(centuries: Centuries) -> Self {
|
|
106
|
+
// `Centuries` are interpreted as Julian centuries relative to J2000.
|
|
107
|
+
Self::J2000 + Days::new(centuries.value() * Self::JULIAN_CENTURY.value())
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
impl From<Time<JD>> for Centuries {
|
|
112
|
+
fn from(jd: Time<JD>) -> Self {
|
|
113
|
+
jd.julian_centuries()
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
impl From<Millennia> for Time<JD> {
|
|
118
|
+
fn from(millennia: Millennia) -> Self {
|
|
119
|
+
// `Millennia` are interpreted as Julian millennia relative to J2000.
|
|
120
|
+
Self::J2000 + Days::new(millennia.value() * Self::JULIAN_MILLENNIUM.value())
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
impl From<Time<JD>> for Millennia {
|
|
125
|
+
fn from(jd: Time<JD>) -> Self {
|
|
126
|
+
jd.julian_millennias()
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
#[cfg(test)]
|
|
131
|
+
mod tests {
|
|
132
|
+
use crate::{Time, JD, MJD};
|
|
133
|
+
|
|
134
|
+
#[test]
|
|
135
|
+
fn to_mjd_convenience_matches_to_generic() {
|
|
136
|
+
// to_mjd() is a convenience wrapper for .to::<MJD>().
|
|
137
|
+
let jd = Time::<JD>::J2000;
|
|
138
|
+
let via_convenience = jd.to_mjd();
|
|
139
|
+
let via_generic = jd.to::<MJD>();
|
|
140
|
+
assert_eq!(via_convenience.value(), via_generic.value());
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
+
// Copyright (C) 2026 Vallés Puig, Ramon
|
|
3
|
+
|
|
4
|
+
//! Time Module
|
|
5
|
+
//!
|
|
6
|
+
//! This module provides time-related types and abstractions for astronomical calculations.
|
|
7
|
+
//!
|
|
8
|
+
//! # Core types
|
|
9
|
+
//!
|
|
10
|
+
//! - [`Time<S>`] — generic instant parameterised by a [`TimeScale`] marker.
|
|
11
|
+
//! - [`TimeScale`] — trait that defines a time scale (epoch offset + conversions).
|
|
12
|
+
//! - [`JulianDate`] — type alias for `Time<JD>`.
|
|
13
|
+
//! - [`JulianEphemerisDay`] — type alias for `Time<JDE>`.
|
|
14
|
+
//! - [`ModifiedJulianDate`] — type alias for `Time<MJD>`.
|
|
15
|
+
//! - [`Period<S>`] — a time interval parameterised by a [`TimeScale`] marker.
|
|
16
|
+
//! - [`Interval<T>`] — a generic interval over any [`TimeInstant`].
|
|
17
|
+
//! - [`TimeInstant`] — trait for points in time usable with [`Interval`].
|
|
18
|
+
//!
|
|
19
|
+
//! # Time scales
|
|
20
|
+
//!
|
|
21
|
+
//! The following markers implement [`TimeScale`]:
|
|
22
|
+
//!
|
|
23
|
+
//! | Marker | Scale |
|
|
24
|
+
//! |--------|-------|
|
|
25
|
+
//! | [`JD`] | Julian Date |
|
|
26
|
+
//! | [`JDE`] | Julian Ephemeris Day |
|
|
27
|
+
//! | [`MJD`] | Modified Julian Date |
|
|
28
|
+
//! | [`TDB`] | Barycentric Dynamical Time |
|
|
29
|
+
//! | [`TT`] | Terrestrial Time |
|
|
30
|
+
//! | [`TAI`] | International Atomic Time |
|
|
31
|
+
//! | [`TCG`] | Geocentric Coordinate Time |
|
|
32
|
+
//! | [`TCB`] | Barycentric Coordinate Time |
|
|
33
|
+
//! | [`GPS`] | GPS Time |
|
|
34
|
+
//! | [`UnixTime`] | Unix / POSIX time |
|
|
35
|
+
//! | [`UT`] | Universal Time (Earth rotation) |
|
|
36
|
+
//!
|
|
37
|
+
//! # ΔT (Delta T)
|
|
38
|
+
//!
|
|
39
|
+
//! The difference **ΔT = TT − UT** is applied automatically by the
|
|
40
|
+
//! [`UT`] time scale. Use `Time::<UT>::new(jd_ut)` for UT-based values,
|
|
41
|
+
//! or construct any scale via `from_utc()` which routes through `UT` internally.
|
|
42
|
+
//! The raw ΔT value (in seconds) is available via [`Time::<UT>::delta_t()`](Time::delta_t).
|
|
43
|
+
|
|
44
|
+
mod delta_t;
|
|
45
|
+
pub(crate) mod instant;
|
|
46
|
+
mod julian_date_ext;
|
|
47
|
+
mod period;
|
|
48
|
+
mod scales;
|
|
49
|
+
|
|
50
|
+
// ── Re-exports ────────────────────────────────────────────────────────────
|
|
51
|
+
|
|
52
|
+
pub use instant::{NonFiniteTimeError, Time, TimeInstant, TimeScale};
|
|
53
|
+
pub use period::{
|
|
54
|
+
complement_within, intersect_periods, normalize_periods, validate_period_list, ConversionError,
|
|
55
|
+
Interval, InvalidIntervalError, Period, PeriodListError, UtcPeriod,
|
|
56
|
+
};
|
|
57
|
+
pub use scales::{tai_minus_utc, UnixTime, GPS, JD, JDE, MJD, TAI, TCB, TCG, TDB, TT, UT};
|
|
58
|
+
|
|
59
|
+
// ── Backward-compatible type aliases ──────────────────────────────────────
|
|
60
|
+
|
|
61
|
+
/// Julian Date — continuous count of days since the Julian Period.
|
|
62
|
+
///
|
|
63
|
+
/// This is a type alias for [`Time<JD>`]. All historical call-sites
|
|
64
|
+
/// (`JulianDate::new(...)`, `JulianDate::J2000`, `.julian_centuries()`, …)
|
|
65
|
+
/// continue to work without modification.
|
|
66
|
+
pub type JulianDate = Time<JD>;
|
|
67
|
+
|
|
68
|
+
/// Julian Ephemeris Day — dynamical Julian day used by many ephemeris formulas.
|
|
69
|
+
///
|
|
70
|
+
/// This is a type alias for [`Time<JDE>`].
|
|
71
|
+
pub type JulianEphemerisDay = Time<JDE>;
|
|
72
|
+
|
|
73
|
+
/// Modified Julian Date — `JD − 2 400 000.5`.
|
|
74
|
+
///
|
|
75
|
+
/// This is a type alias for [`Time<MJD>`].
|
|
76
|
+
pub type ModifiedJulianDate = Time<MJD>;
|
|
77
|
+
|
|
78
|
+
/// Universal Time — Earth-rotation civil time scale.
|
|
79
|
+
///
|
|
80
|
+
/// This is a type alias for [`Time<UT>`].
|
|
81
|
+
pub type UniversalTime = Time<UT>;
|