コード例 #1
0
    def transpose(self, other):
        """
            Expects a datetime object as argument,
            which will be transposed by a specified amount.
        """
        quarks = {}
        newMonth = False
        for i, unit in enumerate(self.units):
            if hasattr(other, unit) and self.values[i] !=0:
                quarks[unit] = (self.values[i] + getattr(other, unit))
                if i> 0 and quarks[unit] > self.modulo[i]:
                    quarks[unit] = quarks[unit] % self.modulo[i]
                    if self.units[i-1] in quarks:
                        quarks[self.units[i-1]] += 1
                    else:
                        quarks[self.units[i-1]] = getattr(other, self.units[i-1], 0) + 1
                    if unit == "day":
                        newMonth = True

        error = None
        for j in range(3):
            try:
                return other.replace(**quarks)
            except ValueError as e:
                if j > 2:
                    raise ValueError(e)
                quarks["day"] = quarks['day'] - 1 if 'day' in quarks else getattr(other, 'day', 0) - 1
                if not newMonth:
                    newMonth=True
                    quarks['month'] = quarks['month'] + 1 if 'month' in quarks else getattr(other, 'month', 0) + 1
コード例 #2
0
def _cook_slots(period, increment):
    """
        Prepare slots to be displayed on the left hand side
        calculate dimensions (in px) for each slot.
        Arguments:
        period - time period for the whole series
        increment - slot size in minutes
    """
    tdiff = datetime.timedelta(minutes=increment)
    num = int((period.end - period.start).total_seconds()) // int(tdiff.total_seconds())
    s = period.start
    slots = []
    for i in range(num):
        sl = period.get_time_slot(s, s + tdiff)
        slots.append(sl)
        s = s + tdiff
    return slots
コード例 #3
0
    from django.db.models.query import prefetch_related_objects

from django.utils.translation import ugettext
from django.utils.encoding import python_2_unicode_compatible
from django.template.defaultfilters import date as date_filter
from django.utils.dates import WEEKDAYS, WEEKDAYS_ABBR
from schedule.settings import SHOW_CANCELLED_OCCURRENCES
from schedule.models import Occurrence
from django.utils import timezone

weekday_names = []
weekday_abbrs = []

if settings.FIRST_DAY_OF_WEEK == 1:
    # The calendar week starts on Monday
    for i in range(7):
        weekday_names.append(WEEKDAYS[i])
        weekday_abbrs.append(WEEKDAYS_ABBR[i])
else:
    # The calendar week starts on Sunday, not Monday
    weekday_names.append(WEEKDAYS[6])
    weekday_abbrs.append(WEEKDAYS_ABBR[6])
    for i in range(6):
        weekday_names.append(WEEKDAYS[i])
        weekday_abbrs.append(WEEKDAYS_ABBR[i])


class Period(object):
    """
    This class represents a period of time. It can return a set of occurrences
    based on its events, and its time period (start and end).
コード例 #4
0
 def test_get_months(self):
     months = self.year.get_months()
     self.assertEqual([month.start for month in months], [
         datetime.datetime(2008, i, 1, tzinfo=pytz.utc)
         for i in range(1, 13)
     ])
コード例 #5
0
 def test_get_months(self):
     months = self.year.get_months()
     self.assertEqual([month.start for month in months],
         [datetime.datetime(2008, i, 1, tzinfo=pytz.utc) for i in range(1,13)])
コード例 #6
0
from django.conf import settings
from django.utils.translation import ugettext
from django.utils.encoding import python_2_unicode_compatible
from django.template.defaultfilters import date as date_filter
from django.utils.dates import WEEKDAYS, WEEKDAYS_ABBR
from schedule.conf.settings import SHOW_CANCELLED_OCCURRENCES
from schedule.models import Occurrence
from django.utils import timezone

weekday_names = []
weekday_abbrs = []

if settings.FIRST_DAY_OF_WEEK == 1:
    # The calendar week starts on Monday
    for i in range(7):
        weekday_names.append(WEEKDAYS[i])
        weekday_abbrs.append(WEEKDAYS_ABBR[i])
else:
    # The calendar week starts on Sunday, not Monday
    weekday_names.append(WEEKDAYS[6])
    weekday_abbrs.append(WEEKDAYS_ABBR[6])
    for i in range(6):
        weekday_names.append(WEEKDAYS[i])
        weekday_abbrs.append(WEEKDAYS_ABBR[i])


class Period(object):
    """
    This class represents a period of time. It can return a set of occurrences
    based on its events, and its time period (start and end).