[futurebasic] RE: [FB] Adjusting time

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : August 1999 : Group Archive : Group : All Groups

From: Ken Shmidheiser <kshmidheiser@...>
Date: Tue, 24 Aug 1999 16:33:41 -0400
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.

Comments are invited and welcome.


Remember, please adjust for e-mail line breaks.

'---------------------- Begin -------------------------

COMPILE 0, _caseInsensitive_IncludeCDEF

'---------------------- Globals -------------------------
DIM gProgramEnds

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,"GMT",( 20, 75)-( 158, 95),_statNoFramed, _centerJust
EDIT FIELD  2,"",( 20, 95)-( 158, 112),_statFramed, _centerJust

EDIT FIELD  3,"System Time",( 220, 75)-( 368, 95),_statNoFramed, _centerJust
EDIT FIELD  4,"",( 220, 95)-( 368, 112),_statFramed, _centerJust

EDIT FIELD  5,"Adjusted Time Zone",( 420, 75)-( 557, 
95),_statNoFramed, _centerJust
EDIT FIELD  6,"0 hour change",( 420, 95)-( 557, 112),_statFramed, _centerJust

TEXT _times, 30
EDIT FIELD  7,"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), 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), Russia 7",( 20, 251)-( 200, 
271),_radio_CDEFbaseID_CDEFuseWindowFont
BUTTON  6, 1,"+7 WAST (W. Australian), 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 Eurpean 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 or UT (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

WINDOW  1
END FN


LOCAL FN showMap

WINDOW #2,"",( 0, 0)-( 250, 100),_docNoGrow
EDIT FIELD #1,"This window is a placeholder for a map of 
international time zones. Sorry, you need a Resource file to hold the 
map, so I couldn't send it to the list. If you want it, e-mail me off 
list.", ( 10, 20)-( 240, 80), _statNoFramed,_centerJust
WINDOW #2

END FN


LOCAL FN doTimer

t$=TIME$
t$=LEFT$(t$,8)

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
t$=" 12"+RIGHT$(t$,9)
END IF
END IF

LONG IF RIGHT$(t$,2)<>"PM"
t$=STR$(VAL(LEFT$(t$,2)))+RIGHT$(t$,6)+" 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

EDIT$(4) = t$

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

convert% = AstroInfo.LocDif!                      'AstroInfo.LocDif! 
equals Hours Time Difference East from GMT
convert$ = STR$(convert%)

EDIT$(2) = convert$

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)
EDIT$(6) = "+12 hour change"
CASE(2)
FN radioGroup(2, 1, 25)
EDIT$(6) = "+11 hour change"
CASE(3)
FN radioGroup(3, 1, 25)
EDIT$(6) = "+10 hour change"
CASE(4)
FN radioGroup(4, 1, 25)
EDIT$(6) = "+9 hour change"
CASE(5)
FN radioGroup(5, 1, 25)
EDIT$(6) = "+8 hour change"
CASE(6)
FN radioGroup(6, 1, 25)
EDIT$(6) = "+7 hour change"
CASE(7)
FN radioGroup(7, 1, 25)
EDIT$(6) = "+6 hour change"
CASE(8)
FN radioGroup(8, 1, 25)
EDIT$(6) = "+5 hour change"
CASE(9)
FN radioGroup(9, 1, 25)
EDIT$(6) = "+4 hour change"
CASE(10)
FN radioGroup(10, 1, 25)
EDIT$(6) = "+3 hour change"
CASE(11)
FN radioGroup(11, 1, 25)
EDIT$(6) = "+2 hour change"
CASE(12)
FN radioGroup(12, 1, 25)
EDIT$(6) = "+1 hour change"
CASE(13)
FN radioGroup(13, 1, 25)
EDIT$(6) = "0 hour change"
CASE(14)
FN radioGroup(14, 1, 25)
EDIT$(6) = "-1 hour change"
CASE(15)
FN radioGroup(15, 1, 25)
EDIT$(6) = "-2 hour change"
CASE(16)
FN radioGroup(16, 1, 25)
EDIT$(6) = "-3 hour change"
CASE(17)
FN radioGroup(17, 1, 25)
EDIT$(6) = "-4 hour change"
CASE(18)
FN radioGroup(18, 1, 25)
EDIT$(6) = "-5 hour change"
CASE(19)
FN radioGroup(19, 1, 25)
EDIT$(6) = "-6 hour change"
CASE(20)
FN radioGroup(20, 1, 25)
EDIT$(6) = "-7 hour change"
CASE(21)
FN radioGroup(21, 1, 25)
EDIT$(6) = "-8 hour change"
CASE(22)
FN radioGroup(22, 1, 25)
EDIT$(6) = "-9 hour change"
CASE(23)
FN radioGroup(23, 1, 25)
EDIT$(6) = "-10 hour change"
CASE(24)
FN radioGroup(24, 1, 25)
EDIT$(6) = "-11 hour change"
CASE(25)
FN radioGroup(25, 1, 25)
EDIT$(6) = "-12 hour change"

CASE(26)
gProgramEnds = true
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 -------------------------



___________________________________________________________________
Ken Shmidheiser               Systems Administrator/General Manager

Internet: kshmidheiser@...    Fax:  606.679.9225
Somerset, KY 42502-0221                        Phone:  606.679.4266
___________________________________________________________________