CHALLENGE: Timezone calculator.
CHALLENGE: Timezone calculator.
My son is in Japan this week participating in a Robocup (robots that play soccer) competition. Anyway, we in the family have a tough time figuring out what date and time it is over there. This made me think of a timezone calculator program.
Note: This challenge recently appeared on other QB forums, but the specifications below have been significantly revised and enhanced.
Here are the requirements of the program:
- Program written in QB or Quickbasic.
- For input and output time, please use military time, example 00:45 instead of 12:45 am, and 17:30 instead of 5:30 pm.
- Input timezones will be expressed as GMT +nn or GMT -nn or GMT itself. (See table of timezones below.)
- Input #1: the FROM timezone, and respective time.
- Input #2: the TO timezone.
- Perform adequate input validation.
- Output #1: Print the FROM timezone, the country/city name from timezones table, and the given time at the FROM timezone.
- Output #2: Print the TO timezone, the country/city name from timezones table, the calculated time in the TO timezone based on the given time at the FROM timezone, and an indication as to whether the date in the TO timezone needs adjustment by -1, 0, or +1 days.
Considerations:
- The program will only handle the 24 standard timezones as shown in the table below.
- Due to the complexity, Daylight Savings Time or Summer Time will not be addressed by the program. An adjustment to the computed time can be performed by the user of the program, as required.
Please submit a complete working program, not just a function. I'll check every entry and provide feedback.
TABLE OF TIMEZONES:
GMT = London
GMT - 1 = Reykjavik
GMT - 2 = Greenland
GMT - 3 = Rio de Janeiro, Brazil
GMT - 4 = Santiago de Chile
GMT - 5 = New York
GMT - 6 = Chicago
GMT - 7 = Denver
GMT - 8 = Seattle
GMT - 9 = Alaska
GMT -10 = Honolulu
GMT -11 = Midway Island
GMT -12 (does not exist, see GMT +12)
continuing in a circle around the world............
GMT +12 = New Zealand
GMT +11 = Solomon Islands
GMT +10 = Sydney
GMT + 9 = Tokyo
GMT + 8 = Hong Kong, and China
GMT + 7 = Bangkok
GMT + 6 = Omsk, Russia
GMT + 5 = Karachi
GMT + 4 = Stalingrad
GMT + 3 = Moscow
GMT + 2 = Cairo
GMT + 1 = Berlin
*****
Note: This challenge recently appeared on other QB forums, but the specifications below have been significantly revised and enhanced.
Here are the requirements of the program:
- Program written in QB or Quickbasic.
- For input and output time, please use military time, example 00:45 instead of 12:45 am, and 17:30 instead of 5:30 pm.
- Input timezones will be expressed as GMT +nn or GMT -nn or GMT itself. (See table of timezones below.)
- Input #1: the FROM timezone, and respective time.
- Input #2: the TO timezone.
- Perform adequate input validation.
- Output #1: Print the FROM timezone, the country/city name from timezones table, and the given time at the FROM timezone.
- Output #2: Print the TO timezone, the country/city name from timezones table, the calculated time in the TO timezone based on the given time at the FROM timezone, and an indication as to whether the date in the TO timezone needs adjustment by -1, 0, or +1 days.
Considerations:
- The program will only handle the 24 standard timezones as shown in the table below.
- Due to the complexity, Daylight Savings Time or Summer Time will not be addressed by the program. An adjustment to the computed time can be performed by the user of the program, as required.
Please submit a complete working program, not just a function. I'll check every entry and provide feedback.
TABLE OF TIMEZONES:
GMT = London
GMT - 1 = Reykjavik
GMT - 2 = Greenland
GMT - 3 = Rio de Janeiro, Brazil
GMT - 4 = Santiago de Chile
GMT - 5 = New York
GMT - 6 = Chicago
GMT - 7 = Denver
GMT - 8 = Seattle
GMT - 9 = Alaska
GMT -10 = Honolulu
GMT -11 = Midway Island
GMT -12 (does not exist, see GMT +12)
continuing in a circle around the world............
GMT +12 = New Zealand
GMT +11 = Solomon Islands
GMT +10 = Sydney
GMT + 9 = Tokyo
GMT + 8 = Hong Kong, and China
GMT + 7 = Bangkok
GMT + 6 = Omsk, Russia
GMT + 5 = Karachi
GMT + 4 = Stalingrad
GMT + 3 = Moscow
GMT + 2 = Cairo
GMT + 1 = Berlin
*****
- SebMcClouth
- Veteran
- Posts: 240
- Joined: Fri Apr 29, 2005 2:20 am
- Location: Inside the Matrix
If someone has build this... may I then use in my program? qbinux?
grtz
Seb
grtz
Seb
I know why you're here. I know what you've been doing... why you hardly sleep, why you live alone, and why night after night, you sit by your computer...<br>
Unfortunately, no one can be told what Qbinux is. You have to see it for yourself.
Unfortunately, no one can be told what Qbinux is. You have to see it for yourself.
Hey guys, is anybody working on a solution to 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.
Seb, if you'd like my version in the meantime, send me your email address by PM.
*****
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.
Seb, if you'd like my version in the meantime, send me your email address by PM.
*****
If you are ahead of me, lead.
If you are behind me, follow.
If you are not doing anything,
Get out of the way.
If you are behind me, follow.
If you are not doing anything,
Get out of the way.
- SebMcClouth
- Veteran
- Posts: 240
- Joined: Fri Apr 29, 2005 2:20 am
- Location: Inside the Matrix
? ?? Q??$ ??Sj ? ] ? V ? ? ? ? ? ? 2 { ? ? PR FTz? LocalTimeu NMALLOC? TT? TTz
NLocalTime NTTime
ELSENTTime TTime TTDateAdjustA ToTime CC Value z Milit< GA TRIM NTTAdjust TTAdjust FT$ DateAdjustT
DateAdjust FTTime F NDateAdjust
; H IF NLocalTime% + FTz% < 0 OR NLocalTime% + FTz% > 24 THE ?
? ! (C) 2005, by Sebastian McClouthS D ? ? ? D ? ? ? D ? ? ? s? rse ? m Universal TimeZone Calculator"? rse ? m -----------------------------"? rse ? m
TIMEZONES:? rse ? m GMT 0: LONDON? rsd? m GMT -1: REYKJAVIK"? ? rse0 ? m GMT +1: BERLIN? rsd? m GMT -2: GREENLAND"? ? rse0 ? m
GMT +2: CAIRO"? rsd? m GMT -3: RIO DE JANEIRO, BRAZIL? ? rse0 ? m GMT +3: MOSCOW? rsd? m GMT -4: SANTIAGO DE CHILE"? ? rse0 ? m GMT +4: STALINGRAD? rsd? m GMT -5: NEW YORK? ? rse0 ? m GMT +5: KARACHI"? rsd? m GMT -6: CHICAGO"? ? rse0 ? m GMT +6: OMSK, RUSSIA? rsd? m GMT -7: DENVER? ? rse0 ? m GMT +7: BANGKOK"? rsd? m GMT -8: SEATTLE"? ? rse0 ? m GMT +8: HONG KONG, AND CHINA? rsd? m GMT -9: ALASKA? ? rse0 ? m
GMT +9: TOKYO"? rsd? m GMT-10: HONOLULU? ? rse0 ? m GMT+10: SYDNEY? rsd? m GMT-11: MIDWAY ISLANDS? ? rse0 ? m GMT+11: SOLOMON ISLANDS"? rse0 ? m GMT+12: NEW ZEALAND"? ? eP m -"S? m0 If giving e.g. GMT+1, etc, give as input 1, etc.? ? m Enter FROM timezone: "? ? m ? V ? ? m Enter GMT"V QE+ ? m respective time as e.g. 14:00: ? ? m ? ] ? ? ? m Enter TO timezone: "? ? m ? { ? ? { e x] e { ? 0 As stated, -12 doesn't exist.l ? % Adjust LocalTime$ from FTz% to TTz% ?
$- ? ( First we bring LocalTime$ back to GMT: ] d ,Z? ? PRINT NLocalTime%% ? V wdc? V we _ua 8 ? V wdca e ? V wnw? dx A ? V we _M 2 ? V wne w? d A P I N ? V wn? d A P ? ; Okay, we moved FTz% to GMT, now we gonna move GMT to TTz% ? { dc? { e _ua ? { dca ? e ? { nw? dx A ? { e _M ? { ne w? d A P I > ? { n? d $ P ? QE+m :" ] d B ? ? E The DateAdjuster was bugged... can someone help me out on this one? ? rsd? m
TIMEZONES:? ? rse ? m
COUNTRY/CITY:"? ? rse$ ? m LOCAL TIME:"? ? rse2 ? m APROX. DATE ADJUST:"? eF m -"S? rsd? m FROM: ? ? rsd!? m GMT"V QE+ ? ? ? rse ? V ? ? ? rse$ ? ] ? rsd? m TO:"? ? rsd!? m GMT"{ QE+ ? ? ? rse ? { ? ? ? rse$ ? ? ? ? rse2 ? $QE+? ????????V W CC06 X ? ? ? ? e ] 6 m New Zealand"? ? e ] ^ m Solomon Islands"? ? d)] z m Sydney? ? d%] ? m Tokyo"? ? d!] ? m Hong Kong, and China? ? d] ? m Bangkok"? ? d] m Omsk, Russia? ? d] m Karachi"? ? d] >m
Stalingrad? ? d
] Zm Moscow? ? d ] vm Cairo"? ? d] ?m Berlin? ? d] ?m London? ? dx] ?m Reykjavik"? ? d x] ?m Greenland"? ? d
x] m Rio de Janeiro, Brazil? ? dx] Jm Santiago de Chile"? ? dx] jm New York? ? dx] ?m Chicago"? ? dx] ?m Denver? ? d!x] ?m Seattle"? ? d%x] ?m Alaska? ? d)x] m Honolulu? ? e x] .m
Midway Island"? Q ???????? Milit0B X ? ? ? ? -?dca : m 0" ? ? P Q ???????? GA0t X ? ? ? ? Zd_a : m +" ? ? ? m 0"M b m " ? ? I p ? ? P Q ????????
NLocalTime NTTime
ELSENTTime TTime TTDateAdjustA ToTime CC Value z Milit< GA TRIM NTTAdjust TTAdjust FT$ DateAdjustT
DateAdjust FTTime F NDateAdjust
; H IF NLocalTime% + FTz% < 0 OR NLocalTime% + FTz% > 24 THE ?
? ! (C) 2005, by Sebastian McClouthS D ? ? ? D ? ? ? D ? ? ? s? rse ? m Universal TimeZone Calculator"? rse ? m -----------------------------"? rse ? m
TIMEZONES:? rse ? m GMT 0: LONDON? rsd? m GMT -1: REYKJAVIK"? ? rse0 ? m GMT +1: BERLIN? rsd? m GMT -2: GREENLAND"? ? rse0 ? m
GMT +2: CAIRO"? rsd? m GMT -3: RIO DE JANEIRO, BRAZIL? ? rse0 ? m GMT +3: MOSCOW? rsd? m GMT -4: SANTIAGO DE CHILE"? ? rse0 ? m GMT +4: STALINGRAD? rsd? m GMT -5: NEW YORK? ? rse0 ? m GMT +5: KARACHI"? rsd? m GMT -6: CHICAGO"? ? rse0 ? m GMT +6: OMSK, RUSSIA? rsd? m GMT -7: DENVER? ? rse0 ? m GMT +7: BANGKOK"? rsd? m GMT -8: SEATTLE"? ? rse0 ? m GMT +8: HONG KONG, AND CHINA? rsd? m GMT -9: ALASKA? ? rse0 ? m
GMT +9: TOKYO"? rsd? m GMT-10: HONOLULU? ? rse0 ? m GMT+10: SYDNEY? rsd? m GMT-11: MIDWAY ISLANDS? ? rse0 ? m GMT+11: SOLOMON ISLANDS"? rse0 ? m GMT+12: NEW ZEALAND"? ? eP m -"S? m0 If giving e.g. GMT+1, etc, give as input 1, etc.? ? m Enter FROM timezone: "? ? m ? V ? ? m Enter GMT"V QE+ ? m respective time as e.g. 14:00: ? ? m ? ] ? ? ? m Enter TO timezone: "? ? m ? { ? ? { e x] e { ? 0 As stated, -12 doesn't exist.l ? % Adjust LocalTime$ from FTz% to TTz% ?
$- ? ( First we bring LocalTime$ back to GMT: ] d ,Z? ? PRINT NLocalTime%% ? V wdc? V we _ua 8 ? V wdca e ? V wnw? dx A ? V we _M 2 ? V wne w? d A P I N ? V wn? d A P ? ; Okay, we moved FTz% to GMT, now we gonna move GMT to TTz% ? { dc? { e _ua ? { dca ? e ? { nw? dx A ? { e _M ? { ne w? d A P I > ? { n? d $ P ? QE+m :" ] d B ? ? E The DateAdjuster was bugged... can someone help me out on this one? ? rsd? m
TIMEZONES:? ? rse ? m
COUNTRY/CITY:"? ? rse$ ? m LOCAL TIME:"? ? rse2 ? m APROX. DATE ADJUST:"? eF m -"S? rsd? m FROM: ? ? rsd!? m GMT"V QE+ ? ? ? rse ? V ? ? ? rse$ ? ] ? rsd? m TO:"? ? rsd!? m GMT"{ QE+ ? ? ? rse ? { ? ? ? rse$ ? ? ? ? rse2 ? $QE+? ????????V W CC06 X ? ? ? ? e ] 6 m New Zealand"? ? e ] ^ m Solomon Islands"? ? d)] z m Sydney? ? d%] ? m Tokyo"? ? d!] ? m Hong Kong, and China? ? d] ? m Bangkok"? ? d] m Omsk, Russia? ? d] m Karachi"? ? d] >m
Stalingrad? ? d
] Zm Moscow? ? d ] vm Cairo"? ? d] ?m Berlin? ? d] ?m London? ? dx] ?m Reykjavik"? ? d x] ?m Greenland"? ? d
x] m Rio de Janeiro, Brazil? ? dx] Jm Santiago de Chile"? ? dx] jm New York? ? dx] ?m Chicago"? ? dx] ?m Denver? ? d!x] ?m Seattle"? ? d%x] ?m Alaska? ? d)x] m Honolulu? ? e x] .m
Midway Island"? Q ???????? Milit0B X ? ? ? ? -?dca : m 0" ? ? P Q ???????? GA0t X ? ? ? ? Zd_a : m +" ? ? ? m 0"M b m " ? ? I p ? ? P Q ????????
I know why you're here. I know what you've been doing... why you hardly sleep, why you live alone, and why night after night, you sit by your computer...<br>
Unfortunately, no one can be told what Qbinux is. You have to see it for yourself.
Unfortunately, no one can be told what Qbinux is. You have to see it for yourself.
- SebMcClouth
- Veteran
- Posts: 240
- Joined: Fri Apr 29, 2005 2:20 am
- Location: Inside the Matrix
Hope this helps a bit... there was only a slight problem... the date adjusting...
Code: Select all
'(C) 2005, by Sebastian McClouth
DECLARE FUNCTION GA$ (Value AS STRING)
DECLARE FUNCTION Milit$ (Value AS STRING)
DECLARE FUNCTION CC$ (Value AS INTEGER)
CLS
LOCATE , 20: PRINT "Universal TimeZone Calculator"
LOCATE , 20: PRINT "-----------------------------"
LOCATE , 32: PRINT "TIMEZONES:"
LOCATE , 30: PRINT "GMT 0: LONDON"
LOCATE , 1: PRINT "GMT -1: REYKJAVIK"; : LOCATE , 48: PRINT "GMT +1: BERLIN"
LOCATE , 1: PRINT "GMT -2: GREENLAND"; : LOCATE , 48: PRINT "GMT +2: CAIRO"
LOCATE , 1: PRINT "GMT -3: RIO DE JANEIRO, BRAZIL"; : LOCATE , 48: PRINT "GMT +3: MOSCOW"
LOCATE , 1: PRINT "GMT -4: SANTIAGO DE CHILE"; : LOCATE , 48: PRINT "GMT +4: STALINGRAD"
LOCATE , 1: PRINT "GMT -5: NEW YORK"; : LOCATE , 48: PRINT "GMT +5: KARACHI"
LOCATE , 1: PRINT "GMT -6: CHICAGO"; : LOCATE , 48: PRINT "GMT +6: OMSK, RUSSIA"
LOCATE , 1: PRINT "GMT -7: DENVER"; : LOCATE , 48: PRINT "GMT +7: BANGKOK"
LOCATE , 1: PRINT "GMT -8: SEATTLE"; : LOCATE , 48: PRINT "GMT +8: HONG KONG, AND CHINA"
LOCATE , 1: PRINT "GMT -9: ALASKA"; : LOCATE , 48: PRINT "GMT +9: TOKYO"
LOCATE , 1: PRINT "GMT-10: HONOLULU"; : LOCATE , 48: PRINT "GMT+10: SYDNEY"
LOCATE , 1: PRINT "GMT-11: MIDWAY ISLANDS"; : LOCATE , 48: PRINT "GMT+11: SOLOMON ISLANDS"
LOCATE , 48: PRINT "GMT+12: NEW ZEALAND"
PRINT
PRINT STRING$(80, "-")
PRINT "If giving e.g. GMT+1, etc, give as input 1, etc."
PRINT
PRINT "Enter FROM timezone: "; : INPUT "", FTz%
PRINT "Enter GMT" + GA$(LTRIM$(RTRIM$(STR$(FTz%)))) + " respective time as e.g. 14:00: "; : INPUT "", LocalTime$
PRINT : PRINT "Enter TO timezone: "; : INPUT "", TTz%
IF TTz% = -12 THEN TTz% = 12 'As stated, -12 doesn't exist.
'Adjust LocalTime$ from FTz% to TTz%
'------------------------------------
'First we bring LocalTime$ back to GMT:
NLocalTime% = VAL(LEFT$(LocalTime$, 2))
'PRINT NLocalTime%
IF NLocalTime% - FTz% < 0 OR NLocalTime% - FTz% > 24 THEN
IF NLocalTime% - FTz% < 0 THEN
NTTime% = 24 - (NLocalTime% - FTz%)
NDateAdjust = -1
ELSEIF NLocalTime% - FTz% > 24 THEN
NTTime% = (NLocalTime% - FTz%) - 24
NDateAdjust = 1
END IF
ELSE
NTTime% = (NLocalTime% - FTz%)
NDateAdjust = 0
END IF
'Okay, we moved FTz% to GMT, now we gonna move GMT to TTz%
IF NTTime% + TTz% < 0 OR NTTime% + TTz% > 24 THEN
IF NTTime% + TTz% < 0 THEN
TTime% = 24 - (NTTime% + TTz%)
NDateAdjust = -1
ELSEIF NTTime% + TTz% > 24 THEN
TTime% = (NTTime% + TTz%) - 24
NDateAdjust = 1
END IF
ELSE
TTime% = (NTTime% + TTz%)
DateAdjust = 0
END IF
ToTime$ = LTRIM$(RTRIM$(STR$(TTime%))) + ":" + RIGHT$(LocalTime$, 2)
'The DateAdjuster was bugged... can someone help me out on this one?
PRINT
LOCATE , 1: PRINT "TIMEZONES:";
LOCATE , 20: PRINT "COUNTRY/CITY:";
LOCATE , 36: PRINT "LOCAL TIME:";
LOCATE , 50: PRINT "APROX. DATE ADJUST:"
PRINT STRING$(70, "-")
LOCATE , 1: PRINT "FROM: ";
LOCATE , 8: PRINT "GMT" + GA$(LTRIM$(RTRIM$(STR$(FTz%))));
LOCATE , 20: PRINT CC$(FTz%);
LOCATE , 36: PRINT LocalTime$
LOCATE , 1: PRINT "TO:";
LOCATE , 8: PRINT "GMT" + GA$(LTRIM$(RTRIM$(STR$(TTz%))));
LOCATE , 20: PRINT CC$(TTz%);
LOCATE , 36: PRINT ToTime$;
LOCATE , 50: PRINT LTRIM$(RTRIM$(STR$(DateAdjust)))
FUNCTION CC$ (Value AS INTEGER)
IF Value = 12 THEN CC$ = "New Zealand"
IF Value = 11 THEN CC$ = "Solomon Islands"
IF Value = 10 THEN CC$ = "Sydney"
IF Value = 9 THEN CC$ = "Tokyo"
IF Value = 8 THEN CC$ = "Hong Kong, and China"
IF Value = 7 THEN CC$ = "Bangkok"
IF Value = 6 THEN CC$ = "Omsk, Russia"
IF Value = 5 THEN CC$ = "Karachi"
IF Value = 4 THEN CC$ = "Stalingrad"
IF Value = 3 THEN CC$ = "Moscow"
IF Value = 2 THEN CC$ = "Cairo"
IF Value = 1 THEN CC$ = "Berlin"
IF Value = 0 THEN CC$ = "London"
IF Value = -1 THEN CC$ = "Reykjavik"
IF Value = -2 THEN CC$ = "Greenland"
IF Value = -3 THEN CC$ = "Rio de Janeiro, Brazil"
IF Value = -4 THEN CC$ = "Santiago de Chile"
IF Value = -5 THEN CC$ = "New York"
IF Value = -6 THEN CC$ = "Chicago"
IF Value = -7 THEN CC$ = "Denver"
IF Value = -8 THEN CC$ = "Seattle"
IF Value = -9 THEN CC$ = "Alaska"
IF Value = -10 THEN CC$ = "Honolulu"
IF Value = -11 THEN CC$ = "Midway Island"
END FUNCTION
FUNCTION GA$ (Value AS STRING)
IF VAL(Value) > 0 THEN
GA$ = "+" + Value
ELSEIF Value = "0" THEN
GA$ = " " + Value
ELSE
GA$ = Value
END IF
END FUNCTION
FUNCTION Milit$ (Value AS STRING)
IF LEN(Value) < 5 THEN
Milit$ = "0" + Value
END IF
END FUNCTION
I know why you're here. I know what you've been doing... why you hardly sleep, why you live alone, and why night after night, you sit by your computer...<br>
Unfortunately, no one can be told what Qbinux is. You have to see it for yourself.
Unfortunately, no one can be told what Qbinux is. You have to see it for yourself.
Right, the date adjustment is not working yet, it seems to always say 0.SebMcClouth wrote:Hope this helps a bit... there was only a slight problem... the date adjusting...
Anyway, I like you program very much. I like the table of timezones displayed for the user, and I like the neatly formatted output.
It compiled on the first try and ran on the first test. Excellent!
The time of the TO timezone for all the cases that I tested was computed correctly. This is what the program is all about. Great!
I'm not finished testing yet, but so far I noticed the following minor anomalies:
1) the date adjustment as we already mentioned.
2) You didn't validate the input timezones. That's your choice, but it can produce some strange output.
3) You didn't validate the input time (hh:mm). Ditto.
4) When displaying the computed time at the TO timezone, if the time is less than 10:00, it's missing a leading zero, like 9:00 should be 09:00. Without the zero, it could be interpreted as 9:00 pm.
5) On the final output, when the country/city name is too long, like Rio de Janeiro, Brazil, it corrupts the next field (Local Time) with underlay from the excess characters.
*****
If you are ahead of me, lead.
If you are behind me, follow.
If you are not doing anything,
Get out of the way.
If you are behind me, follow.
If you are not doing anything,
Get out of the way.
- SebMcClouth
- Veteran
- Posts: 240
- Joined: Fri Apr 29, 2005 2:20 am
- Location: Inside the Matrix
I'll work on it some more later today. I'll probably have a working version 2night, which I'll post then.
Till then.
grtz
Seb
Till then.
grtz
Seb
I know why you're here. I know what you've been doing... why you hardly sleep, why you live alone, and why night after night, you sit by your computer...<br>
Unfortunately, no one can be told what Qbinux is. You have to see it for yourself.
Unfortunately, no one can be told what Qbinux is. You have to see it for yourself.
- SebMcClouth
- Veteran
- Posts: 240
- Joined: Fri Apr 29, 2005 2:20 am
- Location: Inside the Matrix
Bit later but I actually rewrote the whole math part...
Now it doesn't calculate back to GMT anymore but straight to the desired Timezone, and because of this I was able to rewrite the dateadjust code...
Here goes:
Good luck!
Grtz
Seb
Now it doesn't calculate back to GMT anymore but straight to the desired Timezone, and because of this I was able to rewrite the dateadjust code...
Here goes:
Code: Select all
'(C) 2005, by Sebastian McClouth
DECLARE FUNCTION GA$ (Value AS STRING)
DECLARE FUNCTION Milit$ (Value AS STRING)
DECLARE FUNCTION CC$ (Value AS INTEGER)
CLS
LOCATE , 20: PRINT "Universal TimeZone Calculator"
LOCATE , 20: PRINT "-----------------------------"
LOCATE , 32: PRINT "TIMEZONES:"
LOCATE , 30: PRINT "GMT 0: LONDON"
LOCATE , 1: PRINT "GMT -1: REYKJAVIK"; : LOCATE , 48: PRINT "GMT +1: BERLIN"
LOCATE , 1: PRINT "GMT -2: GREENLAND"; : LOCATE , 48: PRINT "GMT +2: CAIRO"
LOCATE , 1: PRINT "GMT -3: RIO DE JANEIRO, BRAZIL"; : LOCATE , 48: PRINT "GMT +3: MOSCOW"
LOCATE , 1: PRINT "GMT -4: SANTIAGO DE CHILE"; : LOCATE , 48: PRINT "GMT +4: STALINGRAD"
LOCATE , 1: PRINT "GMT -5: NEW YORK"; : LOCATE , 48: PRINT "GMT +5: KARACHI"
LOCATE , 1: PRINT "GMT -6: CHICAGO"; : LOCATE , 48: PRINT "GMT +6: OMSK, RUSSIA"
LOCATE , 1: PRINT "GMT -7: DENVER"; : LOCATE , 48: PRINT "GMT +7: BANGKOK"
LOCATE , 1: PRINT "GMT -8: SEATTLE"; : LOCATE , 48: PRINT "GMT +8: HONG KONG, AND CHINA"
LOCATE , 1: PRINT "GMT -9: ALASKA"; : LOCATE , 48: PRINT "GMT +9: TOKYO"
LOCATE , 1: PRINT "GMT-10: HONOLULU"; : LOCATE , 48: PRINT "GMT+10: SYDNEY"
LOCATE , 1: PRINT "GMT-11: MIDWAY ISLANDS"; : LOCATE , 48: PRINT "GMT+11: SOLOMON ISLANDS"
LOCATE , 48: PRINT "GMT+12: NEW ZEALAND"
PRINT
PRINT STRING$(80, "-")
PRINT "If giving e.g. GMT+1, etc, give as input 1, etc."
PRINT
PRINT "Enter FROM timezone: "; : INPUT "", FTz%
PRINT "Enter GMT" + GA$(LTRIM$(RTRIM$(STR$(FTz%)))) + " respective time as e.g. 14:00: "; : INPUT "", LocalTime$
PRINT : PRINT "Enter TO timezone: "; : INPUT "", TTz%
IF TTz% = -12 THEN TTz% = 12 'As stated, -12 doesn't exist.
'Adjust LocalTime$ from FTz% to TTz%
'------------------------------------
DateAdjust = 0 'Standard. If not changed not adjust.
NTime% = VAL(LEFT$(LocalTime$, 2)) 'Retrieve the hours from LocalTime$
TzToPass% = -FTz% + TTz% 'Get the total timezones to pass
N2Time% = NTime% + TzToPass% 'Calculate the NewTime
PRINT N2Time%;
IF N2Time% < 0 THEN 'If N2Time% goes below zero
NTime% = 24 + N2Time% 'NewTime% = 24 + (-value%)
DateAdjust = -1 'Date needs adjustment
ELSEIF N2Time% > 23 THEN 'If N2Time% goes over 24
NTime% = (23 - N2Time%) 'NewTime% = 0 + (24 - (-value%)
IF NTime% < 0 THEN 'if NewTime% goes under zero
NTime% = -NTime% 'Make it positive
END IF 'Else nothing
DateAdjust = 1 'Date needs adjustment
END IF
'NTime%=NTime% + TzToPass% 'Just here as a code reminder for
'myselfs...
IF LEN(STR$(NTime%)) = 2 THEN 'Adjust hourstring to hourvariable
ToTime$ = "0" + LTRIM$(RTRIM$(STR$(NTime%))) + RIGHT$(LocalTime$, 3)
ELSE
ToTime$ = STR$(NTime%) + RIGHT$(LocalTime$, 3)
END IF
PRINT
LOCATE , 1: PRINT "TIMEZONES:";
LOCATE , 20: PRINT "COUNTRY/CITY:";
LOCATE , 46: PRINT "LOCAL TIME:";
LOCATE , 60: PRINT "APROX. DATE ADJUST:"
PRINT STRING$(80, "-")
LOCATE , 1: PRINT "FROM: ";
LOCATE , 8: PRINT "GMT" + GA$(LTRIM$(RTRIM$(STR$(FTz%))));
LOCATE , 20: PRINT CC$(FTz%);
LOCATE , 46: PRINT LocalTime$
LOCATE , 1: PRINT "TO:";
LOCATE , 8: PRINT "GMT" + GA$(LTRIM$(RTRIM$(STR$(TTz%))));
LOCATE , 20: PRINT CC$(TTz%);
LOCATE , 46: PRINT LTRIM$(RTRIM$(ToTime$));
LOCATE , 60: PRINT LTRIM$(RTRIM$(STR$(DateAdjust)))
FUNCTION CC$ (Value AS INTEGER)
IF Value = 12 THEN CC$ = "New Zealand"
IF Value = 11 THEN CC$ = "Solomon Islands"
IF Value = 10 THEN CC$ = "Sydney"
IF Value = 9 THEN CC$ = "Tokyo"
IF Value = 8 THEN CC$ = "Hong Kong, and China"
IF Value = 7 THEN CC$ = "Bangkok"
IF Value = 6 THEN CC$ = "Omsk, Russia"
IF Value = 5 THEN CC$ = "Karachi"
IF Value = 4 THEN CC$ = "Stalingrad"
IF Value = 3 THEN CC$ = "Moscow"
IF Value = 2 THEN CC$ = "Cairo"
IF Value = 1 THEN CC$ = "Berlin"
IF Value = 0 THEN CC$ = "London"
IF Value = -1 THEN CC$ = "Reykjavik"
IF Value = -2 THEN CC$ = "Greenland"
IF Value = -3 THEN CC$ = "Rio de Janeiro, Brazil"
IF Value = -4 THEN CC$ = "Santiago de Chile"
IF Value = -5 THEN CC$ = "New York"
IF Value = -6 THEN CC$ = "Chicago"
IF Value = -7 THEN CC$ = "Denver"
IF Value = -8 THEN CC$ = "Seattle"
IF Value = -9 THEN CC$ = "Alaska"
IF Value = -10 THEN CC$ = "Honolulu"
IF Value = -11 THEN CC$ = "Midway Island"
END FUNCTION
FUNCTION GA$ (Value AS STRING)
IF VAL(Value) > 0 THEN
GA$ = "+" + Value
ELSEIF Value = "0" THEN
GA$ = " " + Value
ELSE
GA$ = Value
END IF
END FUNCTION
FUNCTION Milit$ (Value AS STRING)
IF LEN(Value) < 5 THEN
Milit$ = "0" + Value
END IF
END FUNCTION
Grtz
Seb
I know why you're here. I know what you've been doing... why you hardly sleep, why you live alone, and why night after night, you sit by your computer...<br>
Unfortunately, no one can be told what Qbinux is. You have to see it for yourself.
Unfortunately, no one can be told what Qbinux is. You have to see it for yourself.
- SebMcClouth
- Veteran
- Posts: 240
- Joined: Fri Apr 29, 2005 2:20 am
- Location: Inside the Matrix
I'm gonna work on these two. And while I'm add it, I'm gonna implent in my core code.moneo wrote:2) You didn't validate the input timezones. That's your choice, but it can produce some strange output.
3) You didn't validate the input time (hh:mm). Ditto.
grtz
Seb
I know why you're here. I know what you've been doing... why you hardly sleep, why you live alone, and why night after night, you sit by your computer...<br>
Unfortunately, no one can be told what Qbinux is. You have to see it for yourself.
Unfortunately, no one can be told what Qbinux is. You have to see it for yourself.
Seb,
When you were fixing it, you must have broken something, 'cause it's not working properly.
Your first version worked fine for calculating the time at the TO timezone. Now, with your new (simplified) logic, there's problems. Do some additional testing.
Keep at it --- you're so close.
*****
When you were fixing it, you must have broken something, 'cause it's not working properly.
Your first version worked fine for calculating the time at the TO timezone. Now, with your new (simplified) logic, there's problems. Do some additional testing.
Keep at it --- you're so close.
*****
If you are ahead of me, lead.
If you are behind me, follow.
If you are not doing anything,
Get out of the way.
If you are behind me, follow.
If you are not doing anything,
Get out of the way.
- SebMcClouth
- Veteran
- Posts: 240
- Joined: Fri Apr 29, 2005 2:20 am
- Location: Inside the Matrix
I've testing it several times... it seemed to work...moneo wrote: Your first version worked fine for calculating the time at the TO timezone. Now, with your new (simplified) logic, there's problems. Do some additional testing.
Reason why I used the simplified is because I had trouble calculating the date adjuster... mh... it give me an idea... I could add some version2 code to version1... you'll see it later on...
mhh... I've done it before...
grtz
BTW this is no code from a book, just from my head and a little help from my gf who happend to be great at mathematics...
I know why you're here. I know what you've been doing... why you hardly sleep, why you live alone, and why night after night, you sit by your computer...<br>
Unfortunately, no one can be told what Qbinux is. You have to see it for yourself.
Unfortunately, no one can be told what Qbinux is. You have to see it for yourself.
There was a slight error in my math, here's the fix:
The error was in the formula which should have been
If it isn't fixed now, let me know.
grtz
Seb
Code: Select all
IF N2Time% < 0 THEN 'If N2Time% goes below zero
NTime% = 23 + N2Time% 'NewTime% = 24 + (-value%)
DateAdjust = -1 'Date needs adjustment
ELSEIF N2Time% > 23 THEN 'If N2Time% goes over 24
NTime% = (23 - N2Time%) 'NewTime% = 0 + (24 - (-value%)
IF NTime% < 0 THEN 'if NewTime% goes under zero
NTime% = -NTime% 'Make it positive
END IF 'Else nothing
DateAdjust = 1 'Date needs adjustment
END IF
Code: Select all
NTime% = 24 + N2Time%
Code: Select all
NTime% = 23 + N2Time%
grtz
Seb
- SebMcClouth
- Veteran
- Posts: 240
- Joined: Fri Apr 29, 2005 2:20 am
- Location: Inside the Matrix
Okay, fixed some more... You try this one... hope it works...
Code: Select all
'(C) 2005, by Sebastian McClouth
DECLARE FUNCTION GA$ (Value AS STRING)
DECLARE FUNCTION Milit$ (Value AS STRING)
DECLARE FUNCTION CC$ (Value AS INTEGER)
CLS
LOCATE , 20: PRINT "Universal TimeZone Calculator"
LOCATE , 20: PRINT "-----------------------------"
LOCATE , 32: PRINT "TIMEZONES:"
LOCATE , 30: PRINT "GMT 0: LONDON"
LOCATE , 1: PRINT "GMT -1: REYKJAVIK"; : LOCATE , 48: PRINT "GMT +1: BERLIN"
LOCATE , 1: PRINT "GMT -2: GREENLAND"; : LOCATE , 48: PRINT "GMT +2: CAIRO"
LOCATE , 1: PRINT "GMT -3: RIO DE JANEIRO, BRAZIL"; : LOCATE , 48: PRINT "GMT +3: MOSCOW"
LOCATE , 1: PRINT "GMT -4: SANTIAGO DE CHILE"; : LOCATE , 48: PRINT "GMT +4: STALINGRAD"
LOCATE , 1: PRINT "GMT -5: NEW YORK"; : LOCATE , 48: PRINT "GMT +5: KARACHI"
LOCATE , 1: PRINT "GMT -6: CHICAGO"; : LOCATE , 48: PRINT "GMT +6: OMSK, RUSSIA"
LOCATE , 1: PRINT "GMT -7: DENVER"; : LOCATE , 48: PRINT "GMT +7: BANGKOK"
LOCATE , 1: PRINT "GMT -8: SEATTLE"; : LOCATE , 48: PRINT "GMT +8: HONG KONG, AND CHINA"
LOCATE , 1: PRINT "GMT -9: ALASKA"; : LOCATE , 48: PRINT "GMT +9: TOKYO"
LOCATE , 1: PRINT "GMT-10: HONOLULU"; : LOCATE , 48: PRINT "GMT+10: SYDNEY"
LOCATE , 1: PRINT "GMT-11: MIDWAY ISLANDS"; : LOCATE , 48: PRINT "GMT+11: SOLOMON ISLANDS"
LOCATE , 48: PRINT "GMT+12: NEW ZEALAND"
PRINT
PRINT STRING$(80, "-")
PRINT "If giving e.g. GMT+1, etc, give as input 1, etc."
PRINT
PRINT "Enter FROM timezone: "; : INPUT "", FTz%
PRINT "Enter GMT" + GA$(LTRIM$(RTRIM$(STR$(FTz%)))) + " respective time as e.g. 14:00: "; : INPUT "", LocalTime$
PRINT : PRINT "Enter TO timezone: "; : INPUT "", TTz%
IF FTz% <= -12 THEN FTz% = 12 'As stated, -12 doesn't exist.
IF FTz% > 12 THEN FTz% = -11 'Not sure if this is correct, but it
IF TTz% <= -12 THEN TTz% = 12 'seems logical.
IF TTz% > 12 THEN TTz% = -11
'Adjust LocalTime$ from FTz% to TTz%
'------------------------------------
DateAdjust = 0 'Standard. If not changed not adjust.
NTime% = VAL(LEFT$(LocalTime$, 2)) 'Retrieve the hours from LocalTime$
TzToPass% = -FTz% + TTz% 'Get the total timezones to pass
N2Time% = NTime% + TzToPass% 'Calculate the NewTime
PRINT N2Time%;
IF N2Time% < 0 THEN 'If N2Time% goes below zero
NTime% = 23 + N2Time% 'NewTime% = 24 + (-value%)
DateAdjust = -1 'Date needs adjustment
ELSEIF N2Time% > 23 THEN 'If N2Time% goes over 24
NTime% = (23 - N2Time%) 'NewTime% = 0 + (24 - (-value%)
IF NTime% < 0 THEN 'if NewTime% goes under zero
NTime% = -NTime% 'Make it positive
END IF 'Else nothing
DateAdjust = 1 'Date needs adjustment
END IF
'NTime%=NTime% + TzToPass% 'Just here as a code reminder for
'myselfs...
IF LEN(STR$(NTime%)) = 2 THEN 'Adjust hourstring to hourvariable
ToTime$ = "0" + LTRIM$(RTRIM$(STR$(NTime%))) + RIGHT$(LocalTime$, 3)
ELSE
ToTime$ = STR$(NTime%) + RIGHT$(LocalTime$, 3)
END IF
PRINT
LOCATE , 1: PRINT "TIMEZONES:";
LOCATE , 20: PRINT "COUNTRY/CITY:";
LOCATE , 46: PRINT "LOCAL TIME:";
LOCATE , 60: PRINT "APROX. DATE ADJUST:"
PRINT STRING$(80, "-")
LOCATE , 1: PRINT "FROM: ";
LOCATE , 8: PRINT "GMT" + GA$(LTRIM$(RTRIM$(STR$(FTz%))));
LOCATE , 20: PRINT CC$(FTz%);
LOCATE , 46: PRINT LocalTime$
LOCATE , 1: PRINT "TO:";
LOCATE , 8: PRINT "GMT" + GA$(LTRIM$(RTRIM$(STR$(TTz%))));
LOCATE , 20: PRINT CC$(TTz%);
LOCATE , 46: PRINT LTRIM$(RTRIM$(ToTime$));
LOCATE , 60: PRINT LTRIM$(RTRIM$(STR$(DateAdjust)))
FUNCTION CC$ (Value AS INTEGER)
IF Value = 12 THEN CC$ = "New Zealand"
IF Value = 11 THEN CC$ = "Solomon Islands"
IF Value = 10 THEN CC$ = "Sydney"
IF Value = 9 THEN CC$ = "Tokyo"
IF Value = 8 THEN CC$ = "Hong Kong, and China"
IF Value = 7 THEN CC$ = "Bangkok"
IF Value = 6 THEN CC$ = "Omsk, Russia"
IF Value = 5 THEN CC$ = "Karachi"
IF Value = 4 THEN CC$ = "Stalingrad"
IF Value = 3 THEN CC$ = "Moscow"
IF Value = 2 THEN CC$ = "Cairo"
IF Value = 1 THEN CC$ = "Berlin"
IF Value = 0 THEN CC$ = "London"
IF Value = -1 THEN CC$ = "Reykjavik"
IF Value = -2 THEN CC$ = "Greenland"
IF Value = -3 THEN CC$ = "Rio de Janeiro, Brazil"
IF Value = -4 THEN CC$ = "Santiago de Chile"
IF Value = -5 THEN CC$ = "New York"
IF Value = -6 THEN CC$ = "Chicago"
IF Value = -7 THEN CC$ = "Denver"
IF Value = -8 THEN CC$ = "Seattle"
IF Value = -9 THEN CC$ = "Alaska"
IF Value = -10 THEN CC$ = "Honolulu"
IF Value = -11 THEN CC$ = "Midway Island"
END FUNCTION
FUNCTION GA$ (Value AS STRING)
IF VAL(Value) > 0 THEN
GA$ = "+" + Value
ELSEIF Value = "0" THEN
GA$ = " " + Value
ELSE
GA$ = Value
END IF
END FUNCTION
FUNCTION Milit$ (Value AS STRING)
IF LEN(Value) < 5 THEN
Milit$ = "0" + Value
END IF
END FUNCTION
I know why you're here. I know what you've been doing... why you hardly sleep, why you live alone, and why night after night, you sit by your computer...<br>
Unfortunately, no one can be told what Qbinux is. You have to see it for yourself.
Unfortunately, no one can be told what Qbinux is. You have to see it for yourself.
Seb,
Your latest version runs but gives the wrong answers.
Examples:
FROM: GMT-5 at 14:00
TO....: GMT+9 says 05:00 (should be 04:00)
FROM: GMT-5 at 01:00
TO....: GMT-3 says 01:00 (should be 03:00)
FROM: GMT-3 at 23:00
TO....: GMT-5 says 23:00 (should be 21:00)
I suggest going back to your original version which worked for the TO time, and then try to modify it to figure the date adjustment.
*****
Your latest version runs but gives the wrong answers.
Examples:
FROM: GMT-5 at 14:00
TO....: GMT+9 says 05:00 (should be 04:00)
FROM: GMT-5 at 01:00
TO....: GMT-3 says 01:00 (should be 03:00)
FROM: GMT-3 at 23:00
TO....: GMT-5 says 23:00 (should be 21:00)
I suggest going back to your original version which worked for the TO time, and then try to modify it to figure the date adjustment.
*****
If you are ahead of me, lead.
If you are behind me, follow.
If you are not doing anything,
Get out of the way.
If you are behind me, follow.
If you are not doing anything,
Get out of the way.