mIRC Home    About    Download    Register    News    Help

Print Thread
$ctime does not accept timezones #247685 20/08/14 06:07 PM
Joined: Apr 2010
Posts: 943
F
FroggieDaFrog Offline OP
Hoopy frood
OP Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 943
Im not sure if this should be listed as a bug or feature request but...

$ctime(date) does not take into account a specified timezone, or its variants:

Code:
; This should have a 3600 second offset
//echo -a $calc($ctime(2014-08-20 18:00:00 BST) - $ctime(2014-08-20 18:00:00 GMT))

; $ctime(2014-08-20 18:00:00 +0100)
; $ctime(2014-08-20 18:00:00 +01:00)
; $ctime(2014-08-20 18:00:00 GMT+1)
; $ctime(2014-08-20 18:00:00 +0100 GMT+1)


After further investigation, $ctime (without parameters) does take into account timezone(and DST), leading me to assume this is a bug "oversight/failed to implement"

Last edited by FroggieDaFrog; 20/08/14 06:33 PM.

I am SReject
My Stuff
Re: $ctime does not accept timezones [Re: FroggieDaFrog] #247689 20/08/14 10:53 PM
Joined: Aug 2014
Posts: 3
F
fncwill Offline
Self-satisified door
Offline
Self-satisified door
F
Joined: Aug 2014
Posts: 3
I had a hard time when doing mine Time script for my IRC channel , but here's what I did to get timezones to work . Hopefully this is what your looking for , or can help you smile

Typing !Time followed by the abbreviated time code will give you that current timezones time
Example : !Time PST

Accepted TimeZones : IDLW NT HST CAT AHST YST AKST PST AKDT PDT MST MDT CST EST CDT AST NST ADT NDT AT WAT IDLE NZST NFT AEDT ACDT AEST GST ACST AWDT JST AWST CCT WST CXT MSD MSK BT EEDT EEST EET CEDT CEST CET DST BST IST WEDT WEST WET UTC UT GMT



Code:
on *:TEXT:!time*:#:tzone $2 $chan

alias tzone {
  var %w = -12&-11&-10&-10&-10&-9&-9&-8&-8&-7&-7&-6&-6&-5&-5&-4&-3.5&-3&-2.5&-2&-1&+12&+12&11.5&+11&+10.5&+10&+10&+9.5&+9&+9&+8&+8+8&&+7&+4&+3&+3&+3&+3&+2&+2&+2&+1&+1&+1&+1&+1&+1&0&0&0&0
  var %x = IDLW NT HST CAT AHST YST AKST PST AKDT PDT MST MDT CST EST CDT AST NST ADT NDT AT WAT IDLE NZST NFT AEDT ACDT AEST GST ACST AWDT JST AWST CCT WST CXT MSD MSK BT EEDT EEST EET CEDT CEST CET DST BST IST WEDT WEST WET UTC UT GMT
  var %y = International Date Line West.Nome.Hawaii Standard.Central Alaska.Alaska-Hawaii Standard.Yukon Standard.Alaska Standard.Pacific Standard.Alaska Daylight.Pacific Daylight.Mountain Standard.Mountain Daylight.Central Standard.Eastern Standard.Central Daylight.Atlantic Standard.Newfoundland Standard.Atlantic Daylight.Newfoundland Daylight.Azores.West Africa.International Date Line East.New Zealand Standard.Norfolk Island.Australian Eastern Daylight.Australian Central Daylight.Australian Eastern Standard.Guam Standard.Australia Central Standard.Australian Western Daylight Time.Japan Standard.Australian Western Standard.China Coast.Western Standard.Christmas Island.Moscow Daylight.Moscow Standard.Baghdad.Eastern European Daylight.Eastern European Summer.Eastern European.Central European Daylight.Central European Summer.Central European.Daylight Saving.British Summer.Irish Summer.Western European Daylight.Western European Summer.Western European.Universal Co-ordinated.Universal.Greenwich Mean
  if (!$istok(%x,$alpha($1),32)) { $iif(!$isin($left($1,1),+ -),.msg $2 Unknown Timezone Format - Defaulting to GMT..) | tokenize 32 $+(GMT,$iif($isin($left($1,1),+ -),$1,$+($v1,$gettok($1,2,$asc($v1))))) $2 }
  var %zone = $gettok(%y,$findtok(%x,$alpha($1),1,32),46), %gmt = $iif($calc($gettok(%w,$findtok(%x,$alpha($1),1,32),38) $iif($isin($1,+ -),$v1 $gettok($1,2,$asc($v1)))) > -1,$+($chr(43),$v1),$v1)
  var %time = $calc($gmt $left(%gmt,1) (($remove($gettok(%gmt,1,46),$chr(43),$chr(45)) * 60 * 60) + $iif($numtok(%gmt,46),$calc(60 * $+($chr(46),$gettok(%gmt,2,46)))) * 60)) )
  $iif($2,.msg $2,echo -a) $1 $+($chr(91),$addtok(%zone,Time,32),$chr(93)) $asctime(%time,HH:nn) @ $asctime(%time,ddd ddoo mmm) $iif($alpha($1) != GMT,$+($chr(91),GMT %gmt,$chr(93)))
}

alias -l isin { var %n = $numtok($2-,32) | while (%n) { if ($gettok($2-,%n,32) isin $1) { return $v1 } | dec %n } }
alias -l alpha { var %a = $len($1), %b = 1, %z | while (%b <= %a) { var %v = $mid($1,%b,1) | if (%v !isalpha) { return %z } | var %z = $+(%z,$mid($1,%b,1)) | inc %b } | return $1 }

Re: $ctime does not accept timezones [Re: FroggieDaFrog] #248238 28/09/14 11:31 AM
Joined: Dec 2002
Posts: 4,736
Khaled Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 4,736
Thanks for your bug report. I decided not to add support for timezone abbreviations for several reasons. Window's own time functions support some abbreviations and not others. There are also many identical abbreviations that stand for different timezones (see here, for example: AMST, AST, BST, CDT, CST, etc.) so using one of these abbreviations could provide an unexpected offset. Also, I have not found a single definitive abbreviations list. Every list I come across includes or excludes abbreviations that exist in other lists.

That said, adding support for offsets like +NNNN and UTC/GMT would work. The only possible issue is that if scripters are already catering for this limitation (considering that $ctime() has always worked this way), adding support for this now would break existing scripts.

Re: $ctime does not accept timezones [Re: Khaled] #248252 30/09/14 09:07 AM
Joined: Apr 2010
Posts: 943
F
FroggieDaFrog Offline OP
Hoopy frood
OP Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 943
I see why you didn't add support for the abbreviations, as neither did I find a definitive list/iso of TZ abbreviations.

With that said, I don't see how adding support for the offset would break scripts.


I am SReject
My Stuff
Re: $ctime does not accept timezones [Re: FroggieDaFrog] #248260 30/09/14 06:34 PM
Joined: Dec 2002
Posts: 4,736
Khaled Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 4,736
Quote:
With that said, I don't see how adding support for the offset would break scripts.

As $ctime() has always behaved this way, scripts may already be checking for UTC/GMT/+NNNN in the string and applying it to the result. If I add support for it, this will result in the offset being applied twice.