#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region
'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private Button1 As B4XView
Dim dialog As B4XDialog
Private Base As B4XView
End Sub
Public Sub Initialize
' B4XPages.GetManager.LogEvents = True
dialog.Initialize (Base)
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
End Sub
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
Sub ConstructShiftSchedule(FromYear As Int, ToYear As Int, ShiftPattern As String, Jan1stPatternDay As Int) As Map
Dim ShiftSchedule As Map
ShiftSchedule.Initialize
Dim ShiftPatternDay As Int = Jan1stPatternDay
For Y = FromYear To ToYear
For M = 1 To 12
For D = 1 To NumDaysInMonth(Y, M)
ShiftSchedule.Put(ZeroPadLeft(M, 2) & "-" & ZeroPadLeft(D, 2) & "-" & Y, ShiftPattern.CharAt(ShiftPatternDay).As(String))
ShiftPatternDay = (ShiftPatternDay + 1) Mod ShiftPattern.Length
Next
Next
Next
Return ShiftSchedule
End Sub
Sub NumDaysInMonth(Year As Int, Month As Int) As Int
Select Month
Case 9, 4, 6, 11 'thirty days hath september...
Return 30
Case 2 'except february
If (Year Mod 4) = 0 Then
Return 29
Else
Return 28
End If
Case Else 'and all the others
Return 31
End Select
End Sub
Sub ZeroPadLeft(S As String, L As Int) As String
Dim ZS As String = S
Do While ZS.Length < L
ZS = "0" & ZS
Loop
Return ZS
End Sub
Private Sub Button1_Click
Dim calendario As B4XDateTemplate
Dim ShiftName As Map
ShiftName.Initialize
ShiftName.Put("m", "Morning 9am to 5pm")
ShiftName.Put("a", "Afternoon 5pm to 1am next day")
ShiftName.Put("n", "Night 1am to 9am")
ShiftName.Put("-", "?")
ShiftName.Put("=", "? Party All Day ?")
Dim ShiftSchedule As Map = ConstructShiftSchedule(2020, 2026, "mmmmm-aaaaa=nnnnn-", 9)
For D = 10 To 31
Wait For (dialog.ShowTemplate(calendario, "", "", "CANCEL")) Complete (Result As Int)
If Result = xui.DialogResponse_Positive Then
Dim K As String = DateTime.Date(calendario.Date)
Log("Date = " & K)
Log("Shift = " & ShiftSchedule.Get(K))
End If
Next
End Sub