Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- echo $BASH_VERSION ;date -R
- echo 'USAGE: d-test.sh "[path/datediff.sh]" "[month..]" "[day..]"' >&2
- export DEBUG=2
- src="$HOME/bin/datediff.sh"
- [[ -e $1 ]] && { src="$1" ;set -- "${@:2}" ;}
- echo ". $src" >&2
- . "$src" -D >&2 #flag -D disables package `date' warping
- for y in 1988 1989 #there should be a year in between!
- do for m in ${1:-1 2 3 6 11 12}
- do echo "MONTH=$m"
- for d in ${2:-1 2 3 27 28 29 30 31}
- do for h in 0 1 12 23
- do for min in 0 1 59
- do for s in 0 1 59
- do
- (( d <= $(month_maxday $m $y) )) || continue
- D1="$y-$m-${d}T$h:$min:$s+00:00"
- #dates must have time zone, even if set to +00:00
- for Y in 1989 1988
- do for M in 1 2 3 5 10 12
- do for D in 1 2 3 4 27 28 29 30 31
- do for H in 0 1 23
- do for MIN in 0 1 58
- do for S in 0 1 58
- do
- (( D <= $(month_maxday $M $Y) )) || continue
- D2="$Y-$M-${D}T$H:$MIN:$S+00:00"
- {
- p=$(mainf "$D1" "$D2") || { echo >&2 ;echo "$p" ;}
- } &
- printf '\033[2K%s | %s\t(%d) [%d] {%d}\r' "${D1:0:19}" "${D2:0:19}" $((++n)) $SECONDS $((n/(SECONDS+1))) >&2
- done
- done
- done
- done
- done
- done
- done
- done
- done
- done
- done
- wait
- echo "n=$n ($y)"
- done
- wait
- echo "N=$n"
- #NOTES
- #Year 1988==4405104; Year 1989==4304988; total==8.710.092
- #2*6*8*4*3*3 * 9*3*3*3*2*6 == 10077696
- #Note input dates must have time zone, even if set to +00:00, to avoid
- #debug checkign errors as `date' programme has got undefined behaviour
- #interpreting dates without timezone settings!
- #LOG
- ##v0.16.6
- #Compound range testing:
- #.35171, about 35% of errors detected in testing are `datediff' only errs (9720/27644).
- #.1554, about 16% of errors is from wrong shell arithmetics compensation for start-and-end-of-month days.
- #.10577, about 11% of error testing results are due to shell arithmetics outputting negative days.
- #.04720, at least 5% of other times we are probably right, too, as well as `datediff' (different ways of counting).
- #
- ##v0.16.7 (addon2)
- #.4570, about 45% of errors detected in testing are `datediff' only errs (12636/27644) (compound range).
- #Result differences remain the same, we detect false-positive errors thanks to addon2 code.
- #It fixes most negative day ranges but takes apart a full month in these cases, which makes result more refined than `datediff' and equally correct.
- #
- ##v0.16.8 (addon2+addon3)
- #Addon3 prevents breaking a full month from count and delivers correct results, specially when dayA is `31'.
- #Result differences remain the same, we detect false-positive errors thanks to addon3 code. We cannot really see bad range results any more but we note that we count differently than `datediff' in some cases.
- #
- #Testing was performed on 4,405,104 pairs of dates for 1988 vs. 1989 (compound range):
- #.00311, `datediff' error rate is at least 3% of total dates tested.
- #.006275, a 0,62% of error rate of total dates tested was produced.
- #Errors are understood as results that differ from `datediff' and may be false-positive errors (just different counting refinements).
- #.45709, `datediff' errs account for about 45% (12636/27644) of one testing error type (eights and nines as resulting weeks) while our results seems correct in those cases.
- #.03885 `datediff' accounts for almost 4% more errs of another type (start-and-end-of-month dates), while our results seem correct in those cases.
- #.4959, thus almost 50% of testing errors are only `datediff'.
- #Remaining date results match although with different refinements (our results are little more refined than `datediff').
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement