
FB II Compiler
PG PRO
Debugging
Memory
System
Mathematics
Resources
Disk I/O
Windows
Controls
Menus
Mouse
Keyboard
Text
Fonts
Drawing
Sound
Clipboard
Printing
Communication
ASM
|
MATHEMATICS
Adjust time zones
Okay, after a night of mad coding incorporating suggestions from several continents and a lot of web cramming on time zone information, I have stumbled my way into this yet-to-be completed prototype of a "universal time zone conversion" engine.
I discovered that ham radio operators and transcontinental pilots already have a lot of this worked out. I also discovered that "time zones" are the exclusive domain of the sovereignty in which you live.
That being said, there are some constants in the universe, the most solid being Greenwich Mean Time (GMT), alias UT (Universal Time) and Zulu Time (for our airborne brethren). If my logic is correct, to develop a universal time zone conversion system, the CPU's internal clock time--assuming it's correctly set both time and Daylight Savingswise--would have to be converted to GMT, after which all other conversions fall in place.
I finally gave up on getting the TIME$ function example on page 310 of the refererence manual to work, and came up with alternative in this code. It's verbose, but seems to work (at least until Jim Henson gets a hold of it!) One nice feature is that it returns "Noon" and "Midnight" at the appropriate times.
One drawback of this code is that it relies on the Map Control Panel being installed. Another is that is only references eastward from GMT (which means only minus numbers will work.)
While the engine returns the proper values (I think), I ran out of time to code the the GMT time in the leftmost edit field. In that EF, an hour conversion figure based on your system clock is returned. You can use the system time running in the center window to see if it is working correctly. (Eastern Time is four hours behind GMT, so the EF should show a -4 for ET, a -5 for CT, a -5 for MT and a -6 for PT, etc.) Please feel free to modify, rework or totally rewrite the code.
Similarly, the radio buttons return values in the right EF, but since the GMT conversion is not complete, they simply return a conversion code and not a real time.
I would like to see if the check box at bottom left accurately detects Daylight Savings Time on your systems. Feedback would be appreciated.
Special thanks to Deepesh Letap and Joe Lewis Wilkins for their invaluable suggestions.
I'm still wrestling with the Daylight Savings time adjustment, but if I can get a universal time conversion prototype working, it could have many uses. Thanks to all who have written with suggestions, comments and encouragement. I'm looking forward to compiling it for PPC in FB^3.
Ken Shmidheiser
Ken asked me to put up my version of his program when I got it going. It assumes the world is divided into 24 time zones, so leaves out the 1/6 of the world in odd time zones. But you should be able to tell if you are going to wake somone up if you ring across many time zones. Also you will have to get Ken's PICT of time zones for the second window (just un REM the appropriate spots). Well here it is:
'---------------------- Begin -------------------------
'un Rem the next line if you have Ken's PICT
'RESOURCES "timeZone.rsrc"
COMPILE 0, _caseInsensitive_IncludeCDEF
'---------------------- Globals -------------------------
DIM gProgramEnds,gZone%,gSelZoneDS%
DIM RECORD AstroInfo
DIM LocLat!
DIM LocLaD%
DIM LocLaM%
DIM LocLaS%
DIM LocLng!
DIM LocLnD%
DIM LocLnM%
DIM LocLnS%
DIM LocDst%
DIM LocDif!
DIM END RECORD _AstroInfoRecSize
END GLOBALS
'---------------------- Constants -----------------------
_machineLocation = 12
'---------------------- Functions -----------------------
CLEAR LOCAL
DIM rect.8
LOCAL FN mainBuild
WINDOW # -1,"Universal Time Adjuster",( 5, 42)-( 620, 445),_docNoGrow
APPLE MENU "(Time Adjuster Demo"
MENU 1,0,_enable,"File"
MENU 1,1,_enable,"Quit/Q"
EDIT MENU 2
MENU 3,0,_enable,"Map"
MENU 3,1,_enable,"Show Time Zone Map"
MENU 3,2,_disable,"Hide Time Zone Map"
TEXT _geneva, 12
EDIT FIELD 1,"Current GMT",( 20, 75)-( 158, 95),_statNoFramed,_centerJust
EDIT FIELD 2,"",( 20, 95)-( 158, 112),_statFramed, _centerJust
EDIT FIELD 3,"Current System Time",( 220, 75)-( 368,95),_statNoFramed, _centerJust
EDIT FIELD 4,"",( 220, 95)-( 368, 112),_statFramed, _centerJust
EDIT FIELD 5,"Current Selected Zone Time",( 420, 59)-( 557,95),_statNoFramed, _centerJust
EDIT FIELD 6,"",( 420, 95)-( 557, 112),_statFramed, _centerJust
EDIT FIELD 7,"",( 220, 120)-( 358, 140),_statNoFramed, _centerJust
TEXT _times,30
COLOR _zRed
EDIT FIELD 8,"Universal Time Adjuster",( 0, 19)-( 620,49),_statNoFramed, _centerJust
TEXT _geneva, 9
COLOR _zBlack
BUTTON 1, 1,"+12 International Date Line East",( 20, 168)-( 200,188),¬
_radio_CDEFbaseID_CDEFuseWindowFont
BUTTON 2, 1,"+11 X-Ray (Military)",( 20, 189)-( 200,209), ¬
_radio_CDEFbaseID_CDEFuseWindowFont
BUTTON 3, 1,"+10 GST (Guam), AEST, Russia 9",( 20, 209)-( 200,229), ¬
_radio_CDEFbaseID_CDEFuseWindowFont
BUTTON 4, 1,"+9 JST (Japan), Russia 8",( 20, 231)-( 200,251), ¬
_radio_CDEFbaseID_CDEFuseWindowFont
BUTTON 5, 1,"+8 CTT (China Coast), WAST",( 20, 251)-( 200,271), ¬
_radio_CDEFbaseID_CDEFuseWindowFont
BUTTON 6, 1,"+7 Russia 6",( 20, 271)-( 200,291), ¬
_radio_CDEFbaseID_CDEFuseWindowFont
BUTTON 7, 1,"+6 ZP6-Chesapeake Bay, Russia 5",( 20, 293)-( 200,313), ¬
_radio_CDEFbaseID_CDEFuseWindowFont
BUTTON 8, 1,"+5 ZP5-Chesapeake Bay, Russia 4",( 20, 313)-( 200,333), ¬
_radio_CDEFbaseID_CDEFuseWindowFont
BUTTON 9, 1,"+4 ZP4-Russia Zone 3",( 220, 146)-( 400,166), ¬
_radio_CDEFbaseID_CDEFuseWindowFont
BUTTON 10, 1,"+3 BT (Baghdad Time), Russia 2",( 220, 167)-( 400,187), ¬
_radio_CDEFbaseID_CDEFuseWindowFont
BUTTON 11, 1,"+2 EET (Eastern European Time)",( 220, 187)-( 400,207), ¬
_radio_CDEFbaseID_CDEFuseWindowFont
BUTTON 12, 1,"+1 CET (Central European Time)",( 220, 209)-( 400,229), ¬
_radio_CDEFbaseID_CDEFuseWindowFont
BUTTON 13, 2,"0 - GMT, UT or Zulu Time",( 220, 241)-( 400,261), ¬
_radio
BUTTON 14, 1,"-1 WAT (West Africa Time)",( 220, 272)-( 400,292), ¬
_radio_CDEFbaseID_CDEFuseWindowFont
BUTTON 15, 1,"-2 AT (Azores Time)",( 220, 294)-( 400,314), ¬
_radio_CDEFbaseID_CDEFuseWindowFont
BUTTON 16, 1,"-3 Charlie Time (Brazil)",( 220, 314)-( 400,334), ¬
_radio_CDEFbaseID_CDEFuseWindowFont
BUTTON 17, 1,"-4 AST (Atlantic Standard Time)",( 220, 334)-( 400,354), ¬
_radio_CDEFbaseID_CDEFuseWindowFont
BUTTON 18, 1,"-5 EST (Eastern Standard Time)",( 420, 168)-( 690,188), ¬
_radio_CDEFbaseID_CDEFuseWindowFont
BUTTON 19, 1,"-6 CST (Central Standard Time)",( 420, 188)-( 690,208), ¬
_radio_CDEFbaseID_CDEFuseWindowFont
BUTTON 20, 1,"-7 MST (Mountain Standard Time)",( 420, 210)-( 690,230), ¬
_radio_CDEFbaseID_CDEFuseWindowFont
BUTTON 21, 1,"-8 PST (Pacific Standard Time)",( 420, 230)-( 690,250), ¬
_radio_CDEFbaseID_CDEFuseWindowFont
BUTTON 22, 1,"-9 YST (Yukon Standard Time)",( 420, 250)-( 690,270), ¬
_radio_CDEFbaseID_CDEFuseWindowFont
BUTTON 23, 1,"-10 AHST (Alaska-Hawaii Standard)",( 420, 272)-( 690,292), ¬
_radio_CDEFbaseID_CDEFuseWindowFont
BUTTON 24, 1,"-11 NT (Nome) & ST (Samoa)",( 420, 292)-( 690,312), ¬
_radio_CDEFbaseID_CDEFuseWindowFont
BUTTON 25, 1,"-12 International Date Line West",( 420, 312)-( 690,332), ¬
_radio_CDEFbaseID_CDEFuseWindowFont
BUTTON 26, 1,"Quit",(525,365)-(583,385), ¬
_shadow
BUTTON 27, 1,"Checked box means this Mac is running on Daylight Savings Time.",(20,370)-(370,390), ¬
_checkBox_CDEFbaseID_CDEFuseWindowFont
BUTTON 28,1,"Click if Daylight savings in selected zone.",( 395,120)-( 625, 140), ¬
_radio_CDEFbaseID_CDEFuseWindowFont
WINDOW 1
END FN
LOCAL FN showMap
WINDOW #2,"World Time Zones",( 0, 0)-( 640, 410),_docNoGrow
'un Rem the next line if you have Ken's PICT
'PICTURE FIELD #1, %128%, ( 0, 0)-( 640, 410),_statNoFramed,_scaledPict
WINDOW #2
END FN
LOCAL FN setTime$(t$)
LONG IF (VAL(LEFT$(t$,2)) => 12) AND (VAL(LEFT$(t$,2)) < 24)
t$ = STR$(VAL(LEFT$(t$,2))-12) + RIGHT$(t$,6) + " PM"
LONG IF (VAL(LEFT$(t$,2)) = 0) OR (VAL(LEFT$(t$,2)) = 24)
t$ =" 12" + RIGHT$(t$,9)
END IF
END IF
LONG IF RIGHT$(t$,2) <> "PM"
t$ = t$ + " AM"
LONG IF VAL(LEFT$(t$,2)) = 0
t$ = " 12" + RIGHT$(t$,9)
END IF
END IF
LONG IF (VAL(LEFT$(t$,3)) = 12) AND (RIGHT$(t$,2) = "PM")
LONG IF (VAL(MID$(t$,5,2)) < 1) AND (VAL(MID$(t$,8,2)) < 1)
t$ = LEFT$(t$,10) + "Noon"
END IF
END IF
LONG IF (VAL(LEFT$(t$,3)) = 12) AND (RIGHT$(t$,2) = "AM")
LONG IF (VAL(MID$(t$,5,2)) < 1) AND (VAL(MID$(t$,8,2)) < 1)
t$ = LEFT$(t$,10) + "Midnight"
END IF
END IF
END FN = t$
LOCAL FN doTimer
t$=TIME$
t$=LEFT$(t$,8)
ut$ = t$ 'universal/UT/GMT/zulu time
zt$ = t$ 'time in zone selected
ut$ = LEFT$(ut$,2)
ut% = VAL(ut$)
ut% = ut% - AstroInfo.LocDif!
IF AstroInfo.LocDst% THEN ut% = ut% - 1
IF ut% > 24 THEN ut% = ut% - 24
IF ut% < 0 THEN ut% = ut% + 24
ut$ = MID$(t$,3,6)
ut$ = STR$(ut%) + ut$
ut$ = RIGHT$(ut$,8)
zt$ = LEFT$(zt$,2)
zt% = VAL(zt$)
zt% = zt% - AstroInfo.LocDif!
IF AstroInfo.LocDst% THEN zt% = zt% - 1
zt% = zt% + gZone%
IF gSelZoneDS% THEN zt% = zt% + 1
IF zt% > 24 THEN zt% = zt% - 24
IF zt% < 0 THEN zt% = zt% + 24
zt$ = MID$(t$,3,6)
zt$ = STR$(zt%) + zt$
zt$ = RIGHT$(zt$,8)
ut$ = FN setTime$(ut$)
t$ = FN setTime$(t$)
zt$ = FN setTime$(zt$)
z$ = STR$(AstroInfo.LocDif!) + " is your Zone."
EDIT$(2) = ut$
EDIT$(4) = t$
EDIT$(6) = zt$
EDIT$(7) = z$
END FN
LOCAL FN ReadLocation(locRecAddr&)
` MOVE.L ^locRecAddr&,A0
` MOVE.L #$000C00E4,D0
` DC.W $A051
END FN
LOCAL FN StoreLocation(LocationLat!,LocationLng!,LocationDst%,LocationDif!)
DIM DateTimeRec.DateTimeRecSize
Seconds&=3600*ABS(FRAC(LocationLat!))
CALL SECS2DATE(Seconds&,@DateTimeRec)
LocationLaD%=INT(LocationLat!)
LocationLaM%=DateTimeRec.Minute%
LocationLaS%=DateTimeRec.Second%
Seconds&=3600*ABS(FRAC(LocationLng!))
CALL SECS2DATE(Seconds&,@DateTimeRec)
LocationLnD%=INT(LocationLng!)
LocationLnM%=DateTimeRec.Minute%
LocationLnS%=DateTimeRec.Second%
AstroInfo.LocLat!=LocationLat!
AstroInfo.LocLaD%=LocationLaD%
AstroInfo.LocLaM%=LocationLaM%
AstroInfo.LocLaS%=LocationLaS%
AstroInfo.LocLng!=LocationLng!
AstroInfo.LocLnD%=LocationLnD%
AstroInfo.LocLnM%=LocationLnM%
AstroInfo.LocLnS%=LocationLnS%
AstroInfo.LocDst%=LocationDst%
AstroInfo.LocDif!=LocationDif!
END FN
LOCAL FN GetLocation 'Uses settings of Map control panel
DIM Location.machineLocation
FN ReadLocation(@Location)
LocationLat! = 360.0 * Location.latitude& / (2^32)
LocationLng! = 360.0 * Location.longitude& / (2^32)
LocationDst% = PEEK(@Location + _DlsDelta)
IF LocationDst%=128 THEN LocationDst%=-1
LocationGMT& = Location.DlsDelta& AND &00FFFFFF
IF LocationGMT& AND &00800000 THEN LocationGMT& = LocationGMT& OR &FF000000
LocationDif! = LocationGMT&/3600
FN StoreLocation(LocationLat!,LocationLng!,LocationDst%,LocationDif!)
dstCheck% = AstroInfo.LocDst% 'AstroInfo.LocDst% equals Summertime Hrs +/- from Present Time
LONG IF dstCheck% = -1
BUTTON 27, _markedBtn
XELSE
BUTTON 27, 1
END IF
END FN
LOCAL FN radioGroup (btnClicked, first, last)
FOR btnNum = first TO last
LONG IF BUTTON(btnNum) = _markedBtn
BUTTON #btnNum, _activeBtn
END IF
NEXT btnNum
BUTTON #btnClicked, _markedBtn
END FN
LOCAL FN doDialog
evnt = DIALOG(0)
id = DIALOG(evnt)
SELECT evnt
CASE _wndClick
LONG IF WINDOW(1)
WINDOW #1
XELSE
WINDOW #2
END IF
CASE _wndClose
SELECT id
CASE (1)
WINDOW CLOSE #1
gProgramEnds = true
CASE (2)
WINDOW CLOSE #2
MENU 3,1, _enable
MENU 3,2, _disable
END SELECT
CASE _btnClick
SELECT id
CASE(1)
FN radioGroup(1, 1, 25)
gZone% = 12
CASE(2)
FN radioGroup(2, 1, 25)
gZone% = 11
CASE(3)
FN radioGroup(3, 1, 25)
gZone% = 10
CASE(4)
FN radioGroup(4, 1, 25)
gZone% = 9
CASE(5)
FN radioGroup(5, 1, 25)
gZone% = 8
CASE(6)
FN radioGroup(6, 1, 25)
gZone% = 7
CASE(7)
FN radioGroup(7, 1, 25)
gZone% = 6
CASE(8)
FN radioGroup(8, 1, 25)
gZone% = 5
CASE(9)
FN radioGroup(9, 1, 25)
gZone% = 4
CASE(10)
FN radioGroup(10, 1, 25)
gZone% = 3
CASE(11)
FN radioGroup(11, 1, 25)
gZone% = 2
CASE(12)
FN radioGroup(12, 1, 25)
gZone% = 1
CASE(13)
FN radioGroup(13, 1, 25)
gZone% = 0
CASE(14)
FN radioGroup(14, 1, 25)
gZone% = -1
CASE(15)
FN radioGroup(15, 1, 25)
gZone% = -2
CASE(16)
FN radioGroup(16, 1, 25)
gZone% = -3
CASE(17)
FN radioGroup(17, 1, 25)
gZone% = -4
CASE(18)
FN radioGroup(18, 1, 25)
gZone% = -5
CASE(19)
FN radioGroup(19, 1, 25)
gZone% = -6
CASE(20)
FN radioGroup(20, 1, 25)
gZone% = -7
CASE(21)
FN radioGroup(21, 1, 25)
gZone% = -8
CASE(22)
FN radioGroup(22, 1, 25)
gZone% = -9
CASE(23)
FN radioGroup(23, 1, 25)
gZone% = -10
CASE(24)
FN radioGroup(24, 1, 25)
gZone% = -11
CASE(25)
FN radioGroup(25, 1, 25)
gZone% = -12
CASE(26)
gProgramEnds = true
CASE (28)
LONG IF BUTTON (28) = 1
BUTTON 28, _markedBtn
gSelZoneDS% = _ztrue
XELSE
BUTTON 28, 1
gSelZoneDS% = _false
END IF
END SELECT
FN doTimer
END SELECT
END FN
LOCAL FN doMenu
menuID% = MENU(_menuID)
itemID% = MENU(_itemID)
SELECT menuID%
CASE(1)
SELECT itemID%
CASE(1)
END
END SELECT
CASE(3)
SELECT itemID%
CASE(1)
FN showMap
MENU 3,1, _disable
MENU 3,2, _enable
CASE(2)
WINDOW CLOSE #2
MENU 3,1, _enable
MENU 3,2, _disable
END SELECT
END SELECT
MENU
END FN
'---------------------- Main -------------------------
WINDOW OFF
COORDINATE WINDOW
ON DIALOG FN doDialog
ON MENU FN doMenu
ON TIMER(1) FN doTimer
FN mainBuild
FN GetLocation
DO
HANDLEEVENTS
UNTIL gProgramEnds
'---------------------- End -------------------------
Chris Wyatt
|