# How do I use the RtiNtpTime structure?

Note:Applies to NDDS 3.x.

NDDS's internal time representation is in NTP format rather than `DDS_Time`

for computational efficiency reasons.

The header *osapi/osapi_ntptime.h* defines NTP time class (`struct RTINtpTime`

) as well as its manipulation methods. A brief excerpt from this header file is given below:

`struct RTINtpTime`

defines a structure used to represent times and time intervals as seconds and binary fractions ( `1/2^32-ths`

) of a second. (`Ntp`

is used because the format is the same as the one used by the Network Time Protocol standard.)

Here is a very brief synopsis of the supported functions/macros:

RTINtpTime_add(ANSWER, T1, T2)

Sets `ANSWER`

to `T1`

+ `T2`

.

RTINtpTime_compare(TIME1, TIME2)

Returns an integer that is

- < 0 if
`TIME1`

<`TIME2`

, - 0 if
`TIME1 == TIME2`

, - > 0 if
`TIME1 > TIME2`

.

RTINtpTime_compareToZero(TIME)

Returns an integer that is

- < 0 if
`TIME < 0`

, - 0 if
`TIME == 0`

, - > 0 if
`TIME > 0`

.

RTINtpTime_decrement(ANSWER, TIME)

Sets `ANSWER`

to `ANSWER - TIME`

.

RTINtpTime_increment(ANSWER, TIME)

Sets `ANSWER`

to `ANSWER - TIME`

.

RTINtpTime_incrementInfinitesimally(TIME)

Increases `TIME`

by a very small amount.

RTINtpTime_isInfinite(TIME)

Returns true if `TIME`

is infinitely large.

RTINtpTime_packFromFraction(TIME, NUMERATOR, DENOMINATOR_PER_SEC)

Sets `TIME`

to (approximately) `NUMERATOR / DENOMINATOR_PER_SEC`

seconds.

RTINtpTime_packFromMillisec(TIME, S, MSEC)

Sets `TIME`

to `S`

seconds and `MSEC`

milliseconds (1/1000 sec).

RTINtpTime_packFromMicrosec(TIME, S, USEC)

Sets `TIME`

to `S`

seconds and `USEC`

microseconds (1/1000000 sec).

RTINtpTime_packFromNanosec(TIME, S, NSEC)

Sets `TIME`

to `S`

seconds and `NSEC`

nanoseconds (1/1000000000 sec).

RTINtpTime_setMax(TIME)

Sets `TIME`

to the largest possible value (which is considered infinite).

RTINtpTime_setZero(TIME)

Sets `TIME`

to zero.

RTINtpTime_shiftLeft(ANSWER, TIME, SHIFT)

Sets `ANSWER`

to `TIME * 2^SHIFT`

.

RTINtpTime_shiftRight(ANSWER, TIME, SHIFT)

Sets `ANSWER`

to `TIME / 2^SHIFT`

.

RTINtpTime_subtract(ANSWER, T1, T2)

Sets `ANSWER`

to `T1 - T2`

.

RTINtpTime_toDouble(T)

Converts `T`

(an `RTINtpTime`

) to a `double`

and returns the result.

RTINtpTime_toString(T, STR)

Writes a string representation of `T`

to `STR`

, which should be a `char*`

. `STR`

must be at least `RTI_NTP_TIME_STRING_LEN`

characters long.

RTINtpTime_unpackToFraction(NUMERATOR, DENOMINATOR_PER_SEC, TIME)

Sets `NUMERATOR`

to (approximately) `TIME * DENOMINATOR_PER_SEC`

.

RTINtpTime_unpackToMillisec(S, MSEC, TIME)

Converts `TIME`

to seconds and milliseconds; set `S`

and `MSEC`

to the result.

RTINtpTime_unpackToMicrosec(S, USEC, TIME)

Converts `TIME`

to seconds and microseconds; set `S`

and `USEC`

to the result.

RTINtpTime_unpackToNanosec(S, NSEC, TIME)

Converts `TIME`

to seconds and nanoseconds; set `S`

and `NSEC`

to the result.