Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify instead Add inside ArrayTransformer. #193

Open
Gu3 opened this issue Sep 9, 2021 · 0 comments
Open

Modify instead Add inside ArrayTransformer. #193

Gu3 opened this issue Sep 9, 2021 · 0 comments

Comments

@Gu3
Copy link

Gu3 commented Sep 9, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant