.and_time()
moves on to Datelike and a lot of .timestamp*()
methods move on to a new DateTimelike) but it's fairly drastic.
Period
and NaivePeriod
. Otherwise you could move a lot of functionality into Datelike/Timelike/DateTimelike or you could do away with Naive* entirely in some way (either by assuming UTC unless otherwise specified or by making the TimeZone inside a Date/Time/DateTime be an Option of some kind).
RUST_BACKTRACE=1
thread 'main' panicked at 'No such local time', /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/chrono-0.4.11/src/offset/mod.rs:173:34
stack backtrace:
0: std::panicking::begin_panic
1: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
2: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
3: <tokio::future::poll_fn::PollFn<F> as core::future::future::Future>::poll
4: exchange_data_capture::spreader_runner::start_spreader::{{closure}}
5: <tokio::future::maybe_done::MaybeDone<Fut> as core::future::future::Future>::poll
6: <tokio::future::poll_fn::PollFn<F> as core::future::future::Future>::poll
7: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
8: std::thread::local::LocalKey<T>::with
9: tokio::runtime::enter::Enter::block_on
10: tokio::runtime::thread_pool::ThreadPool::block_on
11: tokio::runtime::context::enter
12: grpc_server::main
NaiveTime::parse_from_str
, at least hour and minutes are required for it to suceed. I want to parse a time which is expressed only with the hour (9PM), which I think can be widely understood to mean 21:00:00. What is the reason behind not allowing this kind of common notation?
HH:MM:[SS]
and SS is optional ?
#[derive(Debug, ByteMe, PartialEq, Eq, Clone, Copy)]
pub struct NtpTimestamp {
/// 32 bit representation in seconds
pub seconds: u32,
/// 32 bit representation after seconds
pub fraction: u32,
}
/// Basic implentation. Taken from
/// Converts a NTP timestamp to a DateTime
/// https://books.google.com.pk/books?id=x1w4EAAAQBAJ&pg=PA319&lpg=PA319&dq=impl+From%3CNtpTimeStamp%3E+for+DateTime%3CUtc%3E+rust&source=bl&ots=O0MEZZr9fH&sig=ACfU3U1KkmXgxHkjc44EQ1CL1ayo6EqwJA&hl=en&sa=X&ved=2ahUKEwjnzLDLk4f0AhVSRBoKHdkSBUIQ6AF6BAgZEAM#v=onepage&q&f=false
impl From<NtpTimestamp> for DateTime<Utc> {
fn from(ntp_timestamp: NtpTimestamp) -> Self {
let seconds = ntp_timestamp.seconds as i64 - PRIME_EPOCH_DELTA as i64;
let mut nanos = ntp_timestamp.fraction as f64;
println!("{}", nanos as u32);
nanos *= 1e9;
nanos /= 2_f64.powi(32);
println!("{}", nanos as u32);
Utc.timestamp(seconds, nanos as u32)
}
}
/// Convert a DateTime to a NTP timestamp
impl From<DateTime<Utc>> for NtpTimestamp {
fn from(dt: DateTime<Utc>) -> Self {
let seconds = dt.timestamp() as i64 + PRIME_EPOCH_DELTA as i64;
let fraction = dt.nanosecond() as f64;
let fraction = (fraction * 2_f64.powi(32)) / 1e9;
println!("{:?}", fraction as u32);
NtpTimestamp {
seconds: seconds as u32,
fraction: fraction as u32,
}
}
}
impl NtpTimestamp {
/// Create an NTP timestamp from a DateTime
pub fn new(seconds: u32, fraction: u32) -> Self {
NtpTimestamp { seconds, fraction }
}
/// Get the current NTP timestamp
pub fn now() -> Self {
let now = Utc::now();
NtpTimestamp::from(now)
}
}
num-iter = { version = "0.1.35", default-features = false }
dependency? from what i saw it used in tests for calls like range_inclusive(1u32, 366)
. Can it be just replaced with 1u32..=366 syntax and get rid of it? or what consideration i am missing?