Generate the calendar

@access  public

@param   integer the year
@param   integer the month
@param   array   the data to be shown in the calendar cells

@return  string
552170
public function generate($year = '', $month = '', $data = [])
    {
        // Set and validate the supplied month/year
        if ($year == '') {
            $year = date("Y", $this->local_time);
        }

        if ($month == '') {
            $month = date("m", $this->local_time);
        }

        if (strlen($year) == 1) {
            $year = '200' . $year;
        }

        if (strlen($year) == 2) {
            $year = '20' . $year;
        }

        if (strlen($month) == 1) {
            $month = '0' . $month;
        }

        $adjusted_date = $this->adjust_date($month, $year);

        $month = $adjusted_date['month'];
        $year  = $adjusted_date['year'];

        // Determine the total days in the month
        $total_days = $this->get_total_days($month, $year);

        // Set the starting day of the week
        $start_days = [
            'sunday'    => 0,
            'monday'    => 1,
            'tuesday'   => 2,
            'wednesday' => 3,
            'thursday'  => 4,
            'friday'    => 5,
            'saturday'  => 6,
        ];
        $start_day  = (!isset($start_days[$this->start_day])) ? 0 : $start_days[$this->start_day];

        // Set the starting day number
        $local_date = mktime(12, 0, 0, $month, 1, $year);
        $date       = getdate($local_date);
        $day        = $start_day + 1 - $date["wday"];

        while ($day > 1) {
            $day -= 7;
        }

        // Set the current month/year/day
        // We use this to determine the "today" date
        $cur_year  = date("Y", $this->local_time);
        $cur_month = date("m", $this->local_time);
        $cur_day   = date("j", $this->local_time);

        $is_current_month = ($cur_year == $year && $cur_month == $month) ? true : false;

        // Generate the template data array
        $this->parse_template();

        // Begin building the calendar output
        $out = $this->temp['table_open'];
        $out .= "\n";

        $out .= "\n";
        $out .= $this->temp['heading_row_start'];
        $out .= "\n";

        // "previous" month link
        if ($this->show_next_prev == true) {
            // Add a trailing slash to the  URL if needed
            $this->next_prev_url = preg_replace("/(.+?)\/*$/", "\\1/", $this->next_prev_url);

            $adjusted_date = $this->adjust_date($month - 1, $year);
            $out           .= str_replace('{previous_url}', $this->next_prev_url . $adjusted_date['year'] . '/' . $adjusted_date['month'], $this->temp['heading_previous_cell']);
            $out           .= "\n";
        }

        // Heading containing the month/year
        $colspan = ($this->show_next_prev == true) ? 5 : 7;

        $this->temp['heading_title_cell'] = str_replace('{colspan}', $colspan, $this->temp['heading_title_cell']);
        $this->temp['heading_title_cell'] = str_replace('{heading}', $this->get_month_name($month) . "&nbsp;" . $year, $this->temp['heading_title_cell']);

        $out .= $this->temp['heading_title_cell'];
        $out .= "\n";

        // "next" month link
        if ($this->show_next_prev == true) {
            $adjusted_date = $this->adjust_date($month + 1, $year);
            $out           .= str_replace('{next_url}', $this->next_prev_url . $adjusted_date['year'] . '/' . $adjusted_date['month'], $this->temp['heading_next_cell']);
        }

        $out .= "\n";
        $out .= $this->temp['heading_row_end'];
        $out .= "\n";

        // Write the cells containing the days of the week
        $out .= "\n";
        $out .= $this->temp['week_row_start'];
        $out .= "\n";

        $day_names = $this->get_day_names();

        for ($i = 0; $i < 7; $i++) {
            $out .= str_replace('{week_day}', $day_names[($start_day + $i) % 7], $this->temp['week_day_cell']);
        }

        $out .= "\n";
        $out .= $this->temp['week_row_end'];
        $out .= "\n";

        // Build the main body of the calendar
        while ($day <= $total_days) {
            $out .= "\n";
            $out .= $this->temp['cal_row_start'];
            $out .= "\n";

            for ($i = 0; $i < 7; $i++) {
                $out .= ($is_current_month == true && $day == $cur_day) ? $this->temp['cal_cell_start_today'] : $this->temp['cal_cell_start'];

                if ($day > 0 && $day <= $total_days) {

                    /* --------------------------------------------------------------------------
                     * Start of Shed modification.
                     * Making more information available to cells
                    /* ------------------------------------------------------------------------*/

                    if (isset($data[$day])) {
                        // Cells with content
                        $temp = ($is_current_month == true && $day == $cur_day) ? $this->temp['cal_cell_content_today'] : $this->temp['cal_cell_content'];
                        $temp = str_replace('{day}', $day, $temp);
                        $temp = str_replace('{day_padded}', str_pad($day, 2, '0', STR_PAD_LEFT), $temp);
                        $temp = str_replace('{month}', $month, $temp);
                        $temp = str_replace('{year}', $year, $temp);
                        $temp = str_replace('{content}', $data[$day], $temp);

                        $out .= $temp;
                    } else {
                        // Cells with no content
                        $temp = ($is_current_month == true && $day == $cur_day) ? $this->temp['cal_cell_no_content_today'] : $this->temp['cal_cell_no_content'];
                        $temp = str_replace('{day}', $day, $temp);
                        $temp = str_replace('{day_padded}', str_pad($day, 2, '0', STR_PAD_LEFT), $temp);
                        $temp = str_replace('{month}', $month, $temp);
                        $temp = str_replace('{year}', $year, $temp);

                        $out .= $temp;
                    }

                    /* --------------------------------------------------------------------------
                     * End of Shed modification.
                    /* ------------------------------------------------------------------------*/

                } else {
                    // Blank cells
                    $out .= $this->temp['cal_cell_blank'];
                }

                $out .= ($is_current_month == true && $day == $cur_day) ? $this->temp['cal_cell_end_today'] : $this->temp['cal_cell_end'];
                $day++;
            }

            $out .= "\n";
            $out .= $this->temp['cal_row_end'];
            $out .= "\n";
        }

        $out .= "\n";
        $out .= $this->temp['table_close'];

        return $out;
    }
