From 7364b0034329382dc2646649e23b24d9bf2b7e0d Mon Sep 17 00:00:00 2001 From: "jsonijr@gmail.com" Date: Sat, 16 Nov 2024 19:58:51 -0300 Subject: [PATCH] sync --- README.md | 3 +- datediff.sh | 198 ++++++++++++++++------------------------ man/README.md | 21 +++-- man/datediff.sh.1 | 20 ++-- man/datediff.sh.1.md | 25 +++-- man/datediff.sh.html | 26 +++--- man/datediff.sh.txt | 19 ++-- tests/datediff.debug.sh | 80 ++++++++++++++++ 8 files changed, 232 insertions(+), 160 deletions(-) create mode 100755 tests/datediff.debug.sh diff --git a/README.md b/README.md index 7e3bcfd..b709536 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,8 @@ When only one date is specified, the first date is assumed to be *now* or *1970* Note that `option -u` sets dates as UTC time and it influences how the underlying `C-code date` programme works. -For direct execution without wrapping the `C-code date` programme, set `options -DD`, and use ISO-8601 format or UNIX timestamps as input. +To test the shell built-in code for the ISO-8601 and UNIX timestamp processing and conversion +without wrapping the `C-code date` programme, set `options -DD`. Setting the last argument of the command line to exactly `y`, `mo`, `w`, `d`, `m`, or `s` will print only the specified timeframe result. diff --git a/datediff.sh b/datediff.sh index a11087c..14b896c 100755 --- a/datediff.sh +++ b/datediff.sh @@ -1,6 +1,6 @@ -#!/usr/bin/env ksh +#!/usr/bin/env bash # datediff.sh - Calculate time ranges between dates -# v0.24.4 oct/2024 mountaineerbr GPLv3+ +# v0.25 nov/2024 mountaineerbr GPLv3+ [[ -n $BASH_VERSION ]] && shopt -s extglob #bash2.05b+/ksh93u+/zsh5+ [[ -n $ZSH_VERSION ]] && setopt NO_SH_GLOB KSH_GLOB KSH_ARRAYS SH_WORD_SPLIT GLOB_SUBST @@ -95,14 +95,15 @@ DESCRIPTION calculations, as long as input is a valid ISO-8601 date format. - Debug and Direct Execution + Debug and Test - Option -d sets TZ=UTC, unsets verbose switches and run checks - against \`C-code datediff' and \`C-code date'. Set once to dump - only when results differ and set twice to code exit only. + Options -d and -dd execute result checks against \`C-code datediff' + and \`C-code date' programmes. Requires \`datediff.debug.sh'. Option -D disables \`C-code date' warping and -DD disables Bash/ - Ksh \`printf %()T' warping, too. + Ksh \`printf %()T' warping, too. This will have the script run and + process dates with only the shell built-in code instead of trying + to execute \`C-code date' for date processing and format conversion. Project source is hosted at: @@ -352,7 +353,10 @@ function datefun function is_leapyear { typeset year - ((year=10#${1:-0})) + set -- "${1:-0}"; + ((year=10#${1##[+-]})); + case "$1" in -*) year=-$year;; esac; + ((!(year % 4) && (year % 100 || !(year % 400) ) )) } @@ -362,7 +366,11 @@ function is_leapyear function month_maxday { typeset month year - ((month=10#${1:-1}, year=10#${2:-0})) + set -- "${1:-1}" "${2:-0}"; + ((month=10#${1})); + ((year= 10#${2##[+-]})); + case "$2" in -*) year=-$year;; esac; + if ((month==2)) && is_leapyear $year then echo 29 else echo ${YEAR_MONTH_DAYS[month-1]} @@ -374,7 +382,11 @@ function month_maxday function year_days_adj { typeset month year - ((month=10#${1:-1}, year=10#${2:-0})) + set -- "${1:-1}" "${2:-0}"; + ((month=10#${1})); + ((year= 10#${2##[+-]})); + case "$2" in -*) year=-$year;; esac; + if ((month<=2)) && is_leapyear $year then echo 366 else echo 365 @@ -397,8 +409,8 @@ function is_leapyear_verbose typeset year year="$1" if is_leapyear $year - then ((OPTVERBOSE)) || printf 'leap year -- %04d\n' $year - else ((OPTVERBOSE)) || printf 'not leap year -- %04d\n' $year + then ((OPTVERBOSE)) || printf 'leap year -- %4s\n' $year + else ((OPTVERBOSE)) || printf 'not leap year -- %4s\n' $year false fi } @@ -473,7 +485,9 @@ function monthconv function get_day_in_week { typeset unix - ((unix=10#${1:-0})) + set -- "${1:-0}"; + ((unix=10#${1##[+-]})); + case "$1" in -*) unix=-$unix;; esac; echo ${DAY_OF_WEEK[( ( (unix+(unix<0?1:0))/(24*60*60))%7 +(unix<0?6:7))%7]} } @@ -482,7 +496,11 @@ function get_day_in_week function get_day_in_year { typeset day month year month_test daysum - ((day=10#${1:-1}, month=10#${2:-1}, year=10#${3:-0})) + set -- "${1:-1}" "${2:-1}" "${3:-0}"; + ((day= 10#${1})); + ((month=10#${2})); + ((year= 10#${3##[+-]})); + case "$3" in -*) year=-$year;; esac; for ((month_test=1;month_test0 ? (SCL+1) : 0) )) - range_pr="$range_pr"$'\n'Sec$SS$'\t'$SSS$range + range_pr="$range_pr"$'\n'"${BOLD}Sec$SS${NC}"$'\t'$SSS$range range_pr="${range_pr##*([$IFS])}" #https://www.themathdoctors.org/should-we-put-zero-before-a-decimal-point/ ((OPTLAYOUT>1)) && { p= q=. ;for ((p=0;p&2; fi #print results @@ -1197,10 +1221,10 @@ function mainf fi printf '%s%s\n%s%s%s\n%s%s%s\n%s\n' \ - DATES "${neg_range%1}" \ + "${BOLD}DATES${NC}" "${neg_range%1}" \ "${date1_iso8601_pr:-${date1_iso8601:-$inputA}}" ''${unix1:+$'\t'} "$unix1" \ "${date2_iso8601_pr:-${date2_iso8601:-$inputB}}" ''${unix2:+$'\t'} "$unix2" \ - RANGES + "${BOLD}RANGES${NC}" fi ((OPTVERBOSE<2 || OPTVERBOSE>2)) && { ((OPTVERBOSE>3)) && v= || v=' ' #AST `date -E' style printf "%dY${v}%02dM${v}%02dW${v}%02dD${v}${v}%02dh${v}%02dm${v}%02ds\n" "${sh[@]}" @@ -1211,75 +1235,7 @@ function mainf } #Execute result checks against `datediff' and `date'. -#Copy this function body to where debugf() is to run it faster. -#Use GNU date preferably. Input must be well-formatted ISO8601. -#We defaults to UTC while `date' may set random offsets. -function debugf -{ - unset unix2t unix1t buf d_cmd ranget utc2t utc1t rfc2t rfc1t ddout y_dd mo_dd w_dd d_dd h_dd m_dd s_dd dd brk ret - d_cmd="$DATE_CMD" DATE_CMD="${DATE_CMD_DEBUG:-date}" - - [[ $d_cmd = [Ff][Aa][Ll][Ss][Ee] ]] && [[ -z $TZ ]] && TZ=UTC+0 - if ((TZs)) || [[ $TZ = *:*:*:* ]] || [[ $tzA = *:*:*:* ]] || [[ $tzB = *:*:*:* ]] - then echo "warning: \`datediff' and \`date' may not take offsets with seconds" >&2 - ((ret+=230)) - fi - if [[ $2 != *[Tt:]*[+-]$GLOBTZ ]] || [[ $1 != *[Tt:]*[+-]$GLOBTZ ]] - then echo "warning: input dates are missing offset/tz bits!" >&2 - fi - if [[ -z $1 || -z $2 ]] - then if [[ $d_cmd = [Ff][Aa][Ll][Ss][Ee] ]] || ((OPTDD)) - then set -- "${1:-$EPOCH}" "${2:-$EPOCH}" - else set -- "${1:-$(datefun -Isec)}" "${2:-$(datefun -Isec)}" - fi - fi - - unix2t=$(datefun "$2" +%s) unix1t=$(datefun "$1" +%s) - if ((unix1t>unix2t)) #sort dates - then set -- "$2" "$1" ;buf=$unix1t unix1t=$unix2t unix2t=$buf - fi - ((ranget=unix2t-unix1t)) - - utc2t=$(datefun -Isec "$2") utc1t=$(datefun -Isec "$1") - ((OPTRR)) && rfc2t=$(datefun -R "$2") rfc1t=$(datefun -R "$1") - - #compound range check against `datediff', offset range between -14h and +14h! - ddout=$(datediff -f'%Y %m %w %d %H %M %S' "${1:-$utc1t}" "${2:-$utc2t}") || ((ret+=250)) - read y_dd mo_dd w_dd d_dd h_dd m_dd s_dd <<<"$ddout" - dd=(${y_dd#-} $mo_dd $w_dd $d_dd $h_dd $m_dd $s_dd) - - { { { [[ ${date2_iso8601:0:25} = ${utc2t:0:25} ]] && - [[ ${date1_iso8601:0:25} = ${utc1t:0:25} ]] #iso - } || - { [[ ${date2_iso8601_pr:0:25} = ${rfc2t:0:25} ]] && - [[ ${date1_iso8601_pr:0:25} = ${rfc1t:0:25} ]] #rfc - } - } && - - ((unix2==unix2t)) && ((unix1==unix1t)) && - ((range==(unix2t-unix1t) )) && - - [[ ${sh[*]} = "${dd[*]:-${sh[*]}}" ]] - } || { #brk='\n' - echo -ne "\033[2K" >&2 - echo ${brk+-e} \ -"${TZ},${1},${2} | $brk"\ -"${date1_iso8601:0:25} ${utc1t:0:25} | $brk"\ -"${date2_iso8601:0:25} ${utc2t:0:25} | $brk"\ -"${date1_iso8601_pr:0:25} ${rfc1t:0:25} | $brk"\ -"${date2_iso8601_pr:0:25} ${rfc2t:0:25} | $brk"\ -"${unix1} ${unix1t} | $brk"\ -"${unix2} ${unix2t} | $brk"\ -"${range} ${ranget} | $brk"\ -"sh=${sh[*]} dd=${dd[*]}" - ((ret+=1)) - } - DATE_CMD="$d_cmd" - - #((DEBUG>1)) && return ${ret:-0} #!# - ((DEBUG>1)) && exit ${ret:-0} #!# - return 0 -} +function debugf { ! : ;} ## Parse options @@ -1398,25 +1354,26 @@ then set -- "${1#"${1%%[!$IFS]*}"}" ;set -- "${1%"${1##*[!$IFS]}"}" fi #-r, unix times -if ((OPTR)) || [[ \ $1\ $2 = *\ @* ]] -then if (($# >1)) - then if [[ $DATE_CMD = false ]] - then if [[ $1 = ?(@)+([0-9]) ]] - then UNIX1=${1#@} - set -- "$(unix_toiso "${1#@}")" "${@:2}" - fi - if [[ $2 = ?(@)+([0-9]) ]] - then UNIX2=${2#@} - set -- "$1" "$(unix_toiso "${2#@}")" "${@:3}" - fi - else set -- @"${1#@}" @"${2#@}" "${@:3}" +if ((OPTR && ${#1}+${#2})) || [[ \ $1\ $2 = *\ @[0-9.+-]* ]] +then + if [[ $DATE_CMD = false ]] + then if ((${#1})) && [[ $1 != *[!0-9@.+-]* ]] + then ((UNIX1=10#${1##*[!0-9.]})); + case "$1" in @-*|-*) UNIX1=-$UNIX1;; esac; + set -- "$(unix_toiso "${UNIX1}")" "${@:2}"; fi - elif (($#)) - then if [[ $DATE_CMD = false ]] - then [[ $1 = ?(@)+([0-9]) ]] && UNIX1=${1#@} - set -- "$(unix_toiso "${1#@}")" - else set -- @"${1#@}" + + if ((${#2})) && [[ $2 != *[!0-9@.+-]* ]] + then ((UNIX2=10#${2##*[!0-9.]})); + case "$2" in @-*|-*) UNIX2=-$UNIX2;; esac; + set -- "$1" "$(unix_toiso "${UNIX2}")" "${@:3}"; fi + else + #set dates for datefun() processing + ((${#2})) && [[ $2 != *[!0-9@.+-]* ]] && + set -- "${@:1:1}" @"${2##@}" "${@:3}"; + ((${#1})) && [[ $1 != *[!0-9@.+-]* ]] && + set -- @"${1##@}" "${@:2}"; fi fi @@ -1465,8 +1422,7 @@ then for DATE_Y #fill in months and days else set -- "$DATE_M" #;PHASE_SKIP= fi for DATE - do [[ $DATE = $GLOBDATE ]] || echo 'warning: DATE seems invallid' >&2 - set -- ${DATE//[\ $SEP]/ } #input is ISO8601 + do set -- ${DATE//[$SEP]/ } # ISO8601 input phase_of_the_moon "$3" "$2" "$1" done done @@ -1474,5 +1430,9 @@ then for DATE_Y #fill in months and days elif ((OPTFF)) then friday_13th "$@" else + + ((DEBUG)) && . datediff.debug.sh || DEBUG= ; + [[ -t 1 ]] && BOLD=$'\u001b[0;1m' NC=$'\u001b[m' || BOLD= NC= ; + mainf "$@" fi diff --git a/man/README.md b/man/README.md index a8d81d6..925e477 100644 --- a/man/README.md +++ b/man/README.md @@ -1,8 +1,8 @@ --- author: - Jamil Soni N -date: October 2024 -title: DATEDIFF.SH(1) v0.24.4 \| General Commands Manual +date: November 2024 +title: DATEDIFF.SH(1) v0.25 \| General Commands Manual --- # NAME @@ -104,14 +104,21 @@ calculations, and relies on `bc` for large-number integers and float arithmetics. The programme `dc` is executed in the Easter function as a mysterious function taken from *Dershowitz and Reingold*’s paper. -### Debug and Direct Execution +### Debug and Test + +**Options -d** and **-dd** execute result checks against +`C-code datediff` and `C-code date` programmes in the main function. +Requires `datediff.debug.sh`. **Option -d** sets *TZ=UTC*, unsets verbose switches and run checks -against `C-code datediff` and `C-code date`. Set once to dump only when -results differ and set twice to code exit only. +against `C-code datediff` and `C-code date`. Set once to dump debug +information only when results differ and set the flag twice to code exit +only. **Option -D** disables C-code date warping and **option -DD** disables -`Bash`/`Ksh` `printf %()T` warping, too. +`Bash`/`Ksh` `printf %()T` warping, too. This will have the script run +and process dates with only the shell built-in code instead of trying to +execute `C-code date` for date processing and format conversion.
The project source is hosted at: @@ -268,7 +275,7 @@ Print lunar phase at DATE (ISO UTC time). Set scale for single unit interval results. **-DD**, **-dd** -Debug options, check man page and on-line docs. +Debug options, check the Debug Section above. **-f** \[*FMT*\] Input time string format (only with `BSD date`). diff --git a/man/datediff.sh.1 b/man/datediff.sh.1 index df804ed..ff0d763 100644 --- a/man/datediff.sh.1 +++ b/man/datediff.sh.1 @@ -1,6 +1,6 @@ -.\" Automatically generated by Pandoc 3.1.10 +.\" Automatically generated by Pandoc 3.1.11.1 .\" -.TH "DATEDIFF.SH" "1" "October 2024" "v0.24.4" "General Commands Manual" +.TH "DATEDIFF.SH" "1" "November 2024" "v0.25" "General Commands Manual" .SH NAME .PP \ \ \ \f[B]datediff.sh\f[R] \- Calculate time ranges / intervals between @@ -120,16 +120,24 @@ large\-number integers and float arithmetics. The programme \f[CR]dc\f[R] is executed in the Easter function as a mysterious function taken from \f[I]Dershowitz and Reingold\f[R]\[cq]s paper. -.SS Debug and Direct Execution +.SS Debug and Test +\f[B]Options \-d\f[R] and \f[B]\-dd\f[R] execute result checks against +\f[CR]C\-code datediff\f[R] and \f[CR]C\-code date\f[R] programmes in +the main function. +Requires \f[CR]datediff.debug.sh\f[R]. +.PP \f[B]Option \-d\f[R] sets \f[I]TZ=UTC\f[R], unsets verbose switches and run checks against \f[CR]C\-code datediff\f[R] and \f[CR]C\-code date\f[R]. -Set once to dump only when results differ and set twice to code exit -only. +Set once to dump debug information only when results differ and set the +flag twice to code exit only. .PP \f[B]Option \-D\f[R] disables C\-code date warping and \f[B]option \-DD\f[R] disables \f[CR]Bash\f[R]/\f[CR]Ksh\f[R] \f[CR]printf %()T\f[R] warping, too. +This will have the script run and process dates with only the shell +built\-in code instead of trying to execute \f[CR]C\-code date\f[R] for +date processing and format conversion. .PP \ The project source is hosted at: .IP @@ -382,7 +390,7 @@ Print lunar phase at DATE (ISO UTC time). Set scale for single unit interval results. .TP \f[B]\-DD\f[R], \f[B]\-dd\f[R] -Debug options, check man page and on\-line docs. +Debug options, check the Debug Section above. .TP \f[B]\-f\f[R] [\f[I]FMT\f[R]] Input time string format (only with \f[CR]BSD date\f[R]). diff --git a/man/datediff.sh.1.md b/man/datediff.sh.1.md index 6261d80..c920dbb 100644 --- a/man/datediff.sh.1.md +++ b/man/datediff.sh.1.md @@ -1,6 +1,6 @@ -% DATEDIFF.SH(1) v0.24.4 | General Commands Manual +% DATEDIFF.SH(1) v0.25 | General Commands Manual % Jamil Soni N -% October 2024 +% November 2024 # NAME @@ -103,14 +103,20 @@ The programme `dc` is executed in the Easter function as a mysterious function taken from _Dershowitz and Reingold_'s paper. -### Debug and Direct Execution +### Debug and Test -**Option -d** sets _TZ=UTC_, unsets verbose switches and run checks -against `C-code datediff` and `C-code date`. Set once to dump only when -results differ and set twice to code exit only. -**Option -D** disables C-code date warping and **option -DD** -disables `Bash`/`Ksh` `printf %()T` warping, too. +**Options -d** and **-dd** execute result checks against `C-code datediff` +and `C-code date` programmes in the main function. Requires `datediff.debug.sh`. + +**Option -d** sets _TZ=UTC_, unsets verbose switches and run checks against +`C-code datediff` and `C-code date`. Set once to dump debug information +only when results differ and set the flag twice to code exit only. + +**Option -D** disables C-code date warping and **option -DD** disables +`Bash`/`Ksh` `printf %()T` warping, too. This will have the script run +and process dates with only the shell built-in code instead of trying +to execute `C-code date` for date processing and format conversion.
@@ -293,7 +299,8 @@ optionally required. **-DD**, **-dd** -: Debug options, check man page and on-line docs. +: Debug options, check the Debug Section above. + **-f** \[_FMT_] diff --git a/man/datediff.sh.html b/man/datediff.sh.html index 81b1ae3..5c0b4cd 100644 --- a/man/datediff.sh.html +++ b/man/datediff.sh.html @@ -5,7 +5,7 @@ - DATEDIFF.SH(1) v0.24.4 | General Commands Manual + DATEDIFF.SH(1) v0.25 | General Commands Manual -
-

