Ok, an update to improve the coding thanks to ideas from Kelder's script as well as some of my own. I also changed the variable names a bit to help prevent any conflicts with other scripts. And, it's been updated to work on mIRC 6.16. Apparently 6.16 doesn't have $year anymore. I had written this for 6.14 to begin with and didn't realize it wouldn't work on 6.16 because of the $year. Anyhow, it now works on 6.16.

Any other suggestions for improvement? I still will see about adding formatting options like mentioned. I'm having an issue with making the format work properly, though....

The problem is the if I do something like $datexpander(40wks 2days 3hrs,mmddhh) then the comma is removed, so I can't just use it as a token. Why is that? I obviously don't want to make people use something other than a comma... and I'd rather save code so that I don't have to check the last $chr(32) token in order to see if it's formatting information.

Btw, try it out with: //echo -a $datexpander($duration($ctime)) laugh

Code:
; *******************************************************************
; DateXpander Script
; by Riamus 2005
;
; Suggestions and ideas for improvement from mIRC.com's forum
;
; This script will take a standard $duration and make it include months and years
; based on the current date.
;
; For this script to be accurate, it is only meant to be used when the $duration is
; using today's date and counting backwards (such as an uptime $duration). It
; will still be really accurate (within 3 days) even if you use a $duration that isn't
; from the current date, but it won't be exact that way.
;
; Use: $DateXpander(value)
; "value" must be in the format of $duration
;
; For questions about this script, contact Riamus on IRC -- #oldgames on irc.undernet.org
; *******************************************************************

alias DateXpander {
  unset %dx-dateoutput

  if ($1- isalpha || $1- isnum) {
    echo -a Error.  Use the same format as in $chr(36) $+ duration.
    halt
  }

  set %dx_weeks $iif($gettok($1-,1,119) isnum,$gettok($1-,1,119),0)
  set %dx_days $iif($gettok($gettok($1-,1,100),-1,32) isnum,$gettok($gettok($1-,1,100),-1,32),0)
  set %dx_hours $iif($gettok($gettok($1-,1,104),-1,32) isnum,$gettok($gettok($1-,1,104),-1,32),0)
  set %dx_minutes $iif($gettok($gettok($1-,1,109),-1,32) isnum,$gettok($gettok($1-,1,109),-1,32),0)
  set %dx_seconds $iif(sec isin $gettok($1-,$gettok($1-,0,32),32),$gettok($gettok($1-,$gettok($1-,0,32),32),1,115),0)
  set %dx_totaldays $calc(%dx_weeks * 7 + %dx_days)

  set %dx_currentmonth $date(m)

  :monthstart
  if (%dx_currentmonth == 12 || %dx_currentmonth == 10 || %dx_currentmonth == 7 || %dx_currentmonth == 5) {
    set %dx_monthdays 30
  }
  elseif (%dx_currentmonth == 11 || %dx_currentmonth == 9 || %dx_currentmonth == 8 || %dx_currentmonth == 6 || %dx_currentmonth == 4 || %dx_currentmonth == 2 || %dx_currentmonth == 1) {
    set %dx_monthdays 31
  }
  elseif (%dx_currentmonth == 3 && $calc($date(yyyy) % 4) != 0) {
    set %dx_monthdays 28
  }
  elseif (%dx_currentmonth == 3 && $calc($date(yyyy) % 4) == 0) {
    set %dx_monthdays 29
  }
  if (%dx_totaldays >= %dx_monthdays) {
    inc %dx_months
    dec %dx_totaldays %dx_monthdays
    if (%dx_currentmonth != 1) {
      dec %dx_currentmonth
    }
    else { set %dx_currentmonth 12 }
    goto monthstart
  }

  set %dx_years $int($calc(%dx_months / 12))
  dec %dx_months $calc(%dx_years * 12)
  set %dx_weeks $int($calc(%dx_totaldays / 7))
  set %dx_totaldays $calc(%dx_totaldays - (%dx_weeks * 7))

  if (%dx_years > 1) { set %dx-dateoutput %dx-dateoutput %dx_years $+ _years }
  elseif (%dx_years == 1) { set %dx-dateoutput %dx-dateoutput %dx_years $+ _year }
  if (%dx_months > 1) { set %dx-dateoutput %dx-dateoutput %dx_months $+ _months }
  elseif (%dx_months == 1) { set %dx-dateoutput %dx-dateoutput %dx_months $+ _month }
  if (%dx_weeks > 1) { set %dx-dateoutput %dx-dateoutput %dx_weeks $+ _weeks }
  elseif (%dx_weeks == 1) { set %dx-dateoutput %dx-dateoutput %dx_weeks $+ _week }
  if (%dx_totaldays > 1) { set %dx-dateoutput %dx-dateoutput %dx_totaldays $+ _days }
  elseif (%dx_totaldays == 1) { set %dx-dateoutput %dx-dateoutput %dx_totaldays $+ _day }
  if (%dx_hours > 1) { set %dx-dateoutput %dx-dateoutput %dx_hours $+ _hours }
  elseif (%dx_hours == 1) { set %dx-dateoutput %dx-dateoutput %dx_hours $+ _hour }
  if (%dx_minutes > 1) { set %dx-dateoutput %dx-dateoutput %dx_minutes $+ _minutes }
  elseif (%dx_minutes == 1) { set %dx-dateoutput %dx-dateoutput %dx_minutes $+ _minute }
  if (%dx_seconds > 1) { set %dx-dateoutput %dx-dateoutput %dx_seconds $+ _seconds }
  elseif (%dx_seconds == 1) { set %dx-dateoutput %dx-dateoutput %dx_seconds $+ _second }

  unset %dx_*

  return $replace(%dx-dateoutput,$chr(32),$chr(44) $+ $chr(32),_,$chr(32))
}

Last edited by Riamus2; 27/07/05 01:58 PM.

Invision Support
#Invision on irc.irchighway.net