Countdown Timer

By RusselB on May 19, 2007

This allows people to set a date & time in the future, then be able to track how long until that date & time.
Required parameter got missed. Code has been repaired, and messages have been added/updated to make the code more flexible and understandable. Option to delete a tracking has been added. Note: The person using the !del command must have ops in at least one common channel.

on *:text:!setdate*:*:{
  if !$ctime($2-) {
    .msg $nick Sorry, but I don't recognize the format used.
    .msg $nick Examples of recognized formats are:
    .msg $nick January 1 1970 00:00:00
    .msg $nick 3rd August 1987 3:46pm
    .msg $nick 21/4/72 1:30:37
    .msg $nick Wed 1998-3-27 21:16
  }
  elseif $ctime($2-) < $ctime {
    .msg $iif($chan,$v1,$nick) Sorry, but $2- has already passed
  }
  else {
    .hadd -m setdate  $ctime($2-) $2-
    .msg $iif($chan,$v1,$nick) Countdown timer $hget(setdate,0).item has been initiated.
  }
}
on *:text:!timeleft*:*:{
  if $2 == $null {
    .msg $iif($chan,$v1,$nick)  There are $hget(setdate,0).item countdown timings in progress.
    .msg $iif($chan,$v1,$nick) Please specify which timing you wish, or use 0 (zero) for all
  }
  elseif $2 == 0 {
    var %a = 1, %b = $hget(setdate,0).item
    while %a <= %b {
      var %setdate = $hget(setdate,%a).data, %settime = $hget(setdate,%a).item
      .timer 1 %a .msg $iif($chan,$v1,$nick) $iif(%settime < $ctime,%setdate passed $duration($calc($ctime - %settime)),Time left to %setdate is $duration($calc(%settime - $ctime)))
      inc %a
    }
  }
  else {
    if !$hget(setdate,$2).item {
      .msg $iif($chan,$v1,$nick) Sorry, no entry found for $2
    }
    elseif $hget(setdate,$2).item < $ctime {
      .msg $iif($chan,$v1,$nick) $hget(setdate,$2).data passed $duration($calc($ctime - $hget(setdate,$2).item))
    }
    else {
      .msg $iif($chan,$v1,$nick) Time left to $hget(setdate,$2).data is $duration($calc($hget(setdate,$2).item - $ctime))
    }
  }
}
on *:start:{
  if !$hget(setdate) { .hmake setdate 100 }
  if $exists(setdate.hsh) { .hload setdate setdate.hsh }
}
on *:exit:{
  .hsave -o setdate setdate.hsh
}
on *:disconnect:{
  .hsave -o setdate setdate.hsh
}
on *:text:!del*:*:{ 
  var %op = 0, %a = 1, %b = $comchan($nick,0) 
  while %a <= %b { 
    if $nick isop $comchan($nick,%a) { 
      inc %op 
    } 
    inc %a 
  } 
  if %op { 
    .msg $iif($chan,$v1,$nick) Time Left tracking for $hget(setdate,$2).data has been deleted.
    .hdel setdate $hget(setdate,$2).item 
  } 
  else { 
    .notice $nick Insufficient Access 
  } 
} 

Comments

Sign in to comment.
Aucun50   -  Feb 14, 2009

Well you could have went with sec like set -z %var 9000000 are something then msg $chan %var.

But thats for seconds only tho your is for dates and it works nice.

 Respond  
RPTNNN   -  Oct 18, 2008

Sorry I did not take a look at it and I had selected year 2011

 Respond  
RusselB   -  Oct 18, 2008

1) Alternative languages could be implemented, but if I do implement them, then the code will not be as a snippet, but as a Add-On, due to the complexity of trying to allocate for an unknown number of languages,

2) A memo field is in my current plans.

3) I suggest you check your calendar, as leap year specifications indicate that February 2012 will have 29 days as the year is evenly divisible by 4, and I just checked 4 different perpetuual calendars, and they all show Feb. 2012 as having 29 days.

3a) If your calendar still indicates that Feb. 2012 only has 28 days, please let me know where you are checking.

 Respond  
RPTNNN   -  Oct 18, 2008

Any way to translate the time left (wk, days, ...) to another language? I don't know if it is possible, if it can be done could anyone tell me where to modify that?
By the way, it would be great to be able to add some text to the countdown timer, like:

Someone's Birthday and the time left

Another one, what about checking that february has 28 or 29 days? If you write !setdate 29/02/2012 it is accepted although february in 2012 only has 28 days

 Respond  
RusselB   -  Oct 13, 2008

I have not forgotten about updating this code, just had a lot of other things come up.

My apologies for it taking so long, but some of the alterations I wanted to make, in addition to some that have been requested, are being more stubborn to code than I thought.

 Respond  
RusselB   -  Sep 28, 2007

I\'ll see what I can do, Pangaea.

 Respond  
Pangaea   -  Sep 06, 2007

Great.. is there a way to make it msg the channel when the time is up.. or even better give 5, 4, 3, 2, 1.. 5 seconds before the time is up?

 Respond  
CharltonJ   -  May 21, 2007

very nice!!! i love it :D Good job RusselB :)))

 Respond  
|MELIORITE|   -  May 20, 2007

I really love this idea, this could be a lot of fun. The coding is of great quality... I have not tested its functionality yet, but your hash tables are always of the highest order.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.