573466
public static function nextMonth($month, $year)
    {
        if ($year >= 1970) {
            if ($month >= 12) {
                $nextMonth = 1;
                $yearMonth = $year + 1;
            } else {
                $nextMonth = $month + 1;
                $yearMonth = $year;
            }
        }

        return array('month' => $nextMonth, 'year' => $yearMonth);
    }
287915
function setMDY( $month, $day = 0, $year = 0 )
    {
        if ( $year != 0 )
            $date = mktime( 0, 0, 0, $month, $day, $year );
        else if ( $day != 0 )
            $date = mktime( 0, 0, 0, $month, $day );
        else
            $date = mktime( 0, 0, 0, $month );
        $this->Date = $date;
    }
542210
private static String getDaysInMonthBound(int year, int month) {
	    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
		cal.set(Calendar.YEAR, year);
	    cal.set(Calendar.MONTH, month);
		cal.set(Calendar.DAY_OF_MONTH, 1);
		return new Integer(cal.getActualMaximum(Calendar.DAY_OF_MONTH)).toString();
	}
1369263
public static function daysInMonth(int $month, int $year = null)
    {
        // Redefine vars
        $year   = ! empty($year) ? $year : (int) date('Y');

        if ($month < 1 or $month > 12) {
            return false;
        } elseif ($month == 2) {
            if ($year % 400 == 0 or ($year % 4 == 0 and $year % 100 != 0)) {
                return 29;
            }
        }

        $days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

        return $days_in_month[$month-1];
    }
526220
public void setDate(int year, int month, int day) {
        Calendar to = Calendar.getInstance();
        to.set(year, month, day);
        setDate(to);
    }
386969
private static function jdMonthNameCalendar(CalendarInterface $calendar, $julian_day, $months)
    {
        list(, $month) = $calendar->jdToYmd($julian_day);

        return $months[$month];
    }
875649
protected function generate()
    {
        if ($this->subperiodsProcessed) {
            return;
        }

        parent::generate();

        $date = $this->date;

        $startMonth = $date->setDay(1)->setTime('00:00:00');
        $endMonth   = $startMonth->addPeriod(1, 'month')->setDay(1)->subDay(1);

        $this->processOptimalSubperiods($startMonth, $endMonth);
    }
