/* mod_pgsqllog.c version 1.3 under */
/* /web_servers/apache/programming/c/mod_pgsqllog */
/*
// epoch_timestamp()
//
// Internal function to convert a integer timestamp value (epoch) to readable timestamp.
// Format used is yy/mm/dd hh/mm/ss UTC offset, which may need to be
// modified for specific PostgreSQL setups. Returns timestamp string.
//
// timer - epoch integer value to convert
//
// Contributed by Brian Holman (me@brianholman.com)
*/
const char *
epoch_timestamp (time_t timer)
{
struct tm *tblock;
static char tmstr[MAX_TIMESTAMP_LEN];
#ifdef _TRACE_C_CALLS
fprintf (stderr,
"%s DEBUG: epoch_timestamp() (file: %s, line: %i)\n",
MODULE_NAME, __FILE__, __LINE__);
#endif
if ((tblock = localtime (&timer)) == NULL)
{
fprintf (stderr,
"%s ERROR: Failed to convert value %i to tm struct: localtime()\n",
timer);
return ("NULL");
}
if (strftime (tmstr, MAX_TIMESTAMP_LEN, "%G-%m-%d %H:%M:%S %Z", tblock)
== 0)
{
fprintf (stderr,
"%s ERROR: Failed to convert value %i into timestamp: strftime()\n",
timer);
return ("NULL");
}
return (tmstr);
}
return to top