/* expirationdate.c 
** a quick hack to print out the value of a 
** time_t for the time 'now'
** plus an offset
*/

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

main(int argc, char **argv){
    time_t now;
    time_t offset = 0;
    int bozo=0;
    char **argptr;
    int multiplier;
    int timeunit;
    int arglen;

    for( argptr = argv+1; *argptr != NULL;argptr++){
	if(**argptr == '+'){
	    arglen=strlen(*argptr);
	    timeunit = 1;
	    switch( *(*argptr + arglen -1) ){
		case 'M':  timeunit *= 4;
		case 'w':  timeunit *= 7;
		case 'd':  timeunit *=24;
		case 'h':  timeunit *=60;
		case 'm':  timeunit *=60;
		    multiplier = atoi(*argptr);
		    offset += timeunit * multiplier;
		    break;
		default:
		    printf(" %s is an invalid option\n", *argptr);
		    bozo++;
	    }
	} else {
	    printf(" %s is an invalid option\n", *argptr);
	    bozo++;
	}
    }
    if(bozo){
	printf("%s usage:\n [offset options] ", *argv[0]);
	printf(" +#M	Add '#' 28 day 'months' \n");
	printf(" +#w	Add '#' weeks \n");
	printf(" +#d	Add '#' days \n");
	printf(" +#h	Add '#' hours \n");
	printf(" +#m	Add '#' minutes \n");
    }
    now = time(NULL);

    offset += now;
    

    printf(" The time with that offset added will be %ul (%s)\n", offset, 
	ctime(&offset));
}
