patternphpModerate
Show days of single week
Viewed 0 times
showsingledaysweek
Problem
I'm currently in the process of creating a online work schedule for internal use. For this, the client needs to show the days of a single week.
I pass a week number and a year.
From that I get the first day of that week, by using
With that function I create my table as mentioned earlier:
Well, it works, but I'm pretty sure that I'm reinventing the wheel, and doing a pretty bad job at it too. I'd like to know what you think and to hear any suggestions.
I pass a week number and a year.
From that I get the first day of that week, by using
strtotime() passing an argument in the format [year]-W[weekno]-[dayofweek]. Example: strtotime('2011-48W-1');With that function I create my table as mentioned earlier:
>
note; ?>">
workStart)); ?>
workStart != "0000-00-00 00:00:00") { echo " - ".date("H:i", strtotime($entry->workEnd)); } ?>
userId == 0): ?>
Unspecifed
name; ?>, pgroup; ?>
Well, it works, but I'm pretty sure that I'm reinventing the wheel, and doing a pretty bad job at it too. I'd like to know what you think and to hear any suggestions.
Solution
Three minor notes:
-
From Steve McConnell, Code Complete 2nd Edition, 31.2 Layout Techniques, p737:
Using blank lines is a way to indicate how a program is organized. You can use them
to divide groups of related statements into paragraphs, to separate routines from one
another, and to highlight comments.
It does not make sense if all groups contain only one line.
-
-
If I'm right you are iterating through the days of the week with this loop:
Renaming
-
From Steve McConnell, Code Complete 2nd Edition, 31.2 Layout Techniques, p737:
Using blank lines is a way to indicate how a program is organized. You can use them
to divide groups of related statements into paragraphs, to separate routines from one
another, and to highlight comments.
It does not make sense if all groups contain only one line.
-
strtotime($year.'-W'.$week.'-'.$i) is used and duplicated multiple times in the code. You could extract it out to a function to remove the duplication.-
If I'm right you are iterating through the days of the week with this loop:
Renaming
$i to $weekday or something similar would make it obvious and help readers/maintainers a lot.Code Snippets
<?php for($i = 1; $i <= 7; $i++): ?>Context
StackExchange Code Review Q#6422, answer score: 12
Revisions (0)
No revisions yet.