Android Question Date manipulation

Mattiaf

Active Member
Licensed User
Hey guys,

I wrote a vb.net code where I'm going to guess which shift I'll be working on a working cycle like
5 afternoon shifts
1 day off
5 morning shifts
1 day off
5 night shift
1 day off
and so forth

But I'm trying to replicate it for b4x but to be honest, I literally don't know where to start :\

Would someone mind to help me?
Much thanks..
Code

B4X:
Public Class Form1

    Private Sub DisplayShifts()
        Dim startdate = New DateTime(2022, 12, 24)
        Dim selectedDate = DateTimePicker1.Value

        Dim shift = GetShift(startdate, selectedDate)
        MsgBox(shift.ToString())
    End Sub
    Function GetShift(startDate As Date, selectedDate As Date) As ShiftKind
        Dim days = (selectedDate - startDate).TotalDays
        Dim intervals = days \ 18
        Dim normalizedSelected = selectedDate.AddDays(intervals * -18)
        days = (normalizedSelected - startDate).TotalDays
        Select Case days
            Case 0 To 4
                Return ShiftKind.Afternoon
            Case 6 To 10
                Return ShiftKind.Morning
            Case 12 To 16
                Return ShiftKind.Night
        End Select
        Return ShiftKind.Off
    End Function
    Public Structure Shift
        Public Property StartDate As Date
        Public Property EndDate As Date
        Public Property Kind As ShiftKind
        Public Function Contains(value As Date) As Boolean
            Return value >= StartDate AndAlso value <= EndDate
        End Function
        Public Overrides Function ToString() As String
            Return $"{StartDate} - {EndDate} : {Kind}"
        End Function
    End Structure
    Public Enum ShiftKind
        Off = 1
        Morning
        Afternoon
        Night
    End Enum

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        DisplayShifts()
    End Sub
End Class
 

emexes

Expert
Licensed User
But I'm trying to replicate it for b4x but to be honest, I literally don't know where to start :\

Maybe start with something like this:

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
    
    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("-", "-")
    
    Dim ShiftPattern As String = "aaaaa-mmmmm-nnnnn-"
    
    Dim ShiftDay As Int = 0    'whereabouts in ShiftPattern corresponds to:

    DateTime.DateFormat = "yyyy-MM-dd"
    Dim ShiftDate As Long = DateTime.DateParse("2022-12-01")
    
    Dim OneDay As Period
    OneDay.Initialize
    OneDay.Days = 1
    
    DateTime.DateFormat = "EEE dd MMM"
    
    For DoDay = 1 To 28    '''365 / 4 + 1
        Log(DateTime.Date(ShiftDate) & TAB & ShiftName.Get("" & ShiftPattern.CharAt(ShiftDay)))
        ShiftDate = DateUtils.AddPeriod(ShiftDate, OneDay)
        ShiftDay = (ShiftDay + 1) Mod ShiftPattern.Length
    Next
    
End Sub

Log output:
Logger connected to:  TCL 5009A
--------- beginning of system
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Thu. 01 Dec.    Afternoon 5pm to 1am next day
Fri. 02 Dec.    Afternoon 5pm to 1am next day
Sat. 03 Dec.    Afternoon 5pm to 1am next day
Sun. 04 Dec.    Afternoon 5pm to 1am next day
Mon. 05 Dec.    Afternoon 5pm to 1am next day
Tue. 06 Dec.    -
Wed. 07 Dec.    Morning   9am to 5pm
Thu. 08 Dec.    Morning   9am to 5pm
Fri. 09 Dec.    Morning   9am to 5pm
Sat. 10 Dec.    Morning   9am to 5pm
Sun. 11 Dec.    Morning   9am to 5pm
Mon. 12 Dec.    -
Tue. 13 Dec.    Night     1am to 9am
Wed. 14 Dec.    Night     1am to 9am
Thu. 15 Dec.    Night     1am to 9am
Fri. 16 Dec.    Night     1am to 9am
Sat. 17 Dec.    Night     1am to 9am
Sun. 18 Dec.    -
Mon. 19 Dec.    Afternoon 5pm to 1am next day
Tue. 20 Dec.    Afternoon 5pm to 1am next day
Wed. 21 Dec.    Afternoon 5pm to 1am next day
Thu. 22 Dec.    Afternoon 5pm to 1am next day
Fri. 23 Dec.    Afternoon 5pm to 1am next day
Sat. 24 Dec.    -
Sun. 25 Dec.    Morning   9am to 5pm
Mon. 26 Dec.    Morning   9am to 5pm
Tue. 27 Dec.    Morning   9am to 5pm
Wed. 28 Dec.    Morning   9am to 5pm
** Activity (main) Resume **
 
Upvote 0

emexes

Expert
Licensed User
Or now that it's been bouncing around my head for a while... this way might be simpler/better:

construct a schedule once, at startup, for say last year to next year, and then lookup by date using a Map as an associative array:

Make poor man's associative array ~ ShiftSchedule.Get(Date):
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(Y & "-" & ZeroPadLeft(M, 2) & "-" & ZeroPadLeft(D, 2), ShiftPattern.CharAt(ShiftPatternDay).As(String))
                ShiftPatternDay = (ShiftPatternDay + 1) Mod ShiftPattern.Length 
            Next
        Next
    Next
 
    Return ShiftSchedule
 
End Sub

Helper Subs:
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

Test using:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")

    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
        Dim K As String = "2022-12-" & D
        '''Log(K & TAB & ShiftSchedule.Get(K) & TAB & ShiftName.Get(ShiftSchedule.Get(K)))
        Log(                                             _
            K                                    & TAB & _
            ShiftSchedule.Get(K)                 & TAB & _
            ShiftName.Get(ShiftSchedule.Get(K))          _
        )
    Next

    Next

End Sub

JSON:
Logger connected to:  TCL 5009A
--------- beginning of system
--------- beginning of main
2022-12-10    m    Morning   9am to 5pm
2022-12-11    m    Morning   9am to 5pm
2022-12-12    -    ?
2022-12-13    a    Afternoon 5pm to 1am next day
2022-12-14    a    Afternoon 5pm to 1am next day
2022-12-15    a    Afternoon 5pm to 1am next day
2022-12-16    a    Afternoon 5pm to 1am next day
2022-12-17    a    Afternoon 5pm to 1am next day
2022-12-18    =    ? Party All Day ?
2022-12-19    n    Night     1am to 9am
2022-12-20    n    Night     1am to 9am
2022-12-21    n    Night     1am to 9am
2022-12-22    n    Night     1am to 9am
2022-12-23    n    Night     1am to 9am
2022-12-24    -    ?
2022-12-25    m    Morning   9am to 5pm
2022-12-26    m    Morning   9am to 5pm
2022-12-27    m    Morning   9am to 5pm
2022-12-28    m    Morning   9am to 5pm
2022-12-29    m    Morning   9am to 5pm
2022-12-30    -    ?
2022-12-31    a    Afternoon 5pm to 1am next day
** Activity (main) Resume **
 
Last edited:
Upvote 0

Mattiaf

Active Member
Licensed User
would it be possible to choose a single day from a calendar control and check which shift i ll be working on that day without have a range?
 
Upvote 0

emexes

Expert
Licensed User
would it be possible to choose a single day from a calendar control and check which shift i ll be working on that day without have a range?

conveniently ignoring the "without have a range" stipulation ? for a moment, this would should do the job:

B4X:
Dim K As String = Date_From_Calendar_Control 'must be in YYYY-MM-DD format precisely
Log("Date = " & K)
Log("Shift = " & ShiftSchedule.Get(K))

Without the range, can still be done using DateUtils, but I get a bit nervous about what happens around daylight-saving changeover when everything shifts backward/forward by an hour (or whatever). Although I guess if we decreed a date to be "as-at-noon" rather than "as-at-midnight-ie-time-is-zero" then that'd be enough of a margin to eliminate those pesky edge cases.
 
Upvote 0

emexes

Expert
Licensed User
How does the employer specify the alignment of the shift pattern to the calendar date?

Do they say "the first morning shift is/was on yyyy-mm-dd" ?

Or "the first day of 2020 was a third-of-five afternoon shift" ?

Or do they just provide a calendar, in which case: how would you like to specify it to the computer?

Just need one alignment point eg "arbitrary date = day of shift schedule".
 
Upvote 0

Mattiaf

Active Member
Licensed User
How does the employer specify the alignment of the shift pattern to the calendar date?

Do they say "the first morning shift is/was on yyyy-mm-dd" ?

Or "the first day of 2020 was a third-of-five afternoon shift" ?

Or do they just provide a calendar, in which case: how would you like to specify it to the computer?

Just need one alignment point eg "arbitrary date = day of shift schedule".
sure, the employer send us a pdf with our shifts
the shifts are 5 morning and to follow a day off
5 afternoon shifts and to follow a day off
5 night shifts and to follow a day off
and again the same routine over and over.
Obviously if today I was starting my afternoon shifts, I'll set on my software afternoons-nights-mornings.
But I really don't care to see all the results alltogether. I just want to pick a day in the future and I ' will know which shift I will be working :))

p.s. an afternoon shift will never be after 10pm
 
Last edited:
Upvote 0

Mattiaf

Active Member
Licensed User
conveniently ignoring the "without have a range" stipulation ? for a moment, this would should do the job:

B4X:
Dim K As String = Date_From_Calendar_Control 'must be in YYYY-MM-DD format precisely
Log("Date = " & K)
Log("Shift = " & ShiftSchedule.Get(K))

Without the range, can still be done using DateUtils, but I get a bit nervous about what happens around daylight-saving changeover when everything shifts backward/forward by an hour (or whatever). Although I guess if we decreed a date to be "as-at-noon" rather than "as-at-midnight-ie-time-is-zero" then that'd be enough of a margin to eliminate those pesky edge cases.
which control are you using for calendar?
I found this but it is not in y-m-d

 
Upvote 0

emexes

Expert
Licensed User
which control are you using for calendar?

I am not using a calendar, I'm just suggesting one way of translating dates to shifts.


I found this but it is not in y-m-d

What format would you like the date to be in?

Examples of different date formats:
'say for Swiss National Day 1st August 2022:

'2022-08-01
ShiftSchedule.Put(Y & "-" & ZeroPadLeft(M, 2) & "-" & ZeroPadLeft(D, 2), ShiftPattern.CharAt(ShiftPatternDay).As(String))

'01-08-2022
ShiftSchedule.Put(ZeroPadLeft(D, 2) & "-" & ZeroPadLeft(M, 2) & "-" & Y, ShiftPattern.CharAt(ShiftPatternDay).As(String))

'08-01-2022
ShiftSchedule.Put(ZeroPadLeft(M, 2) & "-" & ZeroPadLeft(D, 2) & "-" & Y, ShiftPattern.CharAt(ShiftPatternDay).As(String))

'1/8/2022
ShiftSchedule.Put(D & "/" & M & "/" & Y, ShiftPattern.CharAt(ShiftPatternDay).As(String))

'8/1/2022
ShiftSchedule.Put(M & "/" & D & "/" & Y, ShiftPattern.CharAt(ShiftPatternDay).As(String))
 
Upvote 0

LordZenzo

Well-Known Member
Licensed User
Longtime User
I could give you the link to my program for work shifts, it is able to manage all types of shifts with also the calculation of hours, it is able to manage shifts both based on simple codes "M" morning "A" afternoon etcc . and also shifts with start and end times in the format "HH:MM"
but my program shows the whole month both on the main page of the day and in a comfortable full screen widget
so it's not for you
 
Upvote 0

Mattiaf

Active Member
Licensed User
I am not using a calendar, I'm just suggesting one way of translating dates to shifts.




What format would you like the date to be in?

Examples of different date formats:
'say for Swiss National Day 1st August 2022:

'2022-08-01
ShiftSchedule.Put(Y & "-" & ZeroPadLeft(M, 2) & "-" & ZeroPadLeft(D, 2), ShiftPattern.CharAt(ShiftPatternDay).As(String))

'01-08-2022
ShiftSchedule.Put(ZeroPadLeft(D, 2) & "-" & ZeroPadLeft(M, 2) & "-" & Y, ShiftPattern.CharAt(ShiftPatternDay).As(String))

'08-01-2022
ShiftSchedule.Put(ZeroPadLeft(M, 2) & "-" & ZeroPadLeft(D, 2) & "-" & Y, ShiftPattern.CharAt(ShiftPatternDay).As(String))

'1/8/2022
ShiftSchedule.Put(D & "/" & M & "/" & Y, ShiftPattern.CharAt(ShiftPatternDay).As(String))

'8/1/2022
ShiftSchedule.Put(M & "/" & D & "/" & Y, ShiftPattern.CharAt(ShiftPatternDay).As(String))
I will definitely use
B4X:
ShiftSchedule.Put(ZeroPadLeft(D, 2) & "-" & ZeroPadLeft(M, 2) & "-" & Y, ShiftPattern.CharAt(ShiftPatternDay).As(String))

but is there any control of which I can select a date like a calendar on my app?
thanks
 
Last edited:
Upvote 0

Mattiaf

Active Member
Licensed User
I could give you the link to my program for work shifts, it is able to manage all types of shifts with also the calculation of hours, it is able to manage shifts both based on simple codes "M" morning "A" afternoon etcc . and also shifts with start and end times in the format "HH:MM"
but my program shows the whole month both on the main page of the day and in a comfortable full screen widget
so it's not for you
thanks lord, but I only need a easy tool to know which shift I will be working on a select date. Employer send us 2 weeks shifts at the time, but I m not interested on knowing hours and place of work, rather if morning/afternoon or night following the 5+1 system
 
