You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please let me know if I should rather split the following issues into separate issues, but for convenience's sake I'll keep them in this one.
1. DatePeriod
In PHP you were able to use iterator_to_array on a DatePeriod object, but this is not possible at the moment, because it throws an ArgumentException. From looking at the source code, I suspect its because it extends Traversable and not IteratorAggregate, as it use to in PHP.
My next step was just to try to iterate through the DatePeriod object, but this did not resolve my issue.
Example:
$fromDate = new DateTime("2022-01-01");
$toDate = new DateTime("2022-01-05");
$interval = DateInterval::createFromDateString("+1 Day");
$datePeriod = new DatePeriod($fromDate, $interval, $toDate);
foreach($datePeriod as $day){
echo $day->format("Y-m-d")." ";
}
I saw that it is stated on the Compatibility status page of the project that DatePeriod::getIterator() is not yet supported, which I assume is the root of my issue. Will this be done in the near future or should I rather invest time into alternative solutions?
2. DateTime->modify uses wrong date
When modifying a DateTime object the date is reset to the current time instead of using the initialized value.
Example:
$date = (new DateTime("2022-01-01"))->modify("+1 month");
echo $date->format("Y-m-d");
Expected:
2022-02-01
Result:
2022-06-25
When using the modify function's parameters in the DateTime object's constructor you get the correct result (new DateTime("2022-01-01 +1 month"); \\ 2022-02-01)
3. DateTime->modify using complex strings
This one is not too important.
In PHP you use to be able to use 'complex' strings to modify dates. For example say you wanted the first day of the month you were able to use $date->modify('first day of month');, but it throws Pchp.Library.Spl.Exception: 'Parse error on position 3 near 'st day of this month' currently.
PHP handles negative values in the createFromDateString function correctly, by setting the day, month or year to negative (and not invert for some reason). Currently peachpie does neither.
PHP:
$interval = DateInterval::createFromDateString('-1 day');
echo var_dump($interval);
object(DateInterval)[12]
public 'y' => int 0
public 'm' => int 0
public 'd' => int -1
public 'h' => int 0
public 'i' => int 0
public 's' => int 0
public 'f' => float 0
public 'weekday' => int 0
public 'weekday_behavior' => int 0
public 'first_last_day_of' => int 0
public 'invert' => int 0
public 'days' => boolean false
public 'special_type' => int 0
public 'special_amount' => int 0
public 'have_weekday_relative' => int 0
public 'have_special_relative' => int 0
Please let me know if I should rather split the following issues into separate issues, but for convenience's sake I'll keep them in this one.
1. DatePeriod
In PHP you were able to use
iterator_to_array
on aDatePeriod
object, but this is not possible at the moment, because it throws anArgumentException
. From looking at the source code, I suspect its because it extendsTraversable
and notIteratorAggregate
, as it use to in PHP.My next step was just to try to iterate through the
DatePeriod
object, but this did not resolve my issue.Example:
Expected:
Result
I saw that it is stated on the
Compatibility status
page of the project thatDatePeriod::getIterator()
is not yet supported, which I assume is the root of my issue. Will this be done in the near future or should I rather invest time into alternative solutions?2. DateTime->modify uses wrong date
When modifying a
DateTime
object the date is reset to the current time instead of using the initialized value.Example:
Expected:
Result:
When using the
modify
function's parameters in theDateTime
object's constructor you get the correct result (new DateTime("2022-01-01 +1 month"); \\ 2022-02-01
)3. DateTime->modify using complex strings
This one is not too important.
In PHP you use to be able to use 'complex' strings to modify dates. For example say you wanted the first day of the month you were able to use
$date->modify('first day of month');
, but it throwsPchp.Library.Spl.Exception: 'Parse error on position 3 near 'st day of this month'
currently.4. DateInterval::createFromDateString ignores negative signs
PHP handles negative values in the
createFromDateString
function correctly, by setting the day, month or year to negative (and not invert for some reason). Currently peachpie does neither.PHP:
Peachpie:
The text was updated successfully, but these errors were encountered: