在第N个月之后的每周一周

时间:2013-12-24 15:40:56

标签: python-dateutil rrule

在每年六月的第三个星期一之后写周二的最佳方法是什么?

目前我写这样的规则:

rule_mo = rrule(freq=YEARLY,              
            bymonth=6, 
            byweekday=MO(+3),
            ...)
rule = (x + relativedelta(weekday=TU(+1)) for x in rule_mo)

有没有办法只使用rrule编写整个规则,而不必使用relativedelta的第二遍?

1 个答案:

答案 0 :(得分:3)

参考:http://jkbr.github.io/rrule/

rule = RRule.fromText("every June on 3rd Tuesday")

rule.origOptions    
{
   freq: RRule.YEARLY,
   bymonth: [6],
   byweekday: [RRule.TU.nth(3)]
}

rule.toString()     

FREQ=YEARLY;BYMONTH=6;BYDAY=+3TU

rule.toText()   every June on the 3rd Tuesday