Skip to content

Commit

Permalink
TimeClock: include wfh days in 'hours' output
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mmcclimon committed Sep 24, 2021
1 parent 02a0b1c commit 661f31a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
9 changes: 5 additions & 4 deletions lib/Synergy/Reactor/TimeClock.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
},
{
Expand Down Expand Up @@ -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),
);
}

Expand Down
8 changes: 7 additions & 1 deletion lib/Synergy/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -518,14 +518,20 @@ 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);

my %desc = map {; keys($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)) {
Expand Down

0 comments on commit 661f31a

Please sign in to comment.