django-recurrence icon indicating copy to clipboard operation
django-recurrence copied to clipboard

Using Rules

Open jlugao opened this issue 7 years ago • 1 comments

Hey,

I am trying to use this library programatically. I want to generate occurrences like follow: between 2017-01-01 and 2017-10-01 I want an occurrence every friday (or every sunday, etc..)

The problem is: how do I pass the weekday the occurence should occur? or do I always manage this through dt_start and have to implement a logic on my own to handle this?

currently my code is

     def get_recurrences(self):
         if self.tipo == 'D':
             myrule = recurrence.Rule(
                         recurrence.DAILY
                     )
         elif self.tipo == 'S':
             myrule = recurrence.Rule(
                         recurrence.WEEKLY
                     )
         else:
             raise TypeError("Tipo de Turma invalido")

         pattern = recurrence.Recurrence(
             dtstart=datetime.combine(self.dt_inicio, self.horario),
             dtend=datetime.combine(self.dt_fim, self.horario),
             rrules=[myrule, ]
         )
         return list( pattern.occurrences() )

Regards, João

jlugao avatar Jul 08 '17 21:07 jlugao

@jlugao A bit late, but you have to pass the weekday to your rule with byday like so:

myrule = recurrence.Rule( recurrence.WEEKLY, byday=recurrence.MONDAY )

denisiko avatar Oct 20 '17 10:10 denisiko