Jon thanks, you're absolutely right let me attach the missing next() method that is inside the class:
public date Next(date d)
{
if (!d.valid()) return new date();
date ndat = new date((d.Day() + 1), d.Month(), d.Year());
if (ndat.valid()) return ndat;
ndat = new date(1, (d.Month() + 1), d.Year());
if (ndat.valid()) return ndat;
ndat = new date(1, 1, (d.Year() + 1));
return ndat;
}
Since this uses valid() I'll attach this also:
public bool valid()
{
// This method will check the given date is valid or not.
// If the date is not valid then it will return the value false.
if (year < 0) return false;
if (month > 12 || month < 1) return false;
if (day > 31 || day < 1) return false;
if ((day == 31 && (month == 2 || month == 4 || month == 6 || month == 9 || month == 11)))
return false;
if (day == 30 && month == 2) return false;
if (day == 29 && month == 2 && (year % 4) != 0) return false;
if (day == 29 && month == 2 && (((year % 100) == 0) && ((year % 400) != 0))) return false;
/* ASIDE. The duration of a solar year is slightly less than 365.25 days. Therefore,
years that are evenly divisible by 100 are NOT leap years, unless they are also
evenly divisible by 400, in which case they are leap years. */
return true;
}
the Day(), Month(), and Year() I think are self explanatory but let me know if they're needed. I also have a previous() method that does the opposite of next() which I want to use in the -- decrement method.
Now in my program, I have
class Program
{
static void Main()
{
date today = new date(7,10,1985);
date tomoz = new date();
tomorrow = today++;
tomorrow.Print(); // prints "7/10/1985" i.e. doesn't increment
Console.Read();
}
}
So it doesn't actually fail it just prints todays date instead of tomorrow's but works correctly if I had used ++today instead.
Regarding the order D/M/Y, yep I agree, with higher frequency data I can see how that improves things, I'll move on to fixing that next.