aboutsummaryrefslogtreecommitdiffstats
path: root/functions
diff options
context:
space:
mode:
authorjwangen <jwangen>2002-09-30 03:50:40 +0000
committerjwangen <jwangen>2002-09-30 03:50:40 +0000
commit4706c676d2c1995efdac08750f66f5ce37529866 (patch)
tree5bc060e9b38814ebe1c5f09d39a42bde0b6913ea /functions
parent7aeb7747f21d936f33ced01e19073c6f9957f5a3 (diff)
downloadphpicalendar-4706c676d2c1995efdac08750f66f5ce37529866.tar.gz
phpicalendar-4706c676d2c1995efdac08750f66f5ce37529866.tar.bz2
phpicalendar-4706c676d2c1995efdac08750f66f5ce37529866.zip
dateOfWeek now expects 3 char day names, instead of Apple's 2 char names
Diffstat (limited to 'functions')
-rw-r--r--functions/date_functions.php2
-rw-r--r--functions/list_weeks.php21
2 files changed, 8 insertions, 15 deletions
diff --git a/functions/date_functions.php b/functions/date_functions.php
index 8127b4b..0b8f640 100644
--- a/functions/date_functions.php
+++ b/functions/date_functions.php
@@ -1 +1 @@
-<?php // date_functions.php // functions for returning or comparing dates // takes Apple's 2 character day format and makes it into 3 characters function two2threeCharDays($day) { if ($day == "SU") $day_longer = "sun"; elseif ($day == "MO") $day_longer = "mon"; elseif ($day == "TU") $day_longer = "tue"; elseif ($day == "WE") $day_longer = "wed"; elseif ($day == "TH") $day_longer = "thu"; elseif ($day == "FR") $day_longer = "fri"; elseif ($day == "SA") $day_longer = "sat"; return $day_longer; } // dateOfWeek() takes a date in Ymd and a day of week as iCal knows them // (ie: SU, MO, TU, etc)and returns the date of that day. // This function may be specific to WEEKLY recurring events. function dateOfWeek($Ymd, $day) { global $week_start_day; if (!$week_start_day) $week_start_day = "Sunday"; $timestamp = strtotime($Ymd); $sunday = strtotime((date("w",$timestamp)==0 ? "$week_start_day" : "last $week_start_day"), $timestamp); $day_longer = two2threeCharDays($day); return date("Ymd",strtotime($day_longer,$sunday)); } // function to compare to dates in Ymd and return the number of weeks // that differ between them. requires dateOfWeek() function weekCompare($now, $then) { global $week_start_day; $day = substr($week_start_day, 0, 2); $sun_now = dateOfWeek($now, $day); $sun_then = dateOfWeek($then, $day); $seconds_now = strtotime($sun_now); $seconds_then = strtotime($sun_then); $diff_seconds = $seconds_now - $seconds_then; $diff_minutes = $diff_seconds/60; $diff_hours = $diff_minutes/60; $diff_days = round($diff_hours/24); $diff_weeks = $diff_days/7; return $diff_weeks; } // function to compare to dates in Ymd and return the number of days // that differ between them. requires dateOfWeek() function dayCompare($now, $then) { $seconds_now = strtotime($now); $seconds_then = strtotime($then); $diff_seconds = $seconds_now - $seconds_then; $diff_minutes = $diff_seconds/60; $diff_hours = $diff_minutes/60; $diff_days = round($diff_hours/24); return $diff_days; } // function to compare to dates in Ymd and return the number of months // that differ between them. requires dateOfWeek() function monthCompare($now, $then) { ereg ("([0-9]{4})([0-9]{2})([0-9]{2})", $now, $date_now); ereg ("([0-9]{4})([0-9]{2})([0-9]{2})", $then, $date_then); $diff_years = $date_now[1] - $date_then[1]; $diff_months = $date_now[2] - $date_then[2]; if ($date_now[2] < $date_then[2]) { $diff_years -= 1; $diff_months = ($diff_months + 12) % 12; } $diff_months = ($diff_years * 12) + $diff_months; return $diff_months; } ?> \ No newline at end of file
+<?php // date_functions.php // functions for returning or comparing dates // takes Apple's 2 character day format and makes it into 3 characters function two2threeCharDays($day) { if ($day == "SU") $day_longer = "sun"; elseif ($day == "MO") $day_longer = "mon"; elseif ($day == "TU") $day_longer = "tue"; elseif ($day == "WE") $day_longer = "wed"; elseif ($day == "TH") $day_longer = "thu"; elseif ($day == "FR") $day_longer = "fri"; elseif ($day == "SA") $day_longer = "sat"; return $day_longer; } // dateOfWeek() takes a date in Ymd and a day of week in 3 letters or more // and returns the date of that day. function dateOfWeek($Ymd, $day) { $timestamp = strtotime($Ymd); $sunday = strtotime((date("w",$timestamp)==0 ? "sunday" : "last sunday"), $timestamp); return date("Ymd",strtotime($day,$sunday)); } // function to compare to dates in Ymd and return the number of weeks // that differ between them. requires dateOfWeek() function weekCompare($now, $then) { global $week_start_day; $sun_now = dateOfWeek($now, $week_start_day); $sun_then = dateOfWeek($then, $week_start_day); $seconds_now = strtotime($sun_now); $seconds_then = strtotime($sun_then); $diff_seconds = $seconds_now - $seconds_then; $diff_minutes = $diff_seconds/60; $diff_hours = $diff_minutes/60; $diff_days = round($diff_hours/24); $diff_weeks = $diff_days/7; return $diff_weeks; } // function to compare to dates in Ymd and return the number of days // that differ between them. function dayCompare($now, $then) { $seconds_now = strtotime($now); $seconds_then = strtotime($then); $diff_seconds = $seconds_now - $seconds_then; $diff_minutes = $diff_seconds/60; $diff_hours = $diff_minutes/60; $diff_days = round($diff_hours/24); return $diff_days; } // function to compare to dates in Ymd and return the number of months // that differ between them. function monthCompare($now, $then) { ereg ("([0-9]{4})([0-9]{2})([0-9]{2})", $now, $date_now); ereg ("([0-9]{4})([0-9]{2})([0-9]{2})", $then, $date_then); $diff_years = $date_now[1] - $date_then[1]; $diff_months = $date_now[2] - $date_then[2]; if ($date_now[2] < $date_then[2]) { $diff_years -= 1; $diff_months = ($diff_months + 12) % 12; } $diff_months = ($diff_years * 12) + $diff_months; return $diff_months; } ?> \ No newline at end of file
diff --git a/functions/list_weeks.php b/functions/list_weeks.php
index 578193b..58d1465 100644
--- a/functions/list_weeks.php
+++ b/functions/list_weeks.php
@@ -5,18 +5,17 @@ ereg ("([0-9]{4})([0-9]{2})([0-9]{2})", $getdate, $day_array2);
$this_day = $day_array2[3];
$this_month = $day_array2[2];
$this_year = $day_array2[1];
-$i = 0;
+
$check_week = strtotime($getdate);
-$week_time = sundayOfWeek($this_year,"1","1");
-$start_week_time = strtotime(dateOfWeek($week_time, substr($week_start_day, 0, 2)));
-$end_week_time2 = $start_week_time + (6 * 25 * 60 * 60);
-$week_time = $start_week_time;
+
+$start_week_time = strtotime(dateOfWeek(date("Ymd", strtotime("$this_year-01-01")), $week_start_day));
+$end_week_time = $start_week_time + (6 * 25 * 60 * 60);
print "<form>\n<select name=\"action\" class=\"query_style\" onChange=\"window.location=(this.options[this.selectedIndex].value);\">\n";
// build the <option> tags
do {
- $weekdate = date ("Ymd", $week_time);
+ $weekdate = date ("Ymd", $start_week_time);
$select_week1 = strftime($dateFormat_week_jump, $start_week_time);
$select_week2 = strftime($dateFormat_week_jump, $end_week_time);
@@ -25,15 +24,9 @@ do {
} else {
print "<option value=\"week.php?cal=$cal&getdate=$weekdate\">$select_week1 - $select_week2</option>\n";
}
- $week_time = strtotime ("+1 week", $week_time);
- $week_year = date("Y", $month_time);
- $wDay = date ("d", $week_time);
- $wMonth = date ("m", $week_time);
- $start_week_time = sundayOfWeek($this_year,$wMonth,$wDay);
- $start_week_time = strtotime($start_week_time);
+ $start_week_time = strtotime ("+1 week", $start_week_time);
$end_week_time = $start_week_time + (6 * 25 * 60 * 60);
- $i++;
-} while (((date("Y", $start_week_time)) == $this_year) && ($i > 0));
+} while (date("Y", $start_week_time) <= $this_year);
// finish <select>
print "</select>\n</form>";

© 2014-2024 Faster IT GmbH | imprint | privacy policy