rudi Posted November 7, 2012 Share Posted November 7, 2012 (edited) Hi. For a certain task I need to know, if "today" is a working day (Mo-Fr, and not a Holiday either). Maybe someone else comes across a similar task: expandcollapse popup; Autoit v3.3.8.1 #region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Res_LegalCopyright=Rudolf Thilo, IT-Beratung Rudolf Thilo #AutoIt3Wrapper_Res_Language=1031 ://////=__=.= ://////=__==forum: "rudi") #endregion ;**** Directives created by AutoIt3Wrapper_GUI **** #include-once #include <Date.au3> #include <array.au3> ; Example Call for the function: $Result = CheckWorkingDay("2012/04/08") ; that was Easter Sunday this year If $Result == True Then ConsoleWrite("Working Day" & @LF) Else ConsoleWrite($Result & @LF) EndIf Func CheckWorkingDay($Date = False) ; Function to check, if a Date is a workingday (TRUE), or "Saturday", "Sunday", "Holiday" ; Add / Remove holidays by altering the Array $aHDay ; German National Holidays (Bavaria, predominantly katholic cities) are implemented, also the Easter dependant holidays are included. (Gauss' Easter Formula) ; ;Optional Parameter $Date: If no date value "yyyy/mm/dd" is specified, "today" will be processed ; A validity check for $Date is *NOT* done! ; ; Return value: "True", if "working day" is detected; otherwise: "Saturday", "Sunday" or "Holiday" ; if a Saturday or Sunday is a Holiday as well, "Holiday" is returned. ; important note: As the return value is *NEVER* "False", you have to compare it with "==" instead of "=" !! ; Example: if CheckHoliday() == True then ... ; the statement "if CheckHoliday() then..." will *ALWAYS* be True, so it's useless as well. If $Date = False Then $Date = _NowCalcDate() ; Funktion within a Function Definition is not allowed: So $Date=False in definition, fill in "today" here... Local $Year = StringLeft($Date, 4) ; get the year Local $a, $b, $c, $d, $e, $m, $N, $k, $q If $Year < 1582 Then $Calendar = "julian" ; the retirement of the "Julian Calendar" began 1582. Else $Calendar = "gregorian" ; The use of the "Gegorian Calendar" started 1582. In 1949 China was the last state to introduce the Gregorian Calendar. EndIf $a = Mod($Year, 19) $b = Mod($Year, 4) $c = Mod($Year, 7) $k = Int($Year / 100) $p = Int((8 * $k + 13) / 25) $q = Int($k / 4) Switch $Calendar Case "gregorian" $m = Mod(15 + $k - $p - $q, 30) $N = Mod(4 + $k - $q, 7) Case "julian" $m = 15 $N = 6 EndSwitch $d = Mod(19 * $a + $m, 30) $e = Mod(2 * $b + 4 * $c + 6 * $d + $N, 7) $Shift = 22 + $d + $e ; could have used "21" here, saving the "-1" next line. Then it wouldn't match the Gauss Formula found elswhere in the web. $Easter = _DateAdd("D", $Shift - 1, $Year & "/03/01") ; "-1", because Gauss' Easter Rule returns the "Day-of-March", so we have to start at "-1" ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Easter = ' & $Easter & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console Local $aHDay[1] _ArrayAdd($aHDay, $Year & "/01/01") ; Neujahr _ArrayAdd($aHDay, $Year & "/01/06") ; Hl. 3 König #region Easter related holidays, Germany _ArrayAdd($aHDay, _DateAdd("D", -2, $Easter)) ; Karfreitag _ArrayAdd($aHDay, $Easter) ; Ostersonntag _ArrayAdd($aHDay, _DateAdd("D", 1, $Easter)) ; Ostermontag _ArrayAdd($aHDay, _DateAdd("D", 39, $Easter)) ; Christi Himmelfahrt _ArrayAdd($aHDay, _DateAdd("D", 49, $Easter)) ; Pfingstsonntag _ArrayAdd($aHDay, _DateAdd("D", 50, $Easter)) ; Pfingstmontag _ArrayAdd($aHDay, _DateAdd("D", 60, $Easter)) ; Fronleichnam #endregion Easter related holidays, Germany _ArrayAdd($aHDay, $Year & "/08/15") ; Mariä Himmelfahrt _ArrayAdd($aHDay, $Year & "/10/03") ; Tag der deutschen Einheit _ArrayAdd($aHDay, $Year & "/11/01") ; Allerheiligen _ArrayAdd($aHDay, $Year & "/12/25") ; 1. Weihnachtsfeiertag _ArrayAdd($aHDay, $Year & "/12/26") ; 2. Weihnachtsfeiertag ; add other national / regional holidays here: Reformationstag, Friedensfest, Buß & Bettag... Local $WorkingDay = True ; Retun value, in case the lines below don't detect Sat, Sun, Holiday. Local $Mon = StringMid($Date, 6, 2) Local $Day = StringRight($Date, 2) Switch _DateToDayOfWeekISO($Year, $Mon, $Day) ; 1 = Monday, 7 = Sunday Case 6 $WorkingDay = "Saturday" Case 7 $WorkingDay = "Sunday" EndSwitch For $i = 1 To UBound($aHDay) - 1 If $Date = $aHDay[$i] Then $WorkingDay = "Holiday" ExitLoop EndIf Next Return $WorkingDay #cs Osterabhängige Tage Rosenmontag: -48 Tage Faschingsdienstag: -47 Tage Karfreitag: -2 Tage Ostermontag: +1 Tag Christi Himmelfahrt: +39 Tage Pfingstsonntag: +49 Tage Pfingstmontag: +50 Tage Fronleichnam: +60 Tage #ce EndFunc ;==>CheckWorkingDay Regards, Rudi. Edited November 7, 2012 by rudi Skysnake and robertocm 2 Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
PhoenixXL Posted November 13, 2012 Share Posted November 13, 2012 (edited) you are complicating You can achieve it simply by this #RequireAdmin #include <Date.au3> Func GetWorkingDay($nDay, $nMon, $nYear) Local $aRet = False ;Get the Real Dates Local $pDay = @MDAY, $pMon = @MON, $pYear = @YEAR ;Set the Date to be Checked _SetDate($nDay, $nMon, $nYear) ; Set the current date to 20-10-2004 If @error Then Return SetError(@error,@extended,-1) ;Check Working Day If @WDAY == 1 Or @WDAY == 7 Then $aRet = True ;Set the Real Date _SetDate($pDay, $pMon, $pYear) If @error Then Return SetError(@error,@extended,-1) ;Return Return $aRet EndFunc ;==>GetWorkingDay MsgBox ( 64, @ScriptName & '| Phoenix XL', _ GetWorkingDay(07, 04, 2012) _ ) Edited November 13, 2012 by PhoenixXL My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
guinness Posted November 13, 2012 Share Posted November 13, 2012 PhoenixXL, Your version doesn't calculate German holidays as rudi's does. But the point for posting was your version can be consolidated to the following >> no need for _SetDate. #include <Date.au3> MsgBox(4096, '', 'Is today (' & @MDAY & '/' & @MON & '/' & @YEAR & ') a weekday/workingday? ' & _IsWeekday(@YEAR, @MON, @MDAY)) MsgBox(4096, '', 'Is today (10/11/2012) a weekday/workingday? ' & _IsWeekday(2012, 11, 10)) ; Saturday Func _IsWeekday($iYear, $iMonth, $iDay) ; YYYY/MM/DD Format. Local $iReturn = _DateToDayOfWeek($iYear, $iMonth, $iDay) Return SetError(@error, $iReturn, $iReturn > 1 And $iReturn < 7) EndFunc ;==>_IsWeekday UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
PhoenixXL Posted November 13, 2012 Share Posted November 13, 2012 Indeed My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
marcusawerly Posted September 2, 2019 Share Posted September 2, 2019 Exactly what I am looking for thank you!!!!! I have a script that I run an autodialer program from. I don't want it to run on holidays or sundays. Windows task scheduler can't do the holiday part! Marcus Link to comment Share on other sites More sharing options...
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