aboutsummaryrefslogtreecommitdiffstats
path: root/functions/date_functions.php
diff options
context:
space:
mode:
authorWesley Miaw <josuah@users.sourceforge.net>2005-10-30 01:32:44 +0000
committerWesley Miaw <josuah@users.sourceforge.net>2005-10-30 01:32:44 +0000
commitfc81f9ebde033c58f729f392dba7914112d40720 (patch)
tree949f1a56d5a6de5695d93eb6c01adc3f24907c4f /functions/date_functions.php
parent966c67f92d14beaf7f6a2ba3386a8e6953cf9eb3 (diff)
downloadphpicalendar-fc81f9ebde033c58f729f392dba7914112d40720.tar.gz
phpicalendar-fc81f9ebde033c58f729f392dba7914112d40720.tar.bz2
phpicalendar-fc81f9ebde033c58f729f392dba7914112d40720.zip
Added support for recursively searching for calendars in your
$calendar_path and the new iCal calendar repository structure. The calendars are still referenced by calendar name, so all URLs are unchanged. Refactored the date parsing code out of ical_parser.php and into date_functions.php. Minor logic changes to the parser to correctly populate the TODO date and time values. Refactored the calendar name code into a new getCalendarName() function, since calendar names may no longer be determined solely by filename if using an iCal repository. Template code updated to match. Added calls to stripslashes() for calendar text data, such as the summaries and descriptions. Also put stripslashes() into people data, since people's names may contain escaped characters.
Diffstat (limited to 'functions/date_functions.php')
-rw-r--r--functions/date_functions.php87
1 files changed, 87 insertions, 0 deletions
diff --git a/functions/date_functions.php b/functions/date_functions.php
index a541a99..f6bfd53 100644
--- a/functions/date_functions.php
+++ b/functions/date_functions.php
@@ -206,4 +206,91 @@ $return = "
return $return;
}
+
+// Returns an array of the date and time extracted from the data
+// passed in. This array contains (unixtime, date, time, allday).
+//
+// $data = A string representing a date-time per RFC2445.
+// $property = The property being examined, e.g. DTSTART, DTEND.
+// $field = The full field being examined, e.g. DTSTART;TZID=US/Pacific
+function extractDateTime($data, $property, $field) {
+ global $tz_array;
+
+ // Initialize values.
+ unset($unixtime, $date, $time, $allday);
+
+ // What the heck is this doing in here?
+ $data = str_replace ('/softwarestudio.org/Olson_20011030_5/', '', $data);
+
+ // Check for zulu time.
+ $zulu_time = false;
+ if (substr($data,-1) == 'Z') $zulu_time = true;
+ $data = str_replace('Z', '', $data);
+
+ // Remove some substrings we don't want to look at.
+ $data = str_replace('T', '', $data);
+ $field = str_replace(';VALUE=DATE-TIME', '', $field);
+
+ // Extract date-only values.
+ if ((preg_match('/^'.$property.';VALUE=DATE/i', $field)) || (ereg ('^([0-9]{4})([0-9]{2})([0-9]{2})$', $data))) {
+ // Pull out the date value. Minimum year is 1970.
+ ereg ('([0-9]{4})([0-9]{2})([0-9]{2})', $data, $dt_check);
+ if ($dt_check[1] < 1970) {
+ $data = '1971'.$dt_check[2].$dt_check[3];
+ }
+
+ // Set the values.
+ $unixtime = strtotime($data);
+ $date = date('Ymd', $unixtime);
+ $allday = $data;
+ }
+
+ // Extract date-time values.
+ else {
+ // Pull out the timezone, or use GMT if zulu time was indicated.
+ if (preg_match('/^'.$property.';TZID=/i', $field)) {
+ $tz_tmp = explode('=', $field);
+ $tz_dt = $tz_tmp[1];
+ unset($tz_tmp);
+ } elseif ($zulu_time) {
+ $tz_dt = 'GMT';
+ }
+
+ // Pull out the date and time values. Minimum year is 1970.
+ preg_match ('/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{0,2})([0-9]{0,2})/', $data, $regs);
+ if ($regs[1] < 1970) {
+ $regs[1] = '1971';
+ }
+ $date = $regs[1] . $regs[2] . $regs[3];
+ $time = $regs[4] . $regs[5];
+ $unixtime = mktime($regs[4], $regs[5], 0, $regs[2], $regs[3], $regs[1]);
+
+ // Check for daylight savings time.
+ $dlst = date('I', $unixtime);
+ $server_offset_tmp = chooseOffset($unixtime);
+ if (isset($tz_dt)) {
+ if (array_key_exists($tz_dt, $tz_array)) {
+ $offset_tmp = $tz_array[$tz_dt][$dlst];
+ } else {
+ $offset_tmp = '+0000';
+ }
+ } elseif (isset($calendar_tz)) {
+ if (array_key_exists($calendar_tz, $tz_array)) {
+ $offset_tmp = $tz_array[$calendar_tz][$dlst];
+ } else {
+ $offset_tmp = '+0000';
+ }
+ } else {
+ $offset_tmp = $server_offset_tmp;
+ }
+
+ // Set the values.
+ $unixtime = calcTime($offset_tmp, $server_offset_tmp, $unixtime);
+ $date = date('Ymd', $unixtime);
+ $time = date('Hi', $unixtime);
+ }
+
+ // Return the results.
+ return array($unixtime, $date, $time, $allday);
+}
?>

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