function amr_process_RDATE($p, $start, $end) { /* RDATE or EXDATE processes a parsed array. If the specified event repeats between the given start and * end times, return one or more nonrepeating date strings in array RDATE:19970714T123000Z RDATE:19970714T083000 RDATE;TZID=US-EASTERN:19970714T083000 RDATE;VALUE=PERIOD:19960403T020000Z/19960403T040000Z,19960404T010000Z/PT3H RDATE;VALUE=DATE:19970101,19970120,19970217,19970421,19970526,19970704,19970901,19971014,19971128,19971129,19971225 should be passed as object now? *** amr check!! */ $repeats = array(); if (is_object($p)) { if (isset($_REQUEST['debugexc'])) { echo '<br> R or exdate Object passed ' . amr_format_date('Y m j, g:i a P', $p); } if (amr_falls_between($p, $start, $end)) { $repeats[] = $p; } } else { if (is_array($p)) { //var_dump($p); foreach ($p as $i => $r) { if (amr_falls_between($r, $start, $end)) { $repeats[] = $r; } } } else { if (isset($_REQUEST['rdebug'])) { echo '<br />****Cannot process RDATE - Not an Object, Not an array passed <br />'; var_dump($p); } //if (amr_falls_between($p, $start, $end)) $repeats[] = $p; } } //if (isset($_REQUEST['debugexc'])) { echo '<br/>*** Array of repeats '; var_dump($repeats); } return $repeats; }
function amr_format_time($format, $datestamp) { /* want a integer timestamp or a date object */ global $amr_globaltz; date_timezone_set($datestamp, $amr_globaltz); /* Converting here, but then some derivations wrong eg: unsetting of end date */ // check for midnight, midday, noon etc $time = $datestamp->format('His'); if (isset($_GET['tzdebug'])) { echo '<br />Time=' . $time; } $humanspeak = apply_filters('amr_human_time', $time); if (!($time === $humanspeak)) { return $humanspeak; } else { return amr_format_date($format, $datestamp); } }
function date_season($type = 'Meteorological', $D) { /* Receives ($Dateobject and returns a string with the Meterological season by default*/ /* Note that the limits must be defined on backwards order with a seemingly repeated entry at the end to catch all */ if (!isset($D)) { $D = amr_newDateTime(); } $Y = amr_format_date('Y', $D); $limits['Quarter'] = array('/12/31' => $Y . ' Q1', '/09/31' => $Y . ' Q4', '/06/30' => $Y . ' Q3', '/03/31' => $Y . ' Q2', '/01/00' => $Y . ' Q1'); $limits['Meteorological'] = array('/12/01' => 'N. Winter, S. Summer', '/09/01' => 'N. Fall, S. Spring', '/06/01' => 'N. Summer, S. Winter', '/03/01' => 'N. Spring, S. Autumn', '/01/00' => 'N. Winter, S. Summer'); $limits['Astronomical'] = array('/12/21' => 'N. Winter, S. Summer', '/09/23' => 'N. Fall, S. Spring', '/06/21' => 'N. Summer, S. Winter', '/03/21' => 'N. Spring, S. Autumn', '/01/00' => 'N. Winter, S. Summer'); $limits['Traditional'] = array('/11/08' => 'N. Winter, S. Summer', '/08/06' => 'N. Fall, S. Spring', '/06/05' => 'N. Summer, S. Winter', '/02/05' => 'N. Spring, S. Autumn', '/01/00' => 'N. Winter, S. Summer'); $limits['Zodiac'] = array('/12/22' => 'Capricorn', '/11/22' => 'Sagittarius', '/10/23' => 'Scorpio', '/09/23' => 'Libra', '/08/23' => 'Virgo', '/07/23' => 'Leo', '/06/21' => 'Cancer', '/05/21' => 'Gemini', '/04/20' => 'Taurus', '/03/21' => 'Aries', '/02/19' => 'Pisces', '/01/20' => 'Aquarius', '/01/00' => 'Capricon'); /* get the current year */ foreach ($limits[$type] as $key => $value) { /* add the current year to the limit */ $limit = $key; $input = amr_format_date('/m/d', $D); /* if date is later than limit, then return the current value, else continue to check the next limit */ if ($input > $limit) { return $value; } } }
function amr_prepare_pretty_rrule($rule) { global $ical_timezone, $amr_formats; /* take the event and it's parsed rrule or exrule and convert some aspects for people use. Used by both edit event and event info */ $df = $amr_formats['Day']; $tf = $amr_formats['Time']; $rule['UNTIL-DATE'] = ''; $rule['UNTIL-TIME'] = ''; if (isset($_GET['wpmldebug'])) { echo '<hr> inprep pretty'; var_dump($rule); } foreach ($rule as $i => $r) { $rule[strtoupper($i)] = $r; } if (isset($rule['UNTIL']) and is_object($rule['UNTIL'])) { /* until is possibly in Z time, move to our time first */ date_timezone_set($rule['UNTIL'], $ical_timezone); // $rule['UNTIL-DATE'] = $rule['UNTIL']->format($df); $rule['UNTIL-DATE'] = amr_format_date($df, $rule['UNTIL']); $rule['UNTIL-TIME'] = amr_format_date($tf, $rule['UNTIL']); } else { if (!isset($rule['COUNT'])) { $rule['forever'] = 'forever'; } } if (isset($rule['NOMOWEBYDAY'])) { /* what the F?? */ foreach ($rule['BYDAY'] as $j => $k) { $l = strlen($k); if ($l > 2) { /* special treatment required - we have a numeric byday */ $d = substr($k, $l - 2, $l); $rule['NBYDAY'][$d][substr($k, 0, $l - 2)] = true; $rule['BYDAY'][$d] = true; } else { $rule['BYDAY'][$k] = true; /* ie recurs every one of those days of week */ $rule['NBYDAY'][$k]['0'] = true; } unset($rule['BYDAY'][$j]); } } return $rule; }
function amr_calendar_colheaders($liststyle, $start) { global $wp_locale, $amr_options, $amr_globaltz, $amr_listtype; // week_begins = 0 stands for Sunday $week_begins = intval(get_option('start_of_week')); $format = $amr_options['listtypes'][$amr_listtype]['format']['Day']; $dummydate = new Datetime(); //if cloning dont need tz $dummydate = clone $start; // so as not to overwrite start $myweek = array(); $calendar_output = ''; for ($wdcount = 0; $wdcount <= 6; $wdcount++) { $dayofweek = ($wdcount + $week_begins) % 7; $myweek[] = $wp_locale->get_weekday($dayofweek); // make a note of which number is saturday and sunday so we can add css classes for the weekend if ($dayofweek == 0) { $sunday = $wdcount; } if ($dayofweek == 6) { $satday = $wdcount; } } foreach ($myweek as $dayofweek => $wd) { switch ($liststyle) { case "smallcalendar": $day_name = $wp_locale->get_weekday_initial($wd); break; case "weekscalendar": //else weekscalendar $day_name = amr_format_date($format, $dummydate); // v 4.0.9 break; default: //else large calendar $day_name = $wp_locale->get_weekday_abbrev($wd); } date_modify($dummydate, '+1 day'); //must increment the day // $day_name = ($liststyle=="smallcalendar") ? // $wp_locale->get_weekday_initial($wd) : // $wp_locale->get_weekday_abbrev($wd); $wd = esc_attr($wd); if ($dayofweek === $sunday) { $class = ' class="sunday" '; } elseif ($dayofweek === $satday) { $class = ' class="saturday" '; } else { $class = ''; } $calendar_output .= "\n\t\t<th " . $class . " scope=\"col\" title=\"{$wd}\">{$day_name}</th>"; } return $calendar_output; }
function amrical_formats($i) { global $amr_options; ?> <fieldset id="formats<?php echo $i; ?> " class="formats" > <h4 class="trigger"><a href="#" > <?php _e(' Define date and time formats:', 'amr-ical-events-list'); ?> </a></h4> <div class="toggle_container"><p><em><?php _e('Define the formats for the day (eg: Event date, End Date) and time (eg: Start time, End Time) fields. You can actually use any of these to display a full Date time string too. Use the Event date for event instances - the DTSTART field is the first startdate of a recurring event sequence.', 'amr-ical-events-list'); ?> </em></p><p><em><?php _e('These are also used for the date related grouping headings (ie: will show the date in that format as a heading for that group of dates if relevant.)', 'amr-ical-events-list'); ?> <?php echo __('Use the standard PHP format strings: ', 'amr-ical-events-list') . '<a href="http://www.php.net/manual/en/function.date.php" target="new" title="' . __('Php manual - date datetime formats', 'amr-ical-events-list') . '" ' . '> ' . __('See php date function format strings', 'amr-ical-events-list') . '</a>' . __(' (will localise) ', 'amr-ical-events-list'); ?> </em></p><?php if (!isset($amr_options['listtypes'][$i]['format'])) { echo 'No formats set'; } else { $date = amr_newDateTime(); echo '<ul>'; foreach ($amr_options['listtypes'][$i]['format'] as $c => $v) { $l = str_replace(' ', '', $c) . $i; echo '<li><label for="' . $l . ' ">' . __($c, 'amr-ical-events-list') . '</label>'; echo '<input type="text" size="12" id="' . $l . '" name="format[' . $i . '][' . $c . ']"'; echo ' value="' . $v . '" /> '; echo amr_format_date($v, $date); //a* amr ***/ echo '</li>'; } echo '</ul>'; } ?> </div> </fieldset><?php return; }