@@ -63,6 +63,7 @@ public function settingsForm(array $form, FormStateInterface $form_state) {
63
63
'space ' => t ("Space ' ' " ),
64
64
],
65
65
];
66
+
66
67
$ form ['date_order ' ] = [
67
68
'#title ' => t ('Date Order ' ),
68
69
'#type ' => 'select ' ,
@@ -74,11 +75,13 @@ public function settingsForm(array $form, FormStateInterface $form_state) {
74
75
'middle_endian ' => t ('Middle-endian (month, day, year) ' ),
75
76
],
76
77
];
78
+
77
79
$ form ['month_format ' ] = [
78
80
'#title ' => t ('Month Format ' ),
79
81
'#type ' => 'select ' ,
80
82
'#default_value ' => $ this ->getSetting ('month_format ' ),
81
83
'#options ' => [
84
+ 'nm ' => t ('Do not show Month ' ),
82
85
'mm ' => t ('two-digit month, e.g. 04 ' ),
83
86
'm ' => t ('one-digit month for months below 10, e.g. 4 ' ),
84
87
'mmm ' => t ('three-letter abbreviation for month, Apr ' ),
@@ -90,10 +93,21 @@ public function settingsForm(array $form, FormStateInterface $form_state) {
90
93
'#type ' => 'select ' ,
91
94
'#default_value ' => $ this ->getSetting ('day_format ' ),
92
95
'#options ' => [
96
+ 'nd ' => t ('Do not show day ' ),
93
97
'dd ' => t ('two-digit day of the month, e.g. 02 ' ),
94
98
'd ' => t ('one-digit day of the month for days below 10, e.g. 2 ' ),
95
99
],
96
100
];
101
+ $ form ['year_format ' ] = [
102
+ '#title ' => t ('Year Format ' ),
103
+ '#type ' => 'select ' ,
104
+ '#default_value ' => $ this ->getSetting ('year_format ' ),
105
+ '#options ' => [
106
+ 'ny ' => t ('Do not show year ' ),
107
+ 'yy ' => t ('two-digit day of the month, e.g. 02 ' ),
108
+ 'y ' => t ('four-digit representation of the year, e.g. 2020 ' ),
109
+ ],
110
+ ];
97
111
return $ form ;
98
112
}
99
113
@@ -242,6 +256,9 @@ protected function formatDate($edtf_text) {
242
256
elseif ($ settings ['month_format ' ] === 'm ' ) {
243
257
$ month = ltrim ($ parsed_date [EDTFUtils::MONTH ], ' 0 ' );
244
258
}
259
+ elseif ($ settings ['month_format ' ] == 'nm ' ) {
260
+ $ month = "" ;
261
+ }
245
262
// IF 'mm', do nothing, it is already in this format.
246
263
else {
247
264
$ month = $ parsed_date [EDTFUtils::MONTH ];
@@ -255,11 +272,26 @@ protected function formatDate($edtf_text) {
255
272
elseif ($ settings ['day_format ' ] === 'd ' ) {
256
273
$ day = ltrim ($ parsed_date [EDTFUtils::DAY ], ' 0 ' );
257
274
}
275
+ elseif ($ settings ['day_format ' ] == "nd " ) {
276
+ $ day = "" ;
277
+ }
258
278
else {
259
279
$ day = $ parsed_date [EDTFUtils::DAY ];
260
280
}
261
281
}
262
282
283
+ if (array_key_exists (EDTFUtils::YEAR_BASE , $ parsed_date )) {
284
+ if ($ settings ['year_format ' ] == 'ny ' ) {
285
+ $ year = '' ;
286
+ }
287
+ elseif ($ settings ['year_format ' ] = 'yy ' ) {
288
+ $ year = ltrim ($ parsed_date [EDTFUtils::YEAR_BASE ], '0 ' );
289
+ }
290
+ else {
291
+ $ year = substr (ltrim ($ parsed_date [EDTFUtils::YEAR_BASE ], '0 ' ), 0 , 2 );
292
+ }
293
+ }
294
+
263
295
// Put the parts back together.
264
296
if ($ settings ['date_order ' ] === 'little_endian ' ) {
265
297
$ parts_in_order = [$ day , $ month , $ year ];
0 commit comments