Removing old tests and translations directories

This commit is contained in:
Manuel Cillero 2017-08-09 10:49:41 +02:00
parent 433e7eec80
commit dfa2e142a7
53 changed files with 0 additions and 20508 deletions

View file

@ -1,19 +0,0 @@
The tests here were written for an older version of simpletest and
still need to be updated to work with the current version.
This folder includes files that can be used to test imports of date information.
To test them, set up FeedAPI and the Feed Element Mapper with Parser iCal
or Parser CVS and import these files into a date field.
- rrule.ics:
Creates repeating dates using a wide variety of RRULEs.
- Yahoo.csv:
This file uses the csv export format from Yahoo Calendar, similar to the
format created by Outlook's csv export. The sample contains both timed
and untimed 'All day' events.
- USHolidays.ics:
An ical export of US Holidays in the 'All day' format used by
Microsoft and Apple (where the Start date is the date of the event
and the End date is the following day).

File diff suppressed because it is too large Load diff

View file

@ -1,16 +0,0 @@
"Subject","Start Date","Start Time","End Date","End Time","All day event","Description"
"New Year's Day","1/1/2009","","","","true",""
"Valentine's Day","2/14/2009","","","","true",""
"St. Patrick's Day","3/17/2009","","","","true",""
"Memorial Day","5/31/2009","","","","true",""
"Independence Day","7/4/2009","","","","true",""
"Labor Day","09/07/2009","","","","true",""
"Halloween","10/31/2009","","","","true",""
"Veteran's Day","11/11/2009","","","","true",""
"Thanksgiving Day","11/26/2009","","","","true",""
"Christmas Day","12/25/2009","","","","true",""
"Do It With Drupal","12/10/2008","08:00 AM","12/10/2008","05:00 PM","false",""
"DrupalCon","03/04/2009","08:00 AM","03/04/2009","05:00 PM","false",""
"DrupalCon","03/05/2009","08:00 AM","03/05/2009","05:00 PM","false",""
"DrupalCon","03/06/2009","08:00 AM","03/06/2009","05:00 PM","false",""
"DrupalCon","03/07/2009","08:00 AM","03/07/2009","05:00 PM","false",""
1 Subject Start Date Start Time End Date End Time All day event Description
2 New Year's Day 1/1/2009 true
3 Valentine's Day 2/14/2009 true
4 St. Patrick's Day 3/17/2009 true
5 Memorial Day 5/31/2009 true
6 Independence Day 7/4/2009 true
7 Labor Day 09/07/2009 true
8 Halloween 10/31/2009 true
9 Veteran's Day 11/11/2009 true
10 Thanksgiving Day 11/26/2009 true
11 Christmas Day 12/25/2009 true
12 Do It With Drupal 12/10/2008 08:00 AM 12/10/2008 05:00 PM false
13 DrupalCon 03/04/2009 08:00 AM 03/04/2009 05:00 PM false
14 DrupalCon 03/05/2009 08:00 AM 03/05/2009 05:00 PM false
15 DrupalCon 03/06/2009 08:00 AM 03/06/2009 05:00 PM false
16 DrupalCon 03/07/2009 08:00 AM 03/07/2009 05:00 PM false

View file

@ -1,146 +0,0 @@
<?php
/**
* @file
* Date test.
*/
class DateTestCase extends DrupalWebTestCase {
protected $privileged_user;
function getInfo() {
return array(
'name' => 'CCK UI',
'description' => 'Test creation of various date fields and widgets using CCK UI.',
'group' => 'Date',
);
}
function setUp() {
// Load the date_api module.
parent::setUp('content', 'date_api', 'date_timezone', 'date', 'date_popup', 'jquery_ui');
// Create and log in our privileged user.
$this->privileged_user = $this->drupalCreateUser(array(
'administer content types', 'administer nodes'
));
$this->drupalLogin($this->privileged_user);
variable_set('date_format_long', 'D, m/d/Y - H:i');
variable_set('date_format_short', 'm/d/Y - H:i');
variable_set('date_popup_timepicker', 'none');
}
function testDate() {
// Creates select list date field stored as a date with default settings.
$this->createDateField($type = 'date', $widget = 'date_select');
$edit = array();
$this->drupalPost(NULL, $edit, t('Save field settings'));
$this->dateForm($options = 'select');
$this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a date field using the date_select widget.');
$this->deleteDateField();
// Creates text date field stored as a date with default settings.
$this->createDateField($type = 'date', $widget = 'date_text');
$edit = array();
$this->drupalPost(NULL, $edit, t('Save field settings'));
$this->dateForm($options = 'text');
$this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a date field using the date_text widget.');
$this->deleteDateField();
// Creates popup date field stored as a date with default settings.
$this->createDateField($type = 'date', $widget = 'date_popup');
$edit = array(
'input_format' => 'm/d/Y - H:i',
);
$this->drupalPost(NULL, $edit, t('Save field settings'));
$this->dateForm($options = 'popup');
$this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a date field using the date_popup widget.');
$this->deleteDateField();
// Creates select list date field stored as a datestamp with default settings.
$this->createDateField($type = 'datestamp', $widget = 'date_select');
$edit = array();
$this->drupalPost(NULL, $edit, t('Save field settings'));
$this->dateForm($options = 'select');
$this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datestamp field using the date_select widget.');
$this->deleteDateField();
// Creates text date field stored as a datestamp with default settings.
$this->createDateField($type = 'datestamp', $widget = 'date_text');
$edit = array();
$this->drupalPost(NULL, $edit, t('Save field settings'));
$this->dateForm($options = 'text');
$this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datestamp field using the date_text widget.');
$this->deleteDateField();
// Creates popup date field stored as a datestamp with default settings.
$this->createDateField($type = 'datestamp', $widget = 'date_popup');
$edit = array(
'input_format' => 'm/d/Y - H:i',
);
$this->drupalPost(NULL, $edit, t('Save field settings'));
$this->dateForm($options = 'popup');
$this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datestamp field using the date_popup widget.');
$this->deleteDateField();
// Creates select list date field stored as a datetime with default settings.
$this->createDateField($type = 'datetime', $widget = 'date_select');
$edit = array();
$this->drupalPost(NULL, $edit, t('Save field settings'));
$this->dateForm($options = 'select');
$this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datetime field using the date_select widget.');
$this->deleteDateField();
// Creates text date field stored as a datetime with default settings.
$this->createDateField($type = 'datetime', $widget = 'date_text');
$edit = array();
$this->drupalPost(NULL, $edit, t('Save field settings'));
$this->dateForm($options = 'text');
$this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datetime field using the date_text widget.');
$this->deleteDateField();
// Creates popup date field stored as a datetime with default settings.
$this->createDateField($type = 'datetime', $widget = 'date_popup');
$edit = array(
'input_format' => 'm/d/Y - H:i',
);
$this->drupalPost(NULL, $edit, t('Save field settings'));
$this->dateForm($options = 'popup');
$this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datetime field using the date_popup widget.');
$this->deleteDateField();
}
function createDateField($type, $widget) {
$edit = array();
$edit['_add_new_field[label]'] = 'Test';
$edit['_add_new_field[field_name]'] = 'test';
$edit['_add_new_field[weight]'] = '-4';
$edit['_add_new_field[type]'] = $type;
$edit['_add_new_field[widget_type]'] = $widget;
$this->drupalPost('admin/content/node-type/story/fields', $edit, t('Save'));
}
function dateForm($options) {
// Tests that date field functions properly.
$edit = array();
$edit['title'] = $this->randomName(8);
$edit['body'] = $this->randomName(16);
if ($options == 'select') {
$edit['field_test[0][value][year]'] = '2010';
$edit['field_test[0][value][month]'] = '10';
$edit['field_test[0][value][day]'] = '7';
$edit['field_test[0][value][hour]'] = '10';
$edit['field_test[0][value][minute]'] = '30';
}
elseif ($options == 'text') {
$edit['field_test[0][value][date]'] = '10/07/2010 - 10:30';
}
elseif ($options == 'popup') {
// The default format for a popup is an odd one.
$edit['field_test[0][value][date]'] = '10/07/2010';
$edit['field_test[0][value][time]'] = '10:30';
}
$this->drupalPost('node/add/story', $edit, t('Save'));
$this->assertText($edit['title'], 'Test node has been created');
}
function deleteDateField() {
$this->drupalGet('admin/content/node-type/story/fields');
$this->clickLink('Remove');
$this->drupalPost(NULL, NULL, t('Remove'));
$this->assertText('Removed field Test from Story.', 'Removed date field.');
}
}

