fromdatetimeimportdatetime,timedeltaclassMondays():@staticmethoddefcount(birth:datetime,current_date:datetime):# For a more accurate deltatime in years use dateutil library with relativedelta instead, it supports leap years
end_working=birth+timedelta(days=78*365)start_working=birth+timedelta(days=22*365)ifcurrent_date>end_working:current_date=birth+end_workingfirst_monday=start_working+timedelta(days=(7-start_working.weekday())%7)last_monday=current_date-timedelta(days=current_date.weekday())days_between_mondays=(last_monday-first_monday).daysifdays_between_mondays>=7:returnint(days_between_mondays/7)return1ifnotcurrent_date.weekday()ornotstart_working.weekday()else0try:mondays=Mondays.count(datetime(1995,4,3),datetime(2017,4,3))print(mondays)exceptValueErrorasex:print(ex)try:mondays=Mondays.count(datetime(1995,4,2),datetime(2018,4,2))print(mondays)exceptValueErrorasex:print(ex)try:mondays=Mondays.count(datetime(1700,9,20),datetime(1762,9,26))print(mondays)exceptValueErrorasex:print(ex)try:mondays=Mondays.count(datetime(-300,12,20),datetime(-258,12,22))print(mondays)exceptValueErrorasex:print(ex)try:mondays=Mondays.count(datetime(1000000,2,25),datetime(1000022,12,28))print(mondays)exceptValueErrorasex:print(ex)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Python implementation