<?php
$base = new DateTime("2000-03-04 00:00:00 Europe/Berlin");
$date = new DateTime("2016-09-03 00:00:00 Europe/Berlin");
$interval = new DateInterval('P5Y6M0D');
$ret = $date;
$diff = $base->diff($date);
// var_dump($diff);
$iterations = 0;
$y = $base->format('Y');
$m = $base->format('m');
$d = $base->format('d');
$h = $base->format('G');
$i = $base->format('i');
$s = $base->format('s');
if ($interval->y || $interval->m) {
$monthDiff = $diff->y * 12 + $diff->m;
$monthInterval = $interval->y * 12 + $interval->m;
$iterations = floor($monthDiff / $monthInterval);
$y = $base->format('Y') + ($interval->y * $iterations);
$m = $base->format('m') + ($interval->m * $iterations);
echo "set y:{$y}, m:{$m}, iterations:{$iterations}\n";
}
var_dump($diff, ($interval->d * $iterations));
$modify = $diff->d - ($interval->d * $iterations);
if ($modify > 0) {
$y += $interval->y;
$m += $interval->m;
$iterations++;
}
$d += $interval->d * $iterations;
echo "set y:{$y}, m:{$m}, d:{$d}, iterations:{$iterations}\n";
$modify = $diff->h - ($interval->h * $iterations);
if ($modify > 0) {
$y += $interval->y;
$m += $interval->m;
$d += $interval->d;
$iterations++;
}
$h += $interval->h * $iterations;
echo "set y:{$y}, m:{$m}, d:{$d}, h:{$h}, iterations:{$iterations}\n";
$ret->setDate($y, $m, $d);
$ret->setTime($h, $i, $s);
echo $ret->format("Y-m-d H:i:s") . "\n";
exit;
if ($interval->y) {
$y = $diff->y / $interval->y;
if ($y) {
$intervals = $y / $interval->y;
$m = $interval->m * $intervals;
$y -= floor($m / 12);
$m -= floor($m / 12) * 12;
$ret->setDate(
$base->format('Y') + $y,
$base->format('m') + $m,
$base->format('d')
);
/*
$ret->setTime(
$base->format('G') + ($interval->h * $intervals),
$base->format('i') + ($interval->i * $intervals),
$base->format('s') + ($interval->s * $intervals)
);
*/
}
}
var_dump($ret); exit;
- Output for 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
- set y:2010, m:15, iterations:2
object(DateInterval)#4 (10) {
["y"]=>
int(16)
["m"]=>
int(5)
["d"]=>
int(30)
["h"]=>
int(0)
["i"]=>
int(0)
["s"]=>
int(0)
["f"]=>
float(0)
["invert"]=>
int(0)
["days"]=>
int(6027)
["from_string"]=>
bool(false)
}
float(0)
set y:2015, m:21, d:4, iterations:3
set y:2015, m:21, d:4, h:0, iterations:3
2016-09-04 00:00:00
- Output for 7.1.0 - 7.1.7, 7.1.20 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27
- set y:2010, m:15, iterations:2
object(DateInterval)#4 (16) {
["y"]=>
int(16)
["m"]=>
int(5)
["d"]=>
int(30)
["h"]=>
int(0)
["i"]=>
int(0)
["s"]=>
int(0)
["f"]=>
float(0)
["weekday"]=>
int(0)
["weekday_behavior"]=>
int(0)
["first_last_day_of"]=>
int(0)
["invert"]=>
int(0)
["days"]=>
int(6027)
["special_type"]=>
int(0)
["special_amount"]=>
int(0)
["have_weekday_relative"]=>
int(0)
["have_special_relative"]=>
int(0)
}
float(0)
set y:2015, m:21, d:4, iterations:3
set y:2015, m:21, d:4, h:0, iterations:3
2016-09-04 00:00:00
- Output for 7.1.10
Process exited with code 137.- Output for 5.3.27 - 5.3.29, 5.4.17 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20
- set y:2010, m:15, iterations:2
object(DateInterval)#4 (15) {
["y"]=>
int(16)
["m"]=>
int(5)
["d"]=>
int(30)
["h"]=>
int(0)
["i"]=>
int(0)
["s"]=>
int(0)
["weekday"]=>
int(0)
["weekday_behavior"]=>
int(0)
["first_last_day_of"]=>
int(0)
["invert"]=>
int(0)
["days"]=>
int(6027)
["special_type"]=>
int(0)
["special_amount"]=>
int(0)
["have_weekday_relative"]=>
int(0)
["have_special_relative"]=>
int(0)
}
float(0)
set y:2015, m:21, d:4, iterations:3
set y:2015, m:21, d:4, h:0, iterations:3
2016-09-04 00:00:00
- Output for 5.3.0 - 5.3.26, 5.4.0 - 5.4.16
- set y:2010, m:15, iterations:2
object(DateInterval)#4 (8) {
["y"]=>
int(16)
["m"]=>
int(5)
["d"]=>
int(30)
["h"]=>
int(0)
["i"]=>
int(0)
["s"]=>
int(0)
["invert"]=>
int(0)
["days"]=>
int(6027)
}
float(0)
set y:2015, m:21, d:4, iterations:3
set y:2015, m:21, d:4, h:0, iterations:3
2016-09-04 00:00:00
- Output for 5.2.0 - 5.2.17
- Fatal error: Class 'DateInterval' not found in /in/rbDLH on line 5
Process exited with code 255. - Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6
- Fatal error: Class 'DateTime' not found in /in/rbDLH on line 3
Process exited with code 255. - Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.9
- Fatal error: Cannot instantiate non-existent class: datetime in /in/rbDLH on line 3
Process exited with code 255. - Output for 4.3.0 - 4.3.1
- Fatal error: Cannot instantiate non-existent class: datetime in /in/rbDLH on line 3
preferences:
233.89 ms | 401 KiB | 323 Q