Bläddra i källkod

Adding Correct Weeknumbers

Bash script to output week number as 01 to 52 or 53 depending on the
year
master
Nate Bohman 5 år sedan
förälder
incheckning
60bbf1cf93
1 ändrade filer med 35 tillägg och 0 borttagningar
  1. +35
    -0
      correct_weeknumbers.sh

+ 35
- 0
correct_weeknumbers.sh Visa fil

@@ -0,0 +1,35 @@
#!/usr/bin/env bash

# Print out the correct week number with rollover

WEEKNUM=$(printf %02d $(($(date +"%U" -d "next saturday") + $(if [ "$(date +"%A" -d "$(date +"%Y")-01-01")" == "Sunday" ]; then echo "0"; else echo "1"; fi))))

echo ${WEEKNUM}

#$ for year in 20{19..31}; do for month_day in "1-1" "12-25"; do for day in {0..6}; do if [ $(date -d "${year}-${month_day} + ${day} day" +"%u") == 6 ]; then echo "$(printf %02d $(($(date +"%U" -d "${year}-${month_day} + ${day} day") + $(if [ "$(date +"%A" -d "${year}-01-01")" == "Sunday" ]; then echo "0"; else echo "1"; fi)))) - $(date -d "${year}-${month_day}")"; fi; done; done; done
#01 - Tue 01 Jan 2019 12:00:00 AM MST
#52 - Wed 25 Dec 2019 12:00:00 AM MST
#01 - Wed 01 Jan 2020 12:00:00 AM MST
#52 - Fri 25 Dec 2020 12:00:00 AM MST
#01 - Fri 01 Jan 2021 12:00:00 AM MST
#52 - Sat 25 Dec 2021 12:00:00 AM MST
#01 - Sat 01 Jan 2022 12:00:00 AM MST
#53 - Sun 25 Dec 2022 12:00:00 AM MST
#01 - Sun 01 Jan 2023 12:00:00 AM MST
#52 - Mon 25 Dec 2023 12:00:00 AM MST
#01 - Mon 01 Jan 2024 12:00:00 AM MST
#52 - Wed 25 Dec 2024 12:00:00 AM MST
#01 - Wed 01 Jan 2025 12:00:00 AM MST
#52 - Thu 25 Dec 2025 12:00:00 AM MST
#01 - Thu 01 Jan 2026 12:00:00 AM MST
#52 - Fri 25 Dec 2026 12:00:00 AM MST
#01 - Fri 01 Jan 2027 12:00:00 AM MST
#52 - Sat 25 Dec 2027 12:00:00 AM MST
#01 - Sat 01 Jan 2028 12:00:00 AM MST
#53 - Mon 25 Dec 2028 12:00:00 AM MST
#01 - Mon 01 Jan 2029 12:00:00 AM MST
#52 - Tue 25 Dec 2029 12:00:00 AM MST
#01 - Tue 01 Jan 2030 12:00:00 AM MST
#52 - Wed 25 Dec 2030 12:00:00 AM MST
#01 - Wed 01 Jan 2031 12:00:00 AM MST
#52 - Thu 25 Dec 2031 12:00:00 AM MST

Laddar…
Avbryt
Spara