Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #12084

Re: Only one Friday 13th coming in 2016

From Stephane Chazelas <stephane.chazelas@gmail.com>
Newsgroups gnu.bash.bug
Subject Re: Only one Friday 13th coming in 2016
Date 2015-12-22 14:18 +0000
Message-ID <mailman.377.1450793896.843.bug-bash@gnu.org> (permalink)
References <slrnn7g4tl.2r3t.knock_yourself_out@vps.jonz.net> <20151221151338.GW27325@eeg.ccf.org> <20151222010544.GA21298@linda> <1450753456.7845.5.camel@16bits.net> <20151222131628.GZ27325@eeg.ccf.org>

Show all headers | View raw


2015-12-22 08:16:28 -0500, Greg Wooledge:
[...]
> t=946702800	# Start at Sat Jan  1 12:00:00 EST 2000
> endyear=2036
> 
> while true; do
>   printf -v year '%(%Y)T' "$t"
>   ((year > endyear)) && break
>   printf -v day  '%(%d)T' "$t"
>   printf -v dow  '%(%w)T' "$t"
>   if [[ $day = 13 && $dow = 5 ]]; then
>     printf -v month '%(%m)T' "$t"
>     echo "$year-$month-$day"
>   fi
>   ((t += 86400))
> done
> 
> But just because it doesn't fork, doesn't mean it's *fast*.  Bash is so
> slow at everything. :(  Your one-fork-per-month loop (plus one fork per
> year) might end up being much faster than my zero-forks-per-day loop.
> Mine is portable, though.
[...]

(assumes a recent version of bash though).

Starting on a Friday and looping with ((t += 7*86400)) and look
for %d == 13 would be more efficient.

TZ=UTC0 perl -MPOSIX -le 'for ($i=86400;$i<2**31;$i+=7*86400) {
@t=gmtime($i); if ($t[3] == 13){print strftime"%c",@t}}'

only takes a few miliseconds here.
-- 
Stephane

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Re: Only one Friday 13th coming in 2016 Stephane Chazelas <stephane.chazelas@gmail.com> - 2015-12-22 14:18 +0000

csiph-web