<?php
//echo date('r', strtotime('last sunday', strtotime('6 April 1991')));
function align_timestamp_to($stamp, $unit, $past){ // timestamp, unit string, start/end
static $modes = array(
'week' => 'last monday'
'month' => 'first day of month'
);
// TODO error out if unknown $unit
$offset = $modes[$unit];
if($past == 'end')$offset = '+1 '.$unit.' '.$offset;
$new = strtotime($offset, $stamp);
}
foreach(array(
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]));
- Output for 5.4.0 - 5.4.9
- Parse error: syntax error, unexpected ''month'' (T_CONSTANT_ENCAPSED_STRING), expecting ')' in /in/aNloj on line 8
Process exited with code 255. - Output for 5.3.0 - 5.3.19
- Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in /in/aNloj on line 8
Process exited with code 255.
preferences:
175.33 ms | 1386 KiB | 37 Q