Пример #1
0
int main(void)
{
	struct calendar birthday, today;
	int days;
	char* param;
	
	param = getParamString();
	if (param == NULL){
		printPage(ERROR, 0, NULL, NULL);
		return 0;
	}

	getParameter(param, &birthday);
	if (verifyDay(&birthday) == FAIL){
		perror("Birthday verification failed");
		printPage(INCORRECT, 0, NULL, NULL);
		return 0;
	}
	
	getToday(&today);
	if (verifyDay(&today) == FAIL){
		perror("Today verification failed");
		printPage(INCORRECT, 0, NULL, NULL);
		return 0;
	}
	
	if (isGreaterThan(birthday, today)){	// Birthday is future
		days = -computeDays(birthday, today);
	}else{
		days = computeDays(today, birthday);
	}

	printPage(SUCCESS, days, &birthday, &today);
	return 0;
}
Пример #2
0
/**
 * Compose a string indicating date of today in the format of SQL date:
 * "2009-02-19"
 */
char *getTodayToSQL()
{
    struct tm *today = getToday();
    char *date = (char *) malloc(21*sizeof(char));
    if (date == NULL) {
        perror("malloc error\n");
        exit(EXIT_FAILURE);
    }
    sprintf(date, "%d-%d-%d", today->tm_year+1900, today->tm_mon, today->tm_mday);

    return date;
}
Пример #3
0
/**
 * Compose a string indicating date of today in the format of date in the HTTP line:
 * "Thu, 19 Feb 2009 12:27:04 GMT"
 */
