Skip to content

Commit

Permalink
Fix #424 - allow relative dates for limits
Browse files Browse the repository at this point in the history
  • Loading branch information
lochmueller committed Feb 13, 2021
1 parent bef2f6d commit 6b39f84
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
6 changes: 4 additions & 2 deletions Classes/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use HDNET\Calendarize\Domain\Repository\IndexRepository;
use HDNET\Calendarize\Property\TypeConverter\AbstractBookingRequest;
use HDNET\Calendarize\Service\PluginConfigurationService;
use HDNET\Calendarize\Utility\DateTimeUtility;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand Down Expand Up @@ -241,8 +242,9 @@ protected function addCacheTags(array $tags)

protected function isDateOutOfTypoScriptConfiguration(\DateTime $dateTime): bool
{
$prev = new \DateTime($this->settings['dateLimitBrowserPrev']);
$next = new \DateTime($this->settings['dateLimitBrowserNext']);

$prev = DateTimeUtility::normalizeDateTimeSingle($this->settings['dateLimitBrowserPrev']);
$next = DateTimeUtility::normalizeDateTimeSingle($this->settings['dateLimitBrowserNext']);
return ($prev > $dateTime || $next < $dateTime);
}

Expand Down
3 changes: 3 additions & 0 deletions Classes/Utility/DateTimeUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ public static function normalizeDateTimeSingle($dateInformation = null, \DateTim
// http://php.net/manual/en/datetime.construct#refsect1-datetime.construct-parameters :
// The $timezone parameter and the current timezone are ignored [ie. set to UTC] when the $time parameter [...] is a UNIX timestamp (e.g. @946684800) [...]
$date = new \DateTime("@$dateInformation");
} elseif (\is_string($dateInformation) && in_array($dateInformation[0], ['-', '+'])) {
$date = self::getNow();
$date->modify($dateInformation);
} elseif (\is_string($dateInformation)) {
// Add timezone explicitly here, so that it does not depend on the "current timezone".
$date = new \DateTime($dateInformation, $timezone);
Expand Down
8 changes: 4 additions & 4 deletions Configuration/TypoScript/constants.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
plugin.tx_calendarize {

settings {
# cat=calendarize//0010; type=string; label=Previous Limit: Limit for the previous button in the day,week,month,year view - Format: YYYY-MM-DD
dateLimitBrowserPrev = 2019-01-01
# cat=calendarize//0010; type=string; label=Previous Limit: Limit for the previous button in the day,week,month,year view - Format: YYYY-MM-DD or something like "-2 years"
dateLimitBrowserPrev = -2 years

# cat=calendarize//0020; type=string; label=Next Limit: Limit for the next button in the day,week,month,year view - Format: YYYY-MM-DD
dateLimitBrowserNext = 2028-01-01
# cat=calendarize//0020; type=string; label=Next Limit: Limit for the next button in the day,week,month,year view - Format: YYYY-MM-DD or something like "+2 years"
dateLimitBrowserNext = +3 years

# cat=calendarize//0030; type=int+; label=Start of the week: Start of the week (1 Mo - 7 Su) - ISO-8601 / http://php.net/manual/de/function.date.php 'N' / http://php.net/manual/de/function.date.php#119974
weekStart = 1
Expand Down

0 comments on commit 6b39f84

Please sign in to comment.