Jump to content

Removing Saturday and Sunday from a count of dates


Recommended Posts

I created a little script to give me the number of days left before the end of the school year. Additionally, I took out Saturday and Sundays to just return a count of school days. But, I am guessing this is not the most elegant solution since I make an array of available dates and then remove the Saturdays and Sundays. Anyone else have a better idea of how I could have achieved this?

;Count the number of days left in school
#AutoIt3Wrapper_Run_Tidy=Yes
#include
#include

Local $sLastDayOfSchool = "2013/06/12"
Local $sTodaysDate = @YEAR & "/" & @MON & "/" & @MDAY
Local $sStartDate = $sTodaysDate

Local $iDaysCalc = _DateDiff('d', _NowCalc(), $sLastDayOfSchool); Calculated the number of days left
Local $sNewDate
Local $aArrayOfDates[1]

;Figure out how many weekdays are left
; ....Try making an array of dates, then taking out Sat and Sun? Seems like there should be a better way

Do
$sNewDate = _DateAdd('d', 1, $sStartDate) ; Add 1 day
$sStartDate = $sNewDate
$sSplitDate = StringSplit($sNewDate, "/") ;Split the date, so we can remove the Saturdays and Sundays
$iDateAsDayOfWeek = _DateToDayOfWeek($sSplitDate[1], $sSplitDate[2], $sSplitDate[3]) ;Return the days as an integer (Sun =1, Sat = 7)

If Not (($iDateAsDayOfWeek == 1) Or (_DateDayOfWeek($sNewDate) == 7)) Then ;Remove all 1's and 7's (Sun/Sat)
_ArrayAdd($aArrayOfDates, $sNewDate) ;Add to array
EndIf
Until ($sNewDate = $sLastDayOfSchool) ;Stop on the last Day of school
$aArrayOfDates[0] = UBound($aArrayOfDates) - 1 ;Make the 0-index = the Ubound

;~ _ArrayDisplay($aArrayOfDates)

MsgBox(0, "Countdown", $iDaysCalc & " total days left" & @CRLF & $aArrayOfDates[0] & " school days left")
Link to comment
Share on other sites

another example:

#include <Date.au3>
 
#include <Date.au3>
Local $sLastDayOfSchool = "2013/06/12"
Local $sTodaysDate = @YEAR & "/" & @MON & "/" & @MDAY
$sDate = $sTodaysDate
$iDaysLeft = 0
While _DateDiff('d', $sDate, $sLastDayOfSchool) > 0
 $aTemp = StringSplit($sDate, "/")
 $iDate =_DateToDayOfWeek($aTemp[1], $aTemp[2], $aTemp[3])
 ConsoleWrite($iDate & " " )
 If $iDate <> 1 And $iDate <> 7 Then
  $iDaysLeft += 1
 EndIf
 $sDate = _DateAdd("D", 1, $sDate)
 ConsoleWrite($iDaysLeft & @CRLF)
WEnd
MsgBox(1, 1, $iDaysLeft)
Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

  • Developers

I created a little script to give me the number of days left before the end of the school year. Additionally, I took out Saturday and Sundays to just return a count of school days. But, I am guessing this is not the most elegant solution since I make an array of available dates and then remove the Saturdays and Sundays. Anyone else have a better idea of how I could have achieved this?

Are you sure it is even working correctly?

I think this line is wrong as the second test after the Or seems to be off:

If Not (($iDateAsDayOfWeek == 1) Or (_DateDayOfWeek($sNewDate) == 7)) Then ;Remove all 1's and 7's (Sun/Sat)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Are you sure it is even working correctly?

I think this line is wrong as the second test after the Or seems to be off:

If Not (($iDateAsDayOfWeek == 1) Or (_DateDayOfWeek($sNewDate) == 7)) Then ;Remove all 1's and 7's (Sun/Sat)

You know, you might be correct. It works, in that it produces a result, but that 2nd test does look off, I'll go back and verify. Thanks for catching that!

another example:

#include <Date.au3>

#include <Date.au3>
Local $sLastDayOfSchool = "2013/06/12"
Local $sTodaysDate = @YEAR & "/" & @MON & "/" & @MDAY
$sDate = $sTodaysDate
$iDaysLeft = 0
While _DateDiff('d', $sDate, $sLastDayOfSchool) > 0
$aTemp = StringSplit($sDate, "/")
$iDate =_DateToDayOfWeek($aTemp[1], $aTemp[2], $aTemp[3])
ConsoleWrite($iDate & " " )
If $iDate <> 1 And $iDate <> 7 Then
$iDaysLeft += 1
EndIf
$sDate = _DateAdd("D", 1, $sDate)
ConsoleWrite($iDaysLeft & @CRLF)
WEnd
MsgBox(1, 1, $iDaysLeft)

I like this! Yea, that is more elegant. Thanks for taking the time to show me another approach.
Link to comment
Share on other sites

Another approach:

You only need to examine the first (partial) and last (partial) weeks of the time range by day. The rest can be processed by week.

Start by processing every day until you reach a monday (first week is complete). Add 7 to the day count. If the date is still in the range, add 5 to the total day count. If it is out of range, go back six days and then process every day.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Without any loop:

#include <Date.au3>

Local $Date1 = "2013/05/02"
Local $Date2 = _NowCalcDate()

ConsoleWrite("There are " & _WorkDays($Date1, $Date2) & " work days (Mon..Fri) between " & $Date1 & " and " & $Date2 & " (included)." & @LF)

Func _WorkDays($DateFrom, $DateTo)
    Local $Date = StringSplit($DateFrom, '-/', 2)
    Local $DayFrom = _DateToDayOfWeekISO($Date[0], $Date[1], $Date[2]) - 1
    $Date = StringSplit($DateTo, '-/', 2)
    Local $DayTo = _DateToDayOfWeekISO($Date[0], $Date[1], $Date[2]) - 1
    Local Const $ExtraDays[7][7] = [[0, 1, 2, 3, 4, 4, 4],[4, 0, 1, 2, 3, 3, 3],[3, 4, 0, 1, 2, 2],[2, 3, 4, 0, 1, 2, 2],[1, 2, 3, 4, 0, 1, 2],[1, 2, 3, 4, 5, 0, 1],[1, 2, 3, 4, 5, 5, 0]]
    Return (Floor(_DateDiff('D', $DateFrom, $DateTo) / 7) * 5 + $ExtraDays[$DayFrom][$DayTo] + 1)
EndFunc ;==>_WorkDays

Leave or remove the +1 in the result returned depending on whether you count today-->today as 1 day or 0.

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

@jchd

Very nice. Can you explain how you came up with the $ExtraDays array to me?

Also, shouldn't the return line be?

Return (Floor(_DateDiff('D', $DateFrom, $DateTo) / 7) * 5 + $ExtraDays[$DayFrom-1][$DayTo-1])

I also found that having the +1 at the end may end up including a Sat or Sun.

edit: I suppose you could always deduct 1 from _DateToDayOfWeekISO funcs.

Edited by spudw2k
Spoiler

Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder
Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array
Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc
Cool Stuff: AutoItObject UDF â—Š Extract Icon From Proc â—Š GuiCtrlFontRotate â—Š Hex Edit Funcs â—Š Run binary â—Š Service_UDF

 

Link to comment
Share on other sites

