When you pass field settings with at least one zero value to the DateObject::limitGranularity(), it doesn't filter out anything, because non-strict comparison returns match for any granularity string and integer zero.

Patch follows.

Issue fork date-1679552

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dmitriy.trt’s picture

Status: Active » Needs review
FileSize
2.03 KB

Fix and a test.

barami’s picture

I have same problem.
It needs to be accept.

Accepet above patch or change code using in_array function to add parameter 'strict' to TRUE.
http://php.net/manual/en/function.in-array.php

default 'strict' parameter is FALSE and it searchs on array keys too.
So, limitGranularity functions always don't remove granularity part.

barami’s picture

barami’s picture

Merge test case with patch in #2.

barami’s picture

Change tab to spaces.

Status: Needs review » Needs work

The last submitted patch, fix_limitGranularity-1679552-5.patch, failed testing.

RoSk0’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
1.01 KB
1.52 KB

Properly formatted version of the #4 patch with test separated.

The last submitted patch, 7: date-1679552-7-test-only.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Chris Matthews’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll, +Needs rework

The year old patch in #7 to date_api.module does not apply to the latest 7.x-2.x-dev and will need a reroll.

Checking patch date_api/date_api.module...
error: while searching for:
   */
  public function limitGranularity($granularity) {
    foreach ($this->granularity as $key => $val) {
      if ($val != 'timezone' && !in_array($val, $granularity)) {
        unset($this->granularity[$key]);
      }
    }

error: patch failed: date_api/date_api.module:538
error: date_api/date_api.module: patch does not apply
spiritcapsule’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll, -
FileSize
1.59 KB

reroll of #7

rohan-sinha’s picture

Status: Needs review » Reviewed & tested by the community

reviewed patch on #10 , DateObject::limitGranularity() issue is resolved.

kunal_sahu made their first commit to this issue’s fork.

kunal_sahu’s picture

Hi @all,

I have tested this patch . The patch LGTM.

$ git apply -v date-1679552-10.patch.patch
Checking patch date_api/date_api.module...
Checking patch date_api/tests/DateApiTestCase.test...
Applied patch date_api/date_api.module cleanly.
Applied patch date_api/tests/DateApiTestCase.test cleanly.

And this does solves the issue.

RTBC++.

Provided an MR for helping the maintainer.

Please merge.

Thanks