Lines 32-37
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} }) : |
Lines 42-47
sub datetime_from_string {
Link Here
|
42 |
my ( $self, @params ) = @_; |
43 |
my ( $self, @params ) = @_; |
43 |
return dt_from_string( @params ); |
44 |
return dt_from_string( @params ); |
44 |
} |
45 |
} |
|
|
46 |
sub _parse_config_for_durations { |
47 |
# Supports passing things like add_years => 1 or subtract_years => 1 |
48 |
# Same for months, weeks, days, hours, minutes or seconds |
49 |
# Returns a list of hashrefs like { years => 1 }, { days => -1 } that can be passed to dt->add |
50 |
my $config = shift; |
51 |
my @results; |
52 |
foreach my $entry ( keys %$config ) { |
53 |
if( $entry =~ /^(add|subtract)_(years|months|weeks|days|hours|minutes|seconds)$/ ) { |
54 |
push @results, { $2 => ( $1 eq 'add' ? 1 : -1 ) * $config->{$entry} }; |
55 |
} |
56 |
} |
57 |
return @results; |
58 |
} |
45 |
|
59 |
|
46 |
sub output_preference { |
60 |
sub output_preference { |
47 |
my ( $self, @params ) = @_; |
61 |
my ( $self, @params ) = @_; |
48 |
- |
|
|