Jump to content

Public Holidays (in Germany, incl. Federal States)


Tom Wellige
 Share


Recommended Posts

The well known Forum user JoergG has provided me with the following VBScript function to calculate public holidays in Germany. The function even takes the different federal states into consideration.

 

There is another version of this function available, IsPublicHolidayAT, which calculates the public holidays in Austria.

 

 

Please find the IsPublicHolidayDE function in the Function Collection (VBScript) and Function Collection (Lua) area of the Programming References section of the SwyxPEDIA here on Swyx Forum. 

 

 

 

Link to comment
Share on other sites


  • Most Valued User

Thank you for this script!


 


I have some questions:


1. I got error messages because of the comma at the end of the line where the variables are declared (e.g. "Ostermontag,")


2. The constant "vbSN" is declared for the Bundesland Sachsen. But in the script vbSA is used i think.


3. How is the correct syntax to run the script? I think it is possible to omit the date if I want to check the current day, but I did not manage to do so.


Link to comment
Share on other sites


Hello Markus,


 


just checked the dates and it looks like vbSA is vbSN, so a typo.


 


The same should apply to the commas, I am not (yet) a Swyx user, but this looks like VB / VBA code and the commas at the end of the DIM statements should be omitted.


 


The function must be supplied with the State (Bundesland), but if the supplied date is empty, then it takes today's date.


 


If this is VBA, then the parameter can be made optional as follows:


 


Function IstFeiertag(BundesLand, Optional Datum = "")


 


As I said, I am not yet a Swyx user, so that might not be correct, I was here looking for other information, but this was the first post I saw. I hope that helps.


Link to comment
Share on other sites


Okay guys,


 


as I am a total noob to VB-Code, could you please explain how exactly i have to set the variables, and where to put the evaluate-block and how it has to be configured?


As i understand i have to copy the whole code from above into the start-block.


Do i have to set the state right here like :


 


Function IstFeiertag(vbNW, DateSerial(Now))


 


And then i have to define a new "Evaluate Variable" - Block and put something like this in:


IstFeiertag = True use exit 0 ?


Link to comment
Share on other sites


  • 3 weeks later...

To use this function within a call routing script just do the following:

  1. Copy & Paste the above code into the Start block.
  2. Call the function within an Evaluate (Variable auswerten) block.
  3. On it's Properties page just write the function call. For a check of today in Nordrhein-Westfalen use the following code:

    IstFeiertag(vbNW, DateSerial(Now))
     
  4. As the function returns already a boolean value it can be called directly and it's return value will be automatically mapped on the exits of the block.
Link to comment
Share on other sites


  • 3 weeks later...
  • Most Valued User

I've tried the script but it doesn't work on my Swyx Server 2015


 


I get the following error in the log. It's seems that "DateSerial" is unknown. What can i do to get it work ?



21 11:04:22.101 001098 Info SrvScript 07ED4778 0000000f SPBXScript::OutputTrace () GSEVersion: 10.0.0.1
21 11:04:22.101 001098 Info SrvScript 07ED4778 0000000f SPBXScript::OutputTrace () case [Start0]
21 11:04:22.101 001098 Info SrvScript 07ED4778 0000000f SPBXScript::OutputTrace () --> gseStart()
21 11:04:22.101 001098 Info SrvScript 07ED4778 0000000f SPBXScript::OutputTrace () <-- gseStart, rc = 1 [gseStateStarted]
21 11:04:22.101 001098 Info SrvScript 07ED4778 0000000f SPBXScript::OutputTrace () case [Evaluate4]
21 11:04:22.101 001098 Info SrvScript 07ED4778 0000000f SPBXScript::OutputTrace () IstFeiertag(vbHE, DateSerial(Now))
21 11:04:22.112 000848 Info SwSIPSub 04B59058 00000000 SwSIPEndp::OnPresenceNotify () Notify for IpPbx user ID 18
21 11:04:22.112 000848 Info SwSIPSub 04B59058 00000000 SwSIPEndp::OnPresenceNotify () Found resource list subscription 06CDFBE0 of user for event package 'presence' in list of server subscriptions!
21 11:04:22.112 001f54 Info SwSIPSub 06CDFBE0 00000000 SFsm::OnProcessEvent () Subscribed evtUserStatusChange Result: 1 NewSt: Subscribed
21 11:04:22.117 001098 *Err SrvScrAPI 0703F468 0000000f SPBXScriptSite::OnScriptError ()
~Code: 0
~Src: Laufzeitfehler in Microsoft VBScript
~Desc: Falsche Anzahl an Argumenten oder ungültige Eigenschaftszuweisung: 'DateSerial'
~RetVal: 800a01c2
~Line: 14978
~Column: 8
~Source code:
~ PBXScriptOutputTrace "IstFeiertag(vbHE, DateSerial(Now))"

~ ^ error position


Link to comment
Share on other sites


Well, I don't know if you find someone here to explain the Easter days calculation.

The church itself wasn't able to come up with a proper set of rules for the for centuries. Only Carl Friedrich Gauss came up with a proper calculation in 1800, and updated it again in 1816.

To be honest, I can't explain it to you. It just works 🙂

If you have public holidays on a fixed day just take a look how it is done e.g. with Christmas.

 

Link to comment
Share on other sites


  • 1 month later...

