Skip to content

Commit a82d0b6

Browse files
Merge pull request #2 from mohammedmanssour/handle-zero-values
handle zero values
2 parents 9d665f6 + 8f89923 commit a82d0b6

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/Casts/TimezonedDatetime.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct(?string $format = null)
3737
*/
3838
public function get($model, $key, $value, $attributes)
3939
{
40-
if(! $value) {
40+
if(!$value && $value !== 0) {
4141
return null;
4242
}
4343

@@ -57,7 +57,7 @@ public function get($model, $key, $value, $attributes)
5757
*/
5858
public function set($model, $key, $value, $attributes)
5959
{
60-
if(! $value) {
60+
if(!$value && $value !== 0) {
6161
return null;
6262
}
6363

tests/CastTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,20 @@
122122
$output = $cast->set(fakeModel(), 'id', $input, []);
123123

124124
expect($output)->toBeNull();
125+
});
126+
127+
128+
it('can mutate 0 values', function() {
129+
// 4 hours difference between dubai and UTC
130+
setupFacade(current: 'Asia/Dubai');
131+
132+
$cast = new TimezonedDatetime('H');
133+
134+
$input = 0;
135+
136+
$output = $cast->set(fakeModel(), 'id', $input, []);
137+
expect($output)->toEqual(20);
138+
139+
$output = $cast->get(fakeModel(), 'id', $input, []);
140+
expect($output->format('H'))->toEqual(4);
125141
});

0 commit comments

Comments
 (0)