You can try this one. It is a German version of getting the working days.

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#region ### START Koda GUI section ### Form=
$GUI = GUICreate("Anzahl Arbeitstage per AutoIt", 321, 169, 192, 124)
GUICtrlCreateGroup("", 8, 0, 305, 161)
GUICtrlCreateLabel("StartDatum", 16, 28, 57, 21)
GUICtrlCreateLabel("EndeDatum", 16, 52, 60, 21)
$start_D = GUICtrlCreateDate(_NowCalcDate(), 120, 24, 186, 21, $DTS_SHORTDATEFORMAT)
$end_D = GUICtrlCreateDate(_NowCalcDate(), 120, 48, 186, 21, $DTS_SHORTDATEFORMAT)
$state_CB = GUICtrlCreateCombo("01 SH Schleswig-Holstein", 120, 72, 185, 25)
GUICtrlSetData(-1, "02 HH Hansestadt Hamburg|03 NI Niedersachsen|04 HB Freie Hansestadt Bremen|05 NW Nordrhein-Westfalen" & _
"|06 HE Hessen|07 RP Rheinland-Pfalz|08 BW Baden-Württemberg|09 BY Bayern|10 SL Saarland|11 BE Berlin|12 BB Brandenburg|13 MV Mecklenburg-Vorpommern" & _
"|14 SN Freistaat Sachsen|15 ST Sachsen-Anhalt|16 TH Thüringen", "")
GUICtrlCreateLabel("Bundesland", 16, 76, 60, 21)
GUICtrlCreateLabel("Anzahl Arbeitstage", 16, 100, 92, 21)
$wdays_I = GUICtrlCreateInput("", 120, 96, 185, 21)
GUICtrlCreateGroup("", 8, 120, 305, 41)
$calc_B = GUICtrlCreateButton("Berechnen", 16, 130, 139, 25, $WS_GROUP)
$exit_B = GUICtrlCreateButton("Beenden", 168, 130, 139, 25, $WS_GROUP)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
;~ #EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit (0)
Case $exit_B
Exit (0)
Case $calc_B
ConsoleWrite(GUICtrlRead($start_D) & @CRLF)
ConsoleWrite(GUICtrlRead($end_D) & @CRLF)
ConsoleWrite(GUICtrlRead($state_CB) & @CRLF)
ConsoleWrite(GUICtrlRead($wdays_I) & @CRLF)
GUICtrlSetData($wdays_I, _GetWorkingDaysInRange(GUICtrlRead($start_D), GUICtrlRead($end_D), Int(GUICtrlRead($state_CB))))
ConsoleWrite(_GetWorkingDaysInRange('01.01.2011', '07.01.2011', '') & @CRLF)
EndSwitch
WEnd

; $iCountWorkDays = Standard-Arbeitstage (5= Mo-Fr; 6=Mo-Sa; 7=Mo-So)
; Übergabe deutsches Datum: TT.MM.JJJJ, ; $vFederalState = Index oder Kürzel des BuLandes, Bundesweit Gesetzlich (BG) = 0
Func _GetWorkingDaysInRange($sFromDate, $sToDate, $vFederalState, $iCountWorkDays = 5)
Local $aSplitFrom = StringSplit($sFromDate, '.', 2)
Local $aSplitTo = StringSplit($sToDate, '.', 2)
Local $aYears[1] = [$aSplitFrom[2]] ; für jahresübergreifende Daten
If $aSplitTo[2] <> $aSplitFrom[2] Then
ReDim $aYears[$aSplitTo[2] - $aSplitFrom[2] + 1]
For $i = 1 To UBound($aYears) - 1
$aYears[$i] = $aYears[$i - 1] + 1
Next
EndIf
Local $aHolidays, $iWorkingDayCounter = 0, $n = 0, $sTmpDate
Switch UBound($aYears)
Case 1 ; Datumswerte in einem Jahr
$aHolidays = _Feiertage($aYears[0], $vFederalState, 0, 0, 1)
Do
$sTmpDate = _DateAdd('D', $n, $aSplitFrom[2] & '/' & $aSplitFrom[1] & '/' & $aSplitFrom[0])
$iWorkingDayCounter += _IsWorkingDay($aHolidays, $sTmpDate)
$n += 1
Until $aSplitTo[2] & '/' & $aSplitTo[1] & '/' & $aSplitTo[0] = $sTmpDate
Case 2 ; Datumswerte in zwei Jahren
$aHolidays = _Feiertage($aYears[0], $vFederalState, 0, 0, 1)
Do
$sTmpDate = _DateAdd('D', $n, $aSplitFrom[2] & '/' & $aSplitFrom[1] & '/' & $aSplitFrom[0])
$iWorkingDayCounter += _IsWorkingDay($aHolidays, $sTmpDate)
$n += 1
If $aSplitFrom[2] & '/12/31' = $sTmpDate Then $aHolidays = _Feiertage($aYears[1], $vFederalState, 0, 0, 1)
Until $aSplitTo[2] & '/' & $aSplitTo[1] & '/' & $aSplitTo[0] = $sTmpDate
Case Else ; Datumswerte über mehr als 2 Jahre
Local $tmpYear, $index = 0, $sDateEnd = $aSplitTo[2] & '/' & $aSplitTo[1] & '/' & $aSplitTo[0]
$aHolidays = _Feiertage($aYears[$index], $vFederalState, 0, 0, 1)
Do
$sTmpDate = _DateAdd('D', $n, $aSplitFrom[2] & '/' & $aSplitFrom[1] & '/' & $aSplitFrom[0])
$iWorkingDayCounter += _IsWorkingDay($aHolidays, $sTmpDate)
$n += 1
$tmpYear = StringLeft($sTmpDate, 4)
If $tmpYear & '/12/31' = $sTmpDate And $tmpYear & '/12/31' <> $sDateEnd Then
$index += 1
$aHolidays = _Feiertage($aYears[$index], $vFederalState, 0, 0, 1)
EndIf
Until $sDateEnd = $sTmpDate
EndSwitch
Return $iWorkingDayCounter
EndFunc ;==>_GetWorkingDaysInRange