Upvote 0

Mattiaf

Active Member
Licensed User
I could give you the link to my program for work shifts, it is able to manage all types of shifts with also the calculation of hours, it is able to manage shifts both based on simple codes "M" morning "A" afternoon etcc . and also shifts with start and end times in the format "HH:MM"
but my program shows the whole month both on the main page of the day and in a comfortable full screen widget
so it's not for you
I'm trying using the b4x view templates
B4X:
#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

but it keeps returning a debug error...
B4X:
Logger connected to:  samsung SM-G985F
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
Error occurred on line: 95 (B4XDialog)
java.lang.RuntimeException: Object should first be initialized (B4XView).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
    at anywheresoftware.b4a.objects.B4XViewWrapper.getViewObject(B4XViewWrapper.java:104)
    at anywheresoftware.b4a.objects.B4XViewWrapper.asPanelWrapper(B4XViewWrapper.java:107)
    at anywheresoftware.b4a.objects.B4XViewWrapper.GetAllViewsRecursive(B4XViewWrapper.java:307)
    at b4a.example.b4xdialog$ResumableSub_ShowCustom.resume(b4xdialog.java:976)
    at b4a.example.b4xdialog._showcustom(b4xdialog.java:911)
    at b4a.example.b4xdialog$ResumableSub_ShowTemplate.resume(b4xdialog.java:117)
    at b4a.example.b4xdialog._showtemplate(b4xdialog.java:74)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:146)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:7881)
    at android.widget.TextView.performClick(TextView.java:16201)
    at android.view.View.performClickInternal(View.java:7858)
    at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0)
    at android.view.View$PerformClick.run(View.java:30863)
    at android.os.Handler.handleCallback(Handler.java:942)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:226)
    at android.os.Looper.loop(Looper.java:313)
    at android.app.ActivityThread.main(ActivityThread.java:8741)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)

eventho I'm initializing that.. :\
 
Upvote 0

emexes

Expert
Licensed User
eventho I'm initializing that.. :\

I'm not sure that is is (or, at least, I can't see it) :

B4X:
Private Sub Button1_Click
    Dim calendario As B4XDateTemplate
    ...      
    Wait For (dialog.ShowTemplate(calendario, "", "", "CANCEL")) Complete (Result As Int)

Phase 1 might be to get calendario displaying like you want.

Phase 2, to hard-code example shifts into calandario so that they are displaying like you want.

Phase 3, to replace the hard-coded example shifts with the "calculated" shifts.
 
Upvote 0

Mattiaf

Active Member
Licensed User
oh my bad, I pasted the code after i was trying to changed it, but still doesn't work .
B4X:
    Dim calendario As B4XDateTemplate
    calendario.initialize
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

it still gives me the same error log..

maybe am I doing something wrong importing the template?
i did like this, importing datetemplate and datepicker into the project libs
Immagine 2022-12-26 010038.png
 
Upvote 0

emexes

Expert
Licensed User
I have never used a calendar in my apps. Closest I get is when I include current date and time in log file or report screen.

With luck, there is a calendar expert lurking on the forum with some spare time during the xmas-ny break, who is looking for something interesting to help with.

If that doesn't happen, I'll give it a burl tonight, but it'll probably descend into a comedy of the blind leading the blind ?
 
Upvote 0

Mattiaf

Active Member
Licensed User
ok i got it!
the calendar works!
I zipped the entire project
You need Xui Views to be insterted inside C:\Program Files\Anywhere Software\B4A\lib
and the rest of the files (template) is already inside the project
But unfortunately it returns this log
B4X:
Date = 12/30/2022
Shift = null
Date = 12/31/2022
Shift = null
Date = 12/30/2022
Shift = null
Date = 12/31/2022
Shift = null
 
Upvote 0

emexes

Expert
Licensed User
I thought we were going with date format DD-MM-YYYY :

I will definitely use
ShiftSchedule.Put(ZeroPadLeft(D, 2) & "-" & ZeroPadLeft(M, 2) & "-" & Y, ShiftPattern.CharAt(ShiftPatternDay).As(String))

As noted earlier, for doing Map lookups, dates have to be in the chosen format precisely:

B4X:
Dim K As String = Date_From_Calendar_Control 'must be in YYYY-MM-DD format precisely
Log("Date = " & K)
Log("Shift = " & ShiftSchedule.Get(K))

but these dates:

B4X:
Date = 12/30/2022
Date = 12/31/2022
Date = 12/30/2022
Date = 12/31/2022

are instead MM/DD/YYYY.
 
Last edited:
Upvote 0
Top