/*      ctypes.c                           25.02.04       */
/*
/  --------------------------------------------------------
/  COPYRIGHT (C) 2004
/  --------------------------------------------------------
/
/  HIER/SACHN: 
/  BENENNUNG : __________________________________________________
/  ERSTELLER : M.Braun - Socon GmbH
/  FREIGABE  :
/  AEND/STAND: 25.02.04
/  PRUEFVERM.:
/
/
/  SCHNITTSTELLE UND AUFGABENBESCHREIBUNG:
/  ---------------------------------------
/    
/
/  SPRACHE: C
/  
/  NAME UND STRUKTUR DER EINGABEPARAMETER:
/
/
/  NAME UND STRUKTUR DER AUSGABEPARAMETER:
/ 
/
/  AUFGABENBESCHREIBUNG:
/
*/


/* include files */

#include <stdlib.h>
#include <stdio.h>
#include <time.h>


static show_datetime(time_t act_time)
{
struct tm * tm0;

    printf ("time = %10d, ", act_time);

    printf ("mod 86400 = %5d, ", act_time % 86400);

    tm0 = localtime (&act_time);
    printf ("date / time = %02d.%02d.%04d / ",
             tm0->tm_mday,
             tm0->tm_mon + 1,
             tm0->tm_year + 1900);

    printf ("%02d:%02d:%02d \n",
             tm0->tm_hour,
             tm0->tm_min,
             tm0->tm_sec);

}  /* show_datetime */


int main(int argc, char *argv[])
{
time_t act_time;

	printf ("\nprogram datetime - M. Braun - %s / %s \n", __DATE__, __TIME__);

	printf ("show actual date / time \n\n");
	system("date");
	printf ("\n");

    if (argc > 1) act_time = atoi(argv[1]);
    else          act_time = 0;


    show_datetime(0);
    show_datetime(time(NULL));
	printf ("\n");
    show_datetime(389055600-7*3600+1800-1);
    show_datetime(389055600-7*3600+1800);
	printf ("\n");
    show_datetime(389055600-3600-1);
    show_datetime(389055600-3600);
	printf ("\n");

    if (act_time != 0) show_datetime(act_time);
    else               printf ("no optional argument given <no of seconds since epoch> \n");


	printf ("\n");

	exit (0);
	return (0);
}  /* main */

