[][src]Struct rsntp::SynchronizationResult

pub struct SynchronizationResult { /* fields omitted */ }

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 about the outcome of the synchronization and might need deeper knwoledge about SNTP protocol internals.

Implementations

impl SynchronizationResult[src]

pub fn clock_offset(&self) -> Duration[src]

Returns with the offset between 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, for secondary IPv6 servers this contains first 32 bits of an MD5 hash of an IPv6 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.

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]

impl Debug for SynchronizationResult[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.