Qbasicnews.com

Full Version: Timezone calculator.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6
Quote:BTW, your name, rpgfan3233, it couldn't possibly be rpg for RPG (Report Program Generator)?
*****
Sorry, but you are wrong. Smile Why do you ask about a Report Program Generator? :???:
RPG (I got lazy and used all lowercase) - Role-Playing Game
Hey guys, is anybody working on this timezone problem?

If anybody has something in the works, please say so, because I'm ready to post my own version. I don't want to steal your thunder. :wink:

DrV, rgpfan, Deleter and anarky: You all seem to understand the problem. You must have developed some solution, no?

Remember, there's no best way to do this. I know of 3 ways, and finally picked the one that I was able to get working.

Please let me know, 'cause this thread is getting stale.
*****
I haven't worked on it, but the code shouldn't be too long. I might post mine on Thursday (I'm busy all day Wednesday).
I haven't written anything yet; if I don't post anything in, say, 2 days, feel free to post your own. I might get to it, but I wouldn't count on it (this 'time' business is the problem - or rather, not enough of it Smile ).
Heck, I'd forgotten about it. I really don't have the time myself, but I think I can work out a text one for you.

>anarky
RPGFAN,
Ok, I'll wait until Thursday night.
If you need extra time, tell me.


DrV,
You should be able to whip something up by Thursday night.
Give it a shot. Forget all the frills, just work on computing the time at the TO timezone.


ANARKY,
You said: "I think I can work out a text one."
If that means a pseudo-code version, that's fine. We'd be interested in seeing you method, at least.

*****
Psuedo code:
Code:
Display cities
Choose your city (this could be preset)
Find own timezone (also maybe preset)
Choose destination city
Find dest city timezone (Mine is in a database, but I am having some curious problems with that)
Calculate difference between own city and GMT, adjust time
Calculate difference betwen destination city and GMT, adjust time

I have not included DST anywhere in the world. Therefore times may vary. I bet you didn't know Kathmandu is in an ODD timezone (GMT+5:45)?

>anarky
Sorry, I forgot about this. I finished it, but forgot to post it.

It doesn't have comments, unfortunately, but it should be fairly simple. Most of the stuff is just error-checking. The actual calculations are only a few lines. No DST was included, as per the revised rules.

[syntax="qbasic"]CONST key$ = "0123456789"
DIM tZone1 AS STRING, date AS STRING, time AS STRING, tZone2 AS STRING
DIM cities(-11 TO 12) AS STRING

FOR i = -11 TO 12
READ cities(i)
NEXT i

CLS
DO
plusMinusCount = 0
CLS
LOCATE 1, 1
INPUT "Enter the timezone you are currently in: ", tZone1
FOR i = 1 TO LEN(tZone1)
IF MID$(tZone1, i, 1) = "-" OR MID$(tZone1, i, 1) = "+" THEN
plusMinusCount = plusMinusCount + 1
IF i <> LEN(tZone1) - 1 AND i <> LEN(tZone1) - 2 THEN
badZone = -1
ELSE
badZone = 0
END IF
IF plusMinusCount > 1 THEN badZone = -1: EXIT FOR
END IF
NEXT i
IF badZone <> -1 THEN
IF INSTR(tZone1, "GMT") <> 0 AND LEN(tZone1) < 7 THEN
IF INSTR(tZone1, "-") = LEN(tZone1) - 2 OR INSTR(tZone1, "+") = LEN(tZone1) - 2 THEN
badZone = 0
plusMinusPos = LEN(tZone1) - 2
ELSEIF INSTR(tZone1, "-") = LEN(tZone1) - 1 OR INSTR(tZone1, "+") = LEN(tZone1) - 1 THEN
badZone = 0
plusMinusPos = LEN(tZone1) - 1
ELSE
badZone = -1
END IF
ELSE
badZone = -1
END IF
IF VAL(RIGHT$(tZone1, plusMinusPos - 1)) > 12 OR VAL(RIGHT$(tZone1, plusMinusPos - 1)) < -11 THEN
badZone = -1
END IF
END IF
LOOP WHILE badZone = -1

DO
dateStr$ = ""
CLS
LOCATE 1, 1
PRINT "Enter the timezone you are currently in: "; tZone1
INPUT "Enter the date you are in that timezone: ", date
FOR i = 1 TO LEN(date)
IF INSTR(key$, MID$(date, i, 1)) <> 0 THEN
dateStr$ = dateStr$ + MID$(date, i, 1)
END IF
NEXT i
IF LEN(dateStr$) = 8 THEN
badDate = 0
ELSE
badDate = -1
END IF
LOOP WHILE badDate = -1

DO
timeStr$ = ""
CLS
LOCATE 1, 1
PRINT "Enter the timezone you are currently in: "; tZone1
PRINT "Enter the date you are in that timezone: "; date
INPUT "Enter the time you are in that timezone: ", time
FOR i = 1 TO LEN(time)
IF INSTR(key$, MID$(time, i, 1)) <> 0 THEN
timeStr$ = timeStr$ + MID$(time, i, 1)
END IF
NEXT i
IF LEN(timeStr$) = 4 THEN
IF VAL(LEFT$(timeStr$, 2)) < 24 AND VAL(RIGHT$(timeStr$, 2)) < 60 THEN
badTime = 0
ELSE
badTime = -1
END IF
ELSEIF LEN(timeStr$) = 3 THEN
timeStr$ = "0" + timeStr$
IF VAL(LEFT$(timeStr$, 2)) < 24 AND VAL(RIGHT$(timeStr$, 2)) < 60 THEN
badTime = 0
ELSE
badTime = -1
END IF
ELSE
badTime = -1
END IF
LOOP WHILE badTime = -1
DO
plusMinusCount2 = 0
CLS
LOCATE 1, 1
PRINT "Enter the timezone you are currently in: "; tZone1
PRINT "Enter the date you are in that timezone: "; date
PRINT "Enter the time you are in that timezone: "; time
INPUT "Enter the timezone you want to find the time for: ", tZone2
FOR i = 1 TO LEN(tZone2)
IF MID$(tZone2, i, 1) = "-" OR MID$(tZone2, i, 1) = "+" THEN
plusMinusCount2 = plusMinusCount2 + 1
IF i <> LEN(tZone2) - 1 AND i <> LEN(tZone2) - 2 THEN
badZone = -1
ELSE
badZone = 0
END IF
IF plusMinusCount2 > 1 THEN badZone = -1: EXIT FOR
END IF
NEXT i
IF badZone <> -1 THEN
IF INSTR(tZone2, "GMT") <> 0 AND LEN(tZone2) < 7 THEN
IF INSTR(tZone2, "-") = LEN(tZone2) - 2 OR INSTR(tZone2, "+") = LEN(tZone2) - 2 THEN
badZone = 0
plusMinusPos2 = LEN(tZone2) - 2
ELSEIF INSTR(tZone2, "-") = LEN(tZone2) - 1 OR INSTR(tZone2, "+") = LEN(tZone2) - 1 THEN
badZone = 0
plusMinusPos2 = LEN(tZone2) - 1
ELSE
badZone = -1
END IF
ELSE
badZone = -1
END IF
IF VAL(RIGHT$(tZone2, plusMinusPos - 1)) > 12 OR VAL(RIGHT$(tZone2, plusMinusPos - 1)) < -11 THEN
badZone = -1
END IF
END IF
LOOP WHILE badZone = -1
gmt = VAL(LEFT$(timeStr$, 2)) + (-1 * VAL(MID$(tZone1, plusMinusPos)))
IF gmt + VAL(MID$(tZone2, plusMinusPos2)) > 24 THEN
MID$(dateStr$, 3, 2) = LTRIM$(STR$(VAL(MID$(dateStr$, 3, 2)) + 1))
hour$ = LTRIM$(STR$((gmt + VAL(MID$(tZone2, plusMinusPos2))) - 24))
ELSEIF gmt + VAL(MID$(tZone2, plusMinusPos2)) < 0 THEN
MID$(dateStr$, 3, 2) = LTRIM$(STR$(VAL(MID$(dateStr$, 3, 2)) - 1))
hour$ = LTRIM$(STR$(24 - ABS(gmt + VAL(MID$(tZone2, plusMinusPos2)))))
ELSE
hour$ = LTRIM$(STR$(gmt + VAL(MID$(tZone2, plusMinusPos2))))
END IF
finalTime$ = hour$ + ":" + RIGHT$(timeStr$, 2)
finalDate$ = LEFT$(dateStr$, 2) + "/" + MID$(dateStr$, 3, 2) + "/" + RIGHT$(dateStr$, 4)
PRINT tZone2, finalDate$, finalTime$, cities(VAL(MID$(tZone2, plusMinusPos2)))
END

DATA "Midway Island","Honolulu","Alaska","Seattle","Denver","Chicago"
DATA "New York","Santiago de Chile","Rio de Janeiro","Greenland","Reykjavik","London"
DATA "Berlin","Cairo","Moscow","Stalingrad","Karachi","Omsk, Russia"
DATA "Bangkok","Hong Kong, and China","Tokyo","Sydney","Solomon Islands","New Zealand"[/syntax]

Of course, there are probably bugs, but I didn't spend much time on it. Smile
Oops, forgot too :oops: . (Plus I managed to blow away the Windows bootloader again a couple days ago, ouch... Smile ) I might whip something up tonight after I get home from work.
RPGFAN,

Very good. The main part which calculates the time at the TO timezone, seems to be working.

Had some problems because of not knowing what the format of the input should be. Like the date, what format do you want?

By the way, we had decided that we were not going to calculate dates, only a day adjustment like -1, 0, +1.

I need to do a bit more testing. But in the meantime, you are a stong contender for winning this challenge. Good work! Big Grin
*****
Pages: 1 2 3 4 5 6