View file

@ -1,414 +0,0 @@
<?php
/**
* Test Date API functions
*/
class DateAPITestCase extends DrupalWebTestCase {
function getInfo() {
return array(
'name' => t('Date API'),
'description' => t('Test Date API functions.') ,
'group' => t('Date'),
);
}
/**
* Implementation of setUp().
*/
public function setUp() {
// Load the date_api module.
parent::setUp('date_api', 'date_timezone');
variable_set('date_api_use_iso8601', FALSE);
variable_set('date_first_day', 1);
}
function testDateAPI() {
$value = '2007-12-05 23:59';
$this->assertEqual(TRUE, date_part_extract($value, 'year'), "Test date_part_extract(". $value .", year), results ". date_part_extract($value, 'year'));
$this->assertEqual(TRUE, date_part_extract($value, 'month'), "Test date_part_extract(". $value .", mon), results ". date_part_extract($value, 'month'));
$this->assertEqual(TRUE, date_part_extract($value, 'day'), "Test date_part_extract(". $value .", mday), results ". date_part_extract($value, 'day'));
$this->assertEqual(TRUE, date_is_valid($value), "Test date_is_valid(". $value .")");
$value = '2007-00-00 00:00';
$this->assertNotEqual(TRUE, date_is_valid($value), "Test for invalid date_is_valid(". $value .")");
$value = '0000-00-00 00:00';
$this->assertNotEqual(TRUE, date_is_valid($value), "Test for invalid date_is_valid(". $value .")");
$value = '-100';
$this->assertNotEqual(TRUE, date_is_valid($value), "Test for invalid date_is_valid(". $value .")");
$value = '2007-00-01T00:00';
$this->assertEqual(TRUE, date_is_valid($value, DATE_ISO), "Test ISO exception to date_is_valid(". $value .", DATE_ISO)");
$dates = array(
'2007-01-01 00:00:00',
'1970-01-01 00:00:00',
'1900-01-01 00:00:00',
'1600-01-01 00:00:00',
'0100-01-01 00:00:00');
foreach ($dates as $date) {
$unix = date_convert($date, DATE_DATETIME, DATE_UNIX);
$datetime = date_convert($unix, DATE_UNIX, DATE_DATETIME);
$this->assertEqual($date, $datetime, 'Test roundtrip using date_convert() from DATE_DATETIME to DATE_UNIX back to DATE_DATETIME, results '. $date .' >> '. $unix .' >> '. $datetime);
}
// Test date_format_date().
$formatters = array(
'a',
'A',
'B',
'c',
'd',
'D',
'e',
'F',
'g',
'G',
'h',
'H',
'i',
'I',
'j',
'l',
'L',
'm',
'M',
'n',
'N',
'o',
'O',
'P',
'r',
'R',
's',
'S',
't',
'T',
'u',
'U',
'w',
'W',
'y',
'Y',
'z',
'Z',
);
foreach ($formatters as $formatter) {
$date_api_format = date_format_date(date_now(), 'custom', $formatter);
$php_format = date_format(date_now(), $formatter);
$this->assertEqual($date_api_format, $php_format, 'Test that the "' . $formatter . '" formatter is formatted correctly by date_format_date()');
}
// Test the order of the weeks days for a calendar that starts on Monday and one that starts on Sunday.
variable_set('date_first_day', 1);
$expected = array( 0 => t('Mon'), 1 => t('Tue'), 2 => t('Wed'), 3 => t('Thu'), 4 => t('Fri'), 5 => t('Sat'), 6 => t('Sun'), );
$days = date_week_days_ordered(date_week_days_abbr(1));
$this->assertEqual($expected, $days, 'Test that date_week_days_ordered() array starts on Monday when the site first day is on Monday.');
variable_set('date_first_day', 0);
$expected = array( 0 => t('Sun'), 1 => t('Mon'), 2 => t('Tue'), 3 => t('Wed'), 4 => t('Thu'), 5 => t('Fri'), 6 => t('Sat'), );
$days = date_week_days_ordered(date_week_days_abbr(1));
$this->assertEqual($expected, $days, 'Test that date_week_days_ordered() array starts on Sunday when the site first day is on Sunday.');
// Test days in February for a leap year and a non-leap year.
$expected = 28;
$value = date_days_in_month(2005, 2);
$this->assertEqual($expected, $value, "Test date_days_in_month(2, 2005): should be $expected, found $value.");
$expected = 29;
$value = date_days_in_month(2004, 2);
$this->assertEqual($expected, $value, "Test date_days_in_month(2, 2004): should be $expected, found $value.");
// Test days in year for a leap year and a non-leap year.
$expected = 365;
$value = date_days_in_year('2005-06-01 00:00:00', DATE_DATETIME);
$this->assertEqual($expected, $value, "Test date_days_in_year(2005-06-01, DATE_DATETIME): should be $expected, found $value.");
$expected = 366;
$value = date_days_in_year('2004-06-01 00:00:00', DATE_DATETIME);
$this->assertEqual($expected, $value, "Test date_days_in_year(2004-06-01, DATE_DATETIME): should be $expected, found $value.");
// Test ISO weeks for a leap year and a non-leap year.
$expected = 52;
$value = date_iso_weeks_in_year('2008-06-01 00:00:00', DATE_DATETIME);
$this->assertEqual($expected, $value, "Test date_iso_weeks_in_year(2008-06-01, DATE_DATETIME): should be $expected, found $value.");
$expected = 53;
$value = date_iso_weeks_in_year('2009-06-01 00:00:00', DATE_DATETIME);
$this->assertEqual($expected, $value, "Test date_iso_weeks_in_year(2009-06-01, DATE_DATETIME): should be $expected, found $value.");
// Test day of week for March 1, the day after leap day.
$expected = 6;
$value = date_day_of_week('2008-03-01 00:00:00', DATE_DATETIME);
$this->assertEqual($expected, $value, "Test date_day_of_week(2008-03-01, DATE_DATETIME): should be $expected, found $value.");
$expected = 0;
$value = date_day_of_week('2009-03-01 00:00:00', DATE_DATETIME);
$this->assertEqual($expected, $value, "Test date_day_of_week(2009-03-01, DATE_DATETIME): should be $expected, found $value.");
// Test day of week name for March 1, the day after leap day.
$expected = 'Sat';
$value = date_day_of_week_name('2008-03-01 00:00:00', DATE_DATETIME);
$this->assertEqual($expected, $value, "Test date_day_of_week_name(2008-03-01, DATE_DATETIME): should be $expected, found $value.");
$expected = 'Sun';
$value = date_day_of_week_name('2009-03-01 00:00:00', DATE_DATETIME);
$this->assertEqual($expected, $value, "Test date_day_of_week_name(2009-03-01, DATE_DATETIME): should be $expected, found $value.");
// Test week range with calendar weeks.
variable_set('date_first_day', 0);
variable_set('date_api_use_iso8601', FALSE);
$expected = '2008-01-27 to 2008-02-03';
$result = date_week_range(5, 2008);
$value = $result[0]->format(DATE_FORMAT_DATE) .' to '. $result[1]->format(DATE_FORMAT_DATE);
$this->assertEqual($expected, $value, "Test calendar date_week_range(5, 2008): should be $expected, found $value.");
$expected = '2009-01-25 to 2009-02-01';
$result = date_week_range(5, 2009);
$value = $result[0]->format(DATE_FORMAT_DATE) .' to '. $result[1]->format(DATE_FORMAT_DATE);
$this->assertEqual($expected, $value, "Test calendar date_week_range(5, 2009): should be $expected, found $value.");
// And now with ISO weeks.
variable_set('date_first_day', 1);
variable_set('date_api_use_iso8601', TRUE);
$expected = '2008-01-28 to 2008-02-04';
$result = date_week_range(5, 2008);
$value = $result[0]->format(DATE_FORMAT_DATE) .' to '. $result[1]->format(DATE_FORMAT_DATE);
$this->assertEqual($expected, $value, "Test ISO date_week_range(5, 2008): should be $expected, found $value.");
$expected = '2009-01-26 to 2009-02-02';
$result = date_week_range(5, 2009);
$value = $result[0]->format(DATE_FORMAT_DATE) .' to '. $result[1]->format(DATE_FORMAT_DATE);
$this->assertEqual($expected, $value, "Test ISO date_week_range(5, 2009): should be $expected, found $value.");
variable_set('date_api_use_iso8601', FALSE);
// Find calendar week for a date.
variable_set('date_first_day', 0);
$expected = '09';
$value = date_week('2008-03-01');
$this->assertEqual($expected, $value, "Test date_week(2008-03-01): should be $expected, found $value.");
$expected = '10';
$value = date_week('2009-03-01');
$this->assertEqual($expected, $value, "Test date_week(2009-03-01): should be $expected, found $value.");
// Create date object from datetime string.
$input = '2009-03-07 10:30';
$timezone = 'America/Chicago';
$date = date_make_date($input, $timezone);
$value = date_format($date, 'c');
$expected = '2009-03-07T10:30:00-06:00';
$this->assertEqual($expected, $value, "Test date_make_date($input, $timezone): should be $expected, found $value.");
// Same during daylight savings time.
$input = '2009-06-07 10:30';
$timezone = 'America/Chicago';
$date = date_make_date($input, $timezone);
$value = date_format($date, 'c');
$expected = '2009-06-07T10:30:00-05:00';
$this->assertEqual($expected, $value, "Test date_make_date($input, $timezone): should be $expected, found $value.");
// Create date object from date string.
$input = '2009-03-07';
$timezone = 'America/Chicago';
$date = date_make_date($input, $timezone);
$value = date_format($date, 'c');
$expected = '2009-03-07T00:00:00-06:00';
$this->assertEqual($expected, $value, "Test date_make_date($input, $timezone): should be $expected, found $value.");
// Same during daylight savings time.
$input = '2009-06-07';
$timezone = 'America/Chicago';
$date = date_make_date($input, $timezone);
$value = date_format($date, 'c');
$expected = '2009-06-07T00:00:00-05:00';
$this->assertEqual($expected, $value, "Test date_make_date($input, $timezone): should be $expected, found $value.");
// Create date object from date array, date only.
$input = array('year' => 2010, 'month' => 2, 'day' => 28);
$timezone = 'America/Chicago';
$granularity = array('year', 'month', 'day');
$date = date_make_date($input, $timezone, DATE_ARRAY, $granularity);
$value = date_format($date, 'c');
$expected = '2010-02-28T00:00:00-06:00';
$this->assertEqual($expected, $value, "Test date_make_date(array('year' => 2010, 'month' => 2, 'day' => 28), $timezone, DATE_ARRAY, array('year', 'month', 'day')): should be $expected, found $value.");
// Create date object from date array with hour.
$input = array('year' => 2010, 'month' => 2, 'day' => 28, 'hour' => 10);
$timezone = 'America/Chicago';
$granularity = array('year', 'month', 'day', 'hour');
$date = date_make_date($input, $timezone, DATE_ARRAY, $granularity);
$value = date_format($date, 'c');
$expected = '2010-02-28T10:00:00-06:00';
$this->assertEqual($expected, $value, "Test date_make_date(array('year' => 2010, 'month' => 2, 'day' => 28, 'hour' => 10), $timezone, DATE_ARRAY, array('year', 'month', 'day', 'hour')): should be $expected, found $value.");
// 0 = January 1, 1970 00:00:00 (UTC);
// 1000000000 = September 9, 2001 01:46:40 (UTC);
// Create date object from unix timestamp and convert it to a local date.
$input = 0;
$timezone = 'UTC';
$date = date_make_date($input, $timezone, DATE_UNIX);
$value = date_format($date, 'c');
$expected = '1970-01-01T00:00:00+00:00';
$this->assertEqual($expected, $value, "Test date_make_date($input, $timezone, DATE_UNIX): should be $expected, found $value.");
$expected = 'UTC';
$value = timezone_name_get(date_timezone_get($date));
$this->assertEqual($expected, $value, "The current timezone is $value: should be $expected.");
$expected = 0;
$value = date_offset_get($date);
$this->assertEqual($expected, $value, "The current offset is $value: should be $expected.");
$timezone = 'America/Los_Angeles';
date_timezone_set($date, timezone_open($timezone));
$value = date_format($date, 'c');
$expected = '1969-12-31T16:00:00-08:00';
$this->assertEqual($expected, $value, "Test date_timezone_set(\$date, timezone_open($timezone)): should be $expected, found $value.");
$expected = 'America/Los_Angeles';
$value = timezone_name_get(date_timezone_get($date));
$this->assertEqual($expected, $value, "The current timezone should be $expected, found $value.");
$expected = '-28800';
$value = date_offset_get($date);
$this->assertEqual($expected, $value, "The current offset should be $expected, found $value.");
// Convert the local version of a timestamp to UTC.
$input = 0;
$timezone = 'America/Los_Angeles';
$date = date_make_date($input, $timezone, DATE_UNIX);
$offset = date_offset_get($date);
$value = date_format($date, 'c');
$expected = '1969-12-31T16:00:00-08:00';
$this->assertEqual($expected, $value, "Test date_make_date($input, $timezone, DATE_UNIX): should be $expected, found $value.");
$expected = 'America/Los_Angeles';
$value = timezone_name_get(date_timezone_get($date));
$this->assertEqual($expected, $value, "The current timezone should be $expected, found $value.");
$expected = '-28800';
$value = date_offset_get($date);
$this->assertEqual($expected, $value, "The current offset should be $expected, found $value.");
$timezone = 'UTC';
date_timezone_set($date, timezone_open($timezone));
$value = date_format($date, 'c');
$expected = '1970-01-01T00:00:00+00:00';
$this->assertEqual($expected, $value, "Test date_timezone_set(\$date, timezone_open($timezone)): should be $expected, found $value.");
$expected = 'UTC';
$value = timezone_name_get(date_timezone_get($date));
$this->assertEqual($expected, $value, "The current timezone should be $expected, found $value.");
$expected = '0';
$value = date_offset_get($date);
$this->assertEqual($expected, $value, "The current offset should be $expected, found $value.");
// Create date object from datetime string and convert it to a local date.
$input = '1970-01-01 00:00:00';
$timezone = 'UTC';
$date = date_make_date($input, $timezone);
$value = date_format($date, 'c');
$expected = '1970-01-01T00:00:00+00:00';
$this->assertEqual($expected, $value, "Test date_make_date('$input', '$timezone'): should be $expected, found $value.");
$expected = 'UTC';
$value = timezone_name_get(date_timezone_get($date));
$this->assertEqual($expected, $value, "The current timezone is $value: should be $expected.");
$expected = 0;
$value = date_offset_get($date);
$this->assertEqual($expected, $value, "The current offset is $value: should be $expected.");
$timezone = 'America/Los_Angeles';
date_timezone_set($date, timezone_open($timezone));
$value = date_format($date, 'c');
$expected = '1969-12-31T16:00:00-08:00';
$this->assertEqual($expected, $value, "Test date_timezone_set(timezone_open($timezone)): should be $expected, found $value.");
$expected = 'America/Los_Angeles';
$value = timezone_name_get(date_timezone_get($date));
$this->assertEqual($expected, $value, "The current timezone should be $expected, found $value.");
$expected = '-28800';
$value = date_offset_get($date);
$this->assertEqual($expected, $value, "The current offset should be $expected, found $value.");
// Convert the local version of a datetime string to UTC.
$input = '1969-12-31 16:00:00';
$timezone = 'America/Los_Angeles';
$date = date_make_date($input, $timezone);
$offset = date_offset_get($date);
$value = date_format($date, 'c');
$expected = '1969-12-31T16:00:00-08:00';
$this->assertEqual($expected, $value, "Test date_make_date('$input', '$timezone'): should be $expected, found $value.");
$expected = 'America/Los_Angeles';
$value = timezone_name_get(date_timezone_get($date));
$this->assertEqual($expected, $value, "The current timezone should be $expected, found $value.");
$expected = '-28800';
$value = date_offset_get($date);
$this->assertEqual($expected, $value, "The current offset should be $expected, found $value.");
$timezone = 'UTC';
date_timezone_set($date, timezone_open($timezone));
$value = date_format($date, 'c');
$expected = '1970-01-01T00:00:00+00:00';
$this->assertEqual($expected, $value, "Test date_timezone_set(\$date, timezone_open($timezone)): should be $expected, found $value.");
$expected = 'UTC';
$value = timezone_name_get(date_timezone_get($date));
$this->assertEqual($expected, $value, "The current timezone should be $expected, found $value.");
$expected = '0';
$value = date_offset_get($date);
$this->assertEqual($expected, $value, "The current offset should be $expected, found $value.");
// Create year-only date.
$input = '2009-00-00T00:00:00';
$timezone = NULL;
$granularity = array('year');
$date = date_make_date($input, $timezone, DATE_DATETIME, $granularity);
$value = date_format($date, 'Y');
$expected = '2009';
$this->assertEqual($expected, $value, "Test date_make_date($input, $timezone, DATE_DATETIME, array('year')): should be $expected, found $value.");
// Create month and year-only date.
$input = '2009-10-00T00:00:00';
$timezone = NULL;
$granularity = array('year', 'month');
$date = date_make_date($input, $timezone, DATE_DATETIME, $granularity);
$value = date_format($date, 'Y-m');
$expected = '2009-10';
$this->assertEqual($expected, $value, "Test date_make_date($input, $timezone, DATE_DATETIME, array('year', 'month')): should be $expected, found $value.");
// Create time-only date.
$input = '0000-00-00T10:30:00';
$timezone = NULL;
$granularity = array('hour', 'minute', 'second');
$date = date_make_date($input, $timezone, DATE_DATETIME, $granularity);
$value = date_format($date, 'H:i:s');
$expected = '10:30:00';
$this->assertEqual($expected, $value, "Test date_make_date($input, $timezone, DATE_DATETIME, array('hour', 'minute', 'second')): should be $expected, found $value.");
// Test date ranges.
$valid = array(
'-20:+20',
'-1:+0',
'-10:-5',
'2000:2020',
'-10:2010',
'1980:-10',
'1920:+20',
);
$invalid = array(
'abc',
'abc:+20',
'1920:+20a',
'+-20:+-30',
'12:12',
'0:+20',
'-20:0',
);
foreach ($valid as $range) {
$this->assertTrue(date_range_valid($range), "$range recognized as a valid date range.");
}
foreach ($invalid as $range) {
$this->assertFalse(date_range_valid($range), "$range recognized as an invalid date range.");
}
}
/**
* Implementation of tearDown().
*/
function tearDown() {
variable_del('date_first_day');
variable_del('date_api_use_iso8601');
parent::tearDown();
}
}

