#54132 closed defect (bug) (worksforme)
get_calendar functions depends on gmdate instead of date
Reported by: | voregnev | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Date/Time | Keywords: | |
Focuses: | Cc: |
Description
include/general-template.php
When we use get_calendar() - its generate wrong weeks breaks, because ancient function calendar_week_mod not depends on start day of week variable.
Change History (9)
#2
@
3 years ago
I found that the action of this function is related to the setting of the timezone on the hosting.
for example, run the following code
echo "\nTZ:".date_default_timezone_get()."\n";
$week_begins = 1;
$thismonth =11;
$thisyear = 2021;
$unixmonth = mktime( 0, 0, 0, $thismonth, 1, $thisyear );
$last_day = gmdate( 't', $unixmonth );
echo "GMUNIXMONTH".gmdate('d.m.Y',$unixmonth)."\n";
echo "UNIXMONTH".date('d.m.Y',$unixmonth)."\n";
echo "LASTDAY".$last_day."\n";
$dwgm = gmdate( 'w', $unixmonth );
echo "DW-GM".$dwgm;
echo "\nPAD-gm".calendar_week_mod($dwgm - $week_begins)."\n";
$dwd = date( 'w', $unixmonth );
echo "DW-DATE".$dwd;
echo "\nPAD-DATE".calendar_week_mod($dwd - $week_begins)."\n";
My output:
TZ:Europe/Moscow (GMT+3)
GMUNIXMONTH31.10.2021
UNIXMONTH01.11.2021
LASTDAY31
DW-GM0
PAD-gm6
DW-DATE1
PAD-DATE0
Seems we need use date instead gmdate for getting right pad
#3
@
3 years ago
- Component changed from General to Date/Time
- Keywords reporter-feedback removed
Thanks for the extra information.
#4
@
3 years ago
- Summary changed from Function calendar_week_mod should depends on week_begins to get_calendar functions depends on gmdate instead of date
#5
@
3 years ago
/wp-includes/general-template.php
@2271
<?php - $last_day = gmdate( 't', $unixmonth ); + $last_day = date( 't', $unixmonth );
#6
@
3 years ago
Hi there, thanks for the ticket!
Using gmdate()
is intentional as per [45424] / #46438 & #44491, see Date/Time component improvements in WordPress 5.3 for more details.
Using date()
instead would actually produce a WPCS error:
---------------------------------------------------------------------- FOUND 1 ERROR AFFECTING 1 LINE ---------------------------------------------------------------------- 2271 | ERROR | date() is affected by runtime timezone changes which | | can cause date/time to be incorrectly displayed. Use | | gmdate() instead. | | (WordPress.DateTime.RestrictedFunctions.date_date) ----------------------------------------------------------------------
There might still be a bug here where the timezone is not applied correctly, but I think the solution would look different.
#7
@
3 years ago
- Keywords reporter-feedback added
In my testing with the Europe/Moscow (GMT+3) timezone, get_calendar()
output does respect the "Week Starts On" setting as expected. I think the steps to reproduce the issue on a clean install would be helpful here, ideally with some screenshots, as it's not quite clear to me what the issue is.
Hi and welcome to Trac!
The
$week_begins
variable is used for all threecalendar_week_mod
calculations within theget_calendar
function:So I think the problem could be somewhere else. I did not have trouble changing the week's start day with the Calendar widget.
get_calendar
filter?get_calendar
directly in a theme template file (or a plugin)?