8
8
use Astral \Serialize \Support \Collections \DataCollection ;
9
9
use Astral \Serialize \Support \Context \OutContext ;
10
10
use Attribute ;
11
- use DateInvalidTimeZoneException ;
12
- use DateMalformedStringException ;
13
11
use DateTime ;
14
12
use DateTimeInterface ;
15
13
use DateTimeZone ;
14
+ use Exception ;
16
15
17
16
/**
18
17
* toArray 输出值为 固定日期格式 默认 YYYY-MM-DD HH:ii:ss的日期格式
@@ -31,19 +30,12 @@ public function match(mixed $value, DataCollection $collection, OutContext $cont
31
30
return is_string ($ value ) || is_numeric ($ value ) || is_subclass_of ($ value , DateTimeInterface::class);
32
31
}
33
32
34
- /**
35
- * @throws DateMalformedStringException
36
- * @throws DateInvalidTimeZoneException
37
- */
33
+
38
34
public function resolve (mixed $ value , DataCollection $ collection , OutContext $ context ): string |DateTime |null
39
35
{
40
36
return $ this ->formatValue ($ value );
41
37
}
42
38
43
- /**
44
- * @throws DateMalformedStringException
45
- * @throws DateInvalidTimeZoneException
46
- */
47
39
private function formatValue (mixed $ value ): ?string
48
40
{
49
41
$ timezone = $ this ->timezone ? new DateTimeZone ($ this ->timezone ) : null ;
@@ -57,7 +49,7 @@ private function formatValue(mixed $value): ?string
57
49
}
58
50
59
51
/**
60
- * @throws DateMalformedStringException
52
+ * @throws Exception
61
53
*/
62
54
private function formatDateTime (DateTimeInterface $ dateTime , ?DateTimeZone $ timezone ): string
63
55
{
@@ -69,7 +61,7 @@ private function formatDateTime(DateTimeInterface $dateTime, ?DateTimeZone $time
69
61
}
70
62
71
63
/**
72
- * @throws DateMalformedStringException
64
+ * @throws Exception
73
65
*/
74
66
private function formatTimestamp (int $ timestamp , ?DateTimeZone $ timezone ): string
75
67
{
@@ -82,7 +74,7 @@ private function formatTimestamp(int $timestamp, ?DateTimeZone $timezone): strin
82
74
}
83
75
84
76
/**
85
- * @throws DateMalformedStringException
77
+ * @throws Exception
86
78
*/
87
79
private function formatStringDate (string $ value , ?DateTimeZone $ timezone ): string
88
80
{
0 commit comments