Ejemplo n.º 1
0
    def test_getSchedulingRange(self):

        # scheduling range is 0:00 of timezone of first day
        # to the last day at 8:00 EST

        # test it in winter time
        dt = datetime(2010, 1, 1)
        days = 2
        expStart = datetime(2010, 1, 1, 0)
        expEnd   = datetime(2010, 1, 3, 13)
        expDur = TimeAgent.dtDiffMins(expStart, expEnd)

        start, dur = ScheduleTools().getSchedulingRange(dt, 'UTC', days)
        self.assertEquals(expStart, start)
        self.assertEquals(expDur, dur)

        # make sure it works in ET too
        expStart = datetime(2010, 1, 1, 5)
        expEnd   = datetime(2010, 1, 3, 13)
        expDur = TimeAgent.dtDiffMins(expStart, expEnd)

        start, dur = ScheduleTools().getSchedulingRange(dt, 'ET', days)
        self.assertEquals(expStart, start)

        # test it in summer time
        dt = datetime(2010, 6, 10)
        days = 3
        expStart = datetime(2010, 6, 10, 0)
        expEnd   = datetime(2010, 6, 13, 12)
        expDur = TimeAgent.dtDiffMins(expStart, expEnd)

        start, dur = ScheduleTools().getSchedulingRange(dt, 'UTC', days)
        self.assertEquals(expStart, start)
        self.assertEquals(expDur, dur)

        # make sure it works in ET too
        expStart = datetime(2010, 6, 10, 4)
        expEnd   = datetime(2010, 6, 13, 12)
        expDur = TimeAgent.dtDiffMins(expStart, expEnd)

        start, dur = ScheduleTools().getSchedulingRange(dt, 'ET', days)
        self.assertEquals(expStart, start)
        self.assertEquals(expDur, dur)
Ejemplo n.º 2
0
    def getSchedulingRange(self, firstDay, timezone, days):
        """
        Converts given time range (start dt, days) to 'scheduling range' 
        (start dt, minutes)
        """

        startHour = 0 if timezone == 'UTC' else self.getUTCHour(firstDay, 0)
        start = datetime(firstDay.year
                       , firstDay.month
                       , firstDay.day
                       , startHour
                        )

        lastDay = firstDay + timedelta(days = days)

        end   = datetime(lastDay.year
                       , lastDay.month
                       , lastDay.day
                       , self.getUTCHour(lastDay, self.schedulingEnd)
                        )

        duration = TimeAgent.dtDiffMins(end, start)

        return (start, duration)