Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6948a68

Browse files
committed
Merge branch '1.0' into 1.1
* 1.0: Fix JS error when autocomplete field is empty Use nullable return type formatting content in a email message willdurand/hateoas 2.12 version update (Sylius#9302) Minor documentation changes for product reviews Minor doc fix Correct minor typo in docs Test edge case for orders filtering Provide default times for datetime filter Filtering orders without time scenaio
2 parents 0499eda + c6161d2 commit 6948a68

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

Filter/DateFilter.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function apply(DataSourceInterface $dataSource, string $name, $data, arra
3131

3232
$field = (string) $this->getOption($options, 'field', $name);
3333

34-
$from = isset($data['from']) ? $this->getDateTime($data['from']) : null;
34+
$from = isset($data['from']) ? $this->getDateTime($data['from'], '00:00') : null;
3535
if (null !== $from) {
3636
$inclusive = (bool) $this->getOption($options, 'inclusive_from', self::DEFAULT_INCLUSIVE_FROM);
3737
if (true === $inclusive) {
@@ -41,7 +41,7 @@ public function apply(DataSourceInterface $dataSource, string $name, $data, arra
4141
}
4242
}
4343

44-
$to = isset($data['to']) ? $this->getDateTime($data['to']) : null;
44+
$to = isset($data['to']) ? $this->getDateTime($data['to'], '23:59') : null;
4545
if (null !== $to) {
4646
$inclusive = (bool) $this->getOption($options, 'inclusive_to', self::DEFAULT_INCLUSIVE_TO);
4747
if (true === $inclusive) {
@@ -66,17 +66,18 @@ private function getOption(array $options, string $name, $default)
6666

6767
/**
6868
* @param string[] $data
69+
* @param string $defaultTime
6970
*
7071
* @return string|null
7172
*/
72-
private function getDateTime(array $data): ?string
73+
private function getDateTime(array $data, string $defaultTime): ?string
7374
{
7475
if (empty($data['date'])) {
7576
return null;
7677
}
7778

7879
if (empty($data['time'])) {
79-
return $data['date'];
80+
$data['time'] = $defaultTime;
8081
}
8182

8283
return $data['date'] . ' ' . $data['time'];

spec/Filter/DateFilterSpec.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ function it_filters_date_from_not_inclusive(
7777
);
7878
}
7979

80-
function it_filters_date_from_without_time(
80+
function it_filters_date_from_with_default_time(
8181
DataSourceInterface $dataSource,
8282
ExpressionBuilderInterface $expressionBuilder
8383
): void {
8484
$dataSource->getExpressionBuilder()->willReturn($expressionBuilder);
8585

8686
$expressionBuilder
87-
->greaterThanOrEqual('checkoutCompletedAt', '2016-12-05')
87+
->greaterThanOrEqual('checkoutCompletedAt', '2016-12-05 00:00')
8888
->shouldBeCalled()
8989
;
9090

@@ -157,14 +157,14 @@ function it_filters_date_to_inclusive(
157157
);
158158
}
159159

160-
function it_filters_date_to_without_time(
160+
function it_filters_date_to_with_default_time(
161161
DataSourceInterface $dataSource,
162162
ExpressionBuilderInterface $expressionBuilder
163163
): void {
164164
$dataSource->getExpressionBuilder()->willReturn($expressionBuilder);
165165

166166
$expressionBuilder
167-
->lessThan('checkoutCompletedAt', '2016-12-06')
167+
->lessThan('checkoutCompletedAt', '2016-12-06 23:59')
168168
->shouldBeCalled()
169169
;
170170

0 commit comments

Comments
 (0)