' Meeting planner: find meeting times across multiple timezones
#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN() AS LONG
    LOCAL i  AS LONG
    LOCAL j  AS LONG
    LOCAL numParticipants  AS LONG
    LOCAL pplName(10) AS STRING
    LOCAL pplTZ(10) AS LONG
    LOCAL pplStart(10) AS LONG
    LOCAL pplEnd(10) AS LONG
    LOCAL overlapStart  AS LONG
    LOCAL overlapEnd  AS LONG
    LOCAL slotHour  AS LONG
    LOCAL slotFound  AS LONG
    LOCAL refHour  AS LONG
    LOCAL refTZ  AS LONG
    LOCAL localHour  AS LONG
    LOCAL participantHour  AS LONG
    LOCAL s AS STRING

    PRINT "=== Meeting Time Planner ==="
    PRINT

    numParticipants = 5
    pplName(0) = "Alice (NY)      "
    pplTZ(0) = -5
    pplStart(0) = 9
    pplEnd(0) = 17

    pplName(1) = "Bob (London)    "
    pplTZ(1) = 0
    pplStart(1) = 9
    pplEnd(1) = 17

    pplName(2) = "Carol (Paris)   "
    pplTZ(2) = 1
    pplStart(2) = 9
    pplEnd(2) = 18

    pplName(3) = "David (Tokyo)   "
    pplTZ(3) = 9
    pplStart(3) = 8
    pplEnd(3) = 19

    pplName(4) = "Eve (Sydney)    "
    pplTZ(4) = 10
    pplStart(4) = 9
    pplEnd(4) = 17

    PRINT "Participants and their local working hours:"
    FOR i = 0 TO numParticipants - 1
        s = TRIM$(pplName(i))
        PRINT "  " & s & ": " & FORMAT$(pplStart(i)) & ":00-" & FORMAT$(pplEnd(i)) & ":00 (UTC" & FORMAT$(pplTZ(i)) & ")"
    NEXT i
    PRINT

    PRINT "--- Convert all to UTC and find overlap ---"
    overlapStart = 0
    overlapEnd = 24

    FOR i = 0 TO numParticipants - 1
        pplStart(i) = pplStart(i) - pplTZ(i)
        pplEnd(i) = pplEnd(i) - pplTZ(i)
        IF pplStart(i) < 0 THEN pplStart(i) = pplStart(i) + 24
        IF pplStart(i) >= 24 THEN pplStart(i) = pplStart(i) - 24
        IF pplEnd(i) < 0 THEN pplEnd(i) = pplEnd(i) + 24
        IF pplEnd(i) >= 24 THEN pplEnd(i) = pplEnd(i) - 24
    NEXT i

    FOR i = 0 TO numParticipants - 1
        IF pplStart(i) > overlapStart THEN overlapStart = pplStart(i)
        IF pplEnd(i) < overlapEnd THEN overlapEnd = pplEnd(i)
    NEXT i

    PRINT "UTC overlap window: " & FORMAT$(overlapStart) & ":00 to " & FORMAT$(overlapEnd) & ":00"
    PRINT

    IF overlapEnd > overlapStart THEN
        PRINT "Meeting can be scheduled!"
        PRINT "Possible start times (in each timezone):"
        FOR slotHour = overlapStart TO overlapEnd - 1
            PRINT "  UTC " & FORMAT$(slotHour) & ":00 ->"
            FOR j = 0 TO numParticipants - 1
                participantHour = slotHour + pplTZ(j)
                IF participantHour < 0 THEN participantHour = participantHour + 24
                IF participantHour >= 24 THEN participantHour = participantHour - 24
                s = TRIM$(pplName(j))
                PRINT "    " & s & ": " & FORMAT$(participantHour) & ":00"
            NEXT j
            PRINT
        NEXT slotHour
    ELSE
        PRINT "No common working hours found."
        PRINT "Overlap window: " & FORMAT$(overlapStart) & " - " & FORMAT$(overlapEnd)
        PRINT "Suggestion: extend working hours or try different day"
    END IF

    PRINT "--- Alternative: Convert reference time to all zones ---"
    refHour = 15
    refTZ = -5
    PRINT "If meeting is at " & FORMAT$(refHour) & ":00 in " & TRIM$(pplName(0)) & ":"
    FOR i = 0 TO numParticipants - 1
        localHour = refHour + (pplTZ(i) - refTZ)
        IF localHour < 0 THEN localHour = localHour + 24
        IF localHour >= 24 THEN localHour = localHour - 24
        s = TRIM$(pplName(i))
        PRINT "  " & s & ": " & FORMAT$(localHour) & ":00"
    NEXT i

    PRINT
    PRINT "--- Scheduling Tips ---"
    PRINT "  Best times: Tue-Wed-Thu 10am-2pm ET"
    PRINT "  Avoid: Monday mornings, Friday afternoons"
    PRINT "  Length: 30-60 min ideal"
    PRINT "  Send calendar invite with UTC time"

    PRINT
    PRINT "Meeting planner complete."

    FUNCTION = 0
END FUNCTION
