#ifndef NLV_PARSEDATE_INCLUDED
#define NLV_PARSEDATE_INCLUDED

#include "copyright.h"

/*
 ****************************************************************************
 *
 * parsedate.(c/h)
 *
 * All function(s) required for parsing netlogger timestamps:
 *
 *   - double calcDate( const char *)
 *   - double convertDate( long sec, long usec )
 *
 * $Author: mstoufer $
 * $Source: /home/g2/src/projects/NetLogger/src/nlv/parsedate.h,v $
 * $RCSfile: parsedate.h,v $
 * $Revision: 1.1.1.1 $
 * $Locker:  $
 * $Date: 2000/12/05 19:52:32 $
 *
 ****************************************************************************
 */

#include <stdio.h> /* for calcDate sscanf */
#include <time.h>  /* for convertDate fn */

#define DATE_STRING_LENGTH 21

/*========= FUNCTIONS ================================================*/

/*
 *---------------------------------------------------------------------------
 * calcDate -- Calculate date in sec. since 1/1/1970 from string.
 *             Algorithm borrowed from linux kernel source code,
 *             i.e. Linus Torvalds, who in turn credits it to Gauss.
 *
 * PRE: Input is properly formatted, non-null, need _not_ be null-terminated.
 * IN : String in format YYYYMMDDHHmmss.uuuuuu
 *        YYYY  = 4 digit year
 *        MM    = 2 digit month (1..12)
 *        DD    = 2 digit day of month (1..31)
 *        HH    = 2 digit hour of day ( 0..23 )
 *        mm    = 2 digit minute of hour ( 0..59 )
 *        ss    = 2 digit second of minute ( 0..59 )
 *        uuuuuu= 1..6 digit microsecond of second ( 0..999999 )
 * OUT: Number of seconds, and fraction accurate to at most microseconds,
 *      elapsed since 1/1/1970 (GMT).
 *---------------------------------------------------------------------------
 */
double Nlv_pdCalcDate( const char *s );
/* For a separate thread that doesn't want a mutex */
double Nlv_pdCalcDate2( const char *s );

/*
 *---------------------------------------------------------------------------
 * convertDate -- Take a seconds, microseconds argument and convert it
 *                to a date string that calcDate could parse.
 *
 * CALL: gmtime, strftime
 *
 * PRE : seconds, usec >= 0 , usec < 1000000 (checked)
 *       date string has DATE_STRING_LENGTH+1 bytes allocated (not checked)
 * IN  : seconds, useconds
 * OUT : date string 'dstr'.
 * RTRN: 0=OK, other=FAILURE
 * POST: This is the inverse of calcDate, i.e.
 *         calcDate( convertDate( sec, usec ) ) = sec.usec
 *---------------------------------------------------------------------------
 */
int Nlv_pdConvertDate( long sec, long usec, char *dstr );

#endif /* NLV_PARSEDATE_INCLUDED */
