mIRC Home    About    Download    Register    News    Help

Print Thread
#119205 02/05/05 10:19 PM
Joined: May 2005
Posts: 13
S
Pikka bird
OP Offline
Pikka bird
S
Joined: May 2005
Posts: 13
Does anyone know how to make a script that would count down to a specific date --
something that would activate with a alias and answer
its only xxxx till xxxx ??

#119206 02/05/05 10:28 PM
Joined: Nov 2003
Posts: 2,327
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
Code:
alias timeuntil { return $calc($ctime($1) - $ctime) }
alias saytimeuntil { say It is exactly $duration($timeuntil($1)) until $1! }


/saytimeuntil <date>


New username: hixxy
#119207 03/05/05 12:44 PM
Joined: May 2005
Posts: 13
S
Pikka bird
OP Offline
Pikka bird
S
Joined: May 2005
Posts: 13
Is that how its posted in the alias sec just as you have it listed?

#119208 03/05/05 12:48 PM
Joined: May 2005
Posts: 13
S
Pikka bird
OP Offline
Pikka bird
S
Joined: May 2005
Posts: 13
okies I have it working how do I make it post that in yrs months days then seconds

#119209 03/05/05 06:44 PM
Joined: Apr 2003
Posts: 701
K
Hoopy frood
Offline
Hoopy frood
K
Joined: Apr 2003
Posts: 701
That's more difficult, since it's not clear how long a year or a month really is. Is one month equal to 30, 31, 28, 29 or 365.24219/12 days?

Keeping that in mind, here's something I wrote instead of doing useful stuff. It should give rather accurate results in that it works with all the separate numbers (year,month,day,hour,minute,second) instead of converting it all to seconds since some specific date and then using some arbitrary (read: always wrong) period of time for a month, a year etc.
Code:
alias datediff {
  ; calculate difference between date 1 and date 2, in years,months,days,hours,minutes,seconds
  ; date 1 must be before date 2
  ; usage $datediff(dd/mm/yyyy HH:nn:ss, dd/mm/yyyy HH:nn:ss)
  ; meaning $datediff($date $time, $date $time)
  ; example:  [color:green]//echo -a $datediff(3/5/2005 20:00:10, 5/10/2000 12:15:20)[/color]
  ; ** IMPORTANT: $date uses dd/mm/yyyy, if you want to input mm/dd/yyyy style, 
  ; **   add a third parameter (not 0, $null or $false)
  ; example:  [color:green]//echo -a $datediff(1/5/2005 11:15:22pm, 1/8/2005 12:15:22P.M., us)[/color]
  ; hh:nn:ss am/pm is supported (only now I realize how strange it actually is)
  ; my reference: http://www.worldtimezone.com/wtz-names/wtz-am-pm.html
  if ($regex($2,/^0*(\d+)\D0*(\d+)\D(\d+)\D0*(\d+)\D0*(\d+)\D0*(\d+)(?:\D?([ap]\.?m\.?|noon|midday|midnight))?$/i)) {
    var %d1 = $regml($iif($3,2,1)), %m1 = $regml($iif($3,1,2))
    var %h1 = $regml(4), %n1 = $regml(5), %s1 = $regml(6), %y1 = $regml(3)
    if ((%h1 == 12) &amp;&amp; (($regml(7) == am) || ($v1 == midnight))) var %h1 = 0
    elseif ((%h1 isnum 1-11) &amp;&amp; ($regml(7) == pm)) inc %h1 12
  }
  else return Date 1 in incorrect format
  if ($regex($1,/^0*(\d+)\D0*(\d+)\D(\d+)\D0*(\d+)\D0*(\d+)\D0*(\d+)(?:\D?([ap]\.?m\.?|noon|midday|midnight))?$/i)) {
    var %d2 = $regml($iif($3,2,1)), %m2 = $regml($iif($3,1,2))
    var %h2 = $regml(4), %n2 = $regml(5), %s2 = $regml(6), %y2 = $regml(3)
    if ((%h2 == 12) &amp;&amp; (($regml(7) == am) || ($v1 == midnight))) var %h2 = 0
    elseif ((%h2 isnum 1-11) &amp;&amp; ($regml(7) == pm)) inc %h2 12
  }
  else return Date 2 in incorrect format
  if ((%m1 !isnum 1-12) || (%d1 !isnum 1-31) || (%h1 !isnum 0-23) || (%m1 !isnum 0-59) $&amp;
    || (%s1 !isnum 0-59)) return Date 1 invalid
  if ((%m2 !isnum 1-12) || (%d2 !isnum 1-31) || (%h2 !isnum 0-23) || (%m2 !isnum 0-59) $&amp;
    || (%s2 !isnum 0-59)) return Date 2 invalid
  var %s = %s1 - %s2
  if (%s &lt; 0) var %s = %s + 60, %n1 = %n1 - 1
  var %n = %n1 - %n2
  if (%n &lt; 0) var %n = %n + 60, %h1 = %h1 - 1
  var %h = %h1 - %h2
  if (%h &lt; 0) var %h = %h + 24, %d1 = %d1 - 1
  var %d = %d1 - %d2
  if (%d &lt; 0) var %d = %d + $daysinmonth(%m1, %y), %m1 = %m1 - 1
  var %m = %m1 - %m2
  if (%m &lt; 0) var %m = %m + 12, %y = %y - 1
  var %y = %y1 - %y2
  if (%y &lt; 0) return reverse the dates please...
  return Difference: %y years %m months %d days %h hours %n minutes %s seconds
}
alias -l daysinmonth {
  ; usage: $daysinmonth(number of month, year)
  ; returns the number of days that month has, with full support for leap years
  if ($1 isin 1.3.5.7.8.10.12) return 31
  elseif ($1 isin 4.6.9.11) return 30
  elseif ($calc($2 % 400) == 0) return 29
  elseif ($calc($2 % 100) == 0) return 28
  elseif ($calc($2 % 4) == 0) return 29
  return 28
}

