mIRC Home    About    Download    Register    News    Help

Print Thread
#198505 29/04/08 09:21 PM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline OP
Hoopy frood
OP Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Hi there,
I just got stuck trying to return the *offset* between local time ($ctime) and the networks time (/time reply)

Example: raw 391 returns:
<Mynick> <TheServer> Tuesday April 29 2008 -- 15:57 -05:00
My $asctime was:
Tue Apr 29 22:57:48 2008
My $asctime(zzz) was:
+0100 GMT

I tried something messy to return a "server ctime":
$calc($ctime($gettok($1-,3-6,32) $gettok($1-,8,32)) - $duration($+($gettok($1-,9,32),:00)) - $calc($gmt - $ctime))
Now, this returns an offset of 1hr to my local $ctime.
Do I err? And/or is there a better way to calc this difference out of that raw reply?

ty smile


Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Code:
raw 391:*:{
  var %gmt = $calc($ctime($4-6 $8) - $duration($9 $+ :00))
}


From there you have a UTC "ctime" value of the server's current time to do with as you will.

I think the problem with your code is that $gmt isn't truly GMT - it includes daylight savings so you need to use $daylight to account for it. Or something. I dunno, mIRC's time identifiers seem badly messed up to me.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline OP
Hoopy frood
OP Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
You're right, I don't need to take account of my 'own' gmt there.

Offsetting relative vs absolute times is always a worry to me...
e.g.: whowas returns a value formatted like $time(ddd mmm dd HH:nn:ss yyyy) - without info about server's gmt, or the like - Suppose I have to (at least want to) check the gmt of /time plus my own offset to the server to get the "true" time passed.
On the other hand side, $ibl for example (and the accordant raws) already "took" gmt into account (thus, some $calc($ctime - $ibl(#,N).time +offset without gmt).
Struggling ("arf! $daylight, too?"),

Thanks a lot

Last edited by Horstl; 29/04/08 10:48 PM.
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline OP
Hoopy frood
OP Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Looks like I worked it out.
(It's not even worth a snippet - just FYI or if there's a better approach...)

Code:
; of course, this could be shortened
RAW 391:*: {
  ; "servers local" time
  var %s.local = $ctime($4-6 $8)
  ; "servers global" time (- servers gmt)
  var %s.global = $calc(%s.local - $duration($9 $+ :00))
  ; "own local" time with padded seconds
  var %o.local = $calc($floor($calc($ctime /60)) *60)
  ; "own global" time (padded local time - daylight - own gmt)
  var %o.global = $calc(%o.local - $daylight - $calc($ctime - $gmt))

  ; offset "servers global" - "own global"
  set -e %g.offset $calc(%s.global - %o.global)
  ; offset "server local" - "own local"
  set -e %l.offset $calc(%s.local - %o.local)
}

Thus, if you'd set your local time to x, the age of a ban in your absence is none the less calculated correct with something like:
Code:
$duration($calc($ctime - $ibl(#,N).ctime + %g.offset))
And a whowas reply may be parsed e.g. :
Code:
raw 312:*: { 
  echo -a server saw $2 at $4-
  echo -a this represents a local time of: $asctime($calc($ctime($4-) - %l.offset))
  echo -a it happened $duration($calc($ctime - $ctime($4-) + %l.offset)) ago
}



Link Copied to Clipboard