mIRC Home    About    Download    Register    News    Help

Print Thread
#188330 21/10/07 12:01 PM
Joined: Apr 2006
Posts: 464
O
Fjord artisan
OP Offline
Fjord artisan
O
Joined: Apr 2006
Posts: 464
I want to have a world clock function on my bot.
It should return the current time in some major cities around the world. Like New York, London, Sydney etc.

I've started by creating this little alias:
Code:
alias world-clock {
  var %amsterdam = $time(HH:nn:ss)
  echo -a 05Amsterdam, NL:07 %amsterdam
}

But I'm already stuck when I need to calculate another locations time.

Does anyone already have something like this?
Or what would be a fancy way of making this?

Thanks in advance!

OrionsBelt #188332 21/10/07 12:20 PM
Joined: Jun 2006
Posts: 508
D
Fjord artisan
Offline
Fjord artisan
D
Joined: Jun 2006
Posts: 508
You'd need to know the difference between GMT (or your local timezone) and the timezone of where you wanted, and add/subtract that from $gmt (or $ctime if you use your local timezone)
Bear in mind too, that daylight savings will play a part on both ends of the equation. For your own timezone you can use $daylight to offset that.

Example: Anchorage, Alaska, is GMT -9 hours, plus 1 hour (DST). (GMT -9 +1) = GMT - 8(hours)
//echo -a Anchorage, Alaska: $time($calc($gmt - (8 * 60 * 60)),HH:nn:ss)


deegee #188334 21/10/07 12:48 PM
Joined: Apr 2006
Posts: 464
O
Fjord artisan
OP Offline
Fjord artisan
O
Joined: Apr 2006
Posts: 464
Thanks for that deegee.
I now have:
Code:
alias world-clock {
  var %gmt = $asctime($calc($gmt - $daylight),HH:nn:ss)
  var %amsterdam = $time(HH:nn:ss)
  var %new-york = $asctime($calc($gmt - 14400 - $daylight),HH:nn:ss)

  echo -a 07 $+ %gmt 05GMT -07 %amsterdam 05Amsterdam-NL -07 %new-york 05New-York-USA.
}


This returns:
12:45:12 GMT - 14:45:12 Amsterdam-NL - 08:45:12 New-York-USA.

Is this the way forward?
With daylight savind taken into account?

Thanks again smile

OrionsBelt #188335 21/10/07 01:06 PM
Joined: Jun 2006
Posts: 508
D
Fjord artisan
Offline
Fjord artisan
D
Joined: Jun 2006
Posts: 508
Well, the $daylight is relative to your own timezone, not to others. Your times there appear pretty right, as both Amsterdam and NY have DST in effect. If you try that with a zone that has no DST you'll be wrong by your DST offset, I think.


deegee #188339 21/10/07 01:57 PM
Joined: Apr 2006
Posts: 464
O
Fjord artisan
OP Offline
Fjord artisan
O
Joined: Apr 2006
Posts: 464
Aight, well I added Sydney, which doesn't have DST in effect:

Code:
alias world-clock {
  var %gmt = $asctime($calc($gmt - $daylight),HH:nn)
  var %amsterdam = $asctime($calc($gmt + 7200 - $daylight),HH:nn)
  var %new-york = $asctime($calc($gmt - 14400 - $daylight),HH:nn)
  var %sydney = $asctime($calc($gmt + 36000 - $daylight),HH:nn)

  echo -a 07 $+ %gmt 05GMT -07 %amsterdam 05Amsterdam-NL -07 %new-york 05New-York-USA -07 %sydney 05Sydney-AUS.
}


13:55 GMT - 15:55 Amsterdam-NL - 09:55 New-York-USA - 23:55 Sydney-AUS.
This seems to be correct also, so I think I can do this for any other city as well.

Thanks very mucho laugh


Link Copied to Clipboard