View file

@ -1,447 +0,0 @@
<?php
/**
* @file
* Test for Date Repeat.
*/
/**
* Test PHP 4 Timezone Conversion
*/
class DateRepeatTestCase extends DrupalWebTestCase {
function getInfo() {
return array(
'name' => t('Date repeat calculations'),
'description' => t('Test Date Repeat processes to create arrays of dates from iCal rules.') ,
'group' => t('Date'),
);
}
/**
* Implementation of setUp().
*/
function setUp() {
// Load the date_repeat module.
parent::setUp('date_api', 'date_timezone', 'date_repeat', 'jquery_ui');
}
public function testDateRepeat() {
require_once('./'. drupal_get_path('module', 'date_api') .'/date_api_ical.inc');
require_once('./'. drupal_get_path('module', 'date_repeat') .'/date_repeat_calc.inc');
// Examples adapted from http://www.faqs.org/rfcs/rfc2445.html and
// http://www.kanzaki.com/docs/ical/rrule.html.
// Daily for 10 occurrences:
$start = "1997-09-02 09:00:00";
$end = "1997-09-30 09:00:00";
$rule = "RRULE:FREQ=DAILY;COUNT=10";
$dates = date_repeat_calc($rule, $start, $end, array());
// should be (1997 9:00 AM EDT)September 2-11
$shouldbe = '1997-09-02 09:00:00, 1997-09-03 09:00:00, 1997-09-04 09:00:00, 1997-09-05 09:00:00, 1997-09-06 09:00:00, 1997-09-07 09:00:00, 1997-09-08 09:00:00, 1997-09-09 09:00:00, 1997-09-10 09:00:00, 1997-09-11 09:00:00';
$result = implode(', ', $dates);
$this->assertEqual($result, $shouldbe, $rule .'; Starting '. $start .'; results: '. $result);
//Daily until September 24, 1997:
$start = "1997-09-02 09:00:00";
$end = "1997-09-30 09:00:00";
$rule = "RRULE:FREQ=DAILY;UNTIL=19970924T000000Z";
$dates = date_repeat_calc($rule, $start, $end, array());
// should be (1997 9:00 AM EDT)September 2-23
$shouldbe = '1997-09-02 09:00:00, 1997-09-03 09:00:00, 1997-09-04 09:00:00, 1997-09-05 09:00:00, 1997-09-06 09:00:00, 1997-09-07 09:00:00, 1997-09-08 09:00:00, 1997-09-09 09:00:00, 1997-09-10 09:00:00, 1997-09-11 09:00:00, 1997-09-12 09:00:00, 1997-09-13 09:00:00, 1997-09-14 09:00:00, 1997-09-15 09:00:00, 1997-09-16 09:00:00, 1997-09-17 09:00:00, 1997-09-18 09:00:00, 1997-09-19 09:00:00, 1997-09-20 09:00:00, 1997-09-21 09:00:00, 1997-09-22 09:00:00, 1997-09-23 09:00:00';
$result = implode(', ', $dates);
$this->assertEqual($result, $shouldbe, $rule .'; Starting '. $start .'; results: '. $result);
//Every other day - until September 30:
$start = "1997-09-02 09:00:00";
$end = "1997-09-30 09:00:00";
$rule = "RRULE:FREQ=DAILY;INTERVAL=2";
$dates = date_repeat_calc($rule, $start, $end, array());
// should be (1997 9:00 AM EDT)September2,4,6,8...24,26,28,30;
$shouldbe = '1997-09-02 09:00:00, 1997-09-04 09:00:00, 1997-09-06 09:00:00, 1997-09-08 09:00:00, 1997-09-10 09:00:00, 1997-09-12 09:00:00, 1997-09-14 09:00:00, 1997-09-16 09:00:00, 1997-09-18 09:00:00, 1997-09-20 09:00:00, 1997-09-22 09:00:00, 1997-09-24 09:00:00, 1997-09-26 09:00:00, 1997-09-28 09:00:00, 1997-09-30 09:00:00';
$result = implode(', ', $dates);
$this->assertEqual($result, $shouldbe, $rule .'; Starting '. $start .'; results: '. $result);
//Every 10 days, 2 occurrences:
$start = "1997-09-02 09:00:00";
$end = "1997-09-30 09:00:00";
$rule = "RRULE:FREQ=DAILY;INTERVAL=10;COUNT=2";
$dates = date_repeat_calc($rule, $start, $end, array());
// should be (1997 9:00 AM EDT)September 2,12
$shouldbe = '1997-09-02 09:00:00, 1997-09-12 09:00:00';
$result = implode(', ', $dates);
$this->assertEqual($result, $shouldbe, $rule .'; Starting '. $start .'; results: '. $result);
//Weekly for 3 occurrences
$start = "1997-09-02 09:00:00";
$end = "1997-09-30 09:00:00";
$rule = "RRULE:FREQ=WEEKLY;COUNT=3";
$dates = date_repeat_calc($rule, $start, $end, array());
// should be (1997 9:00 AM EDT)September 2,9,16
$shouldbe = '1997-09-02 09:00:00, 1997-09-09 09:00:00, 1997-09-16 09:00:00';
$result = implode(', ', $dates);
$this->assertEqual($result, $shouldbe, $rule .'; Starting '. $start .'; results: '. $result);
//Weekly until September 24, 1997
$start = "1997-09-02 09:00:00";
$end = "1997-09-30 09:00:00";
$rule = "RRULE:FREQ=WEEKLY;UNTIL=19970924T000000Z";
// ==> (1997 9:00 AM EDT)September 2,9,16,23
$dates = date_repeat_calc($rule, $start, $end, array());
$shouldbe = '1997-09-02 09:00:00, 1997-09-09 09:00:00, 1997-09-16 09:00:00, 1997-09-23 09:00:00';
$result = implode(', ', $dates);
$this->assertEqual($result, $shouldbe, $rule .'; Starting '. $start .'; results: '. $result);
//Every other week - forever:
$start = "1997-09-02 09:00:00";
$end = "1997-09-30 09:00:00";
$rule = "RRULE:FREQ=WEEKLY;INTERVAL=2;WKST=SU";
// should be (1997 9:00 AM EDT)September 2,16,30
$dates = date_repeat_calc($rule, $start, $end, array());
$shouldbe = '1997-09-02 09:00:00, 1997-09-16 09:00:00, 1997-09-30 09:00:00';
$result = implode(', ', $dates);
$this->assertEqual($result, $shouldbe, $rule .'; Starting '. $start .'; results: '. $result);
//Weekly on Tuesday and Thursday for 4 weeks:
$start = "1997-09-02 09:00:00";
$end = "1997-09-30 09:00:00";
$rule = "RRULE:FREQ=WEEKLY;COUNT=8;WKST=SU;BYDAY=TU,TH";
// should be(1997 9:00 AM EDT)September 2,4,9,11,16,18,23,25
$dates = date_repeat_calc($rule, $start, $end, array());
$shouldbe = '1997-09-02 09:00:00, 1997-09-04 09:00:00, 1997-09-09 09:00:00, 1997-09-11 09:00:00, 1997-09-16 09:00:00, 1997-09-18 09:00:00, 1997-09-23 09:00:00, 1997-09-25 09:00:00';
$result = implode(', ', $dates);
$this->assertEqual($result, $shouldbe, $rule .'; Starting '. $start .'; results: '. $result);
//Every other week on Tuesday and Thursday, for 5 occurrences:
$start = "1997-09-02 09:00:00";
$end = "1997-09-30 09:00:00";
$rule = "RRULE:FREQ=WEEKLY;INTERVAL=2;COUNT=5;WKST=SU;BYDAY=TU,TH";
// should be (1997 9:00 AM EDT)September 2,4,16,18,30
$dates = date_repeat_calc($rule, $start, $end, array());
$shouldbe = '1997-09-02 09:00:00, 1997-09-04 09:00:00, 1997-09-16 09:00:00, 1997-09-18 09:00:00, 1997-09-30 09:00:00';
$result = implode(', ', $dates);
$this->assertEqual($result, $shouldbe, $rule .'; Starting '. $start .'; results: '. $result);
//Every other week on Monday, Wednesday and Friday until September 24, 1997,
$start = "1997-09-02 09:00:00";
$end = "1997-09-30 09:00:00";
$rule = "RRULE:FREQ=WEEKLY;INTERVAL=2;UNTIL=19970924T000000Z;WKST=SU;BYDAY=MO,WE,FR";
// should be (1997 9:00 AM EDT)September 2,3,5,15,17,19
$dates = date_repeat_calc($rule, $start, $end, array());
$shouldbe = '1997-09-02 09:00:00, 1997-09-03 09:00:00, 1997-09-05 09:00:00, 1997-09-15 09:00:00, 1997-09-17 09:00:00, 1997-09-19 09:00:00';
$result = implode(', ', $dates);
$this->assertEqual($result, $shouldbe, $rule .'; Starting '. $start .'; results: '. $result);
//Monthly on the 1st Friday for 2 occurrences:
$start = "1997-09-05 09:00:00";
$end = "1997-10-31 09:00:00";
$rule = "RRULE:FREQ=MONTHLY;COUNT=2;BYDAY=1FR";
// should be (1997 9:00 AM EDT)September 5;October 3
$dates = date_repeat_calc($rule, $start, $end, array());
$shouldbe = '1997-09-05 09:00:00, 1997-10-03 09:00:00';
$result = implode(', ', $dates);
$this->assertEqual($result, $shouldbe, $rule .'; Starting '. $start .'; results: '. $result);
//Monthly on the 1st Friday until December 24, 1997:
$start = "1997-09-05 09:00:00";
$end = "1998-10-01 09:00:00";
$rule = "RRULE:FREQ=MONTHLY;UNTIL=19971224T000000Z;BYDAY=1FR";
$dates = date_repeat_calc($rule, $start, $end, array());
$shouldbe = '1997-09-05 09:00:00, 1997-10-03 09:00:00, 1997-11-07 09:00:00, 1997-12-05 09:00:00';
$result = implode(', ', $dates);
$this->assertEqual($result, $shouldbe, $rule .'; Starting '. $start .'; results: '. $result);
//Every other month on the 1st and last Sunday of the month for 10 occurrences:
$start = "1997-09-07 09:00:00";
$end = "1998-10-01 09:00:00";
$rule = "RRULE:FREQ=MONTHLY;INTERVAL=2;COUNT=10;BYDAY=1SU,-1SU";
// ==> (1997 9:00 AM EDT)September 7,28
// (1997 9:00 AM EST)November 2,30
// (1998 9:00 AM EST)January 4,25;March 1,29
// (1998 9:00 AM EDT)May 3,31
$dates = date_repeat_calc($rule, $start, $end, array());
$shouldbe = '1997-09-07 09:00:00, 1997-09-28 09:00:00, 1997-11-02 09:00:00, 1997-11-30 09:00:00, 1998-01-04 09:00:00, 1998-01-25 09:00:00, 1998-03-01 09:00:00, 1998-03-29 09:00:00, 1998-05-03 09:00:00, 1998-05-31 09:00:00';
$result = implode(', ', $dates);
$this->assertEqual($result, $shouldbe, $rule .'; Starting '. $start .'; results: '. $result);
//Monthly on the second to last Monday of the month for 6 months:
$start = "1997-09-22 09:00:00";
$end = "1998-10-01 09:00:00";
$rule = "RRULE:FREQ=MONTHLY;COUNT=6;BYDAY=-2MO";
//==> (1997 9:00 AM EDT)September 22;October 20
// (1997 9:00 AM EST)November 17;December 22
// (1998 9:00 AM EST)January 19;February 16
$dates = date_repeat_calc($rule, $start, $end, array());
$shouldbe = '1997-09-22 09:00:00, 1997-10-20 09:00:00, 1997-11-17 09:00:00, 1997-12-22 09:00:00, 1998-01-19 09:00:00, 1998-02-16 09:00:00';
$result = implode(', ', $dates);
$this->assertEqual($result, $shouldbe, $rule .'; Starting '. $start .'; results: '. $result);
//Every Tuesday, every other month:
$start = "1997-09-02 09:00:00";
$end = "1998-02-01 09:00:00";
$rule = "RRULE:FREQ=MONTHLY;INTERVAL=2;BYDAY=TU";
// ==> (1997 9:00 AM EDT)September 2,9,16,23,30
// (1997 9:00 AM EST)November 4,11,18,25
// (1998 9:00 AM EST)January 6,13,20,27;March 3,10,17,24,31
$dates = date_repeat_calc($rule, $start, $end, array());
$shouldbe = '1997-09-02 09:00:00, 1997-09-09 09:00:00, 1997-09-16 09:00:00, 1997-09-23 09:00:00, 1997-09-30 09:00:00, 1997-11-04 09:00:00, 1997-11-11 09:00:00, 1997-11-18 09:00:00, 1997-11-25 09:00:00, 1998-01-06 09:00:00, 1998-01-13 09:00:00, 1998-01-20 09:00:00, 1998-01-27 09:00:00';
$result = implode(', ', $dates);
$this->assertEqual($result, $shouldbe, $rule .'; Starting '. $start .'; results: '. $result);
//Yearly in June and July for 10 occurrences:
$start = "1997-06-10 09:00:00";
$end = "2002-01-01 09:00:00";
$rule = "RRULE:FREQ=YEARLY;COUNT=10;BYMONTH=6,7";
// ==> (1997 9:00 AM EDT)June 10;July 10
// (1998 9:00 AM EDT)June 10;July 10
// (1999 9:00 AM EDT)June 10;July 10
// (2000 9:00 AM EDT)June 10;July 10
// (2001 9:00 AM EDT)June 10;July 10
// Note: Since none of the BYDAY, BYMONTHDAY or BYYEARDAY components
// are specified, the day is gotten from DTSTART
$dates = date_repeat_calc($rule, $start, $end, array());
$shouldbe = '1997-06-10 09:00:00, 1997-07-10 09:00:00, 1998-06-10 09:00:00, 1998-07-10 09:00:00, 1999-06-10 09:00:00, 1999-07-10 09:00:00, 2000-06-10 09:00:00, 2000-07-10 09:00:00, 2001-06-10 09:00:00, 2001-07-10 09:00:00';
$result = implode(', ', $dates);
$this->assertEqual($result, $shouldbe, $rule .'; Starting '. $start .'; results: '. $result);
//Every other year on January, February, and March for 10 occurrences:
$start = "1997-03-10 09:00:00";
$end = "2004-01-01 09:00:00";
$rule = "RRULE:FREQ=YEARLY;INTERVAL=2;COUNT=10;BYMONTH=1,2,3";
// ==> (1997 9:00 AM EST)March 10
// (1999 9:00 AM EST)January 10;February 10;March 10
// (2001 9:00 AM EST)January 10;February 10;March 10
// (2003 9:00 AM EST)January 10;February 10;March 10
$dates = date_repeat_calc($rule, $start, $end, array());
$shouldbe = '1997-03-10 09:00:00, 1999-01-10 09:00:00, 1999-02-10 09:00:00, 1999-03-10 09:00:00, 2001-01-10 09:00:00, 2001-02-10 09:00:00, 2001-03-10 09:00:00, 2003-01-10 09:00:00, 2003-02-10 09:00:00, 2003-03-10 09:00:00';
$result = implode(', ', $dates);
$this->assertEqual($result, $shouldbe, $rule .'; Starting '. $start .'; results: '. $result);
//An example where the days generated makes a difference because of WKST:
$start = "1997-08-05 09:00:00";
$end = "2004-01-01 09:00:00";
$rule = "RRULE:FREQ=WEEKLY;INTERVAL=2;COUNT=4;BYDAY=TU,SU;WKST=MO";
// ==> (1997 EDT)Aug 5,10,19,24
$dates = date_repeat_calc($rule, $start, $end, array());
$shouldbe = '1997-08-05 09:00:00, 1997-08-10 09:00:00, 1997-08-19 09:00:00, 1997-08-24 09:00:00';
$result = implode(', ', $dates);
$this->assertEqual($result, $shouldbe, $rule .'; Starting '. $start .'; results: '. $result);
//changing only WKST from MO to SU, yields different results...
$start = "1997-08-05 09:00:00";
$end = "2004-01-01 09:00:00";
$rule = "RRULE:FREQ=WEEKLY;INTERVAL=2;COUNT=4;BYDAY=TU,SU;WKST=SU";
// Result: 1997 EDT August 5,17,19,31;
$dates = date_repeat_calc($rule, $start, $end, array());
$shouldbe = '1997-08-05 09:00:00, 1997-08-17 09:00:00, 1997-08-19 09:00:00, 1997-08-31 09:00:00';
$result = implode(', ', $dates);
$this->assertEqual($result, $shouldbe, $rule .'; Starting '. $start .'; results: '. $result);
//Every 18 months on the 10th thru 15th of the month for 10 occurrences:
$start = "1997-09-10 09:00:00";
$end = "2004-01-01 09:00:00";
$rule = "RRULE:FREQ=MONTHLY;INTERVAL=18;COUNT=10;BYMONTHDAY=10,11,12,13,14,15";
// ==> (1997 9:00 AM EDT)September 10,11,12,13,14,15
// (1999 9:00 AM EST)March 10,11,12,13
$dates = date_repeat_calc($rule, $start, $end, array());
$shouldbe = '1997-09-10 09:00:00, 1997-09-11 09:00:00, 1997-09-12 09:00:00, 1997-09-13 09:00:00, 1997-09-14 09:00:00, 1997-09-15 09:00:00, 1999-03-10 09:00:00, 1999-03-11 09:00:00, 1999-03-12 09:00:00, 1999-03-13 09:00:00';
$result = implode(', ', $dates);
$this->assertEqual($result, $shouldbe, $rule .'; Starting '. $start .'; results: '. $result);
//Monthly on the third to the last day of the month, forever:
$start = "1997-09-28 09:00:00";
$end = "1998-03-01 09:00:00";
$rule = "RRULE:FREQ=MONTHLY;BYMONTHDAY=-3";
// ==> (1997 9:00 AM EDT)September 28
// (1997 9:00 AM EST)October 29;November 28;December 29
// (1998 9:00 AM EST)January 29;February 26
$dates = date_repeat_calc($rule, $start, $end, array());
$shouldbe = '1997-09-28 09:00:00, 1997-10-29 09:00:00, 1997-11-28 09:00:00, 1997-12-29 09:00:00, 1998-01-29 09:00:00, 1998-02-26 09:00:00';
$result = implode(', ', $dates);
$this->assertEqual($result, $shouldbe, $rule .'; Starting '. $start .'; results: '. $result);
//Every Thursday in March, forever:
// ==> (1997 9:00 AM EST)March 13,20,27
// (1998 9:00 AM EST)March 5,12,19,26
// (1999 9:00 AM EST)March 4,11,18,25
$start = "1997-03-13 09:00:00";
$end = "1999-03-31 09:00:00";
$rule = "RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=TH";
$dates = date_repeat_calc($rule, $start, $end, array());
$shouldbe = '1997-03-13 09:00:00, 1997-03-20 09:00:00, 1997-03-27 09:00:00, 1998-03-05 09:00:00, 1998-03-12 09:00:00, 1998-03-19 09:00:00, 1998-03-26 09:00:00, 1999-03-04 09:00:00, 1999-03-11 09:00:00, 1999-03-18 09:00:00, 1999-03-25 09:00:00';
$result = implode(', ', $dates);
$this->assertEqual($result, $shouldbe, $rule .'; Starting '. $start .'; results: '. $result);
//Every Thursday, but only during June, July, and August, forever:
// ==> (1997 9:00 AM EDT)June 5,12,19,26;July 3,10,17,24,31;August 7,14,21,28
// (1998 9:00 AM EDT)June 4,11,18,25;July 2,9,16,23,30;August 6,13,20,27
// (1999 9:00 AM EDT)June 3,10,17,24;July 1,8,15,22,29;August 5,12,19,26
$start = "1997-06-05 09:00:00";
$end = "1999-08-31 09:00:00";
$rule = "RRULE:FREQ=YEARLY;BYDAY=TH;BYMONTH=6,7,8";
$dates = date_repeat_calc($rule, $start, $end, array());
$shouldbe = '1997-06-05 09:00:00, 1997-06-12 09:00:00, 1997-06-19 09:00:00, 1997-06-26 09:00:00, 1997-07-03 09:00:00, 1997-07-10 09:00:00, 1997-07-17 09:00:00, 1997-07-24 09:00:00, 1997-07-31 09:00:00, 1997-08-07 09:00:00, 1997-08-14 09:00:00, 1997-08-21 09:00:00, 1997-08-28 09:00:00, 1998-06-04 09:00:00, 1998-06-11 09:00:00, 1998-06-18 09:00:00, 1998-06-25 09:00:00, 1998-07-02 09:00:00, 1998-07-09 09:00:00, 1998-07-16 09:00:00, 1998-07-23 09:00:00, 1998-07-30 09:00:00, 1998-08-06 09:00:00, 1998-08-13 09:00:00, 1998-08-20 09:00:00, 1998-08-27 09:00:00, 1999-06-03 09:00:00, 1999-06-10 09:00:00, 1999-06-17 09:00:00, 1999-06-24 09:00:00, 1999-07-01 09:00:00, 1999-07-08 09:00:00, 1999-07-15 09:00:00, 1999-07-22 09:00:00, 1999-07-29 09:00:00, 1999-08-05 09:00:00, 1999-08-12 09:00:00, 1999-08-19 09:00:00, 1999-08-26 09:00:00';
$result = implode(', ', $dates);
$this->assertEqual($result, $shouldbe, $rule .'; Starting '. $start .'; results: '. $result);
//Monthly on the 2nd and 15th of the month for 10 occurrences:
// ==> (1997 9:00 AM EDT)September 2,15;October 2,15
// (1997 9:00 AM EST)November 2,15;December 2,15
// (1998 9:00 AM EST)January 2,15
$start = "1997-09-02 09:00:00";
$end = "1998-01-31 09:00:00";
$rule = "RRULE:FREQ=MONTHLY;COUNT=10;BYMONTHDAY=2,15";
$dates = date_repeat_calc($rule, $start, $end, array());
$shouldbe = '1997-09-02 09:00:00, 1997-09-15 09:00:00, 1997-10-02 09:00:00, 1997-10-15 09:00:00, 1997-11-02 09:00:00, 1997-11-15 09:00:00, 1997-12-02 09:00:00, 1997-12-15 09:00:00, 1998-01-02 09:00:00, 1998-01-15 09:00:00';
$result = implode(', ', $dates);
$this->assertEqual($result, $shouldbe, $rule .'; Starting '. $start .'; results: '. $result);
//Monthly on the first and last day of the month for 10 occurrences:
// ==> (1997 9:00 AM EDT)September 30;October 1
// (1997 9:00 AM EST)October 31;November 1,30;December 1,31
// (1998 9:00 AM EST)January 1,31;February 1
$start = "1997-09-30 09:00:00";
$end = "1998-03-31 09:00:00";
$rule = "RRULE:FREQ=MONTHLY;COUNT=10;BYMONTHDAY=1,-1";
$dates = date_repeat_calc($rule, $start, $end, array());
$shouldbe = '1997-09-30 09:00:00, 1997-10-01 09:00:00, 1997-10-31 09:00:00, 1997-11-01 09:00:00, 1997-11-30 09:00:00, 1997-12-01 09:00:00, 1997-12-31 09:00:00, 1998-01-01 09:00:00, 1998-01-31 09:00:00, 1998-02-01 09:00:00';
$result = implode(', ', $dates);
$this->assertEqual($result, $shouldbe, $rule .'; Starting '. $start .'; results: '. $result);
//Every Friday the 13th, forever:
$rule = "EXDATE;TZID=US-Eastern:19970902T090000";
// ==> (1998 9:00 AM EST)February 13;March 13;November 13
// (1999 9:00 AM EDT)August 13
// (2000 9:00 AM EDT)October 13
$start = "1997-09-02 09:00:00";
$end = "2000-12-31 09:00:00";
$rule = "RRULE:FREQ=MONTHLY;BYDAY=FR;BYMONTHDAY=13";
$dates = date_repeat_calc($rule, $start, $end, array());
$shouldbe = '1997-09-02 09:00:00, 1998-02-13 09:00:00, 1998-03-13 09:00:00, 1998-11-13 09:00:00, 1999-08-13 09:00:00, 2000-10-13 09:00:00';
$result = implode(', ', $dates);
$this->assertEqual($result, $shouldbe, $rule .'; Starting '. $start .'; results: '. $result);
//The first Saturday that follows the first Sunday of the month, forever:
// ==> (1997 9:00 AM EDT)September 13;October 11
// (1997 9:00 AM EST)November 8;December 13
// (1998 9:00 AM EST)January 10;February 7;March 7
// (1998 9:00 AM EDT)April 11;May 9;June 13...
$start = "1997-09-13 09:00:00";
$end = "1998-06-30 09:00:00";
$rule = "RRULE:FREQ=MONTHLY;BYDAY=SA;BYMONTHDAY=7,8,9,10,11,12,13";
$dates = date_repeat_calc($rule, $start, $end, array());
$shouldbe = '1997-09-13 09:00:00, 1997-10-11 09:00:00, 1997-11-08 09:00:00, 1997-12-13 09:00:00, 1998-01-10 09:00:00, 1998-02-07 09:00:00, 1998-03-07 09:00:00, 1998-04-11 09:00:00, 1998-05-09 09:00:00, 1998-06-13 09:00:00';
$result = implode(', ', $dates);
$this->assertEqual($result, $shouldbe, $rule .'; Starting '. $start .'; results: '. $result);
//Every four years, the first Tuesday after a Monday in November,
//forever (U.S. Presidential Election day):
// ==> (1996 9:00 AM EST)November 5
// (2000 9:00 AM EST)November 7
// (2004 9:00 AM EST)November 2
$start = "1996-11-05 09:00:00";
$end = "2004-11-30 09:00:00";
$rule = "RRULE:FREQ=YEARLY;INTERVAL=4;BYMONTH=11;BYDAY=TU;BYMONTHDAY=2,3,4,5,6,7,8";
$shouldbe = '1996-11-05 09:00:00, 2000-11-07 09:00:00, 2004-11-02 09:00:00';
$dates = date_repeat_calc($rule, $start, $end, array());
$result = implode(', ', $dates);
$this->assertEqual($result, $shouldbe, $rule .'; Starting '. $start .'; results: '. $result);
//Every 20th Monday of the year, forever:
$start = "1997-05-19 09:00:00";
$end = "2000-01-01 09:00:00";
$rule = "RRULE:FREQ=YEARLY;BYDAY=20MO";
// ==> (1997 9:00 AM EDT)May 19
// (1998 9:00 AM EDT)May 18
// (1999 9:00 AM EDT)May 17
$dates = date_repeat_calc($rule, $start, $end, array());
$shouldbe = '1997-05-19 09:00:00, 1998-05-18 09:00:00, 1999-05-17 09:00:00';
$result = implode(', ', $dates);
$this->assertEqual($result, $shouldbe, $rule .'; Starting '. $start .'; results: '. $result);
//Every Sunday in January, every other year, forever:
$start = "1997-01-05 09:00:00";
$end = "2001-02-01 09:00:00";
$rule = 'RRULE:FREQ=YEARLY;INTERVAL=2;BYMONTH=1;BYDAY=SU';
// ==> (1997 9:00 AM EDT)January 5,12,19,26
// (1999 9:00 AM EDT)January 3,10,17,24,31
// (2001 9:00 AM EDT)January 7,14,21,28
$dates = date_repeat_calc($rule, $start, $end, array());
$shouldbe = '1997-01-05 09:00:00, 1997-01-12 09:00:00, 1997-01-19 09:00:00, 1997-01-26 09:00:00, 1999-01-03 09:00:00, 1999-01-10 09:00:00, 1999-01-17 09:00:00, 1999-01-24 09:00:00, 1999-01-31 09:00:00, 2001-01-07 09:00:00, 2001-01-14 09:00:00, 2001-01-21 09:00:00, 2001-01-28 09:00:00';
$result = implode(', ', $dates);
$this->assertEqual($result, $shouldbe, $rule .'; Starting '. $start .'; results: '. $result);
return;
//Every Thanksgiving, forever:
$start = "1997-01-01 09:00:00";
$end = "2001-02-01 09:00:00";
$rule = 'RRULE:FREQ=YEARLY;INTERVAL=1;BYMONTH=11;BYDAY=4TH';
// ==> (1997 9:00 AM EDT)Nov
// (1999 9:00 AM EDT)Nov
// (2001 9:00 AM EDT)Nov
$dates = date_repeat_calc($rule, $start, $end, array());
$shouldbe = '';
$result = implode(', ', $dates);
$this->assertEqual($result, $shouldbe, $rule .'; Starting '. $start .'; results: '. $result);
// TODO:
// BYYEARDAY, BYSETPOS,
// BYHOUR, BYMINUTE, HOURLY, MINUTELY, SECONDLY
// have not yet been implemented in date_repeat.
//Every 3rd year on the 1st, 100th and 200th day for 10 occurrences:
$date = "DTSTART;TZID=US-Eastern:19970101T090000";
$rule = "RRULE:FREQ=YEARLY;INTERVAL=3;COUNT=10;BYYEARDAY=1,100,200";
// ==> (1997 9:00 AM EST)January 1
// (1997 9:00 AM EDT)April 10;July 19
// (2000 9:00 AM EST)January 1
// (2000 9:00 AM EDT)April 9;July 18
// (2003 9:00 AM EST)January 1
// (2003 9:00 AM EDT)April 10;July 19
// (2006 9:00 AM EST)January 1
//Monday of week number 20 (where the default start of the week is Monday), forever:
$date = "DTSTART;TZID=US-Eastern:19970512T090000";
$rule = "RRULE:FREQ=YEARLY;BYWEEKNO=20;BYDAY=MO";
// ==> (1997 9:00 AM EDT)May 12
// (1998 9:00 AM EDT)May 11
// (1999 9:00 AM EDT)May 17
//The 3rd instance into the month of one of Tuesday, Wednesday or
//Thursday, for the next 3 months:
$date = "DTSTART;TZID=US-Eastern:19970904T090000";
$rule = "RRULE:FREQ=MONTHLY;COUNT=3;BYDAY=TU,WE,TH;BYSETPOS=3";
// ==> (1997 9:00 AM EDT)September 4;October 7
// (1997 9:00 AM EST)November 6
//The 2nd to last weekday of the month:
$date = "DTSTART;TZID=US-Eastern:19970929T090000";
$rule = "RRULE:FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-2";
// ==> (1997 9:00 AM EDT)September 29
// (1997 9:00 AM EST)October 30;November 27;December 30
// (1998 9:00 AM EST)January 29;February 26;March 30
//Every 3 hours from 9:00 AM to 5:00 PM on a specific day:
$date = "DTSTART;TZID=US-Eastern:19970902T090000";
$rule = "RRULE:FREQ=HOURLY;INTERVAL=3;UNTIL=19970902T170000Z";
// ==> (September 2, 1997 EDT)09:00,12:00,15:00
//Every 15 minutes for 6 occurrences:
$date = "DTSTART;TZID=US-Eastern:19970902T090000";
$rule = "RRULE:FREQ=MINUTELY;INTERVAL=15;COUNT=6";
// ==> (September 2, 1997 EDT)09:00,09:15,09:30,09:45,10:00,10:15
//Every hour and a half for 4 occurrences:
$date = "DTSTART;TZID=US-Eastern:19970902T090000";
$rule = "RRULE:FREQ=MINUTELY;INTERVAL=90;COUNT=4";
// ==> (September 2, 1997 EDT)09:00,10:30;12:00;13:30
//Every 20 minutes from 9:00 AM to 4:40 PM every day:
$date = "DTSTART;TZID=US-Eastern:19970902T090000";
$rule = "RRULE:FREQ=DAILY;BYHOUR=9,10,11,12,13,14,15,16;BYMINUTE=0,20,40";
// or
$rule = "RRULE:FREQ=MINUTELY;INTERVAL=20;BYHOUR=9,10,11,12,13,14,15,16";
// ==> (September 2, 1997 EDT)9:00,9:20,9:40,10:00,10:20,16:00,16:20,16:40
// (September 3, 1997 EDT)9:00,9:20,9:40,10:00,10:20,16:00,16:20,16:40
}
}

