@@ -43,12 +43,7 @@ public static function get(
43
43
/**
44
44
* @see https://www.php.net/manual/en/datetimeimmutable.createfromformat.php#datetimeimmutable.createfromformat.parameters
45
45
*/
46
- $ format = match ($ params [0 ] ?? '' ) {
47
- '' => $ helper ->dateFormat ['datetime ' ],
48
- 'ms ' => $ helper ->dateFormat ['datetime-ms ' ],
49
- 'us ' => $ helper ->dateFormat ['datetime-us ' ],
50
- default => throw new InvalidArgumentException ('Invalid parameter: ' . $ params [0 ]),
51
- };
46
+ $ format = self ::getDateTimeFormat ($ params , $ helper );
52
47
53
48
return Time::createFromFormat ($ format , $ value );
54
49
}
@@ -68,13 +63,23 @@ public static function set(
68
63
throw new InvalidArgumentException ($ message );
69
64
}
70
65
71
- $ format = match ($ params [0 ] ?? '' ) {
72
- '' => $ helper ->dateFormat ['datetime ' ],
73
- 'ms ' => $ helper ->dateFormat ['datetime-ms ' ],
74
- 'us ' => $ helper ->dateFormat ['datetime-us ' ],
75
- default => throw new InvalidArgumentException ('Invalid parameter: ' . $ params [0 ]),
76
- };
66
+ $ format = self ::getDateTimeFormat ($ params , $ helper );
77
67
78
68
return $ value ->format ($ format );
79
69
}
70
+
71
+ /**
72
+ * Gets DateTime format from the DB connection.
73
+ *
74
+ * @param list<string> $params Additional param
75
+ */
76
+ protected static function getDateTimeFormat (array $ params , BaseConnection $ db ): string
77
+ {
78
+ return match ($ params [0 ] ?? '' ) {
79
+ '' => $ db ->dateFormat ['datetime ' ],
80
+ 'ms ' => $ db ->dateFormat ['datetime-ms ' ],
81
+ 'us ' => $ db ->dateFormat ['datetime-us ' ],
82
+ default => throw new InvalidArgumentException ('Invalid parameter: ' . $ params [0 ]),
83
+ };
84
+ }
80
85
}
0 commit comments