diff --git a/core/modules/views/src/Plugin/views/query/Sql.php b/core/modules/views/src/Plugin/views/query/Sql.php index 5b0ec1b..7f51afa 100644 --- a/core/modules/views/src/Plugin/views/query/Sql.php +++ b/core/modules/views/src/Plugin/views/query/Sql.php @@ -1799,6 +1799,7 @@ public function getDateFormat($field, $format) { $format = strtr($format, $replace); // SQLite does not have a ISO week substitution string, so it needs // special handling. + // @see http://en.wikipedia.org/wiki/ISO_week_date#Calculation // @see http://stackoverflow.com/a/15511864/1499564 if ($format === '%W') { $expression = "((strftime('%j', date(strftime('%Y-%m-%d', $field, 'unixepoch'), '-3 days', 'weekday 4')) - 1) / 7 + 1)"; diff --git a/core/modules/views/src/Tests/Handler/ArgumentDateTest.php b/core/modules/views/src/Tests/Handler/ArgumentDateTest.php index 4c66e79..c6e2957 100644 --- a/core/modules/views/src/Tests/Handler/ArgumentDateTest.php +++ b/core/modules/views/src/Tests/Handler/ArgumentDateTest.php @@ -148,6 +148,16 @@ public function testMonthHandler() { */ public function testWeekHandler() { $this->container->get('database')->update('views_test_data') + ->fields(array('created' => gmmktime(0, 0, 0, 9, 26, 2008))) + ->condition('id', 1) + ->execute(); + + $this->container->get('database')->update('views_test_data') + ->fields(array('created' => gmmktime(0, 0, 0, 2, 29, 2004))) + ->condition('id', 2) + ->execute(); + + $this->container->get('database')->update('views_test_data') ->fields(array('created' => gmmktime(0, 0, 0, 1, 1, 2000))) ->condition('id', 3) ->execute(); @@ -164,11 +174,27 @@ public function testWeekHandler() { $view = Views::getView('test_argument_date'); $view->setDisplay('embed_3'); - // The first jan 2000 was still in the last week of the previous year. - $this->executeView($view, array(52)); + // Check the week calculation for a leap year. + // @see http://en.wikipedia.org/wiki/ISO_week_date#Calculation + $this->executeView($view, array('39')); $expected = array(); $expected[] = array('id' => 1); + $this->assertIdenticalResultset($view, $expected, $this->columnMap); + $view->destroy(); + + $view->setDisplay('embed_3'); + // Check the week calculation for the 29th of February in a leap year. + // @see http://en.wikipedia.org/wiki/ISO_week_date#Calculation + $this->executeView($view, array('09')); + $expected = array(); $expected[] = array('id' => 2); + $this->assertIdenticalResultset($view, $expected, $this->columnMap); + $view->destroy(); + + $view->setDisplay('embed_3'); + // The first jan 2000 was still in the last week of the previous year. + $this->executeView($view, array('52')); + $expected = array(); $expected[] = array('id' => 3); $this->assertIdenticalResultset($view, $expected, $this->columnMap); $view->destroy();