//-----------------------------------------------------------------------------
// Copyright © 2004 - Philip Howard - All rights reserved
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//-----------------------------------------------------------------------------
// package	libh/time
// homepage	http://libh.slashusr.org/
//-----------------------------------------------------------------------------
// author	Philip Howard
// email	libh at ipal dot org
// homepage	http://phil.ipal.org/
//-----------------------------------------------------------------------------
// This file is best viewed using a fixed spaced font such as Courier
// and in a display at least 120 columns wide.
//-----------------------------------------------------------------------------

#include "time_lib.h"

#include <libh/string.h>

__PROTO_BEGIN__
//-----------------------------------------------------------------------------
// function	etime_to_fprintf
//
// purpose	Convert an Earth Time value to a formatted string and output.
//
// arguments	1 (FILE *) which file to write to
//		2 (const char *) format string
//		3 (etime_t) Earth Time value
//
// returns	(int) return value from fputs()
//
// format	The format string is copied with format specifiers replaced
//		with character expressions of the specified date or time
//		component.  The available specifiers are:
//		%g	Specify Gregorian calendar (no output)
//		%j	Specify Julian calendar (no output)
//		%l	Specify lower case conversion (no output)
//		%u	Specify upper case conversion (no output)
//		%n	Specify no case conversion (no output)
//		%E	(1) Earth Time as a decimal number
//		%e	(1) Earth Day as a decimal number
//		%t	(1) System time as a decimal number (e.g. time())
//		%J	(1,0) Julian Date (floating point format)
//		%Y	(04) Year number in the specified calendar
//		%Z	(04) Year number with BC if needed
//		%m	(02) Month number in the specified calendar
//		%d	(02) Day of month in the specified calendar
//		%D	(03) Day of year in the specified calendar
//		%w	(1) Day of week number (0=Sunday, 6=Saturay)
//		%W	(02) Week number in the year (0..53)
//		%A	Day of week name full
//		%a	Day of week name abbreviated
//		%B	Month of year name full
//		%b	Month of year name abbreviated
//		%H	(02) Hours (00..23) of day
//		%M	(02) Minutes (00..59) of hour
//		%S	(02) Seconds (00..59) of minute
//		%F	(03) Fractions of a second (default milliseconds)
//		%U	(06) Fractions of a second (default microseconds)
//		%N	(09) Fractions of a second (default nanoseconds)
//		%s	(05) Seconds (00000..86401) of day
//		%L	(06) Lilian day (LDAY, IBM Y2K hack)
//		%X	(06) eXchange day (XDAY, Bob Bemer Y2K hack)
//		%I	(02) Hour (12,01..11) of meridian
//		%p	Meridian hour designator, AM or PM
//		%T	short form for "%H:%M:%S"
//		%r	short form for "%I:%M:%S %p"
//		%%	Literal "%" character
//
// note		Although many specifiers are the same as those defined for
//		use in strftime(), many others are different.
//
// modifiers	A sequence of decimal digits may modify the minimum size
//		and leading character for fields.  Some default to a normal
//		size and this may be overridden.  For example, the day of
//		month defaults to a size specifier of "02" if none is given.
//		To force a date to have 1 digit when less than 10, use "1"
//		as the modifier like "%1d".
//-----------------------------------------------------------------------------
int
etime_to_fprintf (
    FILE *		arg_file
    ,
    const char *	arg_format
    ,
    etime_t		arg_etime
    )
__PROTO_END__
{
    size_t	len	;
    char	buf	[4096];

    buf[0] = 0;
    if ( ( len = etime_to_str_app( buf, sizeof (buf), arg_format, arg_etime ) ) == ~ (size_t) 0 ) return 0;
    return fputs( buf, arg_file );
}

