Skip to content

Commit

Permalink
Take wellness days into account for working days count
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalchevrel committed Dec 1, 2023
1 parent bfeca9f commit 9703b9e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
16 changes: 10 additions & 6 deletions app/classes/ReleaseInsights/Duration.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@
*/
class Duration
{
public function __construct(public readonly Datetime $start, public readonly Datetime $end)
/** @var array<string> $wellness_days */
private array $wellness_days;

public function __construct(
public readonly Datetime $start,
public readonly Datetime $end)
{
$this->wellness_days = include DATA . 'wellness_days.php';
}

/**
Expand Down Expand Up @@ -44,11 +50,9 @@ public function weeks(): float
*/
public function isWorkDay(DateTime $day): bool
{
/**
* We only substract week-ends, we may add more logic to
* also remove wellness days in the future.
*/
return ! in_array($day->format('l'), ['Saturday','Sunday']);
// We substract week-ends and wellness days.
return ! in_array($day->format('l'), ['Saturday','Sunday'])
&& ! in_array($day->format('Y-m-d'), $this->wellness_days);
}

/**
Expand Down
16 changes: 16 additions & 0 deletions app/data/wellness_days.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

/*
Wellness days.
Those days are non-working days for all staff
*/

return [
'2024-02-16',
'2024-04-12',
'2024-07-05',
'2024-10-04',
];
4 changes: 3 additions & 1 deletion tests/Unit/ReleaseInsights/DurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
->toBeTrue();
expect($obj->isWorkDay(new DateTime('2023-11-11')))
->toBeFalse();
expect($obj->isWorkDay(new DateTime('2024-02-16')))
->toBeFalse();
});

test('Duration->workDays()', function () {
Expand All @@ -38,4 +40,4 @@
$obj = new Duration(new DateTime('2023-11-01'), new DateTime('2023-12-01'));
expect($obj->report())
->toHaveCount(3);
});
});
16 changes: 16 additions & 0 deletions tests/data/wellness_days.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

/*
Wellness days.
Those days are non-working days for all staff
*/

return [
'2024-02-16',
'2024-04-12',
'2024-07-05',
'2024-10-04',
];

0 comments on commit 9703b9e

Please sign in to comment.