public function getByMonthDayAsText($byMonthDay, $listSeparator = 'and') { if (empty($byMonthDay)) { return ''; } // sort negative indices in reverse order so we get e.g. 1st, 2nd, 4th, 3rd last, last day usort($byMonthDay, function ($a, $b) { if ($a < 0 && $b < 0 || $a >= 0 && $b >= 0) { return $a - $b; } return $b - $a; }); // generate ordinal numbers and insert a "on the" for clarity in the middle if we have both // positive and negative ordinals. This is to avoid confusing situations like: // // monthly on the 1st and 2nd to the last day // // which gets clarified to: // // monthly on the 1st day and on the 2nd to the last day $hadPositives = false; $hadNegatives = false; foreach ($byMonthDay as $index => $day) { $prefix = ''; if ($day >= 0) { $hadPositives = true; } if ($day < 0) { if ($hadPositives && !$hadNegatives && $listSeparator === 'and') { $prefix = $this->translator->trans('on the') . ' '; } $hadNegatives = true; } $byMonthDay[$index] = $prefix . $this->getOrdinalNumber($day, end($byMonthDay) < 0, true); } return $this->getListStringFromArray($byMonthDay, $listSeparator); }