Date: Tue, 15 Aug 2000 23:42:18 -0500
From: Ben Beuchler <[EMAIL PROTECTED]>
I've read and reread DjB's documentation of the format and still find it
quite confusing. For example, I still do not understand the
significance of the first eight bytes of the stamp. I think it is the
reference point for the second four bytes, but why is it necessary? Why
would the reference point change? Why not select an arbitrary point in
time and make it the reference point?
tai64n is tai64 followed by a number of nanoseconds. tai64 is a 64
bit number. In external format, this is 24 hexadecimal digits. The
first 16 hex digits are the tai64 portion. The last 8 hex digits are
the number of nanoseconds. The web page refers to these 24 hex digits
as 12 bytes--8 bytes for tai64 and 4 bytes for the nanoseconds.
Here is a recent tai64n timestamp: 40000000399a2c15230e6f14. The
tai64 portion is 40000000399a2c15. This is 2^62 + 0x399a2c15. This
is between 2^62 and 2^63, so this represents the second 0x399a2c15
seconds after the beginning of 1970. The rest of the timestamp is is
0x230e6f14 == 588148500. So this tai64n label represents
August 16, 2000 05:52:21.5881485 +0000
Your questions about the reference point seem to indicate some
confusion. I'm not sure what you are getting at. DJB did pick an
arbitrary reference point: he picked January 1, 1970, the same
reference point as is used for the Unix epoch. The first 8 bytes,
minus 2^62, give the number of seconds since January 1, 1970. The
last 4 bytes give the number of nanoseconds since the start of that
second. There are one (American) billion nanoseconds in one second,
so 4 bytes is enough.
I would also appreciate it if someone could sketch out some pseudo-code
for working with tai64n. A task I have frequently wished I could
perform would be slicing out a section of a log file covering a
specified time range. Since I do not know C, I do not have the luxury
of using libtai. So I guess I would need a way of converting a specific
time to it's tai64n equivalent.
Well, here is a trivial way to do that using GNU date, restricted to
times before the year 2038, ignoring nanoseconds:
echo 40000000`(echo obase = 16; date +%s) | bc`00000000
Here I use "date +%s" to convert the current time into the number of
seconds since January 1, 1970. The --date option can be used to pick
any other time. Then I prepend 40000000 to effectively add 2^62, and
I use zeroes to pick out the start of the given second.
Ian