1<?php
2/**
3 * Copyright 2009-2017 Horde LLC (http://www.horde.org/)
4 *
5 * See the enclosed file COPYING for license information (LGPL). If you
6 * did not receive this file, see http://www.horde.org/licenses/lgpl21.
7 *
8 * @author   Chuck Hagenbuch <chuck@horde.org>
9 * @category Horde
10 * @license  http://www.horde.org/licenses/lgpl21 LGPL
11 * @package  Date
12 */
13
14/**
15 * Date repeater.
16 *
17 * @author    Chuck Hagenbuch <chuck@horde.org>
18 * @category  Horde
19 * @copyright 2009-2017 Horde LLC
20 * @license   http://www.horde.org/licenses/lgpl21 LGPL
21 * @package   Date
22 */
23class Horde_Date_Repeater_Minute extends Horde_Date_Repeater
24{
25    public $currentMinuteStart;
26
27    public function next($pointer = 'future')
28    {
29        parent::next($pointer);
30
31        if (!$this->currentMinuteStart) {
32            $this->currentMinuteStart = new Horde_Date(array('month' => $this->now->month, 'year' => $this->now->year, 'day' => $this->now->day, 'hour' => $this->now->hour, 'min' => $this->now->min));
33        }
34        $direction = ($pointer == 'future') ? 1 : -1;
35        $this->currentMinuteStart->min += $direction;
36
37        $end = clone $this->currentMinuteStart;
38        $end->min++;
39        return new Horde_Date_Span($this->currentMinuteStart, $end);
40    }
41
42    public function this($pointer = 'future')
43    {
44        parent::this($pointer);
45
46        switch ($pointer) {
47        case 'future':
48            $minuteBegin = clone $this->now;
49            $minuteEnd = new Horde_Date(array('month' => $this->now->month, 'year' => $this->now->year, 'day' => $this->now->day, 'hour' => $this->now->hour, 'min' => $this->now->min));
50            break;
51
52        case 'past':
53            $minuteBegin = new Horde_Date(array('month' => $this->now->month, 'year' => $this->now->year, 'day' => $this->now->day, 'hour' => $this->now->hour, 'min' => $this->now->min));
54            $minuteEnd = clone $this->now;
55            break;
56
57        case 'none':
58            $minuteBegin = new Horde_Date(array('month' => $this->now->month, 'year' => $this->now->year, 'day' => $this->now->day, 'hour' => $this->now->hour, 'min' => $this->now->min));
59            $minuteEnd = new Horde_Date(array('month' => $this->now->month, 'year' => $this->now->year, 'day' => $this->now->day, 'hour' => $this->now->hour, 'min' => $this->now->min + 1));
60            break;
61        }
62
63        return new Horde_Date_Span($minuteBegin, $minuteEnd);
64    }
65
66    public function offset($span, $amount, $pointer)
67    {
68        $direction = ($pointer == 'future') ? 1 : -1;
69        return $span->add(array('min' => $direction * $amount));
70    }
71
72    public function width()
73    {
74        return 60;
75    }
76
77    public function __toString()
78    {
79        return parent::__toString() . '-minute';
80    }
81
82}
83