| 1 | package SVK::Log::Filter::Date; | ||
| 2 | |||
| 3 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 1 | ▶ | use base qw( SVK::Log::Filter::Selection ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | use Date::PeriodParser qw( parse_period ); | ||
| 8 | use Time::Local qw( timegm ); | ||
| 9 | |||
| 10 | our $VERSION = '0.0.1'; | ||
| 11 | |||
| 12 | sub setup { | ||
| 13 | my ($self) = @_; | ||
| 14 | |||
| 15 | my $period = $self->{argument} || q{}; | ||
| 16 | my ( $from, $to ) = parse_period($period); | ||
| 17 | |||
| 18 | # validate the date range | ||
| 19 | die "Can't parse the period '$period' : $to\n" | ||
| 20 | if $from == -1; | ||
| 21 | |||
| 22 | # store the date ranges for later | ||
| 23 | $self->{from} = $from; | ||
| 24 | $self->{to} = $to; | ||
| 25 | |||
| 26 | return; | ||
| 27 | } | ||
| 28 | |||
| 29 | sub revision { | ||
| 30 | my ($self, $args) = @_; | ||
| 31 | |||
| 32 | # we need a commit date (Is there ever not a svn:date property?) | ||
| 33 | my $date = $args->{props}->{'svn:date'}; | ||
| 34 | $self->pipeline('next') if !$date; | ||
| 35 | |||
| 36 | # can we parse the date | ||
| 37 | my $commit_time = $self->date_to_epoch($date) | ||
| 38 | or $self->pipeline('next'); | ||
| 39 | |||
| 40 | # skip revisions that are too late | ||
| 41 | $self->pipeline('next') if $commit_time > $self->{to}; | ||
| 42 | |||
| 43 | # stop the pipeline entirely if a revision is too early | ||
| 44 | $self->pipeline('last') if $commit_time < $self->{from}; | ||
| 45 | |||
| 46 | return; | ||
| 47 | } | ||
| 48 | |||
| 49 | sub date_to_epoch { | ||
| 50 | my ($self, $svn_date) = @_; | ||
| 51 | |||
| 52 | # parse the date | ||
| 53 | my ($y, $M, $d, $h, $m, $s) = split(/[-T:.Z]/, $svn_date) | ||
| 54 | or return; | ||
| 55 | |||
| 56 | # normalize the date parts to match what timegm() expects | ||
| 57 | $y -= 1900; | ||
| 58 | $M--; | ||
| 59 | return timegm( $s, $m, $h, $d, $M, $y ); | ||
| 60 | } | ||
| 61 | |||
| 62 | 1; | ||
| 63 | |||
| 64 | __END__ | ||