$dur - doing things differently.

By Conscious on Apr 07, 2011

Usage: $dur(seconds)
Replaces seconds into x hours x minutes etc.

alias dur {
  tokenize 32 $calc($1 - $calc($weeks($1) * 604800)) $iif($weeks($1) != 0, $v1 week $+ $iif($v1 != 1,s) $+ $iif($calc($1 - $calc($weeks($1) * 60)) != 0,$chr(44)))
  tokenize 32 $calc($1 - $calc($days($1) * 86400)) $2- $iif($days($1) != 0, $v1 day $+ $iif($v1 != 1,s) $+ $iif($calc($1 - $calc($days($1) * 60)) != 0,$chr(44)))
  tokenize 32 $calc($1 - $calc($hours($1) * 3600)) $2- $iif($hours($1) != 0, $v1 hour $+ $iif($v1 != 1,s) $+ $iif($calc($1 - $calc($hours($1) * 60)) != 0,$chr(44)))
  tokenize 32 $calc($1 - $calc($minutes($1) * 60)) $2- $iif($minutes($1) != 0, $v1 minute $+ $iif($v1 != 1,s) $+ $iif($calc($1 - $calc($minutes($1) * 60)) != 0,$chr(44)))
  tokenize 32 $2- $iif($1 != 0,$round($v1,0) second $+ $iif($v1 != 1,s))
  return $iif(!$1-,0 seconds,$1-)
}
alias weeks return $gettok($calc($1 / 604800),1,46)
alias days return $gettok($calc($1 / 86400),1,46)
alias hours return $gettok($calc($1 / 3600),1,46)
alias minutes return $gettok($calc($1 / 60),1,46)

Comments

Sign in to comment.
Conscious   -  Apr 08, 2011

It basically sets $1 as the amount of seconds remaining so it can simply do $hours($1) or $days($1) with the leftover seconds.

 Respond  
Jethro   -  Apr 08, 2011

What's the snippet's business with "tokenize 32?" I don't get this fancy schmancy thingy...

 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.