예제 #1
0
    def generate_dates(self, num_dates=20):
        """
        Generate the first num_dates dates of the recurrence and return a list of datetimes
        """
        assert num_dates > 0

        self.pre_save_hooks()

        dates = []

        rule = self.get_rrule()

        try:
            d = rule[0]
            # Convert to time zone
            date_with_tz = fleming.attach_tz_if_none(d, self.time_zone)
            date_in_utc = fleming.convert_to_tz(date_with_tz, pytz.utc, True)
            dates.append(date_in_utc)

            for x in range(0, num_dates):
                d = rule.after(d)
                if not d:
                    break
                # Convert to time zone
                date_with_tz = fleming.attach_tz_if_none(d, self.time_zone)
                date_in_utc = fleming.convert_to_tz(date_with_tz, pytz.utc,
                                                    True)
                dates.append(date_in_utc)
        except Exception:  # pragma: no cover
            pass

        return dates
예제 #2
0
    def convert_to_utc(self, dt):
        """
        Treats the datetime object as being in the timezone of self.timezone and then converts it to utc timezone.
        :type dt: datetime
        """
        # Add timezone info
        dt = fleming.attach_tz_if_none(dt, self.time_zone)

        # Convert to utc
        dt = fleming.convert_to_tz(dt, pytz.utc, return_naive=True)

        return dt