|
|
|
@ -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,
|
|
|
|
|
)
|
|
|
|
|