I knew this code was going to be bulky before I wrote it but I figured once I had something that worked it would be easier to make it smaller.
It just needs to progress through the year with respect to the amount of days in each month. It works, It’s just got a lot of duplicate code and despite my brain hardly functioning right now I’m confident there’s a neater way to do this. I can write the code my self I think if you give me some logical advice.
private void setDate()
{
//updating the day, month and year
day++;
if (day > 28 && month == 2 && year % 4 != 0) // Month 2, February, has 28 days on non-leap years, or years not divisible by 4.
{
month++;
day = 1;
if (month > 12)
{
year++;
month = 1;
}
} else if (day > 29 && month == 2 &&year % 4 == 0) // Month 2, February, has 29 days on leap years, or years divisible by 4.
{
month++;
day = 1;
if (month > 12)
{
year++;
month = 1;
}
} else if (day > 30 && month % 2 == 0 && month != 2) //Every month evenly divisible by 2, except February, has 30 days
{
month++;
day = 1;
if (month > 12)
{
year++;
month = 1;
}
} else if (day > 31 && month % 2 == 1 && month != 2) //Odd months have 31 days, except February.
{
month++;
day = 1;
if (month > 12)
{
year++;
month = 1;
}
}
}
Edit: SetDate() is called in Update(). Also, I wanted to write this myself, without relying on the already available time functions.