Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Timezone calculator.
#51
Quote:I can't be bothered changing stuff around now, but please feel free to go ahead and modify it. Smile

>anarky
What would be the purpose of my modifying your code? My understanding of a challenge is that participants submit working solutions in compliance with the specifications.

As the author of this challenge, I am not seeking solutions to be used for my own benefit, only as a challenge.

It's too bad you're deciding to abandon your solution at this time.
*****
Reply
#52
I have these times. I didn't aim to win, only to perhaps provide a helping hand for others who are more serious about this goal. It's easy to add the new features. I just don't have the time or energy now to bother with this little program.

>anarky
Screwing with your reality since 1998.
Reply
#53
Well, it doesn't seem like anyone else is willing to post a completely working version.

Therefore, I think we owe DrV a round of congratulations for his brilliant solution to this challenge.

DrV, you are the winner of this timezone challenge, by far. Congratulations for an excellent program. Big Grin

*****
Reply
#54
Thanks. Big Grin I think this is the first challenge that I've ever actually completed... perhaps there will be more like this one that strike my fancy. Smile
Reply
#55
Just so you all know that I also developed a solution, here's my working version.

Based on the logic that I chose, it turned out that I did not need to use the table of timezones except for displaying the city names.

There are sections of the code which are not structured because it was easier for me to do it elsewise.

My code is full of input validations since it didn't occur to me to do restricted input menu selections like in DrV's program.
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
*****
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)