-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgenerate-workingdays-sheet
executable file
·73 lines (61 loc) · 2 KB
/
generate-workingdays-sheet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env bash
#
# Generate working days sheet.
dir=${XDG_VAR_HOME:-$HOME/var}/lib/workingdays
declare -A off=()
date_fmt=%-Y%t%-m%t%-d%t%-j%t%-q%t%-V%t%-u%t
for y in "${@:-$(printf '%(%Y)T')}"; do
{
dir=$dir/$y
printf %d "$y" 1>/dev/null && command -- mkdir -p -- "$dir" ||
exit
command -- touch -- "$dir/"{holiday,urlaub{stageanzahl,},sick}.txt
esunday=$(exec -- date --date="$(exec -- ncal -e "$y")" +%F)
# berlin:
#
# neujahr, internationaler_frauentag, tag_der_{arbeit,deutschen_einheit},
# [12]._weihnachtstag, karfreitag, ostermontag, christi_himmelfahrt, pfingstmontag,
# extra holidays and urlaub
eval "$(
date --file /dev/stdin +off["%F"]=\"${date_fmt}holiday\" <<-IN
$y-01-01
$y-03-08
$y-05-01
$y-10-03
$y-12-25
$y-12-26
$esunday - 2 days
$esunday + 1 day
$esunday + 39 days
$esunday + 50 days
IN
for f in "$dir/"{holiday,urlaub,sick}.txt; do
t=${f%.txt}
t=${t##*/}
exec -- sed -n 's:^\([^\t]\{4\}\)\t\([^\t]\{2\}\)\t\([^\t]\{2\}\)$:\1-\2-\3:p' "$f" |
exec -- date --file /dev/stdin +off["%F"]=\"$date_fmt$t\" &
done
wait
)"
{
for m in {01..12}; do
{
declare -a days="({01..$(exec -- date --date="$y-$m-01 + 1 month - 1 day" +%d)})"
for d in "${days[@]}"; do
if [[ -n ${off["$y-$m-$d"]} ]]; then
printf '%s\n' "${off["$y-$m-$d"]}"
else
exec -- date --date=$y-$m-$d "+${date_fmt}work"
fi &
done
wait
} &
done
wait
} |
exec -- sort -k 4,4n |
exec -- sed '/[67]\twork$/ s:work:weekend:' >"$dir/year.txt"
} &
done
wait
# vim: set ft=zsh :