--- trunk/bin/irc-logger.pl 2007/09/29 13:11:45 66 +++ trunk/bin/irc-logger.pl 2007/09/29 13:13:41 67 @@ -260,16 +260,21 @@ my $sql = $context ? $sql_context : $sql_message; - $sql .= " where message ilike ? or nick ilike ? " if ($args->{search}); - $sql .= " where id in (" . join(",", @{ $tags->{ $args->{tag} } }) . ") " if ($args->{tag} && $tags->{ $args->{tag} }); - if ($args->{date}) { - my $date = eval { DateTime::Format::ISO8601->parse_datetime( $args->{date} )->ymd; }; + sub check_date { + my $date = shift; + $date = eval { DateTime::Format::ISO8601->parse_datetime( $args->{date} )->ymd; }; if ( $@ ) { warn "invalid date ", $args->{date}, $/; $date = DateTime->now->ymd; } + return $date; + } + + $sql .= " where message ilike ? or nick ilike ? " if ($args->{search}); + $sql .= " where id in (" . join(",", @{ $tags->{ $args->{tag} } }) . ") " if ($args->{tag} && $tags->{ $args->{tag} }); + if ($args->{date}) { $sql .= " where date(time) = ? "; - $args->{date} = $date; + $args->{date} = check_date( $args->{date} ); } $sql .= " order by log.time desc"; $sql .= " limit " . $args->{limit} if ($args->{limit}); @@ -284,7 +289,7 @@ $sth->execute(); _log "tag '$tag' returned ", $sth->rows, " results ", $context || ''; } elsif (my $date = $args->{date}) { - $sth->execute($date); + $sth->execute( check_date($date) ); _log "found ", $sth->rows, " messages for date $date ", $context || ''; } else { $sth->execute(); @@ -952,7 +957,7 @@ limit => $q->param('last') || $q->param('date') ? undef : 100, search => $search || undef, tag => $q->param('tag') || undef, - date => $q->param('date') || undef, + date => check_date( $q->param('date') ), fmt => { date => sub { my $date = shift || return;