Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Time zone offset for script 1

Status
Not open for further replies.

phonejack99

Technical User
Jul 21, 2003
156
US
Using the basic get time from my pc and rest that time on a Nortel pbx any ideas how I could modify script to adjust for time zone differences, i.e, I'm in central time could I have a script that is plus 1 hour for ET and minus 2 for pacific time?

Thank you for any assistance/guidance!!!!!!!!

Jack

Here is the script --

proc main
integer iDay, iMonth, iYear, iMin, iHour, iSec
string sSend

ltimeints $LTIME iYear iMonth iDay iHour iMin iSec

strfmt sSend "STAD %02d %02d %d %02d %02d %02d" iDay iMonth iYear iHour iMin iSec
set txpace 30
transmit "****^M"
waitfor ">"
transmit "ld 2^M"
waitfor "."
transmit "TTAD^M"
waitfor "."
transmit sSend
transmit "^M"
waitfor "."
pause 2
transmit "TTAD^M"
waitfor "."
pause 2
transmit "****^M"

set txpace 0

Endproc
 
Jack (please advise me if I'm wrong here Knob)

If I understand correctly - the PC which you are getting the time from will always be in Central Time, no? It is the PBX's you are calling which reside in different time zones. If this is the case, all you really need to do is modify the time you are sending to each PBX. You should be able to simply adjust the iTime variable before you format it into the sSend string.

Below is an example using a separate process with the parameter iZone. You call the ‘sendtime’ process and pass it whichever iZone parameter you need for each PBX’s time zone. You can recall the process for each PBX, each time sending it the appropriate time zone.

This is just one idea - again, assuming I understand what you are trying to do here…. Hope it helps a little at least.
------------------------------------------------------------

proc main
sendtime(2) ;send a 0 for Central Time, 1 for Eastern, or 2 for Pacific
endproc


proc sendtime
param integer iZone ;accepts the 0, 1, or 2 sent from procmain

integer iDay, iMonth, iYear, iMin, iHour, iSec
string sSend
ltimeints $LTIME iYear iMonth iDay iHour iMin iSec


if (iZone == 1) ;if a 1 was sent from procmain,
iHour = iHour + 1 ;then add 1 to iHour for Eastern time
endif


if (iZone == 2) ;or if a 2 was sent,
iHour = iHour - 2 ;then subtract 2 from iHour for Pacific time
endif

strfmt sSend "STAD %02d %02d %d %02d %02d %02d" iDay iMonth iYear iHour iMin iSec

set txpace 30
transmit "****^M"
waitfor ">"
transmit "ld 2^M"
waitfor "."
transmit "TTAD^M"
waitfor "."
transmit sSend
transmit "^M"
waitfor "."
pause 2
transmit "TTAD^M"
waitfor "."
pause 2
transmit "****^M"

set txpace 0

endproc
 
Jack,

I wrote some code that would read the time from a DMS, sample the current PC time, and calculate an offset in seconds.

My needs were different. I was trying to "sync" the PC to the DMS in order to perform certain tasks at very specific DMS times.

This code allowed the PC to be located in any timezone, and automatically adjust the tasks to match the local switch time regardless of where the switch was located. I was able to use a single PC to communicate with multiple switches in different time zones and have the PC perform the tasks at the correct time for each switch.

You may need to build a "reference list" of the various switches and store the associated time zone offset. If you can "lookup" a switch ID on the list, your code can make the time of day adjustments. I know it's a pain to maintain, but nothing else jumps to mind.

Putz
 
STLEddie,

You are 100% correct on what I am looking for.

If I'm reading the script correctly the send time variable from procedure main as script is now will down the -2 hour offset from central time, which is perfect!!

Short of editing the file/script before each use is there a way to have the script "ask" for the variable before it is run.

Thank you again for your assistance!!

Jack
 
Try this. Once you dial in and run the script, a dialog box will pop up asking you to select the time zone. Your response will increase/decrease the iHour variable accordingly. (it would be a better written script if you substitute case statements for the if/endif's – but this works and is pretty simple to follow).

Hope this helps! Eddie

----------------------------------------------------

proc main
string sList, sZone
integer iEvent, iZone

dialogbox 0 130 130 127 110 2 "Select Time Zone"
text 1 15 10 100 8 "Time Zone:" left
listbox 2 15 25 96 42 sList SINGLE sZone ;sZone returns text of choice
pushbutton 3 15 80 42 14 "&OK" DEFAULT
pushbutton 4 69 80 42 14 "&Cancel"
enddialog

dlglist 0 2 INSERT "Pacific Time"
dlglist 0 2 INSERT "Mountain Time"
dlglist 0 2 INSERT "Central Time"
dlglist 0 2 INSERT "Eastern Time"

while 1
dlgevent 0 iEvent
switch iEvent
case -1
exit
case 3 ;OK button is chosen
if strFind sZone "Pacific Time"
iZone = 1
endif
if strFind sZone "Mountain Time"
iZone = 2
endif
if strFind sZone "Central Time"
iZone = 3
endif
if strFind sZone "Eastern Time"
iZone = 4
endif
exitwhile
endcase
case 4 ;Cancel button is chosen
exit
endcase
endswitch
endwhile
dlgdestroy 0 CANCEL
sendtime(iZone) ;send a 0 for Central Time, 1 for Eastern, or 2 for Pacific

endproc


proc sendtime
param integer iZone ;accepts the 0, 1, or 2 sent from procmain

integer iDay, iMonth, iYear, iMin, iHour, iSec
string sSend
ltimeints $LTIME iYear iMonth iDay iHour iMin iSec

if (iZone == 1) ;if a 1 was sent from procmain,
iHour = iHour - 2 ;then subtract 2 from iHour for Pacific
endif

if (iZone == 2) ;or if a 2 was sent,
iHour = iHour - 1 ;then subtract 1 from iHour for Mountain
endif

;no action needed where iZone == 3

if (iZone == 4) ;or if a 4 was sent,
iHour = iHour + 1 ;then add 1 to iHour for Pacific time
endif

strfmt sSend "STAD %02d %02d %d %02d %02d %02d" iDay iMonth iYear iHour iMin iSec

set txpace 30
transmit "****^M"
waitfor ">"
transmit "ld 2^M"
waitfor "."
transmit "TTAD^M"
waitfor "."
transmit sSend
transmit "^M"
waitfor "."
pause 2
transmit "TTAD^M"
waitfor "."
pause 2
transmit "****^M"

set txpace 0

endproc
 
Correction:

if (iZone == 4) ;or if a 4 was sent,
iHour = iHour + 1 ;then add 1 to iHour for Eastern time
endif

...hey, when you cut and paste enough, you are bound to miss things. Anyway, if I missed anything else and you have a problem compiling or running - just let me know.
 
Eddie,

Thank you!!!!!!!!!!!!!!

This is the bomb!!!!!!!!!!!!!!!!!!!!!

Jack
 
Glad I could help.

The only thing you need to watch is that you don’t run this too close to midnight. If you do, you will need to make adjustments for the fact that the date, month, and even year could be different.

For example, at 01:00 central, if you subtract 2 from iHour, you will get a –1. You will need more equations in the script to change the –1 into 23, and decrease the day by 1 (since you are going from 01:00 today to 23:00 yesterday). Also, if you are on the first day of the month (or even worse, Jan 1), you now have to change the day, month, and year – (since at 01:00 1-1-2006, going back 2 hours takes you to 23:00 on 12-31-2005).

So, if you only run this during the day, you will be fine. Just be advised it gets trickier close to midnight.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top