forked from ProcessMaker/processmaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMillisecondsToDateCast.php
More file actions
40 lines (36 loc) · 1011 Bytes
/
MillisecondsToDateCast.php
File metadata and controls
40 lines (36 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
namespace ProcessMaker\Casts;
use Carbon\Carbon;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
use Illuminate\Database\Eloquent\Model;
class MillisecondsToDateCast implements CastsAttributes
{
/**
* Cast the given value.
*
* @param Model $model
* @param string $key
* @param mixed $value
* @param array<string, mixed> $attributes
*
* @return Carbon|null
*/
public function get(Model $model, string $key, mixed $value, array $attributes): Carbon|null
{
return $value ? Carbon::createFromTimestampMs($value) : null;
}
/**
* Prepare the given value for storage.
*
* @param Model $model
* @param string $key
* @param mixed $value
* @param array<string, mixed> $attributes
*
* @return float|null
*/
public function set(Model $model, string $key, mixed $value, array $attributes): float|null
{
return $value ? Carbon::parse($value)->valueOf() : null;
}
}