[dw-free] check calls to LJ::ago_text for inappropriate uses of zero
[commit: http://hg.dwscoalition.org/dw-free/rev/72171d6809cb]
http://bugs.dwscoalition.org/show_bug.cgi?id=3158
Make a new function, diff_ago_text, to handle when we're looking at the
difference from the current time.
Patch by
kareila.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=3158
Make a new function, diff_ago_text, to handle when we're looking at the
difference from the current time.
Patch by
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Files modified:
- cgi-bin/LJ/Directory/Results.pm
- cgi-bin/LJ/User.pm
- cgi-bin/LJ/Widget/ImportStatus.pm
- cgi-bin/LJ/Widget/InboxFolder.pm
- cgi-bin/ljtimeutil.pl
- htdocs/admin/theschwartz.bml
- htdocs/latest.bml
- htdocs/support/help.bml
- htdocs/support/see_request.bml
- htdocs/tools/endpoints/directorysearch.bml
- htdocs/tools/recent_comments.bml
-------------------------------------------------------------------------------- diff -r 890ddde03d5b -r 72171d6809cb cgi-bin/LJ/Directory/Results.pm --- a/cgi-bin/LJ/Directory/Results.pm Wed Oct 27 15:18:37 2010 +0800 +++ b/cgi-bin/LJ/Directory/Results.pm Wed Oct 27 15:25:22 2010 +0800 @@ -95,7 +95,8 @@ sub render_simple { foreach my $u (@users) { $ret .= "<tr><td class='SearchResult'>"; $ret .= $u->ljuser_display . " - " . $u->name_html; - $ret .= " <small>(Last updated: ". LJ::ago_text(time() - $updated->{$u->id}) . ")</small>"; + # FIXME: consider replacing this with $u->last_updated + $ret .= " <small>(Last updated: ". LJ::diff_ago_text( $updated->{$u->id} ) . ")</small>"; $ret .= "</td></tr>"; } $ret .= "</table>"; @@ -123,13 +124,15 @@ sub render_pics { }; $ret .= '<div class="Username">' . $u->ljuser_display . '</div>'; - if ($updated->{$u->id}) { - $ret .= "<small>Updated ". LJ::ago_text(time() - $updated->{$u->id}) . "</small>"; + $ret .= "<small>"; + + if ( $updated->{$u->id} ) { + $ret .= LJ::Lang::ml( 'search.user.update.last', { time => LJ::diff_ago_text( $updated->{$u->id} ) } ); } else { - $ret .= "<small>Never updated</small>"; + $ret .= LJ::Lang::ml( 'search.user.update.never' ); } - $ret .= "</td>"; + $ret .= "</small></td>"; } $ret .= "</tr></table>"; diff -r 890ddde03d5b -r 72171d6809cb cgi-bin/LJ/User.pm --- a/cgi-bin/LJ/User.pm Wed Oct 27 15:18:37 2010 +0800 +++ b/cgi-bin/LJ/User.pm Wed Oct 27 15:25:22 2010 +0800 @@ -720,8 +720,7 @@ sub last_updated { return undef unless $u -> is_person || $u->is_community; my $lastupdated = substr( LJ::mysql_time( $u->timeupdate ), 0, 10 ); - my $secondsold = time() - $u->timeupdate; - my $ago_text = LJ::ago_text( $secondsold ); + my $ago_text = LJ::diff_ago_text( $u->timeupdate ); if ( $u->timeupdate ) { return LJ::Lang::ml( 'lastupdated.ago', @@ -8369,9 +8368,9 @@ sub user_search_display { $ret .= "<tr><td colspan='2' style='text-align: left; font-size: smaller' class='lastupdated'>"; if ( $updated->{$u->userid} > 0 ) { - $ret .= BML::ml( 'search.user.update.last', { time => LJ::ago_text( time() - $updated->{$u->userid} ) } ); - } else { - $ret .= BML::ml( 'search.user.update.never' ); + $ret .= LJ::Lang::ml( 'search.user.update.last', { time => LJ::diff_ago_text( $updated->{$u->id} ) } ); + } else { + $ret .= LJ::Lang::ml( 'search.user.update.never' ); } $ret .= "</td></tr>"; diff -r 890ddde03d5b -r 72171d6809cb cgi-bin/LJ/Widget/ImportStatus.pm --- a/cgi-bin/LJ/Widget/ImportStatus.pm Wed Oct 27 15:18:37 2010 +0800 +++ b/cgi-bin/LJ/Widget/ImportStatus.pm Wed Oct 27 15:25:22 2010 +0800 @@ -46,7 +46,7 @@ sub render_body { foreach my $item ( sort keys %{$import_item->{items}} ) { my $i = $import_item->{items}->{$item}; my $color = { init => '#333333', ready => '#3333aa', queued => '#33aa33', failed => '#aa3333', succeeded => '#00ff00' }->{$i->{status}}; - my $ago_text = $i->{last_touch} ? LJ::ago_text( time() - $i->{last_touch} ) : ""; + my $ago_text = $i->{last_touch} ? LJ::diff_ago_text( $i->{last_touch} ) : ""; my $status = "<span style='color: $color;'>"; if ( $i->{status} eq 'init' ) { $status .= $class->ml( "widget.importstatus.status.$i->{status}.$item" ); @@ -60,7 +60,7 @@ sub render_body { $ret .= "<td>"; $ret .= $ago_text ? $class->ml( 'widget.importstatus.statusasof', { status => $status, timeago => $ago_text } ) : $status; $ret .= "</td>"; - $ret .= "<td>" . $class->ml( 'widget.importstatus.createtime', { timeago => LJ::ago_text( time() - $i->{created} ) } ) . "</td>"; + $ret .= "<td>" . $class->ml( 'widget.importstatus.createtime', { timeago => LJ::diff_ago_text( $i->{created} ) } ) . "</td>"; $ret .= "</tr>"; $import_in_progress = 1 if $i->{status} =~ /^(?:init|ready|queued)$/; diff -r 890ddde03d5b -r 72171d6809cb cgi-bin/LJ/Widget/InboxFolder.pm --- a/cgi-bin/LJ/Widget/InboxFolder.pm Wed Oct 27 15:18:37 2010 +0800 +++ b/cgi-bin/LJ/Widget/InboxFolder.pm Wed Oct 27 15:25:22 2010 +0800 @@ -172,7 +172,7 @@ sub render_body { . LJ::img( $bookmark, "", { class => 'InboxItem_Bookmark' } ) . "</a>"; - my $when = LJ::ago_text(time() - $inbox_item->when_unixtime); + my $when = LJ::diff_ago_text( $inbox_item->when_unixtime ); my $contents = $inbox_item->as_html || ''; my $row_class = ($rownum++ % 2 == 0) ? "InboxItem_Meta" : "InboxItem_Meta alt"; diff -r 890ddde03d5b -r 72171d6809cb cgi-bin/ljtimeutil.pl --- a/cgi-bin/ljtimeutil.pl Wed Oct 27 15:18:37 2010 +0800 +++ b/cgi-bin/ljtimeutil.pl Wed Oct 27 15:25:22 2010 +0800 @@ -246,6 +246,18 @@ sub ago_text } } +# args: time in seconds of last activity; "current" time in seconds. +# returns: result of LJ::ago_text for the difference. + +sub diff_ago_text { + my ( $last, $time ) = @_; + return ago_text( 0 ) unless $last; + $time = time() unless defined $time; + + my $diff = ( $time - $last ) || 1; + return ago_text( $diff ); +} + # Given a year, month, and day; calculate the age in years compared to now. May return a negative number or # zero if called in such a way as would cause those. diff -r 890ddde03d5b -r 72171d6809cb htdocs/admin/theschwartz.bml --- a/htdocs/admin/theschwartz.bml Wed Oct 27 15:18:37 2010 +0800 +++ b/htdocs/admin/theschwartz.bml Wed Oct 27 15:25:22 2010 +0800 @@ -73,8 +73,8 @@ body<= foreach my $job ( @$jobs ) { my ( $jid, $fn, $it, $r_it, $ra, $r_ra, $gu, $r_gu, $pr ) = @$job; - my $ago_it = LJ::ago_text( time() - $r_it ); - my $ago_ra = LJ::ago_text( time() - $r_ra ); + my $ago_it = LJ::diff_ago_text( $r_it ); + my $ago_ra = LJ::diff_ago_text( $r_ra ); my $state; warn "[$r_ra, $r_gu]\n"; diff -r 890ddde03d5b -r 72171d6809cb htdocs/latest.bml --- a/htdocs/latest.bml Wed Oct 27 15:18:37 2010 +0800 +++ b/htdocs/latest.bml Wed Oct 27 15:25:22 2010 +0800 @@ -159,7 +159,7 @@ EOC if ( ! $obj->poster->equals( $obj->journal ) ) { $user .= ' in ' . $obj->journal->ljuser_display; } - my $time = LJ::ago_text( $now - $obj->logtime_unix ); + my $time = LJ::diff_ago_text( $obj->logtime_unix, $now ); my $url = $obj->url; my $truncated; my $evt = $obj->event_html_summary( 2000, { cuturl => $url, preformatted => $obj->prop( 'opt_preformatted' ) }, \$truncated ); diff -r 890ddde03d5b -r 72171d6809cb htdocs/support/help.bml --- a/htdocs/support/help.bml Wed Oct 27 15:18:37 2010 +0800 +++ b/htdocs/support/help.bml Wed Oct 27 15:25:22 2010 +0800 @@ -327,7 +327,7 @@ body<= # other content for this request my $summary = LJ::ehtml($sp->{'subject'}); my $secold = time() - $sp->{'timecreate'}; - my $age = $GET{rawdates} ? LJ::mysql_time($sp->{'timecreate'}) : LJ::ago_text($secold); + my $age = $GET{rawdates} ? LJ::mysql_time( $sp->{timecreate} ) : LJ::ago_text( $secold || 1 ); my $probarea = $sp->{_cat}->{'catname'}; my $points = LJ::Support::calc_points($sp, $secold); diff -r 890ddde03d5b -r 72171d6809cb htdocs/support/see_request.bml --- a/htdocs/support/see_request.bml Wed Oct 27 15:18:37 2010 +0800 +++ b/htdocs/support/see_request.bml Wed Oct 27 15:25:22 2010 +0800 @@ -473,8 +473,8 @@ body<= $ret .= "<tr><td align='right'><b>$ML{'.tier'}</b></td><td>$tier_map{$latest_timelogged_tier}</td></tr>\n"; } - my $timecreate = LJ::time_to_http($sp->{'timecreate'}); - my $age = LJ::ago_text(time() - $sp->{'timecreate'}); + my $timecreate = LJ::time_to_http( $sp->{timecreate} ); + my $age = LJ::diff_ago_text( $sp->{timecreate} ); $ret .= "<tr><td align='right'><b>$ML{'.timeposted'}:</b></td><td>$timecreate ($age)</td></tr>\n"; my $state = $sp->{'state'}; if ($state eq "open") { diff -r 890ddde03d5b -r 72171d6809cb htdocs/tools/endpoints/directorysearch.bml --- a/htdocs/tools/endpoints/directorysearch.bml Wed Oct 27 15:18:37 2010 +0800 +++ b/htdocs/tools/endpoints/directorysearch.bml Wed Oct 27 15:25:22 2010 +0800 @@ -61,8 +61,7 @@ _c?> my @users; foreach my $u ($results->users) { my $updatetime = $updated->{$u->userid}; - my $updatetimestring = $updatetime ? LJ::ago_text(time() - $updatetime) : - 'Never'; + my $updatetimestring = LJ::diff_ago_text( $updatetime ); push @users, { lastupdated => $updatetime, diff -r 890ddde03d5b -r 72171d6809cb htdocs/tools/recent_comments.bml --- a/htdocs/tools/recent_comments.bml Wed Oct 27 15:18:37 2010 +0800 +++ b/htdocs/tools/recent_comments.bml Wed Oct 27 15:25:22 2010 +0800 @@ -197,7 +197,7 @@ body<= $ret .= "<tr valign='top' id='cmtbar$talkid'><td style='width: 150px; line-height: 1.5em; border-top: 1px solid #999; background-color: $bgcolor' id='cmtbar$talkid'>"; $ret .= (LJ::isu($pu) ? LJ::ljuser($pu) : $ML{ '.anonymous' }) . "<br />"; - $ret .= LJ::ago_text($now - $r->{datepostunix}) . "<br />"; + $ret .= LJ::diff_ago_text( $r->{datepostunix}, $now ) . "<br />"; $ret .= "<div id='state$talkid'>$state</div>" if $r->{state} ne "D"; unless ($r->{state} eq "D") { @@ -302,7 +302,7 @@ body<= my $commentanchor = LJ::Talk::comment_anchor( $talkid ); my $talkurl = "$logurl?thread=$talkid$commentanchor"; - my $hr_ago = LJ::ago_text($now - $r->{'posttime'}); + my $hr_ago = LJ::diff_ago_text( $r->{posttime}, $now ); my $subject; my $delete; my $editlink; --------------------------------------------------------------------------------