DATEDIFF.SH(1) v0.24.4 | General Commands Manual

+

DATEDIFF.SH(1) v0.25 | General Commands Manual

Jamil Soni N

-

October 2024

+

November 2024

NAME

   datediff.sh - Calculate time @@ -266,14 +263,21 @@

Timezone Offsets

large-number integers and float arithmetics. The programme dc is executed in the Easter function as a mysterious function taken from Dershowitz and Reingold’s paper.

-

Debug and Direct Execution

+

Debug and Test

+

Options -d and -dd execute result +checks against C-code datediff and C-code date +programmes in the main function. Requires +datediff.debug.sh.

Option -d sets TZ=UTC, unsets verbose switches and run checks against C-code datediff and -C-code date. Set once to dump only when results differ and -set twice to code exit only.

+C-code date. Set once to dump debug information only when +results differ and set the flag twice to code exit only.

Option -D disables C-code date warping and option -DD disables Bash/Ksh -printf %()T warping, too.

+printf %()T warping, too. This will have the script run and +process dates with only the shell built-in code instead of trying to +execute C-code date for date processing and format +conversion.


The project source is hosted at:

<https://gitlab.com/fenixdragao/shelldatediff>
 <https://github.com/mountaineerbr/shellDatediff>
@@ -433,7 +437,7 @@

OPTIONS

-DD, -dd
-

Debug options, check man page and on-line docs.

+

Debug options, check the Debug Section above.

-f [FMT]
diff --git a/man/datediff.sh.txt b/man/datediff.sh.txt index 55f834a..f89928e 100644 --- a/man/datediff.sh.txt +++ b/man/datediff.sh.txt @@ -1,6 +1,6 @@ -DATEDIFF.SH(1) v0.24.4 | General Commands Manual +DATEDIFF.SH(1) v0.25 | General Commands Manual Jamil Soni N -October 2024 +November 2024 NAME @@ -96,14 +96,19 @@ calculations, and relies on bc for large-number integers and float arithmetics. The programme dc is executed in the Easter function as a mysterious function taken from Dershowitz and Reingold’s paper. -Debug and Direct Execution +Debug and Test + +Options -d and -dd execute result checks against C-code datediff and +C-code date programmes in the main function. Requires datediff.debug.sh. Option -d sets TZ=UTC, unsets verbose switches and run checks against -C-code datediff and C-code date. Set once to dump only when results -differ and set twice to code exit only. +C-code datediff and C-code date. Set once to dump debug information only +when results differ and set the flag twice to code exit only. Option -D disables C-code date warping and option -DD disables Bash/Ksh -printf %()T warping, too. +printf %()T warping, too. This will have the script run and process +dates with only the shell built-in code instead of trying to execute +C-code date for date processing and format conversion. The project source is hosted at: @@ -266,7 +271,7 @@ Main Function -DD, -dd - Debug options, check man page and on-line docs. + Debug options, check the Debug Section above. -f [FMT] diff --git a/tests/datediff.debug.sh b/tests/datediff.debug.sh new file mode 100755 index 0000000..4a46945 --- /dev/null +++ b/tests/datediff.debug.sh @@ -0,0 +1,80 @@ +# datediff.debug.sh v0.25 +# Function for `mountaineer's `chatgpt.sh'' + +# Option -d sets TZ=UTC, unsets verbose switches and run checks +# against \`C-code datediff' and \`C-code date'. Set once to dump +# only when results differ and set twice to code exit only. + +#Copy the function body to where debugf() is in `chatgpt.sh' (fast). +#Otherwise this function must be under your `$PATH' to be sourced. + +#Execute result checks against `datediff' and `date'. +#GNU date preferably. Input must be well-formatted ISO8601. +#We defaults to UTC while `date' may set random offsets. +function debugf +{ + unset unix2t unix1t buf d_cmd ranget utc2t utc1t rfc2t rfc1t ddout y_dd mo_dd w_dd d_dd h_dd m_dd s_dd dd brk ret + d_cmd="$DATE_CMD" DATE_CMD="${DATE_CMD_DEBUG:-date}" + + [[ $d_cmd = [Ff][Aa][Ll][Ss][Ee] ]] && [[ -z $TZ ]] && TZ=UTC+0 + if ((TZs)) || [[ $TZ = *:*:*:* ]] || [[ $tzA = *:*:*:* ]] || [[ $tzB = *:*:*:* ]] + then echo "warning: \`datediff' and \`date' may not take offsets with seconds" >&2 + ((ret+=230)) + fi + if [[ $2 != *[Tt:]*[+-]$GLOBTZ ]] || [[ $1 != *[Tt:]*[+-]$GLOBTZ ]] + then echo "warning: input dates are missing offset/tz bits!" >&2 + fi + if [[ -z $1 || -z $2 ]] + then if [[ $d_cmd = [Ff][Aa][Ll][Ss][Ee] ]] || ((OPTDD)) + then set -- "${1:-$EPOCH}" "${2:-$EPOCH}" + else set -- "${1:-$(datefun -Isec)}" "${2:-$(datefun -Isec)}" + fi + fi + + unix2t=$(datefun "$2" +%s) unix1t=$(datefun "$1" +%s) + if ((unix1t>unix2t)) #sort dates + then set -- "$2" "$1" ;buf=$unix1t unix1t=$unix2t unix2t=$buf + fi + ((ranget=unix2t-unix1t)) + + utc2t=$(datefun -Isec "$2") utc1t=$(datefun -Isec "$1") + ((OPTRR)) && rfc2t=$(datefun -R "$2") rfc1t=$(datefun -R "$1") + + #compound range check against `datediff', offset range between -14h and +14h! + ddout=$(datediff -f'%Y %m %w %d %H %M %S' "${1:-$utc1t}" "${2:-$utc2t}") || ((ret+=250)) + read y_dd mo_dd w_dd d_dd h_dd m_dd s_dd <<<"$ddout" + dd=(${y_dd#-} $mo_dd $w_dd $d_dd $h_dd $m_dd $s_dd) + + { { { [[ ${date2_iso8601:0:25} = ${utc2t:0:25} ]] && + [[ ${date1_iso8601:0:25} = ${utc1t:0:25} ]] #iso + } || + { [[ ${date2_iso8601_pr:0:25} = ${rfc2t:0:25} ]] && + [[ ${date1_iso8601_pr:0:25} = ${rfc1t:0:25} ]] #rfc + } + } && + + ((unix2==unix2t)) && ((unix1==unix1t)) && + ((range==(unix2t-unix1t) )) && + + [[ ${sh[*]} = "${dd[*]:-${sh[*]}}" ]] + } || { #brk='\n' + echo -ne "\033[2K" >&2 + echo ${brk+-e} \ +"${TZ},${1},${2} | $brk"\ +"${date1_iso8601:0:25} ${utc1t:0:25} | $brk"\ +"${date2_iso8601:0:25} ${utc2t:0:25} | $brk"\ +"${date1_iso8601_pr:0:25} ${rfc1t:0:25} | $brk"\ +"${date2_iso8601_pr:0:25} ${rfc2t:0:25} | $brk"\ +"${unix1} ${unix1t} | $brk"\ +"${unix2} ${unix2t} | $brk"\ +"${range} ${ranget} | $brk"\ +"sh=${sh[*]} dd=${dd[*]}" + ((ret+=1)) + } + DATE_CMD="$d_cmd" + + #((DEBUG>1)) && return ${ret:-0} #!# + ((DEBUG>1)) && exit ${ret:-0} #!# + return ${ret:-0} +} +