Func _IsWorkingDay(ByRef $aHolidays, $sDate, $iCountWorkDays = 5)
Local $sFreeDay = 'N' ; 7 Werktage, ./. frei
If $iCountWorkDays = 5 Then ; 5 Werktage, Sa/So frei
$sFreeDay = '6 7'
ElseIf $iCountWorkDays = 6 Then ; 6 Werktage, So frei
$sFreeDay = '7'
EndIf
Local $aSplitDate = StringSplit($sDate, '/', 2)
Local $iWeekday = _DateToDayOfWeekISO($aSplitDate[0], $aSplitDate[1], $aSplitDate[2])
If @error Then Return 0
If StringInStr($sFreeDay, $iWeekday) Then Return 0 ; ist Sa./So. = kein WorkingDay
Local $index = _ArraySearch($aHolidays, $sDate, 0, 0, 1)
If $index = -1 Then Return 1 ; nicht in Feiertagen (u. kein Sa./So.) = WorkingDay
Local $sDay = StringRight($sDate, 5)
ConsoleWrite($sDay & @CRLF)
If $sDay = '12/24' Or $sDay = '12/31' Then
ConsoleWrite("0.5 Tg" & @CRLF)
Return 0.5 ; Halber Feiertag (24./31. Dez.)
EndIf
Return 0 ; in Feiertagen = kein WorkingDay
EndFunc ;==>_IsWorkingDay

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Funktion _Feiertage($Jahr)
;
; gibt die Feiertage des übergebenen Jahres
; als sortiertes Array[TT.MM.JJJJ od. JJJJ/MM/TT][Feiertag][Geltungsbereich][opt. Wochentag] zurück
; Geltungsbereich Leerstring - kein offizieller Feiertag
; BG - Bundesweit Gesetzlich
; Regionalkennzeichen: BB-Brandenburg BE-Berlin BW-Baden-Württemberg BY-Bayern
; HB-Bremen HE-Hessen HH-Hamburg MV-Mecklenburg-Vorpommern
; NI-Niedersachsen NW-Nordrhein-Westfalen RP-Rheinland-Pfalz
; SH-Schleswig-Holstein SL-Saarland SN-Sachsen
; ST-Sachsen-Anhalt TH-Thüringen
; $vBundesland -1 alle Feiertage mit Geltungsbereich (Bundesländer), (Standard)
; 0 BG nur Bundesweit gesetzlich
;
; Bundesland (inkl. BG)
; 1 SH Schleswig-Holstein
; 2 HH Freie und Hansestadt Hamburg
; 3 NI Niedersachsen
; 4 HB Freie Hansestadt Bremen
; 5 NW Nordrhein-Westfalen
; 6 HE Hessen
; 7 RP Rheinland-Pfalz
; 8 BW Baden-Württemberg
; 9 BY Bayern
; 10 SL Saarland
; 11 BE Berlin
; 12 BB Brandenburg
; 13 MV Mecklenburg-Vorpommern
; 14 SN Freistaat Sachsen|Sachsen
; 15 ST Sachsen-Anhalt
; 16 TH Thüringen
; $DateTyp 1 - Datum als TT.MM.JJJJ (Standard)
; 0 - Datum als JJJJ/MM/TT
; $wDay 0 - geändert: Rückabe Wochentag numerisch 1-7 / Sonntag-Samstag
; 1 - Rückgabe Wochentag ($array[n][3])
; $sort 0 - gegliedert fix/variabel (Standard), innerhalb sortiert
; 1 - komplett sortiert
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func _Feiertage($year, $vBundesland = -1, $DateTyp = 1, $wDay = 0, $sort = 0)
Local $4AdvDat, $3AdvDat, $2AdvDat, $1AdvDat, $TotSoDat, $BuBDat, $MutterDat, $ErnteDat, $tmp
Local $HDays[33][4], $a, $b, $c, $d, $e, $H1, $H2, $n, $M
Local $aWDays[8] = [7, 'Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Sonnabend']
Local $aBuLand[17] = ['BG', 'SH', 'HH', 'NI', 'HB', 'NW', 'HE', 'RP', 'BW', 'BY', 'SL', 'BE', 'BB', 'MV', 'SN', 'ST', 'TH']
If IsString($vBundesland) Then $vBundesland = _ArraySearch($aBuLand, $vBundesland)
;fixe Feiertage
$HDays[0][0] = $year & "/01/01\Neujahr\BG"
$HDays[1][0] = $year & "/01/06\Heilige Drei Könige\BW BY ST"
$HDays[2][0] = $year & "/02/14\Valentinstag\"
$HDays[3][0] = $year & "/05/01\Maifeiertag\BG"
$HDays[4][0] = $year & "/08/15\Mariä Himmelfahrt\BY SL"
$HDays[5][0] = $year & "/10/03\Tag der Deutschen Einheit\BG"
$HDays[6][0] = $year & "/10/31\Reformationstag\BB MV SN ST TH"
$HDays[7][0] = $year & "/11/01\Allerheiligen\BW BY NW RP SL"
$HDays[8][0] = $year & "/12/24\Heiligabend\BG"
$HDays[9][0] = $year & "/12/25\1. Weihnachtsfeiertag\BG"
$HDays[10][0] = $year & "/12/26\2. Weihnachtsfeiertag\BG"
$HDays[11][0] = $year & "/12/31\Silvester\BG"
;variable Feiertage
$a = Mod($year, 19)
$b = Mod($year, 4)
$c = Mod($year, 7)
$H1 = Int($year / 100)
$H2 = Int($year / 400)
$n = 4 + $H1 - $H2
$M = 15 + $H1 - $H2 - Floor(Int((8 * $H1 + 13) / 25))
$d = Mod((19 * $a + $M), 30)
$e = Mod((2 * $b + 4 * $c + 6 * $d + $n), 7)
If $d + $e = 35 Then
$Easter = 50
Else
If $d = 28 And $e = 6 And $a > 10 Then
$Easter = 49
Else
$Easter = 22 + $d + $e
EndIf
EndIf
If $Easter < 32 Then
$EasterDay = $Easter
$EasterMonth = "03"
Else
$EasterDay = $Easter - 31
$EasterMonth = "04"
EndIf
If $EasterDay < 10 Then
$EasterDay = "0" & $EasterDay
EndIf
If $year < 1900 Then ; Datumsoperationen nur mgl. wenn > 1900 , Jahr wird konvertiert
$RestJahr = Mod($year, 100)
If _DateIsLeapYear($year) Then
If $RestJahr < 10 Then
$RestJahr = "0" & $RestJahr
EndIf
$Tempyear = 20 & $RestJahr
Else
If $RestJahr < 10 Then
$RestJahr = "0" & $RestJahr
EndIf
$Tempyear = 19 & $RestJahr
EndIf
$EasterDate = $Tempyear & "/" & $EasterMonth & "/" & $EasterDay
Else
$EasterDate = $year & "/" & $EasterMonth & "/" & $EasterDay
EndIf
$WFastDate = _DateAdd('d', -52, $EasterDate)
$RosDat = _DateAdd('d', -48, $EasterDate)
$FastDat = _DateAdd('d', -47, $EasterDate)
$AschDat = _DateAdd('d', -46, $EasterDate)
$GrDoDat = _DateAdd('d', -3, $EasterDate)
$KarDat = _DateAdd('d', -2, $EasterDate)
$OSaDat = _DateAdd('d', -1, $EasterDate)
$OSoDat = $EasterDate
$OMoDat = _DateAdd('d', 1, $EasterDate)
$HiFaDat = _DateAdd('d', 39, $EasterDate)
$PfSoDat = _DateAdd('d', 49, $EasterDate)
$PfMoDat = _DateAdd('d', 50, $EasterDate)
$FroDat = _DateAdd('d', 60, $EasterDate)
; Ermitteln nicht von Ostern abhängiger, veränderlicher Feiertage
; Muttertag = 2. Sonntag im Mai ABER wenn Pfingsten = 2.Sonntag im Mai dann ist Muttertag am 1. Sonntag
; Der 2. Sonntag kann nur zw. dem 8. u. 14.5. liegen
For $maitag = 8 To 14
If _DateToDayOfWeek($year, 5, $maitag) = 1 Then
If $maitag < 10 Then
$maitag = "0" & $maitag
EndIf
$MutterDat = $year & "/05/" & $maitag
If $MutterDat = $PfSoDat Then
$MutterDat = _DateAdd('d', -7, $year & "/05/" & $maitag)
EndIf
ExitLoop
EndIf
Next
; Erntedankfest 1. Sonntag im Oktober (zw. 1. u. 7.10.)
For $oktobertag = 1 To 7
If _DateToDayOfWeek($year, 10, $oktobertag) = 1 Then
$oktobertag = "0" & $oktobertag
$ErnteDat = $year & "/10/" & $oktobertag
ExitLoop
EndIf
Next
; 4.Advent = Sonntag vor 25.12. (zw. 18. u. 24.12.)
For $deztag = 18 To 24
If _DateToDayOfWeek($year, 12, $deztag) = 1 Then
$4AdvDat = $year & "/12/" & $deztag
$3AdvDat = _DateAdd('d', -7, $4AdvDat)
$2AdvDat = _DateAdd('d', -14, $4AdvDat)
$1AdvDat = _DateAdd('d', -21, $4AdvDat)
$TotSoDat = _DateAdd('d', -28, $4AdvDat)
$BuBDat = _DateAdd('d', -32, $4AdvDat)
ExitLoop
EndIf
Next
$HDays[12][0] = $WFastDate & "\Weiberfastnacht\"
$HDays[13][0] = $RosDat & "\Rosenmontag\"
$HDays[14][0] = $FastDat & "\Fastnacht\"
$HDays[15][0] = $AschDat & "\Aschermittwoch\"
$HDays[16][0] = $GrDoDat & "\Gründonnerstag\"
$HDays[17][0] = $KarDat & "\Karfreitag\BG"
$HDays[18][0] = $OSaDat & "\Ostersamstag\"
$HDays[19][0] = $OSoDat & "\Ostersonntag\"
$HDays[20][0] = $OMoDat & "\Ostermontag\BG"
$HDays[21][0] = $HiFaDat & "\Christi Himmelfahrt\BG"
$HDays[22][0] = $PfSoDat & "\Pfingstsonntag\"
$HDays[23][0] = $PfMoDat & "\Pfingstmontag\BG"
$HDays[24][0] = $MutterDat & "\Muttertag\"
$HDays[25][0] = $FroDat & "\Fronleichnam\BW BY HE NW RP SL SN TH"
$HDays[26][0] = $ErnteDat & "\Erntedankfest\"
$HDays[27][0] = $BuBDat & "\Buß- und Bettag\SN"
$HDays[28][0] = $TotSoDat & "\Totensonntag\"
$HDays[29][0] = $1AdvDat & "\1. Advent\"
$HDays[30][0] = $2AdvDat & "\2. Advent\"
$HDays[31][0] = $3AdvDat & "\3. Advent\"
$HDays[32][0] = $4AdvDat & "\4. Advent\"
If $sort Then
_ArraySort($HDays)
Else
_ArraySort($HDays, 0, 0, 11)
_ArraySort($HDays, 0, 12)
EndIf
For $i = 0 To 32
$tmp = StringSplit($HDays[$i][0], "\", 2)
If $DateTyp Then ; Datum konvertieren zu TT.MM.JJJJ
$HDays[$i][0] = StringRight($tmp[0], 2) & "." & StringMid($tmp[0], 6, 2) & "." & StringLeft($tmp[0], 4)
Else
$HDays[$i][0] = $tmp[0]
EndIf
$HDays[$i][1] = $tmp[1]
$HDays[$i][2] = $tmp[2]
If $wDay = 1 Then
$HDays[$i][3] = $aWDays[_DateToDayOfWeek(StringLeft($tmp[0], 4), StringMid($tmp[0], 6, 2), StringRight($tmp[0], 2))]
Else
$HDays[$i][3] = _DateToDayOfWeek(StringLeft($tmp[0], 4), StringMid($tmp[0], 6, 2), StringRight($tmp[0], 2))
EndIf
Next
If $vBundesland > -1 Then
Local $aTmp[1][4]
For $i = 0 To 32
If StringInStr($HDays[$i][2], $aBuLand[$vBundesland], 1) Or StringInStr($HDays[$i][2], 'BG', 1) Then
If $aTmp[UBound($aTmp) - 1][0] <> '' Then ReDim $aTmp[UBound($aTmp) + 1][4]
$aTmp[UBound($aTmp) - 1][0] = $HDays[$i][0]
$aTmp[UBound($aTmp) - 1][1] = $HDays[$i][1]
$aTmp[UBound($aTmp) - 1][2] = $HDays[$i][2]
$aTmp[UBound($aTmp) - 1][3] = $HDays[$i][3]
EndIf
Next
Return $aTmp
EndIf
Return $HDays
EndFunc ;==>_Feiertage

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Hi Xeno,

Of course you're right, both day-of-week should be one less and it was supposed to be coded this way, else array indices will overflow array size for sunday dates! I have fixed the code posted above.

Ooops!

About the values in the array: I simply hardcoded them by simple count for row 0 then shifted and adjusted subsequent rows. I've tried to come up with a closed form formula but it's complexity far exceeds a dumb constant lookup like I used.

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Spudw. :P

Any the array? How you make?

Spoiler

Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder
Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array
Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc
Cool Stuff: AutoItObject UDF â—Š Extract Icon From Proc â—Š GuiCtrlFontRotate â—Š Hex Edit Funcs â—Š Run binary â—Š Service_UDF

 

Link to comment
Share on other sites

See post edited above.

I had a use for actual worked days (excluding fixed and mobile hollydays [Easter-based]) but it's too specific to be of general use here.

Since I had to cover periods a bit longer than one year I had to take mobile hollydays for 2 years into account. I also had extra entries for days where the (variable) French post vans are prohibited to circulate, also for days on strike (!). I excluded those dates by dichotomy in the sorted hollydays array and counting dates being between date from and dateto.

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

... I also had extra entries for days where the (variable) French post vans are prohibited to circulate, also for days on strike (!).

Doesn't this returns the 'number of days left for school work' instead of 'number of days left before the end of the school year' ?

In this case you forgot in the extra entries the 'teachers absences due to illness' :)

Link to comment
Share on other sites

Not precisely. Its main use was for managing parcel tracking data and detecting obsolescence of parcels having experienced problems (lost, delayed beyond contract, damaged, not sent) while reimbursements were being claimed.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...