Skip to main content

Module time

Module time 

Source
Expand description

The two timestamp formats the packet forwarder protocol prescribes.

An rxpk object times a packet’s reception in the ISO 8601 compact form with microsecond precision, 2013-03-31T16:21:17.528002Z, and a stat object times the gateway’s own clock in the expanded form 2014-01-12 08:59:28 GMT. Both are UTC, and the protocol carries both as strings, so these turn a count from the Unix epoch into one and read one back. The calendar arithmetic is Howard Hinnant’s days_from_civil and civil_from_days, which are exact for every year the protocol can carry.

§Examples

use pamoja_gateway::time;

// The reception time of the protocol's own rxpk example.
assert_eq!(time::compact(1_364_746_877_528_002), "2013-03-31T16:21:17.528002Z");
assert_eq!(time::from_compact("2013-03-31T16:21:17.528002Z"), Some(1_364_746_877_528_002));

// The gateway clock of its stat example.
assert_eq!(time::expanded(1_389_517_168), "2014-01-12 08:59:28 GMT");

Functions§

compact
Formats a reception time as an rxpk carries it: ISO 8601, compact, to the microsecond.
expanded
Formats a gateway’s clock as a stat carries it: the expanded form, to the second.
from_compact
Reads a compact timestamp back.
from_expanded
Reads an expanded timestamp back, as a stat object carries one.