for yrs in range(2020, 2030):
for date in holidays.BD(years=yrs):
here this i get 10 years holiday in my country. how can I define these dates as holiday. here I define friday and saturday as holidays and now I want to define other holidays that means I get the holiday dates
for yrs in range(2020, 2030):
for date in holidays.BD(years=yrs):
from this function. how can I define these dates as holiday here is my code:
@api.depends("start_date", "date_deadline")
def _compute_hours(self):
for yrs in range(2020, 2030):
for date in holidays.BD(years=yrs):
# holiday_years = date.day
holiday = date
# print(date)
if self.start_date and self.date_deadline:
t1 = datetime.strptime(str(self.start_date), '%Y-%m-%d')
print(t1)
t2 = datetime.strptime(str(self.date_deadline), '%Y-%m-%d')
# holiday = datetime.strptime(str(date), '%Y-%m-%d')
print('=================================T2')
print(t2)
# if date:
# days = datetime.timedelta(days=5)
t3 = t2 - t1
delta = timedelta(days=1)
count = 0
while t1 <= t2:
print(t1.strftime("%Y-%m-%d"))
t1 += delta
if t1.weekday() in [5, 6]:
print('holiday')
count += 1
print("total holidays", count)
print('=================================T3')
print(t3)
print('=================================')
seconds = t3.total_seconds() / 3
diff_in_hours = seconds / 3600
print('Difference between two datetimes in hours:')
# print(diff_in_hours)
self.total_hours = diff_in_hours - (count * 8)