def parse_vacation_data(name, start, end, note, condition_vacation): result = [None, None, note] if start: result = [str_to_date(start), str_to_date(end), note] else: result = condition_vacation(name, note) return result
def get_dates(self, start, end): start_date = dates.str_to_date(start) end_date = dates.str_to_date(end) result = [] num_days = (end_date - start_date).days + 1 for i in range(num_days): delta = datetime.timedelta(days=i) result.append(start_date + delta) return result
def expand_dates(self, dates_list): """ Given a list of vacation records, returns expanded dates. """ result = [] for v_range in dates_list: # We're pulling the start and end dates out of each vacation record. vac_dates = [dates.str_to_date(s) for s in v_range[1:3]] num_days = (vac_dates[1] - vac_dates[0]).days + 1 for i in range(num_days): delta = datetime.timedelta(days=i) result.append(vac_dates[0] + delta) return result
def get_vacations(self, track_staff, out_lines, my_dates): # TODO: Handle "All" case result = {} num_dates = len(my_dates) # Precompute date indices date_index = {} for i in range(num_dates): date_index[my_dates[i]] = i # Parse vacation data out vacations = {} for l in out_lines.split("\n"): [name, type, date_strings] = l.split("\t") # Create placeholders for each vacation type if not name in vacations: vacations[name] = [""] * num_dates for d in date_strings.split(":"): index = date_index[dates.str_to_date(d)] vacations[name][index] = type # Set all dates first (also specifying weekends) for name in track_staff: if not name in result: result[name] = [""] * num_dates for i in range(num_dates): if dates.is_weekend(my_dates[i]): result[name][i] = "weekend" # Override from 'All' if person's day is empty if "All" in vacations: for name in track_staff: for i in range(num_dates): if result[name][i] == "": result[name][i] = vacations["All"][i] # Override from parsed dates for name in track_staff: if name not in vacations: continue for i in range(num_dates): if vacations[name][i] != "": result[name][i] = vacations[name][i] return result
def str_to_type( str_, convert_types=True, inner_quotes=True, date_format=dt.DATE_DEFAULT_FMT, datetime_format=dt.DATETIME_DEFAULT_FMT, symbol_list=None): # Пытается привести строку к разным типам данных if convert_types: if str_.lower() == 'true': return True if str_.lower() == 'false': return False if str_ == 'None': return None if str_.isnumeric(): return int(str_) if str_.count('.') == 1 and str_.replace('.', '').isnumeric(): return float(str_) try: return dt.str_to_date(str_.strip('\''), date_format) except Exception: pass try: return dt.str_to_datetime(str_.strip('\''), datetime_format) except Exception: pass if is_quoted(str_): if inner_quotes: return QuotedString(str_.strip("'").replace('"', "'")) else: return QuotedString(str_.strip("'")) elif type(symbol_list) in (tuple, list) and str_ in symbol_list: return Symbol(str_) elif type(symbol_list) == str and str_ == symbol_list: return Symbol(str_) else: return UnConvString(str_) if inner_quotes: # удаляем концевые кавычки и подменяем внутренние двойные кавычки на одинарные, если стоит соотв. флаг return str_.strip('\'').replace('"', "'") else: # иначе просто удаляем концевые кавычки return str_.strip('\'')