Skip to content

Commit 661f31a

Browse files
committed
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.
1 parent 02a0b1c commit 661f31a

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

lib/Synergy/Reactor/TimeClock.pm

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use experimental qw(signatures lexical_subs);
1111
use namespace::clean;
1212

1313
use Synergy::Logger '$Logger';
14-
use Synergy::Util qw(bool_from_text);
14+
use Synergy::Util qw(bool_from_text describe_business_hours);
1515

1616
use IO::Async::Timer::Periodic;
1717
use List::Util qw(max);
@@ -35,7 +35,7 @@ sub listener_specs {
3535
exclusive => 1,
3636
predicate => sub ($self, $e) {
3737
return unless $e->was_targeted;
38-
return $e->text =~ /\Ahours(\s+for)?\s+/;
38+
return $e->text =~ /\Ahours(\s+for)?\s+/i;
3939
}
4040
},
4141
{
@@ -185,11 +185,12 @@ sub handle_hours_for ($self, $event) {
185185
my $tz = $target->time_zone;
186186
my $tz_nick = $self->hub->env->time_zone_names->{ $tz } // $tz;
187187

188+
188189
return $event->reply(
189-
sprintf "%s's usual hours: %s, %s",
190+
sprintf "%s's usual hours (%s): %s",
190191
$target->username,
191-
$self->hub->user_directory->describe_user_preference($target, 'business-hours'),
192192
$tz_nick,
193+
describe_business_hours($target->business_hours, $target),
193194
);
194195
}
195196

lib/Synergy/Util.pm

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,14 +518,20 @@ sub validate_business_hours ($value) {
518518
return \%week_struct;
519519
}
520520

521-
sub describe_business_hours ($value) {
521+
sub describe_business_hours ($value, $user = undef) {
522522
my @wdays = qw(mon tue wed thu fri);
523523
my @wends = qw(sat sun);
524524

525525
my %desc = map {; keys($value->{$_}->%*)
526526
? ($_ => "$value->{$_}{start}-$value->{$_}{end}")
527527
: ($_ => '') } (@wdays, @wends);
528528

529+
if ($user) {
530+
for my $dow (keys %desc) {
531+
$desc{$dow} .= $user->is_wfh_on($dow) ? " \N{HOUSE WITH GARDEN}" : '';
532+
}
533+
}
534+
529535
return "None" unless any { length $_ } values %desc;
530536

531537
if ($desc{mon} && 7 == grep {; $desc{$_} eq $desc{mon} } (@wdays, @wends)) {

0 commit comments

Comments
 (0)