Skip to content
Snippets Groups Projects
Commit 8d46b188 authored by Steven Wittens's avatar Steven Wittens
Browse files

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.
parent 564e3ed3
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -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 @@ function display() {
// 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 @@ function display() {
// 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 @@ function display() {
// 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";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment