mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
MDL-84657 core_calendar: Initial deprecation of calendar_add_month
Signed-off-by: Daniel Ziegenberg <daniel@ziegenberg.at>
This commit is contained in:
parent
8cb5d000a1
commit
bf7abf4171
8
.upgradenotes/MDL-84657-2025022610485077.yml
Normal file
8
.upgradenotes/MDL-84657-2025022610485077.yml
Normal file
@ -0,0 +1,8 @@
|
||||
issueNumber: MDL-84657
|
||||
notes:
|
||||
core_calendar:
|
||||
- message: >-
|
||||
Initial deprecation of calendar_add_month(). Use
|
||||
\core_calendar\type_factory::get_calendar_instance()->get_next_month()
|
||||
instead.
|
||||
type: deprecated
|
@ -135,7 +135,7 @@ if(!empty($what) && !empty($time)) {
|
||||
$startmonth = $now['mon'];
|
||||
$startyear = $now['year'];
|
||||
if ($startmonthday > calendar_days_in_month($startmonth, $startyear)) {
|
||||
list($startmonth, $startyear) = calendar_add_month($startmonth, $startyear);
|
||||
[$startmonth, $startyear] = $calendartype->get_next_month($startyear, $startmonth);
|
||||
$startmonthday = find_day_in_month(1, $startweekday, $startmonth, $startyear);
|
||||
}
|
||||
$gregoriandate = $calendartype->convert_to_gregorian($startyear, $startmonth, $startmonthday);
|
||||
@ -146,7 +146,7 @@ if(!empty($what) && !empty($time)) {
|
||||
$endmonth = $startmonth;
|
||||
$endyear = $startyear;
|
||||
if ($endmonthday > calendar_days_in_month($endmonth, $endyear)) {
|
||||
list($endmonth, $endyear) = calendar_add_month($endmonth, $endyear);
|
||||
[$endmonth, $endyear] = $calendartype->get_next_month($endyear, $endmonth);
|
||||
$endmonthday = find_day_in_month(1, $startweekday, $endmonth, $endyear);
|
||||
}
|
||||
$gregoriandate = $calendartype->convert_to_gregorian($endyear, $endmonth, $endmonthday);
|
||||
@ -159,7 +159,7 @@ if(!empty($what) && !empty($time)) {
|
||||
$startmonth = $now['mon'];
|
||||
$startyear = $now['year'];
|
||||
if ($startmonthday > calendar_days_in_month($startmonth, $startyear)) {
|
||||
list($startmonth, $startyear) = calendar_add_month($startmonth, $startyear);
|
||||
[$startmonth, $startyear] = $calendartype->get_next_month($startyear, $startmonth);
|
||||
$startmonthday = find_day_in_month(1, $startweekday, $startmonth, $startyear);
|
||||
}
|
||||
$gregoriandate = $calendartype->convert_to_gregorian($startyear, $startmonth, $startmonthday);
|
||||
@ -170,7 +170,7 @@ if(!empty($what) && !empty($time)) {
|
||||
$endmonth = $startmonth;
|
||||
$endyear = $startyear;
|
||||
if ($endmonthday > calendar_days_in_month($endmonth, $endyear)) {
|
||||
list($endmonth, $endyear) = calendar_add_month($endmonth, $endyear);
|
||||
[$endmonth, $endyear] = $calendartype->get_next_month($endyear, $endmonth);
|
||||
$endmonthday = find_day_in_month(1, $startweekday, $endmonth, $endyear);
|
||||
}
|
||||
$gregoriandate = $calendartype->convert_to_gregorian($endyear, $endmonth, $endmonthday);
|
||||
@ -187,7 +187,7 @@ if(!empty($what) && !empty($time)) {
|
||||
break;
|
||||
case 'monthnext':
|
||||
// Get the next month for this calendar.
|
||||
list($nextmonth, $nextyear) = calendar_add_month($now['mon'], $now['year']);
|
||||
[$nextmonth, $nextyear] = $calendartype->get_next_month($now['year'], $now['mon']);
|
||||
|
||||
// Convert to gregorian.
|
||||
$gregoriandate = $calendartype->convert_to_gregorian($nextyear, $nextmonth, 1);
|
||||
|
@ -1843,18 +1843,6 @@ function calendar_days_in_month($month, $year) {
|
||||
return $calendartype->get_num_days_in_month($year, $month);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next following month.
|
||||
*
|
||||
* @param int $month the number of the month.
|
||||
* @param int $year the number of the year.
|
||||
* @return array the following month
|
||||
*/
|
||||
function calendar_add_month($month, $year) {
|
||||
$calendartype = \core_calendar\type_factory::get_calendar_instance();
|
||||
return $calendartype->get_next_month($year, $month);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the previous month.
|
||||
*
|
||||
|
@ -207,6 +207,11 @@ final class calendartype_test extends \advanced_testcase {
|
||||
$this->assertEquals($calendar->get_starting_weekday(), calendar_get_starting_weekday());
|
||||
$this->assertEquals($calendar->get_num_days_in_month('1986', '9'), calendar_days_in_month('9', '1986'));
|
||||
$this->assertEquals($calendar->get_next_month('1986', '9'), calendar_add_month('9', '1986'));
|
||||
$this->assertDebuggingCalled(
|
||||
'Deprecation: calendar_add_month has been deprecated since 5.0. ' .
|
||||
'Use \core_calendar\type_factory::get_calendar_instance()->get_next_month() instead. ' .
|
||||
'See MDL-84657 for more information.'
|
||||
);
|
||||
$this->assertEquals($calendar->get_prev_month('1986', '9'), calendar_sub_month('9', '1986'));
|
||||
|
||||
// Test the lib/moodle.php functions.
|
||||
|
@ -965,3 +965,24 @@ function check_igbinary322_version(environment_results $result) {
|
||||
\core\deprecation::emit_deprecation_if_present(__FUNCTION__);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next following month.
|
||||
*
|
||||
* @param int $month the number of the month.
|
||||
* @param int $year the number of the year.
|
||||
* @return array the following month
|
||||
*
|
||||
* @deprecated since 5.0 MDL-84657 Use \core_calendar\type_factory::get_calendar_instance()->get_prev_month() instead,
|
||||
* but pay regard to the order of arguments!
|
||||
* @todo MDL-84655 Remove this function in Moodle 6.0
|
||||
*/
|
||||
#[\core\attribute\deprecated(
|
||||
'\core_calendar\type_factory::get_calendar_instance()->get_next_month()',
|
||||
since: '5.0',
|
||||
mdl: 'MDL-84657'
|
||||
)]
|
||||
function calendar_add_month($month, $year) {
|
||||
\core\deprecation::emit_deprecation_if_present(__FUNCTION__);
|
||||
return \core_calendar\type_factory::get_calendar_instance()->get_next_month($year, $month);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user