3 * Helper class for calculating and displaying event times
9 * @author Zach Copley <zach@status.net>
10 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
11 * @link http://status.net/
13 * StatusNet - the distributed open-source microblogging tool
14 * Copyright (C) 2011, StatusNet, Inc.
16 * This program is free software: you can redistribute it and/or modify
17 * it under the terms of the GNU Affero General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU Affero General Public License for more details.
26 * You should have received a copy of the GNU Affero General Public License
27 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 * Class to get fancy times for the dropdowns on the new event form
35 * Round up to the nearest half hour
37 * @param string $time the time to round (date/time string)
38 * @return DateTime the rounded time
40 public static function nearestHalfHour($time)
42 $startd = new DateTime($time);
44 $minutes = $startd->format('i');
45 $hour = $startd->format('H');
54 $startd->setTime($hour, $minutes, 0);
60 * Output a list of times in half-hour intervals
62 * @param string $start Time to start with (date string, usually a ts)
63 * @param boolean $duration Whether to include the duration of the event
65 * @return array $times (localized 24 hour time string => fancy time string)
67 public static function getTimes($start = 'now', $duration = false)
69 $newTime = new DateTime($start);
73 $newTime->setTimezone(new DateTimeZone(common_timezone()));
75 for ($i = 0; $i < 47; $i++) {
77 $localTime = $newTime->format("g:ia");
79 // pretty up the end-time option list a bit
84 // TRANS: 0 minutes abbreviated. Used in a list.
85 $total = ' ' . _m('(0 min)');
88 // TRANS: 30 minutes abbreviated. Used in a list.
89 $total = ' ' . _m('(30 min)');
92 // TRANS: 1 hour. Used in a list.
93 $total = ' ' . _m('(1 hour)');
96 // TRANS: Number of hours (%.1f and %d). Used in a list.
97 $format = is_float($hours)
100 $total = ' ' . sprintf($format, $hours);
103 $localTime .= $total;
107 $times[$newTime->format('g:ia')] = $localTime;
108 $newTime->modify('+30min'); // 30 min intervals