Created
July 12, 2013 05:27
-
-
Save joshuapaling/5982066 to your computer and use it in GitHub Desktop.
I'm using this for a job, and I don't think I need it anymore - but I don't want to throw it out just yet either. Today is 12 Jul 2013, so in a few months if I haven't used it I can throw this out.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Takes a date and calculates the start and end of the calendar week that it's in. | |
* Start will be 00:00:00 of the Monday of that calendar week, and end will be | |
* 00:00:00 of the Monday of the next calendar week (ie, just after the Sunday ends) | |
* | |
* @param string $date MySQL friendly date, with format "Y-m-d H:i:s" | |
* @return array - has two keys, 'start' and 'end' which are the boundaries of the calendar | |
* week, in MySQL format - ie, "Y-m-d H:i:s" | |
*/ | |
protected function _getWeekEndpoints($date){ | |
$timestamp = strtotime($date); | |
if(date('D', $timestamp) == 'Mon'){ | |
$startTimestamp = $timestamp; | |
} else { | |
$startTimestamp = strtotime('last monday', $timestamp); | |
} | |
$weekStart = date($this->sqlDateTimeFormat, $startTimestamp); | |
$endTimestamp = strtotime('next monday', $timestamp); | |
$weekEnd = date($this->sqlDateTimeFormat, $endTimestamp); | |
return array('start' => $weekStart, 'end' => $weekEnd); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment