diff --git a/VERAG_PROG_ALLGEMEIN/Classes/cFeiertage.vb b/VERAG_PROG_ALLGEMEIN/Classes/cFeiertage.vb index c7171311..d9ab1251 100644 --- a/VERAG_PROG_ALLGEMEIN/Classes/cFeiertage.vb +++ b/VERAG_PROG_ALLGEMEIN/Classes/cFeiertage.vb @@ -1,4 +1,6 @@ -Public Class cFeiertage +Imports System.Runtime.InteropServices.ComTypes + +Public Class cFeiertage Private _Year As Integer Private _Ostern As Date @@ -65,15 +67,23 @@ Public Function GetLastyDayInyMonth(ByVal day As DayOfWeek, ByVal month As Integer, ByVal year As Integer) As DateTime - ' Create a start date for the 1st day of the month - Dim startDate As DateTime = New DateTime(year, month, 1) + ' Create a start date for the last weekday of the month + Dim startDate As DateTime - While startDate.DayOfWeek <> day - startDate = startDate.AddDays(1) + If (month < 12) Then + startDate = New DateTime(year, month + 1, 1) + Else + startDate = New DateTime(year + 1, 1, 1) + startDate = startDate.AddDays(-1) + End If + + While (startDate.DayOfWeek <> day) + startDate = startDate.AddDays(-1) End While Return startDate + End Function