@@ -36,11 +36,6 @@ public function render(): array
36
36
$ additionalAttributes = $ this ->arguments ['additionalAttributes ' ];
37
37
$ value = $ this ->arguments ['value ' ];
38
38
39
- $ additionalAttributes ['data-datepicker-force ' ] =
40
- $ this ->settings ['misc ' ]['datepicker ' ]['forceJavaScriptDatePicker ' ] ?? 0 ;
41
- $ additionalAttributes ['data-datepicker-settings ' ] = $ this ->getDatepickerSettings ($ field );
42
- $ additionalAttributes ['data-datepicker-months ' ] = $ this ->getMonthNames ();
43
- $ additionalAttributes ['data-datepicker-days ' ] = $ this ->getDayNames ();
44
39
$ additionalAttributes ['data-datepicker-format ' ] = $ this ->getFormat ($ field );
45
40
if ($ value ) {
46
41
$ additionalAttributes ['data-date-value ' ] = $ value ;
@@ -54,7 +49,7 @@ public function render(): array
54
49
/**
55
50
* Get Datepicker Settings
56
51
*
57
- * @param Field $field
52
+ * @param Field|null $field
58
53
* @return string
59
54
*/
60
55
protected function getDatepickerSettings (Field $ field = null ): string
@@ -66,64 +61,39 @@ protected function getDatepickerSettings(Field $field = null): string
66
61
}
67
62
68
63
/**
69
- * Get timeformat out of datepicker type
70
- *
71
- * @param Field $field
64
+ * @param Field|null $field
72
65
* @return string
73
66
*/
74
67
protected function getFormat (Field $ field = null ): string
75
68
{
76
- return LocalizationUtility::translate ('datepicker_format_ ' . $ this ->getDatepickerSettings ($ field ));
77
- }
78
-
79
- /**
80
- * Generate Monthnames from locallang
81
- *
82
- * @return string
83
- */
84
- protected function getDayNames (): string
85
- {
86
- $ days = [
87
- 'so ' ,
88
- 'mo ' ,
89
- 'tu ' ,
90
- 'we ' ,
91
- 'th ' ,
92
- 'fr ' ,
93
- 'sa ' ,
94
- ];
95
- $ dayArray = [];
96
- foreach ($ days as $ day ) {
97
- $ dayArray [] = LocalizationUtility::translate ('datepicker_day_ ' . $ day );
98
- }
99
- return implode (', ' , $ dayArray );
69
+ $ format = LocalizationUtility::translate ('datepicker_format_ ' . $ this ->getDatepickerSettings ($ field ));
70
+ return $ this ->convertFormatForMomentJs ($ format );
100
71
}
101
72
102
73
/**
103
- * Generate Monthnames from locallang
104
- *
74
+ * Because moment.js needs a different format writings, we need to convert this
75
+ * "Y-m-d H:i" => "YYYY-MM-DD HH:mm"
76
+ * @param string $format
105
77
* @return string
106
78
*/
107
- protected function getMonthNames ( ): string
79
+ protected function convertFormatForMomentJs ( string $ format ): string
108
80
{
109
- $ months = [
110
- 'jan ' ,
111
- 'feb ' ,
112
- 'mar ' ,
113
- 'apr ' ,
114
- 'may ' ,
115
- 'jun ' ,
116
- 'jul ' ,
117
- 'aug ' ,
118
- 'sep ' ,
119
- 'oct ' ,
120
- 'nov ' ,
121
- 'dec ' ,
81
+ $ replace = [
82
+ [
83
+ 'Y ' ,
84
+ 'm ' ,
85
+ 'd ' ,
86
+ 'H ' ,
87
+ 'i ' ,
88
+ ],
89
+ [
90
+ 'YYYY ' ,
91
+ 'MM ' ,
92
+ 'DD ' ,
93
+ 'HH ' ,
94
+ 'mm ' ,
95
+ ]
122
96
];
123
- $ monthArray = [];
124
- foreach ($ months as $ month ) {
125
- $ monthArray [] = LocalizationUtility::translate ('datepicker_month_ ' . $ month );
126
- }
127
- return implode (', ' , $ monthArray );
97
+ return str_replace ($ replace [0 ], $ replace [1 ], $ format );
128
98
}
129
99
}
0 commit comments