def test_finish_property(self):
     smidge = timedelta.resolution
     assert_equal(self.hour.finish,  make_datetime(1982, 8, 17, 7) - smidge)
     assert_equal(self.day.finish,   make_datetime(1982, 8, 18) - smidge)
     assert_equal(self.week.finish,  make_datetime(1982, 8, 23) - smidge)
     assert_equal(self.month.finish, make_datetime(1982, 9, 1) - smidge)
     assert_equal(self.year.finish,  make_datetime(1983, 1, 1) - smidge)
    def test_membership(self):
        for i in (self.hour, self.day, self.week, self.month, self.year):
            assert i in self.year
        for i in (self.hour, self.day, self.week, self.month):
            assert i in self.month
        for i in (self.hour, self.day, self.week):
            assert i in self.week
        for i in (self.hour, self.day,):
            assert i in self.day
        for i in (self.hour,):
            assert i in self.hour


        class TenMinuteInterval(Period):
            interval = timedelta(minutes=10)
            def convert(self, dt):
                dt = super(TenMinuteInterval, self).convert(dt)
                return dt.replace(second=0)

        ten_min_period = TenMinuteInterval(datetime(1982, 8, 17, 6, 30, 5))
        good_inputs = (
            make_datetime(1982, 8, 17, 6, 30),
            make_datetime(1982, 8, 17, 6, 35),
            make_datetime(1982, 8, 17, 6, 40) - timedelta.resolution,
        )
        bad_inputs = (
            date(1982, 8, 17),
            make_datetime(1982, 8, 17, 6, 30) - timedelta.resolution,
            make_datetime(1982, 8, 17, 6, 40),
        )
        for inp in good_inputs:
            assert_in(inp, ten_min_period)
        for inp in bad_inputs:
            assert_not_in(inp, ten_min_period)
 def setUp(self):
     translation.activate('en-gb')
     self.datetime = make_datetime(1982, 8, 17)   # Tuesday
     self.week = Week(self.datetime)
     self.expected = [
         make_datetime(1982, 8, 16),              # Monday
         make_datetime(1982, 8, 22)
     ]
 def test_default_datetimeproxy_conversion(self):
     mapping = (
         (date(1982, 8, 17), make_datetime(1982, 8, 17)),
         (datetime(1982, 8, 17, 6), make_datetime(1982, 8, 17, 6, 0, 0)),
         (datetime(1982, 8, 17, 6, 30), make_datetime(1982, 8, 17, 6, 30, 0)),
         (datetime(1982, 8, 17, 6, 30, 5), make_datetime(1982, 8, 17, 6, 30, 5)),
     )
     for inp, expected in mapping:
         assert_equal(Period(inp).start, expected)
Esempio n. 5
0
    def clean_until(self):
        until = self.cleaned_data["until"]

        if until is not None:
            until = make_datetime(until.year, until.month, until.day)

        return until
