Page 1 of 1 1
Topic Options
#15283 - 2001-12-18 03:15 PM GMT Time
jechilt Offline
Starting to like KiXtart

Registered: 2000-12-01
Posts: 102
Loc: Denver Colorado
is there any way to capture GMT Time?
my machine is in the EST time zone, but for my record compilation, I need GMT time.

any suggestions are welcome! jecmail@fastmail.fm

_________________________
John
LM Contractor
One of the 2 dads

Top
#15284 - 2001-12-18 03:56 PM Re: GMT Time
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
I thought we'd get lucky and be able to use Jen's UDF called SerialTime() ... take the current time as a number, than add the GMT bias from registry timezone info :


break on


$BIAS = 0 + readvalue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation","Bias")


? "GMT=" serialtime(serialtime(@TIME)+($BIAS*60))


exit


function serialtime($strtime)
dim $hours, $minutes, $seconds, $serial, $error
$error
if instr($strtime,':')<instrrev($strtime,':')
if len($strtime)>4 and len($strtime)< 9
$hours=val(left($strtime,instr($strtime,':')-1))
if $hours>23
$error=1
endif
$minutes=val(substr($strtime,instr($strtime,':')+1,instrrev($strtime,':')-instr($strtime,':')-1))
if $minutes>59
$error=1
endif
$seconds=val(right($strtime,len($strtime)-instrrev($strtime,':')))
if $seconds>59
$error=1
endif
$serial=($hours*3600)+($minutes*60)+$seconds
if $serial>86399
$error=1
endif
if $error
$serialtime='-1'
else
$serialtime=$serial
endif
else
$serialtime = '-1'
endif
else
$strtime=val($strtime)
if $strtime<=86399 and $strtime>=0
$hours=$strtime/3600
$strtime=$strtime-($hours*3600)
$hours=right('00'+$hours,2)
$minutes=$strtime/60
$strtime=$strtime-($minutes*60)
$minutes=right('00'+$minutes,2)
$seconds=$strtime
$seconds=right('00'+$seconds,2)
$serialtime=$hours+':'+$minutes+':'+$seconds
else
$serialtime='-1'
endif
endif
endfunction


The problem is that if you add say 22:00:00 hrs + 05:00:00 hours, the function doesn't wrap around to the "next day" so to speak ... it returns a -1. Now if Jens could see his way clear to modify the UDF (if it make sense to do so), that would be cool ... coming out of this with a GMT() UDF would be very nice !

-Shawn

Top
#15285 - 2001-12-18 04:15 PM Re: GMT Time
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Shawn:

What exactly are the requirements for the UDF?

Right now, the SerialTime() UDF is designed to convert times into seconds (milliseconds) since midnight. Therefore, it doesn't care about dates.

Anyway, since I already have a SerialTime() and SerialDate() UDF, I will think about writing a new DateMath() wrapping function that correctly does date/time calculations.

It might take me a while since I decided to post my login script including all UDFs for everybody's perusal. So, that'll keep me busy for the next day or two.

Stay tuned!

_________________________
There are two types of vessels, submarines and targets.

Top
#15286 - 2001-12-18 04:34 PM Re: GMT Time
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Jens,

Not too sure actually what the requirements would be .... two things come to mind.

1) Time math like this:

$time = serialtime(serialtime("23:00:00")+serialtime("05:00:00"))

$time would equal "04:00:00" ???

2) A GMT function, eg:

$time = GMT(@TIME)

or:

$time = GMT("09:00:00") ; est

and:

$time would equal 14:00:00 (for me anyway)

-Shawn

p.s. If none of this makes any sense - no worries - i'm just flinging stuff around to see if anything sticks [shrug] won't hurt my feelings if you say none of this stuff would ever get used in the real world ... the GMT function might though ...

[ 18 December 2001: Message edited by: Shawn ]

Top
#15287 - 2001-12-18 07:05 PM Re: GMT Time
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Shawn:

If you want just a GMT function, that'll be easy. I've already an idea how to do it, it'll be pretty simple, actually. With regards to a more general date/time math function, I'll have to do some brainstorming about this.

_________________________
There are two types of vessels, submarines and targets.

Top
#15288 - 2001-12-18 07:58 PM Re: GMT Time
jechilt Offline
Starting to like KiXtart

Registered: 2000-12-01
Posts: 102
Loc: Denver Colorado
We need to keep at least one point in mind.

1. Adding 'x' hours to a time zone to result GMT time will not take into consideration daylight savings time.

