vtcn05

Feiertage Skript um 24.12. und 31.12. ergänzen

Recommended Posts

Hallo zusammen,

 

ich habe folgendes Skript laufen, welches an Feiertagen auf den AB umleitet:

 

' Federal States of Germany
const vb_FS_BW = 1       ' Baden-Württemberg
const vb_FS_BY = 2       ' Bayern
const vb_FS_BE = 4       ' Berlin
const vb_FS_BB = 8       ' Brandenburg
const vb_FS_HB = 16      ' Bremen
const vb_FS_HH = 32      ' Hamburg
const vb_FS_HE = 64      ' Hessen
const vb_FS_MV = 128     ' Mecklenburg-Vorpommern
const vb_FS_NI = 256     ' Niedersachsen
const vb_FS_NW = 512     ' Nordrhein-Westfalen
const vb_FS_RP = 1024    ' Rheinland-Pfalz
const vb_FS_SL = 2048    ' Saarland
const vb_FS_SN = 4096    ' Sachsen
const vb_FS_ST = 8192    ' Sachen-Anhalt
const vb_FS_SH = 16384   ' Schleswig-Holstein
const vb_FS_TH = 32768   ' Thüringen
const vb_FS_KD = 65536   ' Köln/Düsseldorf (Rosenmontag)




''-------------------------------------------------------------------
'' Name:     IsPublicHoliday 
''           ===============
'' 
'' Returns true if the given date is a public holiday in the given German federal state.
'' Multiple federal states can be combined with "OR"
''
'' Parameter:
''   nFederalState     single or combination of federal states
''   vCheckDate        vbscript date to check (e.g. as returned by now) or "" (for current date)
''
'' Returns:
''   Boolean           True = is public holiday
''
''--------------------------------------------------------------------
Function IsPublicHoliday ( nFederalState, vCheckDate )


    On Error Resume Next


    PBXScript.OutputTrace "-------> IsPublicHoliday"
    PBXScript.OutputTrace "nFederalState = " & nFederalState
    PBXScript.OutputTrace "vCheckDate = " & vCheckDate


    Dim bReturn
    bReturn = False


    Dim a, b, c, d, e, f
    Dim nTempYear, vTempDate
    Dim Neujahr, Erscheinungsfest, Karfreitag, Ostersonntag, Ostermontag
    Dim Maifeiertag, Rosenmontag, ChrHimmelfahrt, Pfingstmontag, Fronleichnam
    Dim MarieaHimmelfahrt, Tagdereinheit, Reformationstag, Allerheiligen
    Dim BussUndBettag, Weihnachten1, Weihnachten2 


    if Not IsDate(vCheckDate) then
        vCheckDate = Now
    end if
    vTempDate = DateSerial(Year(vCheckDate), Month(vCheckDate), Day(vCheckDate))
    nTempYear = Year(vTempDate)


    PBXScript.OutputTrace "Using nTempYear = " & nTempYear
    PBXScript.OutputTrace "Using vTempDate = " & vTempDate
          
    ' Gauss Formular
    a = nTempYear Mod 19
    b = nTempYear \ 100
    c = (8 * b + 13) \ 25 - 2
    d = b - (nTempYear \ 400) - 2
    e = (19 * (nTempYear Mod 19) + ((15 - c + d) Mod 30)) Mod 30
    If e = 28 Then
        If a > 10 Then
            e = 27
        End If
    ElseIf e = 29 Then
        e = 28
    End If
    f = (d + 6 * e + 2 * (nTempYear Mod 4) + 4 * (nTempYear Mod 7) + 6) Mod 7


    ' Calculate public holidays
    Neujahr           = DateSerial(nTempYear, 1, 1)
    Erscheinungsfest  = DateSerial(nTempYear, 1, 6)
    Ostersonntag      = DateSerial(nTempYear, 3, e + f + 22)
    Rosenmontag       = DateSerial(nTempYear, 3, e + f + 22 - 48)
    Karfreitag        = DateSerial(nTempYear, 3, e + f + 22 - 2)
    Ostermontag       = DateSerial(nTempYear, 3, e + f + 22 + 1)
    Maifeiertag       = DateSerial(nTempYear, 5, 1)
    ChrHimmelfahrt    = DateSerial(nTempYear, 3, e + f + 22 + 39)
    Pfingstmontag     = DateSerial(nTempYear, 3, e + f + 22 + 50)
    Fronleichnam      = DateSerial(nTempYear, 3, e + f + 22 + 60)
    MarieaHimmelfahrt = DateSerial(nTempYear, 8, 15) 
    Tagdereinheit     = DateSerial(nTempYear, 10, 3) 
    Reformationstag   = DateSerial(nTempYear, 10, 31) 
    Allerheiligen     = DateSerial(nTempYear, 11, 1) 
    BussUndBettag     = DateSerial(nTempYear, 12, 25) - Weekday(DateSerial(nTempYear, 12, 25), vbMonday) - 4 * 7 - vbWednesday 
    Weihnachten1      = DateSerial(nTempYear, 12, 25)
    Weihnachten2      = DateSerial(nTempYear, 12, 26)


    ' Is public holiday?
    select case vTempDate
        case Neujahr
            bReturn = True
        case Erscheinungsfest
            if (nFederalState and (vb_FS_BW or vb_FS_BY or vb_FS_ST)) then bReturn = True
        case Ostersonntag
            bReturn = True
        Case Rosenmontag
            If(nFederalState and (vb_FS_KD)) then bReturn = True
        case Karfreitag
            bReturn = True
        case Ostermontag
            bReturn = True
        case Maifeiertag
            bReturn = True
        case ChrHimmelfahrt
            bReturn = True
        case Pfingstmontag
            bReturn = True
        case Fronleichnam
            if (nFederalState and (vb_FS_BW or vb_FS_BY or vb_FS_HE or vb_FS_NW or vb_FS_RP or vb_FS_SL or vb_FS_SN or vb_FS_TH)) then bReturn = True
        case MarieaHimmelfahrt
            if (nFederalState and (vb_FS_BY or vb_FS_SL)) then bReturn = True
        case Tagdereinheit
            bReturn = True
        case Reformationstag
            if (nFederalState and (vb_FS_BB or vb_FS_MV or vb_FS_SN or vb_FS_ST or vb_FS_TH)) then bReturn = True
        case Allerheiligen
            if (nFederalState and (vb_FS_BW or vb_FS_BY or vb_FS_NW or vb_FS_RP or vb_FS_SL)) then bReturn = True
        case BussUndBettag
            if (nFederalState and (vb_FS_SN)) then bReturn = True
        case Weihnachten1
            bReturn = True
        case Weihnachten2
            bReturn = True
    end select


    IsPublicHoliday = bReturn


    PBXScript.OutputTrace "bReturn = " & bReturn
    PBXScript.OutputTrace "<------- IsPublicHoliday"


