use warnings; use strict; =head1 NAME BarnOwl::Module::TimeFilter =head1 DESCRIPTION I have no idea what's going on bpchen, 2015/10/26 =cut package BarnOwl::Module::TimeFilter; use POSIX; use Time::Local; our $VERSION = 0.2.1; # The default value is a day I lost my zephyr logs. Oops. # You can't actually invoke it though. my $lower_bound = timelocal(0, 0, 0, 20, 9, 2015); my $upper_bound = undef; sub bad_parse_time { my ($year, $month, $day, $hour, $minutes, $seconds) = grep { $_ ne '' } split(/\D+/, shift); # BarnOwl::error("$year;$month;$day;$hour;$minutes;$seconds"); if (!defined($month)) { $month = 0; } else { $month -= 1; # NOTE: because for timelocal, 0 is January and so on } if (!defined($day )) { $day = 1; } if (!defined($hour )) { $hour = 0; } if (!defined($minutes)) { $minutes = 0; } if (!defined($seconds)) { $seconds = 0; } return timelocal($seconds, $minutes, $hour, $day, $month, $year); } sub timefilter { my $msgtime = shift->{"unix_time"}; # second, minute, hour, day, month, year return (!defined($lower_bound) || $msgtime > $lower_bound) && (!defined($upper_bound) || $msgtime < $upper_bound); } sub do_view { $lower_bound = shift; $upper_bound = shift; BarnOwl::command("view", "-d", "perl", "BarnOwl::Module::TimeFilter::timefilter", @_); } sub cmd_view_after { shift; do_view( bad_parse_time(shift), undef, @_); } sub cmd_view_before { shift; do_view( undef, bad_parse_time(shift), @_); } sub cmd_view_between { shift; do_view( bad_parse_time(shift), bad_parse_time(shift), @_); } my $description = "\nThe time parsing is very stupid, it just breaks it into digit chunks.\n" . "You can append extra clauses, as in normal view -d, like `and class help`.\n" . "No parenthesization though."; BarnOwl::new_command("view-after" => \&cmd_view_after, { summary => "View zephyrs after a time", usage => "view-after 2001/09/09T01:46:40 [and class whatever...]", description => "View zephyrs after a time.$description" }); BarnOwl::new_command("view-before" => \&cmd_view_before, { summary => "View zephyrs before a time", usage => "view-before 2001/09/09T01:46:40 [and class whatever...]", description => "View zephyrs before a time.$description" }); BarnOwl::new_command("view-between" => \&cmd_view_between, { summary => "View zephyrs between two times", usage => "view-before 1969/2/2T02:02:02 2001/09/09T01:46:40 [and class whatever...]", description => "View zephyrs between two times.$description" }); 1;