<commit_before><?php

namespace Plummer\Calendarful\Recurrence\Type;

use Plummer\Calendarful\Recurrence\RecurrenceInterface;

class MonthlyDate implements RecurrenceInterface
{
	protected $label = 'monthly';

	protected $limit = '+25 year';

	public function getLabel()
	{
		return $this->label;
	}

	public function getLimit()
	{
		return $this->limit;
	}

	public function generateOccurrences(Array $events, \DateTime $fromDate, \DateTime $toDate, $limit = null)
	{
		$return = [];

		$monthlyEvents = array_filter($events, function ($event) {
			return $event->getRecurrenceType() === $this->getLabel();
		});

		foreach ($monthlyEvents as $monthlyEvent) {

			$start = $fromDate > new \DateTime($monthlyEvent->getStartDate())
				? $fromDate
				: new \DateTime($monthlyEvent->getStartDate());

			$startMarker = clone($start);
			$startMarker->modify('first day of this month');

			$endMarker = $monthlyEvent->getRecurrenceUntil()
				? min(new \DateTime($monthlyEvent->getRecurrenceUntil()), $toDate)
				: $toDate;

			// The DatePeriod class does not actually include the end date so you have to increment it first
			$endMarker->modify('+1 day');

			$monthlyDay = $monthlyEvent->getRecurrenceDayOfMonth();

			$dateInterval = new \DateInterval('P1M');
			$datePeriod = new \DatePeriod($startMarker, $dateInterval, $endMarker);

			foreach($datePeriod as $date) {

				if($monthlyDay > $date->format('t')) {
					continue;
				}
<commit_msg>Change Monthly recurrence type to take the day number from the event start date.<commit_after><?php

namespace Plummer\Calendarful\Recurrence\Type;

use Plummer\Calendarful\Recurrence\RecurrenceInterface;

class MonthlyDate implements RecurrenceInterface
{
	protected $label = 'monthly';

	protected $limit = '+25 year';

	public function getLabel()
	{
		return $this->label;
	}

	public function getLimit()
	{
		return $this->limit;
	}

	public function generateOccurrences(Array $events, \DateTime $fromDate, \DateTime $toDate, $limit = null)
	{
		$return = [];

		$monthlyEvents = array_filter($events, function ($event) {
			return $event->getRecurrenceType() === $this->getLabel();
		});

		foreach ($monthlyEvents as $monthlyEvent) {

			$monthlyDate = date('d', strtotime($monthlyEvent->getStartDate()));

			$start = $fromDate > new \DateTime($monthlyEvent->getStartDate())
				? $fromDate
				: new \DateTime($monthlyEvent->getStartDate());

			$startMarker = clone($start);
			$startMarker->modify('first day of this month');

			$endMarker = $monthlyEvent->getRecurrenceUntil()
				? min(new \DateTime($monthlyEvent->getRecurrenceUntil()), $toDate)
				: $toDate;

			// The DatePeriod class does not actually include the end date so you have to increment it first
			$endMarker->modify('+1 day');

			$dateInterval = new \DateInterval('P1M');
			$datePeriod = new \DatePeriod($startMarker, $dateInterval, $endMarker);

			foreach($datePeriod as $date) {

				if($monthlyDate > $date->format('t')) {
					continue;
				}

{'fraction_non_alphanumeric': 0.14209115281501342, 'fraction_numerical': 0.002680965147453083, 'mean_word_length': 4.507380073800738, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2473901', 'n_tokens_mistral': 1057, 'n_tokens_neox': 920, 'n_words': 220}