Inklings: a tumblelog

A CSS Naked Day concordance

The date of this years’s CSS Naked Day is just a bit problematic - neither the 9th nor the 5th are available according to the criteria, thus I’m proposing that we split the difference and have it on the 7th this year. With that in mind, here’s a lump of PHP code that will tell you, given any POSIX timestamp, whether it falls in CSS Naked Day. Here’s the code:

function is_naked_day($now) {
    $y = gmdate('Y', $now);
    // The 7th is our fallback if neither the 5th or 9th work.
    foreach (array(5, 9, 7) as $try) {
        $day_of_week = gmdate('N', gmmktime(0, 0, 0, 4, $try, $y));
        // Best if it's a Tuesday, Wednesday, or Thursday.
        if ($day_of_week >= 2 && $day_of_week <= 4) {
            $d = $try;
            break;
        }
    }
    $start = gmmktime(-12, 0, 0, 4, $d, $y);
    $end = gmmktime(36, 0, 0, 4, $d, $y);
    return $now >= $start && $now <= $end;
}

You can use it like so:

<?php if (is_naked_day(time()) { ?>
    <p>w00t!</p>
<?php } ?>