I took it to mean July 28th to be rounded up to August 3rd.
I put those julian date functions into awk, since awk seems to work the same everywhere no matter your shell.
mute@ovh:~$ printf '%s\n' 20120728 20120726 20120520 | ./julian.awk
Friday after:
Min: 2012/05/25
Max: 2012/08/03
#!/usr/bin/awk -f
function mk_j(y,m,d, a, j)
{
a = int((14 - m) / 12);
y = y + 4800 - a;
m = m + 12 * a - 3;
j = d + int((153*m + 2)/5) + 365*y + int(y/4) - int(y/100) + int(y/400) - 32045
return j
}
function mk_g(jd, l,n,i,j,d,m,y)
{
l = jd + 68569
n = int(( 4 * l ) / 146097)
l = l - int(( 146097 * n + 3 ) / 4)
i = int(4000 * ( l + 1 ) / 1461001)
l = l - int(( 1461 * i ) / 4) + 31
j = int(( 80 * l ) / 2447);
d = l - int(( 2447 * j ) / 80);
l = int(j / 11);
m = j + 2 - ( 12 * l );
y = 100 * ( n - 49 ) + i + l
return sprintf("%04d/%02d/%02d",y,m,d)
}
{
y=substr($0,1,4)
m=substr($0,5,2)
d=substr($0,7,2)
dates[++i]=mk_j(y,m,d)
}
function next_fri(jd, dow) {
dow = jd % 7
# friday=4
return jd + ( (dow > 4) ? 7 : 0 ) + (4 - dow)
}
END {
min=max=dates[1]
for (i in dates) {
if (dates > max) max=dates
if (dates < min) min=dates
}
printf("Friday after:\nMin: %s\nMax: %s\n",
mk_g(next_fri(min)), mk_g(next_fri(max)));
}
It is a bit lengthy. If only output you want is that next friday, there are day-of-week algorithm that wouldn't require converting to-and-from julian. You could use sort -n on that column and grab the first and last, then depends on OS if you can use date -d to get next friday...
This is bash function for day of week, since GNU date did allow "next friday" but not "2012-07-27 next friday"
mkdow() {
local y=$1 m=$2 d=$3
echo $((
((m<3?y--:y-2)+23*m/9+4+d+y/4+y/100*25/4)%7
))
}
could then just add days yourself until it is friday (like next_friday i wrote in awk)