Thema: Delphi Wochentage Feiertage

Einzelnen Beitrag anzeigen

jensw_2000
(Gast)

n/a Beiträge
 
#5

Re: Wochentage Feiertage

  Alt 3. Nov 2004, 01:26
Hallo Jasocul,

für die Feiertage kannst du folgende unit verwenden ...

Delphi-Quellcode:
unit uFeiertage;

interface

uses Windows, SysUtils;

type
  THoliday = record
    Date: TDateTime;
    Name: STRING;
  end;
  THolidayTable = array of THoliday;

function GetHolidayTable(Year: WORD): THolidayTable;

implementation

function GetHolidayTable(Year: WORD): THolidayTable;

  procedure AddHoliday(DD, MM: WORD; HDName: STRING); overload;
  begin
    SetLength(Result, High(Result) + 2);
    with Result[High(Result)] do
    begin
      Date := EncodeDate(Year, MM, DD);
      Name := HDName;
    end;
  end;

  procedure AddHoliday(HDDate: TDateTime; HDName: STRING); overload;
  begin
    SetLength(Result, High(Result) + 2);
    with Result[High(Result)] do
    begin
      Date := HDDate;
      Name := HDName;
    end;
  end;

  function GetEasterDate(YYYY: WORD): TDateTime;
  var
    A, B, C, D, E, F, G, H, I, K, L, M, N, P: WORD;
    DD, MM: WORD;
  begin
    a := YYYY MOD 19;

    b := YYYY DIV 100;
    c := YYYY MOD 100;

    d := b DIV 4;
    e := b MOD 4;

    f := (b + 8) DIV 25;

    g := (b - f + 1) DIV 3;

    h := (19 * a + b - d - g + 15) MOD 30;

    i := c DIV 4;
    k := c MOD 4;

    l := (32 + 2 * e + 2 * i - h - k) MOD 7;

    m := (a + 11 * h + 22 * l) DIV 451;

    n := (h + l - 7 * m + 114) DIV 31;
    p := (h + l - 7 * m + 114) MOD 31 + 1;

    DD := p;
    MM := n;

    Result := EncodeDate(YYYY, MM, DD);
  end;

var
  EDate: TDateTime;
begin
  AddHoliday(1, 1, 'Neujahr');
  AddHoliday(1, 5, 'Tag der Arbeit');
  AddHoliday(3, 10, 'Tag der deutschen Einheit');
  // AddHoliday(31, 10, 'Reformationstag');
  AddHoliday(24, 12, 'Heiligabend');
  AddHoliday(25, 12, '1. Weihnachtsfeiertag');
  AddHoliday(26, 12, '2. Weihnachtsfeiertag');
  AddHoliday(31, 12, 'Silvester');

  EDate := GetEasterDate(Year);

  AddHoliday(EDate, 'Ostersonntag');
  AddHoliday(EDate - 2, 'Karfreitag');
  AddHoliday(EDate + 1, 'Ostermontag');
  AddHoliday(EDate + 39, 'Christi Himmelfahrt');
  AddHoliday(EDate + 49, 'Pfingstsonntag');
  AddHoliday(EDate + 50, 'Pfingstmontag');

  //Ermittelt den 3. Mittwoch im November ...
  EDate := EncodeDate(Year, 11, 1);
  EDate := EDate + ((11 - DayOfWeek(EDate)) MOD 7) + 14;
  // AddHoliday(EDate, 'Buß- und Bettag');
end;

end.
Schöne Grüße,
Jens
  Mit Zitat antworten Zitat