def isholiday(timestamp): """check if date is a official holiday, høstferie, summer or christmas""" nor_holidays = holidays.Norway() if timestamp in nor_holidays: return True if timestamp.week in [41, 28, 52, 29, 30]: return True return False
def create_calendar_and_region_data(years_to_check, list_of_regions): """Returns a dictionary containing lists of equal length. The lists would have one row for each combination of year and region """ regions = [] dates = [] weekends = [] weekdays = [] red_days = [] norwegian_holidays = holidays.Norway() for year_to_check in years_to_check: # Set current date to 1. of december of the specified year current_date = date(year_to_check, 12, 1) # Continue until date is 15. of june the following year while current_date.month != 6 or current_date.day != 15: # Add data for each region for region in list_of_regions: regions.append(region) dates.append(current_date) if current_date.weekday() == 5 or current_date.weekday() == 6: weekends.append(1) else: weekends.append(0) weekdays.append(current_date.weekday() + 1) if current_date in norwegian_holidays and current_date.weekday( ) != 6: red_days.append(1) else: red_days.append(0) # Go to next day current_date = current_date + timedelta(days=1) # Return dectionary with all data return { 'region': regions, 'date': dates, 'weekday': weekdays, 'weekend': weekends, 'red_day': red_days, }
def check_additional(self, overtime, end_of_day): self.time_worked = self.end_time - self.start_time get_endtime = self.end_time.time() get_date = self.start_time.date() get_day = get_date.isoweekday() get_holidays = holidays.Norway(include_sundays=False) if self.time_worked > overtime: self.overtime = self.time_worked - overtime if get_endtime > end_of_day: if self.start_time.time() >= end_of_day: self.evening = self.time_worked else: self.evening = self.end_time - timezone.make_aware(datetime.combine(get_date, end_of_day)) if get_day == 6 or get_day == 7: self.weekend = self.time_worked if get_date in get_holidays: self.holiday = self.time_worked
def get_holidays(self): """ Holiday handling. Sets holiday effect to the interval of plus one day minus the days before that in the week. And adds a specific effect to the fellesferie mondays """ if self.country == "NO": hdays = holidays.Norway(years = range(2015,2021), include_sundays=False) if self.country == "SE": hdays = holidays.Sweden(years = range(2015,2021), include_sundays=False) hdays_array = [] for dates, name in hdays.items(): hdays_array.append([dates, name]) hdays_df = pd.DataFrame(hdays_array, columns=['ds', 'holiday']) hdays_df['lower_window'] = - hdays_df['ds'].apply(lambda x: x.weekday()) hdays_df['upper_window'] = 2 # Get fellesferie fellesferie_mondays = pd.DataFrame(columns=['ds', 'holiday']) i = 1 for year in hdays.years: print(date(year, 7, 1)) all_days = pd.date_range(start=date(year, 7, 1), end=date(year, 7, 31), freq='W-MON')[-3:] print(all_days) all_days_df = pd.DataFrame({'ds': all_days}) all_days_df['holiday'] = 'felles_'+(all_days_df.index+1).astype(str) fellesferie_mondays = pd.concat([fellesferie_mondays, all_days_df]) fellesferie_mondays['lower_window'] = 0 fellesferie_mondays['upper_window'] = 6 hdays_df = pd.concat([hdays_df, fellesferie_mondays]) return hdays_df
def setUp(self): self.holidays_without_sundays = holidays.Norway() self.holidays_with_sundays = holidays.Norway(include_sundays=True)
def date_is_holiday(date): if date in holidays.Norway(years=[date.year], include_sundays=False): return True return False
australia_holidays = holidays.Australia() austria_holidays = holidays.Austria() canada_holidays = holidays.Canada() colombia_holidays = holidays.Colombia() czech_holidays = holidays.Czech() denmark_holidays = holidays.Denmark() england_holidays = holidays.England() europeancentralbank_holidays = holidays.EuropeanCentralBank() germany_holidays = holidays.Germany() ireland_holidays = holidays.Ireland() mexico_holidays = holidays.Mexico() netherlands_holidays = holidays.Netherlands() newzealand_holidays = holidays.NewZealand() northernireland_holidays = holidays.NorthernIreland() norway_holidays = holidays.Norway() portugal_holidays = holidays.Portugal() portugalext_holidays = holidays.PortugalExt() scotland_holidays = holidays.Scotland() spain_holidays = holidays.Spain() unitedkingdom_holidays = holidays.UnitedKingdom() unitedstates_holidays = holidays.UnitedStates() wales_holidays = holidays.Wales() def isDateHoliday(date, countryHolidays): return date in country def isTodayHoliday(countryHolidays): return today in countryHolidays def whatIsTodaysHoliday(countryHolidays):