Beispiel #1
0
def schedule(args):
    '''
    Get convenient time slots to possibly contact the other person.
    '''

    reference = args.here_tz
    zipped_timeline = tuple(zip(U.timeline(args.here_tz, reference),
                                U.timeline(args.remote_tz, reference)))
    timeline_map = dict(zipped_timeline)

    def convenient(ht, rt):
        for a in args.dnd:
            if a.is_current(ht) and U.People.here in args.convenient_for:
                return False
            elif a.is_current(rt) and U.People.there in args.convenient_for:
                return False

        return True

    time_slots = U.grouped_time([
        ht
        for (ht, rt) in zipped_timeline
        if convenient(ht, rt)
    ])

    yield 'Convenient time slots:'
    for start, end, in time_slots:
        yield "\t{} to {} here i.e. {} to {} there".format(
            start.strftime("%R"), end.strftime("%R"),
            timeline_map[start].strftime("%R"), timeline_map[end].strftime("%R")
        )
Beispiel #2
0
    def test_grouped_time(self):
        half_hour = timedelta(minutes=30)
        base = utc.localize(
            datetime(year=2015, month=1, day=1, hour=7)
        )
        tl_deltas = [
            0,
            2, 3,
            5,
            7,
            9, 10, 11, 12,
            15
        ]

        range_deltas = [
            (0, 1),
            (2, 4),
            (5, 6),
            (7, 8),
            (9, 13),
            (15, 16)
        ]
        tl = [(base + half_hour * i) for i in tl_deltas]

        ranges = [
            (base + half_hour * i, base + half_hour * j)
            for i, j in range_deltas
        ]

        self.assertEqual(ranges, U.grouped_time(tl))