Ben Beuchler <[EMAIL PROTECTED]> writes:
> OK. I can see where that is a strong argument for TAI64n. I have tried
> to develop a way of converting from TAI64n to a human readable format
> but I'm afraid I'm having difficulty comprehending the format. Has
> anyone written any perl/python code that translates to a human readable
> format? Or can offer a brief "pseudo-code" algorithm?
Here is some stuff that I use in perl scripts. There is plenty to
criticise here. It assumes a 32-bit platform and fails after 2038.
It is much less efficient than tai64nlocal. Handy if you just need
to output some lines that the script has selected, though.
# Simplistic tai64n converter. Returns float time_t value or undef.
sub tai64n {
my(@x) = map { unpack "N", pack "H8", $_ }
$_[0] =~ /^\@?([0-9a-f]{8})([0-9a-f]{8})([0-9a-f]{8})/;
return unless @x == 3 and $x[0] == 0x40000000;
$x[1]+$x[2]/1_000_000_000;
}
# replace tai64n timestamp at beginning of line and print result
sub putline {
my($stamp,$msg) = $_[0] =~ /^(\S+) (.*)/;
$stamp = tai64n($stamp);
my $int = int($stamp);
my $frac = int(($stamp-$int)*1_000_000_000);
my @t = localtime $int;
printf("%d-%02d-%02d %02d:%02d:%02d.%09d %s\n",
$t[5]+1900,$t[4]+1,@t[3,2,1,0],$frac,$msg);
}
--
Frank Cringle, [EMAIL PROTECTED]
voice: (+49 2304) 467101; fax: 943357