Sub ConstructShiftSchedule(FromYear As Int, ToYear As Int, ShiftPattern As String, ShiftDateAlign As Int) As Map
Dim ShiftSchedule As Map
ShiftSchedule.Initialize
Dim ShiftPatternDay As Int = Modulus(ShiftDateAlign, ShiftPattern.Length) 'get into range 0 .. (ShiftPattern.Length - 1) inclusive
For Y = FromYear To ToYear
For M = 1 To 12
For D = 1 To NumDaysInMonth(Y, M)
ShiftSchedule.Put(ZeroPadLeft(D, 2) & "-" & ZeroPadLeft(M, 2) & "-" & Y, ShiftPattern.CharAt(ShiftPatternDay).As(String))
ShiftPatternDay = (ShiftPatternDay + 1) Mod ShiftPattern.Length 'keep within range
Next
Next
Next
Return ShiftSchedule
End Sub
Sub Modulus(N As Int, D As Int) As Int
Return ((N Mod D) + D) Mod D 'fix for negative N
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout")
Dim ShiftName As Map
ShiftName.Initialize
ShiftName.Put("m", "Mattino 09:00-17:00")
ShiftName.Put("p", "Pomeriggio 17:00-01:00 del giorno successivo")
ShiftName.Put("n", "Notte 01:00-09:00")
ShiftName.Put("-", " ? dormire, non lavorare ?")
ShiftName.Put("+", " ? festa tutto il giorno ?")
Dim ShiftSchedule As Map = ConstructShiftSchedule(2020, 2026, "mmppnn-+", 6)
For D = 10 To 31
Dim DateToGet As String = D & "-12-2022"
Log( _
DateToGet & TAB & _
ShiftSchedule.Get(DateToGet) & TAB & _
ShiftName.Get(ShiftSchedule.Get(DateToGet)) _
)
Next
End Sub