Skip to content

Modify instead Add inside ArrayTransformer.  #193

Description

@Gu3

Hi !
I've got an use case who make an error inside the ArrayTranformer.

Imagine this Rule :

Rule {#11684 
  #timezone: "Europe/Paris"
  #startDate: DateTime {#9670 
    +"date": "2021-07-01 00:00:00.000000"
    +"timezone_type": 3
    +"timezone": "Europe/Paris"
  }
  #endDate: DateTime {#9666 
    +"date": "2021-09-06 00:00:00.000000"
    +"timezone_type": 3
    +"timezone": "Europe/Paris"
  }
  #isStartDateFromDtstart: false
  #freq: 3
  #interval: 1
  #isExplicitInterval: false
  #until: null
  #count: 1
  #bySecond: null
  #byMinute: null
  #byHour: null
  #byDay: null
  #byMonthDay: null
  #byYearDay: null
  #byWeekNumber: null
  #byMonth: null
  #weekStart: "MO"
  #weekStartDefined: false
  #days: array:7 [▶]
  #bySetPosition: null
  #rDates: []
  #exDates: []
}

The duration interval give us :

$start = $rule->getStartDate();
$end   = $rule->getEndDate();
$durationInterval = $start->diff($end);   //  2 months and 6 days ==> 67 days 

the add method give us :

$end->add($durationInterval); // september 7th instead of september 6th

if we used modify instead of add :

$end->modify(sprintf("+ %s day" . ($durationInterval->days == 1 ? '' : 's'), $durationInterval->days)); // september 6th

For a full explanation : https://aiocollective.com/blog/php-datetime-difference-trap/

Is that correct for you too ?
Cheer !
Vincent.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions