WordPress.org

Make WordPress Core

Opened 4 months ago

Last modified 2 months ago

#54132 new defect (bug)

Function calendar_week_mod should depends on week_begins

Reported by: voregnev Owned by:
Milestone: Awaiting Review 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 (3)

#1 @sabernhardt
4 months ago

  • Keywords reporter-feedback added

Hi and welcome to Trac!

The $week_begins variable is used for all three calendar_week_mod calculations within the get_calendar function:

$pad = calendar_week_mod( gmdate( 'w', $unixmonth ) - $week_begins );
if ( 6 == calendar_week_mod( gmdate( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins ) ) {
$pad = 7 - calendar_week_mod( gmdate( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins );

So I think the problem could be somewhere else. I did not have trouble changing the week's start day with the Calendar widget.

  • Is a plugin active that might edit the calendar output with the get_calendar filter?
  • Do you have the get_calendar directly in a theme template file (or a plugin)?
  • Could you upload a screenshot or add other details?
Last edited 4 months ago by sabernhardt (previous) (diff)

#2 @voregnev
2 months 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 @sabernhardt
2 months ago

  • Component changed from General to Date/Time
  • Keywords reporter-feedback removed

Thanks for the extra information.

Note: See TracTickets for help on using tickets.