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

When leap the years ,There are something about the function of "week_of_month" #598

Closed
expressways opened this issue Jan 7, 2022 · 2 comments · Fixed by #774
Closed

Comments

@expressways
Copy link

the source:
@Property
def week_of_month(self):
first_day_of_month = self.replace(day=1)
return self.week_of_year - first_day_of_month.week_of_year + 1

the results eg.:

{'day_wid': '20211229', 'week_wid': '202152', 'week_code': 52, 'week_of_month': 5,}
{'day_wid': '20211230', 'week_wid': '202152', 'week_code': 52, 'week_of_month': 5,}
{'day_wid': '20211231', 'week_wid': '202152', 'week_code': 52, 'week_of_month': 5,}
{'day_wid': '20220101', 'week_wid': '202152', 'week_code': 52, 'week_of_month': 1,}
{'day_wid': '20220102', 'week_wid': '202152', 'week_code': 52, 'week_of_month': 1,}
{'day_wid': '20220103', 'week_wid': '202201', 'week_code': '01', 'week_of_month': -50,}
{'day_wid': '20220104', 'week_wid': '202201', 'week_code': '01', 'week_of_month': -50,}

Thanks🙌 ❤️

@expressways
Copy link
Author

Perhaps this will be fine:
@Property
def week_of_month(self):
first_day_of_month = self.replace(day=1)
# return self.week_of_year - first_day_of_month.week_of_year + 1
days = self.day + first_day_of_month.day_of_week-1
return math.ceil(days/7)

@za
Copy link
Contributor

za commented Feb 11, 2022

Hi @expressways what are you expecting? Can you elaborate more?

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.

2 participants