Lines 32-43
sub filter {
Link Here
|
32 |
$config->{with_hours} //= 0; |
32 |
$config->{with_hours} //= 0; |
33 |
|
33 |
|
34 |
my $dt = dt_from_string( $text, 'iso' ); |
34 |
my $dt = dt_from_string( $text, 'iso' ); |
|
|
35 |
$dt->add( %$_ ) for _parse_config_for_durations($config); # Allow date add/subtract; see _parse_config_for_durations |
35 |
|
36 |
|
36 |
return $config->{as_due_date} ? |
37 |
return $config->{as_due_date} ? |
37 |
output_pref({ dt => $dt, as_due_date => 1, dateformat => $config->{dateformat} }) : |
38 |
output_pref({ dt => $dt, as_due_date => 1, dateformat => $config->{dateformat} }) : |
38 |
output_pref({ dt => $dt, dateonly => !$config->{with_hours}, dateformat => $config->{dateformat} }); |
39 |
output_pref({ dt => $dt, dateonly => !$config->{with_hours}, dateformat => $config->{dateformat} }); |
39 |
} |
40 |
} |
40 |
|
41 |
|
|
|
42 |
sub _parse_config_for_durations { |
43 |
# Supports passing things like add_years => 1 or subtract_years => 1 |
44 |
# Same for months, weeks, days, hours, minutes or seconds |
45 |
# Returns a list of hashrefs like { years => 1 }, { days => -1 } that can be passed to dt->add |
46 |
my $config = shift; |
47 |
my @results; |
48 |
foreach my $entry ( keys %$config ) { |
49 |
if( $entry =~ /^(add|subtract)_(years|months|weeks|days|hours|minutes|seconds)$/ ) { |
50 |
push @results, { $2 => ( $1 eq 'add' ? 1 : -1 ) * $config->{$entry} }; |
51 |
} |
52 |
} |
53 |
return @results; |
54 |
} |
55 |
|
41 |
sub output_preference { |
56 |
sub output_preference { |
42 |
my ( $self, @params ) = @_; |
57 |
my ( $self, @params ) = @_; |
43 |
return output_pref( @params ); |
58 |
return output_pref( @params ); |
44 |
- |
|
|