Advertisement
Guest User

d-test.sh

a guest
Jul 8th, 2022
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.59 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. echo $BASH_VERSION ;date -R
  3. echo 'USAGE: d-test.sh "[path/datediff.sh]" "[month..]" "[day..]"' >&2
  4. export DEBUG=2
  5.  
  6.  
  7. src="$HOME/bin/datediff.sh"
  8. [[ -e $1 ]] && {    src="$1" ;set -- "${@:2}" ;}
  9. echo ". $src" >&2
  10. . "$src" -D >&2  #flag -D disables package `date' warping
  11.  
  12.  
  13. for y in  1988  1989  #there should be a year in between!
  14. do  for m in ${1:-1 2 3  6  11 12}
  15.     do  echo "MONTH=$m"
  16.         for d in ${2:-1 2 3   27 28 29 30 31}
  17.         do  for h in 0 1  12  23
  18.             do  for min in 0 1  59
  19.                 do  for s in 0 1  59
  20.                     do
  21.     (( d <= $(month_maxday $m $y) )) || continue
  22.     D1="$y-$m-${d}T$h:$min:$s+00:00"
  23.     #dates must have time zone, even if set to +00:00
  24.  
  25.         for Y in 1989 1988
  26.         do  for M in 1 2 3  5  10 12
  27.             do  for D in 1 2 3 4  27 28 29 30 31
  28.                 do  for H in 0 1    23
  29.                     do  for MIN in 0 1  58
  30.                         do  for S in 0 1  58
  31.                             do
  32.             (( D <= $(month_maxday $M $Y) )) || continue
  33.             D2="$Y-$M-${D}T$H:$MIN:$S+00:00"
  34.  
  35.             {
  36.                 p=$(mainf "$D1" "$D2") || { echo >&2 ;echo "$p" ;}
  37.             } &
  38.             printf '\033[2K%s | %s\t(%d) [%d] {%d}\r' "${D1:0:19}" "${D2:0:19}" $((++n)) $SECONDS $((n/(SECONDS+1))) >&2
  39.                             done
  40.                         done
  41.                     done
  42.                 done
  43.             done
  44.         done
  45.                     done
  46.                 done
  47.             done
  48.         done
  49.     done
  50.     wait
  51.     echo "n=$n ($y)"
  52. done
  53. wait
  54. echo "N=$n"
  55.  
  56. #NOTES
  57. #Year 1988==4405104; Year 1989==4304988; total==8.710.092
  58. #2*6*8*4*3*3 * 9*3*3*3*2*6 == 10077696
  59.  
  60. #Note input dates must have time zone, even if set to +00:00, to avoid
  61. #debug checkign errors as `date' programme has got undefined behaviour
  62. #interpreting dates without timezone settings!
  63.  
  64. #LOG
  65. ##v0.16.6
  66. #Compound range testing:
  67. #.35171, about 35% of errors detected in testing are `datediff' only errs (9720/27644).
  68. #.1554,  about 16% of errors is from wrong shell arithmetics compensation for start-and-end-of-month days.
  69. #.10577, about 11% of error testing results are due to shell arithmetics outputting negative days.
  70. #.04720, at least 5% of other times we are probably right, too, as well as `datediff' (different ways of counting).
  71. #
  72. ##v0.16.7    (addon2)
  73. #.4570, about 45% of errors detected in testing are `datediff' only errs (12636/27644) (compound range).
  74. #Result differences remain the same, we detect false-positive errors thanks to addon2 code.
  75. #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.
  76. #
  77. ##v0.16.8    (addon2+addon3)
  78. #Addon3 prevents breaking a full month from count and delivers correct results, specially when dayA is `31'.
  79. #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.
  80. #
  81. #Testing was performed on 4,405,104 pairs of dates for 1988 vs. 1989 (compound range):
  82. #.00311, `datediff' error rate is at least 3% of total dates tested.
  83. #.006275, a 0,62% of error rate of total dates tested was produced.
  84. #Errors are understood as results that differ from `datediff' and may be false-positive errors (just different counting refinements).
  85. #.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.
  86. #.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.
  87. #.4959, thus almost 50% of testing errors are only `datediff'.
  88. #Remaining date results match although with different refinements (our results are little more refined than `datediff').
  89.  
  90.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement