]>
zdv2.bktei.com Git - BK-2020-03.git/blob - unitproc/bktemp-list_days_of_year.sh
da36db80060f1c1c12a11e8651ff5274170f4800
3 yell
() { echo " $0 : $*" >& 2 ; } # print script path and all args to stderr
4 die
() { yell
"$*" ; exit 111 ; } # same as yell() but non-zero exit status
5 try
() { "$@" || die
"cannot $*" ; } # runs args as command, reports args if command fails
7 # Desc: Lists days of year in ISO-8601 YYYY-mm-dd format
8 # Usage: script.sh [str year]
9 # Input: arg1: year (4 digit gregorian calendar year)
10 # Output: stdout: iso-8601 dates (newline delimited)
11 # Depends: bash (5.1.16), GNU Coreutils (8.32; date, printf)
13 # 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
16 ## Validate argument count
17 if [[ $# -ne 1 ]]; then die
"FATAL:Invalid number of arguments: $# " ; fi ;
20 ## Validate arg is a 4-digit year
22 if [[ ! $year = ~
$pattern ]]; then die
"FATAL:Not a 4-digit year." ; fi ;
23 if [[ ! $year -gt 1582 ]]; then die
"FATAL:Not a gregorian calendar year." ; fi ;
26 for (( month
= 1 ; month
<= 12 ; month
++ )); do
27 mm
= "$(printf %02d " $month ")" ; # two-digit month; See [1]
29 for (( day
= 1 ; day
<= 31 ; day
++ )); do
30 dd = "$(printf %02d " $day ")" ; # two-digit day; See [1]
32 date_iso8601
= " $yyyy - $mm - $dd " ;
33 if date --date = " $date_iso8601 " 1 >/ dev
/ random
2 >& 1 ; then
34 printf "%s \n " " $date_iso8601 " ;
38 }; # iso-8601 dates (yyyy-mm-dd) to stdout
41 wc -l < <( list_days_of_year
1583 ); # should report 365 lines
42 wc -l < <( list_days_of_year
2023 ); # should report 365 lines
43 wc -l < <( list_days_of_year
2024 ); # should report 366 lines (leap year)
44 wc -l < <( list_days_of_year
2025 ); # should report 365 lines
45 wc -l < <( list_days_of_year
9999 ); # should report 365 lines
47 # Author: Steven Baltakatei Sandoval
51 # # date (GNU coreutils) 8.32
52 # # Copyright (C) 2020 Free Software Foundation, Inc.
53 # # License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
54 # # This is free software: you are free to change and redistribute it.
55 # # There is NO WARRANTY, to the extent permitted by law.
57 # # Written by David MacKenzie.
60 # # printf (GNU coreutils) 8.32
61 # # Copyright (C) 2020 Free Software Foundation, Inc.
62 # # License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
63 # # This is free software: you are free to change and redistribute it.
64 # # There is NO WARRANTY, to the extent permitted by law.
66 # # Written by David MacKenzie.
69 # # GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
70 # # Copyright (C) 2020 Free Software Foundation, Inc.
71 # # License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
73 # # This is free software; you are free to change and redistribute it.
74 # # There is NO WARRANTY, to the extent permitted by law.