master
Tanguy Pruvot 2010-10-31 16:59:40 +01:00
rodzic 30d1dfa4a9
commit b7c6351504
9 zmienionych plików z 136 dodań i 135 usunięć

Wyświetl plik

@ -11,16 +11,16 @@
*/ */
class SG_iCal_VCalendar implements IteratorAggregate { class SG_iCal_VCalendar implements IteratorAggregate {
protected $data; protected $data;
/** /**
* Creates a new SG_iCal_VCalendar. * Creates a new SG_iCal_VCalendar.
*/ */
public function __construct($data) { public function __construct($data) {
$this->data = $data; $this->data = $data;
} }
/** /**
* Returns the title of the calendar. If no title is known, NULL * Returns the title of the calendar. If no title is known, NULL
* will be returned * will be returned
* @return string * @return string
*/ */
@ -31,7 +31,7 @@ class SG_iCal_VCalendar implements IteratorAggregate {
return null; return null;
} }
} }
/** /**
* Returns the description of the calendar. If no description is * Returns the description of the calendar. If no description is
* known, NULL will be returned. * known, NULL will be returned.
@ -44,7 +44,7 @@ class SG_iCal_VCalendar implements IteratorAggregate {
return null; return null;
} }
} }
/** /**
* @see IteratorAggregate.getIterator() * @see IteratorAggregate.getIterator()
*/ */

Wyświetl plik

