in reply to weekday from dayofyear

I'll assume you know the year as well... (Otherwise you can't: It is indeterminate.) Time::Local and localtime together can get it for you:

use Time::Local 'timelocal_nocheck'; (undef,undef,undef,undef,undef,undef,$wday,undef,undef) = localtime(ti +melocal_nocheck(0,0,0,$day_of_year,0,$year));

(If I'm reading the docs right, that should work. It's not quite explicitly stated.)

Replies are listed 'Best First'.
Re^2: weekday from dayofyear
by ikegami (Patriarch) on Jan 02, 2009 at 20:11 UTC

    Time::Local is buggy when you use it to do time/date arithmetic. The maintainer refused to apply a simple harmless fix for the bug. I think this line was added to the docs instead:

    If you supply data which is not valid (month 27, second 1,000) the results will be unpredictable (so don't do that).

    He told me that Time::Local isn't to be used for date/time arithmetic. _nocheck doesn't relax the need for valid inputs. The fourth argument needs to be a valid day for the specified month and year. If it's not allowed with _nocheck, it's not allowed without.

      Which is what made me nervous. Just a few lines above that though he also gave an example which I basically just copy-and-pasted into here...

      On the one hand, everything in it is core, and according to the docs it should work. On the other, according to those same docs it may not be reliable. Depending on the situation, I might consider using it. (Where consider == test thoroughly.)