[futurebasic] Re: [FB] Adjusting time

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

From: "Deepesh Letap" <DLetap@...>
Date: Mon, 23 Aug 1999 22:08:40 +0100

> 1). Any suggestions on accessing the Time Zone data in the Date & 
> Time control panel and using it as a basis for converting the
> computer's clock time to GMT?

Yes, this is possible using the Location Manager routines. I will post an
example at the end of this message. Basically, you run the routine and you
would be interested in the following variables:

"Latitude:  ";AstroInfo.LocLat! 'Degrees North (Neg means South)
"Longitude: ";AstroInfo.LocLng! 'Degrees East  (Neg means West)
"Summertime:";AstroInfo.LocDst% 'Summertime Hrs +/- from Present Time
"Time Diff: ";AstroInfo.LocDif! 'Hours Time Difference East from GMT

Say for example the present time in your area is 14:25. First, you add the
value of AstroInfo.LocDst% to the hours. If Summertime is presently in
effect, the value is -1 meaning you deduct 1 hour from current time to
obtain real time. In winter it would be 0 meaning no adjuustment is needed.
Thus, in Summertime, the 14:25 would be amended to 13:25 and similarly it
would remain 14:25 during winter. Also, you can deduct the value of
AstroInfo.LocDif! from the local time to obtain the present GMT time. If you
were in New York which is normally 5 hours behind GMT, your variables would
read:

 During Wintertime:

 AstroInfo.LocDst% = 0
 AstroInfo.LocDif! = -5

 Local NY Time (14:25) add 0 to adjust for SummerTime
 Winter NY Time is still 14:25

 Deduct -5 hours (double neg mean add!) which becomes 19:25 GMT

 During Summertime:

 AstroInfo.LocDst% = -1
 AstroInfo.LocDif! = -4

 Local NY Time (14:25) add -1 to adjust for SummerTime
 Winter NY Time is therefore 13:25

 Deduct -4 hours (double neg mean add!) which becomes 18:25 GMT

Note how the 5 hour difference is maintained between local real time and GMT
for both summer and winter times.

> 2). The system clock works regardless if Date & Time is disabled. Any
> background way of determining the time zone the system clock is set
> for without Date & Time being active? (We're getting into the bowels
> here, and I'm lost.)

As above, use the AstroInfo.LocDif! to determine difference from GMT.

> 3). I ran Deep's toolbox clock call in the Command window, but found
> it would not consistently update when the HoursForward& variable was
> changed. I inserted a Clear Screen, but that didn't help. My guess is
> that for some reason it has to wait 60 seconds to refresh, but I
> don't understand why. Here's Deep's call again. Maybe some of you
> would be so nice as to run it and see if it refreshes when he
> variable is changed:
>

I think it is updating but since the format is set for short, the display
would be HH:MM thus the minute portion would naturally only update once
every minute! Try setting the format to long and you may find it in
accordance with your expectations.

> 4). I know these things can be done, because I have seen clock
> applications that show the user's time zone compared with time zones
> around the world. Figuring it out is the hard part.

Like many things, hard from the outside, easy once you know how!

Sorry about the poor variable names. The routines was extracted from an
incomplete (actually, more like abandoned by default) set of routines to
determine your location in the world and the times for sunrise and sunset at
that location. Maybe it will get finished one day! Very low priority at the
moment!

Also, if you want more info about Date and Time routines, have a look at the
DateTime Primer available from the FB Org CD or for download from the
Developer Corner at http://www.ScorpionResearch.com/futrebasic/ where the
file is listed.

Hope this helps,

Deep






SAMPLE SOURCE ATTACHED:


COMPILE 0, _caseInsensitive
REM
_machineLocation        = 12
REM
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
REM
END GLOBALS


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
  REM
  Seconds&=3600*ABS(FRAC(LocationLat!))
  CALL SECS2DATE(Seconds&,@DateTimeRec)
  LocationLaD%=INT(LocationLat!)
  LocationLaM%=DateTimeRec.Minute%
  LocationLaS%=DateTimeRec.Second%
  REM
  Seconds&=3600*ABS(FRAC(LocationLng!))
  CALL SECS2DATE(Seconds&,@DateTimeRec)
  LocationLnD%=INT(LocationLng!)
  LocationLnM%=DateTimeRec.Minute%
  LocationLnS%=DateTimeRec.Second%
  REM
  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
  REM
  REM Uses settings of Map control panel
  REM
  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
  REM
  FN StoreLocation(LocationLat!,LocationLng!,LocationDst%,LocationDif!)
END FN

FN GetLocation


PRINT "Latitude:  ";AstroInfo.LocLat! 'Degrees North (Neg means South)
PRINT "Longitude: ";AstroInfo.LocLng! 'Degrees East  (Neg means West)
PRINT "Summertime:";AstroInfo.LocDst% 'Summertime Hrs +/- from Present Time
PRINT "Time Diff: ";AstroInfo.LocDif! 'Hours Time Difference East from GMT