pub struct EagleTime { /* private fields */ }Expand description
EagleTime represents a point in time in the Eagle Time standard.
Stores time as oscillation counts of the 21cm hydrogen-1 hyperfine transition.
Eagle epoch: Apollo 11 lunar landing - July 20, 1969 at 20:17:40 UTC (The moment “The Eagle has landed” was transmitted)
This definition:
- Uses the most abundant element in the universe (hydrogen-1)
- Is measurable with any 21cm radio receiver
- Accounts for gravitational time dilation in the frequency measurement
- Provides universal verifiability without trusted authorities
- Achieves picosecond precision with standard integer types
§Precision Characteristics
| Type | Range | Precision | Use Case |
|---|---|---|---|
| e5 | ±1.5 years | 704 ps | Short intervals, packed structs |
| e6 | ±206 years | 704 ps | Absolute timestamps (default) |
| e7 | astronomical | 704 ps | Geological/astronomical timestamps |
Implementations§
Source§impl EagleTime
impl EagleTime
Sourcepub fn new_from_vsf(value: VsfType) -> Self
pub fn new_from_vsf(value: VsfType) -> Self
Creates a new EagleTime instance from a VsfType.
Integer types are interpreted as oscillation counts. Float types are interpreted as seconds.
§Panics
Panics if the VsfType is not a valid numeric variant or EagleTime type.
Sourcepub fn from_oscillations(count: i64) -> Self
pub fn from_oscillations(count: i64) -> Self
Creates an EagleTime from an oscillation count (i64)
Sourcepub fn from_seconds_f64(seconds: f64) -> Self
pub fn from_seconds_f64(seconds: f64) -> Self
Creates an EagleTime from seconds (f64), converting to oscillation count
Sourcepub fn from_seconds_f32(seconds: f32) -> Self
pub fn from_seconds_f32(seconds: f32) -> Self
Creates an EagleTime from seconds (f32), converting to oscillation count
Sourcepub fn to_vsf_type(&self) -> VsfType
pub fn to_vsf_type(&self) -> VsfType
Converts the current EagleTime to a VsfType.
Sourcepub fn to_datetime_opt(&self) -> Option<DateTime<Utc>>
pub fn to_datetime_opt(&self) -> Option<DateTime<Utc>>
Converts the EagleTime to a UTC DateTime.
For integer types, divides oscillation count by OSCILLATIONS_PER_SECOND. For float types, uses the stored seconds directly.
Returns None if the timestamp is outside chrono’s representable range.
Sourcepub fn to_datetime(&self) -> DateTime<Utc>
pub fn to_datetime(&self) -> DateTime<Utc>
Converts the EagleTime to a UTC DateTime.
Panics if the timestamp is outside chrono’s representable range. For non-panicking version, use to_datetime_opt().
Sourcepub fn to_seconds_f64(&self) -> f64
pub fn to_seconds_f64(&self) -> f64
Converts to f64 seconds, regardless of storage type.
For integer types: divides oscillation count by OSCILLATIONS_PER_SECOND. For float types (deprecated): returns the stored seconds directly.
Sourcepub fn to_seconds_f32(&self) -> f32
pub fn to_seconds_f32(&self) -> f32
Converts to f32 seconds, regardless of storage type.
Sourcepub fn oscillations(&self) -> Option<i64>
pub fn oscillations(&self) -> Option<i64>
Returns the oscillation count as i64 if stored as an integer type, None for deprecated float types.
Examples found in repository?
4fn main() {
5 // Simulate what vsf_builder does
6 let mut vsf: Vec<Vec<u8>> = Vec::new();
7
8 // Magic + header start
9 vsf.push("RÅ".as_bytes().to_vec());
10 vsf[0].push(b'<');
11
12 // Header length placeholder
13 vsf.push(VsfType::b(0, true).flatten());
14
15 // Version and backward compat (in same vec)
16 let header_index = vsf.len();
17 vsf.push(VsfType::z(2).flatten());
18 vsf[header_index].extend_from_slice(&VsfType::y(2).flatten());
19
20 // Creation time (e6 — 64-bit oscillation count)
21 let now = Utc::now();
22 let et = vsf::datetime_to_eagle_time(now);
23 let oscillations = et.oscillations().unwrap_or(0);
24 let creation_time = VsfType::e(EtType::e6(oscillations));
25 vsf[header_index].extend_from_slice(&creation_time.flatten());
26
27 // Hash placeholder
28 vsf[header_index].extend_from_slice(&VsfType::hb(vec![0u8; 32]).flatten());
29
30 // Flatten
31 let bytes: Vec<u8> = vsf.into_iter().flatten().collect();
32
33 println!("Total bytes: {}", bytes.len());
34 println!("\nFirst 60 bytes with positions:");
35 for (i, &b) in bytes.iter().take(60).enumerate() {
36 if i % 16 == 0 {
37 println!();
38 print!("{:04X}: ", i);
39 }
40 print!("{:02X} ", b);
41 }
42 println!("\n");
43
44 // Find where 'h' appears
45 for (i, &b) in bytes.iter().enumerate().take(40) {
46 if b == b'h' {
47 println!("Found 'h' at position {}", i);
48 }
49 }
50
51 // Parse like verification does
52 println!("\nParsing simulation:");
53 let mut pointer = 0;
54
55 // Skip magic
56 pointer += 3; // "RÅ"
57 pointer += 1; // '<'
58 println!("After magic: pointer = {}", pointer);
59
60 // Parse header length
61 let hl_start = pointer;
62 if bytes[pointer] == b'b' {
63 pointer += 1;
64 let len_marker = bytes[pointer];
65 pointer += 1;
66 println!(
67 "Header length type at {}, marker={}, pointer now={}",
68 hl_start, len_marker as char, pointer
69 );
70 }
71
72 // Parse version (z)
73 let v_start = pointer;
74 if bytes[pointer] == b'z' {
75 pointer += 1;
76 let len_marker = bytes[pointer];
77 pointer += 1;
78 println!(
79 "Version at {}, marker={}, pointer now={}",
80 v_start, len_marker as char, pointer
81 );
82 }
83
84 // Parse backward compat (y)
85 let bc_start = pointer;
86 if bytes[pointer] == b'y' {
87 pointer += 1;
88 let len_marker = bytes[pointer];
89 pointer += 1;
90 println!(
91 "Backward compat at {}, marker={}, pointer now={}",
92 bc_start, len_marker as char, pointer
93 );
94 }
95
96 // Parse creation time (e)
97 let et_start = pointer;
98 if bytes[pointer] == b'e' {
99 pointer += 1;
100 if bytes[pointer] == b'f' {
101 pointer += 1;
102 if bytes[pointer] == b'5' {
103 pointer += 1;
104 pointer += 4; // f32
105 println!("Eagle Time (ef5) at {}, pointer now={}", et_start, pointer);
106 }
107 }
108 }
109
110 // Now we should be at the hash
111 println!(
112 "\nAt position {}: byte = 0x{:02X} ('{}')",
113 pointer, bytes[pointer], bytes[pointer] as char
114 );
115 if bytes[pointer] == b'h' {
116 println!("SUCCESS: Found hash placeholder at correct position!");
117 } else {
118 println!("ERROR: Expected 'h', found something else");
119 }
120}Sourcepub fn oscillations_i128(&self) -> Option<i128>
pub fn oscillations_i128(&self) -> Option<i128>
Returns the full i128 oscillation count. Covers e5/e6/e7 without truncation.
Sourcepub fn picoseconds(&self) -> Option<i128>
pub fn picoseconds(&self) -> Option<i128>
Returns the picosecond precision timestamp (oscillations × 704.032 ps). Returns None for deprecated float types.