Coding Critique is the place to post source code for peer review by other members of DevNetwork. Any kind of code can be posted. Code posted does not have to be limited to PHP. All members are invited to contribute constructive criticism with the goal of improving the code. Posted code should include some background information about it and what areas you specifically would like help with.
Popular code excerpts may be moved to "Code Snippets" by the moderators.
koen.h wrote:Aren't there people who start their week with sunday.
That's what the third parameter is for; to set the day which starts the week. It defaults to 1 (Monday).
eivind: Originally I did have that but decided to change it to make it quicker for those who might want to use the default format but want to change the offset and/or the start day.
function getStartOfWeek($format = '', $offset = '', Day $startDayOfWeek) {}
interface Day {
public function toEnglish();
}
This of course makes it less simple than your original and suggests problems (translation) you may know you'll not run into (eg only used in house). On the other hand, this road leads to an object Week, with a method getStartDayOfWeek($format = '', $offset = '').
I don't really see what difference it makes using 1 as Monday and 7 as Sunday. If the person using the function cares that much about which integer refers to which month then they're more than welcome to change it. There's no point in making it unnecessarily complicated.
MichaelR wrote:I don't really see what difference it makes using 1 as Monday and 7 as Sunday. If the person using the function cares that much about which integer refers to which month then they're more than welcome to change it. There's no point in making it unnecessarily complicated.
The point is that it is not clear. If you find my approach unnecessary difficult I would suggest leaving out weekdays as numbers and use the names of the days instead. If you need to look into the code in the function to see what you should fill in as an argument it is unnecessarily complicated.