Older Version
Newer Version
JanetTerra
Oct 5, 2008
Time Zone With Clickable Map
No need for data tables. The Time Zones are calculated from the RGB values of the pixel color clicked. Red values ending in an even number are GMT + while those ending in an odd number are GMT -. Values ending in 1 or 2 are whole hour differences. Values ending in 3 or 4 increase that difference by 1/2 hour. There were one or two small areas that differed by 3/4. Clicking there will result in full hour differences.
The Green and Blue values determine the exact number of hours. The Green xx0 holds the tens units and the Blue xx0 holds the single units. Thus an RGB value of 121-210-238 decodes to GMT -8.
There was no attempt made to adjust for Daylight Savings Time.
There is one required external file -
Please note: The map is a .png file, but fairly large at 1.42 mb.
The file will be removed at the end of two weeks.
After October 22, 2008, the map image file will be available by request.
' Time Zone Extreme Challenge Contest
' http://libertybasic.conforums.com/index.cgi?board=contests&action=display&num=1222370358
' Janet L Terra, October 5, 2008
' GetSystemTime Function courtesty of API's for LB by Alyce Watson
' http://alycesrestaurant.com/apilb/index.htm
' Map modified from World Time Zone Map available at WikiCommons
' http://upload.wikimedia.org/wikipedia/commons/3/3d/Timezones_optimized.png
Struct SystemTime, _
wYear as Short, _
wMonth as Short, _
wDayOfWeek as Short, _
wDay as Short, _
wHour as Short, _
wMinute as Short, _
wSecond as Short, _
wMilliseconds as Short
WindowWidth = 800
WindowHeight = 600
UpperLeftX = Int((DisplayWidth - WindowWidth) / 2)
UpperLeftY = Int((DisplayHeight - WindowHeight) / 2)
dst$ = "* Daylight Savings Time is not factored into "; _
"these time calculations."
Graphicbox #main.map, 20, 20, 600, 500
StaticText #main.gmt0, "", 650, 30, 120, 20
StaticText #main.gmt1, "", 650, 50, 120, 20
StaticText #main.gmt2, "", 650, 70, 120, 40
StaticText #main.lct0, "", 650, 150, 120, 20
StaticText #main.lct1, "", 650, 170, 120, 20
StaticText #main.lct2, "", 650, 190, 120, 40
StaticText #main.slt0, "", 650, 270, 120, 20
StaticText #main.slt1, "", 650, 290, 120, 20
StaticText #main.slt2, "", 650, 310, 120, 40
StaticText #main.dst, dst$, 650, 390, 120, 120
Open "Time Zones" for Window as #main
#main, "Font Verdana 11 Bold"
#main, "Trapclose [XbyTrap]"
#main.map, "Vertscrollbar On 0 550"
#main.map, "Horizscrollbar On 0 1800"
#main.map, "Down; Place -2 -2"
#main.map, "Boxfilled 2400 1200; Flush"
#main.gmt0, "GMT / UTC"
Call PostTimes ""
map$ = "WikiCommonsWorldMap.PNG"
Open "pbimage.dll" for DLL as #pb
CallDLL #pb, "IxGetImage", _
1 as Long, _
map$ as Ptr, _
hMap as uLong
Loadbmp "WorldMap", hMap
#main.map, "Down; Drawbmp WorldMap 0 0; Flush"
Close #pb
hDC = GetDC(hWnd(#main.map))
noCursor = LoadCursor(32648)
#main.map, "When leftButtonDown [MapTime]"
Wait
[XbyTrap]
Call ReleaseDC hWnd(#main.map), hDC
Unloadbmp "WorldMap"
Close #main
End
[MapTime]
xVar = MouseX
yVar = MouseY
PixelLong = PixelLong(hDC, xVar, yVar)
RGB$ = RGB$(PixelLong)
ValidPixel = ValidPixel(hDC, xVar, yVar)
If ValidPixel = 1 Then
h0 = Val(Right$(Word$(RGB$, 1, "-"), 1))
h1 = Val(Right$(Word$(RGB$, 2, "-"), 1))
h2 = Val(Right$(Word$(RGB$, 3, "-"), 1))
nHrs = h1 * 10 + h2
If h0 > 2 Then nHrs = nHrs + 0.5
If h0 Mod 2 = 0 Then
hrsInc = 1
Else
hrsInc = -1
End If
Call PostTimes ""
GetSLT$ = GetSLT$(hrsInc, nHrs)
#main.slt0, Word$(GetSLT$, 1, "*")
#main.slt1, Word$(GetSLT$, 2, "*")
#main.slt2, Word$(GetSLT$, 3, "*")
Else
Call SetCursor noCursor
CallDLL #kernel32, "Sleep", 250 as Long, result as Void
Cursor Normal
End If
Wait
Function ValidPixel(hDC, xVar, yVar)
PixelLong = PixelLong(hDC, xVar, yVar)
ValidPixel = 1
For x = -3 to 3
p = PixelLong(hDC, xVar + x, yVar)
If p <> PixelLong Then
ValidPixel = 0
End If
Next x
If ValidPixel = 0 Then
Exit Function
End If
For y = -4 to 4
p = PixelLong(hDC, xVar, yVar + y)
If p <> PixelLong Then
ValidPixel = 0
End If
Next y
If ValidPixel = 0 Then
Exit Function
End If
End Function
Function PixelLong(hDC, xVar, yVar)
CallDLL #gdi32, "GetPixel", _
hDC as uLong, _
xVar as Long, _
yVar as Long, _
PixelLong as Long
End Function
Function RGB$(LongPixel)
RedHue = LongPixel And 255
GreenHue = (LongPixel And 65280)/256
BlueHue = (LongPixel And 16711680)/65536
RGB$ = Str$(RedHue);"-";Str$(GreenHue);"-";Str$(BlueHue)
End Function
Function GetGMT$()
CallDLL #kernel32, "GetSystemTime", _
SystemTime as Struct, _
result as Long
hr$ = Right$("0";Str$(SystemTime.wHour.struct), 2)
min$ = Right$("0";Str$(SystemTime.wMinute.struct), 2)
GetGMT$ = hr$;":";min$
End Function
Function GetGMD$()
dWeek$ = "Sunday Monday Tuesday Wednesday Thursday Friday Saturday"
mYear$ = "Jan Feb Mar Apr May June July Aug Sep Oct Nov Dec"
yr$ = Str$(SystemTime.wYear.struct)
d = SystemTime.wDayOfWeek.struct
d$ = Right$("0";SystemTime.wDay.struct, 2)
day$ = Word$(dWeek$, d + 1)
mon$ = Word$(mYear$, SystemTime.wMonth.struct)
GetGMD$ = day$;Chr$(10);Chr$(13);mon$;" ";d$;", ";yr$
End Function
Function GetLCT$()
GetLCT$ = Word$(Time$(), 1, ":");":";Word$(Time$(), 2, ":")
End Function
Function GetLCD$()
dWeek$ = "Tuesday Wednesday Thursday Friday Saturday "; _
"Sunday Monday"
d = Date$("days") Mod 7
GetLCD$ = Word$(dWeek$, d + 1);Chr$(10);Chr$(13);Date$()
End Function
Function GetBias(GMT$, t2$)
h1 = Val(Word$(GMT$, 1, ":"))
h2 = Val(Word$(t2$, 1, ":"))
m1 = Val(Word$(GMT$, 2, ":"))
m2 = Val(Word$(t2$, 2, ":"))
If m2 > m1 Then
h1 = h1 - 1
m1 = m1 + 60
End If
b1 = h1 - h2
b2 = m1 - m2
If b2 = 30 Then
b2 = 0.5
End If
GetBias = 0 - (b1 + b2)
End Function
Function GetSLT$(hrInc, hrBias)
If hrInc = 1 Then
GetSLT$ = "GMT + "
Else
GetSLT$ = "GMT - "
End If
GetSLT$ = GetSLT$;hrBias
GetGMT$ = GetGMT$()
SLD$ = GetGMD$()
hG = Val(Word$(GetGMT$, 1, ":"))
mG = Val(Word$(GetGMT$, 2, ":"))
hS = hG + Int(hrBias) * hrInc
mS = mG
If hrBias <> Int(hrBias) Then
If hrInc < 1 Then
mS = mS - 30
If mS < 0 Then
mS = 60 + mS
hS = hS - 1
End If
Else
mS = mS + 30
If mS > 60 Then
mS = mS - 60
hS = hS + 1
End If
End If
End If
dWeek$ = Word$(SLD$, 1, Chr$(10);Chr$(13))
SLD$ = Mid$(SLD$, Len(dWeek$) + 3)
mG$ = Word$(SLD$, 1)
dG$ = Left$(Word$(SLD$, 2), 2)
yG$ = Word$(SLD$, 3)
dt$ = mG$;"/";dG$;"/";yG$
dG = Date$(dt$)
dWeek$ = "Tuesday Wednesday Thursday Friday Saturday "; _
"Sunday Monday"
mYear$ = "Jan Feb Mar Apr May June July Aug Sep Oct Nov Dec"
If hS > 23 Then
hS = hS - 24
dG = dG + 1
End If
If hS < 0 Then
hS = hS + 24
dG = dG - 1
End If
GetSLT$ = GetSLT$;"*";Right$("0";hS, 2);":";Right$("0";mS, 2)
dWeek$ = Word$(dWeek$, (dG Mod 7) + 1)
dt$ = Date$(dG)
m$ = Word$(mYear$, Val(Word$(dt$, 1, "/")))
d$ = Word$(dt$, 2, "/")
y$ = Word$(dt$, 3, "/")
GetSLT$ = GetSLT$;"*";dWeek$;Chr$(10);Chr$(13);m$;" ";d$;", ";y$
End Function
Sub PostTimes GetSLT$
GetGMT$ = GetGMT$()
#main.gmt1, GetGMT$
GetGMD$ = GetGMD$()
#main.gmt2, GetGMD$()
#main.lct0, "Local Time"
GetLCT$ = GetLCT$()
#main.lct1, GetLCT$
GetLCD$ = GetLCD$()
#main.lct2, GetLCD$
If GetSLT$ = "" Then
#main.slt0, "Select Zone"
End If
End Sub
Function LoadImageToSize(pFile$, wPic, hPic)
CallDLL #pb, "IxLoadImageSize", _
1 as Long, _
pFile$ as Ptr, _
wPic as Long, _
hPic as Long, _
LoadImageToSize as uLong
End Function
Function GetDC(handle)
CallDLL #user32, "GetDC", _
handle as uLong, _
GetDC as uLong
End Function
Sub ReleaseDC handle, hDC
CallDLL #user32, "ReleaseDC", _
handle as uLong, _
hDC as uLong, _
result as Long
End Sub
Function LoadCursor(nCursor)
flags = HexDec("8000") or _LR_DEFAULTSIZE
CallDLL #user32, "LoadImageA", _
0 as Long, _
nCursor as Long, _
_IMAGE_CURSOR as Long, _
0 as Long, _
0 as Long, _
flags as Long, _
LoadCursor as uLong
Call SetCursor LoadCursor
End Function
Sub SetCursor hCursor
CallDLL #user32, "SetCursor", _
hCursor as uLong, _
result as Long
End Sub
Sub SetClass handle
index = _GCL_HCURSOR or 0
CallDLL #user32, "SetClassLongA", _
handle as uLong, _
index as Long, _
0 as Long, _
result as Long
End Sub