06-28-2006, 03:43 AM
Quote:You sure know how to pick release dates.Here's a working timezone program that I posted in the timezone challenge last year. It might help you.
Hint. I'm won't be able to get online probably for a week. Maybe it's evening now at your location. I suck at calculating time zones.
Code:
defint a-z
DECLARE FUNCTION NumStrict (Z$)
dim tz (1 to 24)
dim tn$(1 to 24)
tz(1)=0 :tn$(1)="London"
tz(2)=-1 :tn$(2)="Reykjavik"
tz(3)=-2 :tn$(3)="Greenland"
tz(4)=-3 :tn$(4)="Rio de Janeiro"
tz(5)=-4 :tn$(5)="Santiago de Chile"
tz(6)=-5 :tn$(6)="New York"
tz(7)=-6 :tn$(7)="Chicago"
tz(8)=-7 :tn$(8)="Denver"
tz(9)=-8 :tn$(9)="Seattle"
tz(10)=-9 :tn$(10)="Alaska"
tz(11)=-10 :tn$(11)="Honolulu"
tz(12)=-11 :tn$(12)="Midway Is."
tz(13)=+12 :tn$(13)="New Zealand"
tz(14)=+11 :tn$(14)="Solomon Is."
tz(15)=+10 :tn$(15)="Sydney"
tz(16)=+9 :tn$(16)="Tokyo"
tz(17)=+8 :tn$(17)="China"
tz(18)=+7 :tn$(18)="Bangkok"
tz(19)=+6 :tn$(19)="Omsk"
tz(20)=+5 :tn$(20)="Karachi"
tz(21)=+4 :tn$(21)="Stalingrad"
tz(22)=+3 :tn$(22)="Moscow"
tz(23)=+2 :tn$(23)="Cairo"
tz(24)=+1 :tn$(24)="Berlin"
getfrom:
Print "Enter FROM timezone as GMT0, GMT+nn, or GMT-nn ";
gosub getgmt
if gmterr=1 then print "Invalid timezone":goto getfrom
fromzone=gmtzone
fromname$=zonename$
fromgmt$=gmt$
gettime:
Print "Enter military time (hh:mm) for FROM timezone ";
input ztime$
ztime$=ltrim$(rtrim$(ztime$))
if mid$(ztime$,3,1)<>":" or len(ztime$)<>5 then print "Invalid time":goto gettime
z$=left$(ztime$,2)+right$(ztime$,2)
if not NumStrict(z$) then print "Invalid time":goto gettime
hh=val(left$(z$,2))
mm$=right$(z$,2)
if hh>23 or mm>59 then print "Invalid time":goto gettime
getto:
Print "Enter TO timezone as GMT0, GMT+nn, or GMT-nn ";
gosub getgmt
if gmterr=1 then print "Invalid timezone":goto getto
tozone=gmtzone
toname$=zonename$
togmt$=gmt$
if tozone=fromzone then print "FROM and TO timezones must be different":goto getto
rem ***** MAIN PROCESS *****
if fromzone<0 then fromsign$="-" else fromsign$="+"
if tozone<0 then tosign$ ="-" else tosign$="+"
from.to.sign$=fromsign$+tosign$
afrom = abs(fromzone)
ato = abs(tozone)
days$="0"
SELECT CASE from.to.sign$
CASE "-+"
difhours=afrom+ato
CASE "--"
if afrom<ato then
difhours= -(ato-afrom)
else
rem from is greater.
difhours=afrom-ato
end if
CASE "++"
if afrom<ato then
difhours= ato-afrom
else
difhours= -(afrom-ato)
end if
CASE "+-"
rem difhours=ato+afrom
difhours=-(afrom+ato)
CASE ELSE
print "SYSERR: invalid +- variable":system
END SELECT
tohh=hh+difhours
if tohh<0 then tohh=tohh+24 : days$="-1" : goto gothh
if tohh>23 then tohh=tohh-24 : days$="+1"
gothh:
print
rem print "FROM zone is GMT";fromzone;" ";fromname$
rem print "TO zone is GMT"; tozone;" ";toname$
print "FROM zone is ";fromgmt$;" ";fromname$
print "TO zone is "; togmt$;" ";toname$
if difhours<0 then signh$="-" else signh$="+"
print "Time at FROM zone is ";right$("00"+ltrim$(str$(hh)),2);":";mm$
print "dif in hours is ";signh$;ltrim$(str$(abs(difhours)))
print "Time at TO zone is ";right$("00"+ltrim$(str$(tohh)),2);":";mm$
print "Date adjustment for TO zone is ";days$
system
getgmt:
gmterr=0 'assume no error
input gmt$
gmt$=ucase$(ltrim$(rtrim$(gmt$)))
lgmt=len(gmt$)
if left$(gmt$,3)<>"GMT" or lgmt<4 or lgmt>6 then gmterr=1:return
p4$=mid$(gmt$,4,1)
if lgmt=4 and p4$="0" then gmtzone=0:goto findname
if p4$<>"+" and p4$<>"-" then gmterr=1:return
if lgmt<5 then gmterr=1:return
z$=mid$(gmt$,5)
if not NumStrict(z$) then gmterr=1:return
if p4$="-" then zmax=11 else zmax=12
gmtzone=val(z$)
if gmtzone<1 or gmtzone>zmax then gmterr=1:return
if p4$="-" then gmtzone=-gmtzone
findname:
found=0
for x=1 to 24
if tz(x)=gmtzone then found=1:exit for
next x
if found=0 then print "SYSERR: zone not found on table":system
zonename$=tn$(x)
return '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
END
FUNCTION NumStrict (Z$)
REM *
REM *** (NUMSTRICT) - CHECK FOR STRICTLY NUMERIC ONLY (NO NULL NO DECIMAL)
REM *
NumStrict=0 'Init to False
IF Z$="" THEN EXIT FUNCTION
FOR X = 1 TO LEN(Z$)
A=ASC(MID$(Z$,X,1))
IF A<48 OR A>57 THEN EXIT FUNCTION
NEXT X
NumStrict = -1 'True
END FUNCTION