[ create a new paste ] login | about

Link: http://codepad.org/qU4dK7XJ    [ raw code | output | fork ]

PHP, pasted on Aug 13:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
/**
 * @param  $t  UNIX timestamp
 * @return true iff the given time fell in the previous Sunday->Sunday window
 */
function f($t) {
   $a = strtotime("last Sunday");
   $b = strtotime("-1 week", $a);
   
   return ($b <= $t && $t < $a);
}

var_dump(f(strtotime("2011-08-12 11:00")));
var_dump(f(strtotime("2011-08-08 11:00")));
var_dump(f(strtotime("2011-08-04 11:00")));
var_dump(f(strtotime("2011-08-01 11:00")));
?>


Output:
1
2
3
4
bool(false)
bool(false)
bool(true)
bool(true)


Create a new paste based on this one


Comments: