//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
// reference	Explanatory Supplement to the Astronomical Almanac,
//		P. Kenneth Seidelmann, editor  [ISBN 0-935702-68-7]
//		http://shop.bn.com/bookSearch/isbnInquiry.asp?isbn=0935702687
//-----------------------------------------------------------------------------

#include <ctype.h>

#include "time_lib.h"

__PROTO_BEGIN__
//-----------------------------------------------------------------------------
// function	ecal_to_tm
//
// purpose	Convert an struct ecal to struct tm.
//
// arguments	1 (ecal_t *) Ecal struct pointer
//		2 (struct tm *) pointer to struct tm to store into
//
// returns	(void)
//
// warning	Since Standard C defines struct tm generally in terms of it
//		being converted from, or to, type time_t, programs might be
//		expecting the values in struct tm to be restricted to the same
//		range of dates.  Implementations of conversion from struct tm
//		to strings (e.g. strftime()) may be limited in that way due to
//		use of type time_t to do necessary calculations, and lack of a
//		standard requirement for a greater range.
//
//		The ecal_to_tm() function will apply the full scale of years
//		to struct tm, which may not be handled properly by programs
//		and functions not supporting that range.  The range of years
//		supported by Earth Day is over 11 million years.
//-----------------------------------------------------------------------------
void
ecal_to_tm (
    ecal_t *		arg_ecal_p
    ,
    struct tm *		arg_tm_p
    )
__PROTO_END__
{
    if ( ! arg_ecal_p ) return;
    if ( ! arg_tm_p ) return;

    arg_tm_p->tm_year	= arg_ecal_p->year - 1900;
    arg_tm_p->tm_mon	= arg_ecal_p->month - 1;
    arg_tm_p->tm_yday	= arg_ecal_p->yday;
    arg_tm_p->tm_mday	= arg_ecal_p->mday;
    arg_tm_p->tm_wday	= arg_ecal_p->wday;
    arg_tm_p->tm_hour	= arg_ecal_p->hour;
    arg_tm_p->tm_min	= arg_ecal_p->min;
    arg_tm_p->tm_sec	= arg_ecal_p->sec;
    arg_tm_p->tm_isdst	= 0;

    return;
}

