Skip to content

Conversation

alpaca-tc
Copy link

Description:

Add support for excluding specific weekdays when calculating elapsed days for stale issues and PRs. This is particularly useful for organizations that want to consider only business days.

  • Add new exclude-weekdays option to specify which days to exclude (0-6, where 0 is Sunday)
  • Implement weekday exclusion logic in elapsed days calculation
  • Add tests to verify business days calculation
- uses: actions/stale@v9
  with:
    days-before-stale: 5
    days-before-close: 2
    exclude-weekdays: '0,6'  # Exclude weekends

Related issue:

Fixed #564

Check list:

  • Mark if documentation changes are required.
  • Mark if tests were added or updated to cover the changes.

@alpaca-tc alpaca-tc requested a review from a team as a code owner March 7, 2025 10:58
Fixed actions#564

Add support for excluding specific weekdays when calculating elapsed days for stale issues and PRs. This is particularly useful for organizations that want to consider only business days.

- Add new `exclude-weekdays` option to specify which days to exclude (0-6, where 0 is Sunday)
- Implement weekday exclusion logic in elapsed days calculation
- Add tests to verify business days calculation

```yaml
- uses: actions/stale@v9
  with:
    days-before-stale: 5
    days-before-close: 2
    exclude-weekdays: '0,6'  # Exclude weekends
```
@alpaca-tc alpaca-tc force-pushed the add-exclude-weekdays branch from 1403262 to 524c3cd Compare March 7, 2025 13:41
Comment on lines +2375 to +2388
let elapsedMillis = to.getTime() - from.getTime();
if (excludeWeekdays.length > 0) {
const startOfNextDayFrom = startOfDay(new Date(from.getTime() + DAY));
const startOfDayTo = startOfDay(to);
if (excludeWeekdays.includes(from.getDay())) {
elapsedMillis -= startOfNextDayFrom.getTime() - from.getTime();
}
if (excludeWeekdays.includes(to.getDay())) {
elapsedMillis -= to.getTime() - startOfDayTo.getTime();
}
const excludeWeekdaysCount = countWeekdaysBetweenDates(startOfNextDayFrom, startOfDayTo, excludeWeekdays);
elapsedMillis -= excludeWeekdaysCount * DAY;
}
return elapsedMillis;
Copy link
Author

@alpaca-tc alpaca-tc Mar 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't use options, the existing implementation is used, so even if there are bugs, the impact is minimal. A simple O(N) calculation logic is used. While an O(1) logic could also be possible, it would be a bit more complex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow option to exclude weekends from total time

1 participant