Tom Wellige Posted December 10, 2014 #1 Posted December 10, 2014 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. 1
Most Valued User srom Posted December 10, 2014 Most Valued User #2 Posted December 10, 2014 Bestes Skipt ever...danke Jörg.
Most Valued User Markus Wallner Posted December 18, 2014 Most Valued User #3 Posted December 18, 2014 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.
big_D Posted December 18, 2014 #4 Posted December 18, 2014 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.
Daniel Posted December 19, 2014 #5 Posted December 19, 2014 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 ?
Tom Wellige Posted January 5, 2015 Author #6 Posted January 5, 2015 To use this function within a call routing script just do the following:Copy & Paste the above code into the Start block. Call the function within an Evaluate (Variable auswerten) block. 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)) 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.
Most Valued User SvenS Posted January 21, 2015 Most Valued User #7 Posted January 21, 2015 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
Tom Wellige Posted January 21, 2015 Author #8 Posted January 21, 2015 I have updated the function code in the first post and also give some examples there. The parameters are more handy to use in the new version of the function. https://www.swyxforum.com/topic/185-public-holidays-in-germany-incl-federal-states/
Younes Posted January 21, 2015 #9 Posted January 21, 2015 Wow what a script! can someone explain the calculation method so i can change this to a dutch version?
Tom Wellige Posted January 21, 2015 Author #10 Posted January 21, 2015 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.
Most Valued User SvenS Posted January 22, 2015 Most Valued User #11 Posted January 22, 2015 The new script is working. Thanks Tom
Tom Wellige Posted January 22, 2015 Author #12 Posted January 22, 2015 Wow what a script! can someone explain the calculation method so i can change this to a dutch version? If you manage to create a dutch version of this function it would be nice if you would post it here as well. This is of course true also for ALL other countries :-)
Younes Posted January 23, 2015 #13 Posted January 23, 2015 If you manage to create a dutch version of this function it would be nice if you would post it here as well. This is of course true also for ALL other countries :-) Going to look in to it sometime!
Matthias Posted February 26, 2015 #14 Posted February 26, 2015 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) Cheers, Matthias
Most Valued User Virikas Posted February 26, 2015 Most Valued User #15 Posted February 26, 2015 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) If we still talk about the netherlands: It should be SoccerChampion =DateSerial(1/0, 2, 31) shouldn't it? SCNR
Matthias Posted February 27, 2015 #16 Posted February 27, 2015 ... 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
Tom Wellige Posted February 27, 2015 Author #17 Posted February 27, 2015 Thanks Matthias, I have copied your code directly into the first post of this thread!
Most Valued User JoergG Posted January 3, 2018 Most Valued User #18 Posted January 3, 2018 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
Most Valued User Markus Wallner Posted January 4, 2018 Most Valued User #19 Posted January 4, 2018 20 hours ago, JoergG said: Mariä Himmelfahrt is not a holiday anywhere in Bayern. That is not correct, Mariä Himmelfahrt is a public holiday in bavaria in local communities with mostly catholic population.
SFI_AC Posted May 29, 2018 #20 Posted May 29, 2018 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. 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: 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
Tom Wellige Posted May 30, 2018 Author #21 Posted May 30, 2018 Wie sieht denn der "Variable setzen" Block aus? Die Zeile "UseExit = bFeiertagCRM" im "Script Code einfügen" Block sieht falsch aus. Es sei denn, der Inhalt der Variable ist kein boolscher Wert (True, False) sondern eine Zahl zwischen 0 und 4.
SFI_AC Posted May 31, 2018 #22 Posted May 31, 2018 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.
Tom Wellige Posted May 31, 2018 Author #23 Posted May 31, 2018 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.
sschlabs Posted June 7, 2018 #24 Posted June 7, 2018 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!
Tom Wellige Posted June 8, 2018 Author #25 Posted June 8, 2018 Tritt der Fehler auf ohne dass die Funktion irgendwo aufgerufen wird, oder rufst Du die Funktion auch irgendwo auf? Hast Du die Funktion evtl. in mehrere Skripte von einem einzigen Benutzer kopiert?
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now