|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\RenderingInstructions; |
|
4
|
|
|
|
|
5
|
|
|
/*************************************************************** |
|
6
|
|
|
* Copyright notice |
|
7
|
|
|
* |
|
8
|
|
|
* (c) 2015-2016 Hendrik Putzek <[email protected]> |
|
9
|
|
|
* All rights reserved |
|
10
|
|
|
* |
|
11
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
|
12
|
|
|
* free software; you can redistribute it and/or modify |
|
13
|
|
|
* it under the terms of the GNU General Public License as published by |
|
14
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
|
15
|
|
|
* (at your option) any later version. |
|
16
|
|
|
* |
|
17
|
|
|
* The GNU General Public License can be found at |
|
18
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
|
19
|
|
|
* |
|
20
|
|
|
* This script is distributed in the hope that it will be useful, |
|
21
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
22
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
23
|
|
|
* GNU General Public License for more details. |
|
24
|
|
|
* |
|
25
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
|
26
|
|
|
***************************************************************/ |
|
27
|
|
|
|
|
28
|
|
|
use ApacheSolrForTypo3\Solr\System\DateTime\FormatService; |
|
29
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Formats a given date string to another format |
|
33
|
|
|
* |
|
34
|
|
|
* Accepted typoscript parameters: |
|
35
|
|
|
* inputFormat -> The format of the input string |
|
36
|
|
|
* outputFormat -> The format of the processed string (output) |
|
37
|
|
|
* |
|
38
|
|
|
* If the input date can not be processed by the given inputFormat string it is |
|
39
|
|
|
* returned unprocessed. |
|
40
|
|
|
* |
|
41
|
|
|
* @author Hendrik Putzek <[email protected]> |
|
42
|
|
|
*/ |
|
43
|
|
|
class FormatDate |
|
44
|
|
|
{ |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @var FormatService |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $formatService = null; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* FormatDate constructor. |
|
53
|
|
|
* @param FormatService|null $formatService |
|
54
|
|
|
*/ |
|
55
|
3 |
|
public function __construct(FormatService $formatService = null) |
|
56
|
|
|
{ |
|
57
|
3 |
|
$this->formatService = is_null($formatService) ? GeneralUtility::makeInstance(FormatService::class) : $formatService; |
|
58
|
3 |
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Formats a given date string to another format |
|
62
|
|
|
* |
|
63
|
|
|
* @param string $content the content to process |
|
64
|
|
|
* @param array $conf typoscript configuration |
|
65
|
|
|
* @return string formatted date |
|
66
|
|
|
*/ |
|
67
|
3 |
|
public function format($content, $conf) |
|
68
|
|
|
{ |
|
69
|
|
|
// set default values |
|
70
|
3 |
|
$inputFormat = $conf['inputFormat'] ?: 'Y-m-d\TH:i:s\Z'; |
|
71
|
3 |
|
$outputFormat = $conf['outputFormat'] ?: ''; |
|
72
|
3 |
|
return $this->formatService->format($content, $inputFormat, $outputFormat); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|