Yes, in dateutil.relativedelta, MO, TU, etc. are weekday objects, not
strings (that's why you don't put them in quotes when passing them as
argument values). However, I believe the weekday argument to
relativedelta() can also be an integer from 0 to 6 (0 is Monday, etc.), so
maybe your byday field could store weekday integers instead of names.
Anthony
On Thursday, April 26, 2012 1:05:45 PM UTC-4, Annet wrote:
>
> Hi Anthony,
>
> Is byday just a string? If so, how could it have a "weekday" and an "n"
>> attribute?
>
>
> Yes, it is:
>
> Field('byday',length=2,default='',notnull=True,unique=True)
>
> From the python dateutil docs I learned that this:
>
> TODAY+relativedelta(weekday=FR)
>
> gives me next Friday's date.
>
> ... and this:
>
> TODAY+relativedelta(weekday=TH(+1))
>
> next Thursday, which is today.
>
> from exposing the code:
>
> nowdate=request.now.date()
> nowday=request.now.weekday()
> for row in session.oh_rows:
> if nowday==row.Day.id-1:
> row.OpeningHours.date=nowdate
> else:
> byday=row.Day.byday
> row.OpeningHours.date=nowdate+relativedelta(weekday=byday)
>
>
> ... I learned that FR and TH apparently aren't of type string. But I haven't
> been able to figure out how to pass row.day.byday to relativedelta()
> This: TODAY+relativedelta(weekday=FR) does work for everyday except TH which
> is today.
>
> | If so, how could it have a "weekday" and an "n" attribute?
>
> The string cannot have a weekday attribute, and it doesn't need an n
> attribute does it, because it's self.weekday.n or 1
>
>
> I hope I provided you with sufficient information to help me solve the
> problem.
> Kind regards,
>
> Annet
>
>
>
>
>
>
>
>
>