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,265 @@
|
|
|
1
|
+
# @siderust/tempoch
|
|
2
|
+
|
|
3
|
+
**Astronomical time primitives for Node.js — powered by Rust.**
|
|
4
|
+
|
|
5
|
+
`@siderust/tempoch` wraps the [`tempoch`](https://github.com/Siderust/tempoch)
|
|
6
|
+
Rust crate via [napi-rs](https://napi.rs) to provide:
|
|
7
|
+
|
|
8
|
+
- **Julian Date** (`JulianDate`) and **Modified Julian Date** (`ModifiedJulianDate`)
|
|
9
|
+
with precise UTC ↔ JD conversion including the ΔT (TT − UT) correction.
|
|
10
|
+
- **Period** — a half-open time interval `[start, end)` with duration, containment,
|
|
11
|
+
and intersection queries.
|
|
12
|
+
- **Free functions** for scalar conversions and epoch arithmetic.
|
|
13
|
+
- **TypeScript declarations** (auto-generated by napi-rs).
|
|
14
|
+
|
|
15
|
+
All time logic lives in Rust; the JS/TS layer is a thin ergonomic façade.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Quick start
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
const { JulianDate, ModifiedJulianDate, Period } = require('@siderust/tempoch');
|
|
23
|
+
|
|
24
|
+
// Construct from raw value
|
|
25
|
+
const jd = new JulianDate(2_451_545.0);
|
|
26
|
+
console.log(jd.value); // 2451545
|
|
27
|
+
console.log(jd.julianCenturies()); // 0 (J2000.0)
|
|
28
|
+
|
|
29
|
+
// Construct from a JavaScript Date
|
|
30
|
+
const jd2 = JulianDate.fromDate(new Date('2025-06-21T00:00:00Z'));
|
|
31
|
+
console.log(jd2.toMjd().value.toFixed(2)); // ~61027.50
|
|
32
|
+
|
|
33
|
+
// Round-trip to UTC
|
|
34
|
+
const back = jd2.toDate();
|
|
35
|
+
console.log(back.toISOString());
|
|
36
|
+
|
|
37
|
+
// Free conversion functions
|
|
38
|
+
const { jdToMjd, julianCenturies } = require('@siderust/tempoch');
|
|
39
|
+
console.log(jdToMjd(2_451_545.0)); // 51544.5
|
|
40
|
+
console.log(julianCenturies(2_451_545.0)); // 0
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
// TypeScript
|
|
45
|
+
import {
|
|
46
|
+
JulianDate,
|
|
47
|
+
ModifiedJulianDate,
|
|
48
|
+
Period,
|
|
49
|
+
jdToMjd,
|
|
50
|
+
julianCenturies,
|
|
51
|
+
} from '@siderust/tempoch';
|
|
52
|
+
|
|
53
|
+
const jd: JulianDate = JulianDate.j2000();
|
|
54
|
+
const t: number = jd.julianCenturies(); // 0
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Installation
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
npm install @siderust/tempoch
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
The package ships a pre-built native addon for the current platform.
|
|
66
|
+
To build from source, see [Building from source](#building-from-source).
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## API
|
|
71
|
+
|
|
72
|
+
### `JulianDate`
|
|
73
|
+
|
|
74
|
+
Continuous day count since the Julian Period origin. J2000.0 = **JD 2 451 545.0**.
|
|
75
|
+
|
|
76
|
+
#### Constructors / factories
|
|
77
|
+
|
|
78
|
+
| Method | Description |
|
|
79
|
+
| ---------------------------------------- | ------------------------------------------------------ |
|
|
80
|
+
| `new JulianDate(value)` | From raw `f64` days. Throws on `NaN`/`±Infinity`. |
|
|
81
|
+
| `JulianDate.fromDate(date)` | From a JS `Date`. Applies ΔT correction automatically. |
|
|
82
|
+
| `JulianDate.fromUtc(y, mo, d, h, mi, s)` | From explicit UTC components. `s` may be fractional. |
|
|
83
|
+
| `JulianDate.j2000()` | Returns the J2000.0 epoch (JD 2 451 545.0). |
|
|
84
|
+
|
|
85
|
+
#### Accessors / conversions
|
|
86
|
+
|
|
87
|
+
| Member | Type | Description |
|
|
88
|
+
| -------------------- | -------------------- | ---------------------------------------------------- |
|
|
89
|
+
| `.value` | `number` | Raw JD scalar. |
|
|
90
|
+
| `.toMjd()` | `ModifiedJulianDate` | Converts to MJD (`JD − 2 400 000.5`). |
|
|
91
|
+
| `.toDate()` | `Date` | Converts to JS `Date` (UTC). Throws if out of range. |
|
|
92
|
+
| `.julianCenturies()` | `number` | T = (JD − 2 451 545.0) / 36 525. |
|
|
93
|
+
| `.julianYears()` | `number` | (JD − 2 451 545.0) / 365.25. |
|
|
94
|
+
| `.format()` | `string` | Human-readable string. |
|
|
95
|
+
|
|
96
|
+
#### Arithmetic
|
|
97
|
+
|
|
98
|
+
| Method | Description |
|
|
99
|
+
| -------------------- | -------------------------------------------------------------------------------- |
|
|
100
|
+
| `.addDays(days)` | Returns a new `JulianDate` shifted by `days` (can be negative). Throws on `NaN`. |
|
|
101
|
+
| `.difference(other)` | Returns `this − other` in days. |
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
### `ModifiedJulianDate`
|
|
106
|
+
|
|
107
|
+
`MJD = JD − 2 400 000.5`. MJD epoch: 1858-11-17T00:00:00 UTC. J2000.0 = **MJD 51 544.5**.
|
|
108
|
+
|
|
109
|
+
#### Constructors / factories
|
|
110
|
+
|
|
111
|
+
| Method | Description |
|
|
112
|
+
| ------------------------------------------------ | ------------------------------------------------- |
|
|
113
|
+
| `new ModifiedJulianDate(value)` | From raw `f64` days. Throws on `NaN`/`±Infinity`. |
|
|
114
|
+
| `ModifiedJulianDate.fromDate(date)` | From a JS `Date`. |
|
|
115
|
+
| `ModifiedJulianDate.fromUtc(y, mo, d, h, mi, s)` | From explicit UTC components. |
|
|
116
|
+
|
|
117
|
+
#### Accessors / conversions
|
|
118
|
+
|
|
119
|
+
| Member | Type | Description |
|
|
120
|
+
| ----------- | ------------ | ---------------------------------------------------- |
|
|
121
|
+
| `.value` | `number` | Raw MJD scalar. |
|
|
122
|
+
| `.toJd()` | `JulianDate` | Converts to JD. |
|
|
123
|
+
| `.toDate()` | `Date` | Converts to JS `Date` (UTC). Throws if out of range. |
|
|
124
|
+
| `.format()` | `string` | Human-readable string. |
|
|
125
|
+
|
|
126
|
+
#### Arithmetic
|
|
127
|
+
|
|
128
|
+
| Method | Description |
|
|
129
|
+
| -------------------- | ----------------------------------------------------- |
|
|
130
|
+
| `.addDays(days)` | Returns a new `ModifiedJulianDate` shifted by `days`. |
|
|
131
|
+
| `.difference(other)` | Returns `this − other` in days. |
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
### `Period`
|
|
136
|
+
|
|
137
|
+
A half-open time interval `[start, end)` over MJD.
|
|
138
|
+
|
|
139
|
+
#### Constructors / factories
|
|
140
|
+
|
|
141
|
+
| Method | Description |
|
|
142
|
+
| ------------------------------ | --------------------------------------------------------------- |
|
|
143
|
+
| `new Period(startMjd, endMjd)` | From two raw MJD values. Throws if `start > end` or non-finite. |
|
|
144
|
+
| `Period.fromDates(start, end)` | From two JS `Date` objects. Throws if `start > end`. |
|
|
145
|
+
|
|
146
|
+
#### Accessors
|
|
147
|
+
|
|
148
|
+
| Member | Type | Description |
|
|
149
|
+
| ----------- | -------------------- | --------------------------------------- |
|
|
150
|
+
| `.startMjd` | `number` | Start raw MJD value. |
|
|
151
|
+
| `.endMjd` | `number` | End raw MJD value. |
|
|
152
|
+
| `.start` | `ModifiedJulianDate` | Start as a `ModifiedJulianDate` object. |
|
|
153
|
+
| `.end` | `ModifiedJulianDate` | End as a `ModifiedJulianDate` object. |
|
|
154
|
+
|
|
155
|
+
#### Methods
|
|
156
|
+
|
|
157
|
+
| Method | Return | Description |
|
|
158
|
+
| ---------------------- | ------------------------------------ | --------------------------------------------------------------- |
|
|
159
|
+
| `.durationDays()` | `number` | Duration in days. |
|
|
160
|
+
| `.contains(mjd)` | `boolean` | `true` if `start ≤ mjd < end`. |
|
|
161
|
+
| `.intersection(other)` | `Period \| null` | Overlapping sub-period, or `null` if disjoint. |
|
|
162
|
+
| `.toUtc()` | `{ startMs: number, endMs: number }` | Endpoints as ms-since-epoch timestamps. Throws if out of range. |
|
|
163
|
+
| `.format()` | `string` | Human-readable string. |
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
### Free functions
|
|
168
|
+
|
|
169
|
+
| Function | Returns | Description |
|
|
170
|
+
| --------------------------- | -------- | ------------------------- |
|
|
171
|
+
| `jdToMjd(jd)` | `number` | `jd − 2 400 000.5` |
|
|
172
|
+
| `mjdToJd(mjd)` | `number` | `mjd + 2 400 000.5` |
|
|
173
|
+
| `julianCenturies(jd)` | `number` | T = (jd − J2000) / 36 525 |
|
|
174
|
+
| `julianYears(jd)` | `number` | (jd − J2000) / 365.25 |
|
|
175
|
+
| `jdFromDate(date)` | `number` | JS `Date` → JD scalar |
|
|
176
|
+
| `mjdFromDate(date)` | `number` | JS `Date` → MJD scalar |
|
|
177
|
+
| `jdToDate(jd)` | `Date` | JD scalar → JS `Date` |
|
|
178
|
+
| `mjdToDate(mjd)` | `Date` | MJD scalar → JS `Date` |
|
|
179
|
+
| `jdDifference(jd1, jd2)` | `number` | `jd1 − jd2` in days |
|
|
180
|
+
| `mjdDifference(mjd1, mjd2)` | `number` | `mjd1 − mjd2` in days |
|
|
181
|
+
| `version()` | `string` | Package version string |
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## UTC conversions and ΔT
|
|
186
|
+
|
|
187
|
+
The mapping between a Julian Date (expressed in **Terrestrial Time**, TT) and a
|
|
188
|
+
`Date` object (expressed in **UTC**) involves the **ΔT = TT − UT** correction.
|
|
189
|
+
This package applies the correction automatically in both directions using the
|
|
190
|
+
piecewise Meeus/IERS model from `tempoch-core`:
|
|
191
|
+
|
|
192
|
+
```
|
|
193
|
+
JulianDate.fromDate(jsDate) → internal route: UTC → UT → JD(TT)
|
|
194
|
+
jd.toDate() → internal route: JD(TT) → UT → UTC
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
For J2000.0 (JD 2 451 545.0, TT noon), the UTC equivalent is approximately
|
|
198
|
+
**2000-01-01T11:58:56Z** (ΔT ≈ 63.8 s in the year 2000).
|
|
199
|
+
|
|
200
|
+
> **Note:** this ΔT is an astronomical correction, not a leap-second offset.
|
|
201
|
+
> It accounts for the irregular slowing of Earth's rotation relative to
|
|
202
|
+
> dynamical (atomic) time.
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
## Examples
|
|
207
|
+
|
|
208
|
+
| File | Description |
|
|
209
|
+
| -------------------------------------------------- | ---------------------------------------------- |
|
|
210
|
+
| [examples/quickstart.mjs](examples/quickstart.mjs) | Construction, conversions, arithmetic |
|
|
211
|
+
| [examples/periods.mjs](examples/periods.mjs) | Period construction, containment, intersection |
|
|
212
|
+
| [examples/timescales.mjs](examples/timescales.mjs) | J2000 epoch, centuries, observation windows |
|
|
213
|
+
|
|
214
|
+
Run any example directly:
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
node examples/quickstart.mjs
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## Building from source
|
|
223
|
+
|
|
224
|
+
Requirements: **Rust ≥ 1.75**, **Node.js ≥ 18**, **napi-rs CLI 2.x**.
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
git clone https://github.com/Siderust/tempoch
|
|
228
|
+
cd javascript/tempoch-js/tempoch-node
|
|
229
|
+
|
|
230
|
+
# Install JS dev dependencies (includes @napi-rs/cli)
|
|
231
|
+
npm install
|
|
232
|
+
|
|
233
|
+
# Debug build
|
|
234
|
+
npm run build:debug
|
|
235
|
+
|
|
236
|
+
# Optimised release build
|
|
237
|
+
npm run build
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
## Architecture
|
|
243
|
+
|
|
244
|
+
```
|
|
245
|
+
@siderust/tempoch (JS/TS)
|
|
246
|
+
│
|
|
247
|
+
│ napi-rs bindings (src/lib.rs)
|
|
248
|
+
▼
|
|
249
|
+
tempoch (Rust façade crate)
|
|
250
|
+
│
|
|
251
|
+
▼
|
|
252
|
+
tempoch-core (Time<S>, Period, ΔT model, scale markers)
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
The native addon is a `cdylib` Rust crate that depends on `tempoch` and
|
|
256
|
+
`tempoch-core`. No C FFI layer is involved — napi-rs generates the V8 bridge
|
|
257
|
+
directly without going through `tempoch-ffi`.
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
## License
|
|
262
|
+
|
|
263
|
+
AGPL-3.0-only — see [LICENSE](LICENSE).
|
|
264
|
+
|
|
265
|
+
© 2026 Vallés Puig, Ramon
|