diff --git a/core_search_facets/src/Tests/WebTestBase.php b/core_search_facets/src/Tests/WebTestBase.php index 450acc8..240b381 100644 --- a/core_search_facets/src/Tests/WebTestBase.php +++ b/core_search_facets/src/Tests/WebTestBase.php @@ -60,7 +60,7 @@ abstract class WebTestBase extends SimpletestWebTestBase { // Adding 10 pages. for ($i = 1; $i <= 9; $i++) { - $created_time = new \DateTime('March '.$i.' 2016 ' . $i . 'PM'); + $created_time = new \DateTime('March ' . $i . ' 2016 ' . str_pad($i, 2, STR_PAD_LEFT, 0) . 'PM'); $this->drupalCreateNode(array( 'title' => 'foo bar' . $i, 'body' => 'test page' . $i, @@ -78,7 +78,7 @@ abstract class WebTestBase extends SimpletestWebTestBase { // Adding 10 articles. for ($i = 1; $i <= 10; $i++) { - $created_time = new \DateTime('April '.$i.' 2016 ' . $i . 'AM'); + $created_time = new \DateTime('April ' . $i . ' 2016 ' . str_pad($i, 2, STR_PAD_LEFT, 0) . 'PM'); $this->drupalCreateNode(array( 'title' => 'foo baz' . $i, 'body' => 'test article' . $i, diff --git a/src/Utility/FacetsDateHandler.php b/src/Utility/FacetsDateHandler.php index 04eec98..5e4ea9f 100644 --- a/src/Utility/FacetsDateHandler.php +++ b/src/Utility/FacetsDateHandler.php @@ -1,10 +1,5 @@ = 31536000): $gap = static::FACETS_DATE_YEAR; break; @@ -211,8 +205,8 @@ class FacetsDateHandler { break; } - // Return the calculated gap if a minimum gap was not passed of the calculated - // gap is a larger interval than the minimum gap. + // Return the calculated gap if a minimum gap was not passed of the + // calculated gap is a larger interval than the minimum gap. if (is_null($min_gap) || $this->gapCompare($gap, $min_gap) >= 0) { return $gap; } @@ -222,8 +216,10 @@ class FacetsDateHandler { } /** - * Converts ISO date strings to Unix timestamps, passes values to the - * FACETS_get_timestamp_gap() function to calculate the gap. + * Converts ISO date strings to Unix timestamps. + * + * Passes values to the FACETS_get_timestamp_gap() function to calculate the + * gap. * * @param string $start_date * A string containing the start date as an ISO date string. @@ -297,7 +293,7 @@ class FacetsDateHandler { * @param $callback * The formatting callback, defaults to "FACETS_format_timestamp". * - * @return + * @return string * A gap-appropriate display date used in the facet link. * * @see FACETS_format_timestamp() @@ -308,9 +304,10 @@ class FacetsDateHandler { } /** - * Returns the next increment from the given ISO date and gap. This function is - * useful for getting the upper limit of a date range from the given start - * date. + * Returns the next increment from the given ISO date and gap. + * + * This function is useful for getting the upper limit of a date range from + * the given start date. * * @param string $date * A string containing the date as an ISO date string. @@ -319,7 +316,8 @@ class FacetsDateHandler { * values, defaults to YEAR. * * @return string - * A string containing the date, FALSE if the passed date could not be parsed. + * A string containing the date, FALSE if the passed date could not be + * parsed. */ public function getNextDateIncrement($date, $gap) { if (preg_match(static::FACETS_REGEX_DATE, $date, $match)) { @@ -329,21 +327,27 @@ class FacetsDateHandler { case static::FACETS_DATE_MONTH: $match[2] += 1; break; + case static::FACETS_DATE_DAY: $match[3] += 1; break; + case static::FACETS_DATE_HOUR: $match[4] += 1; break; + case static::FACETS_DATE_MINUTE: $match[5] += 1; break; + case static::FACETS_DATE_SECOND: $match[6] += 1; break; + default: $match[1] += 1; break; + } // Gets the next increment. @@ -361,8 +365,8 @@ class FacetsDateHandler { * @param string $gap2 * * @return int - * Returns -1 if gap1 is less than gap2, 1 if gap1 is greater than gap2, and 0 - * if they are equal. + * Returns -1 if gap1 is less than gap2, 1 if gap1 is greater than gap2, and + * 0 if they are equal. */ public function gapCompare($gap1, $gap2) { @@ -387,7 +391,7 @@ class FacetsDateHandler { } /** - * Extracts "start" and "end" dates from an active items + * Extracts "start" and "end" dates from an active items. * * @param string $item * The active item to extract the dates. @@ -414,5 +418,5 @@ class FacetsDateHandler { } return FALSE; } -} +} diff --git a/tests/src/Unit/Utility/FacetsDateHandlerTest.php b/tests/src/Unit/Utility/FacetsDateHandlerTest.php index 5caf6f0..7a906d4 100644 --- a/tests/src/Unit/Utility/FacetsDateHandlerTest.php +++ b/tests/src/Unit/Utility/FacetsDateHandlerTest.php @@ -1,10 +1,5 @@