; #INDEX# ======================================================================================================================= ; Title .........: WorkingDaysDifference ; AutoIt Version : v3.3.14.2 ; Language ......: English ; Description ...: Functions that calculate number of working days between two dates including holidays in Poland ; Author(s) .....: maniootek ; Script version : 1.0 ; =============================================================================================================================== ;_DateGetEaster from: ;https://www.autoitscript.com/trac/autoit/ticket/1715#comment:3 #include Global $aConstHolidaysInPoland = [[01,01], [06, 01], [01,05], [03,05], [15, 08], [01,11], [11,11], [25, 12], [26,12]] ; #FUNCTION# ========================================================================================================= ; Name...........: WorkingDaysDifference ; Description ...: Loads the TreeView from a delimited string of item titles, level and check state ; Syntax.........: WorkingDaysDifference($Start_Date, $End_Date) ; Parameters ....: $Start_Date - Start date in default date format yyyy/mm/dddd ; $End_Date - End date in default date format yyyy/mm/dddd ; Return values .: Intiger (number of days) ;===================================================================================================================== Func WorkingDaysDifference($Start_Date, $End_Date) Local $DT = $Start_Date, $iCount = 0, $Y, $M, $D if $Start_Date > $End_Date then Return False While $DT <= $End_Date $Y = StringRegExpReplace($DT, "(\d+)/.*", "$1") $M = StringRegExpReplace($DT, ".*/(\d+)/.*", "$1") $D = StringRegExpReplace($DT, ".*/(\d+)", "$1") If _DateToDayOfWeek($Y, $M, $D) <> 1 And _DateToDayOfWeek($Y, $M, $D) <> 7 and not _DateIsHoliday($Y, $M, $D) Then $iCount += 1 EndIf $DT = _DateAdd("D", 1, $DT) WEnd Return $iCount EndFunc Func _DateIsHoliday($iYear, $iMonth, $iDay) $date = $iYear & "/" & $iMonth & "/" & $iDay for $i = 0 to Ubound($aConstHolidaysInPoland) - 1 if $aConstHolidaysInPoland[$i][0] = $iDay and $aConstHolidaysInPoland[$i][1] = $iMonth Then Return 1 EndIf Next if _DateGetCorpusChristi($iYear) = $date then Return 1 if _DateGetEasterMonday($iYear) = $date then Return 1 EndFunc Func _DateGetCorpusChristi($iYear = @YEAR) ;60 days after Easter Return _DateAdd('d', 60, _DateGetEaster($iYear)) EndFunc Func _DateGetEasterMonday($iYear = @YEAR) ;1 day after Easter Return _DateAdd('d', 1, _DateGetEaster($iYear)) EndFunc Func _DateGetEaster($iYear, $method = 3) Local $iDay = 0 ; default values for invalid arguments Local $iMonth = 0 $iYear = Int($iYear) If $method < 1 Or $method > 3 Then Return SetError(1, 0, "") ; Method must be 1, 2 or 3 ElseIf $method = 1 And $iYear < 326 Then Return SetError(2, 0, "") ; The original calculation applies to all years from 326 AD ElseIf ($method = 2 Or $method = 3) And ($iYear < 1583 Or $iYear > 4099) Then Return SetError(3, 0, "") ; Gregorian calendar Easters apply for years 1583 to 4099 only EndIf Local $g ; golden year - 1 Local $c ; century Local $h ; = (23 - Epact) mod 30 Local $i ; no of days from March 21 to Paschal Full Moon Local $j ; weekday for PFM (0=Sunday, etc) Local $p ; no of days from March 21 to Sunday on or before PFM ; (-6 to 28 methods 1 & 3, to 56 for method 2) Local $e = 0 ; extra days to add for method 2 (converting Julian date to Gregorian date) $c = Int($iYear / 100) $g = Mod($iYear, 19) If $method = 1 Or $method = 2 Then ; old method (Julian) $i = Mod((19 * $g + 15), 30) $j = Mod($iYear + Int($iYear / 4) + $i, 7) If $method = 2 Then ; extra dates to convert Julian to Gregorian date (Orthodox Church) $e = 10 If $iYear > 1600 Then $e = $e + $c - 16 - Int(($c - 16) / 4) EndIf ElseIf $method = 3 Then ; new method (Gregorian -> Western Church) $h = Mod($c - Int($c / 4) - Int((8 * $c + 13) / 25) + 19 * $g + 15, 30) $i = $h - Int($h / 28) * (1 - Int(29 / ($h + 1)) * Int((21 - $g) / 11)) $j = Mod($iYear + Int($iYear / 4) + $i + 2 - $c + Int($c / 4), 7) EndIf ; return day and month $p = $i - $j + $e ; p can be from -6 to 56 corresponding to dates 22 March to 23 May ; (later dates apply to method 2, although 23 May never actually occurs) $iMonth = 3 + Int(($p + 26) / 30) $iDay = 1 + Mod($p + 27 + Int(($p + 6) / 40), 31) If $iDay < 10 Then $iDay = String("0" & $iDay) Return $iYear & "/0" & $iMonth & "/" & $iDay EndFunc ;==>_DateGetEaster