01.12.2014, 01:53
Quote:
That still will result in dates such as 35/05/2014. You'll need to calculate if it's the next month. Which would require an array with the length of months and also some way to deal with leap years.
|
pawn Код:
new year, month, day, maxdays;
getdate(year, month, day);
printf("Date: %02d/%02d/%d", day, month, year);
switch(month)
{
case 1, 3, 5, 7, 8, 10, 12: maxdays = 31;
case 4, 6, 9, 11: maxdays = 30;
case 2: maxdays = ((!(year % 4)) ? (29) : (28));
}
if((day += 5) > maxdays) day -= maxdays, month++;
if(month > 12) month -= 12, year++;
printf("Date +5 days: %02d/%02d/%d", day, month, year);
Код:
case 1, 3, 5, 7, 8, 10, 12: maxdays = 31; case 4, 6, 9, 11: maxdays = 30; case 2: maxdays = ((!(year % 4)) ? (29) : (28));
If the month is 4, 6, 9, 11, the maximum days in that month will be 30. This never changes depending on the year.
If the month is February, we need to check if it's a leap year to determine whether the maximum days will be 28 or 29.
Код:
maxdays = ((!(year % 4)) ? (29) : (28));
pawn Код:
if(leapyear) maxdays = 29;
else maxdays = 28;
Код:
if((day += 5) > maxdays) day -= maxdays, month++;
Код:
if(month > 12) month -= 12, year++;