View file

@ -1,125 +0,0 @@
BEGIN:VCALENDAR
PRODID:-//Test
VERSION:2.0
X-WR-CALDESC:Test various iCal RRULEs.
BEGIN:VEVENT
UID:iCalRRuleTest1
SUMMARY:Daily for 10 occurrences
DTSTART;TZID=US-Eastern:20090702T090000
RRULE:FREQ=DAILY;COUNT=10
END:VEVENT
BEGIN:VEVENT
UID:iCalRRuleTest2
SUMMARY:Daily until December 24, 2009
DTSTART;TZID=US-Eastern:20091202T090000
RRULE:FREQ=DAILY;UNTIL=20091224T000000Z
END:VEVENT
BEGIN:VEVENT
UID:iCalRRuleTest3
SUMMARY:Every other day
DTSTART;TZID=US-Eastern:20090202T090000
RRULE:FREQ=DAILY;INTERVAL=2
END:VEVENT
BEGIN:VEVENT
UID:iCalRRuleTest4
SUMMARY:Every 10 days, 5 occurrences
DTSTART;TZID=US-Eastern:20090302T090000
RRULE:FREQ=DAILY;INTERVAL=10;COUNT=5
END:VEVENT
BEGIN:VEVENT
UID:iCalRRuleTest5
SUMMARY:Everyday in January, for 2 years
DTSTART;TZID=US-Eastern:20090101T090000
RRULE:FREQ=YEARLY;UNTIL=20110131T090000Z;BYMONTH=1;BYDAY=SU,MO,TU,WE,TH,FR,SA
END:VEVENT
BEGIN:VEVENT
UID:iCalRRuleTest6
SUMMARY:Weekly for 10 occurrences
DTSTART;TZID=US-Eastern:20090102T090000
RRULE:FREQ=WEEKLY;COUNT=10
END:VEVENT
BEGIN:VEVENT
UID:iCalRRuleTest7
SUMMARY:Weekly on Tuesday and Thursday for 5 weeks
DTSTART;TZID=US-Eastern:20090902T090000
RRULE:FREQ=WEEKLY;UNTIL=20091007T000000Z;WKST=SU;BYDAY=TU,TH
END:VEVENT
BEGIN:VEVENT
UID:iCalRRuleTest8
SUMMARY:Every other week on Monday, Wednesday and Friday until December 24, 2009:
DTSTART;TZID=US-Eastern:20090502T090000
RRULE:FREQ=WEEKLY;INTERVAL=2;UNTIL=20091224T000000Z;WKST=SU;BYDAY=MO,WE,FR
END:VEVENT
BEGIN:VEVENT
UID:iCalRRuleTest9
SUMMARY:Every other week on Tuesday and Thursday, for 8 occurrences
DTSTART;TZID=US-Eastern:20090702T090000
RRULE:FREQ=WEEKLY;INTERVAL=2;COUNT=8;WKST=SU;BYDAY=TU,TH
END:VEVENT
BEGIN:VEVENT
UID:iCalRRuleTest10
SUMMARY:Monthly on the 1st Friday for ten occurrences
DTSTART;TZID=US-Eastern:20090905T090000
RRULE:FREQ=MONTHLY;COUNT=10;BYDAY=1FR
END:VEVENT
BEGIN:VEVENT
UID:iCalRRuleTest11
SUMMARY:Monthly on the 1st Friday until December 24, 2009
DTSTART;TZID=US-Eastern:20090905T090000
RRULE:FREQ=MONTHLY;UNTIL=20091224T000000Z;BYDAY=1FR
END:VEVENT
BEGIN:VEVENT
UID:iCalRRuleTest12
SUMMARY:Every other month on the 1st and last Sunday of the month for 10 occurrences
DTSTART;TZID=US-Eastern:20090907T090000
RRULE:FREQ=MONTHLY;INTERVAL=2;COUNT=10;BYDAY=1SU,-1SU
END:VEVENT
BEGIN:VEVENT
UID:iCalRRuleTest13
SUMMARY:Monthly on the second to last Monday of the month for 6 months
DTSTART;TZID=US-Eastern:20090119T090000
RRULE:FREQ=MONTHLY;COUNT=6;BYDAY=-2MO
END:VEVENT
BEGIN:VEVENT
UID:iCalRRuleTest14
SUMMARY:Monthly on the third to the last day of the month
DTSTART;TZID=US-Eastern:20090928T090000
RRULE:FREQ=MONTHLY;BYMONTHDAY=-3
END:VEVENT
BEGIN:VEVENT
UID:iCalRRuleTest15
SUMMARY:Monthly on the 2nd and 15th of the month for 10 occurrences
DTSTART;TZID=US-Eastern:20090202T090000
RRULE:FREQ=MONTHLY;COUNT=10;BYMONTHDAY=2,15
END:VEVENT
BEGIN:VEVENT
UID:iCalRRuleTest16
SUMMARY:Monthly on the first and last day of the month for 10 occurrences
DTSTART;TZID=US-Eastern:20090130T090000
RRULE:FREQ=MONTHLY;COUNT=10;BYMONTHDAY=1,-1
END:VEVENT
BEGIN:VEVENT
UID:iCalRRuleTest17
SUMMARY:Every 3 months on the 10th thru 15th of the month for 10 occurrences
DTSTART;TZID=US-Eastern:20090410T090000
RRULE:FREQ=MONTHLY;INTERVAL=3;COUNT=10;BYMONTHDAY=10,11,12,13,14,15
END:VEVENT
BEGIN:VEVENT
UID:iCalRRuleTest18
SUMMARY:Every Tuesday, every other month
DTSTART;TZID=US-Eastern:20090602T090000
RRULE:FREQ=MONTHLY;INTERVAL=2;BYDAY=TU
END:VEVENT
BEGIN:VEVENT
UID:iCalRRuleTest19
SUMMARY:Yearly in June and July for 10 occurrences
DTSTART;TZID=US-Eastern:20090610T090000
RRULE:FREQ=YEARLY;COUNT=10;BYMONTH=6,7
END:VEVENT
BEGIN:VEVENT
UID:iCalRRuleTest20
SUMMARY:Every Thursday in March
DTSTART;TZID=US-Eastern:20090305T090000
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=TH
END:VEVENT
END:VCALENDAR