ジョンのおかげで、クラス内にある不足している next() メソッドを添付させてください。
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;
}
これは valid() を使用するため、これも添付します。
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;
}
Day()、Month()、Year() は自明だと思いますが、必要な場合はお知らせください。--decrement メソッドで使用したい next() の反対を行う previous() メソッドもあります。
今私のプログラムでは、私は持っています
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();
}
}
したがって、実際には失敗するわけではなく、明日の代わりに今日の日付を出力するだけですが、代わりに ++today を使用した場合は正しく機能します。
D/M/Y の順序については、同意します。より高い頻度のデータを使用すると、それがどのように改善されるかがわかります。次の修正に進みます。