Date: daysAfter() / daysBefore()

thobaben_serialize
Harald Wolff 2015-06-25 01:39:18 +02:00
parent 15306a3804
commit 69db4cd9f7
1 changed files with 31 additions and 2 deletions

View File

@ -116,14 +116,31 @@ public class Date {
return false;
}
public int leapsSinceAC(){
return (year / 4) - (year / 100) + (year / 400);
}
private static int[] daysInMonth = { 31,28,31,30,31,30,31,31,30,31,30,31 };
public int getDaysInMonth(){
int d = daysInMonth[ month - 1];
if (isLeapYear() && (month == 2))
return getDaysInMonth(month);
}
public int getDaysInMonth(int m){
int d = daysInMonth[ m - 1];
if (isLeapYear() && (m == 2))
d += 1;
return d;
}
private int dayOfYear(){
int n = 0;
for (int i=1;i<month;i++){
n += getDaysInMonth(i);
}
n += day;
return n;
}
private static int[] Nmonth = {0,3,3,6,1,4,6,2,5,0,3,5};
@ -153,6 +170,18 @@ public class Date {
return ns % 7;
}
public int getDaysAC() {
int dac = (365 * year) + leapsSinceAC();
dac += dayOfYear();
return dac;
}
public int daysAfter(Date d){
return getDaysAC() - d.getDaysAC();
}
public int daysBefore(Date d){
return d.getDaysAC() - getDaysAC();
}
}