<?xml version="1.0" encoding="UTF-8"?>
<!-- **************************************************************************
.... For copyright and licensing terms, see the file named COPYING.
.... **************************************************************************
.-->
<?xml-stylesheet href="docbook-xml.css" type="text/css"?>

<refentry id="tai64n">

<refmeta xmlns:xi="http://www.w3.org/2001/XInclude">
<refentrytitle>tai64n</refentrytitle>
<manvolnum>1</manvolnum>
<refmiscinfo class="manual">user commands</refmiscinfo>
<refmiscinfo class="source">nosh</refmiscinfo>
<xi:include href="version.xml" />
</refmeta>

<refnamediv>
<refname>tai64n</refname>
<refpurpose>filter to prepend external TAI64N timestamps</refpurpose>
</refnamediv>

<refsynopsisdiv>
<cmdsynopsis>
<command>tai64n</command>
<arg choice='opt' rep='repeat'><replaceable>files</replaceable></arg>
</cmdsynopsis>
</refsynopsisdiv>

<refsection><title>Description</title>

<para>
<command>tai64n</command> reads a series of lines.
To each line it prefixes an <code>@</code> character, a TAI64N timestamp in external form (16 hexadecimal digits of seconds and 8 hexadecimal digits of nanoseconds), and a space.
</para>

<para>
If no <replaceable>files</replaceable> are supplied, <command>tai64n</command> reads from its standard input until EOF.
Otherwise it processes each named file in turn.
In both cases it writes to its standard output.
</para>

<para>
A trailing newline is silently added to any file (or to standard input) that ends with a partial line.
</para>

<para>
The timestamp is the time when <command>tai64n</command> processes the beginning of a line, which is slightly after it has read the beginning of that line.
<command>tai6n</command> uses the <code>CLOCK_REALTIME</code> clock of the <citerefentry><refentrytitle>clock_gettime</refentrytitle><manvolnum>2</manvolnum></citerefentry> system call.
On many systems this has nanosecond resolution.
</para>

<para>
<command>tai64n</command> attempts to generate correct TAI64N timestamps.
On a Linux system where it detects an Olson "right" timezone currently in use, it knows that the system clock is TAI seconds since the Epoch and performs a simple conversion.
On other Linux systems, and on BSDs, it assumes that the system clock is UTC seconds since the Epoch and attempts to correct for (known) UTC leap seconds in order to determine TAI.
</para>

<para>
<command>tai64n</command> uses the C/C++ runtime library for output, and therefore has the normal C/C++ stream buffering semantics.
It uses the <citerefentry><refentrytitle>read</refentrytitle><manvolnum>2</manvolnum></citerefentry> library function for input, however.
To duplicate the GNU and BSD C/C++ runtime libraries' behaviours, it explicitly flushes the output's buffer whenever it is about to read more input and that input is the beginning of a new line.
</para>

</refsection><refsection><title>Compatibility</title>

<para>
daemontools' and daemontools-encore's <citerefentry><refentrytitle>tai64n</refentrytitle><manvolnum>1</manvolnum></citerefentry> uses a timer with only microsecond resolution, and for the same events will thus produce different timestamps to <command>tai64n</command>.
</para>

<para>
See <ulink url="timestamps.html">the <citetitle>timestamps</citetitle> section of the nosh Guide</ulink> for detailed information on the differences from daemontools, daemontools-encore, and other toolsets in how <command>tai64nlocal</command> handles TAI.
</para>

</refsection><refsection><title>Author</title>
<para><author><personname><firstname>Jonathan</firstname> <surname>de Boyne Pollard</surname></personname></author></para>
</refsection>

</refentry>
