Massimo Ferrari schrieb:
Hi Gerhard,

Thank you for your offer, that of course I will accept!


See attatchment

gerhard
  /**
   * Get easter date for a year - default implementation.<br>
   * Implements Meeus/Jones/Butcher Gregorian algorithm<br>
   * From: <http://en.wikipedia.org/wiki/Computus><br>
   * 
   * @param year
   * @return
   */
  @SuppressWarnings("unused")
  public Holiday getEaster(int year) {

    Holiday easter = new Holiday();
    easter.text = "Easter";

    int a = year % 19;
    int b = year / 100;
    int c = year % 100;
    int d = b / 4;
    int e = b % 4;
    int f = (b + 8) / 25;
    int g = (b - f + 1) / 3;
    int h = (19 * a + b - d - g + 15) % 30;
    int i = c / 4;
    int k = c % 4;
    int L = (32 + 2 * e + 2 * i - h - k) % 7;
    int m = (a + 11 * h + 22 * L) / 451;

    int month = (h + L - 7 * m + 114) / 31;
    int day = ((h + L - 7 * m + 114) % 31) + 1;

    easter.date = new LocalDate(year, month, day);

    return easter;
  }


******************************
* calculation of public austrian holidays (including sort comperator)
******************************


    /**
     * Get all public holidays in austria for one year.
     */
    public ArrayList<Holiday> getHolidayList(int year) {

      ArrayList<Holiday> list = new ArrayList<Holiday>();

      // holidays with fixed dates in year:
      list.add(new Holiday(new LocalDate(year, 1, 1), "Neujahr"));
      list.add(new Holiday(new LocalDate(year, 1, 6), "Heiligendreikönig"));
      list.add(new Holiday(new LocalDate(year, 5, 1), "Staatsfeiertag"));
      list.add(new Holiday(new LocalDate(year, 8, 15), "Maria Himmelfahrt"));
      list.add(new Holiday(new LocalDate(year, 10, 26), "Nationalfeiertag"));
      list.add(new Holiday(new LocalDate(year, 11, 1), "Allerheiligen"));
      list.add(new Holiday(new LocalDate(year, 12, 8), "Maria Empfängnis"));
      list.add(new Holiday(new LocalDate(year, 12, 25), "Christtag"));
      list.add(new Holiday(new LocalDate(year, 12, 26), "Stephanstag"));

      // moveable holidays (relative to easter):
      LocalDate easterDate = this.getEaster(year).date;

      list.add(new Holiday(easterDate, "Ostersonntag"));
      list.add(new Holiday(easterDate.plusDays(1), "Ostermontag"));
      list.add(new Holiday(easterDate.plusDays(39), "Christi Himmelfahrt"));
      list.add(new Holiday(easterDate.plusDays(49), "Pfingstsonntag"));
      list.add(new Holiday(easterDate.plusDays(50), "Pfingstmontag"));
      list.add(new Holiday(easterDate.plusDays(60), "Fronleichnam"));

      // sort by date
      Comparator<Holiday> comp = new Comparator<Holiday>() {

        DateTimeComparator dateComp = DateTimeComparator.getInstance();


        /**
         * Implements Comparator.compare().
         * 
         * @param obj1
         * @param obj2
         * @return
         */
        public int compare(Holiday obj1, Holiday obj2) {

          return dateComp.compare(obj1.date.toDateMidnight(),
              obj2.date.toDateMidnight());
        }


        /**
         * Implements Comparator.equals().
         * 
         * @param other
         * @return
         */
        @SuppressWarnings("unused")
        public boolean equals(Holiday other) {

          return dateComp.equals(other);
        }
      };
      Collections.sort(list, comp);

      return list;
    }
  } // end of AT_OFFICIAL class



************************
* helperclass to hold date + name
************************

  /**
   * Representation for one holiday day.
   */
  public static class Holiday {

    public LocalDate date;
    public String text;


    /**
     * Default constructor.
     */
    Holiday() {

      // nothing to do
    }


    /**
     * Constructor with date and name.
     */
    Holiday(LocalDate date, String name) {

      this.date = date;
      this.text = name;
    }

  } // end of class for infos of one holiday (date and name)

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Joda-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/joda-interest

Reply via email to