Hey Younes,


 


dutch or not - Easter has the same place in the calendar. So, don't care for the calculation, just use it :-)


The key-part after the calculation is the line "Ostersonntag = DateSerial(nTempYear, 3, e + f + 22)". Every other holiday around easter is calculated relatively to that day.


 


The harder part for you is to define all national and (so they exist) regional holidays for the netherlands, but this should be mostly work, not brainwork.


 


And don't forget to insert: FootballChampion = DateSerial(9999, 2, 31) :P


 


Cheers, Matthias

Link to comment
Share on other sites


  • Most Valued User

The harder part for you is to define all national and (so they exist) regional holidays for the netherlands, but this should be mostly work, not brainwork.

Most of the national public holidays in the netherlands are AFAIK as static defined as newyear (DateSerial(Year, 1, 1))),

so that should not be that complicated. The mathematical most complicated date (easter) is already there (and should be the same for the whole world.)

And don't forget to insert: FootballChampion = DateSerial(9999, 2, 31) :P

If we still talk about the netherlands:

It should be SoccerChampion =DateSerial(1/0, 2, 31) shouldn't it? :P

SCNR ;)

Link to comment
Share on other sites


... as long as you keep "2, 31", I don't insist on a special year ;)
 
I tried the script on my system and had some problems with the CDate-function, because it doesn't cut off the time from the date when it's given with "now". And therefore I didn't get any holiday except the call is at midnight.
 
I changed the calculation of the year and the at the beginning a little bit and moved the DateSerial from the function-call into the function.
With the change, you can call the function in the following ways:

  • IsPublicHoliday (vb_FS_NI, "")
  • IsPublicHoliday (vb_FS_NI, Now)
  • IsPublicHoliday (vb_FS_NI, "29.2.2016")

 

[ADMIN EDIT: copied the script code into the first post of this thread]

 

 

and I also fixed the Sachsen-bug

 

Cheers, Matthias

Link to comment
Share on other sites


  • 2 years later...
  • Most Valued User

Hi @ All,

 

I add a new pseudo federal state for Bayern. 

Mariä Himmelfahrt is not a holiday anywhere in Bayern.

I had modified vs_FS_BY without Mariä Himmelfahrt as Standard
and a new "pseudo" federal state vs_FS_BYMH with Mariä Himmelfahrt.
 

The new Script:

 

' Federal States of Germany
const vb_FS_BW = 1       ' Baden-Württemberg
const vb_FS_BY = 2       ' Bayern ohne MarieaHimmelfahrt
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_BYMH = 131072  ' Bayern mit Maria Himmelfahrt

'-------------------------------------------------------------------
' 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
  
  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 or vb_FS_BYMH)) 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_BYMH or 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_BYMH 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_BYMH or 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

 

Best Regards,

Jörg

 

Link to comment
Share on other sites


  • 4 months later...

Hallo,

 

ich denke wir benutzen das Script was hier steht. Wurde bei uns eingerichtet. An Pfingsten hat es aber leider nicht funktioniert (war der erste Versuch nach der Installation der TK-Anlage). Ich verstehe das Vorgehen das einbinden nur teilweise. Die Funktion ist bei uns im Block "Start" eingetragen.

1193565232_2_hndischer.jpg.a44b3af155ddab1155c1578e46c10c87.jpg

 

Dann gibt es noch einen Block "Variable setzen", da wird die Funktion nicht aufgerufen. Aber im Block "händischer Schalter" steht bei Parameter folgendes drin:

 

 

1193565232_2_hndischer.jpg.a44b3af155ddab1155c1578e46c10c87.jpg

 

Wurde hier vielleicht nur was falsches kopiert und er ruft die Funktion nicht auf? Wir brauchen halt die Statusmöglichkeiten kein Feiertag, regionaler usw....Aber auch den händischen Schalter der Funktion. Habt ihr einen Tipp?

 

Vielen Dank


Stephan

 

 

1_start.jpg

Link to comment
Share on other sites


Hallo Tom,

 

das steht dort drin. Mache gerade den Live-Test. Wir haben Feiertag und es klappt. nicht. Nach 3 mal klingeln beendet er den Anruf anstand Bandansage. Würde ja gerne den Code übernehmen oben, aber leider fehlen mir ein paar Screenshots wie es nachher auszusehen hat.

1_setzen.jpg.25c4042cfaf50113367f7d8bd56b655b.jpg

 

364567710_setzen2.jpg.87f71682dc3c02c853c1c7790abf55d3.jpg

 

 

Link to comment
Share on other sites


An welcher Stelle rufst Du die Feiertags Funktion denn auf? Ich sehe das nirgendwo.

 

Bitte mache es genau so wie im ersten Post in diesem Topic beschrieben, d.h. den Code in den Start Block kopieren, und anschliessend per Variable auswerten Block die Funktion aufrufen.

Link to comment
Share on other sites


Hallo,

 

ich bin aufgrund der Möglichkeit zum Abbilden von einer Feiertagsregelung auf diesen Eintrag gestoßen. Allerdings erhalte ich nach Einfügen des Skripts in den Start Parameter beim Anruf direkt einen Besetztton. Woran kann dies liegen?

 

Vielen Dank vorab!

Link to comment
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
 Share


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and have taken note of our Privacy Policy.
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.