@ -1,12 +1,12 @@
<?php // BUILD: Remove line <?php // BUILD: Remove line
/** /**
* The wrapper for vevents. Will reveal a unified and simple api for * The wrapper for vevents. Will reveal a unified and simple api for
* the events, which include always finding a start and end (except * the events, which include always finding a start and end (except
* when no end or duration is given) and checking if the event is * when no end or duration is given) and checking if the event is
* blocking or similar. * blocking or similar.
* *
* Will apply the specified timezone to timestamps if a tzid is * Will apply the specified timezone to timestamps if a tzid is
* specified * specified
* *
* @package SG_iCalReader * @package SG_iCalReader
@ -32,7 +32,7 @@ class SG_iCal_VEvent {
public $data; public $data;
/** /**
* Constructs a new SG_iCal_VEvent. Needs the SG_iCalReader * Constructs a new SG_iCal_VEvent. Needs the SG_iCalReader
* supplied so it can query for timezones. * supplied so it can query for timezones.
* @param SG_iCal_Line[] $data * @param SG_iCal_Line[] $data
* @param SG_iCalReader $ical * @param SG_iCalReader $ical
@ -45,7 +45,7 @@ class SG_iCal_VEvent {
if ( isset($data['rrule']) ) { if ( isset($data['rrule']) ) {
$this->recurrence = new SG_iCal_Recurrence($data['rrule']); $this->recurrence = new SG_iCal_Recurrence($data['rrule']);
unset($data['rrule']); unset($data['rrule']);
//exclusions //exclusions
if ( isset($data['exdate']) ) { if ( isset($data['exdate']) ) {
foreach ($data['exdate'] as $exdate) { foreach ($data['exdate'] as $exdate) {
@ -98,15 +98,15 @@ class SG_iCal_VEvent {
unset($data[$import]); unset($data[$import]);
} }
} }
if( isset($this->previous_tz) ) { if( isset($this->previous_tz) ) {
date_default_timezone_set($this->previous_tz); date_default_timezone_set($this->previous_tz);
} }
$this->data = SG_iCal_Line::Remove_Line($data); $this->data = SG_iCal_Line::Remove_Line($data);
} }
/** /**
* Returns the Event Occurrences Iterator (if recurrence set) * Returns the Event Occurrences Iterator (if recurrence set)
* @return SG_iCal_Freq * @return SG_iCal_Freq
@ -119,7 +119,7 @@ class SG_iCal_VEvent {
} }
return $this->freq; return $this->freq;
} }
/** /**
* Returns the UID of the event * Returns the UID of the event
* @return string * @return string
@ -127,7 +127,7 @@ class SG_iCal_VEvent {
public function getUID() { public function getUID() {
return $this->uid; return $this->uid;
} }
/** /**
* Returns the summary (or null if none is given) of the event * Returns the summary (or null if none is given) of the event
* @return string * @return string
@ -135,7 +135,7 @@ class SG_iCal_VEvent {
public function getSummary() { public function getSummary() {
return $this->summary; return $this->summary;
} }
/** /**
* Returns the description (or null if none is given) of the event * Returns the description (or null if none is given) of the event
* @return string * @return string
@ -143,7 +143,7 @@ class SG_iCal_VEvent {
public function getDescription() { public function getDescription() {
return $this->description; return $this->description;
} }
/** /**
* Returns the location (or null if none is given) of the event * Returns the location (or null if none is given) of the event
* @return string * @return string
@ -151,7 +151,7 @@ class SG_iCal_VEvent {
public function getLocation() { public function getLocation() {
return $this->location; return $this->location;
} }
/** /**
* Returns true if the event is blocking (ie not transparent) * Returns true if the event is blocking (ie not transparent)
* @return bool * @return bool
@ -159,7 +159,7 @@ class SG_iCal_VEvent {
public function isBlocking() { public function isBlocking() {
return !(isset($this->data['transp']) && $this->data['transp'] == 'TRANSPARENT'); return !(isset($this->data['transp']) && $this->data['transp'] == 'TRANSPARENT');
} }
/** /**
* Returns true if the event is confirmed * Returns true if the event is confirmed
* @return bool * @return bool
@ -171,7 +171,7 @@ class SG_iCal_VEvent {
return $this->data['status'] == 'CONFIRMED'; return $this->data['status'] == 'CONFIRMED';
} }
} }
/** /**
* Returns the timestamp for the beginning of the event * Returns the timestamp for the beginning of the event
* @return int * @return int
@ -179,7 +179,7 @@ class SG_iCal_VEvent {
public function getStart() { public function getStart() {
return $this->start; return $this->start;
} }
/** /**
* Returns the timestamp for the end of the event * Returns the timestamp for the end of the event
* @return int * @return int
@ -195,7 +195,7 @@ class SG_iCal_VEvent {
public function getRangeEnd() { public function getRangeEnd() {
return max($this->end,$this->lastend); return max($this->end,$this->lastend);
} }
/** /**
* Returns the duration of this event in seconds * Returns the duration of this event in seconds
* @return int * @return int
@ -203,7 +203,7 @@ class SG_iCal_VEvent {
public function getDuration() { public function getDuration() {
return $this->end - $this->start; return $this->end - $this->start;
} }
/** /**
* Returns true if duration is multiple of 86400 * Returns true if duration is multiple of 86400
* @return bool * @return bool
@ -215,7 +215,7 @@ class SG_iCal_VEvent {
} }
return false; return false;
} }
/** /**
* Returns the given property of the event. * Returns the given property of the event.
* @param string $prop * @param string $prop
@ -230,9 +230,9 @@ class SG_iCal_VEvent {
return null; return null;
} }
} }
/** /**
* Set default timezone (temporary) to get timestamps * Set default timezone (temporary) to get timestamps
* @return string * @return string
@ -248,14 +248,14 @@ class SG_iCal_VEvent {
} }
return false; return false;
} }
/** /**
* Calculates the timestamp from a DT line. * Calculates the timestamp from a DT line.
* @param $line SG_iCal_Line * @param $line SG_iCal_Line
* @return int * @return int
*/ */
protected function getTimestamp( SG_iCal_Line $line, SG_iCal $ical ) { protected function getTimestamp( SG_iCal_Line $line, SG_iCal $ical ) {
if( isset($line['tzid']) ) { if( isset($line['tzid']) ) {
$this->setLineTimeZone($line); $this->setLineTimeZone($line);
//$tz = $ical->getTimeZoneInfo($line['tzid']); //$tz = $ical->getTimeZoneInfo($line['tzid']);

Wyświetl plik

@ -13,27 +13,27 @@ class SG_iCal_VTimeZone {
protected $daylight; protected $daylight;
protected $standard; protected $standard;
protected $cache = array(); protected $cache = array();
/** /**
* Constructs a new SG_iCal_VTimeZone * Constructs a new SG_iCal_VTimeZone
*/ */
public function __construct( $data ) { public function __construct( $data ) {
require_once dirname(__FILE__).'/../helpers/SG_iCal_Freq.php'; // BUILD: Remove line require_once dirname(__FILE__).'/../helpers/SG_iCal_Freq.php'; // BUILD: Remove line
$this->tzid = $data['tzid']; $this->tzid = $data['tzid'];
$this->daylight = $data['daylight']; $this->daylight = $data['daylight'];
$this->standard = $data['standard']; $this->standard = $data['standard'];
} }
/** /**
* Returns the timezone-id for this timezone. (Used to * Returns the timezone-id for this timezone. (Used to
* differentiate between different tzs in a calendar) * differentiate between different tzs in a calendar)
* @return string * @return string
*/ */
public function getTimeZoneId() { public function getTimeZoneId() {
return $this->tzid; return $this->tzid;
} }
/** /**
* Returns the given offset in this timezone for the given * Returns the given offset in this timezone for the given
* timestamp. (eg +0200) * timestamp. (eg +0200)
@ -44,7 +44,7 @@ class SG_iCal_VTimeZone {
$act = $this->getActive($ts); $act = $this->getActive($ts);
return $this->{$act}['tzoffsetto']; return $this->{$act}['tzoffsetto'];
} }
/** /**
* Returns the timezone name for the given timestamp (eg CEST) * Returns the timezone name for the given timestamp (eg CEST)
* @param int $ts * @param int $ts
@ -54,7 +54,7 @@ class SG_iCal_VTimeZone {
$act = $this->getActive($ts); $act = $this->getActive($ts);
return $this->{$act}['tzname']; return $this->{$act}['tzname'];
} }
/** /**
* Determines which of the daylight or standard is the active * Determines which of the daylight or standard is the active
* setting. * setting.
@ -65,20 +65,20 @@ class SG_iCal_VTimeZone {
* @return string standard|daylight * @return string standard|daylight
*/ */
private function getActive( $ts ) { private function getActive( $ts ) {
if (class_exists('DateTimeZone')) { if (class_exists('DateTimeZone')) {
//PHP >= 5.2 //PHP >= 5.2
$tz = new DateTimeZone( $this->tzid ); $tz = new DateTimeZone( $this->tzid );
$date = new DateTime("@$ts", $tz); $date = new DateTime("@$ts", $tz);
return ($date->format('I') == 1) ? 'daylight' : 'standard'; return ($date->format('I') == 1) ? 'daylight' : 'standard';
} else { } else {
if( isset($this->cache[$ts]) ) { if( isset($this->cache[$ts]) ) {
return $this->cache[$ts]; return $this->cache[$ts];
} }
$daylight_freq = new SG_iCal_Freq($this->daylight['rrule'], strtotime($this->daylight['dtstart'])); $daylight_freq = new SG_iCal_Freq($this->daylight['rrule'], strtotime($this->daylight['dtstart']));
$standard_freq = new SG_iCal_Freq($this->standard['rrule'], strtotime($this->standard['dtstart'])); $standard_freq = new SG_iCal_Freq($this->standard['rrule'], strtotime($this->standard['dtstart']));
$last_standard = $standard_freq->previousOccurrence($ts); $last_standard = $standard_freq->previousOccurrence($ts);
@ -88,7 +88,7 @@ class SG_iCal_VTimeZone {
} else { } else {
$this->cache[$ts] = 'standard'; $this->cache[$ts] = 'standard';
} }
return $this->cache[$ts]; return $this->cache[$ts];
} }
} }

Wyświetl plik

@ -69,7 +69,7 @@ class SG_iCal_Freq {
$this->rules['bymonthday'] = date('d', $this->start); $this->rules['bymonthday'] = date('d', $this->start);
} }
} }
//set until, and cache //set until, and cache
if( isset($this->rules['count']) ) { if( isset($this->rules['count']) ) {
$ts = $this->start; $ts = $this->start;
@ -83,7 +83,7 @@ class SG_iCal_Freq {
} }
} }
/** /**
* Returns all timestamps array(), build the cache if not made before * Returns all timestamps array(), build the cache if not made before
* @return array * @return array
@ -192,7 +192,7 @@ class SG_iCal_Freq {
return $ts; return $ts;
} }
} }
$debug = false; $debug = false;
//make sure the offset is valid //make sure the offset is valid
@ -268,7 +268,7 @@ class SG_iCal_Freq {
} }
if ($ts && in_array($ts, $this->excluded)) if ($ts && in_array($ts, $this->excluded))
return $this->findNext($ts); return $this->findNext($ts);
return $ts; return $ts;
} }
@ -461,7 +461,7 @@ class SG_iCal_Freq {
if( isset($this->rules['until']) && $t > $this->rules['until'] ) { if( isset($this->rules['until']) && $t > $this->rules['until'] ) {
return false; return false;
} }
if (in_array($t, $this->excluded)) { if (in_array($t, $this->excluded)) {
return false; return false;
} }

Wyświetl plik

@ -4,7 +4,7 @@
* A class for storing a single (complete) line of the iCal file. * A class for storing a single (complete) line of the iCal file.
* Will find the line-type, the arguments and the data of the file and * Will find the line-type, the arguments and the data of the file and
* store them. * store them.
* *
* The line-type can be found by querying getIdent(), data via either * The line-type can be found by querying getIdent(), data via either
* getData() or typecasting to a string. * getData() or typecasting to a string.
* Params can be access via the ArrayAccess. A iterator is also avilable * Params can be access via the ArrayAccess. A iterator is also avilable
@ -18,9 +18,9 @@ class SG_iCal_Line implements ArrayAccess, Countable, IteratorAggregate {
protected $ident; protected $ident;
protected $data; protected $data;
protected $params = array(); protected $params = array();
protected $replacements = array('from'=>array('\\,', '\\n', '\\;', '\\:', '\\"'), 'to'=>array(',', "\n", ';', ':', '"')); protected $replacements = array('from'=>array('\\,', '\\n', '\\;', '\\:', '\\"'), 'to'=>array(',', "\n", ';', ':', '"'));
/** /**
* Constructs a new line. * Constructs a new line.
*/ */
@ -28,21 +28,21 @@ class SG_iCal_Line implements ArrayAccess, Countable, IteratorAggregate {
$split = strpos($line, ':'); $split = strpos($line, ':');
$idents = explode(';', substr($line, 0, $split)); $idents = explode(';', substr($line, 0, $split));
$ident = strtolower(array_shift($idents)); $ident = strtolower(array_shift($idents));
$data = trim(substr($line, $split+1)); $data = trim(substr($line, $split+1));
$data = str_replace($this->replacements['from'], $this->replacements['to'], $data); $data = str_replace($this->replacements['from'], $this->replacements['to'], $data);
$params = array(); $params = array();
foreach( $idents AS $v) { foreach( $idents AS $v) {
list($k, $v) = explode('=', $v); list($k, $v) = explode('=', $v);
$params[ strtolower($k) ] = $v; $params[ strtolower($k) ] = $v;
} }
$this->ident = $ident; $this->ident = $ident;
$this->params = $params; $this->params = $params;
$this->data = $data; $this->data = $data;
} }
/** /**
* Is this line the begining of a new block? * Is this line the begining of a new block?
* @return bool * @return bool
@ -50,7 +50,7 @@ class SG_iCal_Line implements ArrayAccess, Countable, IteratorAggregate {
public function isBegin() { public function isBegin() {
return $this->ident == 'begin'; return $this->ident == 'begin';
} }
/** /**
* Is this line the end of a block? * Is this line the end of a block?
* @return bool * @return bool
@ -58,7 +58,7 @@ class SG_iCal_Line implements ArrayAccess, Countable, IteratorAggregate {
public function isEnd() { public function isEnd() {
return $this->ident == 'end'; return $this->ident == 'end';
} }
/** /**
* Returns the line-type (ident) of the line * Returns the line-type (ident) of the line
* @return string * @return string
@ -66,7 +66,7 @@ class SG_iCal_Line implements ArrayAccess, Countable, IteratorAggregate {
public function getIdent() { public function getIdent() {
return $this->ident; return $this->ident;
} }
/** /**
* Returns the content of the line * Returns the content of the line
* @return string * @return string
@ -74,7 +74,7 @@ class SG_iCal_Line implements ArrayAccess, Countable, IteratorAggregate {
public function getData() { public function getData() {
return $this->data; return $this->data;
} }
/** /**
* A static helper to get a array of SG_iCal_Line's, and calls * A static helper to get a array of SG_iCal_Line's, and calls
* getData() on each of them to lay the data "bare".. * getData() on each of them to lay the data "bare"..
@ -95,14 +95,14 @@ class SG_iCal_Line implements ArrayAccess, Countable, IteratorAggregate {
} }
return $rtn; return $rtn;
} }
/** /**
* @see ArrayAccess.offsetExists * @see ArrayAccess.offsetExists
*/ */
public function offsetExists( $param ) { public function offsetExists( $param ) {
return isset($this->params[ strtolower($param) ]); return isset($this->params[ strtolower($param) ]);
} }
/** /**
* @see ArrayAccess.offsetGet * @see ArrayAccess.offsetGet
*/ */
@ -112,7 +112,7 @@ class SG_iCal_Line implements ArrayAccess, Countable, IteratorAggregate {
return $this->params[ $index ]; return $this->params[ $index ];
} }
} }
/** /**
* Disabled ArrayAccess requirement * Disabled ArrayAccess requirement
* @see ArrayAccess.offsetSet * @see ArrayAccess.offsetSet
@ -120,7 +120,7 @@ class SG_iCal_Line implements ArrayAccess, Countable, IteratorAggregate {
public function offsetSet( $param, $val ) { public function offsetSet( $param, $val ) {
return false; return false;
} }
/** /**
* Disabled ArrayAccess requirement * Disabled ArrayAccess requirement
* @see ArrayAccess.offsetUnset * @see ArrayAccess.offsetUnset
@ -128,7 +128,7 @@ class SG_iCal_Line implements ArrayAccess, Countable, IteratorAggregate {
public function offsetUnset( $param ) { public function offsetUnset( $param ) {
return false; return false;
} }
/** /**
* toString method. * toString method.
* @see getData() * @see getData()
@ -136,14 +136,14 @@ class SG_iCal_Line implements ArrayAccess, Countable, IteratorAggregate {
public function __toString() { public function __toString() {
return $this->getData(); return $this->getData();
} }
/** /**
* @see Countable.count * @see Countable.count
*/ */
public function count() { public function count() {
return count($this->params); return count($this->params);
} }
/** /**
* @see IteratorAggregate.getIterator * @see IteratorAggregate.getIterator
*/ */

