Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add isWeekend() and isWeekday() methods to DateTime classes #19734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
xentixar wants to merge 3 commits into php:master
base: master
Choose a base branch
Loading
from xentixar:add-weekend-and-weekday-methods-to-datetime-class

Conversation

Copy link

@xentixar xentixar commented Sep 6, 2025

This PR adds two new methods to DateTime and DateTimeImmutable classes:

  • isWeekend(): Checks if the date falls on a weekend (Saturday or Sunday)
  • isWeekday(): Checks if the date falls on a weekday (Monday through Friday)

The methods are also declared in DateTimeInterface, ensuring they're available across all implementing classes.

Implementation includes:

  • Helper functions in timelib library
  • Method implementations for DateTime and DateTimeImmutable
  • Proper interface declarations
  • Test cases for basic functionality and inheritance

These methods provide a convenient way to check if a date is a weekend or weekday without manually checking the day of week.

Copy link
Member

kamil-tekiela commented Sep 9, 2025
edited
Loading

Why do you consider the weekend to be Saturday and Sunday? Why not other days? How is this determined? see https://en.wikipedia.org/wiki/Workweek_and_weekend#History

skmedix and Girgias reacted with thumbs up emoji

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@devnexen devnexen devnexen left review comments

@kocsismate kocsismate Awaiting requested review from kocsismate kocsismate is a code owner

@derickr derickr Awaiting requested review from derickr derickr is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /