add workdays script

This commit is contained in:
Ingolf Wagner 2025-06-11 12:04:44 +02:00
parent 35bc98265c
commit fc9d34100a
3 changed files with 67 additions and 1 deletions
assets
flake.nix
homes/ingolf-wagner

59
assets/workdays.sh Normal file
View file

@ -0,0 +1,59 @@
#!/bin/bash
# Check if --lastmonth option is provided
if [[ "$1" == "--lastmonth" ]]; then
# Get last month's year and month
target_year=$(date -d "last month" +%Y)
target_month=$(date -d "last month" +%m)
target_month_name=$(date -d "last month" +%B)
period_description="last"
else
# Get current year and month
target_year=$(date +%Y)
target_month=$(date +%m)
target_month_name=$(date +%B)
period_description="current"
fi
# Get the number of days in the target month
days_in_month=$(date -d "${target_year}-${target_month}-01 +1 month -1 day" +%d)
# Initialize counters
weekday_count=0
saturday_count=0
sunday_count=0
# Loop through each day of the month
for day in $(seq 1 $days_in_month); do
# Get the day of the week (1=Monday, 7=Sunday)
day_of_week=$(date -d "${target_year}-${target_month}-${day}" +%u)
# Count days by type
if [[ $day_of_week -eq 6 ]]; then
((saturday_count++))
elif [[ $day_of_week -eq 7 ]]; then
((sunday_count++))
else
((weekday_count++))
fi
done
# Calculate total work hours (weekdays * 8 hours)
total_work_hours=$((weekday_count * 8))
total_weekend_days=$((saturday_count + sunday_count))
# Display the results as a table
echo "┌─────────────────────────────────────┬──────────────────────┐"
echo "│ Month Analysis │ Value │"
echo "├─────────────────────────────────────┼──────────────────────┤"
printf "│ %-35s │ %20s │\n" "Period" "$period_description"
printf "│ %-35s │ %20s │\n" "Month/Year" "$target_month_name $target_year"
echo "├─────────────────────────────────────┼──────────────────────┤"
printf "│ %-35s │ %20d │\n" "Total days in month" "$days_in_month"
printf "│ %-35s │ %20d │\n" "Weekdays (Mon-Fri)" "$weekday_count"
printf "│ %-35s │ %20d │\n" "Saturdays" "$saturday_count"
printf "│ %-35s │ %20d │\n" "Sundays" "$sunday_count"
printf "│ %-35s │ %20d │\n" "Total weekend days" "$total_weekend_days"
echo "├─────────────────────────────────────┼──────────────────────┤"
printf "│ %-35s │ %20d │\n" "Total Workhours (8h/weekday)" "$total_work_hours"
echo "└─────────────────────────────────────┴──────────────────────┘"

View file

@ -409,6 +409,7 @@
homeConfigurations.ingolf-wagner = home-manager.lib.homeManagerConfiguration {
pkgs = meta.pkgs;
extraSpecialArgs = {
assets = ./assets;
osConfig = {
networking.hostName = "jobrad-laptop";
};

View file

@ -1,4 +1,9 @@
{ pkgs, lib, ... }:
{
pkgs,
lib,
assets,
...
}:
{
imports = [
../palo
@ -24,6 +29,7 @@
pkgs.openconnect
pkgs.ferdium
pkgs.networkmanager-openconnect
(pkgs.writers.writeBashBin "workdays" (lib.fileContents "${assets}/workdays.sh"))
];
home.shellAliases = {