Wyświetl plik

@ -11,7 +11,7 @@ class SG_iCal_Parser {
$content = self::UnfoldLines($content); $content = self::UnfoldLines($content);
self::_Parse( $content, $ical ); self::_Parse( $content, $ical );
} }
/** /**
* Passes a text string on to be parsed * Passes a text string on to be parsed
* @param string $content * @param string $content
@ -21,7 +21,7 @@ class SG_iCal_Parser {
$content = self::UnfoldLines($content); $content = self::UnfoldLines($content);
self::_Parse( $content, $ical ); self::_Parse( $content, $ical );
} }
/** /**
* Fetches a resource and tries to make sure it's UTF8 * Fetches a resource and tries to make sure it's UTF8
* encoded * encoded
@ -29,7 +29,7 @@ class SG_iCal_Parser {
*/ */
protected static function Fetch( $resource ) { protected static function Fetch( $resource ) {
$is_utf8 = true; $is_utf8 = true;
if( is_file( $resource ) ) { if( is_file( $resource ) ) {
// The resource is a local file // The resource is a local file
$content = file_get_contents($resource); $content = file_get_contents($resource);
@ -59,16 +59,16 @@ class SG_iCal_Parser {
$is_utf8 = false; $is_utf8 = false;
} }
} }
if( !$is_utf8 ) { if( !$is_utf8 ) {
$content = utf8_encode($content); $content = utf8_encode($content);
} }
return $content; return $content;
} }
/** /**
* Takes the string $content, and creates a array of iCal lines. * Takes the string $content, and creates a array of iCal lines.
* This includes unfolding multi-line entries into a single line. * This includes unfolding multi-line entries into a single line.
* @param $content string * @param $content string
*/ */
@ -121,14 +121,14 @@ class SG_iCal_Parser {
if( $section == $s ) { if( $section == $s ) {
// It _is_ the main section else // It _is_ the main section else
if ($line->getIdent() != "exdate") if ($line->getIdent() != "exdate")
$current_data[$s][$line->getIdent()] = $line; $current_data[$s][$line->getIdent()] = $line;
else { else {
//exdate could appears more that once //exdate could appears more that once
$current_data[$s][$line->getIdent()][] = $line; $current_data[$s][$line->getIdent()][] = $line;
} }
} else { } else {
// Sub section // Sub section
$current_data[$s][$section][$line->getIdent()] = $line; $current_data[$s][$section][$line->getIdent()] = $line;
} }
break; break;
} }
@ -160,10 +160,10 @@ class SG_iCal_Parser {
} }
/** /**
* This functions does some regexp checking to see if the value is * This functions does some regexp checking to see if the value is
* valid UTF-8. * valid UTF-8.
* *
* The function is from the book "Building Scalable Web Sites" by * The function is from the book "Building Scalable Web Sites" by
* Cal Henderson. * Cal Henderson.
* *
* @param string $data * @param string $data
@ -186,7 +186,7 @@ class SG_iCal_Parser {
$rx .= '|^[\x80-\xBF]'; $rx .= '|^[\x80-\xBF]';
return ( ! (bool) preg_match('!'.$rx.'!', $data) ); return ( ! (bool) preg_match('!'.$rx.'!', $data) );
} }
} }

Wyświetl plik

@ -25,7 +25,7 @@ class SG_iCal_Query {
if( !is_array($ical) ) { if( !is_array($ical) ) {
throw new Exception('SG_iCal_Query::Between called with invalid input!'); throw new Exception('SG_iCal_Query::Between called with invalid input!');
} }
$rtn = array(); $rtn = array();
foreach( $ical AS $e ) { foreach( $ical AS $e ) {
if( ($start <= $e->getStart() && $e->getStart() < $end) if( ($start <= $e->getStart() && $e->getStart() < $end)
@ -35,10 +35,10 @@ class SG_iCal_Query {
} }
return $rtn; return $rtn;
} }
/** /**
* Returns all events from the calendar after a given timestamp * Returns all events from the calendar after a given timestamp
* *
* @param SG_iCalReader|array $ical The calendar to query * @param SG_iCalReader|array $ical The calendar to query
* @param int $start * @param int $start
* @return SG_iCal_VEvent[] * @return SG_iCal_VEvent[]
@ -50,7 +50,7 @@ class SG_iCal_Query {
if( !is_array($ical) ) { if( !is_array($ical) ) {
throw new Exception('SG_iCal_Query::After called with invalid input!'); throw new Exception('SG_iCal_Query::After called with invalid input!');
} }
$rtn = array(); $rtn = array();
foreach( $ical AS $e ) { foreach( $ical AS $e ) {
if($e->getStart() >= $start || $e->getRangeEnd() >= $start) { if($e->getStart() >= $start || $e->getRangeEnd() >= $start) {
@ -59,10 +59,10 @@ class SG_iCal_Query {
} }
return $rtn; return $rtn;
} }
/** /**
* Sorts the events from the calendar after the specified column. * Sorts the events from the calendar after the specified column.
* Column can be all valid entires that getProperty can return. * Column can be all valid entires that getProperty can return.
* So stuff like uid, start, end, summary etc. * So stuff like uid, start, end, summary etc.
* @param SG_iCalReader|array $ical The calendar to query * @param SG_iCalReader|array $ical The calendar to query
* @param string $column * @param string $column
@ -75,7 +75,7 @@ class SG_iCal_Query {
if( !is_array($ical) ) { if( !is_array($ical) ) {
throw new Exception('SG_iCal_Query::Sort called with invalid input!'); throw new Exception('SG_iCal_Query::Sort called with invalid input!');
} }
$cmp = create_function('$a, $b', 'return strcmp($a->getProperty("' . $column . '"), $b->getProperty("' . $column . '"));'); $cmp = create_function('$a, $b', 'return strcmp($a->getProperty("' . $column . '"), $b->getProperty("' . $column . '"));');
usort($ical, $cmp); usort($ical, $cmp);
return $ical; return $ical;

Wyświetl plik

@ -15,12 +15,12 @@
class SG_iCal_Recurrence { class SG_iCal_Recurrence {
public $rrule; public $rrule;
protected $freq; protected $freq;
protected $until; protected $until;
protected $count; protected $count;
protected $interval; protected $interval;
protected $bysecond; protected $bysecond;
protected $byminute; protected $byminute;
@ -31,6 +31,7 @@ class SG_iCal_Recurrence {
protected $byyearno; protected $byyearno;
protected $bymonth; protected $bymonth;
protected $bysetpos; protected $bysetpos;
protected $wkst; protected $wkst;
/** /**
@ -58,7 +59,7 @@ class SG_iCal_Recurrence {
*/ */
protected function parseLine($line) { protected function parseLine($line) {
$this->rrule = $line; $this->rrule = $line;
//split up the properties //split up the properties
$recurProperties = explode(';', $line); $recurProperties = explode(';', $line);
$recur = array(); $recur = array();

Wyświetl plik

@ -23,12 +23,12 @@ class FreqTest extends PHPUnit_Framework_TestCase {
873961200, 873961200,
-1 -1
); );
$rule = 'FREQ=DAILY;COUNT=10'; $rule = 'FREQ=DAILY;COUNT=10';
$start = strtotime('19970902T090000'); $start = strtotime('19970902T090000');
$this->assertRule( $rule, $start, $dateset); $this->assertRule( $rule, $start, $dateset);
} }
public function testDailyUntil() { public function testDailyUntil() {
$dateset = array( $dateset = array(
873183600, 873183600,
@ -43,15 +43,15 @@ class FreqTest extends PHPUnit_Framework_TestCase {
873961200, 873961200,
874047600 874047600
); );
$rule = 'FREQ=DAILY;UNTIL=19971224T000000Z'; $rule = 'FREQ=DAILY;UNTIL=19971224T000000Z';
$start = strtotime('19970902T090000'); $start = strtotime('19970902T090000');
$this->assertRule( $rule, $start, $dateset); $this->assertRule( $rule, $start, $dateset);
$freq = new SG_iCal_Freq($rule, $start); $freq = new SG_iCal_Freq($rule, $start);
$this->assertEquals(882864000, $freq->previousOccurrence(time())); $this->assertEquals(882864000, $freq->previousOccurrence(time()));
} }
public function testDailyInterval() { public function testDailyInterval() {
$dateset = array( $dateset = array(
873183600, 873183600,
@ -66,7 +66,7 @@ class FreqTest extends PHPUnit_Framework_TestCase {
$start = strtotime('19970902T090000'); $start = strtotime('19970902T090000');
$this->assertRule( $rule, $start, $dateset); $this->assertRule( $rule, $start, $dateset);
} }
public function testDailyIntervalCount() { public function testDailyIntervalCount() {
$dateset = array( $dateset = array(
873183600, 873183600,
@ -80,7 +80,7 @@ class FreqTest extends PHPUnit_Framework_TestCase {
$start = strtotime('19970902T090000'); $start = strtotime('19970902T090000');
$this->assertRule( $rule, $start, $dateset); $this->assertRule( $rule, $start, $dateset);
} }
public function testDailyBydayBymonthUntil() { public function testDailyBydayBymonthUntil() {
$rules = array( $rules = array(
'FREQ=YEARLY;UNTIL=20000131T090000Z;BYMONTH=1;BYDAY=SU,MO,TU,WE,TH,FR,SA', 'FREQ=YEARLY;UNTIL=20000131T090000Z;BYMONTH=1;BYDAY=SU,MO,TU,WE,TH,FR,SA',
@ -106,22 +106,22 @@ class FreqTest extends PHPUnit_Framework_TestCase {
946972800 946972800
) )
); );
foreach( $rules As $rule ) { foreach( $rules As $rule ) {
$start = strtotime('19980101T090000'); $start = strtotime('19980101T090000');
$this->assertRule( $rule, $start, $datesets[0]); $this->assertRule( $rule, $start, $datesets[0]);
$start = strtotime('+1 year', $start); $start = strtotime('+1 year', $start);
$this->assertRule( $rule, $start, $datesets[1]); $this->assertRule( $rule, $start, $datesets[1]);
$start = strtotime('+1 year', $start); $start = strtotime('+1 year', $start);
$this->assertRule( $rule, $start, $datesets[2]); $this->assertRule( $rule, $start, $datesets[2]);
$freq = new SG_iCal_Freq($rule, $start); $freq = new SG_iCal_Freq($rule, $start);
$this->assertEquals(949305600, $freq->previousOccurrence(time())); $this->assertEquals(949305600, $freq->previousOccurrence(time()));
} }
} }
public function testWeeklyCount() { public function testWeeklyCount() {
$dateset = array( $dateset = array(
873183600, 873183600,
@ -140,7 +140,7 @@ class FreqTest extends PHPUnit_Framework_TestCase {
$start = strtotime('19970902T090000'); $start = strtotime('19970902T090000');
$this->assertRule( $rule, $start, $dateset); $this->assertRule( $rule, $start, $dateset);
} }
public function testWeeklyUntil() { public function testWeeklyUntil() {
$dateset = array( $dateset = array(
873183600, 873183600,
@ -158,11 +158,11 @@ class FreqTest extends PHPUnit_Framework_TestCase {
$rule = 'FREQ=WEEKLY;UNTIL=19971224T000000Z'; $rule = 'FREQ=WEEKLY;UNTIL=19971224T000000Z';
$start = strtotime('19970902T090000'); $start = strtotime('19970902T090000');
$this->assertRule( $rule, $start, $dateset); $this->assertRule( $rule, $start, $dateset);
$freq = new SG_iCal_Freq($rule, $start); $freq = new SG_iCal_Freq($rule, $start);
$this->assertEquals(882864000, $freq->previousOccurrence(time()), 'Failed getting correct end date'); $this->assertEquals(882864000, $freq->previousOccurrence(time()), 'Failed getting correct end date');
} }
public function testWeeklyBydayLimit() { public function testWeeklyBydayLimit() {
$rules = array( $rules = array(
'FREQ=WEEKLY;UNTIL=19971007T000000Z;WKST=SU;BYDAY=TU,TH', 'FREQ=WEEKLY;UNTIL=19971007T000000Z;WKST=SU;BYDAY=TU,TH',
@ -186,7 +186,7 @@ class FreqTest extends PHPUnit_Framework_TestCase {
$this->assertRule( $rule, $start, $dateset); $this->assertRule( $rule, $start, $dateset);
} }
} }
public function testWeeklyIntervalUntilByday() { public function testWeeklyIntervalUntilByday() {
$dateset = array( $dateset = array(
873183600, 873183600,
@ -204,11 +204,11 @@ class FreqTest extends PHPUnit_Framework_TestCase {
$rule = 'FREQ=WEEKLY;INTERVAL=2;UNTIL=19971224T000000Z;WKST=SU;BYDAY=MO,WE,FR'; $rule = 'FREQ=WEEKLY;INTERVAL=2;UNTIL=19971224T000000Z;WKST=SU;BYDAY=MO,WE,FR';
$start = strtotime('19970902T090000'); $start = strtotime('19970902T090000');
$this->assertRule( $rule, $start, $dateset); $this->assertRule( $rule, $start, $dateset);
$freq = new SG_iCal_Freq($rule, $start); $freq = new SG_iCal_Freq($rule, $start);
$this->assertEquals(882777600, $freq->previousOccurrence(time()), 'Failed getting correct end date'); $this->assertEquals(882777600, $freq->previousOccurrence(time()), 'Failed getting correct end date');
} }
public function testWeeklyIntervalBydayCount() { public function testWeeklyIntervalBydayCount() {
$dateset = array( $dateset = array(
873183600, 873183600,
@ -225,7 +225,7 @@ class FreqTest extends PHPUnit_Framework_TestCase {
$start = strtotime('19970902T090000'); $start = strtotime('19970902T090000');
$this->assertRule( $rule, $start, $dateset); $this->assertRule( $rule, $start, $dateset);
} }
public function testMonthlyBydayCount() { public function testMonthlyBydayCount() {
$dateset = array( $dateset = array(
873442800, 873442800,
@ -244,7 +244,7 @@ class FreqTest extends PHPUnit_Framework_TestCase {
$start = strtotime('19970905T090000'); $start = strtotime('19970905T090000');
$this->assertRule( $rule, $start, $dateset); $this->assertRule( $rule, $start, $dateset);
} }
public function testMonthlyBydayUntil() { public function testMonthlyBydayUntil() {
$dateset = array( $dateset = array(
873442800, 873442800,
@ -257,7 +257,7 @@ class FreqTest extends PHPUnit_Framework_TestCase {
$start = strtotime('19970905T090000'); $start = strtotime('19970905T090000');
$this->assertRule( $rule, $start, $dateset); $this->assertRule( $rule, $start, $dateset);
} }
public function testMonthlyIntervalBydayCount2() { public function testMonthlyIntervalBydayCount2() {
$dateset = array( $dateset = array(
873615600, 873615600,
@ -291,7 +291,7 @@ class FreqTest extends PHPUnit_Framework_TestCase {
$start = strtotime('19970922T090000'); $start = strtotime('19970922T090000');
$this->assertRule( $rule, $start, $dateset); $this->assertRule( $rule, $start, $dateset);
} }
public function testMonthlyBymonthday() { public function testMonthlyBymonthday() {
$dateset = array( $dateset = array(
875430000, 875430000,
@ -305,7 +305,7 @@ class FreqTest extends PHPUnit_Framework_TestCase {
$start = strtotime('19970928T090000'); $start = strtotime('19970928T090000');
$this->assertRule( $rule, $start, $dateset); $this->assertRule( $rule, $start, $dateset);
} }
public function testMonthlyBymonthdayCount() { public function testMonthlyBymonthdayCount() {
$dateset = array( $dateset = array(
873183600, 873183600,
@ -324,7 +324,7 @@ class FreqTest extends PHPUnit_Framework_TestCase {
$start = strtotime('19970902T090000'); $start = strtotime('19970902T090000');
$this->assertRule( $rule, $start, $dateset); $this->assertRule( $rule, $start, $dateset);
} }
public function testMonthlyBymonthdayCount2() { public function testMonthlyBymonthdayCount2() {
$dateset = array( $dateset = array(
875602800, 875602800,
@ -343,7 +343,7 @@ class FreqTest extends PHPUnit_Framework_TestCase {
$start = strtotime('19970930T090000'); $start = strtotime('19970930T090000');
$this->assertRule( $rule, $start, $dateset); $this->assertRule( $rule, $start, $dateset);
} }
public function testMonthlyIntervalBymonthdayCount() { public function testMonthlyIntervalBymonthdayCount() {
$dateset = array( $dateset = array(
873874800, 873874800,
@ -362,7 +362,7 @@ class FreqTest extends PHPUnit_Framework_TestCase {
$start = strtotime('19970910T090000'); $start = strtotime('19970910T090000');
$this->assertRule( $rule, $start, $dateset); $this->assertRule( $rule, $start, $dateset);
} }
public function testMonthlyIntervalByday() { public function testMonthlyIntervalByday() {
$dateset = array( $dateset = array(
873183600, 873183600,
@ -380,7 +380,7 @@ class FreqTest extends PHPUnit_Framework_TestCase {
$start = strtotime('19970902T090000'); $start = strtotime('19970902T090000');
$this->assertRule( $rule, $start, $dateset); $this->assertRule( $rule, $start, $dateset);
} }
public function testYearlyCountBymonth() { public function testYearlyCountBymonth() {
$dateset = array( $dateset = array(
865926000, 865926000,
@ -399,7 +399,7 @@ class FreqTest extends PHPUnit_Framework_TestCase {
$start = strtotime('19970610T090000'); $start = strtotime('19970610T090000');
$this->assertRule( $rule, $start, $dateset); $this->assertRule( $rule, $start, $dateset);
} }
public function testYearlyIntervalCountBymonth() { public function testYearlyIntervalCountBymonth() {
$dateset = array( $dateset = array(
857980800, 857980800,
@ -418,7 +418,7 @@ class FreqTest extends PHPUnit_Framework_TestCase {
$start = strtotime('19970310T090000'); $start = strtotime('19970310T090000');
$this->assertRule( $rule, $start, $dateset); $this->assertRule( $rule, $start, $dateset);
} }
public function testYearlyIntervalCountByyearday() { public function testYearlyIntervalCountByyearday() {
$dateset = array( $dateset = array(
852105600, 852105600,
@ -437,7 +437,7 @@ class FreqTest extends PHPUnit_Framework_TestCase {
$start = strtotime('19970101T090000'); $start = strtotime('19970101T090000');
$this->assertRule( $rule, $start, $dateset); $this->assertRule( $rule, $start, $dateset);
} }
public function testYearlyByday() { public function testYearlyByday() {
$dateset = array( $dateset = array(
864025200, 864025200,
@ -448,7 +448,7 @@ class FreqTest extends PHPUnit_Framework_TestCase {
$start = strtotime('19970519T090000'); $start = strtotime('19970519T090000');
$this->assertRule( $rule, $start, $dateset); $this->assertRule( $rule, $start, $dateset);
} }
public function testYearlyByweeknoByday() { public function testYearlyByweeknoByday() {
$dateset = array( $dateset = array(
863420400, 863420400,
@ -509,7 +509,7 @@ class FreqTest extends PHPUnit_Framework_TestCase {
$start = strtotime('19970902T090000'); $start = strtotime('19970902T090000');
$this->assertRule( $rule, $start, $dateset); $this->assertRule( $rule, $start, $dateset);
} }
public function testYearlyBydayBymonthday2() { public function testYearlyBydayBymonthday2() {
$dateset = array( $dateset = array(
874134000, 874134000,
@ -527,7 +527,7 @@ class FreqTest extends PHPUnit_Framework_TestCase {
$start = strtotime('19970913T090000'); $start = strtotime('19970913T090000');
$this->assertRule( $rule, $start, $dateset); $this->assertRule( $rule, $start, $dateset);
} }
public function testYearlyIntervalBymonthBydayBymonthday() { public function testYearlyIntervalBymonthBydayBymonthday() {
$dateset = array( $dateset = array(
847180800, 847180800,
@ -538,9 +538,9 @@ class FreqTest extends PHPUnit_Framework_TestCase {
$start = strtotime('19961105T090000'); $start = strtotime('19961105T090000');
$this->assertRule( $rule, $start, $dateset); $this->assertRule( $rule, $start, $dateset);
} }
// TODO: SETPOS rules // TODO: SETPOS rules
public function testHourlyIntervalUntil() { public function testHourlyIntervalUntil() {
$dateset = array( $dateset = array(
873183600, 873183600,
@ -552,7 +552,7 @@ class FreqTest extends PHPUnit_Framework_TestCase {
$start = strtotime('19970902T090000'); $start = strtotime('19970902T090000');
$this->assertRule( $rule, $start, $dateset); $this->assertRule( $rule, $start, $dateset);
} }
public function testMinutelyIntervalCount() { public function testMinutelyIntervalCount() {
$dateset = array( $dateset = array(
873183600, 873183600,
@ -567,7 +567,7 @@ class FreqTest extends PHPUnit_Framework_TestCase {
$start = strtotime('19970902T090000'); $start = strtotime('19970902T090000');
$this->assertRule( $rule, $start, $dateset); $this->assertRule( $rule, $start, $dateset);
} }
public function testMinutelyIntervalCount2() { public function testMinutelyIntervalCount2() {
$dateset = array( $dateset = array(
873183600, 873183600,
@ -580,11 +580,11 @@ class FreqTest extends PHPUnit_Framework_TestCase {
$start = strtotime('19970902T090000'); $start = strtotime('19970902T090000');
$this->assertRule( $rule, $start, $dateset); $this->assertRule( $rule, $start, $dateset);
} }
public function testMinutelyIntervalByhour() { public function testMinutelyIntervalByhour() {
$rules = array( $rules = array(
'FREQ=MINUTELY;INTERVAL=20;BYHOUR=9,10,11,12,13,14,15,16'/*, 'FREQ=MINUTELY;INTERVAL=20;BYHOUR=9,10,11,12,13,14,15,16'/*,
'FREQ=DAILY;BYHOUR=9,10,11,12,13,14,15,16;BYMINUTE=0,20,40'*/ 'FREQ=DAILY;BYHOUR=9,10,11,12,13,14,15,16;BYMINUTE=0,20,40'*/
); );
// TODO: Fix it so multi byhour and byminute will work // TODO: Fix it so multi byhour and byminute will work
$dateset = array( $dateset = array(
@ -607,13 +607,13 @@ class FreqTest extends PHPUnit_Framework_TestCase {
/* /*
weird : in this test $start is not a matched occurrence but... weird : in this test $start is not a matched occurrence but...
to do something like that, we need EXDATE : to do something like that, we need EXDATE :
DTSTART;TZID=US-Eastern:19970902T090000 DTSTART;TZID=US-Eastern:19970902T090000
EXDATE;TZID=US-Eastern:19970902T090000 EXDATE;TZID=US-Eastern:19970902T090000
RRULE:FREQ=MONTHLY;BYDAY=FR;BYMONTHDAY=13 RRULE:FREQ=MONTHLY;BYDAY=FR;BYMONTHDAY=13
*/ */
public function testFirstOccurrencesByYearDay() { public function testFirstOccurrencesByYearDay() {
$rule = 'FREQ=YEARLY;INTERVAL=2;BYYEARDAY=1;COUNT=5'; $rule = 'FREQ=YEARLY;INTERVAL=2;BYYEARDAY=1;COUNT=5';
$start = strtotime('2009-10-27T090000'); $start = strtotime('2009-10-27T090000');
@ -621,14 +621,14 @@ class FreqTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(strtotime('2009-10-27T09:00:00'), $freq->firstOccurrence()); $this->assertEquals(strtotime('2009-10-27T09:00:00'), $freq->firstOccurrence());
$this->assertEquals(strtotime('2011-01-01T09:00:00'), $freq->nextOccurrence($start)); $this->assertEquals(strtotime('2011-01-01T09:00:00'), $freq->nextOccurrence($start));
} }
public function testFirstOccurrencesByYearDayWithoutFirstDate() { public function testFirstOccurrencesByYearDayWithoutFirstDate() {
$rule = 'FREQ=YEARLY;INTERVAL=2;BYYEARDAY=1;COUNT=5'; $rule = 'FREQ=YEARLY;INTERVAL=2;BYYEARDAY=1;COUNT=5';
$start = strtotime('2009-10-27T090000'); $start = strtotime('2009-10-27T090000');
$freq = new SG_iCal_Freq($rule, $start, array($start)); $freq = new SG_iCal_Freq($rule, $start, array($start));
$this->assertEquals(strtotime('2011-01-01T09:00:00'), $freq->firstOccurrence()); $this->assertEquals(strtotime('2011-01-01T09:00:00'), $freq->firstOccurrence());
} }
public function testLastOccurrenceByYearDay() { public function testLastOccurrenceByYearDay() {
$rule = 'FREQ=YEARLY;INTERVAL=2;BYYEARDAY=1;COUNT=5'; $rule = 'FREQ=YEARLY;INTERVAL=2;BYYEARDAY=1;COUNT=5';
$start = strtotime('2011-01-01T090000'); $start = strtotime('2011-01-01T090000');
@ -647,14 +647,14 @@ class FreqTest extends PHPUnit_Framework_TestCase {
/* TODO: BYSETPOS rule : /* TODO: BYSETPOS rule :
The 3rd instance into the month of one of Tuesday, Wednesday or The 3rd instance into the month of one of Tuesday, Wednesday or
Thursday, for the next 3 months: Thursday, for the next 3 months:
DTSTART;TZID=US-Eastern:19970904T090000 DTSTART;TZID=US-Eastern:19970904T090000
RRULE:FREQ=MONTHLY;COUNT=3;BYDAY=TU,WE,TH;BYSETPOS=3 RRULE:FREQ=MONTHLY;COUNT=3;BYDAY=TU,WE,TH;BYSETPOS=3
*/ */
/* TODO: WKST rule /* TODO: WKST rule
*/ */
//check a serie of dates //check a serie of dates
private function assertRule( $rule, $start, $dateset ) { private function assertRule( $rule, $start, $dateset ) {
$freq = new SG_iCal_Freq($rule, $start); $freq = new SG_iCal_Freq($rule, $start);