char *getTodayToHTTPLine()
{
    struct tm *today = getToday();
    char weekDay[3];
    char month[3];

    switch (today->tm_wday) {
        case 0:
            sprintf(weekDay,"Mon");
        break;
        case 1:
            sprintf(weekDay,"Tue");
            break;
        case 2:
            sprintf(weekDay,"Wed");
            break;
        case 3:
            sprintf(weekDay,"Thu");
            break;
        case 4:
            sprintf(weekDay,"Fri");
            break;
        case 5:
            sprintf(weekDay,"Sat");
            break;
        case 6:
            sprintf(weekDay,"Sun");
            break;
        default:break;
    }

    switch (today->tm_mon) {
        case 0:
            sprintf(month,"Jan");
            break;
        case 1:
            sprintf(month,"Feb");
            break;
        case 2:
            sprintf(month,"Mar");
            break;
        case 3:
            sprintf(month,"Apr");
            break;
        case 4:
            sprintf(month,"May");
            break;
        case 5:
            sprintf(month,"Jun");
            break;
        case 6:
            sprintf(month,"Jul");
            break;
        case 7:
            sprintf(month,"Aug");
            break;
        case 8:
            sprintf(month,"Sep");
            break;
        case 9:
            sprintf(month,"Oct");
            break;
        case 10:
            sprintf(month,"Nov");
            break;
        case 11:
            sprintf(month,"Dec");
            break;
        default:break;
    }

    char *date;
    date = (char *) malloc(50*sizeof(char)+1);
    if (date == NULL) {
        perror("error in malloc\n");
        exit(EXIT_FAILURE);
    }

    sprintf(date,"%s, %d %s %d %d:%d:%d GMT",
            weekDay,today->tm_mday,month,today->tm_year+1900,today->tm_hour,today->tm_min,today->tm_sec);
    return date;
}
Пример #4
0
int
getBEtime (char *toptarg, char flag, time_t tTime[])
{
    char  *cp ,*cp1, *cp3;
    time_t  sbtime;
    int cc;
    char endTime;

    checkThree (toptarg, ',', &cp, &cp1, &cp3);
    if (cp1 != NULL) {
	lserrno = LSE_BAD_TIME;
        return -1;
    }

    if (cp == NULL) {

	checkThree (toptarg, '.', &cp, &cp1, &cp3);
	if (cp != NULL) {
	    lserrno = LSE_BAD_TIME;
	    return -1;
        }
	endTime = FALSE;
	sbtime = 0;
	if ((cc = getPtime (toptarg, endTime, sbtime, flag, &tTime[0])) == -1)
	    return -1;
	endTime = TRUE;
	if (getPtime (toptarg, endTime, sbtime, flag, &tTime[1]) == -1)
	    return -1;
	if (checkBEtime ( tTime[0], tTime[1]) == -1)
	    return -1;
	return 0;
    }





    while (TRUE) {
	if ( *toptarg == ',' ) {
	    tTime[0] = 0;
	    toptarg ++;
	    break;
	}
	if ( (*toptarg == '.')&&(*(toptarg+1) == ',') ) {
	    tTime[0] = time(0);
	    toptarg = cp;
	}
	if ( *toptarg == ',' ) {
	    tTime[0] = time(0);
	    toptarg = cp +1;
	    break;
	}
	if ( (*toptarg == '.') && (*(toptarg+1) == '-') ) {
	    sbtime = time(0);
	    toptarg += 2;
	    *cp = '\000';
	    endTime = FALSE;
	    if (getPtime (toptarg, endTime, sbtime, flag, &tTime[0]) == -1)
	        return -1;
	    toptarg = cp+1;
	    break;
	}

	if ( (*toptarg == '@') && (*(toptarg+1) == ',') ) {
	    endTime = FALSE;
	    tTime[0] = getToday(endTime);
	    toptarg = cp+1;
	    break;
	}
	if ( (*toptarg == '@') && (*(toptarg+1) == '-') ) {
	    endTime = FALSE;
	    sbtime = getToday(endTime);
	    toptarg += 2;
	    *cp = '\000';
	    if (getPtime (toptarg, endTime, sbtime, flag, &tTime[0]) == -1)
	        return -1;
	    toptarg = cp+1;
	    break;
	}

	endTime = FALSE;
	*cp = '\000';
	sbtime = 0;
	if (getPtime (toptarg, endTime, sbtime, flag, &tTime[0]) == -1) {
	    *cp = ',';
	    return -1;
        }
	toptarg = cp + 1;
	break;
    }




    if ( (*toptarg == '.' && *(toptarg+1) == '\0') || (*toptarg == '\0')) {
	tTime[1] = time(0);
	if (checkBEtime ( tTime[0], tTime[1] ) == -1) {
	    *cp = ',';
	    return -1;
        }
	return 0;
    }
    if ((*toptarg == '.') && (*(toptarg+1) == '-')) {
	sbtime = time(0);
	toptarg += 2;
	endTime = FALSE;
	if (getPtime (toptarg, endTime, sbtime, flag, &tTime[1]) == -1) {
	    *cp = ',';
	    return -1;
        }
	if (checkBEtime ( tTime[0], tTime[1] ) == -1) {
	    *cp = ',';
	    return -1;
        }
	return 0;
    }

    if ((*toptarg == '@') && (*(toptarg+1) == '\0')) {
	endTime = TRUE;
	tTime[1] = getToday(endTime);
	if (checkBEtime ( tTime[0], tTime[1] ) == -1) {
	    *cp = ',';
	    return -1;
        }
	return 0;
    }
    if ((*toptarg == '@') && (*(toptarg+1) == '-')) {
	endTime = TRUE;
	sbtime = getToday(endTime);
	toptarg += 2;
	if (getPtime (toptarg, endTime, sbtime, flag, &tTime[1]) == -1) {
	    *cp = ',';
	    return -1;
        }
	if (checkBEtime ( tTime[0], tTime[1] ) == -1) {
	    *cp = ',';
	    return -1;
        }
	return 0;
    }

    endTime = TRUE;
    sbtime = FALSE;
    toptarg = cp+1;
    if (getPtime (toptarg, endTime, sbtime, flag, &tTime[1]) == -1) {
	*cp = ',';
        return -1;
    }
    if (checkBEtime ( tTime[0], tTime[1] ) == -1) {
	*cp = ',';
	return -1;
    }
    return 0;

}
Пример #5
0
closure* telaDiaria(closure* cl)
{
	char today[TIMEBUF];
	getToday(today);
	return telaRelatorio(cl,strdup(today),strdup(today));
}