Example #1
0
    def datetimeForYear(self, year):
        """
        Given a specific year, determine the actual date/time of the transition

        @param year:  the year to determine the transition for
        @type year: C{int}

        @return: C{tuple} of L{DateTime} and C{str} (which is the special
            tzdata mode character
        """
        # Create a floating date-time
        dt = DateTime()

        # Setup base year/month/day
        dt.setYear(year)
        dt.setMonth(Rule.MONTH_NAME_TO_POS[self.inMonth])
        dt.setDay(1)

        # Setup base hours/minutes
        splits = self.atTime.split(":")
        if len(splits) == 1:
            splits.append("0")
        assert len(splits) == 2, "atTime format is wrong: %s, %s" % (
            self.atTime,
            self,
        )
        hours = int(splits[0])
        if len(splits[1]) > 2:
            minutes = int(splits[1][:2])
            special = splits[1][2:]
        else:
            minutes = int(splits[1])
            special = ""

        # Special case for 24:00
        if hours == 24 and minutes == 0:
            dt.setHours(23)
            dt.setMinutes(59)
            dt.setSeconds(59)
        else:
            dt.setHours(hours)
            dt.setMinutes(minutes)

        # Now determine the actual start day
        if self.onDay in Rule.LASTDAY_NAME_TO_DAY:
            dt.setDayOfWeekInMonth(-1, Rule.LASTDAY_NAME_TO_DAY[self.onDay])
        elif self.onDay.find(">=") != -1:
            splits = self.onDay.split(">=")
            dt.setNextDayOfWeek(int(splits[1]),
                                Rule.DAY_NAME_TO_DAY[splits[0]])
        else:
            try:
                day = int(self.onDay)
                dt.setDay(day)
            except:
                assert False, "onDay value is not recognized: %s" % (
                    self.onDay, )

        return dt, special
Example #2
0
    def getUntilDate(self):

        if self._cached_until is None:
            year = 9999
            month = 12
            day = 1
            hours = 0
            minutes = 0
            seconds = 0
            mode = None
            if self.until and not self.until.startswith("#"):
                splits = self.until.split(" ")
                year = int(splits[0])
                month = 1
                day = 1
                hours = 0
                minutes = 0
                seconds = 0
                mode = None
                if len(splits) > 1 and not splits[1].startswith("#"):
                    month = int(rule.Rule.MONTH_NAME_TO_POS[splits[1]])
                    if len(splits) > 2 and not splits[2].startswith("#"):
                        if splits[2] == "lastSun":
                            dt = DateTime(year=year, month=month, day=1)
                            dt.setDayOfWeekInMonth(-1, DateTime.SUNDAY)
                            splits[2] = dt.getDay()
                        elif splits[2] == "lastSat":
                            dt = DateTime(year=year, month=month, day=1)
                            dt.setDayOfWeekInMonth(-1, DateTime.SATURDAY)
                            splits[2] = dt.getDay()
                        elif splits[2] == "Sun>=1":
                            dt = DateTime(year=year, month=month, day=1)
                            dt.setNextDayOfWeek(1, DateTime.SUNDAY)
                            splits[2] = dt.getDay()
                        elif splits[2] == "Sun>=8":
                            dt = DateTime(year=year, month=month, day=1)
                            dt.setNextDayOfWeek(8, DateTime.SUNDAY)
                            splits[2] = dt.getDay()
                        day = int(splits[2])
                        if len(splits) > 3 and not splits[3].startswith("#"):
                            splits = splits[3].split(":")
                            hours = int(splits[0])
                            minutes = int(splits[1][:2])
                            if len(splits[1]) > 2:
                                mode = splits[1][2:]
                            else:
                                mode = None
                            if len(splits) > 2:
                                seconds = int(splits[2])

            dt = DateTime(year=year,
                          month=month,
                          day=day,
                          hours=hours,
                          minutes=minutes,
                          seconds=seconds)
            self._cached_until = utils.DateTime(dt, mode)
        return self._cached_until
Example #3
0
    def datetimeForYear(self, year):
        """
        Given a specific year, determine the actual date/time of the transition

        @param year:  the year to determine the transition for
        @type year: C{int}

        @return: C{tuple} of L{DateTime} and C{str} (which is the special
            tzdata mode character
        """
        # Create a floating date-time
        dt = DateTime()

        # Setup base year/month/day
        dt.setYear(year)
        dt.setMonth(Rule.MONTH_NAME_TO_POS[self.inMonth])
        dt.setDay(1)

        # Setup base hours/minutes
        splits = self.atTime.split(":")
        if len(splits) == 1:
            splits.append("0")
        assert len(splits) == 2, "atTime format is wrong: %s, %s" % (self.atTime, self,)
        hours = int(splits[0])
        if len(splits[1]) > 2:
            minutes = int(splits[1][:2])
            special = splits[1][2:]
        else:
            minutes = int(splits[1])
            special = ""

        # Special case for 24:00
        if hours == 24 and minutes == 0:
            dt.setHours(23)
            dt.setMinutes(59)
            dt.setSeconds(59)
        else:
            dt.setHours(hours)
            dt.setMinutes(minutes)

        # Now determine the actual start day
        if self.onDay in Rule.LASTDAY_NAME_TO_DAY:
            dt.setDayOfWeekInMonth(-1, Rule.LASTDAY_NAME_TO_DAY[self.onDay])
        elif self.onDay.find(">=") != -1:
            splits = self.onDay.split(">=")
            dt.setNextDayOfWeek(int(splits[1]), Rule.DAY_NAME_TO_DAY[splits[0]])
        else:
            try:
                day = int(self.onDay)
                dt.setDay(day)
            except:
                assert False, "onDay value is not recognized: %s" % (self.onDay,)

        return dt, special