Created
June 5, 2009 21:31
-
-
Save Oshuma/124514 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| <?php | |
| // Rounds the given timestamp (string) up 15 minutes. | |
| function round_timestamp($timestamp) { | |
| $interval = 15; // minutes | |
| $date_format = "%d-%b-%y %I:%M:%S %p %Z"; | |
| $time_array = strptime(strftime($date_format, strtotime($timestamp)), $date_format); | |
| $minutes = $time_array['tm_min']; | |
| $delta = $minutes % $interval; | |
| $time_array['tm_min'] = $minutes + ($delta * ($delta < $interval / 2 ? -1 : 1)); | |
| $new_timestamp = mktime($time_array['tm_hour'], | |
| $time_array['tm_min'], | |
| $time_array['tm_sec'], | |
| $time_array['tm_mon'], | |
| $time_array['tm_mday'], | |
| $time_array['tm_year']); | |
| return strftime($date_format, $new_timestamp); | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment