Skip to content
Snippets Groups Projects
Commit a78d5111 authored by Tim Diels's avatar Tim Diels
Browse files

Issue #3282126 by tim-diels, cimo75: Add long weekend option

parent 2914ae47
Branches
Tags 1.0.0-beta3
1 merge request!4Issue #3282126: Make the starting day for the weekend dependent on the regional settings
......@@ -42,7 +42,8 @@ class DateRangePickerProcessor extends DatePickerProcessorBase implements BuildP
'#options' => [
'today' => $this->t('Today'),
'tomorrow' => $this->t('Tomorrow'),
'this_weekend' => $this->t('This weekend'),
'this_weekend' => $this->t('This weekend (Sat to Sun)'),
'this_weekend_long' => $this->t('This weekend (Fri to Sun)'),
'next_seven_days' => $this->t('Next 7 days'),
'next_fourteen_days' => $this->t('Next 14 days'),
'next_thirty_days' => $this->t('Next 30 days'),
......
......@@ -119,6 +119,29 @@ class SearchApiDateRangePicker extends SearchApiDateRangePickerBase {
}
break;
case 'this_weekend_long':
// Today is friday.
if ($now->format('N') === '5') {
$start_date = $now;
$end_date = $now->modify('+2 days');
}
elseif ($now->format('N') === '6') {
$start_date = $now;
$end_date = $now->modify('+1 day');
}
// Today is sunday.
elseif ($now->format('N') === '7') {
$start_date = $now;
$end_date = $now->modify('-1 day');
}
// Today is just a weekday.
else {
$start_date = new DrupalDateTime('next friday', 'UTC');
$end_date = new DrupalDateTime('next sunday', 'UTC');
}
break;
case 'next_seven_days':
$start_date = new DrupalDateTime('now', 'UTC');
$end_date = new DrupalDateTime('+7 days', 'UTC');
......@@ -189,6 +212,10 @@ class SearchApiDateRangePicker extends SearchApiDateRangePickerBase {
$display = $this->t('This weekend');
break;
case 'this_weekend_long':
$display = $this->t('This long weekend');
break;
case 'next_seven_days':
$display = $this->t('Next 7 days');
break;
......@@ -219,6 +246,7 @@ class SearchApiDateRangePicker extends SearchApiDateRangePickerBase {
'today',
'tomorrow',
'this_weekend',
'this_weekend_long',
'next_seven_days',
'next_fourteen_days',
'next_thirty_days',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment