From: Steven Baltakatei Sandoval Date: Tue, 11 Apr 2023 20:40:58 +0000 (+0000) Subject: temp(user/mw_create_redirect_day_month.sh):Save changes X-Git-Url: https://zdv2.bktei.com/gitweb/BK-2020-03.git/commitdiff_plain/1b4293c549f2051ba6e489e892655770526552a6?ds=sidebyside;hp=98c9cec82e40000f44886b87a01307283b00e3e3 temp(user/mw_create_redirect_day_month.sh):Save changes --- diff --git a/user/mw_create_redirect_day_month.sh b/user/mw_create_redirect_day_month.sh index 8d788c1..d801c4b 100755 --- a/user/mw_create_redirect_day_month.sh +++ b/user/mw_create_redirect_day_month.sh @@ -4,6 +4,7 @@ # Input: arg1: year (string) # Output: none # Version: 0.1.0 (TODO: Support expanded year formats (i.e. ±YYYYYY-mm-dd) +# Ref/Attrib: ISO 8601:2004. 4.1.2.4. “Expanded Representations” # Example: Running 'mw_create_redirect_day_month.sh 2022' creates # directory 'wikicode' in working directory. It then populates it @@ -25,7 +26,41 @@ yell() { echo "$0: $*" >&2; } # print script path and all args to stderr die() { yell "$*"; exit 111; } # same as yell() but non-zero exit status -try() { "$@" || die "cannot $*"; } # runs args as command, reports args if command fails +must() { "$@" || die "cannot $*"; } # runs args as command, reports args if command fails +list_days_of_year_exp() { + # Desc: Lists days of year in expanded ISO-8601 ±Y̲Y̲YYYY-mm-dd format + # Usage: script.sh [str year] + # Input: arg1: year (≥4 digit gregorian calendar year) + # Output: stdout: iso-8601 dates (newline delimited) + # Depends: bash (5.1.16), GNU Coreutils (8.32; date, printf) + # Version: 0.0.1 + # Ref/Attrib: [1] Linux Bash: How to print leading zeroes on a variable https://bytefreaks.net/gnulinux/bash/linux-bash-how-to-print-leading-zeroes-on-a-variable + # Ref/Attrib: ISO 8601:2004. 4.1.2.4. “Expanded Representations” + + # Check arg + ## Validate argument count + if [[ $# -ne 1 ]]; then die "FATAL:Invalid number of arguments:$#"; fi; + year="$1"; + + ## Validate arg as an integer year + pattern='^[0-9]{4,}$'; # !!!! STOPPED WORK HERE 2023-04-11T18:34+00 + if [[ ! $year =~ $pattern ]]; then die "FATAL:Not a 4-digit year:$year"; fi; + if [[ ! $year -gt 1582 ]]; then die "FATAL:Not a gregorian calendar year:$year"; fi; + + yyyy=$year; + for (( month = 1; month <= 12; month++ )); do + mm="$(printf %02d "$month")"; # two-digit month; See [1] + #yell "DEBUG:mm:$mm"; + for (( day = 1; day <= 31; day++ )); do + dd="$(printf %02d "$day")"; # two-digit day; See [1] + #yell "DEBUG:dd:$dd"; + date_iso8601="$yyyy-$mm-$dd"; + if date --date="$date_iso8601" 1>/dev/random 2>&1; then + printf "%s\n" "$date_iso8601"; + fi; + done; + done; +}; # iso-8601 dates (yyyy-mm-dd) to stdout list_days_of_year() { # Desc: Lists days of year in ISO-8601 YYYY-mm-dd format # Usage: script.sh [str year]