The Epoch class is the fundamental time representation in Brahe. It encapsulates a specific instant in time, defined by both a time representation and a time scale. The Epoch class provides methods for converting between different time representations and time scales, as well as for performing arithmetic operations on time instances.
There are even more capabilities and features of the Epoch class beyond what is covered in this guide. For a complete reference of all available methods and properties, please refer to the Epoch API Reference.
The most common way to create an Epoch is from date and time components. You can specify just a date (which defaults to midnight), or provide the full date and time including fractional seconds.
importbraheasbhbh.initialize_eop()# Create epoch from date only (midnight)epc1=bh.Epoch(2024,1,1)print(f"Date only: {epc1}")# Date only: 2024-01-01 00:00:00.000 UTC# Create epoch from full datetime componentsepc2=bh.Epoch(2024,6,15,14,30,45.5,0.0)print(f"Full datetime: {epc2}")# Full datetime: 2024-06-15 14:30:45.500 UTC# Create epoch with different time systemepc3=bh.Epoch(2024,12,25,18,0,0.0,0.0,time_system=bh.TimeSystem.GPS)print(f"GPS time system: {epc3}")# GPS time system: 2024-12-25 18:00:00.000 GPS# In Python you can also use the direct datetime constantepc4=bh.Epoch(2024,12,25,18,0,0.0,0.0,time_system=bh.TAI)print(f"GPS time system: {epc4}")# GPS time system: 2024-12-25 18:00:00.000 TAI
usebraheasbh;fnmain(){bh::initialize_eop().unwrap();// Create epoch from date only (midnight)letepc1=bh::Epoch::from_date(2024,1,1,bh::TimeSystem::UTC);println!("Date only: {}",epc1);// Create epoch from full datetime componentsletepc2=bh::Epoch::from_datetime(2024,6,15,14,30,45.5,0.0,bh::TimeSystem::UTC);println!("Full datetime: {}",epc2);// Create epoch with different time systemletepc3=bh::Epoch::from_datetime(2024,12,25,18,0,0.0,0.0,bh::TimeSystem::GPS);println!("GPS time system: {}",epc3);}
Modified Julian Date (MJD) is a commonly used time representation in astronomy and astrodynamics. MJD is defined as JD - 2400000.5, which makes it more convenient for modern dates.
importbraheasbhbh.initialize_eop()# The string can be an ISO 8601 formatepc1=bh.Epoch.from_string("2025-01-02T04:56:54.123Z")print(f"ISO 8601: {epc1}")# It can be a simple space-separated format with a time systemepc2=bh.Epoch.from_string("2024-06-15 14:30:45.500 GPS")print(f"Simple format: {epc2}")# It can be a datetime without a time system (defaults to UTC)epc3=bh.Epoch.from_string("2023-12-31 23:59:59")print(f"Datetime without time system: {epc3}")# Or it can just be a dateepc4=bh.Epoch.from_string("2022-07-04")print(f"Date only: {epc4}")
usebraheasbh;fnmain(){bh::initialize_eop().unwrap();// The string can be an ISO 8601 formatletepc1=bh::Epoch::from_string("2025-01-02T04:56:54.123Z").unwrap();println!("ISO 8601: {}",epc1);// It can be a simple space-separated format with a time systemletepc2=bh::Epoch::from_string("2024-06-15 14:30:45.500 GPS").unwrap();println!("Simple format: {}",epc2);// It can be a datetime without a time system (defaults to UTC)letepc3=bh::Epoch::from_string("2023-12-31 23:59:59").unwrap();println!("Datetime without time system: {}",epc3);// Or it can just be a dateletepc4=bh::Epoch::from_string("2022-07-04").unwrap();println!("Date only: {}",epc4);}
importbraheasbhbh.initialize_eop()# Create an epochepc=bh.Epoch(2025,1,1,12,0,0.0,0.0)print(f"Original epoch: {epc}")# Original epoch: 2025-01-01 12:00:00.000 UTC# You can add time in seconds to an Epoch and get a new Epoch back# Add 1 hour (3600 seconds)epc_plus_hour=epc+3600.0print(f"Plus 1 hour: {epc_plus_hour}")# Plus 1 hour: 2025-01-01 13:00:00.000 UTC# Add 1 day (86400 seconds)epc_plus_day=epc+86400.0print(f"Plus 1 day: {epc_plus_day}")# Plus 1 day: 2025-01-02 12:00:00.000 UTC# You can also do in-place addition# Add 1 second in-placeepc+=1.0print(f"In-place plus 1 second: {epc}")# In-place plus 1 second: 2025-01-01 12:00:01.000 UTC# Add 1 milisecond in-placeepc+=0.001print(f"In-place plus 1 millisecond: {epc}")# In-place plus 1 millisecond: 2025-01-01 12:00:01.001 UTC
usebraheasbh;fnmain(){bh::initialize_eop().unwrap();// Create an epochletepc=bh::Epoch::from_datetime(2025,1,1,12,0,0.0,0.0,bh::TimeSystem::UTC);println!("Original epoch: {}",epc);// Original epoch: 2025-01-01 12:00:00.000 UTC// You can add time in seconds to an Epoch and get a new Epoch back// Add 1 hour (3600 seconds)letepc_plus_hour=epc+3600.0;println!("Plus 1 hour: {}",epc_plus_hour);// Plus 1 hour: 2025-01-01 13:00:00.000 UTC// Add 1 day (86400 seconds)letepc_plus_day=epc+86400.0;println!("Plus 1 day: {}",epc_plus_day);// Plus 1 day: 2025-01-02 12:00:00.000 UTC// You can also do in-place addition// Add 1 second in-placeletmutepc=epc;epc+=1.0;println!("In-place plus 1 second: {}",epc);// In-place plus 1 second: 2025-01-01 12:00:01.000 UTC// Add 1 millisecond in-placeepc+=0.001;println!("In-place plus 1 millisecond: {}",epc);// In-place plus 1 millisecond: 2025-01-01 12:00:01.001 UTC}
importbraheasbhbh.initialize_eop()# You can subtract two Epoch instances to get the time difference in secondsepc1=bh.Epoch(2024,1,1,12,0,0.0,0.0)epc2=bh.Epoch(2024,1,2,12,1,1.0,0.0)dt=epc2-epc1print(f"Time difference: {dt:.1f} seconds")# You can also subtract a float (in seconds) from an Epoch to get a new Epochepc=bh.Epoch(2024,6,15,10,30,0.0,0.0)# Subtract 1 hour (3600 seconds)epc_minus_hour=epc-3600.0print(f"Minus 1 hour: {epc_minus_hour}")# You can also update an Epoch in-place by subtracting secondsepc=bh.Epoch(2024,1,1,0,0,0.0,0.0)epc-=61.0# Subtract 61 secondsprint(f"In-place minus 61 seconds: {epc}")
usebraheasbh;fnmain(){bh::initialize_eop().unwrap();// Create two epochsletepc1=bh::Epoch::from_datetime(2024,1,1,12,0,0.0,0.0,bh::TimeSystem::UTC);letepc2=bh::Epoch::from_datetime(2024,1,2,13,1,1.0,0.0,bh::TimeSystem::UTC);// Compute time difference in secondsletdt=epc2-epc1;println!("Time difference: {:.1} seconds",dt);// Time difference: 90061.0 seconds// You can also subtract a float (in seconds) from an Epoch to get a new Epochletepc=bh::Epoch::from_datetime(2024,6,15,10,30,0.0,0.0,bh::TimeSystem::UTC);letepc_minus_hour=epc-3600.0;println!("Minus 1 hour: {}",epc_minus_hour);// Minus 1 hour: 2024-06-15 09:30:00.000 UTC// You can also update an Epoch in-place by subtracting secondsletmutepc=bh::Epoch::from_datetime(2024,1,1,0,0,0.0,0.0,bh::TimeSystem::UTC);epc-=61.0;// Subtract 61 secondsprintln!("In-place minus 61 seconds: {}",epc);// In-place minus 61 seconds: 2023-12-31 23:58:59.000 UTC}
The Epoch class also supports comparison operations (e.g., equality, less than, greater than) to compare different time instances. It also supports methods for getting string representations using language-specific formatting options.
importbraheasbhbh.initialize_eop()# Create an epochepc=bh.Epoch(2024,6,15,14,30,45.5,0.0)print(f"Epoch: {epc}")# Epoch: 2024-06-15 14:30:45.500 UTC# Output the equivalent Julian Datejd=epc.jd()print(f"Julian Date: {jd:.6f}")# Julian Date: 2460477.104693# Get the Julian Date in a different time system (e.g., TT)jd_tt=epc.jd_as_time_system(time_system=bh.TT)print(f"Julian Date (TT): {jd_tt:.6f}")# Julian Date (TT): 2460477.105494# Output the equivalent Modified Julian Datemjd=epc.mjd()print(f"Modified Julian Date: {mjd:.6f}")# Modified Julian Date: 60476.604693# Get the Modified Julian Date in a different time system (e.g., GPS)mjd_gps=epc.mjd_as_time_system(time_system=bh.GPS)print(f"Modified Julian Date (GPS): {mjd_gps:.6f}")# Modified Julian Date (GPS): 60476.604902# Get the GPS Week and Seconds of Weekgps_week,gps_sow=epc.gps_date()print(f"GPS Week: {gps_week}, Seconds of Week: {gps_sow:.3f}")# GPS Week: 2318, Seconds of Week: 570663.500# The Epoch as GPS seconds since the GPS epochgps_seconds=epc.gps_seconds()print(f"GPS Seconds since epoch: {gps_seconds:.3f}")# GPS Seconds since epoch: 1402497063.500
usebraheasbh;fnmain(){bh::initialize_eop().unwrap();// Create an epochletepc=bh::Epoch::from_datetime(2024,6,15,14,30,45.5,0.0,bh::TimeSystem::UTC);println!("Epoch: {}",epc);// Epoch: 2024-06-15 14:30:45.500 UTC// Output the equivalent Julian Dateletjd=epc.jd();println!("Julian Date: {:.6}",jd);// Julian Date: 2460477.104693// Get the Julian Date in a different time system (e.g., TT)letjd_tt=epc.jd_as_time_system(bh::TimeSystem::TT);println!("Julian Date (TT): {:.6}",jd_tt);// Julian Date (TT): 2460477.105494// Output the equivalent Modified Julian Dateletmjd=epc.mjd();println!("Modified Julian Date: {:.6}",mjd);// Modified Julian Date: 60476.604693// Get the Modified Julian Date in a different time system (e.g., GPS)letmjd_gps=epc.mjd_as_time_system(bh::TimeSystem::GPS);println!("Modified Julian Date (GPS): {:.6}",mjd_gps);// Modified Julian Date (GPS): 60476.604902// Get the GPS Week and Seconds of Weeklet(gps_week,gps_sow)=epc.gps_date();println!("GPS Week: {}, Seconds of Week: {:.3}",gps_week,gps_sow);// GPS Week: 2318, Seconds of Week: 570663.500// The Epoch as GPS seconds since the GPS epochletgps_seconds=epc.gps_seconds();println!("GPS Seconds since epoch: {:.3}",gps_seconds);// GPS Seconds since epoch: 1402497063.500}
importbraheasbhbh.initialize_eop()# Create an epochepc=bh.Epoch(2024,6,15,14,30,45.123456789,0.0)# Default string representationprint(f"Default: {epc}")# Default: 2024-06-15 14:30:45.123 UTC# Explicit string conversionprint(f"String: {str(epc)}")# String: 2024-06-15 14:30:45.123 UTC# Debug representationprint(f"Debug: {repr(epc)}")# Debug: Epoch<2460477, 9082, 123456788.98545027, 0, UTC># Get string in a different time systemprint(f"TT: {epc.to_string_as_time_system(bh.TimeSystem.TT)}")# TT: 2024-06-15 14:31:54.307 TT# Get as ISO 8601 formatted stringprint(f"ISO 8601: {epc.isostring()}")# ISO 8601: 2024-06-15T14:30:45Z# Get as ISO 8601 with different number of decimal placesprint(f"ISO 8601 (0 decimal places): {epc.isostring_with_decimals(0)}")print(f"ISO 8601 (3 decimal places): {epc.isostring_with_decimals(3)}")print(f"ISO 8601 (6 decimal places): {epc.isostring_with_decimals(6)}")# ISO 8601 (0 decimal places): 2024-06-15T14:30:45Z# ISO 8601 (3 decimal places): 2024-06-15T14:30:45.123Z# ISO 8601 (6 decimal places): 2024-06-15T14:30:45.123456Z
usebraheasbh;fnmain(){bh::initialize_eop().unwrap();// Create an epochletepc=bh::Epoch::from_datetime(2024,6,15,14,30,45.123456789,0.0,bh::TimeSystem::UTC);// Default string representationprintln!("Default: {}",epc);// String: 2024-06-15 14:30:45.123 UTC// Explicit string conversion (same as default in Rust)println!("String: {}",epc.to_string());// String: 2024-06-15 14:30:45.123 UTC// Debug representationprintln!("Debug: {:?}",epc);// Debug: Epoch<2460477, 9082, 123456788.98545027, 0, UTC>// Get string in a different time systemprintln!("TT: {}",epc.to_string_as_time_system(bh::TimeSystem::TT));// TT: 2024-06-15 14:31:54.307 TT// Get as ISO 8601 formatted stringprintln!("ISO 8601: {}",epc.isostring());// ISO 8601: 2024-06-15T14:30:45Z// Get as ISO 8601 with different number of decimal placesprintln!("ISO 8601 (0 decimal places): {}",epc.isostring_with_decimals(0));println!("ISO 8601 (3 decimal places): {}",epc.isostring_with_decimals(3));println!("ISO 8601 (6 decimal places): {}",epc.isostring_with_decimals(6));// ISO 8601 (0 decimal places): 2024-06-15T14:30:45Z// ISO 8601 (3 decimal places): 2024-06-15T14:30:45.123Z// ISO 8601 (6 decimal places): 2024-06-15T14:30:45.123456Z}