| 1 | package App::ListOrgAnniversaries; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Log::ger; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use App::OrgUtils; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Cwd qw(abs_path); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use DateTime; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Digest::MD5 qw(md5_hex); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Lingua::EN::Numbers::Ordinate; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | our $DATE = '2026-07-22'; # DATE | |||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | our $DIST = 'App-OrgUtils'; # DIST | |||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | our $VERSION = '0.489'; # VERSION | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | our @EXPORT_OK = qw(list_org_anniversaries); | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | our %SPEC; | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | my $today; | |||||||||||||||||||||||||||||||||||||||||
| 25 | my $yest; | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub _process_hl { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_hl: not called CC=36 SCAR=71.9
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | my ($file, $hl, $args, $res, $tz) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | return unless $hl->is_leaf; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | log_trace("Processing %s ...", $hl->title->as_string); | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | if ($args->{has_tags} || $args->{lacks_tags}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args->{"has_tags"} or $args->{"lacks_tags"}
MC/DC0%0/2
$args->{"has_tags"} or $args->{"lacks_tags"}
$args->{"has_tags"}
$args->{"lacks_tags"}
Truth table0%0/3
A or B
A= $args->{"has_tags"}B= $args->{"lacks_tags"}
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | my $tags = [$hl->get_tags]; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | if ($args->{has_tags}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | for my $tag (@{ $args->{has_tags} }) { | |||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | return unless grep { $_ eq $tag } @$tags; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | if ($args->{lacks_tags}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | for my $tag (@{ $args->{lacks_tags} }) { | |||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | return if grep { $_ eq $tag } @$tags; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | my @annivs; # elem = [$field, $date, $date_reminded] | |||||||||||||||||||||||||||||||||||||||||
| 49 | $hl->walk( | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=13 SCAR=52.0
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | my ($el) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | if ($el->isa('Org::Element::Timestamp')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | my $field = $el->field_name; | |||||||||||||||||||||||||||||||||||||||||
| 55 | return unless defined($field) && | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | $field =~ $args->{field_pattern}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $field and $field =~ /$args->{"field_pattern"}/
MC/DC0%0/2
defined $field and $field =~ /$args->{"field_pattern"}/
defined $field
$field =~ /$args->{"field_pattern"}/
Truth table0%0/3
A and B
A= defined $fieldB= $field =~ /$args->{"field_pattern"}/
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if ($field =~ $args->{reminded_field_pattern} && @annivs) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$field =~ /$args->{"reminded_field_pattern"}/ and @annivs
MC/DC0%0/2
$field =~ /$args->{"reminded_field_pattern"}/ and @annivs
$field =~ /$args->{"reminded_field_pattern"}/
@annivs
Truth table0%0/3
A and B
A= $field =~ /$args->{"reminded_field_pattern"}/B= @annivs
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | $annivs[-1][2] = $el->datetime; | |||||||||||||||||||||||||||||||||||||||||
| 59 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | push @annivs, [$field, $el->datetime]; | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if ($el->isa('Org::Element::Drawer') && $el->name eq 'PROPERTIES') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$el->isa("Org::Element::Drawer") and $el->name eq "PROPERTIES"
MC/DC0%0/2
$el->isa("Org::Element::Drawer") and $el->name eq "PROPERTIES"
$el->isa("Org::Element::Drawer")
$el->name eq "PROPERTIES"
Truth table0%0/3
A and B
A= $el->isa("Org::Element::Drawer")B= $el->name eq "PROPERTIES"
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | my $props = $el->properties; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | for my $k (keys %$props) { | |||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | next unless $k =~ $args->{field_pattern}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | my $v = $props->{$k}; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | unless ($v =~ /^\s*(\d{4})-(\d{2})-(\d{2})\s*$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | log_warn("Invalid date format $v, ". | |||||||||||||||||||||||||||||||||||||||||
| 71 | "must be YYYY-MM-DD"); | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if ($k =~ $args->{reminded_field_pattern} && @annivs) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$k =~ /$args->{"reminded_field_pattern"}/ and @annivs
MC/DC0%0/2
$k =~ /$args->{"reminded_field_pattern"}/ and @annivs
$k =~ /$args->{"reminded_field_pattern"}/
@annivs
Truth table0%0/3
A and B
A= $k =~ /$args->{"reminded_field_pattern"}/B= @annivs
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | $annivs[-1][2] = $el->datetime; | |||||||||||||||||||||||||||||||||||||||||
| 76 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | push @annivs, [ | |||||||||||||||||||||||||||||||||||||||||
| 78 | lc $k, | ||||||||||||||||||||||||||||||||||||||||||
| 79 | DateTime->new(year=>$1, month=>$2, day=>$3, | ||||||||||||||||||||||||||||||||||||||||||
| 80 | time_zone=>$tz), | ||||||||||||||||||||||||||||||||||||||||||
| 81 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | if (!@annivs) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | log_debug("Headline doesn't contain anniversary fields, skipped"); | |||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | ANNIV: | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | for my $anniv (@annivs) { | |||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | my ($field, $date, $date_reminded) = @$anniv; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | log_debug("Anniversary found: field=%s, date=%s, date reminded=%s", | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | $field, $date->ymd, $date_reminded ? $date_reminded->ymd : undef); | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | my $y = $today->year - $date->year; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | my $date_ly = $date->clone; $date_ly->add(years => $y-1); | |||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | my $date_ty = $date->clone; $date_ty->add(years => $y ); | |||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | my $date_ny = $date->clone; $date_ny->add(years => $y+1); | |||||||||||||||||||||||||||||||||||||||||
| 103 | DATE: | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | for my $d ($date_ly, $date_ty, $date_ny) { | |||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | my $days = ($d < $today ? -1:1) * $d->delta_days($today)->in_units('days'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | next if defined($args->{due_in}) && | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | $days > $args->{due_in}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $args->{"due_in"} and $days > $args->{"due_in"}
MC/DC0%0/2
defined $args->{"due_in"} and $days > $args->{"due_in"}
defined $args->{"due_in"}
$days > $args->{"due_in"}
Truth table0%0/3
A and B
A= defined $args->{"due_in"}B= $days > $args->{"due_in"}
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | next if defined($args->{max_overdue}) && | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | -$days > $args->{max_overdue}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $args->{"max_overdue"} and -$days > $args->{"max_overdue"}
MC/DC0%0/2
defined $args->{"max_overdue"} and -$days > $args->{"max_overdue"}
defined $args->{"max_overdue"}
-$days > $args->{"max_overdue"}
Truth table0%0/3
A and B
A= defined $args->{"max_overdue"}B= -$days > $args->{"max_overdue"}
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | next if !defined($args->{due_in}) && | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | !defined($args->{max_overdue}) && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not defined $args->{"due_in"} || defined $args->{"max_overdue"} and "DateTime"->compare($d, $today) < 0
defined $args->{'due_in'} || defined $args->{'max_overdue'}
MC/DC0%0/3
not defined $args->{"due_in"} || defined $args->{"max_overdue"} and "DateTime"->compare($d, $today) < 0
defined $args->{'due_in'}
defined $args->{'max_overdue'}
"DateTime"->compare($d, $today) < 0
Truth table0%0/4
not(A || B) and C
A= defined $args->{'due_in'}B= defined $args->{'max_overdue'}C= "DateTime"->compare($d, $today) < 0
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | DateTime->compare($d, $today) < 0; | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | REMINDED: { | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | if ($date_reminded) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | my $days_reminded; | |||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | $days_reminded = ($date_reminded < $today ? -1:1) * | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | $date_reminded->delta_days($today)->in_units('days'); | ||||||||||||||||||||||||||||||||||||||||||
| 119 | last REMINDED if defined($args->{due_in}) && | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | $days_reminded > $args->{due_in}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $args->{"due_in"} and $days_reminded > $args->{"due_in"}
MC/DC0%0/2
defined $args->{"due_in"} and $days_reminded > $args->{"due_in"}
defined $args->{"due_in"}
$days_reminded > $args->{"due_in"}
Truth table0%0/3
A and B
A= defined $args->{"due_in"}B= $days_reminded > $args->{"due_in"}
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | last REMINDED if defined($args->{max_overdue}) && | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | -$days_reminded > $args->{max_overdue}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $args->{"max_overdue"} and -$days_reminded > $args->{"max_overdue"}
MC/DC0%0/2
defined $args->{"max_overdue"} and -$days_reminded > $args->{"max_overdue"}
defined $args->{"max_overdue"}
-$days_reminded > $args->{"max_overdue"}
Truth table0%0/3
A and B
A= defined $args->{"max_overdue"}B= -$days_reminded > $args->{"max_overdue"}
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | last REMINDED if !defined($args->{due_in}) && | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | !defined($args->{max_overdue}) && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not defined $args->{"due_in"} || defined $args->{"max_overdue"} and "DateTime"->compare($date_reminded, $today) < 0
defined $args->{'due_in'} || defined $args->{'max_overdue'}
MC/DC0%0/3
not defined $args->{"due_in"} || defined $args->{"max_overdue"} and "DateTime"->compare($date_reminded, $today) < 0
defined $args->{'due_in'}
defined $args->{'max_overdue'}
"DateTime"->compare($date_reminded, $today) < 0
Truth table0%0/4
not(A || B) and C
A= defined $args->{'due_in'}B= defined $args->{'max_overdue'}C= "DateTime"->compare($date_reminded, $today) < 0
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | DateTime->compare($date_reminded, $today) < 0; | ||||||||||||||||||||||||||||||||||||||||||
| 126 | #log_debug("Anniversary already reminded, skipped"); | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | next DATE; | |||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | my $pl = abs($days) > 1 ? "s" : ""; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | my $hide_age = $date->year == 1900; | |||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | my $msg = sprintf( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | "%s (%s): %s of %s (%s)", | ||||||||||||||||||||||||||||||||||||||||||
| 135 | $days == 0 ? "today" : | ||||||||||||||||||||||||||||||||||||||||||
| 136 | $days < 0 ? abs($days)." day$pl ago" : | ||||||||||||||||||||||||||||||||||||||||||
| 137 | "in $days day$pl", | ||||||||||||||||||||||||||||||||||||||||||
| 138 | $d->strftime("%a"), | ||||||||||||||||||||||||||||||||||||||||||
| 139 | $hide_age ? $field : | ||||||||||||||||||||||||||||||||||||||||||
| 140 | ordinate($d->year - $date->year)." $field", | ||||||||||||||||||||||||||||||||||||||||||
| 141 | $hl->title->as_string, | ||||||||||||||||||||||||||||||||||||||||||
| 142 | $hide_age ? $d->ymd : $date->ymd . " - " . $d->ymd); | ||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | log_debug("Added this anniversary to result: %s", $msg); | |||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | push @$res, [$msg, $d]; | |||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | last DATE; | |||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | } # for @annivs | ||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | $SPEC{list_org_anniversaries} = { | ||||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | v => 1.1, | |||||||||||||||||||||||||||||||||||||||||
| 152 | summary => 'List all anniversaries in Org files', | ||||||||||||||||||||||||||||||||||||||||||
| 153 | description => <<'MARKDOWN', | ||||||||||||||||||||||||||||||||||||||||||
| 154 | This function expects contacts in the following format: | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | * First last :office:friend: | ||||||||||||||||||||||||||||||||||||||||||
| 157 | :PROPERTIES: | ||||||||||||||||||||||||||||||||||||||||||
| 158 | :BIRTHDAY: 1900-06-07 | ||||||||||||||||||||||||||||||||||||||||||
| 159 | :EMAIL: foo@example.com | ||||||||||||||||||||||||||||||||||||||||||
| 160 | :OTHERFIELD: ... | ||||||||||||||||||||||||||||||||||||||||||
| 161 | :END: | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | or: | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | * Some name :office: | ||||||||||||||||||||||||||||||||||||||||||
| 166 | - birthday :: [1900-06-07 ] | ||||||||||||||||||||||||||||||||||||||||||
| 167 | - email :: foo@example.com | ||||||||||||||||||||||||||||||||||||||||||
| 168 | - otherfield :: ... | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | Using PROPERTIES, dates currently must be specified in "YYYY-MM-DD" format. | ||||||||||||||||||||||||||||||||||||||||||
| 171 | Other format will be supported in the future. Using description list, dates can | ||||||||||||||||||||||||||||||||||||||||||
| 172 | be specified using normal Org timestamps (repeaters and warning periods will be | ||||||||||||||||||||||||||||||||||||||||||
| 173 | ignored). | ||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | By convention, if year is '1900' it is assumed to mean year is not specified. | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | By default, all contacts' anniversaries will be listed. You can filter contacts | ||||||||||||||||||||||||||||||||||||||||||
| 178 | using tags ('has_tags' and 'lacks_tags' options), or by 'due_in' and | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 'max_overdue' options (due_in=14 and max_overdue=7 is what I commonly use in my | ||||||||||||||||||||||||||||||||||||||||||
| 180 | startup script). | ||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | If you have acted on someone's birthday or anniversary, you can add another | ||||||||||||||||||||||||||||||||||||||||||
| 183 | field with name: the anniversary field + " reminded" (this is customizable using | ||||||||||||||||||||||||||||||||||||||||||
| 184 | the options `reminded_field_pattern`). For example: | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | * First last :office:friend: | ||||||||||||||||||||||||||||||||||||||||||
| 187 | :PROPERTIES: | ||||||||||||||||||||||||||||||||||||||||||
| 188 | :BIRTHDAY: 1900-06-07 | ||||||||||||||||||||||||||||||||||||||||||
| 189 | :BIRTHDAY_REMINDED: 2020-06-08 | ||||||||||||||||||||||||||||||||||||||||||
| 190 | :EMAIL: foo@example.com | ||||||||||||||||||||||||||||||||||||||||||
| 191 | :OTHERFIELD: ... | ||||||||||||||||||||||||||||||||||||||||||
| 192 | :END: | ||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | or: | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | * Some name :office: | ||||||||||||||||||||||||||||||||||||||||||
| 197 | - birthday :: [1900-06-07 ] | ||||||||||||||||||||||||||||||||||||||||||
| 198 | - birthday reminded :: [2020-06-09] | ||||||||||||||||||||||||||||||||||||||||||
| 199 | - email :: foo@example.com | ||||||||||||||||||||||||||||||||||||||||||
| 200 | - otherfield :: ... | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | and the reminder will not be shown again. | ||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | MARKDOWN | ||||||||||||||||||||||||||||||||||||||||||
| 205 | args => { | ||||||||||||||||||||||||||||||||||||||||||
| 206 | %App::OrgUtils::common_args1, | ||||||||||||||||||||||||||||||||||||||||||
| 207 | field_pattern => { | ||||||||||||||||||||||||||||||||||||||||||
| 208 | summary => 'Regex for fields that specify anniversaries', | ||||||||||||||||||||||||||||||||||||||||||
| 209 | schema => 're*', | ||||||||||||||||||||||||||||||||||||||||||
| 210 | default => qr/(?:birthday|dob|date of birth|anniversary)/i, | ||||||||||||||||||||||||||||||||||||||||||
| 211 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 212 | reminded_field_pattern => { | ||||||||||||||||||||||||||||||||||||||||||
| 213 | schema => 're*', | ||||||||||||||||||||||||||||||||||||||||||
| 214 | default => qr/reminded/i, | ||||||||||||||||||||||||||||||||||||||||||
| 215 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 216 | reminded_suffix => { | ||||||||||||||||||||||||||||||||||||||||||
| 217 | schema => 'str*', | ||||||||||||||||||||||||||||||||||||||||||
| 218 | default => ' reminded', | ||||||||||||||||||||||||||||||||||||||||||
| 219 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 220 | has_tags => { | ||||||||||||||||||||||||||||||||||||||||||
| 221 | summary => 'Filter headlines that have the specified tags', | ||||||||||||||||||||||||||||||||||||||||||
| 222 | schema => [array => {of => 'str*'}], | ||||||||||||||||||||||||||||||||||||||||||
| 223 | element_completion => $App::OrgUtils::_complete_tags, | ||||||||||||||||||||||||||||||||||||||||||
| 224 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 225 | lacks_tags => { | ||||||||||||||||||||||||||||||||||||||||||
| 226 | summary => 'Filter headlines that don\'t have the specified tags', | ||||||||||||||||||||||||||||||||||||||||||
| 227 | schema => [array => {of => 'str*'}], | ||||||||||||||||||||||||||||||||||||||||||
| 228 | element_completion => $App::OrgUtils::_complete_tags, | ||||||||||||||||||||||||||||||||||||||||||
| 229 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 230 | due_in => { | ||||||||||||||||||||||||||||||||||||||||||
| 231 | summary => 'Only show anniversaries that are due '. | ||||||||||||||||||||||||||||||||||||||||||
| 232 | 'in this number of days', | ||||||||||||||||||||||||||||||||||||||||||
| 233 | schema => ['int'], | ||||||||||||||||||||||||||||||||||||||||||
| 234 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 235 | max_overdue => { | ||||||||||||||||||||||||||||||||||||||||||
| 236 | summary => 'Don\'t show dates that are overdue '. | ||||||||||||||||||||||||||||||||||||||||||
| 237 | 'more than this number of days', | ||||||||||||||||||||||||||||||||||||||||||
| 238 | schema => ['int'], | ||||||||||||||||||||||||||||||||||||||||||
| 239 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 240 | today => { | ||||||||||||||||||||||||||||||||||||||||||
| 241 | summary => 'Assume today\'s date', | ||||||||||||||||||||||||||||||||||||||||||
| 242 | schema => [obj => isa=>'DateTime'], | ||||||||||||||||||||||||||||||||||||||||||
| 243 | description => <<'MARKDOWN', | ||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | You can provide Unix timestamp or DateTime object. If you provide a DateTime | ||||||||||||||||||||||||||||||||||||||||||
| 246 | object, remember to set the correct time zone. | ||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | MARKDOWN | ||||||||||||||||||||||||||||||||||||||||||
| 249 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 250 | sort => { | ||||||||||||||||||||||||||||||||||||||||||
| 251 | summary => 'Specify sorting', | ||||||||||||||||||||||||||||||||||||||||||
| 252 | schema => [any => { | ||||||||||||||||||||||||||||||||||||||||||
| 253 | of => [ | ||||||||||||||||||||||||||||||||||||||||||
| 254 | ['str*' => {in=>['due_date', '-due_date']}], | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 'code*', | ||||||||||||||||||||||||||||||||||||||||||
| 256 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 257 | default => 'due_date', | ||||||||||||||||||||||||||||||||||||||||||
| 258 | }], | ||||||||||||||||||||||||||||||||||||||||||
| 259 | description => <<'MARKDOWN', | ||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | If string, must be one of 'date', '-date' (descending). | ||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||
| 263 | If code, sorting code will get [REC, DUE_DATE] as the items to compare, where | ||||||||||||||||||||||||||||||||||||||||||
| 264 | REC is the final record that will be returned as final result (can be a string | ||||||||||||||||||||||||||||||||||||||||||
| 265 | or a hash, if 'detail' is enabled), and DUE_DATE is the DateTime object. | ||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | MARKDOWN | ||||||||||||||||||||||||||||||||||||||||||
| 268 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 269 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 270 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | ▶ | sub list_org_anniversaries { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_org_anniversaries: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | require Org::Parser; | |||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | my $sort = $args{sort}; | |||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | my $tz = $args{time_zone} // $ENV{TZ} // "UTC"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/5
($args{"time_zone"} // $ENV{"TZ"}) // "UTC"
$args{"time_zone"} // $ENV{"TZ"}
MC/DC0%0/2
($args{"time_zone"} // $ENV{"TZ"}) // "UTC"
$args{"time_zone"}
$ENV{"TZ"}
Truth table0%0/3
A // B
A= $args{"time_zone"}B= $ENV{"TZ"}
| |||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | my $files = $args{files}; | |||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | $args{field_pattern} //= qr/(?:birthday|anniversary)/i; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args{"field_pattern"} //= qr/(?:birthday|anniversary)/i
MC/DC0%0/1
$args{"field_pattern"} //= qr/(?:birthday|anniversary)/i
$args{"field_pattern"}
Truth table0%0/2
A
A= $args{"field_pattern"}
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | ▶ | $args{reminded_field_pattern} //= qr/reminded/i; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args{"reminded_field_pattern"} //= qr/reminded/i
MC/DC0%0/1
$args{"reminded_field_pattern"} //= qr/reminded/i
$args{"reminded_field_pattern"}
Truth table0%0/2
A
A= $args{"reminded_field_pattern"}
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | ▶ | $today = $args{today} // DateTime->today(time_zone => $tz); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$args{"today"} // "DateTime"->today("time_zone", $tz)
MC/DC0%0/2
$args{"today"} // "DateTime"->today("time_zone", $tz)
$args{"today"}
"DateTime"->today("time_zone", $tz)
Truth table0%0/3
A // B
A= $args{"today"}B= "DateTime"->today("time_zone", $tz)
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | $yest = $today->clone->add(days => -1); | |||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | my $orgp = Org::Parser->new( | |||||||||||||||||||||||||||||||||||||||||
| 287 | ignore_unknown_drawers => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 288 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | my @res; | |||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | my %docs = App::OrgUtils::_load_org_files( | |||||||||||||||||||||||||||||||||||||||||
| 292 | $files, {time_zone=>$tz}); | ||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | for my $file (keys %docs) { | |||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | my $doc = $docs{$file}; | |||||||||||||||||||||||||||||||||||||||||
| 295 | $doc->walk( | ||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | my ($el) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | return unless $el->isa('Org::Element::Headline'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | _process_hl($file, $el, \%args, \@res, $tz); | |||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | ▶ | if ($sort) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | if (ref($sort) eq 'CODE') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | @res = sort $sort @res; | |||||||||||||||||||||||||||||||||||||||||
| 306 | } elsif ($sort =~ /^-?due_date$/) { | ||||||||||||||||||||||||||||||||||||||||||
| 307 | @res = sort { | ||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | my $dt1 = $a->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | my $dt2 = $b->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | my $comp = DateTime->compare($dt1, $dt2); | |||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | ▶ | ($sort =~ /^-/ ? -1 : 1) * $comp; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | } @res; | ||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | [200, "OK", [map {$_->[0]} @res], | |||||||||||||||||||||||||||||||||||||||||
| 317 | {result_format_opts=>{list_max_columns=>1}}]; | ||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 321 | # ABSTRACT: List all anniversaries in Org files | ||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | __END__ | ||||||||||||||||||||||||||||||||||||||||||