Пример #1
0
static int monthDays (int iYear, int iMonth)
{
    switch (iMonth) {
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
            return (31);
        case 4:
        case 6:
        case 9:
        case 11:
            return (30);
        case 2:
            if (isLeapyear(iYear)) {
                return (29);
            } else {
                return (28);
            }
        default:
            return 0;
    }
}
int checkndconvert(char* dob1, struct converteddate *y)
{
	int day1, month1, year1, i, len = -1, lp;
	int a[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
	for (i = 0; dob1[i] != '\0' ; i++)
	{
		len++;
	}
	if (len != 9)
	{
		return -1;
	}
	else
	{
		year1 = split(dob1, 6, 9);
		month1 = split(dob1, 3, 4);
		day1 = split(dob1, 0, 1);
		if (year1 < 0  || month1 < 0|| day1 < 0)
		{
			return -1;
		}
		if (dob1[2] != '-' || dob1[5] != '-')
		{
			return -1;
		}
		if (month1 > 12 || month1 == 0)
		{
			return -1;
		}
		if (day1 > a[month1 - 1])
		{
			return -1;
		}
	
		if (month1 == 2)
		{
			if (day1 == 29)
			{
				lp = isLeapyear(year1);
			}
			if (lp == 0)
			{
				return -1;
			}
		}

		y->year = year1;
		y->month = month1;
		y->day = day1;


	}
	return 1;

}