End Function

Nun möchte ich das der 24.12. und der 31.12. auch als Feiertag angesehen wird. Wie kann ich das einbauen?

 

Vielen Dank und schöne Grüße

Michael

Share this post


Link to post
Share on other sites

lach...so ein zufall genau daran sitze ich gerade ;)

 

kann dir gleich den Code anhängen, habe es fertig.

 

Share this post


Link to post
Share on other sites

Also ich habe ein neues Bundenland angelegt und mit diesem kannst du dann explizit Weihnachten nue Slivester abfragen.

 

IsPublicHoliday(vb_FS_CD, CurDate() )

 

@vtcn05

 

Werde noch Schmotzigen Donnerstag und Fasnachtsdienstag einfügen

Quote

' Federal States of Germany
const vb_FS_BW = 1       ' Baden-Württemberg
const vb_FS_BY = 2       ' Bayern
const vb_FS_BE = 4       ' Berlin
const vb_FS_BB = 8       ' Brandenburg
const vb_FS_HB = 16      ' Bremen
const vb_FS_HH = 32      ' Hamburg
const vb_FS_HE = 64      ' Hessen
const vb_FS_MV = 128     ' Mecklenburg-Vorpommern
const vb_FS_NI = 256     ' Niedersachsen
const vb_FS_NW = 512     ' Nordrhein-Westfalen
const vb_FS_RP = 1024    ' Rheinland-Pfalz
const vb_FS_SL = 2048    ' Saarland
const vb_FS_SN = 4096    ' Sachsen
const vb_FS_ST = 8192    ' Sachen-Anhalt
const vb_FS_SH = 16384   ' Schleswig-Holstein
const vb_FS_TH = 32768   ' Thüringen
const vb_FS_KD = 65536   ' Köln/Düsseldorf (Rosenmontag)
const vb_FS_CD = 131072  ' Heiligabend (ChrismasDay)




