Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
DateTime | |
0.00% |
0 / 14 |
|
0.00% |
0 / 4 |
30 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
extractYear | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
getDisplayDateFormat | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
__call | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * View helper for formatting dates and times. |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Villanova University 2010. |
9 | * |
10 | * This program is free software; you can redistribute it and/or modify |
11 | * it under the terms of the GNU General Public License version 2, |
12 | * as published by the Free Software Foundation. |
13 | * |
14 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | * GNU General Public License for more details. |
18 | * |
19 | * You should have received a copy of the GNU General Public License |
20 | * along with this program; if not, write to the Free Software |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | * |
23 | * @category VuFind |
24 | * @package View_Helpers |
25 | * @author Demian Katz <demian.katz@villanova.edu> |
26 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
27 | * @link https://vufind.org/wiki/development Wiki |
28 | */ |
29 | |
30 | namespace VuFind\View\Helper\Root; |
31 | |
32 | use function call_user_func_array; |
33 | |
34 | /** |
35 | * View helper for formatting dates and times |
36 | * |
37 | * @category VuFind |
38 | * @package View_Helpers |
39 | * @author Demian Katz <demian.katz@villanova.edu> |
40 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
41 | * @link https://vufind.org/wiki/development Wiki |
42 | */ |
43 | class DateTime extends \Laminas\View\Helper\AbstractHelper |
44 | { |
45 | /** |
46 | * Date converter |
47 | * |
48 | * @var \VuFind\Date\Converter |
49 | */ |
50 | protected $converter; |
51 | |
52 | /** |
53 | * Constructor |
54 | * |
55 | * @param \VuFind\Date\Converter $converter Date converter |
56 | */ |
57 | public function __construct(\VuFind\Date\Converter $converter) |
58 | { |
59 | $this->converter = $converter; |
60 | } |
61 | |
62 | /** |
63 | * Extract a year from a human-readable date. Return false if no year can |
64 | * be found. |
65 | * |
66 | * @param string $date Date to reformat |
67 | * |
68 | * @return string|bool |
69 | */ |
70 | public function extractYear($date) |
71 | { |
72 | try { |
73 | return $this->converter->convertFromDisplayDate('Y', $date); |
74 | } catch (\VuFind\Date\DateException $e) { |
75 | // bad date? just ignore it! |
76 | return false; |
77 | } |
78 | } |
79 | |
80 | /** |
81 | * Builds an alphabetical help string based on the default display date format. |
82 | * |
83 | * @return string |
84 | */ |
85 | public function getDisplayDateFormat() |
86 | { |
87 | $dueDateHelpString |
88 | = $this->converter->convertToDisplayDate('m-d-y', '11-22-3333'); |
89 | $search = ['1', '2', '3']; |
90 | $replace = [ |
91 | $this->view->translate('date_month_placeholder'), |
92 | $this->view->translate('date_day_placeholder'), |
93 | $this->view->translate('date_year_placeholder'), |
94 | ]; |
95 | |
96 | return str_replace($search, $replace, $dueDateHelpString); |
97 | } |
98 | |
99 | /** |
100 | * By default, proxy method calls to the converter object. |
101 | * |
102 | * @param string $methodName The name of the called method. |
103 | * @param array $params Array of passed parameters. |
104 | * |
105 | * @return mixed |
106 | */ |
107 | public function __call($methodName, $params) |
108 | { |
109 | return call_user_func_array([$this->converter, $methodName], $params); |
110 | } |
111 | } |