3v4l.org

run code in 300+ PHP versions simultaneously
<?php function align_timestamp_to($stamp, $unit, $past){ // timestamp, unit string, start/end static $modes = array( 'year' => 'last year', 'week' => 'last monday', 'month' => 'first day of this month', 'hour' => 'last hour', 'minute' => 'last minute', ); // TODO error out if unknown $unit $offset = $modes[$unit]; if($past == 'end')$offset = '+1 '.$unit.' '.$offset.' -1 second'; return strtotime($offset, $stamp); } foreach(array( array(strtotime('4 Apr 2012'), 'year', 'start'), array(strtotime('4 Apr 2012'), 'year', 'end'), array(strtotime('4 Apr 2012'), 'month', 'start'), array(strtotime('4 Apr 2012'), 'month', 'end'), array(strtotime('4 Apr 2012'), 'week', 'start'), array(strtotime('4 Apr 2012'), 'week', 'end'), ) as $test)echo date('r', $test[0]).' aligned '.$test[2].' of '.$test[1].' yields '.date('r', align_timestamp_to($test[0], $test[1], $test[2])).'<br/>';
Output for git.master, git.master_jit, rfc.property-hooks
Wed, 04 Apr 2012 00:00:00 +0200 aligned start of year yields Mon, 04 Apr 2011 00:00:00 +0200<br/>Wed, 04 Apr 2012 00:00:00 +0200 aligned end of year yields Tue, 03 Apr 2012 23:59:59 +0200<br/>Wed, 04 Apr 2012 00:00:00 +0200 aligned start of month yields Sun, 01 Apr 2012 00:00:00 +0200<br/>Wed, 04 Apr 2012 00:00:00 +0200 aligned end of month yields Mon, 30 Apr 2012 23:59:59 +0200<br/>Wed, 04 Apr 2012 00:00:00 +0200 aligned start of week yields Mon, 02 Apr 2012 00:00:00 +0200<br/>Wed, 04 Apr 2012 00:00:00 +0200 aligned end of week yields Sun, 08 Apr 2012 23:59:59 +0200<br/>

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
60.23 ms | 402 KiB | 8 Q