Subato

Wochentage und Muttertage

record Date(int day, int month, int year){
  int dayOfWeek(){
    //Schrittweise Lösung über die Einzelziffern
    
    int tz = day%7;
    int[] monatsziffern = {0,3,3,6,1,4,6,2,5,0,3,5};
    int mz = monatsziffern[month-1];
    int jz = year%100; 
    int jahresziffer = (jz+jz/4)%7;
    int jh = year/100;
    int jahrhundertziffer = (3 - jh%4)*2;
    int schaltjahreskorrektur
      = (isEarlierThan(new Date(1,3,year))&&isLeapYear())?6:0;
      return (tz+mz+jahresziffer+jahrhundertziffer+schaltjahreskorrektur)%7;

// oder als eine Gesamtformel
/*
    int year = this.year;
    if(this.month < 3) year -= 1;
    return (((this.day
      + (int)(2.6 *((this.month + 9) % 12 + 1) - 0.2) 
      + year % 100 
      + (int)(year % 100 / 4) 
      + (int)(year / 400) 
      - 2 * (int)(year / 100) - 1) % 7 + 7) % 7 + 1)%7;
*/

  }

  boolean isEarlierThan(Date that){
    return
         year<that.year
      || (year==that.year && month<that.month)
      || (year==that.year && month==that.month && day<that.day);
  }


  Date mothersDay() {
    int wd = new Date(1, 5, year).dayOfWeek();
    return new Date(wd == 0 ? 8 : (15 - wd), 5, year);
  }
  
  boolean isLaterThan(Date that){
    return that.isEarlierThan(this);
  }
  
  boolean isSameDate(Date that){
    return year==that.year &&month==that.month&&day==that.day;
  }
  public String toString(){
    return ""+day+"."+month+"."+year;
  }
  
  boolean isLeapYear(){
    return year%400==0
     ||(year%4==0 && year%100!=0);
  }
  int getAbsoluteDaysInYear(){
    return isLeapYear()?366:365;
  }
  public static void main(String[] args){
    Date d = new Date(30,11,2018);
    System.out.println(d);
  }
}