''-------------------------------------------------------------------
'' Name:     IsPublicHoliday 
''           ===============
'' 
'' Returns true if the given date is a public holiday in the given German federal state.
'' Multiple federal states can be combined with "OR"
''
'' Parameter:
''   nFederalState     single or combination of federal states
''   vCheckDate        vbscript date to check (e.g. as returned by now) or "" (for current date)
''
'' Returns:
''   Boolean           True = is public holiday
''
''--------------------------------------------------------------------
Function IsPublicHoliday ( nFederalState, vCheckDate )


    On Error Resume Next


    PBXScript.OutputTrace "-------> IsPublicHoliday"
    PBXScript.OutputTrace "nFederalState = " & nFederalState
    PBXScript.OutputTrace "vCheckDate = " & vCheckDate


    Dim bReturn
    bReturn = False


    Dim a, b, c, d, e, f
    Dim nTempYear, vTempDate
    Dim Neujahr, Erscheinungsfest, Karfreitag, Ostersonntag, Ostermontag
    Dim Maifeiertag, Rosenmontag, ChrHimmelfahrt, Pfingstmontag, Fronleichnam
    Dim MarieaHimmelfahrt, Tagdereinheit, Reformationstag, Allerheiligen
    Dim BussUndBettag, Heiligabend, Silvester, Weihnachten1, Weihnachten2, Reformationstag2017


    if Not IsDate(vCheckDate) then
        vCheckDate = Now
    end if
    vTempDate = DateSerial(Year(vCheckDate), Month(vCheckDate), Day(vCheckDate))
    nTempYear = Year(vTempDate)


    PBXScript.OutputTrace "Using nTempYear = " & nTempYear
    PBXScript.OutputTrace "Using vTempDate = " & vTempDate
          
    ' Gauss Formular
    a = nTempYear Mod 19
    b = nTempYear \ 100
    c = (8 * b + 13) \ 25 - 2
    d = b - (nTempYear \ 400) - 2
    e = (19 * (nTempYear Mod 19) + ((15 - c + d) Mod 30)) Mod 30
    If e = 28 Then
        If a > 10 Then
            e = 27
        End If
    ElseIf e = 29 Then
        e = 28
    End If
    f = (d + 6 * e + 2 * (nTempYear Mod 4) + 4 * (nTempYear Mod 7) + 6) Mod 7


    ' Calculate public holidays
    Neujahr           = DateSerial(nTempYear, 1, 1)
    Erscheinungsfest  = DateSerial(nTempYear, 1, 6)
    Ostersonntag      = DateSerial(nTempYear, 3, e + f + 22)
    Rosenmontag       = DateSerial(nTempYear, 3, e + f + 22 - 48)
    Karfreitag        = DateSerial(nTempYear, 3, e + f + 22 - 2)
    Ostermontag       = DateSerial(nTempYear, 3, e + f + 22 + 1)
    Maifeiertag       = DateSerial(nTempYear, 5, 1)
    ChrHimmelfahrt    = DateSerial(nTempYear, 3, e + f + 22 + 39)
    Pfingstmontag     = DateSerial(nTempYear, 3, e + f + 22 + 50)
    Fronleichnam      = DateSerial(nTempYear, 3, e + f + 22 + 60)
    MarieaHimmelfahrt = DateSerial(nTempYear, 8, 15) 
    Tagdereinheit     = DateSerial(nTempYear, 10, 3) 
    Reformationstag   = DateSerial(nTempYear, 10, 31) 
    Allerheiligen     = DateSerial(nTempYear, 11, 1) 
    BussUndBettag     = DateSerial(nTempYear, 12, 25) - Weekday(DateSerial(nTempYear, 12, 25), vbMonday) - 4 * 7 - vbWednesday 
    Heiligabend	      = DateSerial(nTempYear, 12, 24)
    Weihnachten1      = DateSerial(nTempYear, 12, 25)
    Weihnachten2      = DateSerial(nTempYear, 12, 26)
    Silvester	      = DateSerial(nTempYear, 12, 31)
    Reformationstag2017 = DateSerial(2017, 10, 31)


    ' Is public holiday?
    select case vTempDate
        case Neujahr
            bReturn = True
        case Erscheinungsfest
            if (nFederalState and (vb_FS_BW or vb_FS_BY or vb_FS_ST)) then bReturn = True
        case Ostersonntag
            bReturn = True
        case Rosenmontag
            If(nFederalState and (vb_FS_KD)) then bReturn = True
        case Karfreitag
            bReturn = True
        case Ostermontag
            bReturn = True
        case Maifeiertag
            bReturn = True
        case ChrHimmelfahrt
            bReturn = True
        case Pfingstmontag
            bReturn = True
        case Fronleichnam
            if (nFederalState and (vb_FS_BW or vb_FS_BY or vb_FS_HE or vb_FS_NW or vb_FS_RP or vb_FS_SL or vb_FS_SN or vb_FS_TH)) then bReturn = True
        case MarieaHimmelfahrt
            if (nFederalState and (vb_FS_BY or vb_FS_SL)) then bReturn = True
        case Tagdereinheit
            bReturn = True
        case Reformationstag
            if (nFederalState and (vb_FS_BB or vb_FS_MV or vb_FS_SN or vb_FS_ST or vb_FS_TH)) then bReturn = True
        case Reformationstag2017
            bReturn = True
        case Allerheiligen
            if (nFederalState and (vb_FS_BW or vb_FS_BY or vb_FS_NW or vb_FS_RP or vb_FS_SL)) then bReturn = True
        case BussUndBettag
            if (nFederalState and (vb_FS_SN)) then bReturn = True
        case Heiligabend
            If(nFederalState and (vb_FS_CD)) then bReturn = True
	case Weihnachten1
            bReturn = True
        case Weihnachten2
            bReturn = True
        case Silvester
            If(nFederalState and (vb_FS_CD)) then bReturn = True
        
    end select


    IsPublicHoliday = bReturn


    PBXScript.OutputTrace "bReturn = " & bReturn
    PBXScript.OutputTrace "<------- IsPublicHoliday"


End Function

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now