155345
public function setDate($year, $month, $day)
    {
      // Validate
      self::validateDate($year, $month, $day);
      
      // Set internal year, month and day variables
      $this->year  = (int)$year;
      $this->month = (int)$month;
      $this->day   = (int)$day;
    }
1090218
public function monthArray($begin, $end, $year = '')
    {
        if (empty($year)) {
            $year = date('Y');
        }
        $dateArray = array();
        for ($i = $begin; $i <= $end; ++$i) {
            $dateArray[] = $i;
        }
        return $dateArray;
    }
647424
protected function generate()
    {
        if ($this->subperiodsProcessed) {
            return;
        }

        parent::generate();

        $year = $this->date->toString("Y");
        for ($i = 1; $i <= 12; $i++) {
            $this->addSubperiod(new Month(
                    Date::factory("$year-$i-01")
                )
            );
        }
    }
1341541
function days_in_month($month = 0, $year = '') {
		if ($month < 1 || $month > 12) {
			$month = $this->mdate('m');
		}
		if (!is_numeric($year) || strlen($year) != 4) {
			$year = date('Y');
		}
		if ($month == 2) {
			if ($year % 400 == 0 || ($year % 4 == 0 && $year % 100 != 0)) {
				return 29;
			}
		}

		$days_in_month	= array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
		return $days_in_month[$month - 1];
	}
720481
function monthOfYear (dyear) {
  if (!monthOfYear.data) { // memoize yearly fractions per month
    monthOfYear.data = {0: [], 1: []}
    for (let m = 0; m <= 12; m++) {
      monthOfYear.data[0][m] = new Calendar(1999, m, 1).toYear() - 1999 // non leap year
      monthOfYear.data[1][m] = new Calendar(2000, m, 1).toYear() - 2000 // leap year
    }
  }
  const year = dyear | 0
  const f = dyear - year
  const d = LeapYearGregorian(year) ? 1 : 0
  const data = monthOfYear.data[d]

  let month = 12 // TODO loop could be improved
  while (month > 0 && data[month] > f) {
    month--
  }
  const first = year + data[month]
  const last = month < 11 ? year + data[month + 2] : year + 1 + data[(month + 2) % 12]
  return {year, month, first, last}
}
535752
public static function createGregorianDate($year = null, $month = null, $day = null, $timezone = null)
    {
        return static::createGregorian($year, $month, $day, null, null, null, $timezone);
    }
903137
function(year) {
			var date = this._validate(year, this.minMonth, this.minDay, $.calendars.local.invalidYear);
			year = date.year();
			if (typeof this.NEPALI_CALENDAR_DATA[year] === 'undefined') {
				return this.daysPerYear;
			}
			var daysPerYear = 0;
			for (var month_number = this.minMonth; month_number <= 12; month_number++) {
				daysPerYear += this.NEPALI_CALENDAR_DATA[year][month_number];
			}
			return daysPerYear;
		}
398189
public function generateObject($current)
	{
		$nodeCalendar = XmlUtil::CreateChild($current, "calendar", "");
				
		XmlUtil::AddAttribute($nodeCalendar, "name", "cal" . (rand(1000, 9999)) );
		XmlUtil::AddAttribute($nodeCalendar, "month", $this->_month);
		XmlUtil::AddAttribute($nodeCalendar, "year", $this->_year);
		XmlUtil::AddAttribute($nodeCalendar, "title", $this->_title);
		
		foreach($this->_events as $key=>$calendarEvent)
		{
			$calendarEvent->generateObject($nodeCalendar);
		}
	}
678633
public static function calToJd($calendar_id, $month, $day, $year)
    {
        switch ($calendar_id) {
            case CAL_FRENCH:
                return self::frenchToJd($month, $day, $year);

            case CAL_GREGORIAN:
                return self::gregorianToJd($month, $day, $year);

            case CAL_JEWISH:
                return self::jewishToJd($month, $day, $year);

            case CAL_JULIAN:
                return self::julianToJd($month, $day, $year);

            default:
                return trigger_error('invalid calendar ID ' . $calendar_id . '.', E_USER_WARNING);
        }
    }