fm.liveswitch.NetworkTimeProtocol Class Reference

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

Public Member Functions

java.util.Date compactNtpToDateTime (long ntp)
 Converts a compact NTP timestamp (32 bits) to a date. More...
 
long compactNtpToTicks (long ntp)
 Converts a compact NTP timestamp (32 bits) to ticks. More...
 
long dateTimeToCompactNtp (java.util.Date dateTime)
 Converts a date to a compact NTP timestamp (32 bits). More...
 
long dateTimeToNtp (java.util.Date dateTime)
 Converts a date to an NTP timestamp (64 bits). More...
 
double dateTimeToNtpSeconds (java.util.Date dateTime)
 Converts a date to an NTP timestamp (double). More...
 
long getUtcNow ()
 Gets the current UTC time in NTP format. More...
 
 NetworkTimeProtocol ()
 Initializes a new instance of the fm.liveswitch.NetworkTimeProtocol class with base set to 1900-01-01. More...
 
 NetworkTimeProtocol (long baseTicks)
 Initializes a new instance of the fm.liveswitch.NetworkTimeProtocol class. More...
 
java.util.Date ntpSecondsToDateTime (double ntpSeconds)
 Converts an NTP timestamp (double) to a date. More...
 
long ntpSecondsToTicks (double ntpSeconds)
 Converts an NTP timestamp (double) to ticks. More...
 
java.util.Date ntpToDateTime (long ntp)
 Converts an NTP timestamp (64 bits) to a date. More...
 
long ntpToTicks (long ntp)
 Converts an NTP timestamp (64 bits) to ticks. More...
 
long ticksToCompactNtp (long ticks)
 Converts ticks to a compact NTP timestamp (32 bits). More...
 
long ticksToNtp (long ticks)
 Converts ticks to an NTP timestamp (64 bits). More...
 
double ticksToNtpSeconds (long ticks)
 Converts ticks to an NTP timestamp (double). More...
 

Static Public Member Functions

static fm.liveswitch.NetworkTimeProtocol getAbsolute ()
 Gets an instance of fm.liveswitch.NetworkTimeProtocol that uses 1900-01-01 as the reference date, for use cases where the absolute wall-clock time represented is important. More...
 
static fm.liveswitch.NetworkTimeProtocol getRelative ()
 Gets an instance of fm.liveswitch.NetworkTimeProtocol 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.

Constructor & Destructor Documentation

◆ NetworkTimeProtocol() [1/2]

fm.liveswitch.NetworkTimeProtocol.NetworkTimeProtocol ( )

Initializes a new instance of the fm.liveswitch.NetworkTimeProtocol class with base set to 1900-01-01.

◆ NetworkTimeProtocol() [2/2]

fm.liveswitch.NetworkTimeProtocol.NetworkTimeProtocol ( long  baseTicks)

Initializes a new instance of the fm.liveswitch.NetworkTimeProtocol class.

Parameters
baseTicksThe base ticks.

Member Function Documentation

◆ compactNtpToDateTime()

java.util.Date fm.liveswitch.NetworkTimeProtocol.compactNtpToDateTime ( long  ntp)

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

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

◆ compactNtpToTicks()

long fm.liveswitch.NetworkTimeProtocol.compactNtpToTicks ( long  ntp)

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

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

◆ dateTimeToCompactNtp()

long fm.liveswitch.NetworkTimeProtocol.dateTimeToCompactNtp ( java.util.Date  dateTime)

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

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

◆ dateTimeToNtp()

long fm.liveswitch.NetworkTimeProtocol.dateTimeToNtp ( java.util.Date  dateTime)

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

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

◆ dateTimeToNtpSeconds()

double fm.liveswitch.NetworkTimeProtocol.dateTimeToNtpSeconds ( java.util.Date  dateTime)

Converts a date to an NTP timestamp (double).

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

◆ getAbsolute()

static fm.liveswitch.NetworkTimeProtocol fm.liveswitch.NetworkTimeProtocol.getAbsolute ( )
static

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

◆ getRelative()

static fm.liveswitch.NetworkTimeProtocol fm.liveswitch.NetworkTimeProtocol.getRelative ( )
static

Gets an instance of fm.liveswitch.NetworkTimeProtocol 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.

◆ getUtcNow()

long fm.liveswitch.NetworkTimeProtocol.getUtcNow ( )

Gets the current UTC time in NTP format.

◆ ntpSecondsToDateTime()

java.util.Date fm.liveswitch.NetworkTimeProtocol.ntpSecondsToDateTime ( double  ntpSeconds)

Converts an NTP timestamp (double) to a date.

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

◆ ntpSecondsToTicks()

long fm.liveswitch.NetworkTimeProtocol.ntpSecondsToTicks ( double  ntpSeconds)

Converts an NTP timestamp (double) to ticks.

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

◆ ntpToDateTime()

java.util.Date fm.liveswitch.NetworkTimeProtocol.ntpToDateTime ( long  ntp)

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

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

◆ ntpToTicks()

long fm.liveswitch.NetworkTimeProtocol.ntpToTicks ( long  ntp)

Converts an NTP timestamp (64 bits) to ticks.

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

◆ ticksToCompactNtp()

long fm.liveswitch.NetworkTimeProtocol.ticksToCompactNtp ( long  ticks)

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

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

◆ ticksToNtp()

long fm.liveswitch.NetworkTimeProtocol.ticksToNtp ( long  ticks)

Converts ticks to an NTP timestamp (64 bits).

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

◆ ticksToNtpSeconds()

double fm.liveswitch.NetworkTimeProtocol.ticksToNtpSeconds ( long  ticks)

Converts ticks to an NTP timestamp (double).

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