aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakub Kicinski <kuba@kernel.org>2023-12-08 10:41:52 -0800
committerDaniel Borkmann <daniel@iogearbox.net>2023-12-11 09:33:55 +0100
commit5704fc22d0089516eb40dfd7cb398de0d4b9837e (patch)
treed5827b211e4513ec4132de1183ae64f97df15f5e
parent950f706e31aa236c081a1e8bbb73a0ded170c3d8 (diff)
downloadpw-5704fc22d0089516eb40dfd7cb398de0d4b9837e.tar.gz
pw-apply: don't count weekend time in how long patch has been on the listHEADmaster
We recently started printing a warning when patches are applied before they spent 24h on the list. The motivation for that was to let reviewers from all time zones post their comments. To further improve reviewers' (chances of) work-life balance exclude weekend time from the 24h limit, meaning that the patch has to spent 24h of work day time on the list. This is useful when patches are posted on the list over the weekend and even tho they may be 2 days old for someone in the eastern / positive timezones the folks in western / negative timezones most likely haven't seen them. The "summary" line for a patch which timeline does not "straddle" weekend time remains unchanged: By: Some Person Age: 1d 11h Tree: net-next Version: 1 Patches: 2 but if weekend time was in the span (e.g. 10 hours) we'll see: By: Some Person Age: 1d 1h (+10h) Tree: net-next Version: 1 Patches: 2 We could say something like "weekend" next to the plus but its a long word and my terminals are 80 chars :S Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
-rw-r--r--lib.sh56
1 files changed, 53 insertions, 3 deletions
diff --git a/lib.sh b/lib.sh
index abf845c..2567c56 100644
--- a/lib.sh
+++ b/lib.sh
@@ -35,17 +35,67 @@ pr_trunc_n()
date_to_hours()
{
local past="$1"
+ local report_weekend="$2"
now=$(date +%s)
was=$(date -d "$past" +%s)
- echo $(( (now - was) / (60 * 60) ))
+ # Don't count "weekend time"; sow = Second Of the Week
+ # Epoch started on Thursday, so 3 day offset.
+ ep_off=$(( 3 * 24 * 60 * 60 ))
+ week_sec=$(( 7 * 24 * 60 * 60 ))
+ week_end=$(( 5 * 24 * 60 * 60 ))
+
+ now_sow=$(( (now+ep_off) % week_sec ))
+ was_sow=$(( (was+ep_off) % week_sec ))
+
+ delta=
+ if [ $now_sow -ge $was_sow -a $now_sow -le $week_end ]; then
+ # No adjustment, both during the same week, and no weekend
+ delta=0
+ elif [ $now_sow -lt $was_sow ]; then
+ # The week has wrapped, cut out 2 days
+ delta=$(( -48 * 60 * 60))
+ elif [ $now_sow -gt $week_end ]; then
+ # It's the weekend now, cut out weekend time
+ delta=$(( week_end - now_sow ))
+ else
+ delta=0
+ fi
+
+ if [ "$delta" != "0" -a $was_sow -gt $week_end ]; then
+ # Check if posted on the weekend
+ delta=$(( delta - (week_end - was_sow)))
+ fi
+
+ echo $(( (now - was + delta) / (60 * 60) ))
+ if [ ! -z "$report_weekend" ]; then
+ echo $((-delta / (60 * 60)))
+ fi
+}
+
+hours_days_fmt()
+{
+ local hours="$1"
+ local ds hs
+
+ [ $((hours / 24)) -gt 0 ] && ds="$((hours / 24))d"
+ [ $((hours % 24)) -gt 0 ] && hs="$((hours % 24))h"
+
+ echo $ds $hs
}
date_to_age()
{
- local hours=$(date_to_hours "$1")
- echo "$((hours / 24))d $((hours % 24))h"
+ local hour_cnt=( $(date_to_hours "$1" yes) )
+ local hours=${hour_cnt[0]}
+ local weekend=${hour_cnt[1]}
+
+ if [ "$weekend" -ne 0 ]; then
+ echo "$(hours_days_fmt "$hours") (+$(hours_days_fmt "$weekend"))"
+ else
+ echo "$(hours_days_fmt "$hours")"
+ fi
}
subject_remove_tag()