Skip to content

weekday() is not consistent with constants #578

@btschr

Description

@btschr
  • I am on the latest Pendulum version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • OS version and name: Tested on Ubuntu 20.04 and Windows 10 with same results
  • Pendulum version: 2.1.2

Issue

The DateTime.weekday() function does not return values consistent with the weekday constants. Illustration below:

import pendulum
# create a test date (this date falls on a Sunday)
test_date = pendulum.DateTime(2021, 11, 7)

# confirm that this is indeed a Sunday:
print(f'{test_date:%A}')  
# output >> Sunday

# check if pendulum thinks its a Sunday (this FAILS)
print(test_date.weekday() == pendulum.SUNDAY) 
# output >> False

# for some reason, it thinks it's a Saturday
print(test_date.weekday() == pendulum.SATURDAY) 
# output >> True

Example output

I believe this is because .weekday() is inherited from datetime.datetime, which means the solution should either be:

  1. Create a pendulum.DateTime.weekday() override function that simply returns the .day_of_week property
  2. Add another set of constants like DT_MONDAY which corresponds with the datetime.datetime weekdays

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