Skip to content

Negative "week_of_month" Values #536

@ppremkumar

Description

@ppremkumar
  • 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

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