[−][src]Struct rsntp::SynchronizationResult
Results of a synchronization.
If you just simply need a fairly accurate SNTP time then check the datetime()
method. Other methods
provide more detailed information received from the server and might need deeper knwoledge about
SNTP protocol internals.
Methods
impl SynchronizationResult
[src]
pub fn clock_offset(&self) -> Duration
[src]
Returns with the offset between the server and local clock.
It is a signed duration, negative value means the local clock is ahead.
Example
Print the synchronized local time using clock offset:
use rsntp::SntpClient; use chrono::Local; let client = SntpClient::new(); let result = client.synchronize("pool.ntp.org").unwrap(); println!("Local time: {}", Local::now() + result.clock_offset());
pub fn round_trip_delay(&self) -> Duration
[src]
Returns with the round trip delay
The time is needed for SNTP packets to travel back and forth between the host and the server. It is a signed value but negative values should not be possible in client mode (which is currently always used by the library).
Example
use rsntp::SntpClient; use chrono::Local; let client = SntpClient::new(); let result = client.synchronize("pool.ntp.org").unwrap(); println!("RTT: {} ms", result.round_trip_delay().num_milliseconds());
pub fn reference_identifier(&self) -> &ReferenceIdentifier
[src]
Returns with the server reference identifier.
This identifies the synchronizaion source of the server. For primary servers (startum = 1) this is a four byte ASCII string, for secondary IPv4 servers (startum >= 2) this is an IP address.
Example
use rsntp::SntpClient; use chrono::Local; let client = SntpClient::new(); let result = client.synchronize("pool.ntp.org").unwrap(); println!("Server reference identifier: {}", result.reference_identifier());
pub fn datetime(&self) -> DateTime<Utc>
[src]
Returns with the current UTC date and time, based on the synchronized SNTP timestamp.
This is the current UTC date and time, calculated by adding clock offset the UTC time. To be accurate, use the returned value immediately after the call of this function.
Example
Calcuating synchronized local time:
use rsntp::SntpClient; use chrono::{DateTime, Local}; let client = SntpClient::new(); let result = client.synchronize("pool.ntp.org").unwrap(); let local_time: DateTime<Local> = DateTime::from(result.datetime());
pub fn leap_indicator(&self) -> LeapIndicator
[src]
Returns with the leap indicator
This is the leap indicator returned by the server. It is a warning of an impending leap second to be inserted/deleted in the last minute of the current day.
It is set before 23:59 on the day of insertion and reset after 00:00 on the following day. This causes the number of seconds (rollover interval) in the day of insertion to be increased or decreased by one.
Example
Printing leap indicator:
use rsntp::SntpClient; use chrono::{DateTime, Local}; let client = SntpClient::new(); let result = client.synchronize("pool.ntp.org").unwrap(); println!("Leap indicator: {:?}", result.leap_indicator());
pub fn stratum(&self) -> u8
[src]
Returns with the server stratum
NTP uses a hierarchical, semi-layered system of time sources. Each level of this hierarchy is termed a stratum and is assigned a number starting with zero for the reference clock at the top. A server synchronized to a stratum n server runs at stratum n + 1
Values defined as:
- 1 - Primary reference (e.g., calibrated atomic clock, radio clock, etc...)
- 2..15 - Secondary reference (via NTP, calculated as the stratum of system peer plus one)
- 16 - Unsynchronized
- 16..255 - Reserved
Example
use rsntp::SntpClient; use chrono::{DateTime, Local}; let client = SntpClient::new(); let result = client.synchronize("pool.ntp.org").unwrap(); assert!(result.stratum() >= 1);
Trait Implementations
impl Clone for SynchronizationResult
[src]
fn clone(&self) -> SynchronizationResult
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for SynchronizationResult
[src]
Auto Trait Implementations
impl RefUnwindSafe for SynchronizationResult
impl Send for SynchronizationResult
impl Sync for SynchronizationResult
impl Unpin for SynchronizationResult
impl UnwindSafe for SynchronizationResult
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,