aboutsummaryrefslogtreecommitdiffstats
path: root/tw_hooks/on-add_schedule_tg.pl
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2020-11-18 16:11:39 +0000
committerMatthew Lemon <lemon@matthewlemon.com>2020-11-18 16:11:39 +0000
commitd5e13c5a1e6ec2f4b5096a2012eac17ce935b068 (patch)
tree9124570e80c5defc43a975af1a2e0b331dc2c2c3 /tw_hooks/on-add_schedule_tg.pl
initial commit
Diffstat (limited to 'tw_hooks/on-add_schedule_tg.pl')
-rw-r--r--tw_hooks/on-add_schedule_tg.pl68
1 files changed, 68 insertions, 0 deletions
diff --git a/tw_hooks/on-add_schedule_tg.pl b/tw_hooks/on-add_schedule_tg.pl
new file mode 100644
index 0000000..a0690f5
--- /dev/null
+++ b/tw_hooks/on-add_schedule_tg.pl
@@ -0,0 +1,68 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature qw(say);
+use JSON;
+use DateTime;
+use DateTime::Format::ISO8601;
+
+# a test hook in Perl for taskwarrior
+
+# this must be JSON - this gets passed in my taskwarrior
+my $added_task = <STDIN>;
+
+my $hashref = decode_json $added_task;
+
+sub parse_scheduled
+{
+ my $sched_date = shift;
+ return DateTime::Format::ISO8601->parse_datetime($sched_date);
+}
+
+if ($hashref->{scheduled}) {
+ my $scheduled_dt = parse_scheduled $hashref->{scheduled};
+ print "Scheduled Date:\n";
+ print "---------------\n";
+ print "Year is: ".$scheduled_dt->year . "\n";
+ print "Month is: ".$scheduled_dt->month . "\n";
+ print "Day is: ".$scheduled_dt->day . "\n";
+ print "\n";
+}
+
+# if ($hashref->{scheduled}) {
+# my $sched_date = $hashref->{scheduled};
+# my $year = substr $sched_date, 0, 4;
+# my $month = substr $sched_date, 4, 2;
+# my $day = substr $sched_date, 6, 2;
+
+# my $dt = DateTime->new(
+# year => $year,
+# month => $month,
+# day => $day,
+# time_zone => 'Europe/London',
+# );
+
+# print "Year is: $dt->year" . "\n";
+# print "Month is: $dt->month" . "\n";
+# print "Day is: $dt->$day" . "\n";
+# print "\n";
+# }
+
+my $original_description = ${$hashref}{description};
+# my $original_description = $hashref->{description}; # alternative (and
+# preferred)
+
+my $tags = ${$hashref}{tags}; # alternative - not using -> in the ref
+
+$hashref->{description} = "DfT Task: " . $original_description if scalar grep {$_ eq "dft" } @{$tags};
+# same as
+# $hashref->{description} = "DfT Task: " . $original_description if scalar grep {$_ eq "dft" } @$tags;
+# You don't need the {} brackets! see perlreftut - The Rest section near the
+# end.
+
+my $output = encode_json $hashref;
+
+print $output;
+
+exit 0;