Skip to content

Instantly share code, notes, and snippets.

@Taluu
Last active December 12, 2015 03:38
Show Gist options
  • Save Taluu/4708093 to your computer and use it in GitHub Desktop.
Save Taluu/4708093 to your computer and use it in GitHub Desktop.
<?php
// php wtf of the day
use \DateTime,
\DateInterval;
$now = ['ref'=> new DateTime(), 0 => new DateTime(), 1 => new DateTime];
$interval = new DateInterval('PT10S');
// Have to do this to make it work. Just putting it here, so we can analyse the difference
$now[1]->sub($interval)->sub($interval);
$tries = [$now[0]->diff($now[0]->sub($interval)->sub($interval), true), //not working...
$now['ref']->diff($now[1], true)]; // working
var_export($tries);
<?php
array (
0 =>
DateInterval::__set_state(array(
'y' => 0,
'm' => 0,
'd' => 0,
'h' => 0,
'i' => 0,
's' => 0,
'invert' => 0,
'days' => 0,
)),
1 =>
DateInterval::__set_state(array(
'y' => 0,
'm' => 0,
'd' => 0,
'h' => 0,
'i' => 0,
's' => 20,
'invert' => 0,
'days' => 0,
)),
)%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment