Exemplo n.º 1
0
    def print_day_stream(self, my_dates, output):
        print >> output, "=====dates"

        for cur_date in my_dates:
            print >> output, "\t%s\t%s" % (cur_date.strftime("%b\t%d\t%a"), str(dates.is_weekend(cur_date)).lower())

        return
Exemplo n.º 2
0
    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