Skip to content
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

Negative "week_of_month" Values #536

Closed
2 tasks
ppremkumar opened this issue Feb 25, 2021 · 0 comments · Fixed by #774
Closed
2 tasks

Negative "week_of_month" Values #536

ppremkumar opened this issue Feb 25, 2021 · 0 comments · Fixed by #774

Comments

@ppremkumar
Copy link

  • 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: Ubuntu 20.04.2 LTS
  • Pendulum version:

Issue

Try running this code. You will notice that week_of_month returns negative values.

import pendulum
from datetime import datetime
problematic_dates = ['2021-01-30 00:00:00',
'2021-01-29 00:00:00',
'2021-01-28 00:00:00',
'2021-01-27 00:00:00',
'2021-01-26 00:00:00',
'2021-01-25 00:00:00',
'2021-01-23 00:00:00',
'2021-01-22 00:00:00',
'2021-01-21 00:00:00',
'2021-01-20 00:00:00',
'2021-01-19 00:00:00',
'2021-01-18 00:00:00',
'2021-01-15 00:00:00',
'2021-01-14 00:00:00',
'2021-01-13 00:00:00',
'2021-01-12 00:00:00',
'2021-01-11 00:00:00',
'2021-01-09 00:00:00',
'2021-01-08 00:00:00',
'2021-01-07 00:00:00',
'2021-01-06 00:00:00',
'2021-01-05 00:00:00',
'2021-01-04 00:00:00',
'2019-12-31 00:00:00',
'2019-12-30 00:00:00']
for x in problematic_dates:
    x = datetime.strptime(x, '%Y-%m-%d %H:%M:%S')
    week_num_of_the_month = pendulum.parse((x.strftime('%Y') + x.strftime('%m') + x.strftime('%d'))).week_of_month
    print(f'{x}: {week_num_of_the_month}')

OUTPUT:

2021-01-30 00:00:00: -48
2021-01-29 00:00:00: -48
2021-01-28 00:00:00: -48
2021-01-27 00:00:00: -48
2021-01-26 00:00:00: -48
2021-01-25 00:00:00: -48
2021-01-23 00:00:00: -49
2021-01-22 00:00:00: -49
2021-01-21 00:00:00: -49
2021-01-20 00:00:00: -49
2021-01-19 00:00:00: -49
2021-01-18 00:00:00: -49
2021-01-15 00:00:00: -50
2021-01-14 00:00:00: -50
2021-01-13 00:00:00: -50
2021-01-12 00:00:00: -50
2021-01-11 00:00:00: -50
2021-01-09 00:00:00: -51
2021-01-08 00:00:00: -51
2021-01-07 00:00:00: -51
2021-01-06 00:00:00: -51
2021-01-05 00:00:00: -51
2021-01-04 00:00:00: -51
2019-12-31 00:00:00: -46
2019-12-30 00:00:00: -46
sdispater added a commit that referenced this issue Dec 14, 2023
sdispater added a commit that referenced this issue Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant