Skip to content

Commit

Permalink
date value fix
Browse files Browse the repository at this point in the history
  • Loading branch information
supun-io committed Apr 11, 2022
1 parent 6f738fb commit 2a3dab7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/FilterQ.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private function addWhereToQuery(EloquentBuilder|QueryBuilder $query, array $log
/**
* @throw InvalidValueException
*/
ValueValidator::validate($keyInst, $value);
$value = ValueValidator::validate($keyInst, $value);

$column = $keyInst->getColumnName();
$join = $keyInst->getJoin();
Expand Down
2 changes: 1 addition & 1 deletion src/ValueValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static function validate(Key $key, mixed $value)
if ($date !== false) {
$isValid = true;
// update value to carbon date
$value = Carbon::createFromTimestamp($date);
$value = Carbon::createFromTimestamp($date)->toDateTimeString();
break;
}

Expand Down
12 changes: 12 additions & 0 deletions tests/Unit/FilterQ/KeyValueTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,16 @@ public function test_key_type_int_invalid_check()

}

public function test_key_type_date()
{

FilterQ::expression("date='2022-02-22'")
->builder(TestModel::class)
->keys(function($keys) {
$keys->add('date')->valueType('date');
})
->addWhere();

}

}
4 changes: 2 additions & 2 deletions tests/Unit/ValueValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public function test_key_value_type_date_relative()
$key = new Key('test');
$key->valueType('date');

$date = Carbon::parse('yesterday');
$date = Carbon::parse('yesterday')->toDateTimeString();

$this->assertEquals($date, ValueValidator::validate($key, 'yesterday'));

Expand All @@ -192,7 +192,7 @@ public function test_key_value_type_date_unix()
$key = new Key('test');
$key->valueType('date');

$date = Carbon::createFromTimestamp(1649358544);
$date = Carbon::createFromTimestamp(1649358544)->toDateTimeString();

$this->assertEquals($date, ValueValidator::validate($key, 1649358544));

Expand Down

0 comments on commit 2a3dab7

Please sign in to comment.