protected function createDayFlydown()
    {
        $flydown = new SwatFlydown($this->id . '_day');
        $flydown->classes = array('swat-date-entry-day');

        if ($this->show_blank_titles) {
            $flydown->blank_title = $this->getDayBlankValueTitle();
        }

        // Subtract a second from the end date. This makes comparison correct,
        // and prevents displaying extra days.
        $range_end = clone $this->valid_range_end;
        $range_end->subtractSeconds(1);

        $start_year = $this->valid_range_start->getYear();
        $end_year = $range_end->getYear();
        $start_month = $this->valid_range_start->getMonth();
        $end_month = $range_end->getMonth();
        $start_day = $this->valid_range_start->getDay();
        $end_day = $range_end->getDay();

        $end_check = clone $this->valid_range_start;
        $end_check->addSeconds(2678400); // add 31 days

        if ($start_year == $end_year && $start_month == $end_month) {
            // Only days left in the month
            for ($i = $start_day; $i <= $end_day; $i++) {
                $flydown->addOption($i, $i);
            }
        } elseif (SwatDate::compare($end_check, $range_end, true) != -1) {
            // extra days at the beginning of the next month allowed
            $days_in_month = $this->valid_range_start->getDaysInMonth();

            for ($i = $start_day; $i <= $days_in_month; $i++) {
                $flydown->addOption($i, $i);
            }

            for ($i = 1; $i <= $end_day; $i++) {
                $flydown->addOption($i, $i);
            }
        } else {
            // all days are valid
            for ($i = 1; $i <= 31; $i++) {
                $flydown->addOption($i, $i);
            }
        }

        return $flydown;
    }