File tree Expand file tree Collapse file tree 1 file changed +43
-4
lines changed
Expand file tree Collapse file tree 1 file changed +43
-4
lines changed Original file line number Diff line number Diff line change 22
33if (!function_exists ('color_value_format ' )) {
44 /**
5- * @param string $value
6- * @param string $color
5+ * Format a value with an optional color.
76 *
7+ * @param string $value
8+ * @param string|null $color
89 * @return string
910 */
10- function color_value_format (string $ value , string $ color ): string
11+ function color_value_format (string $ value , ? string $ color = null ): string
1112 {
12- $ value = str_replace (' ' , ' \space ' , $ value );
13+ if (empty ($ color )) {
14+ return $ value ;
15+ }
1316
1417 return '$${\color{ ' .$ color .'} ' .$ value .'}$$ ' ;
1518 }
1619}
20+
21+ if (!function_exists ('format_date ' )) {
22+ /**
23+ * Format a date string.
24+ *
25+ * @param string|null $date
26+ * @param string $format
27+ *
28+ * @return string|null
29+ */
30+ function format_date (?string $ date , string $ format = 'Y-m-d ' ): ?string
31+ {
32+ if (!$ date ) {
33+ return null ;
34+ }
35+
36+ try {
37+ return \Carbon \Carbon::parse ($ date )->format ($ format );
38+ } catch (\Exception $ e ) {
39+ return $ date ;
40+ }
41+ }
42+ }
43+
44+ if (!function_exists ('format_boolean ' )) {
45+ /**
46+ * Format a boolean value.
47+ *
48+ * @param mixed $value
49+ * @return string
50+ */
51+ function format_boolean ($ value ): string
52+ {
53+ return filter_var ($ value , FILTER_VALIDATE_BOOLEAN ) ? '✅ ' : '❌ ' ;
54+ }
55+ }
You can’t perform that action at this time.
0 commit comments