It is currently Wed, 25.Nov 2009 - 06:00

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: PRETTYTIME.RC Script - Convert Seconds to Formatted Time
PostPosted: Thu, 16.Oct 2008 - 18:47 
Offline
v.i.p.
v.i.p.
User avatar

Joined: Mon, 31.Jul 2006 - 20:25
Posts: 158
Location: Washington state, USA
PRETTYTIME.RC Script

The PRETTYTIME alias is a method for converting raw seconds to a weeks/days/hours/minutes/seconds format.

How long is 654376 seconds?

654376 seconds is 1w 0d 13h 46m 16s

If you want to know in weeks, days, hours, minutes and seconds, the PRETTYTIME.RC script will let you convert seconds into a more legible time format. It's not dissimilar to the $mp3time() function, but that is limited to minutes/seconds. This simplistic script is very easy to modify, and rather self-explanatory. I've played with the idea of adding months and years, but those are less specific units of time, and most of the things I ever want to convert are easily understood in terms of weeks anyway, or smaller units.

What would you use this for? Perhaps you want to see how long a ban period is, and you've used the /admin banlist command to get your information. SlavaNap has a secondary method to retrieve this information, but you may be using an OpenNap server. Maybe you want to know how long an albw runs, or you have some other interest, such as parsing the number of seconds someone's been online using your own WHOIS hook.

For whatever reason, if you want to convert seconds to a more readable format, PRETTYTIME does an adequate job. The script contains no special characters, so it doesn't hurt to simply cut and paste this script. Save it as prettytime.rc wherever your default script folder is, load it and run it with the /prettytime alias.

Code:
# prettytime.rc v.1224168783 by SkyyTek
# Usage:  /prettytime <seconds>

alias prettytime {
eval @ totaltime = $0
@ weeks = totaltime/604800
@ newtime = totaltime-(weeks*604800)
@ totaltime = newtime
@ days = totaltime/86400
@ newtime = totaltime-(days*86400)
@ totaltime = newtime
@ hours = totaltime/3600
@ newtime = totaltime-(hours*3600)
@ totaltime = newtime
@ minutes = totaltime/60
@ newtime = totaltime-(minutes*60)
@ seconds = newtime
eval xecho -b $0 seconds is $weeks\w $days\d $hours\h $minutes\m $seconds\s
}


You can substitute eval xecho -b with just eval echo if you want raw output without the banner. I use EE as an alias for EVAL ECHO as I use that combination so often. As I said, it's very easy to understand and modify this script.

Happy scripting!

8) SkyyTek 8)

_________________
All that is gold does not glitter,
Not all those who wander are lost


Top
 Profile  
 
 Post subject: Re: PRETTYTIME.RC Script - Convert Seconds to Formatted Time
PostPosted: Fri, 04.Sep 2009 - 15:24 
Offline
v.i.p.
v.i.p.
User avatar

Joined: Mon, 31.Jul 2006 - 20:25
Posts: 158
Location: Washington state, USA
Functionally equivalent, this works exactly the same, but is a little cleaner, a little leaner.
Code:
# prettytime.rc v.1252068614 by SkyyTek
# Usage:  /prettytime <seconds>
# Variable secs is seconds

alias prettytime {
eval @ secs = $0
@ weeks = secs/604800
@ secs = secs-(weeks*604800)
@ days = secs/86400
@ secs = secs-(days*86400)
@ hours = secs/3600
@ secs = secs-(hours*3600)
@ minutes = secs/60
@ secs = secs-(minutes*60)
@ seconds = secs
eval xecho -b $0 seconds is $weeks\w $days\d $hours\h $minutes\m $seconds\s
}

Always feel free to suggest improvements to my scripts and aliases!

8) SkyyTek 8)

_________________
All that is gold does not glitter,
Not all those who wander are lost


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
© 2008 phpbbstylists.com
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group