#119210 03/05/05 07:48 PM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Good work, nice to see it done in native mIRC scripting.

As an added note, one could kinda cheat using the msscriptcontrol object to interpret vbscript code (good find tidy), more specifically the datediff() function. I prefer your way, because well, we're not vbscripters, we're mIRCscripters.

Code:
alias datediff {
 [color:red]  [/color] 
  /*
 [color:red]  [/color] 
  Usage: $datediff(begindate,targetdate).property
 [color:red]  [/color] 
  Properties: 
 [color:red]  [/color] 
  "yyyy" Year 
  "q" Quarter 
  "m" Month 
  "y" Day of year 
  "d" Day 
  "w" Weekday 
  "ww" Week of year 
  "h" Hour 
  "n" Minute 
  "s" Second 
 [color:red]  [/color] 
  Example: //echo -a $datediff(18/03/1982 08:30,3/05/2005 15:10).s
 [color:red]  [/color] 
  */
 [color:red]  [/color] 
  if !$ctime($1) || !$ctime($2) || !$istok(yyyy q m d w ww h n s,$prop,32) { return }
  var %a = a $+ $ticks, %b = Datediff( $+(",$prop,") ," $1"," $2")
  .comopen %a msscriptcontrol.scriptcontrol
  if $comerr { return }
  tokenize 32 $com(%a,language,4,bstr,vbscript) $com(%a,eval,3,bstr,%b) $com(%a).result
  .comclose %a
  return $3
}

I should note that when specifying the yyyy property to see the difference in years between the two dates, it ignores the months and time. Just looks at the year of the date.

When using .s to get a result in seconds, one could use $duration on it to get the result in "wks days minutes seconds" format.

Greets


Gone.
#119211 07/05/05 01:50 PM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
I should note that in contrary to what I first thought, vb's datediff function also uses ctime from the looks of it, making it a lot less useful. I thought I used dates prior to 1970 when testing, but turns out that doesn't work.

Oh well...


Gone.

Link Copied to Clipboard