<?php
// example to show the magic date 1937-07-01 change in the NL
// the Zend\Validate\DateStep does not account for this difference
class Blar_DateTime extends DateTime {
/**
* Return Date in ISO8601 format
*
* @return String
*/
public function __toString() {
return $this->format('Y-m-d H:i:s');
}
/**
* Return difference between $this and $now
*
* @param Datetime|String $now
* @return DateInterval
*/
public function diff($now = 'NOW', $absolute = NULL) {
if(!($now instanceOf DateTime)) {
$now = new DateTime($now);
}
return parent::diff($now);
}
/**
* Return Age in Years
*
* @param Datetime|String $now
* @return Integer
*/
public function getAge($now = 'NOW') {
return $this->diff($now)->format('%y');
}
}
$birthday = new Blar_DateTime('1879-03-14', new DateTimeZone("Europe/Amsterdam"));
echo $birthday;
echo '<p>In the Netherlands Albert Einstein would now be ', $birthday->diff(new DateTime('NOW', new DateTimeZone("Europe/Amsterdam")))->format('%y Years, %m Months, %d Days, %h Hours, %i Minutes, %s Seconds'), ' old.</p>';
$birthday = new Blar_DateTime('1879-03-14', new DateTimeZone("Europe/London"));
echo $birthday;
echo '<p>In the United Kingdom Albert Einstein would now be ', $birthday->diff(new DateTime('NOW', new DateTimeZone("Europe/London")))->format('%y Years, %m Months, %d Days, %h Hours, %i Minutes, %s Seconds'), ' old.</p>';
$birthday = new Blar_DateTime('1950-03-14', new DateTimeZone("Europe/Amsterdam"));
echo $birthday;
echo '<p>the Netherlands mr. Anonymous would now be ', $birthday->diff(new DateTime('NOW', new DateTimeZone("Europe/Amsterdam")))->format('%y Years, %m Months, %d Days, %h Hours, %i Minutes, %s Seconds'), ' old.</p>';
$birthday = new Blar_DateTime('1950-03-14', new DateTimeZone("Europe/London"));
echo $birthday;
echo '<p>In the mr. Anonymous would now be ', $birthday->diff(new DateTime('NOW', new DateTimeZone("Europe/London")))->format('%y Years, %m Months, %d Days, %h Hours, %i Minutes, %s Seconds'), ' old.</p>';
// output
/*
1879-03-14 00:00:00
In the Netherlands Albert Einstein would now be 134 Years, 5 Months, 14 Days, 17 Hours, 54 Minutes, 49 Seconds old.
1879-03-14 00:00:00
In the United Kingdom Albert Einstein would now be 134 Years, 5 Months, 14 Days, 16 Hours, 55 Minutes, 17 Seconds old.
1950-03-14 00:00:00
the Netherlands mr. Anonymous would now be 63 Years, 5 Months, 14 Days, 17 Hours, 55 Minutes, 17 Seconds old.
1950-03-14 00:00:00
In the mr. Anonymous would now be 63 Years, 5 Months, 14 Days, 16 Hours, 55 Minutes, 17 Seconds old.
now note the difference in seconds between example 1 and 2 of 28 seconds... exactly the time that does not exists in the netherlands on 1937-07-01
I conclude PHP does it correctly and Zend\Validate\DateStep should account for this.
*/
Deprecated: Return type of Blar_DateTime::diff($now = 'NOW', $absolute = null) should either be compatible with DateTime::diff(DateTimeInterface $targetObject, bool $absolute = false): DateInterval, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/3iO2j on line 24
1879-03-14 00:00:00<p>In the Netherlands Albert Einstein would now be 134 Years, 6 Months, 13 Days, 19 Hours, 13 Minutes, 52 Seconds old.</p>1879-03-14 00:00:00<p>In the United Kingdom Albert Einstein would now be 134 Years, 6 Months, 13 Days, 18 Hours, 13 Minutes, 52 Seconds old.</p>1950-03-14 00:00:00<p>the Netherlands mr. Anonymous would now be 63 Years, 6 Months, 13 Days, 19 Hours, 13 Minutes, 52 Seconds old.</p>1950-03-14 00:00:00<p>In the mr. Anonymous would now be 63 Years, 6 Months, 13 Days, 18 Hours, 13 Minutes, 52 Seconds old.</p>
1879-03-14 00:00:00<p>In the Netherlands Albert Einstein would now be 134 Years, 6 Months, 13 Days, 19 Hours, 13 Minutes, 24 Seconds old.</p>1879-03-14 00:00:00<p>In the United Kingdom Albert Einstein would now be 134 Years, 6 Months, 13 Days, 18 Hours, 13 Minutes, 52 Seconds old.</p>1950-03-14 00:00:00<p>the Netherlands mr. Anonymous would now be 63 Years, 6 Months, 13 Days, 19 Hours, 13 Minutes, 52 Seconds old.</p>1950-03-14 00:00:00<p>In the mr. Anonymous would now be 63 Years, 6 Months, 13 Days, 18 Hours, 13 Minutes, 52 Seconds old.</p>
Output for 5.5.25 - 5.5.38, 5.6.9 - 5.6.14
1879-03-14 00:00:00<p>In the Netherlands Albert Einstein would now be 134 Years, 6 Months, 13 Days, 19 Hours, 13 Minutes, 24 Seconds old.</p>1879-03-14 00:00:00<p>In the United Kingdom Albert Einstein would now be 134 Years, 6 Months, 13 Days, 18 Hours, 13 Minutes, 37 Seconds old.</p>1950-03-14 00:00:00<p>the Netherlands mr. Anonymous would now be 63 Years, 6 Months, 13 Days, 19 Hours, 13 Minutes, 52 Seconds old.</p>1950-03-14 00:00:00<p>In the mr. Anonymous would now be 63 Years, 6 Months, 13 Days, 18 Hours, 13 Minutes, 52 Seconds old.</p>
Output for 5.2.0 - 5.2.17
1879-03-14 00:00:00<p>In the Netherlands Albert Einstein would now be
Fatal error: Call to undefined method DateTime::diff() in /in/3iO2j on line 28
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/3iO2j on line 7
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/3iO2j on line 14
Process exited with code 255.
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/3iO2j on line 14
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/3iO2j on line 14
Process exited with code 255.