I am able to pull GMT using PERL. PERL can retrieve time with localtime(time) or gmtime(time). However, to pass the variable is more challenging.
In the end, it would be nice if Kix could find a variable that would extract GMT time. For example, @time provides time that local machine is running. @gmtime could provide time based on GMT.
Hmmmmmm? and keep it under 200 lines of code?

thanks for the input so far.

john

_________________________
John
LM Contractor
One of the 2 dads

Top
#15289 - 2001-12-18 11:07 PM Re: GMT Time
bleonard Offline
Seasoned Scripter
*****

Registered: 2001-01-19
Posts: 581
Loc: Chicago, IL
One method that may work is below. And I kept it under 200 lines
Bill

code:

$Time = @TIME
$ClkHr = VAL (SUBSTR ($Time, 1, 2)) ; REM ** Parse HOUR value
$ClkMin = VAL (SUBSTR ($Time, 4, 2)) ; REM ** Parse MINUTE value


$Bias = READVALUE ("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation", "ActiveTimeBias")
$Name = READVALUE ("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation", "StandardName")
$GmtVal = READVALUE ("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Time Zones\$Name", "Display")


; REM ** Clock set to adjust for DayLight Savings Time.
IF ($Bias <> "0")
$BiasVal = VAL ("$Bias")
$OffSet = SUBSTR ("$GmtVal", 5, 1) ; REM ** Does local clock add or subtract time from GMT?
IF ($OffSet <> "+") AND ($OffSet <> "-")
? "Time zone is already Greenwich Mean Time"
GOTO EndScript
ENDIF
ENDIF


SELECT
CASE ($BiasVal = "+780") OR ($BiasVal = "-780") $AdjHr = 13 $AdjMin = 0 ; REM ** Plus/minus 13 hours
CASE ($BiasVal = "+720") OR ($BiasVal = "-720") $AdjHr = 12 $AdjMin = 0 ; REM ** Plus/minus 12 hours
CASE ($BiasVal = "+660") OR ($BiasVal = "-660") $AdjHr = 11 $AdjMin = 0 ; REM ** Plus/minus 11 hours
CASE ($BiasVal = "+600") OR ($BiasVal = "-600") $AdjHr = 10 $AdjMin = 0 ; REM ** Plus/minus 10 hours
CASE ($BiasVal = "+570") OR ($BiasVal = "-570") $AdjHr = 9 $AdjMin = 30 ; REM ** Plus/minus 9 hours, 30min
CASE ($BiasVal = "+540") OR ($BiasVal = "-540") $AdjHr = 9 $AdjMin = 0 ; REM ** Plus/minus 9 hours
CASE ($BiasVal = "+480") OR ($BiasVal = "-480") $AdjHr = 8 $AdjMin = 0 ; REM ** Plus/minus 8 hours
CASE ($BiasVal = "+450") OR ($BiasVal = "-450") $AdjHr = 7 $AdjMin = 30 ; REM ** Plus/minus 7 hours, 30min
CASE ($BiasVal = "+420") OR ($BiasVal = "-420") $AdjHr = 7 $AdjMin = 0 ; REM ** Plus/minus 7 hours
CASE ($BiasVal = "+390") OR ($BiasVal = "-390") $AdjHr = 6 $AdjMin = 30 ; REM ** Plus/minus 6 hours, 30min
CASE ($BiasVal = "+360") OR ($BiasVal = "-360") $AdjHr = 6 $AdjMin = 0 ; REM ** Plus/minus 6 hours
CASE ($BiasVal = "+345") OR ($BiasVal = "-345") $AdjHr = 5 $AdjMin = 45 ; REM ** Plus/minus 5 hours, 45min
CASE ($BiasVal = "+330") OR ($BiasVal = "-330") $AdjHr = 5 $AdjMin = 30 ; REM ** Plus/minus 5 hours, 30min
CASE ($BiasVal = "+300") OR ($BiasVal = "-300") $AdjHr = 5 $AdjMin = 0 ; REM ** Plus/minus 5 hours
CASE ($BiasVal = "+270") OR ($BiasVal = "-270") $AdjHr = 4 $AdjMin = 30 ; REM ** Plus/minus 4 hours, 30min
CASE ($BiasVal = "+240") OR ($BiasVal = "-240") $AdjHr = 4 $AdjMin = 0 ; REM ** Plus/minus 4 hours
CASE ($BiasVal = "+210") OR ($BiasVal = "-210") $AdjHr = 3 $AdjMin = 30 ; REM ** Plus/minus 3 hours, 30min
CASE ($BiasVal = "+180") OR ($BiasVal = "-180") $AdjHr = 3 $AdjMin = 0 ; REM ** Plus/minus 3 hours
CASE ($BiasVal = "+150") OR ($BiasVal = "-150") $AdjHr = 2 $AdjMin = 30 ; REM ** Plus/minus 2 hours, 30min
CASE ($BiasVal = "+120") OR ($BiasVal = "-120") $AdjHr = 2 $AdjMin = 0 ; REM ** Plus/minus 2 hours
CASE ($BiasVal = "+60") OR ($BiasVal = "-60") $AdjHr = 1 $AdjMin = 0 ; REM ** Plus/minus 1 hour
CASE ($BiasVal = "+0") OR ($BiasVal = "-0") $AdjHr = 0 $AdjMin = 0 ; REM ** Plus/minus 0 hours
ENDSELECT


IF ($OffSet = "-")
IF ($AdjMin > $ClkMin) $GmtMin = 60 - ($AdjMin - $ClkMin) $AdjHr = $AdjHr + 1
ELSE $GmtMin = ($ClkMin - $AdjMin)
ENDIF
IF ($AdjHr > $ClkHr) $GmtHr = 24 - ($AdjHr - $ClkHr)
ELSE $GmtHr = ($ClkHr - $AdjHr)
ENDIF
ELSE
IF ($AdjMin + $ClkMin) > 60 $GmtMin = 60 - ($AdjMin + ClkMin) $AdjHr = $AdjHr - 1
ELSE $GmtMin = ($AdjMin + ClkMin)
ENDIF
IF ($AdjHr + $ClkHr) > 24 $GmtHr = 24 - ($AdjHr + $ClkHr)
ELSE $GmtHr = ($AdjHr + $ClkHr)
ENDIF
ENDIF


:EndScript



Top
#15290 - 2001-12-19 05:19 PM Re: GMT Time
jechilt Offline
Starting to like KiXtart

Registered: 2000-12-01
Posts: 102
Loc: Denver Colorado
iii-yiiiiii-yiiiiiii-yiiiiiii-yiiiiiii

i will give it a spin and let you know how it pans out...

john

_________________________
John
LM Contractor
One of the 2 dads

Top
#15291 - 2001-12-19 06:18 PM Re: GMT Time
bleonard Offline
Seasoned Scripter
*****

Registered: 2001-01-19
Posts: 581
Loc: Chicago, IL
Forgot to note - the 30/45min selections came from my workstation clock values, and are all time zones noted by Microsoft operating system. These are time offsets outside N. America except New Foundland (-3:30). Certainly N. American users can trim the case selection list down to their needs, just as Europeans/Asians can trim off items not applicable to them. Folks in the US would only require hour offsets of -4 hours (Eastern including Daylight Savings) to -8 hours for Pacific (-9 for Alaska, -10 for Hawaii).

Bil

Top
#15292 - 2001-12-19 06:51 PM Re: GMT Time
jechilt Offline
Starting to like KiXtart

Registered: 2000-12-01
Posts: 102
Loc: Denver Colorado
got a problem...
have you run this on your machine?

READVALUE for $Name and $GmtVal are not returning any value.

$Name and $GmtVal are REG_NONE type keys. I am not sure if READVALUE can read the key, since READVALUE only makes reference to REG_MULTI_SZ and REG_DWORD.
The $Bias is being read fine. It is a REG_DWORD key.

My next question would be, what variable from the script can we pass to another script to call the GMT time?

thanks!

_________________________
John
LM Contractor
One of the 2 dads

Top
#15293 - 2001-12-19 07:40 PM Re: GMT Time
bleonard Offline
Seasoned Scripter
*****

Registered: 2001-01-19
Posts: 581
Loc: Chicago, IL
Yes, I ran this on my Win2K system when creating this script. Recommend checking the registry to confirm these keys exist/are accessible to you. Perhaps, though I am not sure, it may be an issue with local user rights in seeing these keys. Since not all users can adjust the clock of a WinNT/2K system, the user id you are testing with may be restricted in this manner. Check User Manager, User Rights, Change the System Time entry to confirm for your network.

FYI - a quick check of a WinNT system also shows the presence of these keys.

As for these being 'REG_NONE', I an not sure of your point, except perhaps this indicates the possible security restrictions I noted above.

As for variable to send to another script - I assume you want a variable that reflects GMT time in comparison with the local workstation time. That could be something like: $PassGMT = $GmtHr + ":" + $GmtMin + ":" + $ChkSec (a variable not parsed in original version of script I posted but you can add. There is no point in adjusting this value seperately as GMT offsets do not account for seconds). $PassGMT should look like: 09:23:37. I have not tested this.

Of course, the accuracy of $PassGMT is only as good as the accuracy of the local workstation clock. If the GMT time is very important, you also require a good time server to keep accurate time that can be checked at every login (or perhaps more frequently) by each workstation so the local clock can be synchronized. The time server will need to check with authoritative source such as U.S. Naval atomic clock, etc.

Also, if your company has offices in multiple time zones you must confirm each workstation properly set for the correct time zone, and authenticates against time server within its time zone. If systems configured centrally and distributed nationally, possibly time zones improperly set to configuration center time zone.

Bill

Top
#15294 - 2001-12-19 08:36 PM Re: GMT Time
jechilt Offline
Starting to like KiXtart

Registered: 2000-12-01
Posts: 102
Loc: Denver Colorado
Bill,

thanks for the explanation.
the system the script runs on is a server.
I have full administration rights, so I do not think we are dealing with a permission issue. I will continue to look into this...

we run win32Time and have our own NTP sources that get time from an atomic clock.
our servers are in different time zones, but should not be an issue because they all use the same time source...

thanks!!!
john

_________________________
John
LM Contractor
One of the 2 dads

Top
#15295 - 2001-12-20 01:16 AM Re: GMT Time
kholm Offline
Korg Regular
*****

Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
Function to get GMT time from local time

code:

Function GMT_Time($Time)
; Returns GMT time from local time
; Also return Global var: $GMTDay (-1 = Yesterday, 0 = Today, 1 = Tomorrow)
Dim $Min,$Sec,$Bias,$Tmp,$H,$M
Global $GMTDay
$GMTDay = 0
$Min = Val(Left($Time, 2)) * 60 + Val(SubStr($Time, 4, 2))
$Sec = Right($Time, 3)
$Tmp = ReadValue("HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation","ActiveTimeBias")
If ReadType("HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation","ActiveTimeBias") = "REG_BINARY"
For $i = Len($Tmp) - 1 To 1 Step - 2 ; Reverse binary string to Hex string (Win 9x)
$Bias = "" + $Bias + SubStr($Tmp, $i, 2)
Next
$Bias = Val("&" + $Bias)
Else
$Bias = Val($Tmp)
EndIf
If $Bias = 0
$GMT_Time = $Time
Return
EndIf
$GMT_Chg = $Min + $Bias
Select
Case $GMT_Chg >= 60 * 24
$GMT_Chg = $GMT_Chg - 60 * 24
$GMTDay = 1 ; Tomorrow in G
Case $GMT_Chg <= 0
$GMT_Chg = $GMT_Chg + 60 * 24
$GMTDay = -1 ; Yesterday in G
EndSelect
$H = $GMT_Chg / 60
$M = "" + ($GMT_Chg - $H * 60)
If Len($M) = 1
$M = "0" + $M
EndIf
$H = "" + $H
If Len($H) = 1
$H = "0" + $H
EndIf
$GMT_Time = $H + ":" + $M + $Sec
EndFunction

For GMT Date/time look in: GMT_DateTime - Transform local time to GMT (date and) time

-Erik

Top
#15296 - 2001-12-20 01:24 AM Re: GMT Time
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
C:\>time
Current time is 6:24:38.31p
Enter new time:

C:\> kix32 gmt

23:24:38

very nice. well done.

-Shawn

Top
#15297 - 2001-12-20 01:30 AM Re: GMT Time
jechilt Offline
Starting to like KiXtart

Registered: 2000-12-01
Posts: 102
Loc: Denver Colorado
holy smokes.....you guys 'are' good!

Thanks for the help. I will give this a spin!

john

_________________________
John
LM Contractor
One of the 2 dads

Top
#15298 - 2001-12-20 02:37 AM Re: GMT Time
kholm Offline
Korg Regular
*****

Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
John,
The function GMT_Time() should include daylight savings time!

Tested on Win95/Win98/WinNT

Bill, Shawn and Einstein : Time is relative

Shawn,
You are the master of explaing in few words, thank you for testing

-Erik

Top
#15299 - 2001-12-20 02:45 AM Re: GMT Time
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Erik

If theres one thing I thought that I was *NOT* known for - and that is explaining in a few words

I've been waiting to test the next piece (wrap-around) :

C:\>time
Current time is 7:44:26.99p
Enter new time:

C:\>kix32 gmt

00:44:33
C:\>

yup - doesn't get any better than that !

-Shawn

[ 20 December 2001: Message edited by: Shawn ]

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 661 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.068 seconds in which 0.025 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org