/* pfh 2/14/01

   rewrite of 'days' program using libdate from sourceforge.

   Hardwired to use my birthday, not hard to change this though.
   
*/

#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <time.h>


#include "date.h"

int main(int argc, char *argv[])
{
    DT_DATE       *d_bd = NULL;
    DT_DATE       *d_now = NULL;
    unsigned int  days_old = 0;
    time_t        t_now;
    struct tm     *t_tm_now = NULL;
    int           year = 0;
    int           mon = 0;
    int           day = 0;
    

    // Did they specify a birthday on the command line?
    if(argc != 4)
    {
	printf("\nIncorrent arguments.\nSyntax: %s year month day\n",
	       argv[0]);
	printf("e.g. %s 1976 4 27\n\n", argv[0]);
	return(1);
    }

    year = atoi(argv[1]);
    mon = atoi(argv[2]);
    day = atoi(argv[3]);
    
    // Create DT-formatted date of birthday
    d_bd = DT_mkdate(year, mon, day);

    // Get time right now, localize
    t_now = time(NULL);
    t_tm_now = localtime(&t_now);

    // Convert now to DT format
    d_now = DT_mkdate((t_tm_now->tm_year + 1900),
		      (t_tm_now->tm_mon + 1),
		      t_tm_now->tm_mday);
    if((d_bd == NULL) || (d_now == NULL))
    {
	printf("\nError creating dates - malloc failure?\n");
	return(1);
    }
    
    days_old = DT_days_between(d_now, d_bd);

    printf("\nBirthday: %s", DT_ascii(d_bd, DT_US_FORMAT));
    printf("\nToday is %s and you are %d days old.\n\n",
	   DT_ascii(d_now, DT_US_FORMAT), days_old);

    DT_rmdate(d_bd);
    DT_rmdate(d_now);

    return(0);
}

    
	

	
    


syntax highlighted by Code2HTML, v. 0.8.8b