Beispiel #1
0
def test_issue_188_timezone_dropped():
    assert "DTSTART;TZID={tzid}:20200121T070000".format(tzid=Timezone.from_tzid("Europe/Berlin").tzid) in Calendar(fixture1).serialize()
    assert "DTSTART;TZID={tzid}:20200121T070000".format(tzid="W. Europe Standard Time") in Calendar(fixture2).serialize()
    assert "DTSTART;TZID={tzid}:20200121T070000".format(tzid="Europe/Berlin") in Calendar(fixture3).serialize()

    pacific = Timezone.from_tzid("US/Pacific")
    assert pacific.tzid.endswith("America/Los_Angeles")

    event1 = Event(begin=datetime(2014, 1, 1, 0, 0, 0, tzinfo=gettz("US/Pacific")))
    event1.dtstamp = event1.dtstamp.replace(microsecond=0)
    ser1 = Calendar(events=[event1]).serialize()
    assert "DTSTART:20140101T000000Z" not in ser1
    assert "DTSTART;TZID=%s:20140101T000000" % pacific.tzid in ser1

    event2 = event1.clone()
    event2.begin = datetime(2014, 1, 1, 0, 0, 0, tzinfo=pacific)
    ser2 = Calendar(events=[event1]).serialize()
    assert "DTSTART:20140101T000000Z" not in ser2
    assert "DTSTART;TZID=%s:20140101T000000" % pacific.tzid in ser2

    assert event1 == event2
    assert event1.begin == event2.begin
    assert event1.begin.tzinfo != event2.begin.tzinfo
    assert ser1 == ser2
    deser1 = Calendar(ser1).events[0]
    deser2 = Calendar(ser2).events[0]
    assert deser1 == deser2
    assert deser1 == event2
Beispiel #2
0
def matrix_to_ics(matrix_dict, group, begin, end, directory):
    c = Calendar()

    day, month, year = begin.split(" ")
    begin = "{} {} {}".format(day if int(day) > 9 else '0%s' % (day),
                              MONTHS[month], year)

    day, month, year = end.split(" ")
    end = "{} {} {}".format(day if int(day) > 9 else '0%s' % (day),
                            MONTHS[month], year)

    begin = arrow.get("{} {}".format(begin, HOURS[0]), 'DD MM YYYY HH:mm')
    end = arrow.get("{} {}".format(end, HOURS[-1]), 'DD MM YYYY HH:mm')

    # for each day of the week
    for i, day in enumerate(matrix_dict[group]):
        # for each course of the day
        for j, course in enumerate(day):

            if course:
                # get begin hour
                hour = int(HOURS[j].split(':')[0])
                minute = int(HOURS[j].split(':')[1])

                e = Event()

                e.name = course
                e.begin = begin.replace(hour=hour, minute=minute)
                e.end = e.begin.replace(hours=+1)

                c.events.append(e)

                while (e.begin <= end):
                    e = e.clone()

                    e.end = e.end.replace(days=+7)
                    e.begin = e.begin.replace(days=+7)
                    e.uid = uid_gen()

                    c.events.append(e)

        # next day
        begin = begin.replace(days=+1)

    holidays = convert_holidays()
    for event in c.events:
        for date in holidays:
            if str(event.begin.date()) == str(date):
                c.events.remove(event)

    if not os.path.exists("ics/" + directory):
        os.makedirs("ics/" + directory)

    with open('ics/{}/{}.ics'.format(directory, group), 'w') as f:
        f.writelines(c)
Beispiel #3
0
def matrix_to_ics(matrix_dict, group, begin, end, directory):
    c = Calendar()

    day, month, year = begin.split(" ")
    begin = "{} {} {}".format(day if int(day) > 9 else '0%s' % (day), MONTHS[month], year)

    day, month, year = end.split(" ")
    end = "{} {} {}".format(day if int(day) > 9 else '0%s' % (day), MONTHS[month], year)

    begin = arrow.get("{} {}".format(begin, HOURS[0]), 'DD MM YYYY HH:mm')
    end = arrow.get("{} {}".format(end, HOURS[-1]), 'DD MM YYYY HH:mm')

    # for each day of the week
    for i, day in enumerate(matrix_dict[group]):
        # for each course of the day
        for j, course in enumerate(day):

            if course:
                # get begin hour
                hour = int(HOURS[j].split(':')[0])
                minute = int(HOURS[j].split(':')[1])

                e = Event()

                e.name = course
                e.begin = begin.replace(hour=hour, minute=minute)
                e.end = e.begin.replace(hours=+1)

                c.events.append(e)

                while (e.begin <= end):
                    e = e.clone()

                    e.end = e.end.replace(days=+7)
                    e.begin = e.begin.replace(days=+7)
                    e.uid = uid_gen()

                    c.events.append(e)

        # next day
        begin = begin.replace(days=+1)

    holidays = convert_holidays()
    for event in c.events:
        for date in holidays:
            if str(event.begin.date()) == str(date):
                c.events.remove(event)

    if not os.path.exists("ics/" + directory):
        os.makedirs("ics/" + directory)

    with open('ics/{}/{}.ics'.format(directory, group), 'w') as f:
        f.writelines(c)
Beispiel #4
0
 def shift(event: Event):
     new_event = event.clone()
     new_event.end += datetime.timedelta(weeks=weeks)
     new_event.begin += datetime.timedelta(weeks=weeks)
     return new_event