Compare commits
1 Commits
ff9cbb159c
...
0433f068c1
Author | SHA1 | Date | |
---|---|---|---|
0433f068c1 |
@ -727,14 +727,14 @@ impl<ProvidesDaysLen: ProvidesDaysLength> CdsTime<ProvidesDaysLen> {
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
fn from_now_generic(days_len: LengthOfDaySegment) -> Result<Self, StdTimestampError> {
|
||||
fn now_generic(days_len: LengthOfDaySegment) -> Result<Self, StdTimestampError> {
|
||||
let conversion_from_now = ConversionFromNow::new()?;
|
||||
Self::generic_from_conversion(days_len, conversion_from_now)
|
||||
.map_err(|e| StdTimestampError::Timestamp(TimestampError::from(e)))
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
fn from_now_generic_us_prec(days_len: LengthOfDaySegment) -> Result<Self, StdTimestampError> {
|
||||
fn now_generic_with_us_prec(days_len: LengthOfDaySegment) -> Result<Self, StdTimestampError> {
|
||||
let conversion_from_now = ConversionFromNow::new_with_submillis_us_prec()?;
|
||||
Self::generic_from_conversion(days_len, conversion_from_now)
|
||||
.map_err(|e| StdTimestampError::Timestamp(TimestampError::from(e)))
|
||||
@ -823,7 +823,7 @@ impl CdsTime<DaysLen24Bits> {
|
||||
/// Generate a time stamp from the current time using the system clock.
|
||||
#[cfg(feature = "std")]
|
||||
pub fn now_with_u24_days() -> Result<Self, StdTimestampError> {
|
||||
Self::from_now_generic(LengthOfDaySegment::Long24Bits)
|
||||
Self::now_generic(LengthOfDaySegment::Long24Bits)
|
||||
}
|
||||
|
||||
/// Create a provider from a [`chrono::DateTime<chrono::Utc>`] struct.
|
||||
@ -845,7 +845,7 @@ impl CdsTime<DaysLen24Bits> {
|
||||
/// This function will return [CdsError::DateBeforeCcsdsEpoch] if the time is before the CCSDS
|
||||
/// epoch (1958-01-01T00:00:00+00:00) or the CCSDS days value exceeds the allowed bit width
|
||||
/// (24 bits).
|
||||
pub fn from_unix_stamp_with_u24_days(
|
||||
pub fn from_unix_time_with_u24_day(
|
||||
unix_stamp: &UnixTime,
|
||||
submillis_prec: SubmillisPrecision,
|
||||
) -> Result<Self, CdsError> {
|
||||
@ -870,14 +870,14 @@ impl CdsTime<DaysLen24Bits> {
|
||||
|
||||
/// Like [Self::from_now_with_u24_days] but with microsecond sub-millisecond precision.
|
||||
#[cfg(feature = "std")]
|
||||
pub fn from_now_with_u24_days_us_precision() -> Result<Self, StdTimestampError> {
|
||||
Self::from_now_generic_us_prec(LengthOfDaySegment::Long24Bits)
|
||||
pub fn now_with_u24_days_us_precision() -> Result<Self, StdTimestampError> {
|
||||
Self::now_generic_with_us_prec(LengthOfDaySegment::Long24Bits)
|
||||
}
|
||||
|
||||
/// Like [Self::from_now_with_u24_days] but with picoseconds sub-millisecond precision.
|
||||
#[cfg(feature = "std")]
|
||||
pub fn from_now_with_u24_days_ps_precision() -> Result<Self, StdTimestampError> {
|
||||
Self::from_now_generic_us_prec(LengthOfDaySegment::Long24Bits)
|
||||
pub fn now_with_u24_days_ps_precision() -> Result<Self, StdTimestampError> {
|
||||
Self::now_generic_with_us_prec(LengthOfDaySegment::Long24Bits)
|
||||
}
|
||||
|
||||
pub fn from_bytes_with_u24_days(buf: &[u8]) -> Result<Self, TimestampError> {
|
||||
@ -927,7 +927,7 @@ impl CdsTime<DaysLen16Bits> {
|
||||
/// Generate a time stamp from the current time using the system clock.
|
||||
#[cfg(feature = "std")]
|
||||
pub fn now_with_u16_days() -> Result<Self, StdTimestampError> {
|
||||
Self::from_now_generic(LengthOfDaySegment::Short16Bits)
|
||||
Self::now_generic(LengthOfDaySegment::Short16Bits)
|
||||
}
|
||||
|
||||
/// Create a provider from a generic UNIX timestamp (seconds since 1970-01-01T00:00:00+00:00).
|
||||
@ -963,7 +963,7 @@ impl CdsTime<DaysLen16Bits> {
|
||||
/// Like [Self::from_now_with_u16_days] but with microsecond sub-millisecond precision.
|
||||
#[cfg(feature = "std")]
|
||||
pub fn now_with_u16_days_us_precision() -> Result<Self, StdTimestampError> {
|
||||
Self::from_now_generic_us_prec(LengthOfDaySegment::Short16Bits)
|
||||
Self::now_generic_with_us_prec(LengthOfDaySegment::Short16Bits)
|
||||
}
|
||||
|
||||
/// Like [Self::from_now_with_u16_days] but with picosecond sub-millisecond precision.
|
||||
@ -1636,7 +1636,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_time_now_ps_prec_u24_days() {
|
||||
let timestamp_now = CdsTime::from_now_with_u24_days_ps_precision().unwrap();
|
||||
let timestamp_now = CdsTime::now_with_u24_days_ps_precision().unwrap();
|
||||
let compare_stamp = chrono::Utc::now();
|
||||
generic_now_test(timestamp_now, compare_stamp);
|
||||
}
|
||||
@ -1933,7 +1933,7 @@ mod tests {
|
||||
fn test_creation_from_unix_stamp_0_u24_days() {
|
||||
let unix_secs = 0;
|
||||
let subsec_millis = 0;
|
||||
let time_provider = CdsTime::from_unix_stamp_with_u24_days(
|
||||
let time_provider = CdsTime::from_unix_time_with_u24_day(
|
||||
&UnixTime::new(unix_secs, subsec_millis),
|
||||
SubmillisPrecision::Absent,
|
||||
)
|
||||
|
@ -430,15 +430,15 @@ impl CucTime {
|
||||
|
||||
/// Generates a CUC timestamp from a UNIX timestamp with a width of 4. This width is able
|
||||
/// to accomodate all possible UNIX timestamp values.
|
||||
pub fn from_unix_stamp(
|
||||
unix_stamp: &UnixTime,
|
||||
pub fn from_unix_time(
|
||||
unix_time: &UnixTime,
|
||||
res: FractionalResolution,
|
||||
leap_seconds: u32,
|
||||
) -> Result<Self, CucError> {
|
||||
let counter = unix_epoch_to_ccsds_epoch(unix_stamp.secs);
|
||||
let counter = unix_epoch_to_ccsds_epoch(unix_time.secs);
|
||||
// Negative CCSDS epoch is invalid.
|
||||
if counter < 0 {
|
||||
return Err(DateBeforeCcsdsEpochError(*unix_stamp).into());
|
||||
return Err(DateBeforeCcsdsEpochError(*unix_time).into());
|
||||
}
|
||||
// We already excluded negative values, so the conversion to u64 should always work.
|
||||
let mut counter = u32::try_from(counter).map_err(|_| CucError::InvalidCounter {
|
||||
@ -449,7 +449,7 @@ impl CucTime {
|
||||
.checked_add(leap_seconds)
|
||||
.ok_or(CucError::LeapSecondCorrectionError)?;
|
||||
let fractions =
|
||||
fractional_part_from_subsec_ns(res, unix_stamp.subsec_millis() as u64 * 10_u64.pow(6));
|
||||
fractional_part_from_subsec_ns(res, unix_time.subsec_millis() as u64 * 10_u64.pow(6));
|
||||
Self::new_generic(WidthCounterPair(4, counter as u32), fractions)
|
||||
}
|
||||
|
||||
@ -1384,7 +1384,7 @@ mod tests {
|
||||
fn from_unix_stamp() {
|
||||
let unix_stamp = UnixTime::new(0, 0);
|
||||
let cuc =
|
||||
CucTime::from_unix_stamp(&unix_stamp, FractionalResolution::Seconds, LEAP_SECONDS)
|
||||
CucTime::from_unix_time(&unix_stamp, FractionalResolution::Seconds, LEAP_SECONDS)
|
||||
.expect("failed to create cuc from unix stamp");
|
||||
assert_eq!(
|
||||
cuc.counter(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user