Skip to Content
Menu
This question has been flagged
1024 Views

here how can I exclude countries holiday from selected date. here I added holidays.BD(years=[2022, 2023, 2024, 2025]).items(): for my countries holiday now I want to exclude these date from my selected date please help. I want to count total hour per day 8 hour working day and exclude my countries holiday. I exclude weekly 2 days holiday. now I want to exclude my countries holiday.

def _compute_hours(self):
for date in holidays.BD(years=[2022, 2023, 2024, 2025]).items():
print(str(date[0]))
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')
print('=================================T2')
print(t2)
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] and date.days():
print('holiday')
count += 1
print("total holidays", count)
# count = sum(1 for day in t3 if day.weekday() < 5)
# print(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)```
Avatar
Discard