Android Question Intervals between hours

Daniel44

Active Member
Licensed User
Hi everyone. Im developing a medical system and I need from Given a range of hours e.g. 12pm 06pm fragment in 15 minutes e.g. 12pm 12:15 12:30 12:45 etcetera. I don't know how to start. I don't know if to use dateutils library or just strings. Thanks
 

emexes

Well-Known Member
Licensed User
Without a question mark in your post, it is difficult to identify the question. Are you asking which format/type you should use to store dates and times?

Usually I would say to use the DateUtils library, but it sounds more here like you are generating a list of undated times to construct a fixed-format form or table or document. If you are operating overnight, then you would need to consider what happens when summer time / daylight saving kicks in or out.

An implementation that meets your example need (and more) is:
B4X:
'times are in minutes since midnight eg 4:56 pm = (12 + 4) * 60 + 56

Dim OpenTimeMinutes As Int = 12 * 60    '12 midday
Dim CloseTimeMinutes As Int = 18 * 60    '6 pm

Log( "Afternoon sessions are " & SessionTimes(OpenTimeMinutes, CloseTimeMinutes, 15) )

OpenTimeMinutes = 22 * 60 + 30    '10:30 pm
CloseTimeMinutes = (24 + 5) * 60 + 20    '5:20 am next day

Log( "Overnight sessions are " & SessionTimes(OpenTimeMinutes, CloseTimeMinutes, 15) )    'note there is NO session at 05:15 due to closing 5 minutes later


Sub SessionTimes(StartMinutes As Int, EndMinutes As Int, SessionMinutes As Int) As List

    Dim SessionList As List
    SessionList.Initialize
 
    If SessionMinutes > 0 Then
        For T = StartMinutes To EndMinutes - SessionMinutes + 1 Step SessionMinutes
            SessionList.Add( NumberFormat2(Floor(T / 60) Mod 24, 2, 0, 0, False) & ":" & NumberFormat2(T Mod 60, 2, 0, 0, False) )
        Next
    End If
 
    Return SessionList
 
End Sub
generates log:
B4X:
Program started.
Afternoon sessions are (ArrayList) [12:00, 12:15, 12:30, 12:45, 13:00, 13:15, 13:30, 13:45, 14:00, 14:15, 14:30, 14:45, 15:00, 15:15, 15:30, 15:45, 16:00, 16:15, 16:30, 16:45, 17:00, 17:15, 17:30, 17:45]
Overnight sessions are (ArrayList) [22:30, 22:45, 23:00, 23:15, 23:30, 23:45, 00:00, 00:15, 00:30, 00:45, 01:00, 01:15, 01:30, 01:45, 02:00, 02:15, 02:30, 02:45, 03:00, 03:15, 03:30, 03:45, 04:00, 04:15, 04:30, 04:45, 05:00]
 
Last edited:

emexes

Well-Known Member
Licensed User
Might be simpler and more flexible to do something like this:
B4X:
'♪♫ working nine to five ♫♬... except for setup, morning tea, lunch, afternoon tea and cleanup times
Dim SessionList As List = Array As String( _
             "09:15", "09:30", "09:45", _
    "10:00", "10:15", "10:30", "10:45", _
             "11:15", "11:30", "11:45", _
    "12:00", "12:15", "12:30", "12:45", _
                      "13:30", "13:45", _
    "14:00", "14:15", "14:30", "14:45", _
             "15:15", "15:30", "15:45", _
    "16:00", "16:15", "16:30"           _
)

Log(SessionList)
 

emexes

Well-Known Member
Licensed User
Or this... (background info for people not abreast with Australian politics: Julia Gillard was our first female Prime Minister, but before that she was Deputy PM to Kevin Rudd, who had a reputation for driving people hard... freaky thing about this clip is that it was done *before* Kevin got dumped):


B4X:
'♪♫ working nine to nine ♫♬... 
Dim SessionList As List = Array As String( _
    "09:00", "09:15", "09:30", "09:45", _
    "10:00", "10:15", "10:30", "10:45", _
    "11:00", "11:15", "11:30", "11:45", _
    "12:00", "12:15", "12:30", "12:45", _
    "13:00", "13:15", "13:30", "13:45", _
    "14:00", "14:15", "14:30", "14:45", _
    "15:00", "15:15", "15:30", "15:45", _
    "16:00", "16:15", "16:30", "16:45", _
    "17:00", "17:15", "17:30", "17:45", _
    "18:00", "18:15", "18:30", "18:45", _
    "19:00", "19:15", "19:30", "19:45", _
    "20:00", "20:15", "20:30", "20:45"  _
)

Log(SessionList)
 
Top