Strongly typed GNSS time model with explicit conversion semantics and zero-cost arithmetic.
gnss-time is a high-performance temporal abstraction layer for representing and
converting time across GNSS and atomic time scales.
It models time as a typed multi-scale system, not a single linear timeline.
Supported time scales:
- GPS
- GLONASS
- Galileo
- BeiDou
- TAI
- UTC
This crate prioritizes:
- correctness over convenience
- explicitness over implicit conversions
- deterministic behavior over hidden state
It is not a navigation or positioning library.
Each GNSS time scale differs in:
- epoch origin
- unit definition
- discontinuities (leap seconds)
Therefore:
Each time scale is a distinct type.
This prevents invalid mixing at compile time.
The system is structured as:
[ Arithmetic Layer ]
↓
[ GNSS Scale Layer ]
↓
[ UTC / Civil Layer ]
- raw time representation (
u64 nanoseconds) - zero-cost operations
- GPS / Galileo / BeiDou / GLONASS / TAI
- fixed or epoch-shift conversions
- leap-second aware
- discontinuous timeline
- possibly non-invertible
Conversions are classified as:
- Fixed → constant offset, zero-cost
- EpochShift → deterministic remapping
- Contextual → leap-second dependent (UTC only)
Each scale is a distinct type:
GpsGlonassGalileoBeidouTaiUtc
Cross-domain arithmetic is not allowed implicitly.
// ❌ compile error
gps + utc;Arithmetic compiles down to native integer operations:
Time + Duration≈u64 + u64- no heap allocation
- no runtime dispatch
The library models a conversion graph:
- 6×6 scale matrix
- fixed vs contextual edges
- runtime inspectable structure
use gnss_time::prelude::*;
let gps = Time::<Gps>::from_week_tow(
2200,
DurationParts { seconds: 0, nanos: 0 },
).unwrap();
// Fixed conversion (zero-cost)
let gal: Time<Galileo> = gps.into_scale().unwrap();UTC conversions require explicit handling:
use gnss_time::prelude::*;
let gps = Time::<Gps>::from_week_tow(
2200,
DurationParts { seconds: 0, nanos: 0 },
).unwrap();
let ls = LeapSeconds::builtin();
let result = gps.into_scale_with_checked(ls).unwrap();
match result {
ConvertResult::Exact(utc) => {
println!("UTC: {}", utc);
}
ConvertResult::AmbiguousLeapSecond(utc) => {
println!("Leap second ambiguity: {}", utc);
}
}use gnss_time::{Time, Utc};
let utc = Time::<Utc>::EPOCH;
let civil = utc.to_civil();
assert_eq!(
civil.to_string(),
"1972-01-01T00:00:00.000000000Z"
);Proleptic Gregorian UTC representation:
- year, month, day
- hour, minute, second
- nanoseconds
-
Lossless round-trip:
Time<Utc> ↔ CivilDateTime ↔ Time<Utc>
-
ISO 8601 / RFC 3339 formatting
-
nanosecond precision preserved
GNSS systems define incompatible time scales:
| System | Definition |
|---|---|
| GPS | TAI − 19s |
| Galileo | TAI − 19s |
| BeiDou | TAI − 33s |
| GLONASS | UTC(SU)-aligned |
| TAI | continuous atomic time |
| UTC | leap-second discontinuous time |
A single physical instant may have multiple valid representations.
Cross-scale operations are rejected at compile time.
UTC is:
- discontinuous
- not globally invertible
- state-dependent
This is modeled explicitly in:
ConvertResult- GNSS fixed conversions are deterministic
- UTC conversions depend on leap-second table
- ambiguous states are representable, not hidden
| Operation | Cost |
|---|---|
Time + Duration (panic path) |
~0.5 ns |
checked_add |
~4.3 ns |
saturating_add |
~0.5 ns |
| Operation | Cost |
|---|---|
| GPS → TAI / Galileo / BeiDou | ~0.8–1.0 ns |
| GPS → UTC (leap-aware) | ~9–10 ns |
| UTC → GPS | ~22 ns |
| Leap-second binary search | ~6–7 ns |
- GPS → UTC → GPS: ~37 ns
- cost dominated by UTC context resolution
UTC conversions:
- require leap-second table
- may be ambiguous
- are not always invertible
Only UTC crosses the boundary:
GNSS scales → deterministic algebra
UTC → stateful discontinuity system
All conversions must be explicit:
- prevents silent epoch mistakes
- enforces correctness at compile time
| Scale | Representation |
|---|---|
| GLONASS | Day / TOD |
| GPS | Week / TOW |
| Galileo | Week / TOW |
| BeiDou | Week / TOW |
| TAI | seconds + nanos |
| UTC | leap-second aware |
- Core time algebra
- GNSS scale model
- Fixed conversions
- Contextual UTC handling
- Leap-second engine
- Conversion matrix inspection
- Embedded-safe arithmetic
- Civil datetime layer
Minimum Supported Rust Version (MSRV):
- Rust 1.75.0
Enforced in CI.
Licensed under either: