Most recent activity
-
I'm developing an app which needs a list of the days of the week, but right now the
require("locale").dow()
function only accepts a Date object. So I've had to do this:let daysOfWeek = []; for (let i = 1; i <= 7; i++) { daysOfWeek.push(require('locale').dow(new Date(1970, 1, i, 0, 0, 0, 0)); // 1/1/1970 was a Sunday } // Result: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
It seems to me it would be more efficient if the dow() function could accept an integer as well (0 = Sunday, 6 = Saturday) because right now it's just calling
getDay()
on the argument. That way, the code would be simpler:let daysOfWeek = []; for (let i = 0; i < 7; i++) { daysOfWeek.push(require('locale').dow(i); }
Does this make sense?
-
-
-
-
P.S: I'm not saying the function should no longer accept Date objects: that would break previous implementations. Instead, it would accept both Date and integer arguments.