FMLiveSwitchNetworkTimeProtocol Class Reference

Utility class to assist with Network Time Protocol (NTP) conversions. More...

Instance Methods

(NSDate *) - compactNtpToDateTimeWithNtp:
 Converts a compact NTP timestamp (32 bits) to a date. More...
 
(long long) - compactNtpToTicksWithNtp:
 Converts a compact NTP timestamp (32 bits) to ticks. More...
 
(long long) - dateTimeToCompactNtpWithDateTime:
 Converts a date to a compact NTP timestamp (32 bits). More...
 
(double) - dateTimeToNtpSecondsWithDateTime:
 Converts a date to an NTP timestamp (double). More...
 
(long long) - dateTimeToNtpWithDateTime:
 Converts a date to an NTP timestamp (64 bits). More...
 
(instancetype) - init
 Initializes a new instance of the FMLiveSwitchNetworkTimeProtocol class with base set to 1900-01-01. More...
 
(instancetype) - initWithBaseTicks:
 Initializes a new instance of the FMLiveSwitchNetworkTimeProtocol class. More...
 
(NSDate *) - ntpSecondsToDateTimeWithNtpSeconds:
 Converts an NTP timestamp (double) to a date. More...
 
(long long) - ntpSecondsToTicksWithNtpSeconds:
 Converts an NTP timestamp (double) to ticks. More...
 
(NSDate *) - ntpToDateTimeWithNtp:
 Converts an NTP timestamp (64 bits) to a date. More...
 
(long long) - ntpToTicksWithNtp:
 Converts an NTP timestamp (64 bits) to ticks. More...
 
(long long) - ticksToCompactNtpWithTicks:
 Converts ticks to a compact NTP timestamp (32 bits). More...
 
(double) - ticksToNtpSecondsWithTicks:
 Converts ticks to an NTP timestamp (double). More...
 
(long long) - ticksToNtpWithTicks:
 Converts ticks to an NTP timestamp (64 bits). More...
 
(long long) - utcNow
 Gets the current UTC time in NTP format. More...
 

Class Methods

(FMLiveSwitchNetworkTimeProtocol *) + absolute
 Gets an instance of FMLiveSwitchNetworkTimeProtocol that uses 1900-01-01 as the reference date, for use cases where the absolute wall-clock time represented is important. More...
 
(FMLiveSwitchNetworkTimeProtocol *) + networkTimeProtocol
 Initializes a new instance of the FMLiveSwitchNetworkTimeProtocol class with base set to 1900-01-01. More...
 
(FMLiveSwitchNetworkTimeProtocol *) + networkTimeProtocolWithBaseTicks:
 Initializes a new instance of the FMLiveSwitchNetworkTimeProtocol class. More...
 
(FMLiveSwitchNetworkTimeProtocol *) + relative
 Gets an instance of FMLiveSwitchNetworkTimeProtocol that uses zero as the reference date, for use cases where the time is relative to other times, and the reference time is not significant. More...
 

Detailed Description

Utility class to assist with Network Time Protocol (NTP) conversions.

NTP timestamps are 64-bit values that can span just over 136 years, from 1900-01-01 to 2036-02-08. Compact NTP timestamps are 32-bit values that can span span just over 18 hours. These utility methods guarantee precision to the millisecond.

Method Documentation

◆ absolute

Gets an instance of FMLiveSwitchNetworkTimeProtocol that uses 1900-01-01 as the reference date, for use cases where the absolute wall-clock time represented is important.

◆ compactNtpToDateTimeWithNtp:

- (NSDate*) compactNtpToDateTimeWithNtp: (long long)  ntp

Converts a compact NTP timestamp (32 bits) to a date.

Parameters
ntpThe NTP timestamp to convert.
Returns
The equivalent date.

◆ compactNtpToTicksWithNtp:

- (long long) compactNtpToTicksWithNtp: (long long)  ntp

Converts a compact NTP timestamp (32 bits) to ticks.

Parameters
ntpThe NTP timestamp to convert.
Returns
The equivalent ticks.

◆ dateTimeToCompactNtpWithDateTime:

- (long long) dateTimeToCompactNtpWithDateTime: (NSDate *)  dateTime

Converts a date to a compact NTP timestamp (32 bits).

Parameters
dateTimeThe date to convert.
Returns
The equivalent NTP timestamp.

◆ dateTimeToNtpSecondsWithDateTime:

- (double) dateTimeToNtpSecondsWithDateTime: (NSDate *)  dateTime

Converts a date to an NTP timestamp (double).

Parameters
dateTimeThe date to convert.
Returns
The equivalent NTP timestamp.

◆ dateTimeToNtpWithDateTime:

- (long long) dateTimeToNtpWithDateTime: (NSDate *)  dateTime

Converts a date to an NTP timestamp (64 bits).

Parameters
dateTimeThe date to convert.
Returns
The equivalent NTP timestamp.

◆ init

- (instancetype) init

Initializes a new instance of the FMLiveSwitchNetworkTimeProtocol class with base set to 1900-01-01.

◆ initWithBaseTicks:

- (instancetype) initWithBaseTicks: (long long)  baseTicks

Initializes a new instance of the FMLiveSwitchNetworkTimeProtocol class.

Parameters
baseTicksThe base ticks.

◆ networkTimeProtocol

+ (FMLiveSwitchNetworkTimeProtocol*) networkTimeProtocol

Initializes a new instance of the FMLiveSwitchNetworkTimeProtocol class with base set to 1900-01-01.

◆ networkTimeProtocolWithBaseTicks:

+ (FMLiveSwitchNetworkTimeProtocol*) networkTimeProtocolWithBaseTicks: (long long)  baseTicks

Initializes a new instance of the FMLiveSwitchNetworkTimeProtocol class.

Parameters
baseTicksThe base ticks.

◆ ntpSecondsToDateTimeWithNtpSeconds:

- (NSDate*) ntpSecondsToDateTimeWithNtpSeconds: (double)  ntpSeconds

Converts an NTP timestamp (double) to a date.

Parameters
ntpSecondsThe NTP timestamp to convert.
Returns
The equivalent date.

◆ ntpSecondsToTicksWithNtpSeconds:

- (long long) ntpSecondsToTicksWithNtpSeconds: (double)  ntpSeconds

Converts an NTP timestamp (double) to ticks.

Parameters
ntpSecondsThe NTP timestamp to convert.
Returns
The equivalent ticks.

◆ ntpToDateTimeWithNtp:

- (NSDate*) ntpToDateTimeWithNtp: (long long)  ntp

Converts an NTP timestamp (64 bits) to a date.

Parameters
ntpThe NTP timestamp to convert.
Returns
The equivalent date.

◆ ntpToTicksWithNtp:

- (long long) ntpToTicksWithNtp: (long long)  ntp

Converts an NTP timestamp (64 bits) to ticks.

Parameters
ntpThe NTP timestamp to convert.
Returns
The equivalent ticks.

◆ relative

Gets an instance of FMLiveSwitchNetworkTimeProtocol that uses zero as the reference date, for use cases where the time is relative to other times, and the reference time is not significant.

◆ ticksToCompactNtpWithTicks:

- (long long) ticksToCompactNtpWithTicks: (long long)  ticks

Converts ticks to a compact NTP timestamp (32 bits).

Parameters
ticksThe ticks to convert.
Returns
The equivalent NTP timestamp.

◆ ticksToNtpSecondsWithTicks:

- (double) ticksToNtpSecondsWithTicks: (long long)  ticks

Converts ticks to an NTP timestamp (double).

Parameters
ticksThe ticks to convert.
Returns
The equivalent NTP timestamp.

◆ ticksToNtpWithTicks:

- (long long) ticksToNtpWithTicks: (long long)  ticks

Converts ticks to an NTP timestamp (64 bits).

Parameters
ticksThe ticks to convert.
Returns
The equivalent NTP timestamp.

◆ utcNow

- (long long) utcNow

Gets the current UTC time in NTP format.