Skip to content

getBeginWeek() / getEndWeek() always see Sunday: Format('%w') returns "w" #520

Closed

Description

@caseysoftware

getBeginWeek() and getEndWeek() (includes/cleanup_functions.php ~L925–945, used by weekDates(), weekCells() and displayWeeks() and their _r variants for the tasks-per-user report) read the weekday with $d->Format('%w').

w2p_Utilities_Date::format() has no %w (#519), so it returns the string "w", (int) "w" is 0, and both functions treat every date as a Sunday:

function getBeginWeek($d)
{
    $dn = (int) $d->Format('%w');      // always 0
    $dd = new w2p_Utilities_Date($d);
    $dd->subtractSeconds($dn * 24 * 3600);   // never moves
    return (int) $dd->Format('%U');
}

getBeginWeek() therefore returns the date's own week instead of the week of the Sunday on or before it: for Wednesday 2026-10-21 it returns 43, while the Sunday before (2026-10-18) is in week 42. getEndWeek() happens to give the right week, because the Saturday after a date is in the same ISO week. The report's first week column can be off by one.

Fix: use (int) $d->getDayOfWeek() instead of Format('%w'). Also check what the report expects. %U maps to date('W') (ISO, Monday-start weeks), but these functions step to Sunday/Saturday, so the week numbering is mixed either way.

Activity

  1. added a commit that references this issue on Oct 24, 2026
    ad5fed9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions