3 [ "$include_datetime" ] && return 0
6 # Copyright 2023 - 2024 Paul Hänsch
8 # Permission to use, copy, modify, and/or distribute this software for any
9 # purpose with or without fee is hereby granted, provided that the above
10 # copyright notice and this permission notice appear in all copies.
12 # THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
15 # SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
18 # IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 if printf %s "$date" \
24 | grep -xEq '[0-9]{4}-((01|03|05|07|08|10|12)-(0[1-9]|[12][0-9]|3[01])|(04|06|09|11)-(0[1-9]|[12][0-9]|30)|02-(0[1-9]|[12][0-9]))'
25 then # y-m-d (ISO Date)
26 y="${date%%-*}" d="${date##*-}" m="${date%-*}" m="${m#*-}"
27 elif printf %s "$date" \
28 | grep -xEq '((0?1|0?3|0?5|0?7|0?8|10|12)/(0?[1-9]|[12][0-9]|3[01])|(0?4|0?6|0?9|11)/(0?[1-9]|[12][0-9]|30)|0?2-(0[1-9]|[12][0-9]))/([0-9]{2}|[0-9]{4})'
29 then # m/d/y (US Date)
30 y="${date##*/}" m="${date%%/*}" d="${date%/*}" d="${d#*/}"
31 elif printf %s "$date" \
32 | grep -xEq '((0?[1-9]|[12][0-9]|3[01])[\./](0?1|0?3|0?5|0?7|0?8|10|12)|(0?[1-9]|[12][0-9]|30)[\./](0?4|0?6|0?9|11)|(0[1-9]|[12][0-9])[\./]0?2)[\./]([0-9]{2}|[0-9]{4})'
33 then # d/m/y or d.m.y (European Date / German Date)
34 y="${date##*.}" d="${date%%.*}" m="${date%.*}" m="${m#*.}"
38 [ $y -lt 100 -a $y -gt 50 ] && y=$((y + 1900))
39 [ $y -lt 100 -a $y -le 50 ] && y=$((y + 2000))
40 date="$(printf "%04i-%02i-%02i" $y ${m#0} ${d#0})"
43 if [ "$m" -eq 2 -a "$d" -eq 29 ]; then
44 if [ "$((y % 400))" -eq 0 ]; then
46 elif [ "$((y % 100))" -eq 0 ]; then
48 elif [ "$((y % 4))" -eq 0 ]; then
55 printf '%04i-%02i-%02i\n' "$y" "${m#0}" "${d#0}"
62 if printf %s "$time" | grep -xEq '(0?[1-9]|1[012])(:[0-5][0-9])? ?(am|AM)\.?'; then
63 time="${time%?[aA][mM]}" h="${time%:*}" h="$(h % 12)"
64 [ "$h" != "$time" ] && m="${time#*:}" || m=0
65 elif printf %s "$time" | grep -xEq '(0?[1-9]|1[012])(:[0-5][0-9])? ?(pm|PM)\.?'; then
66 time="${time%?[aA][mM]}" h="${time%:*}" h="$(h % 12 + 12)"
67 [ "$h" != "$time" ] && m="${time#*:}" || m=0
68 elif printf %s "$time" | grep -xEq '(0?[0-9]|1[0-9]|2[0-3]):[0-5][0-9]'; then
69 time="${time%?[aA][mM]}" h="${time%:*}" m="${time#*:}"
74 printf '%02i:%02i\n' "${h#0}" "${m#0}"
79 # return number of days in a month (i.e. 28, 29, 30, or 31)
80 local y="$1" m="${2#0}"
89 2) if [ "$((y % 400))" -eq 0 ]; then
91 elif [ "$((y % 100))" -eq 0 ]; then
93 elif [ "$((y % 4))" -eq 0 ]; then