' World clock with timezone offset calculations across multiple cities
#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN() AS LONG
    LOCAL i  AS LONG
    LOCAL numCities  AS LONG
    LOCAL cityName(20) AS STRING
    LOCAL cityOffset(20) AS LONG
    LOCAL baseHour  AS LONG
    LOCAL baseMinute  AS LONG
    LOCAL localHour  AS LONG
    LOCAL localMinute  AS LONG
    LOCAL totalMinutes  AS LONG
    LOCAL localTotal  AS LONG
    LOCAL offsetMin  AS LONG
    LOCAL displayHour AS LONG
    LOCAL ampm AS STRING
    LOCAL h  AS LONG
    LOCAL m  AS LONG
    LOCAL tzOffset  AS LONG
    LOCAL utcHour  AS LONG
    LOCAL utcMinute  AS LONG
    PRINT "=== World Clock ==="
    PRINT

    numCities = 8
    cityName(0) = "New York               "
    cityOffset(0) = -5
    cityName(1) = "London                 "
    cityOffset(1) = 0
    cityName(2) = "Paris                  "
    cityOffset(2) = 1
    cityName(3) = "Moscow                 "
    cityOffset(3) = 3
    cityName(4) = "Dubai                  "
    cityOffset(4) = 4
    cityName(5) = "Tokyo                  "
    cityOffset(5) = 9
    cityName(6) = "Sydney                 "
    cityOffset(6) = 10
    cityName(7) = "Los Angeles            "
    cityOffset(7) = -8

    baseHour = 14
    baseMinute = 30
    tzOffset = cityOffset(0)

    PRINT "Reference time: " & FORMAT$(baseHour) & ":" & FORMAT$(baseMinute) & " " & TRIM$(cityName(0))
    PRINT

    utcHour = baseHour - tzOffset
    IF utcHour < 0 THEN utcHour = utcHour + 24
    IF utcHour >= 24 THEN utcHour = utcHour - 24
    utcMinute = baseMinute
    PRINT "UTC time: " & FORMAT$(utcHour) & ":" & FORMAT$(utcMinute)
    PRINT

    PRINT "--- World Times ---"
    FOR i = 0 TO numCities - 1
        localHour = utcHour + cityOffset(i)
        localMinute = utcMinute
        IF localHour < 0 THEN
            localHour = localHour + 24
        END IF
        IF localHour >= 24 THEN
            localHour = localHour - 24
        END IF

        IF localHour >= 12 THEN
            ampm = "PM"
            IF localHour > 12 THEN
                displayHour = localHour - 12
            ELSE
                displayHour = 12
            END IF
        ELSE
            ampm = "AM"
            IF localHour = 0 THEN
                displayHour = 12
            ELSE
                displayHour = localHour
            END IF
        END IF

        PRINT "  " & TRIM$(cityName(i)) & ": " & FORMAT$(displayHour) & ":" & FORMAT$(localMinute) & " " & ampm & " (UTC" & FORMAT$(cityOffset(i)) & ")"
    NEXT i
    PRINT

    PRINT "--- Timezone Conversion ---"
    PRINT "Convert from New York (UTC-5) to Tokyo (UTC+9)"
    PRINT "  Difference: " & STR$(9 - (-5)) & " hours"
    PRINT "  If it's 14:30 in New York, it's:"
    localHour = 14
    localMinute = 30
    localTotal = localHour * 60 + localMinute
    offsetMin = (9 - (-5)) * 60
    localTotal = localTotal + offsetMin
    IF localTotal >= 1440 THEN localTotal = localTotal - 1440
    IF localTotal < 0 THEN localTotal = localTotal + 1440
    displayHour = localTotal / 60
    localMinute = localTotal MOD 60
    PRINT "  " & FORMAT$(displayHour) & ":" & FORMAT$(localMinute) & " in Tokyo"
    PRINT

    PRINT "--- Daylight Saving Simulation ---"
    PRINT "New York EST (UTC-5) vs EDT (UTC-4):"
    PRINT "  Standard time offset: -5"
    PRINT "  Daylight saving offset: -4"
    PRINT "  During DST, clocks move forward 1 hour"
    PRINT

    PRINT "--- Timezone Abbreviations ---"
    PRINT "  EST (UTC-5): Eastern Standard Time"
    PRINT "  GMT (UTC+0): Greenwich Mean Time"
    PRINT "  CET (UTC+1): Central European Time"
    PRINT "  MSK (UTC+3): Moscow Time"
    PRINT "  GST (UTC+4): Gulf Standard Time"
    PRINT "  JST (UTC+9): Japan Standard Time"
    PRINT "  AEST (UTC+10): Australian Eastern Standard Time"
    PRINT "  PST (UTC-8): Pacific Standard Time"

    PRINT
    PRINT "World clock complete."

    FUNCTION = 0
END FUNCTION
