From 661f31a089dd1bd0c3ffb1982a7a1ba753f5bad2 Mon Sep 17 00:00:00 2001 From: Michael McClimon Date: Fri, 24 Sep 2021 10:49:55 -0400 Subject: [PATCH] TimeClock: include wfh days in 'hours' output This required a small amount of finagling, because by default the pref describer function does not have access to the user it's describing. Possibly it should, but for now we'll just work around it. --- lib/Synergy/Reactor/TimeClock.pm | 9 +++++---- lib/Synergy/Util.pm | 8 +++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/Synergy/Reactor/TimeClock.pm b/lib/Synergy/Reactor/TimeClock.pm index 829d47ca..236115bd 100644 --- a/lib/Synergy/Reactor/TimeClock.pm +++ b/lib/Synergy/Reactor/TimeClock.pm @@ -11,7 +11,7 @@ use experimental qw(signatures lexical_subs); use namespace::clean; use Synergy::Logger '$Logger'; -use Synergy::Util qw(bool_from_text); +use Synergy::Util qw(bool_from_text describe_business_hours); use IO::Async::Timer::Periodic; use List::Util qw(max); @@ -35,7 +35,7 @@ sub listener_specs { exclusive => 1, predicate => sub ($self, $e) { return unless $e->was_targeted; - return $e->text =~ /\Ahours(\s+for)?\s+/; + return $e->text =~ /\Ahours(\s+for)?\s+/i; } }, { @@ -185,11 +185,12 @@ sub handle_hours_for ($self, $event) { my $tz = $target->time_zone; my $tz_nick = $self->hub->env->time_zone_names->{ $tz } // $tz; + return $event->reply( - sprintf "%s's usual hours: %s, %s", + sprintf "%s's usual hours (%s): %s", $target->username, - $self->hub->user_directory->describe_user_preference($target, 'business-hours'), $tz_nick, + describe_business_hours($target->business_hours, $target), ); } diff --git a/lib/Synergy/Util.pm b/lib/Synergy/Util.pm index 3f1bb120..90fdccb9 100644 --- a/lib/Synergy/Util.pm +++ b/lib/Synergy/Util.pm @@ -518,7 +518,7 @@ sub validate_business_hours ($value) { return \%week_struct; } -sub describe_business_hours ($value) { +sub describe_business_hours ($value, $user = undef) { my @wdays = qw(mon tue wed thu fri); my @wends = qw(sat sun); @@ -526,6 +526,12 @@ sub describe_business_hours ($value) { ? ($_ => "$value->{$_}{start}-$value->{$_}{end}") : ($_ => '') } (@wdays, @wends); + if ($user) { + for my $dow (keys %desc) { + $desc{$dow} .= $user->is_wfh_on($dow) ? " \N{HOUSE WITH GARDEN}" : ''; + } + } + return "None" unless any { length $_ } values %desc; if ($desc{mon} && 7 == grep {; $desc{$_} eq $desc{mon} } (@wdays, @wends)) {