Skip to content

Will you accept a PR for week-based functions? #114

@bandtank

Description

@bandtank

Date libraries never have functions for weeks, which is a major pain point. If I submit a PR to add the following features, will you accept it?

public function getWeekStart(
    int $weekStart = 0,
    ?DateTimeInterface $date = null,
    ?DateTimeZone $timezone = null
) : DateTime

public function getWeekStartEnd(
    int $weekStart = 0,
    ?DateTimeInterface $date = null,
    ?DateTimeZone $timezone = null
) : array<DateTime>

getWeekStart: Get the first day of the week based on the date, timezone, and weekStart parameters.
getWeekStartEnd: The same as above, except two dates are returned - one for the start and one for the end of the week.

The weekStart value changes which day of the week is used as the first day.


A few examples:

#At the time of this comment, 'now' is 2024-08-27 20:09 UTC, which is a Tuesday
$date0 = getWeekStart();
$date1 = getWeekStart(1);
$date2 = getWeekStart(2);
$date3 = getWeekStart(3);
$date4 = getWeekStart(4);

$dt = new DateTime("2024-08-10");
$dates = getWeekStartEnd(0, $dt);
Results:
date0: 2024-08-25 00:00:00
date1: 2024-08-26 00:00:00
date2: 2024-08-27 00:00:00
date3: 2024-08-21 00:00:00
date4: 2024-08-22 00:00:00

dates['begin']: 2024-08-04 00:00:00
dates['end']: 2024-08-10 23:59:59

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions