[SimBot-commits] CVS: simbot simbot.pl,1.123,1.124
Status: Abandoned
Brought to you by:
kstange
|
From: Pete P. <fou...@us...> - 2005-07-19 02:50:08
|
Update of /cvsroot/simbot/simbot In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17924 Modified Files: simbot.pl Log Message: * I am insufficiently caffinated. Fixed a logic error in a warning. * timeago can now hide seconds * weather will not show you the seconds in how old the weather report is Index: simbot.pl =================================================================== RCS file: /cvsroot/simbot/simbot/simbot.pl,v retrieving revision 1.123 retrieving revision 1.124 diff -u -d -p -r1.123 -r1.124 --- simbot.pl 19 Jul 2005 02:33:28 -0000 1.123 +++ simbot.pl 19 Jul 2005 02:50:00 -0000 1.124 @@ -524,12 +524,20 @@ sub numberize { } # TIMEAGO: Returns a string of how long ago something happened +# timeago(time, specificity) +# specificity: +# 0 shows as needed (1 hour 15 minutes 36 seconds) +# 1 hides seconds (1 hour 15 minutes) +# except if there are only seconds sub timeago { my ($seconds, $minutes, $hours, $days, $weeks, $years); my $now = time; $seconds = $now - $_[0]; - if($_[0] < $now) { + my $hidemode = $_[1]; + + if(!defined $hidemode) { $hidemode = 0; } + if($_[0] > $now) { warn "Trying to use timeago on a time in the future! Now is ${now}, Then is $_[0]"; } if($seconds >= 60) { @@ -554,7 +562,8 @@ sub timeago { push(@reply, "$days day" . (($days == 1) ? '' : 's')) if $days; push(@reply, "$hours hour" . (($hours == 1) ? '' : 's')) if $hours; push(@reply, "$minutes minute" . (($minutes == 1) ? '' : 's')) if $minutes; - push(@reply, "$seconds second" . (($seconds == 1) ? '' : 's')) if $seconds; + push(@reply, "$seconds second" . (($seconds == 1) ? '' : 's')) + if $seconds && $hidemode != 1; if(@reply) { my $string = join(', ', @reply) . ' ago'; $string =~ s/(.*),/$1 and/; |