Esempio n. 6
0
    def __init__(self, event, *args, **kws):
        self.event = event
        self.request = kws.pop("request", None)
        self.user = getattr(self.request, "user", None)
        super(MultipleOccurrenceForm, self).__init__(*args, **kws)

        self.fields["calendar"].choices = (
            get_model(CALENDAR_APP_LABEL, "Calendar").objects.visible(self.user).values_list("id", "name")
        )

        dtstart = self.initial.get("dtstart", None)
        if dtstart:
            dtstart = dtstart.replace(
                minute=((dtstart.minute // MINUTES_INTERVAL) * MINUTES_INTERVAL), second=0, microsecond=0
            )

            weekday = dtstart.isoweekday()
            ordinal = dtstart.day // 7
            ordinal = u"%d" % (-1 if ordinal > 3 else ordinal + 1,)

            self.initial.setdefault("week_days", u"%d" % weekday)
            self.initial.setdefault("month_ordinal", ordinal)
            self.initial.setdefault("month_ordinal_day", u"%d" % weekday)
            self.initial.setdefault("each_month_day", [u"%d" % dtstart.day])
            self.initial.setdefault("year_months", [u"%d" % dtstart.month])
            self.initial.setdefault("year_month_ordinal", ordinal)
            self.initial.setdefault("year_month_ordinal_day", u"%d" % weekday)

            beginning = make_datetime(dtstart.year, dtstart.month, dtstart.day, tzinfo=dtstart.tzinfo)
            offset = (dtstart - beginning).seconds
            self.initial.setdefault("start_time_delta", u"%d" % offset)
            self.initial.setdefault("end_time_delta", u"%d" % (offset + SECONDS_INTERVAL,))
    def setUp(self):
        deactivate_default_occurrence_validators()
        translation.activate('en-gb')
        self.user = User.objects.create_user(
            'TestyMcTesterson',
            '*****@*****.**',
            'password'
        )
        self.calendar = Calendar.objects.create(name='Basic', slug='basic')
        self.event = Event.objects.create(
            name='The Test Event',
            slug='event-version-1',
            description="This is the description.",
            creator=self.user
        )
        self.start = make_datetime(1982, 8, 16)
        self.end_of_week = self.start + timedelta(7) - timedelta.resolution

        mapping = [
            (self.start, self.start + timedelta(hours=2)),
            (self.end_of_week, self.end_of_week + timedelta(hours=2)),
        ]
        for start, finish in mapping:
            Occurrence.objects.create(
                calendar=self.calendar,
                event=self.event,
                start=start,
                finish=finish
            )
        self.week = Week(self.start, occurrences=Occurrence.objects.all())
 def setUp(self):
     self.datetime = make_datetime(1982, 8, 17)
     self.period   = Period(self.datetime)
     self.year     = Year(self.datetime)
     self.month    = Month(self.datetime)
     self.week     = Week(self.datetime)
     self.day      = Day(self.datetime)
     self.hour     = Hour(self.datetime.replace(hour=6, minute=30, second=5))
     self.original_language = settings.LANGUAGE_CODE
Esempio n. 9
0
    def clean(self):
        self.check_for_required_fields()

        naive_day = self.cleaned_data["day"]
        day = make_datetime(naive_day.year, naive_day.month, naive_day.day)

        self.cleaned_data["start_time"] = day + timedelta(seconds=self.cleaned_data["start_time_delta"])
        self.cleaned_data["end_time"] = day + timedelta(seconds=self.cleaned_data["end_time_delta"])

        self.check_until_later_than_finish_datetime()
        log.debug("Recurrence-form, Cleaned Data\n%s" % (pformat(self.cleaned_data)))
        return self.cleaned_data
 def test_start_and_finish(self):
     assert_equal(self.trimonth.start, self.expected[0])
     expected = make_datetime(1982, 11, 1) - timedelta.resolution
     assert_equal(self.trimonth.finish.replace(tzinfo=None),
                  expected.replace(tzinfo=None))
 def setUp(self):
     self.datetime = datetime(1982, 8, 17)
     self.trimonth = TripleMonth(self.datetime)
     self.expected = [make_datetime(1982, 8, 1), make_datetime(1982, 9, 1),
                      make_datetime(1982, 10, 1)]
 def test_week_properties_usa(self):
     translation.activate('en-us')
     self.week = Week(datetime(1982, 8, 17))
     assert_equal(self.week.start, make_datetime(1982, 8, 15))
     assert_equal(self.week.finish, make_datetime(1982, 8, 22) -
                  timedelta.resolution)
 def test_week_properties(self):
     self.week = Week(datetime(1982, 8, 17))
     assert_equal(self.week.start, make_datetime(1982, 8, 16))
     assert_equal(self.week.finish, make_datetime(1982, 8, 23) -
                  timedelta.resolution)
 def test_start_property(self):
     assert_equal(self.hour.start,  make_datetime(1982, 8, 17, 6))
     assert_equal(self.day.start,   make_datetime(1982, 8, 17))
     assert_equal(self.week.start,  make_datetime(1982, 8, 16))
     assert_equal(self.month.start, make_datetime(1982, 8, 1))
     assert_equal(self.year.start,  make_datetime(1982, 1, 1))