summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Wittens <steven@10.no-reply.drupal.org>2001-06-26 15:40:03 +0000
committerSteven Wittens <steven@10.no-reply.drupal.org>2001-06-26 15:40:03 +0000
commit8d46b18892710baae01f4798f290b91476a042ed (patch)
treefece72b5c8aaab37f3e627e854411736268f1f69
parent564e3ed30f6e18a203b469a00481c3e87c24a7c4 (diff)
downloadbrdo-8d46b18892710baae01f4798f290b91476a042ed.tar.gz
brdo-8d46b18892710baae01f4798f290b91476a042ed.tar.bz2
Updated calendar.module:
- Locale'd the day-of-the-week-letters. Don't worry, you won't find any "F" or "S" in your locale database, just "Friday" and "Sunday". - Fixed a bug with 28/20-day months. Skipping a month ahead from e.g. January 31st would have you end up on March 3rd. Same for skipping backwards. - Made the selected date always appear in bold. - Prevented all skipping into the future. This was still possible by skipping whole months.
-rw-r--r--modules/calendar.module32
1 files changed, 23 insertions, 9 deletions
diff --git a/modules/calendar.module b/modules/calendar.module
index fc519e8e3..a2e66f3a5 100644
--- a/modules/calendar.module
+++ b/modules/calendar.module
@@ -4,7 +4,9 @@ class Calendar {
var $date;
function calendar($date = 0) {
- $this->date = ($date ? $date : time());
+ // Prevent future dates
+ $today = mktime(23, 59, 59, date("n", time()), date("d", time()), date("Y", time()));
+ $this->date = (($date && $date <= $today) ? $date : $today);
}
function display() {
@@ -15,6 +17,9 @@ class Calendar {
// Extract today's date:
$today = mktime(23, 59, 59, date("n", time()), date("d", time()), date("Y", time()));
+
+ // Extract the timestamp of the last day of today's month:
+ $thislast = mktime(23, 59, 59, date("n", time()), date("t", time()), date("Y", time()));
// Extract first day of the month:
$first = date("w", mktime(0, 0, 0, $month, 1, $year));
@@ -22,15 +27,24 @@ class Calendar {
// Extract last day of the month:
$last = date("t", mktime(0, 0, 0, $month, 1, $year));
- // Calculate previous and next months dates:
- $prev = mktime(0, 0, 0, $month - 1, $day, $year);
- $next = mktime(0, 0, 0, $month + 1, $day, $year);
-
- // Generate calendar header:
+ // Calculate previous and next months dates and check for shorter months (28/30 days)
+ $prevmonth = mktime(23, 59, 59, $month - 1, 1, $year);
+ $prev = mktime(23, 59, 59, $month - 1, min(date("t", $prevmonth), $day), $year);
+ $nextmonth = mktime(23, 59, 59, $month + 1, 31, $year);
+ $next = mktime(23, 59, 59, $month + 1, min(date("t", $nextmonth), $day), $year);
+
+ // Generate calendar header:
$output .= "\n<!-- calendar -->\n";
$output .= "<TABLE WIDTH=\"100%\" BORDER=\"1\" CELLSPACING=\"0\" CELLPADDING=\"1\">\n";
- $output .= " <TR><TD ALIGN=\"center\" COLSPAN=\"7\"><SMALL><A HREF=\"index.php?date=$prev\">&lt;</A> &nbsp; ". date("F Y", $this->date) ." &nbsp; <A HREF=\"index.php?date=$next\">&gt;</A></SMALL></TD></TR>\n";
- $output .= " <TR><TD ALIGN=\"center\"><SMALL>S</SMALL></TD><TD ALIGN=\"center\"><SMALL>M</SMALL></TD><TD ALIGN=\"center\"><SMALL>T</SMALL></TD><TD ALIGN=\"center\"><SMALL>W</SMALL></TD><TD ALIGN=\"center\"><SMALL>T</SMALL></TD><TD ALIGN=\"center\"><SMALL>F</SMALL></TD><TD ALIGN=\"center\"><SMALL>S</SMALL></TD></TR>\n";
+ $output .= " <TR><TD ALIGN=\"center\" COLSPAN=\"7\"><SMALL><A HREF=\"index.php?date=$prev\">&lt;</A> &nbsp; ". date("F Y", $this->date) ." &nbsp; " . ($next <= $thislast ? "<A HREF=\"index.php?date=$next\">&gt;</A>" : "&gt;") . "</SMALL></TD></TR>\n";
+
+ // Generate the days of the week:
+ $output .= " <TR>";
+ $somesunday = mktime(0, 0, 0, 3, 20, 1994);
+ for ($i = 0; $i < 7; $i++) {
+ $output .= "<TD ALIGN=\"center\"><SMALL>" . substr(ucfirst(t(date("l", $somesunday + $i * 86400))), 0, 1) . "</SMALL></TD>";
+ }
+ $output .= "</TR>\n";
// Initialize temporary variables:
$nday = 1;
@@ -49,7 +63,7 @@ class Calendar {
// Print one cell:
$date = mktime(23, 59, 59, $month, $nday, $year);
- if ($nday == $day) $output .= " <TD ALIGN=\"center\"><SMALL><B>$nday</B></SMALL></TD>\n";
+ if ($date == $this->date) $output .= " <TD ALIGN=\"center\"><SMALL><B>$nday</B></SMALL></TD>\n";
else if ($date > $today) $output .= " <TD ALIGN=\"center\"><SMALL>$nday</SMALL></TD>\n";
else $output .= " <TD ALIGN=\"center\"><SMALL><A HREF=\"index.php?date=$date\" STYLE=\"text-decoration: none;\">$nday</A></SMALL></TD>\n";