test_rrule.py 211 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. from datetime import datetime, date
  4. import unittest
  5. from six import PY2
  6. from dateutil import tz
  7. from dateutil.rrule import (
  8. rrule, rruleset, rrulestr,
  9. YEARLY, MONTHLY, WEEKLY, DAILY,
  10. HOURLY, MINUTELY, SECONDLY,
  11. MO, TU, WE, TH, FR, SA, SU
  12. )
  13. from freezegun import freeze_time
  14. import pytest
  15. @pytest.mark.rrule
  16. class RRuleTest(unittest.TestCase):
  17. def _rrulestr_reverse_test(self, rule):
  18. """
  19. Call with an `rrule` and it will test that `str(rrule)` generates a
  20. string which generates the same `rrule` as the input when passed to
  21. `rrulestr()`
  22. """
  23. rr_str = str(rule)
  24. rrulestr_rrule = rrulestr(rr_str)
  25. self.assertEqual(list(rule), list(rrulestr_rrule))
  26. def testStrAppendRRULEToken(self):
  27. # `_rrulestr_reverse_test` does not check if the "RRULE:" prefix
  28. # property is appended properly, so give it a dedicated test
  29. self.assertEqual(str(rrule(YEARLY,
  30. count=5,
  31. dtstart=datetime(1997, 9, 2, 9, 0))),
  32. "DTSTART:19970902T090000\n"
  33. "RRULE:FREQ=YEARLY;COUNT=5")
  34. rr_str = (
  35. 'DTSTART:19970105T083000\nRRULE:FREQ=YEARLY;INTERVAL=2'
  36. )
  37. self.assertEqual(str(rrulestr(rr_str)), rr_str)
  38. def testYearly(self):
  39. self.assertEqual(list(rrule(YEARLY,
  40. count=3,
  41. dtstart=datetime(1997, 9, 2, 9, 0))),
  42. [datetime(1997, 9, 2, 9, 0),
  43. datetime(1998, 9, 2, 9, 0),
  44. datetime(1999, 9, 2, 9, 0)])
  45. def testYearlyInterval(self):
  46. self.assertEqual(list(rrule(YEARLY,
  47. count=3,
  48. interval=2,
  49. dtstart=datetime(1997, 9, 2, 9, 0))),
  50. [datetime(1997, 9, 2, 9, 0),
  51. datetime(1999, 9, 2, 9, 0),
  52. datetime(2001, 9, 2, 9, 0)])
  53. def testYearlyIntervalLarge(self):
  54. self.assertEqual(list(rrule(YEARLY,
  55. count=3,
  56. interval=100,
  57. dtstart=datetime(1997, 9, 2, 9, 0))),
  58. [datetime(1997, 9, 2, 9, 0),
  59. datetime(2097, 9, 2, 9, 0),
  60. datetime(2197, 9, 2, 9, 0)])
  61. def testYearlyByMonth(self):
  62. self.assertEqual(list(rrule(YEARLY,
  63. count=3,
  64. bymonth=(1, 3),
  65. dtstart=datetime(1997, 9, 2, 9, 0))),
  66. [datetime(1998, 1, 2, 9, 0),
  67. datetime(1998, 3, 2, 9, 0),
  68. datetime(1999, 1, 2, 9, 0)])
  69. def testYearlyByMonthDay(self):
  70. self.assertEqual(list(rrule(YEARLY,
  71. count=3,
  72. bymonthday=(1, 3),
  73. dtstart=datetime(1997, 9, 2, 9, 0))),
  74. [datetime(1997, 9, 3, 9, 0),
  75. datetime(1997, 10, 1, 9, 0),
  76. datetime(1997, 10, 3, 9, 0)])
  77. def testYearlyByMonthAndMonthDay(self):
  78. self.assertEqual(list(rrule(YEARLY,
  79. count=3,
  80. bymonth=(1, 3),
  81. bymonthday=(5, 7),
  82. dtstart=datetime(1997, 9, 2, 9, 0))),
  83. [datetime(1998, 1, 5, 9, 0),
  84. datetime(1998, 1, 7, 9, 0),
  85. datetime(1998, 3, 5, 9, 0)])
  86. def testYearlyByWeekDay(self):
  87. self.assertEqual(list(rrule(YEARLY,
  88. count=3,
  89. byweekday=(TU, TH),
  90. dtstart=datetime(1997, 9, 2, 9, 0))),
  91. [datetime(1997, 9, 2, 9, 0),
  92. datetime(1997, 9, 4, 9, 0),
  93. datetime(1997, 9, 9, 9, 0)])
  94. def testYearlyByNWeekDay(self):
  95. self.assertEqual(list(rrule(YEARLY,
  96. count=3,
  97. byweekday=(TU(1), TH(-1)),
  98. dtstart=datetime(1997, 9, 2, 9, 0))),
  99. [datetime(1997, 12, 25, 9, 0),
  100. datetime(1998, 1, 6, 9, 0),
  101. datetime(1998, 12, 31, 9, 0)])
  102. def testYearlyByNWeekDayLarge(self):
  103. self.assertEqual(list(rrule(YEARLY,
  104. count=3,
  105. byweekday=(TU(3), TH(-3)),
  106. dtstart=datetime(1997, 9, 2, 9, 0))),
  107. [datetime(1997, 12, 11, 9, 0),
  108. datetime(1998, 1, 20, 9, 0),
  109. datetime(1998, 12, 17, 9, 0)])
  110. def testYearlyByMonthAndWeekDay(self):
  111. self.assertEqual(list(rrule(YEARLY,
  112. count=3,
  113. bymonth=(1, 3),
  114. byweekday=(TU, TH),
  115. dtstart=datetime(1997, 9, 2, 9, 0))),
  116. [datetime(1998, 1, 1, 9, 0),
  117. datetime(1998, 1, 6, 9, 0),
  118. datetime(1998, 1, 8, 9, 0)])
  119. def testYearlyByMonthAndNWeekDay(self):
  120. self.assertEqual(list(rrule(YEARLY,
  121. count=3,
  122. bymonth=(1, 3),
  123. byweekday=(TU(1), TH(-1)),
  124. dtstart=datetime(1997, 9, 2, 9, 0))),
  125. [datetime(1998, 1, 6, 9, 0),
  126. datetime(1998, 1, 29, 9, 0),
  127. datetime(1998, 3, 3, 9, 0)])
  128. def testYearlyByMonthAndNWeekDayLarge(self):
  129. # This is interesting because the TH(-3) ends up before
  130. # the TU(3).
  131. self.assertEqual(list(rrule(YEARLY,
  132. count=3,
  133. bymonth=(1, 3),
  134. byweekday=(TU(3), TH(-3)),
  135. dtstart=datetime(1997, 9, 2, 9, 0))),
  136. [datetime(1998, 1, 15, 9, 0),
  137. datetime(1998, 1, 20, 9, 0),
  138. datetime(1998, 3, 12, 9, 0)])
  139. def testYearlyByMonthDayAndWeekDay(self):
  140. self.assertEqual(list(rrule(YEARLY,
  141. count=3,
  142. bymonthday=(1, 3),
  143. byweekday=(TU, TH),
  144. dtstart=datetime(1997, 9, 2, 9, 0))),
  145. [datetime(1998, 1, 1, 9, 0),
  146. datetime(1998, 2, 3, 9, 0),
  147. datetime(1998, 3, 3, 9, 0)])
  148. def testYearlyByMonthAndMonthDayAndWeekDay(self):
  149. self.assertEqual(list(rrule(YEARLY,
  150. count=3,
  151. bymonth=(1, 3),
  152. bymonthday=(1, 3),
  153. byweekday=(TU, TH),
  154. dtstart=datetime(1997, 9, 2, 9, 0))),
  155. [datetime(1998, 1, 1, 9, 0),
  156. datetime(1998, 3, 3, 9, 0),
  157. datetime(2001, 3, 1, 9, 0)])
  158. def testYearlyByYearDay(self):
  159. self.assertEqual(list(rrule(YEARLY,
  160. count=4,
  161. byyearday=(1, 100, 200, 365),
  162. dtstart=datetime(1997, 9, 2, 9, 0))),
  163. [datetime(1997, 12, 31, 9, 0),
  164. datetime(1998, 1, 1, 9, 0),
  165. datetime(1998, 4, 10, 9, 0),
  166. datetime(1998, 7, 19, 9, 0)])
  167. def testYearlyByYearDayNeg(self):
  168. self.assertEqual(list(rrule(YEARLY,
  169. count=4,
  170. byyearday=(-365, -266, -166, -1),
  171. dtstart=datetime(1997, 9, 2, 9, 0))),
  172. [datetime(1997, 12, 31, 9, 0),
  173. datetime(1998, 1, 1, 9, 0),
  174. datetime(1998, 4, 10, 9, 0),
  175. datetime(1998, 7, 19, 9, 0)])
  176. def testYearlyByMonthAndYearDay(self):
  177. self.assertEqual(list(rrule(YEARLY,
  178. count=4,
  179. bymonth=(4, 7),
  180. byyearday=(1, 100, 200, 365),
  181. dtstart=datetime(1997, 9, 2, 9, 0))),
  182. [datetime(1998, 4, 10, 9, 0),
  183. datetime(1998, 7, 19, 9, 0),
  184. datetime(1999, 4, 10, 9, 0),
  185. datetime(1999, 7, 19, 9, 0)])
  186. def testYearlyByMonthAndYearDayNeg(self):
  187. self.assertEqual(list(rrule(YEARLY,
  188. count=4,
  189. bymonth=(4, 7),
  190. byyearday=(-365, -266, -166, -1),
  191. dtstart=datetime(1997, 9, 2, 9, 0))),
  192. [datetime(1998, 4, 10, 9, 0),
  193. datetime(1998, 7, 19, 9, 0),
  194. datetime(1999, 4, 10, 9, 0),
  195. datetime(1999, 7, 19, 9, 0)])
  196. def testYearlyByWeekNo(self):
  197. self.assertEqual(list(rrule(YEARLY,
  198. count=3,
  199. byweekno=20,
  200. dtstart=datetime(1997, 9, 2, 9, 0))),
  201. [datetime(1998, 5, 11, 9, 0),
  202. datetime(1998, 5, 12, 9, 0),
  203. datetime(1998, 5, 13, 9, 0)])
  204. def testYearlyByWeekNoAndWeekDay(self):
  205. # That's a nice one. The first days of week number one
  206. # may be in the last year.
  207. self.assertEqual(list(rrule(YEARLY,
  208. count=3,
  209. byweekno=1,
  210. byweekday=MO,
  211. dtstart=datetime(1997, 9, 2, 9, 0))),
  212. [datetime(1997, 12, 29, 9, 0),
  213. datetime(1999, 1, 4, 9, 0),
  214. datetime(2000, 1, 3, 9, 0)])
  215. def testYearlyByWeekNoAndWeekDayLarge(self):
  216. # Another nice test. The last days of week number 52/53
  217. # may be in the next year.
  218. self.assertEqual(list(rrule(YEARLY,
  219. count=3,
  220. byweekno=52,
  221. byweekday=SU,
  222. dtstart=datetime(1997, 9, 2, 9, 0))),
  223. [datetime(1997, 12, 28, 9, 0),
  224. datetime(1998, 12, 27, 9, 0),
  225. datetime(2000, 1, 2, 9, 0)])
  226. def testYearlyByWeekNoAndWeekDayLast(self):
  227. self.assertEqual(list(rrule(YEARLY,
  228. count=3,
  229. byweekno=-1,
  230. byweekday=SU,
  231. dtstart=datetime(1997, 9, 2, 9, 0))),
  232. [datetime(1997, 12, 28, 9, 0),
  233. datetime(1999, 1, 3, 9, 0),
  234. datetime(2000, 1, 2, 9, 0)])
  235. def testYearlyByEaster(self):
  236. self.assertEqual(list(rrule(YEARLY,
  237. count=3,
  238. byeaster=0,
  239. dtstart=datetime(1997, 9, 2, 9, 0))),
  240. [datetime(1998, 4, 12, 9, 0),
  241. datetime(1999, 4, 4, 9, 0),
  242. datetime(2000, 4, 23, 9, 0)])
  243. def testYearlyByEasterPos(self):
  244. self.assertEqual(list(rrule(YEARLY,
  245. count=3,
  246. byeaster=1,
  247. dtstart=datetime(1997, 9, 2, 9, 0))),
  248. [datetime(1998, 4, 13, 9, 0),
  249. datetime(1999, 4, 5, 9, 0),
  250. datetime(2000, 4, 24, 9, 0)])
  251. def testYearlyByEasterNeg(self):
  252. self.assertEqual(list(rrule(YEARLY,
  253. count=3,
  254. byeaster=-1,
  255. dtstart=datetime(1997, 9, 2, 9, 0))),
  256. [datetime(1998, 4, 11, 9, 0),
  257. datetime(1999, 4, 3, 9, 0),
  258. datetime(2000, 4, 22, 9, 0)])
  259. def testYearlyByWeekNoAndWeekDay53(self):
  260. self.assertEqual(list(rrule(YEARLY,
  261. count=3,
  262. byweekno=53,
  263. byweekday=MO,
  264. dtstart=datetime(1997, 9, 2, 9, 0))),
  265. [datetime(1998, 12, 28, 9, 0),
  266. datetime(2004, 12, 27, 9, 0),
  267. datetime(2009, 12, 28, 9, 0)])
  268. def testYearlyByHour(self):
  269. self.assertEqual(list(rrule(YEARLY,
  270. count=3,
  271. byhour=(6, 18),
  272. dtstart=datetime(1997, 9, 2, 9, 0))),
  273. [datetime(1997, 9, 2, 18, 0),
  274. datetime(1998, 9, 2, 6, 0),
  275. datetime(1998, 9, 2, 18, 0)])
  276. def testYearlyByMinute(self):
  277. self.assertEqual(list(rrule(YEARLY,
  278. count=3,
  279. byminute=(6, 18),
  280. dtstart=datetime(1997, 9, 2, 9, 0))),
  281. [datetime(1997, 9, 2, 9, 6),
  282. datetime(1997, 9, 2, 9, 18),
  283. datetime(1998, 9, 2, 9, 6)])
  284. def testYearlyBySecond(self):
  285. self.assertEqual(list(rrule(YEARLY,
  286. count=3,
  287. bysecond=(6, 18),
  288. dtstart=datetime(1997, 9, 2, 9, 0))),
  289. [datetime(1997, 9, 2, 9, 0, 6),
  290. datetime(1997, 9, 2, 9, 0, 18),
  291. datetime(1998, 9, 2, 9, 0, 6)])
  292. def testYearlyByHourAndMinute(self):
  293. self.assertEqual(list(rrule(YEARLY,
  294. count=3,
  295. byhour=(6, 18),
  296. byminute=(6, 18),
  297. dtstart=datetime(1997, 9, 2, 9, 0))),
  298. [datetime(1997, 9, 2, 18, 6),
  299. datetime(1997, 9, 2, 18, 18),
  300. datetime(1998, 9, 2, 6, 6)])
  301. def testYearlyByHourAndSecond(self):
  302. self.assertEqual(list(rrule(YEARLY,
  303. count=3,
  304. byhour=(6, 18),
  305. bysecond=(6, 18),
  306. dtstart=datetime(1997, 9, 2, 9, 0))),
  307. [datetime(1997, 9, 2, 18, 0, 6),
  308. datetime(1997, 9, 2, 18, 0, 18),
  309. datetime(1998, 9, 2, 6, 0, 6)])
  310. def testYearlyByMinuteAndSecond(self):
  311. self.assertEqual(list(rrule(YEARLY,
  312. count=3,
  313. byminute=(6, 18),
  314. bysecond=(6, 18),
  315. dtstart=datetime(1997, 9, 2, 9, 0))),
  316. [datetime(1997, 9, 2, 9, 6, 6),
  317. datetime(1997, 9, 2, 9, 6, 18),
  318. datetime(1997, 9, 2, 9, 18, 6)])
  319. def testYearlyByHourAndMinuteAndSecond(self):
  320. self.assertEqual(list(rrule(YEARLY,
  321. count=3,
  322. byhour=(6, 18),
  323. byminute=(6, 18),
  324. bysecond=(6, 18),
  325. dtstart=datetime(1997, 9, 2, 9, 0))),
  326. [datetime(1997, 9, 2, 18, 6, 6),
  327. datetime(1997, 9, 2, 18, 6, 18),
  328. datetime(1997, 9, 2, 18, 18, 6)])
  329. def testYearlyBySetPos(self):
  330. self.assertEqual(list(rrule(YEARLY,
  331. count=3,
  332. bymonthday=15,
  333. byhour=(6, 18),
  334. bysetpos=(3, -3),
  335. dtstart=datetime(1997, 9, 2, 9, 0))),
  336. [datetime(1997, 11, 15, 18, 0),
  337. datetime(1998, 2, 15, 6, 0),
  338. datetime(1998, 11, 15, 18, 0)])
  339. def testMonthly(self):
  340. self.assertEqual(list(rrule(MONTHLY,
  341. count=3,
  342. dtstart=datetime(1997, 9, 2, 9, 0))),
  343. [datetime(1997, 9, 2, 9, 0),
  344. datetime(1997, 10, 2, 9, 0),
  345. datetime(1997, 11, 2, 9, 0)])
  346. def testMonthlyInterval(self):
  347. self.assertEqual(list(rrule(MONTHLY,
  348. count=3,
  349. interval=2,
  350. dtstart=datetime(1997, 9, 2, 9, 0))),
  351. [datetime(1997, 9, 2, 9, 0),
  352. datetime(1997, 11, 2, 9, 0),
  353. datetime(1998, 1, 2, 9, 0)])
  354. def testMonthlyIntervalLarge(self):
  355. self.assertEqual(list(rrule(MONTHLY,
  356. count=3,
  357. interval=18,
  358. dtstart=datetime(1997, 9, 2, 9, 0))),
  359. [datetime(1997, 9, 2, 9, 0),
  360. datetime(1999, 3, 2, 9, 0),
  361. datetime(2000, 9, 2, 9, 0)])
  362. def testMonthlyByMonth(self):
  363. self.assertEqual(list(rrule(MONTHLY,
  364. count=3,
  365. bymonth=(1, 3),
  366. dtstart=datetime(1997, 9, 2, 9, 0))),
  367. [datetime(1998, 1, 2, 9, 0),
  368. datetime(1998, 3, 2, 9, 0),
  369. datetime(1999, 1, 2, 9, 0)])
  370. def testMonthlyByMonthDay(self):
  371. self.assertEqual(list(rrule(MONTHLY,
  372. count=3,
  373. bymonthday=(1, 3),
  374. dtstart=datetime(1997, 9, 2, 9, 0))),
  375. [datetime(1997, 9, 3, 9, 0),
  376. datetime(1997, 10, 1, 9, 0),
  377. datetime(1997, 10, 3, 9, 0)])
  378. def testMonthlyByMonthAndMonthDay(self):
  379. self.assertEqual(list(rrule(MONTHLY,
  380. count=3,
  381. bymonth=(1, 3),
  382. bymonthday=(5, 7),
  383. dtstart=datetime(1997, 9, 2, 9, 0))),
  384. [datetime(1998, 1, 5, 9, 0),
  385. datetime(1998, 1, 7, 9, 0),
  386. datetime(1998, 3, 5, 9, 0)])
  387. def testMonthlyByWeekDay(self):
  388. self.assertEqual(list(rrule(MONTHLY,
  389. count=3,
  390. byweekday=(TU, TH),
  391. dtstart=datetime(1997, 9, 2, 9, 0))),
  392. [datetime(1997, 9, 2, 9, 0),
  393. datetime(1997, 9, 4, 9, 0),
  394. datetime(1997, 9, 9, 9, 0)])
  395. # Third Monday of the month
  396. self.assertEqual(rrule(MONTHLY,
  397. byweekday=(MO(+3)),
  398. dtstart=datetime(1997, 9, 1)).between(datetime(1997, 9, 1),
  399. datetime(1997, 12, 1)),
  400. [datetime(1997, 9, 15, 0, 0),
  401. datetime(1997, 10, 20, 0, 0),
  402. datetime(1997, 11, 17, 0, 0)])
  403. def testMonthlyByNWeekDay(self):
  404. self.assertEqual(list(rrule(MONTHLY,
  405. count=3,
  406. byweekday=(TU(1), TH(-1)),
  407. dtstart=datetime(1997, 9, 2, 9, 0))),
  408. [datetime(1997, 9, 2, 9, 0),
  409. datetime(1997, 9, 25, 9, 0),
  410. datetime(1997, 10, 7, 9, 0)])
  411. def testMonthlyByNWeekDayLarge(self):
  412. self.assertEqual(list(rrule(MONTHLY,
  413. count=3,
  414. byweekday=(TU(3), TH(-3)),
  415. dtstart=datetime(1997, 9, 2, 9, 0))),
  416. [datetime(1997, 9, 11, 9, 0),
  417. datetime(1997, 9, 16, 9, 0),
  418. datetime(1997, 10, 16, 9, 0)])
  419. def testMonthlyByMonthAndWeekDay(self):
  420. self.assertEqual(list(rrule(MONTHLY,
  421. count=3,
  422. bymonth=(1, 3),
  423. byweekday=(TU, TH),
  424. dtstart=datetime(1997, 9, 2, 9, 0))),
  425. [datetime(1998, 1, 1, 9, 0),
  426. datetime(1998, 1, 6, 9, 0),
  427. datetime(1998, 1, 8, 9, 0)])
  428. def testMonthlyByMonthAndNWeekDay(self):
  429. self.assertEqual(list(rrule(MONTHLY,
  430. count=3,
  431. bymonth=(1, 3),
  432. byweekday=(TU(1), TH(-1)),
  433. dtstart=datetime(1997, 9, 2, 9, 0))),
  434. [datetime(1998, 1, 6, 9, 0),
  435. datetime(1998, 1, 29, 9, 0),
  436. datetime(1998, 3, 3, 9, 0)])
  437. def testMonthlyByMonthAndNWeekDayLarge(self):
  438. self.assertEqual(list(rrule(MONTHLY,
  439. count=3,
  440. bymonth=(1, 3),
  441. byweekday=(TU(3), TH(-3)),
  442. dtstart=datetime(1997, 9, 2, 9, 0))),
  443. [datetime(1998, 1, 15, 9, 0),
  444. datetime(1998, 1, 20, 9, 0),
  445. datetime(1998, 3, 12, 9, 0)])
  446. def testMonthlyByMonthDayAndWeekDay(self):
  447. self.assertEqual(list(rrule(MONTHLY,
  448. count=3,
  449. bymonthday=(1, 3),
  450. byweekday=(TU, TH),
  451. dtstart=datetime(1997, 9, 2, 9, 0))),
  452. [datetime(1998, 1, 1, 9, 0),
  453. datetime(1998, 2, 3, 9, 0),
  454. datetime(1998, 3, 3, 9, 0)])
  455. def testMonthlyByMonthAndMonthDayAndWeekDay(self):
  456. self.assertEqual(list(rrule(MONTHLY,
  457. count=3,
  458. bymonth=(1, 3),
  459. bymonthday=(1, 3),
  460. byweekday=(TU, TH),
  461. dtstart=datetime(1997, 9, 2, 9, 0))),
  462. [datetime(1998, 1, 1, 9, 0),
  463. datetime(1998, 3, 3, 9, 0),
  464. datetime(2001, 3, 1, 9, 0)])
  465. def testMonthlyByYearDay(self):
  466. self.assertEqual(list(rrule(MONTHLY,
  467. count=4,
  468. byyearday=(1, 100, 200, 365),
  469. dtstart=datetime(1997, 9, 2, 9, 0))),
  470. [datetime(1997, 12, 31, 9, 0),
  471. datetime(1998, 1, 1, 9, 0),
  472. datetime(1998, 4, 10, 9, 0),
  473. datetime(1998, 7, 19, 9, 0)])
  474. def testMonthlyByYearDayNeg(self):
  475. self.assertEqual(list(rrule(MONTHLY,
  476. count=4,
  477. byyearday=(-365, -266, -166, -1),
  478. dtstart=datetime(1997, 9, 2, 9, 0))),
  479. [datetime(1997, 12, 31, 9, 0),
  480. datetime(1998, 1, 1, 9, 0),
  481. datetime(1998, 4, 10, 9, 0),
  482. datetime(1998, 7, 19, 9, 0)])
  483. def testMonthlyByMonthAndYearDay(self):
  484. self.assertEqual(list(rrule(MONTHLY,
  485. count=4,
  486. bymonth=(4, 7),
  487. byyearday=(1, 100, 200, 365),
  488. dtstart=datetime(1997, 9, 2, 9, 0))),
  489. [datetime(1998, 4, 10, 9, 0),
  490. datetime(1998, 7, 19, 9, 0),
  491. datetime(1999, 4, 10, 9, 0),
  492. datetime(1999, 7, 19, 9, 0)])
  493. def testMonthlyByMonthAndYearDayNeg(self):
  494. self.assertEqual(list(rrule(MONTHLY,
  495. count=4,
  496. bymonth=(4, 7),
  497. byyearday=(-365, -266, -166, -1),
  498. dtstart=datetime(1997, 9, 2, 9, 0))),
  499. [datetime(1998, 4, 10, 9, 0),
  500. datetime(1998, 7, 19, 9, 0),
  501. datetime(1999, 4, 10, 9, 0),
  502. datetime(1999, 7, 19, 9, 0)])
  503. def testMonthlyByWeekNo(self):
  504. self.assertEqual(list(rrule(MONTHLY,
  505. count=3,
  506. byweekno=20,
  507. dtstart=datetime(1997, 9, 2, 9, 0))),
  508. [datetime(1998, 5, 11, 9, 0),
  509. datetime(1998, 5, 12, 9, 0),
  510. datetime(1998, 5, 13, 9, 0)])
  511. def testMonthlyByWeekNoAndWeekDay(self):
  512. # That's a nice one. The first days of week number one
  513. # may be in the last year.
  514. self.assertEqual(list(rrule(MONTHLY,
  515. count=3,
  516. byweekno=1,
  517. byweekday=MO,
  518. dtstart=datetime(1997, 9, 2, 9, 0))),
  519. [datetime(1997, 12, 29, 9, 0),
  520. datetime(1999, 1, 4, 9, 0),
  521. datetime(2000, 1, 3, 9, 0)])
  522. def testMonthlyByWeekNoAndWeekDayLarge(self):
  523. # Another nice test. The last days of week number 52/53
  524. # may be in the next year.
  525. self.assertEqual(list(rrule(MONTHLY,
  526. count=3,
  527. byweekno=52,
  528. byweekday=SU,
  529. dtstart=datetime(1997, 9, 2, 9, 0))),
  530. [datetime(1997, 12, 28, 9, 0),
  531. datetime(1998, 12, 27, 9, 0),
  532. datetime(2000, 1, 2, 9, 0)])
  533. def testMonthlyByWeekNoAndWeekDayLast(self):
  534. self.assertEqual(list(rrule(MONTHLY,
  535. count=3,
  536. byweekno=-1,
  537. byweekday=SU,
  538. dtstart=datetime(1997, 9, 2, 9, 0))),
  539. [datetime(1997, 12, 28, 9, 0),
  540. datetime(1999, 1, 3, 9, 0),
  541. datetime(2000, 1, 2, 9, 0)])
  542. def testMonthlyByWeekNoAndWeekDay53(self):
  543. self.assertEqual(list(rrule(MONTHLY,
  544. count=3,
  545. byweekno=53,
  546. byweekday=MO,
  547. dtstart=datetime(1997, 9, 2, 9, 0))),
  548. [datetime(1998, 12, 28, 9, 0),
  549. datetime(2004, 12, 27, 9, 0),
  550. datetime(2009, 12, 28, 9, 0)])
  551. def testMonthlyByEaster(self):
  552. self.assertEqual(list(rrule(MONTHLY,
  553. count=3,
  554. byeaster=0,
  555. dtstart=datetime(1997, 9, 2, 9, 0))),
  556. [datetime(1998, 4, 12, 9, 0),
  557. datetime(1999, 4, 4, 9, 0),
  558. datetime(2000, 4, 23, 9, 0)])
  559. def testMonthlyByEasterPos(self):
  560. self.assertEqual(list(rrule(MONTHLY,
  561. count=3,
  562. byeaster=1,
  563. dtstart=datetime(1997, 9, 2, 9, 0))),
  564. [datetime(1998, 4, 13, 9, 0),
  565. datetime(1999, 4, 5, 9, 0),
  566. datetime(2000, 4, 24, 9, 0)])
  567. def testMonthlyByEasterNeg(self):
  568. self.assertEqual(list(rrule(MONTHLY,
  569. count=3,
  570. byeaster=-1,
  571. dtstart=datetime(1997, 9, 2, 9, 0))),
  572. [datetime(1998, 4, 11, 9, 0),
  573. datetime(1999, 4, 3, 9, 0),
  574. datetime(2000, 4, 22, 9, 0)])
  575. def testMonthlyByHour(self):
  576. self.assertEqual(list(rrule(MONTHLY,
  577. count=3,
  578. byhour=(6, 18),
  579. dtstart=datetime(1997, 9, 2, 9, 0))),
  580. [datetime(1997, 9, 2, 18, 0),
  581. datetime(1997, 10, 2, 6, 0),
  582. datetime(1997, 10, 2, 18, 0)])
  583. def testMonthlyByMinute(self):
  584. self.assertEqual(list(rrule(MONTHLY,
  585. count=3,
  586. byminute=(6, 18),
  587. dtstart=datetime(1997, 9, 2, 9, 0))),
  588. [datetime(1997, 9, 2, 9, 6),
  589. datetime(1997, 9, 2, 9, 18),
  590. datetime(1997, 10, 2, 9, 6)])
  591. def testMonthlyBySecond(self):
  592. self.assertEqual(list(rrule(MONTHLY,
  593. count=3,
  594. bysecond=(6, 18),
  595. dtstart=datetime(1997, 9, 2, 9, 0))),
  596. [datetime(1997, 9, 2, 9, 0, 6),
  597. datetime(1997, 9, 2, 9, 0, 18),
  598. datetime(1997, 10, 2, 9, 0, 6)])
  599. def testMonthlyByHourAndMinute(self):
  600. self.assertEqual(list(rrule(MONTHLY,
  601. count=3,
  602. byhour=(6, 18),
  603. byminute=(6, 18),
  604. dtstart=datetime(1997, 9, 2, 9, 0))),
  605. [datetime(1997, 9, 2, 18, 6),
  606. datetime(1997, 9, 2, 18, 18),
  607. datetime(1997, 10, 2, 6, 6)])
  608. def testMonthlyByHourAndSecond(self):
  609. self.assertEqual(list(rrule(MONTHLY,
  610. count=3,
  611. byhour=(6, 18),
  612. bysecond=(6, 18),
  613. dtstart=datetime(1997, 9, 2, 9, 0))),
  614. [datetime(1997, 9, 2, 18, 0, 6),
  615. datetime(1997, 9, 2, 18, 0, 18),
  616. datetime(1997, 10, 2, 6, 0, 6)])
  617. def testMonthlyByMinuteAndSecond(self):
  618. self.assertEqual(list(rrule(MONTHLY,
  619. count=3,
  620. byminute=(6, 18),
  621. bysecond=(6, 18),
  622. dtstart=datetime(1997, 9, 2, 9, 0))),
  623. [datetime(1997, 9, 2, 9, 6, 6),
  624. datetime(1997, 9, 2, 9, 6, 18),
  625. datetime(1997, 9, 2, 9, 18, 6)])
  626. def testMonthlyByHourAndMinuteAndSecond(self):
  627. self.assertEqual(list(rrule(MONTHLY,
  628. count=3,
  629. byhour=(6, 18),
  630. byminute=(6, 18),
  631. bysecond=(6, 18),
  632. dtstart=datetime(1997, 9, 2, 9, 0))),
  633. [datetime(1997, 9, 2, 18, 6, 6),
  634. datetime(1997, 9, 2, 18, 6, 18),
  635. datetime(1997, 9, 2, 18, 18, 6)])
  636. def testMonthlyBySetPos(self):
  637. self.assertEqual(list(rrule(MONTHLY,
  638. count=3,
  639. bymonthday=(13, 17),
  640. byhour=(6, 18),
  641. bysetpos=(3, -3),
  642. dtstart=datetime(1997, 9, 2, 9, 0))),
  643. [datetime(1997, 9, 13, 18, 0),
  644. datetime(1997, 9, 17, 6, 0),
  645. datetime(1997, 10, 13, 18, 0)])
  646. def testWeekly(self):
  647. self.assertEqual(list(rrule(WEEKLY,
  648. count=3,
  649. dtstart=datetime(1997, 9, 2, 9, 0))),
  650. [datetime(1997, 9, 2, 9, 0),
  651. datetime(1997, 9, 9, 9, 0),
  652. datetime(1997, 9, 16, 9, 0)])
  653. def testWeeklyInterval(self):
  654. self.assertEqual(list(rrule(WEEKLY,
  655. count=3,
  656. interval=2,
  657. dtstart=datetime(1997, 9, 2, 9, 0))),
  658. [datetime(1997, 9, 2, 9, 0),
  659. datetime(1997, 9, 16, 9, 0),
  660. datetime(1997, 9, 30, 9, 0)])
  661. def testWeeklyIntervalLarge(self):
  662. self.assertEqual(list(rrule(WEEKLY,
  663. count=3,
  664. interval=20,
  665. dtstart=datetime(1997, 9, 2, 9, 0))),
  666. [datetime(1997, 9, 2, 9, 0),
  667. datetime(1998, 1, 20, 9, 0),
  668. datetime(1998, 6, 9, 9, 0)])
  669. def testWeeklyByMonth(self):
  670. self.assertEqual(list(rrule(WEEKLY,
  671. count=3,
  672. bymonth=(1, 3),
  673. dtstart=datetime(1997, 9, 2, 9, 0))),
  674. [datetime(1998, 1, 6, 9, 0),
  675. datetime(1998, 1, 13, 9, 0),
  676. datetime(1998, 1, 20, 9, 0)])
  677. def testWeeklyByMonthDay(self):
  678. self.assertEqual(list(rrule(WEEKLY,
  679. count=3,
  680. bymonthday=(1, 3),
  681. dtstart=datetime(1997, 9, 2, 9, 0))),
  682. [datetime(1997, 9, 3, 9, 0),
  683. datetime(1997, 10, 1, 9, 0),
  684. datetime(1997, 10, 3, 9, 0)])
  685. def testWeeklyByMonthAndMonthDay(self):
  686. self.assertEqual(list(rrule(WEEKLY,
  687. count=3,
  688. bymonth=(1, 3),
  689. bymonthday=(5, 7),
  690. dtstart=datetime(1997, 9, 2, 9, 0))),
  691. [datetime(1998, 1, 5, 9, 0),
  692. datetime(1998, 1, 7, 9, 0),
  693. datetime(1998, 3, 5, 9, 0)])
  694. def testWeeklyByWeekDay(self):
  695. self.assertEqual(list(rrule(WEEKLY,
  696. count=3,
  697. byweekday=(TU, TH),
  698. dtstart=datetime(1997, 9, 2, 9, 0))),
  699. [datetime(1997, 9, 2, 9, 0),
  700. datetime(1997, 9, 4, 9, 0),
  701. datetime(1997, 9, 9, 9, 0)])
  702. def testWeeklyByNWeekDay(self):
  703. self.assertEqual(list(rrule(WEEKLY,
  704. count=3,
  705. byweekday=(TU(1), TH(-1)),
  706. dtstart=datetime(1997, 9, 2, 9, 0))),
  707. [datetime(1997, 9, 2, 9, 0),
  708. datetime(1997, 9, 4, 9, 0),
  709. datetime(1997, 9, 9, 9, 0)])
  710. def testWeeklyByMonthAndWeekDay(self):
  711. # This test is interesting, because it crosses the year
  712. # boundary in a weekly period to find day '1' as a
  713. # valid recurrence.
  714. self.assertEqual(list(rrule(WEEKLY,
  715. count=3,
  716. bymonth=(1, 3),
  717. byweekday=(TU, TH),
  718. dtstart=datetime(1997, 9, 2, 9, 0))),
  719. [datetime(1998, 1, 1, 9, 0),
  720. datetime(1998, 1, 6, 9, 0),
  721. datetime(1998, 1, 8, 9, 0)])
  722. def testWeeklyByMonthAndNWeekDay(self):
  723. self.assertEqual(list(rrule(WEEKLY,
  724. count=3,
  725. bymonth=(1, 3),
  726. byweekday=(TU(1), TH(-1)),
  727. dtstart=datetime(1997, 9, 2, 9, 0))),
  728. [datetime(1998, 1, 1, 9, 0),
  729. datetime(1998, 1, 6, 9, 0),
  730. datetime(1998, 1, 8, 9, 0)])
  731. def testWeeklyByMonthDayAndWeekDay(self):
  732. self.assertEqual(list(rrule(WEEKLY,
  733. count=3,
  734. bymonthday=(1, 3),
  735. byweekday=(TU, TH),
  736. dtstart=datetime(1997, 9, 2, 9, 0))),
  737. [datetime(1998, 1, 1, 9, 0),
  738. datetime(1998, 2, 3, 9, 0),
  739. datetime(1998, 3, 3, 9, 0)])
  740. def testWeeklyByMonthAndMonthDayAndWeekDay(self):
  741. self.assertEqual(list(rrule(WEEKLY,
  742. count=3,
  743. bymonth=(1, 3),
  744. bymonthday=(1, 3),
  745. byweekday=(TU, TH),
  746. dtstart=datetime(1997, 9, 2, 9, 0))),
  747. [datetime(1998, 1, 1, 9, 0),
  748. datetime(1998, 3, 3, 9, 0),
  749. datetime(2001, 3, 1, 9, 0)])
  750. def testWeeklyByYearDay(self):
  751. self.assertEqual(list(rrule(WEEKLY,
  752. count=4,
  753. byyearday=(1, 100, 200, 365),
  754. dtstart=datetime(1997, 9, 2, 9, 0))),
  755. [datetime(1997, 12, 31, 9, 0),
  756. datetime(1998, 1, 1, 9, 0),
  757. datetime(1998, 4, 10, 9, 0),
  758. datetime(1998, 7, 19, 9, 0)])
  759. def testWeeklyByYearDayNeg(self):
  760. self.assertEqual(list(rrule(WEEKLY,
  761. count=4,
  762. byyearday=(-365, -266, -166, -1),
  763. dtstart=datetime(1997, 9, 2, 9, 0))),
  764. [datetime(1997, 12, 31, 9, 0),
  765. datetime(1998, 1, 1, 9, 0),
  766. datetime(1998, 4, 10, 9, 0),
  767. datetime(1998, 7, 19, 9, 0)])
  768. def testWeeklyByMonthAndYearDay(self):
  769. self.assertEqual(list(rrule(WEEKLY,
  770. count=4,
  771. bymonth=(1, 7),
  772. byyearday=(1, 100, 200, 365),
  773. dtstart=datetime(1997, 9, 2, 9, 0))),
  774. [datetime(1998, 1, 1, 9, 0),
  775. datetime(1998, 7, 19, 9, 0),
  776. datetime(1999, 1, 1, 9, 0),
  777. datetime(1999, 7, 19, 9, 0)])
  778. def testWeeklyByMonthAndYearDayNeg(self):
  779. self.assertEqual(list(rrule(WEEKLY,
  780. count=4,
  781. bymonth=(1, 7),
  782. byyearday=(-365, -266, -166, -1),
  783. dtstart=datetime(1997, 9, 2, 9, 0))),
  784. [datetime(1998, 1, 1, 9, 0),
  785. datetime(1998, 7, 19, 9, 0),
  786. datetime(1999, 1, 1, 9, 0),
  787. datetime(1999, 7, 19, 9, 0)])
  788. def testWeeklyByWeekNo(self):
  789. self.assertEqual(list(rrule(WEEKLY,
  790. count=3,
  791. byweekno=20,
  792. dtstart=datetime(1997, 9, 2, 9, 0))),
  793. [datetime(1998, 5, 11, 9, 0),
  794. datetime(1998, 5, 12, 9, 0),
  795. datetime(1998, 5, 13, 9, 0)])
  796. def testWeeklyByWeekNoAndWeekDay(self):
  797. # That's a nice one. The first days of week number one
  798. # may be in the last year.
  799. self.assertEqual(list(rrule(WEEKLY,
  800. count=3,
  801. byweekno=1,
  802. byweekday=MO,
  803. dtstart=datetime(1997, 9, 2, 9, 0))),
  804. [datetime(1997, 12, 29, 9, 0),
  805. datetime(1999, 1, 4, 9, 0),
  806. datetime(2000, 1, 3, 9, 0)])
  807. def testWeeklyByWeekNoAndWeekDayLarge(self):
  808. # Another nice test. The last days of week number 52/53
  809. # may be in the next year.
  810. self.assertEqual(list(rrule(WEEKLY,
  811. count=3,
  812. byweekno=52,
  813. byweekday=SU,
  814. dtstart=datetime(1997, 9, 2, 9, 0))),
  815. [datetime(1997, 12, 28, 9, 0),
  816. datetime(1998, 12, 27, 9, 0),
  817. datetime(2000, 1, 2, 9, 0)])
  818. def testWeeklyByWeekNoAndWeekDayLast(self):
  819. self.assertEqual(list(rrule(WEEKLY,
  820. count=3,
  821. byweekno=-1,
  822. byweekday=SU,
  823. dtstart=datetime(1997, 9, 2, 9, 0))),
  824. [datetime(1997, 12, 28, 9, 0),
  825. datetime(1999, 1, 3, 9, 0),
  826. datetime(2000, 1, 2, 9, 0)])
  827. def testWeeklyByWeekNoAndWeekDay53(self):
  828. self.assertEqual(list(rrule(WEEKLY,
  829. count=3,
  830. byweekno=53,
  831. byweekday=MO,
  832. dtstart=datetime(1997, 9, 2, 9, 0))),
  833. [datetime(1998, 12, 28, 9, 0),
  834. datetime(2004, 12, 27, 9, 0),
  835. datetime(2009, 12, 28, 9, 0)])
  836. def testWeeklyByEaster(self):
  837. self.assertEqual(list(rrule(WEEKLY,
  838. count=3,
  839. byeaster=0,
  840. dtstart=datetime(1997, 9, 2, 9, 0))),
  841. [datetime(1998, 4, 12, 9, 0),
  842. datetime(1999, 4, 4, 9, 0),
  843. datetime(2000, 4, 23, 9, 0)])
  844. def testWeeklyByEasterPos(self):
  845. self.assertEqual(list(rrule(WEEKLY,
  846. count=3,
  847. byeaster=1,
  848. dtstart=datetime(1997, 9, 2, 9, 0))),
  849. [datetime(1998, 4, 13, 9, 0),
  850. datetime(1999, 4, 5, 9, 0),
  851. datetime(2000, 4, 24, 9, 0)])
  852. def testWeeklyByEasterNeg(self):
  853. self.assertEqual(list(rrule(WEEKLY,
  854. count=3,
  855. byeaster=-1,
  856. dtstart=datetime(1997, 9, 2, 9, 0))),
  857. [datetime(1998, 4, 11, 9, 0),
  858. datetime(1999, 4, 3, 9, 0),
  859. datetime(2000, 4, 22, 9, 0)])
  860. def testWeeklyByHour(self):
  861. self.assertEqual(list(rrule(WEEKLY,
  862. count=3,
  863. byhour=(6, 18),
  864. dtstart=datetime(1997, 9, 2, 9, 0))),
  865. [datetime(1997, 9, 2, 18, 0),
  866. datetime(1997, 9, 9, 6, 0),
  867. datetime(1997, 9, 9, 18, 0)])
  868. def testWeeklyByMinute(self):
  869. self.assertEqual(list(rrule(WEEKLY,
  870. count=3,
  871. byminute=(6, 18),
  872. dtstart=datetime(1997, 9, 2, 9, 0))),
  873. [datetime(1997, 9, 2, 9, 6),
  874. datetime(1997, 9, 2, 9, 18),
  875. datetime(1997, 9, 9, 9, 6)])
  876. def testWeeklyBySecond(self):
  877. self.assertEqual(list(rrule(WEEKLY,
  878. count=3,
  879. bysecond=(6, 18),
  880. dtstart=datetime(1997, 9, 2, 9, 0))),
  881. [datetime(1997, 9, 2, 9, 0, 6),
  882. datetime(1997, 9, 2, 9, 0, 18),
  883. datetime(1997, 9, 9, 9, 0, 6)])
  884. def testWeeklyByHourAndMinute(self):
  885. self.assertEqual(list(rrule(WEEKLY,
  886. count=3,
  887. byhour=(6, 18),
  888. byminute=(6, 18),
  889. dtstart=datetime(1997, 9, 2, 9, 0))),
  890. [datetime(1997, 9, 2, 18, 6),
  891. datetime(1997, 9, 2, 18, 18),
  892. datetime(1997, 9, 9, 6, 6)])
  893. def testWeeklyByHourAndSecond(self):
  894. self.assertEqual(list(rrule(WEEKLY,
  895. count=3,
  896. byhour=(6, 18),
  897. bysecond=(6, 18),
  898. dtstart=datetime(1997, 9, 2, 9, 0))),
  899. [datetime(1997, 9, 2, 18, 0, 6),
  900. datetime(1997, 9, 2, 18, 0, 18),
  901. datetime(1997, 9, 9, 6, 0, 6)])
  902. def testWeeklyByMinuteAndSecond(self):
  903. self.assertEqual(list(rrule(WEEKLY,
  904. count=3,
  905. byminute=(6, 18),
  906. bysecond=(6, 18),
  907. dtstart=datetime(1997, 9, 2, 9, 0))),
  908. [datetime(1997, 9, 2, 9, 6, 6),
  909. datetime(1997, 9, 2, 9, 6, 18),
  910. datetime(1997, 9, 2, 9, 18, 6)])
  911. def testWeeklyByHourAndMinuteAndSecond(self):
  912. self.assertEqual(list(rrule(WEEKLY,
  913. count=3,
  914. byhour=(6, 18),
  915. byminute=(6, 18),
  916. bysecond=(6, 18),
  917. dtstart=datetime(1997, 9, 2, 9, 0))),
  918. [datetime(1997, 9, 2, 18, 6, 6),
  919. datetime(1997, 9, 2, 18, 6, 18),
  920. datetime(1997, 9, 2, 18, 18, 6)])
  921. def testWeeklyBySetPos(self):
  922. self.assertEqual(list(rrule(WEEKLY,
  923. count=3,
  924. byweekday=(TU, TH),
  925. byhour=(6, 18),
  926. bysetpos=(3, -3),
  927. dtstart=datetime(1997, 9, 2, 9, 0))),
  928. [datetime(1997, 9, 2, 18, 0),
  929. datetime(1997, 9, 4, 6, 0),
  930. datetime(1997, 9, 9, 18, 0)])
  931. def testDaily(self):
  932. self.assertEqual(list(rrule(DAILY,
  933. count=3,
  934. dtstart=datetime(1997, 9, 2, 9, 0))),
  935. [datetime(1997, 9, 2, 9, 0),
  936. datetime(1997, 9, 3, 9, 0),
  937. datetime(1997, 9, 4, 9, 0)])
  938. def testDailyInterval(self):
  939. self.assertEqual(list(rrule(DAILY,
  940. count=3,
  941. interval=2,
  942. dtstart=datetime(1997, 9, 2, 9, 0))),
  943. [datetime(1997, 9, 2, 9, 0),
  944. datetime(1997, 9, 4, 9, 0),
  945. datetime(1997, 9, 6, 9, 0)])
  946. def testDailyIntervalLarge(self):
  947. self.assertEqual(list(rrule(DAILY,
  948. count=3,
  949. interval=92,
  950. dtstart=datetime(1997, 9, 2, 9, 0))),
  951. [datetime(1997, 9, 2, 9, 0),
  952. datetime(1997, 12, 3, 9, 0),
  953. datetime(1998, 3, 5, 9, 0)])
  954. def testDailyByMonth(self):
  955. self.assertEqual(list(rrule(DAILY,
  956. count=3,
  957. bymonth=(1, 3),
  958. dtstart=datetime(1997, 9, 2, 9, 0))),
  959. [datetime(1998, 1, 1, 9, 0),
  960. datetime(1998, 1, 2, 9, 0),
  961. datetime(1998, 1, 3, 9, 0)])
  962. def testDailyByMonthDay(self):
  963. self.assertEqual(list(rrule(DAILY,
  964. count=3,
  965. bymonthday=(1, 3),
  966. dtstart=datetime(1997, 9, 2, 9, 0))),
  967. [datetime(1997, 9, 3, 9, 0),
  968. datetime(1997, 10, 1, 9, 0),
  969. datetime(1997, 10, 3, 9, 0)])
  970. def testDailyByMonthAndMonthDay(self):
  971. self.assertEqual(list(rrule(DAILY,
  972. count=3,
  973. bymonth=(1, 3),
  974. bymonthday=(5, 7),
  975. dtstart=datetime(1997, 9, 2, 9, 0))),
  976. [datetime(1998, 1, 5, 9, 0),
  977. datetime(1998, 1, 7, 9, 0),
  978. datetime(1998, 3, 5, 9, 0)])
  979. def testDailyByWeekDay(self):
  980. self.assertEqual(list(rrule(DAILY,
  981. count=3,
  982. byweekday=(TU, TH),
  983. dtstart=datetime(1997, 9, 2, 9, 0))),
  984. [datetime(1997, 9, 2, 9, 0),
  985. datetime(1997, 9, 4, 9, 0),
  986. datetime(1997, 9, 9, 9, 0)])
  987. def testDailyByNWeekDay(self):
  988. self.assertEqual(list(rrule(DAILY,
  989. count=3,
  990. byweekday=(TU(1), TH(-1)),
  991. dtstart=datetime(1997, 9, 2, 9, 0))),
  992. [datetime(1997, 9, 2, 9, 0),
  993. datetime(1997, 9, 4, 9, 0),
  994. datetime(1997, 9, 9, 9, 0)])
  995. def testDailyByMonthAndWeekDay(self):
  996. self.assertEqual(list(rrule(DAILY,
  997. count=3,
  998. bymonth=(1, 3),
  999. byweekday=(TU, TH),
  1000. dtstart=datetime(1997, 9, 2, 9, 0))),
  1001. [datetime(1998, 1, 1, 9, 0),
  1002. datetime(1998, 1, 6, 9, 0),
  1003. datetime(1998, 1, 8, 9, 0)])
  1004. def testDailyByMonthAndNWeekDay(self):
  1005. self.assertEqual(list(rrule(DAILY,
  1006. count=3,
  1007. bymonth=(1, 3),
  1008. byweekday=(TU(1), TH(-1)),
  1009. dtstart=datetime(1997, 9, 2, 9, 0))),
  1010. [datetime(1998, 1, 1, 9, 0),
  1011. datetime(1998, 1, 6, 9, 0),
  1012. datetime(1998, 1, 8, 9, 0)])
  1013. def testDailyByMonthDayAndWeekDay(self):
  1014. self.assertEqual(list(rrule(DAILY,
  1015. count=3,
  1016. bymonthday=(1, 3),
  1017. byweekday=(TU, TH),
  1018. dtstart=datetime(1997, 9, 2, 9, 0))),
  1019. [datetime(1998, 1, 1, 9, 0),
  1020. datetime(1998, 2, 3, 9, 0),
  1021. datetime(1998, 3, 3, 9, 0)])
  1022. def testDailyByMonthAndMonthDayAndWeekDay(self):
  1023. self.assertEqual(list(rrule(DAILY,
  1024. count=3,
  1025. bymonth=(1, 3),
  1026. bymonthday=(1, 3),
  1027. byweekday=(TU, TH),
  1028. dtstart=datetime(1997, 9, 2, 9, 0))),
  1029. [datetime(1998, 1, 1, 9, 0),
  1030. datetime(1998, 3, 3, 9, 0),
  1031. datetime(2001, 3, 1, 9, 0)])
  1032. def testDailyByYearDay(self):
  1033. self.assertEqual(list(rrule(DAILY,
  1034. count=4,
  1035. byyearday=(1, 100, 200, 365),
  1036. dtstart=datetime(1997, 9, 2, 9, 0))),
  1037. [datetime(1997, 12, 31, 9, 0),
  1038. datetime(1998, 1, 1, 9, 0),
  1039. datetime(1998, 4, 10, 9, 0),
  1040. datetime(1998, 7, 19, 9, 0)])
  1041. def testDailyByYearDayNeg(self):
  1042. self.assertEqual(list(rrule(DAILY,
  1043. count=4,
  1044. byyearday=(-365, -266, -166, -1),
  1045. dtstart=datetime(1997, 9, 2, 9, 0))),
  1046. [datetime(1997, 12, 31, 9, 0),
  1047. datetime(1998, 1, 1, 9, 0),
  1048. datetime(1998, 4, 10, 9, 0),
  1049. datetime(1998, 7, 19, 9, 0)])
  1050. def testDailyByMonthAndYearDay(self):
  1051. self.assertEqual(list(rrule(DAILY,
  1052. count=4,
  1053. bymonth=(1, 7),
  1054. byyearday=(1, 100, 200, 365),
  1055. dtstart=datetime(1997, 9, 2, 9, 0))),
  1056. [datetime(1998, 1, 1, 9, 0),
  1057. datetime(1998, 7, 19, 9, 0),
  1058. datetime(1999, 1, 1, 9, 0),
  1059. datetime(1999, 7, 19, 9, 0)])
  1060. def testDailyByMonthAndYearDayNeg(self):
  1061. self.assertEqual(list(rrule(DAILY,
  1062. count=4,
  1063. bymonth=(1, 7),
  1064. byyearday=(-365, -266, -166, -1),
  1065. dtstart=datetime(1997, 9, 2, 9, 0))),
  1066. [datetime(1998, 1, 1, 9, 0),
  1067. datetime(1998, 7, 19, 9, 0),
  1068. datetime(1999, 1, 1, 9, 0),
  1069. datetime(1999, 7, 19, 9, 0)])
  1070. def testDailyByWeekNo(self):
  1071. self.assertEqual(list(rrule(DAILY,
  1072. count=3,
  1073. byweekno=20,
  1074. dtstart=datetime(1997, 9, 2, 9, 0))),
  1075. [datetime(1998, 5, 11, 9, 0),
  1076. datetime(1998, 5, 12, 9, 0),
  1077. datetime(1998, 5, 13, 9, 0)])
  1078. def testDailyByWeekNoAndWeekDay(self):
  1079. # That's a nice one. The first days of week number one
  1080. # may be in the last year.
  1081. self.assertEqual(list(rrule(DAILY,
  1082. count=3,
  1083. byweekno=1,
  1084. byweekday=MO,
  1085. dtstart=datetime(1997, 9, 2, 9, 0))),
  1086. [datetime(1997, 12, 29, 9, 0),
  1087. datetime(1999, 1, 4, 9, 0),
  1088. datetime(2000, 1, 3, 9, 0)])
  1089. def testDailyByWeekNoAndWeekDayLarge(self):
  1090. # Another nice test. The last days of week number 52/53
  1091. # may be in the next year.
  1092. self.assertEqual(list(rrule(DAILY,
  1093. count=3,
  1094. byweekno=52,
  1095. byweekday=SU,
  1096. dtstart=datetime(1997, 9, 2, 9, 0))),
  1097. [datetime(1997, 12, 28, 9, 0),
  1098. datetime(1998, 12, 27, 9, 0),
  1099. datetime(2000, 1, 2, 9, 0)])
  1100. def testDailyByWeekNoAndWeekDayLast(self):
  1101. self.assertEqual(list(rrule(DAILY,
  1102. count=3,
  1103. byweekno=-1,
  1104. byweekday=SU,
  1105. dtstart=datetime(1997, 9, 2, 9, 0))),
  1106. [datetime(1997, 12, 28, 9, 0),
  1107. datetime(1999, 1, 3, 9, 0),
  1108. datetime(2000, 1, 2, 9, 0)])
  1109. def testDailyByWeekNoAndWeekDay53(self):
  1110. self.assertEqual(list(rrule(DAILY,
  1111. count=3,
  1112. byweekno=53,
  1113. byweekday=MO,
  1114. dtstart=datetime(1997, 9, 2, 9, 0))),
  1115. [datetime(1998, 12, 28, 9, 0),
  1116. datetime(2004, 12, 27, 9, 0),
  1117. datetime(2009, 12, 28, 9, 0)])
  1118. def testDailyByEaster(self):
  1119. self.assertEqual(list(rrule(DAILY,
  1120. count=3,
  1121. byeaster=0,
  1122. dtstart=datetime(1997, 9, 2, 9, 0))),
  1123. [datetime(1998, 4, 12, 9, 0),
  1124. datetime(1999, 4, 4, 9, 0),
  1125. datetime(2000, 4, 23, 9, 0)])
  1126. def testDailyByEasterPos(self):
  1127. self.assertEqual(list(rrule(DAILY,
  1128. count=3,
  1129. byeaster=1,
  1130. dtstart=datetime(1997, 9, 2, 9, 0))),
  1131. [datetime(1998, 4, 13, 9, 0),
  1132. datetime(1999, 4, 5, 9, 0),
  1133. datetime(2000, 4, 24, 9, 0)])
  1134. def testDailyByEasterNeg(self):
  1135. self.assertEqual(list(rrule(DAILY,
  1136. count=3,
  1137. byeaster=-1,
  1138. dtstart=datetime(1997, 9, 2, 9, 0))),
  1139. [datetime(1998, 4, 11, 9, 0),
  1140. datetime(1999, 4, 3, 9, 0),
  1141. datetime(2000, 4, 22, 9, 0)])
  1142. def testDailyByHour(self):
  1143. self.assertEqual(list(rrule(DAILY,
  1144. count=3,
  1145. byhour=(6, 18),
  1146. dtstart=datetime(1997, 9, 2, 9, 0))),
  1147. [datetime(1997, 9, 2, 18, 0),
  1148. datetime(1997, 9, 3, 6, 0),
  1149. datetime(1997, 9, 3, 18, 0)])
  1150. def testDailyByMinute(self):
  1151. self.assertEqual(list(rrule(DAILY,
  1152. count=3,
  1153. byminute=(6, 18),
  1154. dtstart=datetime(1997, 9, 2, 9, 0))),
  1155. [datetime(1997, 9, 2, 9, 6),
  1156. datetime(1997, 9, 2, 9, 18),
  1157. datetime(1997, 9, 3, 9, 6)])
  1158. def testDailyBySecond(self):
  1159. self.assertEqual(list(rrule(DAILY,
  1160. count=3,
  1161. bysecond=(6, 18),
  1162. dtstart=datetime(1997, 9, 2, 9, 0))),
  1163. [datetime(1997, 9, 2, 9, 0, 6),
  1164. datetime(1997, 9, 2, 9, 0, 18),
  1165. datetime(1997, 9, 3, 9, 0, 6)])
  1166. def testDailyByHourAndMinute(self):
  1167. self.assertEqual(list(rrule(DAILY,
  1168. count=3,
  1169. byhour=(6, 18),
  1170. byminute=(6, 18),
  1171. dtstart=datetime(1997, 9, 2, 9, 0))),
  1172. [datetime(1997, 9, 2, 18, 6),
  1173. datetime(1997, 9, 2, 18, 18),
  1174. datetime(1997, 9, 3, 6, 6)])
  1175. def testDailyByHourAndSecond(self):
  1176. self.assertEqual(list(rrule(DAILY,
  1177. count=3,
  1178. byhour=(6, 18),
  1179. bysecond=(6, 18),
  1180. dtstart=datetime(1997, 9, 2, 9, 0))),
  1181. [datetime(1997, 9, 2, 18, 0, 6),
  1182. datetime(1997, 9, 2, 18, 0, 18),
  1183. datetime(1997, 9, 3, 6, 0, 6)])
  1184. def testDailyByMinuteAndSecond(self):
  1185. self.assertEqual(list(rrule(DAILY,
  1186. count=3,
  1187. byminute=(6, 18),
  1188. bysecond=(6, 18),
  1189. dtstart=datetime(1997, 9, 2, 9, 0))),
  1190. [datetime(1997, 9, 2, 9, 6, 6),
  1191. datetime(1997, 9, 2, 9, 6, 18),
  1192. datetime(1997, 9, 2, 9, 18, 6)])
  1193. def testDailyByHourAndMinuteAndSecond(self):
  1194. self.assertEqual(list(rrule(DAILY,
  1195. count=3,
  1196. byhour=(6, 18),
  1197. byminute=(6, 18),
  1198. bysecond=(6, 18),
  1199. dtstart=datetime(1997, 9, 2, 9, 0))),
  1200. [datetime(1997, 9, 2, 18, 6, 6),
  1201. datetime(1997, 9, 2, 18, 6, 18),
  1202. datetime(1997, 9, 2, 18, 18, 6)])
  1203. def testDailyBySetPos(self):
  1204. self.assertEqual(list(rrule(DAILY,
  1205. count=3,
  1206. byhour=(6, 18),
  1207. byminute=(15, 45),
  1208. bysetpos=(3, -3),
  1209. dtstart=datetime(1997, 9, 2, 9, 0))),
  1210. [datetime(1997, 9, 2, 18, 15),
  1211. datetime(1997, 9, 3, 6, 45),
  1212. datetime(1997, 9, 3, 18, 15)])
  1213. def testHourly(self):
  1214. self.assertEqual(list(rrule(HOURLY,
  1215. count=3,
  1216. dtstart=datetime(1997, 9, 2, 9, 0))),
  1217. [datetime(1997, 9, 2, 9, 0),
  1218. datetime(1997, 9, 2, 10, 0),
  1219. datetime(1997, 9, 2, 11, 0)])
  1220. def testHourlyInterval(self):
  1221. self.assertEqual(list(rrule(HOURLY,
  1222. count=3,
  1223. interval=2,
  1224. dtstart=datetime(1997, 9, 2, 9, 0))),
  1225. [datetime(1997, 9, 2, 9, 0),
  1226. datetime(1997, 9, 2, 11, 0),
  1227. datetime(1997, 9, 2, 13, 0)])
  1228. def testHourlyIntervalLarge(self):
  1229. self.assertEqual(list(rrule(HOURLY,
  1230. count=3,
  1231. interval=769,
  1232. dtstart=datetime(1997, 9, 2, 9, 0))),
  1233. [datetime(1997, 9, 2, 9, 0),
  1234. datetime(1997, 10, 4, 10, 0),
  1235. datetime(1997, 11, 5, 11, 0)])
  1236. def testHourlyByMonth(self):
  1237. self.assertEqual(list(rrule(HOURLY,
  1238. count=3,
  1239. bymonth=(1, 3),
  1240. dtstart=datetime(1997, 9, 2, 9, 0))),
  1241. [datetime(1998, 1, 1, 0, 0),
  1242. datetime(1998, 1, 1, 1, 0),
  1243. datetime(1998, 1, 1, 2, 0)])
  1244. def testHourlyByMonthDay(self):
  1245. self.assertEqual(list(rrule(HOURLY,
  1246. count=3,
  1247. bymonthday=(1, 3),
  1248. dtstart=datetime(1997, 9, 2, 9, 0))),
  1249. [datetime(1997, 9, 3, 0, 0),
  1250. datetime(1997, 9, 3, 1, 0),
  1251. datetime(1997, 9, 3, 2, 0)])
  1252. def testHourlyByMonthAndMonthDay(self):
  1253. self.assertEqual(list(rrule(HOURLY,
  1254. count=3,
  1255. bymonth=(1, 3),
  1256. bymonthday=(5, 7),
  1257. dtstart=datetime(1997, 9, 2, 9, 0))),
  1258. [datetime(1998, 1, 5, 0, 0),
  1259. datetime(1998, 1, 5, 1, 0),
  1260. datetime(1998, 1, 5, 2, 0)])
  1261. def testHourlyByWeekDay(self):
  1262. self.assertEqual(list(rrule(HOURLY,
  1263. count=3,
  1264. byweekday=(TU, TH),
  1265. dtstart=datetime(1997, 9, 2, 9, 0))),
  1266. [datetime(1997, 9, 2, 9, 0),
  1267. datetime(1997, 9, 2, 10, 0),
  1268. datetime(1997, 9, 2, 11, 0)])
  1269. def testHourlyByNWeekDay(self):
  1270. self.assertEqual(list(rrule(HOURLY,
  1271. count=3,
  1272. byweekday=(TU(1), TH(-1)),
  1273. dtstart=datetime(1997, 9, 2, 9, 0))),
  1274. [datetime(1997, 9, 2, 9, 0),
  1275. datetime(1997, 9, 2, 10, 0),
  1276. datetime(1997, 9, 2, 11, 0)])
  1277. def testHourlyByMonthAndWeekDay(self):
  1278. self.assertEqual(list(rrule(HOURLY,
  1279. count=3,
  1280. bymonth=(1, 3),
  1281. byweekday=(TU, TH),
  1282. dtstart=datetime(1997, 9, 2, 9, 0))),
  1283. [datetime(1998, 1, 1, 0, 0),
  1284. datetime(1998, 1, 1, 1, 0),
  1285. datetime(1998, 1, 1, 2, 0)])
  1286. def testHourlyByMonthAndNWeekDay(self):
  1287. self.assertEqual(list(rrule(HOURLY,
  1288. count=3,
  1289. bymonth=(1, 3),
  1290. byweekday=(TU(1), TH(-1)),
  1291. dtstart=datetime(1997, 9, 2, 9, 0))),
  1292. [datetime(1998, 1, 1, 0, 0),
  1293. datetime(1998, 1, 1, 1, 0),
  1294. datetime(1998, 1, 1, 2, 0)])
  1295. def testHourlyByMonthDayAndWeekDay(self):
  1296. self.assertEqual(list(rrule(HOURLY,
  1297. count=3,
  1298. bymonthday=(1, 3),
  1299. byweekday=(TU, TH),
  1300. dtstart=datetime(1997, 9, 2, 9, 0))),
  1301. [datetime(1998, 1, 1, 0, 0),
  1302. datetime(1998, 1, 1, 1, 0),
  1303. datetime(1998, 1, 1, 2, 0)])
  1304. def testHourlyByMonthAndMonthDayAndWeekDay(self):
  1305. self.assertEqual(list(rrule(HOURLY,
  1306. count=3,
  1307. bymonth=(1, 3),
  1308. bymonthday=(1, 3),
  1309. byweekday=(TU, TH),
  1310. dtstart=datetime(1997, 9, 2, 9, 0))),
  1311. [datetime(1998, 1, 1, 0, 0),
  1312. datetime(1998, 1, 1, 1, 0),
  1313. datetime(1998, 1, 1, 2, 0)])
  1314. def testHourlyByYearDay(self):
  1315. self.assertEqual(list(rrule(HOURLY,
  1316. count=4,
  1317. byyearday=(1, 100, 200, 365),
  1318. dtstart=datetime(1997, 9, 2, 9, 0))),
  1319. [datetime(1997, 12, 31, 0, 0),
  1320. datetime(1997, 12, 31, 1, 0),
  1321. datetime(1997, 12, 31, 2, 0),
  1322. datetime(1997, 12, 31, 3, 0)])
  1323. def testHourlyByYearDayNeg(self):
  1324. self.assertEqual(list(rrule(HOURLY,
  1325. count=4,
  1326. byyearday=(-365, -266, -166, -1),
  1327. dtstart=datetime(1997, 9, 2, 9, 0))),
  1328. [datetime(1997, 12, 31, 0, 0),
  1329. datetime(1997, 12, 31, 1, 0),
  1330. datetime(1997, 12, 31, 2, 0),
  1331. datetime(1997, 12, 31, 3, 0)])
  1332. def testHourlyByMonthAndYearDay(self):
  1333. self.assertEqual(list(rrule(HOURLY,
  1334. count=4,
  1335. bymonth=(4, 7),
  1336. byyearday=(1, 100, 200, 365),
  1337. dtstart=datetime(1997, 9, 2, 9, 0))),
  1338. [datetime(1998, 4, 10, 0, 0),
  1339. datetime(1998, 4, 10, 1, 0),
  1340. datetime(1998, 4, 10, 2, 0),
  1341. datetime(1998, 4, 10, 3, 0)])
  1342. def testHourlyByMonthAndYearDayNeg(self):
  1343. self.assertEqual(list(rrule(HOURLY,
  1344. count=4,
  1345. bymonth=(4, 7),
  1346. byyearday=(-365, -266, -166, -1),
  1347. dtstart=datetime(1997, 9, 2, 9, 0))),
  1348. [datetime(1998, 4, 10, 0, 0),
  1349. datetime(1998, 4, 10, 1, 0),
  1350. datetime(1998, 4, 10, 2, 0),
  1351. datetime(1998, 4, 10, 3, 0)])
  1352. def testHourlyByWeekNo(self):
  1353. self.assertEqual(list(rrule(HOURLY,
  1354. count=3,
  1355. byweekno=20,
  1356. dtstart=datetime(1997, 9, 2, 9, 0))),
  1357. [datetime(1998, 5, 11, 0, 0),
  1358. datetime(1998, 5, 11, 1, 0),
  1359. datetime(1998, 5, 11, 2, 0)])
  1360. def testHourlyByWeekNoAndWeekDay(self):
  1361. self.assertEqual(list(rrule(HOURLY,
  1362. count=3,
  1363. byweekno=1,
  1364. byweekday=MO,
  1365. dtstart=datetime(1997, 9, 2, 9, 0))),
  1366. [datetime(1997, 12, 29, 0, 0),
  1367. datetime(1997, 12, 29, 1, 0),
  1368. datetime(1997, 12, 29, 2, 0)])
  1369. def testHourlyByWeekNoAndWeekDayLarge(self):
  1370. self.assertEqual(list(rrule(HOURLY,
  1371. count=3,
  1372. byweekno=52,
  1373. byweekday=SU,
  1374. dtstart=datetime(1997, 9, 2, 9, 0))),
  1375. [datetime(1997, 12, 28, 0, 0),
  1376. datetime(1997, 12, 28, 1, 0),
  1377. datetime(1997, 12, 28, 2, 0)])
  1378. def testHourlyByWeekNoAndWeekDayLast(self):
  1379. self.assertEqual(list(rrule(HOURLY,
  1380. count=3,
  1381. byweekno=-1,
  1382. byweekday=SU,
  1383. dtstart=datetime(1997, 9, 2, 9, 0))),
  1384. [datetime(1997, 12, 28, 0, 0),
  1385. datetime(1997, 12, 28, 1, 0),
  1386. datetime(1997, 12, 28, 2, 0)])
  1387. def testHourlyByWeekNoAndWeekDay53(self):
  1388. self.assertEqual(list(rrule(HOURLY,
  1389. count=3,
  1390. byweekno=53,
  1391. byweekday=MO,
  1392. dtstart=datetime(1997, 9, 2, 9, 0))),
  1393. [datetime(1998, 12, 28, 0, 0),
  1394. datetime(1998, 12, 28, 1, 0),
  1395. datetime(1998, 12, 28, 2, 0)])
  1396. def testHourlyByEaster(self):
  1397. self.assertEqual(list(rrule(HOURLY,
  1398. count=3,
  1399. byeaster=0,
  1400. dtstart=datetime(1997, 9, 2, 9, 0))),
  1401. [datetime(1998, 4, 12, 0, 0),
  1402. datetime(1998, 4, 12, 1, 0),
  1403. datetime(1998, 4, 12, 2, 0)])
  1404. def testHourlyByEasterPos(self):
  1405. self.assertEqual(list(rrule(HOURLY,
  1406. count=3,
  1407. byeaster=1,
  1408. dtstart=datetime(1997, 9, 2, 9, 0))),
  1409. [datetime(1998, 4, 13, 0, 0),
  1410. datetime(1998, 4, 13, 1, 0),
  1411. datetime(1998, 4, 13, 2, 0)])
  1412. def testHourlyByEasterNeg(self):
  1413. self.assertEqual(list(rrule(HOURLY,
  1414. count=3,
  1415. byeaster=-1,
  1416. dtstart=datetime(1997, 9, 2, 9, 0))),
  1417. [datetime(1998, 4, 11, 0, 0),
  1418. datetime(1998, 4, 11, 1, 0),
  1419. datetime(1998, 4, 11, 2, 0)])
  1420. def testHourlyByHour(self):
  1421. self.assertEqual(list(rrule(HOURLY,
  1422. count=3,
  1423. byhour=(6, 18),
  1424. dtstart=datetime(1997, 9, 2, 9, 0))),
  1425. [datetime(1997, 9, 2, 18, 0),
  1426. datetime(1997, 9, 3, 6, 0),
  1427. datetime(1997, 9, 3, 18, 0)])
  1428. def testHourlyByMinute(self):
  1429. self.assertEqual(list(rrule(HOURLY,
  1430. count=3,
  1431. byminute=(6, 18),
  1432. dtstart=datetime(1997, 9, 2, 9, 0))),
  1433. [datetime(1997, 9, 2, 9, 6),
  1434. datetime(1997, 9, 2, 9, 18),
  1435. datetime(1997, 9, 2, 10, 6)])
  1436. def testHourlyBySecond(self):
  1437. self.assertEqual(list(rrule(HOURLY,
  1438. count=3,
  1439. bysecond=(6, 18),
  1440. dtstart=datetime(1997, 9, 2, 9, 0))),
  1441. [datetime(1997, 9, 2, 9, 0, 6),
  1442. datetime(1997, 9, 2, 9, 0, 18),
  1443. datetime(1997, 9, 2, 10, 0, 6)])
  1444. def testHourlyByHourAndMinute(self):
  1445. self.assertEqual(list(rrule(HOURLY,
  1446. count=3,
  1447. byhour=(6, 18),
  1448. byminute=(6, 18),
  1449. dtstart=datetime(1997, 9, 2, 9, 0))),
  1450. [datetime(1997, 9, 2, 18, 6),
  1451. datetime(1997, 9, 2, 18, 18),
  1452. datetime(1997, 9, 3, 6, 6)])
  1453. def testHourlyByHourAndSecond(self):
  1454. self.assertEqual(list(rrule(HOURLY,
  1455. count=3,
  1456. byhour=(6, 18),
  1457. bysecond=(6, 18),
  1458. dtstart=datetime(1997, 9, 2, 9, 0))),
  1459. [datetime(1997, 9, 2, 18, 0, 6),
  1460. datetime(1997, 9, 2, 18, 0, 18),
  1461. datetime(1997, 9, 3, 6, 0, 6)])
  1462. def testHourlyByMinuteAndSecond(self):
  1463. self.assertEqual(list(rrule(HOURLY,
  1464. count=3,
  1465. byminute=(6, 18),
  1466. bysecond=(6, 18),
  1467. dtstart=datetime(1997, 9, 2, 9, 0))),
  1468. [datetime(1997, 9, 2, 9, 6, 6),
  1469. datetime(1997, 9, 2, 9, 6, 18),
  1470. datetime(1997, 9, 2, 9, 18, 6)])
  1471. def testHourlyByHourAndMinuteAndSecond(self):
  1472. self.assertEqual(list(rrule(HOURLY,
  1473. count=3,
  1474. byhour=(6, 18),
  1475. byminute=(6, 18),
  1476. bysecond=(6, 18),
  1477. dtstart=datetime(1997, 9, 2, 9, 0))),
  1478. [datetime(1997, 9, 2, 18, 6, 6),
  1479. datetime(1997, 9, 2, 18, 6, 18),
  1480. datetime(1997, 9, 2, 18, 18, 6)])
  1481. def testHourlyBySetPos(self):
  1482. self.assertEqual(list(rrule(HOURLY,
  1483. count=3,
  1484. byminute=(15, 45),
  1485. bysecond=(15, 45),
  1486. bysetpos=(3, -3),
  1487. dtstart=datetime(1997, 9, 2, 9, 0))),
  1488. [datetime(1997, 9, 2, 9, 15, 45),
  1489. datetime(1997, 9, 2, 9, 45, 15),
  1490. datetime(1997, 9, 2, 10, 15, 45)])
  1491. def testMinutely(self):
  1492. self.assertEqual(list(rrule(MINUTELY,
  1493. count=3,
  1494. dtstart=datetime(1997, 9, 2, 9, 0))),
  1495. [datetime(1997, 9, 2, 9, 0),
  1496. datetime(1997, 9, 2, 9, 1),
  1497. datetime(1997, 9, 2, 9, 2)])
  1498. def testMinutelyInterval(self):
  1499. self.assertEqual(list(rrule(MINUTELY,
  1500. count=3,
  1501. interval=2,
  1502. dtstart=datetime(1997, 9, 2, 9, 0))),
  1503. [datetime(1997, 9, 2, 9, 0),
  1504. datetime(1997, 9, 2, 9, 2),
  1505. datetime(1997, 9, 2, 9, 4)])
  1506. def testMinutelyIntervalLarge(self):
  1507. self.assertEqual(list(rrule(MINUTELY,
  1508. count=3,
  1509. interval=1501,
  1510. dtstart=datetime(1997, 9, 2, 9, 0))),
  1511. [datetime(1997, 9, 2, 9, 0),
  1512. datetime(1997, 9, 3, 10, 1),
  1513. datetime(1997, 9, 4, 11, 2)])
  1514. def testMinutelyByMonth(self):
  1515. self.assertEqual(list(rrule(MINUTELY,
  1516. count=3,
  1517. bymonth=(1, 3),
  1518. dtstart=datetime(1997, 9, 2, 9, 0))),
  1519. [datetime(1998, 1, 1, 0, 0),
  1520. datetime(1998, 1, 1, 0, 1),
  1521. datetime(1998, 1, 1, 0, 2)])
  1522. def testMinutelyByMonthDay(self):
  1523. self.assertEqual(list(rrule(MINUTELY,
  1524. count=3,
  1525. bymonthday=(1, 3),
  1526. dtstart=datetime(1997, 9, 2, 9, 0))),
  1527. [datetime(1997, 9, 3, 0, 0),
  1528. datetime(1997, 9, 3, 0, 1),
  1529. datetime(1997, 9, 3, 0, 2)])
  1530. def testMinutelyByMonthAndMonthDay(self):
  1531. self.assertEqual(list(rrule(MINUTELY,
  1532. count=3,
  1533. bymonth=(1, 3),
  1534. bymonthday=(5, 7),
  1535. dtstart=datetime(1997, 9, 2, 9, 0))),
  1536. [datetime(1998, 1, 5, 0, 0),
  1537. datetime(1998, 1, 5, 0, 1),
  1538. datetime(1998, 1, 5, 0, 2)])
  1539. def testMinutelyByWeekDay(self):
  1540. self.assertEqual(list(rrule(MINUTELY,
  1541. count=3,
  1542. byweekday=(TU, TH),
  1543. dtstart=datetime(1997, 9, 2, 9, 0))),
  1544. [datetime(1997, 9, 2, 9, 0),
  1545. datetime(1997, 9, 2, 9, 1),
  1546. datetime(1997, 9, 2, 9, 2)])
  1547. def testMinutelyByNWeekDay(self):
  1548. self.assertEqual(list(rrule(MINUTELY,
  1549. count=3,
  1550. byweekday=(TU(1), TH(-1)),
  1551. dtstart=datetime(1997, 9, 2, 9, 0))),
  1552. [datetime(1997, 9, 2, 9, 0),
  1553. datetime(1997, 9, 2, 9, 1),
  1554. datetime(1997, 9, 2, 9, 2)])
  1555. def testMinutelyByMonthAndWeekDay(self):
  1556. self.assertEqual(list(rrule(MINUTELY,
  1557. count=3,
  1558. bymonth=(1, 3),
  1559. byweekday=(TU, TH),
  1560. dtstart=datetime(1997, 9, 2, 9, 0))),
  1561. [datetime(1998, 1, 1, 0, 0),
  1562. datetime(1998, 1, 1, 0, 1),
  1563. datetime(1998, 1, 1, 0, 2)])
  1564. def testMinutelyByMonthAndNWeekDay(self):
  1565. self.assertEqual(list(rrule(MINUTELY,
  1566. count=3,
  1567. bymonth=(1, 3),
  1568. byweekday=(TU(1), TH(-1)),
  1569. dtstart=datetime(1997, 9, 2, 9, 0))),
  1570. [datetime(1998, 1, 1, 0, 0),
  1571. datetime(1998, 1, 1, 0, 1),
  1572. datetime(1998, 1, 1, 0, 2)])
  1573. def testMinutelyByMonthDayAndWeekDay(self):
  1574. self.assertEqual(list(rrule(MINUTELY,
  1575. count=3,
  1576. bymonthday=(1, 3),
  1577. byweekday=(TU, TH),
  1578. dtstart=datetime(1997, 9, 2, 9, 0))),
  1579. [datetime(1998, 1, 1, 0, 0),
  1580. datetime(1998, 1, 1, 0, 1),
  1581. datetime(1998, 1, 1, 0, 2)])
  1582. def testMinutelyByMonthAndMonthDayAndWeekDay(self):
  1583. self.assertEqual(list(rrule(MINUTELY,
  1584. count=3,
  1585. bymonth=(1, 3),
  1586. bymonthday=(1, 3),
  1587. byweekday=(TU, TH),
  1588. dtstart=datetime(1997, 9, 2, 9, 0))),
  1589. [datetime(1998, 1, 1, 0, 0),
  1590. datetime(1998, 1, 1, 0, 1),
  1591. datetime(1998, 1, 1, 0, 2)])
  1592. def testMinutelyByYearDay(self):
  1593. self.assertEqual(list(rrule(MINUTELY,
  1594. count=4,
  1595. byyearday=(1, 100, 200, 365),
  1596. dtstart=datetime(1997, 9, 2, 9, 0))),
  1597. [datetime(1997, 12, 31, 0, 0),
  1598. datetime(1997, 12, 31, 0, 1),
  1599. datetime(1997, 12, 31, 0, 2),
  1600. datetime(1997, 12, 31, 0, 3)])
  1601. def testMinutelyByYearDayNeg(self):
  1602. self.assertEqual(list(rrule(MINUTELY,
  1603. count=4,
  1604. byyearday=(-365, -266, -166, -1),
  1605. dtstart=datetime(1997, 9, 2, 9, 0))),
  1606. [datetime(1997, 12, 31, 0, 0),
  1607. datetime(1997, 12, 31, 0, 1),
  1608. datetime(1997, 12, 31, 0, 2),
  1609. datetime(1997, 12, 31, 0, 3)])
  1610. def testMinutelyByMonthAndYearDay(self):
  1611. self.assertEqual(list(rrule(MINUTELY,
  1612. count=4,
  1613. bymonth=(4, 7),
  1614. byyearday=(1, 100, 200, 365),
  1615. dtstart=datetime(1997, 9, 2, 9, 0))),
  1616. [datetime(1998, 4, 10, 0, 0),
  1617. datetime(1998, 4, 10, 0, 1),
  1618. datetime(1998, 4, 10, 0, 2),
  1619. datetime(1998, 4, 10, 0, 3)])
  1620. def testMinutelyByMonthAndYearDayNeg(self):
  1621. self.assertEqual(list(rrule(MINUTELY,
  1622. count=4,
  1623. bymonth=(4, 7),
  1624. byyearday=(-365, -266, -166, -1),
  1625. dtstart=datetime(1997, 9, 2, 9, 0))),
  1626. [datetime(1998, 4, 10, 0, 0),
  1627. datetime(1998, 4, 10, 0, 1),
  1628. datetime(1998, 4, 10, 0, 2),
  1629. datetime(1998, 4, 10, 0, 3)])
  1630. def testMinutelyByWeekNo(self):
  1631. self.assertEqual(list(rrule(MINUTELY,
  1632. count=3,
  1633. byweekno=20,
  1634. dtstart=datetime(1997, 9, 2, 9, 0))),
  1635. [datetime(1998, 5, 11, 0, 0),
  1636. datetime(1998, 5, 11, 0, 1),
  1637. datetime(1998, 5, 11, 0, 2)])
  1638. def testMinutelyByWeekNoAndWeekDay(self):
  1639. self.assertEqual(list(rrule(MINUTELY,
  1640. count=3,
  1641. byweekno=1,
  1642. byweekday=MO,
  1643. dtstart=datetime(1997, 9, 2, 9, 0))),
  1644. [datetime(1997, 12, 29, 0, 0),
  1645. datetime(1997, 12, 29, 0, 1),
  1646. datetime(1997, 12, 29, 0, 2)])
  1647. def testMinutelyByWeekNoAndWeekDayLarge(self):
  1648. self.assertEqual(list(rrule(MINUTELY,
  1649. count=3,
  1650. byweekno=52,
  1651. byweekday=SU,
  1652. dtstart=datetime(1997, 9, 2, 9, 0))),
  1653. [datetime(1997, 12, 28, 0, 0),
  1654. datetime(1997, 12, 28, 0, 1),
  1655. datetime(1997, 12, 28, 0, 2)])
  1656. def testMinutelyByWeekNoAndWeekDayLast(self):
  1657. self.assertEqual(list(rrule(MINUTELY,
  1658. count=3,
  1659. byweekno=-1,
  1660. byweekday=SU,
  1661. dtstart=datetime(1997, 9, 2, 9, 0))),
  1662. [datetime(1997, 12, 28, 0, 0),
  1663. datetime(1997, 12, 28, 0, 1),
  1664. datetime(1997, 12, 28, 0, 2)])
  1665. def testMinutelyByWeekNoAndWeekDay53(self):
  1666. self.assertEqual(list(rrule(MINUTELY,
  1667. count=3,
  1668. byweekno=53,
  1669. byweekday=MO,
  1670. dtstart=datetime(1997, 9, 2, 9, 0))),
  1671. [datetime(1998, 12, 28, 0, 0),
  1672. datetime(1998, 12, 28, 0, 1),
  1673. datetime(1998, 12, 28, 0, 2)])
  1674. def testMinutelyByEaster(self):
  1675. self.assertEqual(list(rrule(MINUTELY,
  1676. count=3,
  1677. byeaster=0,
  1678. dtstart=datetime(1997, 9, 2, 9, 0))),
  1679. [datetime(1998, 4, 12, 0, 0),
  1680. datetime(1998, 4, 12, 0, 1),
  1681. datetime(1998, 4, 12, 0, 2)])
  1682. def testMinutelyByEasterPos(self):
  1683. self.assertEqual(list(rrule(MINUTELY,
  1684. count=3,
  1685. byeaster=1,
  1686. dtstart=datetime(1997, 9, 2, 9, 0))),
  1687. [datetime(1998, 4, 13, 0, 0),
  1688. datetime(1998, 4, 13, 0, 1),
  1689. datetime(1998, 4, 13, 0, 2)])
  1690. def testMinutelyByEasterNeg(self):
  1691. self.assertEqual(list(rrule(MINUTELY,
  1692. count=3,
  1693. byeaster=-1,
  1694. dtstart=datetime(1997, 9, 2, 9, 0))),
  1695. [datetime(1998, 4, 11, 0, 0),
  1696. datetime(1998, 4, 11, 0, 1),
  1697. datetime(1998, 4, 11, 0, 2)])
  1698. def testMinutelyByHour(self):
  1699. self.assertEqual(list(rrule(MINUTELY,
  1700. count=3,
  1701. byhour=(6, 18),
  1702. dtstart=datetime(1997, 9, 2, 9, 0))),
  1703. [datetime(1997, 9, 2, 18, 0),
  1704. datetime(1997, 9, 2, 18, 1),
  1705. datetime(1997, 9, 2, 18, 2)])
  1706. def testMinutelyByMinute(self):
  1707. self.assertEqual(list(rrule(MINUTELY,
  1708. count=3,
  1709. byminute=(6, 18),
  1710. dtstart=datetime(1997, 9, 2, 9, 0))),
  1711. [datetime(1997, 9, 2, 9, 6),
  1712. datetime(1997, 9, 2, 9, 18),
  1713. datetime(1997, 9, 2, 10, 6)])
  1714. def testMinutelyBySecond(self):
  1715. self.assertEqual(list(rrule(MINUTELY,
  1716. count=3,
  1717. bysecond=(6, 18),
  1718. dtstart=datetime(1997, 9, 2, 9, 0))),
  1719. [datetime(1997, 9, 2, 9, 0, 6),
  1720. datetime(1997, 9, 2, 9, 0, 18),
  1721. datetime(1997, 9, 2, 9, 1, 6)])
  1722. def testMinutelyByHourAndMinute(self):
  1723. self.assertEqual(list(rrule(MINUTELY,
  1724. count=3,
  1725. byhour=(6, 18),
  1726. byminute=(6, 18),
  1727. dtstart=datetime(1997, 9, 2, 9, 0))),
  1728. [datetime(1997, 9, 2, 18, 6),
  1729. datetime(1997, 9, 2, 18, 18),
  1730. datetime(1997, 9, 3, 6, 6)])
  1731. def testMinutelyByHourAndSecond(self):
  1732. self.assertEqual(list(rrule(MINUTELY,
  1733. count=3,
  1734. byhour=(6, 18),
  1735. bysecond=(6, 18),
  1736. dtstart=datetime(1997, 9, 2, 9, 0))),
  1737. [datetime(1997, 9, 2, 18, 0, 6),
  1738. datetime(1997, 9, 2, 18, 0, 18),
  1739. datetime(1997, 9, 2, 18, 1, 6)])
  1740. def testMinutelyByMinuteAndSecond(self):
  1741. self.assertEqual(list(rrule(MINUTELY,
  1742. count=3,
  1743. byminute=(6, 18),
  1744. bysecond=(6, 18),
  1745. dtstart=datetime(1997, 9, 2, 9, 0))),
  1746. [datetime(1997, 9, 2, 9, 6, 6),
  1747. datetime(1997, 9, 2, 9, 6, 18),
  1748. datetime(1997, 9, 2, 9, 18, 6)])
  1749. def testMinutelyByHourAndMinuteAndSecond(self):
  1750. self.assertEqual(list(rrule(MINUTELY,
  1751. count=3,
  1752. byhour=(6, 18),
  1753. byminute=(6, 18),
  1754. bysecond=(6, 18),
  1755. dtstart=datetime(1997, 9, 2, 9, 0))),
  1756. [datetime(1997, 9, 2, 18, 6, 6),
  1757. datetime(1997, 9, 2, 18, 6, 18),
  1758. datetime(1997, 9, 2, 18, 18, 6)])
  1759. def testMinutelyBySetPos(self):
  1760. self.assertEqual(list(rrule(MINUTELY,
  1761. count=3,
  1762. bysecond=(15, 30, 45),
  1763. bysetpos=(3, -3),
  1764. dtstart=datetime(1997, 9, 2, 9, 0))),
  1765. [datetime(1997, 9, 2, 9, 0, 15),
  1766. datetime(1997, 9, 2, 9, 0, 45),
  1767. datetime(1997, 9, 2, 9, 1, 15)])
  1768. def testSecondly(self):
  1769. self.assertEqual(list(rrule(SECONDLY,
  1770. count=3,
  1771. dtstart=datetime(1997, 9, 2, 9, 0))),
  1772. [datetime(1997, 9, 2, 9, 0, 0),
  1773. datetime(1997, 9, 2, 9, 0, 1),
  1774. datetime(1997, 9, 2, 9, 0, 2)])
  1775. def testSecondlyInterval(self):
  1776. self.assertEqual(list(rrule(SECONDLY,
  1777. count=3,
  1778. interval=2,
  1779. dtstart=datetime(1997, 9, 2, 9, 0))),
  1780. [datetime(1997, 9, 2, 9, 0, 0),
  1781. datetime(1997, 9, 2, 9, 0, 2),
  1782. datetime(1997, 9, 2, 9, 0, 4)])
  1783. def testSecondlyIntervalLarge(self):
  1784. self.assertEqual(list(rrule(SECONDLY,
  1785. count=3,
  1786. interval=90061,
  1787. dtstart=datetime(1997, 9, 2, 9, 0))),
  1788. [datetime(1997, 9, 2, 9, 0, 0),
  1789. datetime(1997, 9, 3, 10, 1, 1),
  1790. datetime(1997, 9, 4, 11, 2, 2)])
  1791. def testSecondlyByMonth(self):
  1792. self.assertEqual(list(rrule(SECONDLY,
  1793. count=3,
  1794. bymonth=(1, 3),
  1795. dtstart=datetime(1997, 9, 2, 9, 0))),
  1796. [datetime(1998, 1, 1, 0, 0, 0),
  1797. datetime(1998, 1, 1, 0, 0, 1),
  1798. datetime(1998, 1, 1, 0, 0, 2)])
  1799. def testSecondlyByMonthDay(self):
  1800. self.assertEqual(list(rrule(SECONDLY,
  1801. count=3,
  1802. bymonthday=(1, 3),
  1803. dtstart=datetime(1997, 9, 2, 9, 0))),
  1804. [datetime(1997, 9, 3, 0, 0, 0),
  1805. datetime(1997, 9, 3, 0, 0, 1),
  1806. datetime(1997, 9, 3, 0, 0, 2)])
  1807. def testSecondlyByMonthAndMonthDay(self):
  1808. self.assertEqual(list(rrule(SECONDLY,
  1809. count=3,
  1810. bymonth=(1, 3),
  1811. bymonthday=(5, 7),
  1812. dtstart=datetime(1997, 9, 2, 9, 0))),
  1813. [datetime(1998, 1, 5, 0, 0, 0),
  1814. datetime(1998, 1, 5, 0, 0, 1),
  1815. datetime(1998, 1, 5, 0, 0, 2)])
  1816. def testSecondlyByWeekDay(self):
  1817. self.assertEqual(list(rrule(SECONDLY,
  1818. count=3,
  1819. byweekday=(TU, TH),
  1820. dtstart=datetime(1997, 9, 2, 9, 0))),
  1821. [datetime(1997, 9, 2, 9, 0, 0),
  1822. datetime(1997, 9, 2, 9, 0, 1),
  1823. datetime(1997, 9, 2, 9, 0, 2)])
  1824. def testSecondlyByNWeekDay(self):
  1825. self.assertEqual(list(rrule(SECONDLY,
  1826. count=3,
  1827. byweekday=(TU(1), TH(-1)),
  1828. dtstart=datetime(1997, 9, 2, 9, 0))),
  1829. [datetime(1997, 9, 2, 9, 0, 0),
  1830. datetime(1997, 9, 2, 9, 0, 1),
  1831. datetime(1997, 9, 2, 9, 0, 2)])
  1832. def testSecondlyByMonthAndWeekDay(self):
  1833. self.assertEqual(list(rrule(SECONDLY,
  1834. count=3,
  1835. bymonth=(1, 3),
  1836. byweekday=(TU, TH),
  1837. dtstart=datetime(1997, 9, 2, 9, 0))),
  1838. [datetime(1998, 1, 1, 0, 0, 0),
  1839. datetime(1998, 1, 1, 0, 0, 1),
  1840. datetime(1998, 1, 1, 0, 0, 2)])
  1841. def testSecondlyByMonthAndNWeekDay(self):
  1842. self.assertEqual(list(rrule(SECONDLY,
  1843. count=3,
  1844. bymonth=(1, 3),
  1845. byweekday=(TU(1), TH(-1)),
  1846. dtstart=datetime(1997, 9, 2, 9, 0))),
  1847. [datetime(1998, 1, 1, 0, 0, 0),
  1848. datetime(1998, 1, 1, 0, 0, 1),
  1849. datetime(1998, 1, 1, 0, 0, 2)])
  1850. def testSecondlyByMonthDayAndWeekDay(self):
  1851. self.assertEqual(list(rrule(SECONDLY,
  1852. count=3,
  1853. bymonthday=(1, 3),
  1854. byweekday=(TU, TH),
  1855. dtstart=datetime(1997, 9, 2, 9, 0))),
  1856. [datetime(1998, 1, 1, 0, 0, 0),
  1857. datetime(1998, 1, 1, 0, 0, 1),
  1858. datetime(1998, 1, 1, 0, 0, 2)])
  1859. def testSecondlyByMonthAndMonthDayAndWeekDay(self):
  1860. self.assertEqual(list(rrule(SECONDLY,
  1861. count=3,
  1862. bymonth=(1, 3),
  1863. bymonthday=(1, 3),
  1864. byweekday=(TU, TH),
  1865. dtstart=datetime(1997, 9, 2, 9, 0))),
  1866. [datetime(1998, 1, 1, 0, 0, 0),
  1867. datetime(1998, 1, 1, 0, 0, 1),
  1868. datetime(1998, 1, 1, 0, 0, 2)])
  1869. def testSecondlyByYearDay(self):
  1870. self.assertEqual(list(rrule(SECONDLY,
  1871. count=4,
  1872. byyearday=(1, 100, 200, 365),
  1873. dtstart=datetime(1997, 9, 2, 9, 0))),
  1874. [datetime(1997, 12, 31, 0, 0, 0),
  1875. datetime(1997, 12, 31, 0, 0, 1),
  1876. datetime(1997, 12, 31, 0, 0, 2),
  1877. datetime(1997, 12, 31, 0, 0, 3)])
  1878. def testSecondlyByYearDayNeg(self):
  1879. self.assertEqual(list(rrule(SECONDLY,
  1880. count=4,
  1881. byyearday=(-365, -266, -166, -1),
  1882. dtstart=datetime(1997, 9, 2, 9, 0))),
  1883. [datetime(1997, 12, 31, 0, 0, 0),
  1884. datetime(1997, 12, 31, 0, 0, 1),
  1885. datetime(1997, 12, 31, 0, 0, 2),
  1886. datetime(1997, 12, 31, 0, 0, 3)])
  1887. def testSecondlyByMonthAndYearDay(self):
  1888. self.assertEqual(list(rrule(SECONDLY,
  1889. count=4,
  1890. bymonth=(4, 7),
  1891. byyearday=(1, 100, 200, 365),
  1892. dtstart=datetime(1997, 9, 2, 9, 0))),
  1893. [datetime(1998, 4, 10, 0, 0, 0),
  1894. datetime(1998, 4, 10, 0, 0, 1),
  1895. datetime(1998, 4, 10, 0, 0, 2),
  1896. datetime(1998, 4, 10, 0, 0, 3)])
  1897. def testSecondlyByMonthAndYearDayNeg(self):
  1898. self.assertEqual(list(rrule(SECONDLY,
  1899. count=4,
  1900. bymonth=(4, 7),
  1901. byyearday=(-365, -266, -166, -1),
  1902. dtstart=datetime(1997, 9, 2, 9, 0))),
  1903. [datetime(1998, 4, 10, 0, 0, 0),
  1904. datetime(1998, 4, 10, 0, 0, 1),
  1905. datetime(1998, 4, 10, 0, 0, 2),
  1906. datetime(1998, 4, 10, 0, 0, 3)])
  1907. def testSecondlyByWeekNo(self):
  1908. self.assertEqual(list(rrule(SECONDLY,
  1909. count=3,
  1910. byweekno=20,
  1911. dtstart=datetime(1997, 9, 2, 9, 0))),
  1912. [datetime(1998, 5, 11, 0, 0, 0),
  1913. datetime(1998, 5, 11, 0, 0, 1),
  1914. datetime(1998, 5, 11, 0, 0, 2)])
  1915. def testSecondlyByWeekNoAndWeekDay(self):
  1916. self.assertEqual(list(rrule(SECONDLY,
  1917. count=3,
  1918. byweekno=1,
  1919. byweekday=MO,
  1920. dtstart=datetime(1997, 9, 2, 9, 0))),
  1921. [datetime(1997, 12, 29, 0, 0, 0),
  1922. datetime(1997, 12, 29, 0, 0, 1),
  1923. datetime(1997, 12, 29, 0, 0, 2)])
  1924. def testSecondlyByWeekNoAndWeekDayLarge(self):
  1925. self.assertEqual(list(rrule(SECONDLY,
  1926. count=3,
  1927. byweekno=52,
  1928. byweekday=SU,
  1929. dtstart=datetime(1997, 9, 2, 9, 0))),
  1930. [datetime(1997, 12, 28, 0, 0, 0),
  1931. datetime(1997, 12, 28, 0, 0, 1),
  1932. datetime(1997, 12, 28, 0, 0, 2)])
  1933. def testSecondlyByWeekNoAndWeekDayLast(self):
  1934. self.assertEqual(list(rrule(SECONDLY,
  1935. count=3,
  1936. byweekno=-1,
  1937. byweekday=SU,
  1938. dtstart=datetime(1997, 9, 2, 9, 0))),
  1939. [datetime(1997, 12, 28, 0, 0, 0),
  1940. datetime(1997, 12, 28, 0, 0, 1),
  1941. datetime(1997, 12, 28, 0, 0, 2)])
  1942. def testSecondlyByWeekNoAndWeekDay53(self):
  1943. self.assertEqual(list(rrule(SECONDLY,
  1944. count=3,
  1945. byweekno=53,
  1946. byweekday=MO,
  1947. dtstart=datetime(1997, 9, 2, 9, 0))),
  1948. [datetime(1998, 12, 28, 0, 0, 0),
  1949. datetime(1998, 12, 28, 0, 0, 1),
  1950. datetime(1998, 12, 28, 0, 0, 2)])
  1951. def testSecondlyByEaster(self):
  1952. self.assertEqual(list(rrule(SECONDLY,
  1953. count=3,
  1954. byeaster=0,
  1955. dtstart=datetime(1997, 9, 2, 9, 0))),
  1956. [datetime(1998, 4, 12, 0, 0, 0),
  1957. datetime(1998, 4, 12, 0, 0, 1),
  1958. datetime(1998, 4, 12, 0, 0, 2)])
  1959. def testSecondlyByEasterPos(self):
  1960. self.assertEqual(list(rrule(SECONDLY,
  1961. count=3,
  1962. byeaster=1,
  1963. dtstart=datetime(1997, 9, 2, 9, 0))),
  1964. [datetime(1998, 4, 13, 0, 0, 0),
  1965. datetime(1998, 4, 13, 0, 0, 1),
  1966. datetime(1998, 4, 13, 0, 0, 2)])
  1967. def testSecondlyByEasterNeg(self):
  1968. self.assertEqual(list(rrule(SECONDLY,
  1969. count=3,
  1970. byeaster=-1,
  1971. dtstart=datetime(1997, 9, 2, 9, 0))),
  1972. [datetime(1998, 4, 11, 0, 0, 0),
  1973. datetime(1998, 4, 11, 0, 0, 1),
  1974. datetime(1998, 4, 11, 0, 0, 2)])
  1975. def testSecondlyByHour(self):
  1976. self.assertEqual(list(rrule(SECONDLY,
  1977. count=3,
  1978. byhour=(6, 18),
  1979. dtstart=datetime(1997, 9, 2, 9, 0))),
  1980. [datetime(1997, 9, 2, 18, 0, 0),
  1981. datetime(1997, 9, 2, 18, 0, 1),
  1982. datetime(1997, 9, 2, 18, 0, 2)])
  1983. def testSecondlyByMinute(self):
  1984. self.assertEqual(list(rrule(SECONDLY,
  1985. count=3,
  1986. byminute=(6, 18),
  1987. dtstart=datetime(1997, 9, 2, 9, 0))),
  1988. [datetime(1997, 9, 2, 9, 6, 0),
  1989. datetime(1997, 9, 2, 9, 6, 1),
  1990. datetime(1997, 9, 2, 9, 6, 2)])
  1991. def testSecondlyBySecond(self):
  1992. self.assertEqual(list(rrule(SECONDLY,
  1993. count=3,
  1994. bysecond=(6, 18),
  1995. dtstart=datetime(1997, 9, 2, 9, 0))),
  1996. [datetime(1997, 9, 2, 9, 0, 6),
  1997. datetime(1997, 9, 2, 9, 0, 18),
  1998. datetime(1997, 9, 2, 9, 1, 6)])
  1999. def testSecondlyByHourAndMinute(self):
  2000. self.assertEqual(list(rrule(SECONDLY,
  2001. count=3,
  2002. byhour=(6, 18),
  2003. byminute=(6, 18),
  2004. dtstart=datetime(1997, 9, 2, 9, 0))),
  2005. [datetime(1997, 9, 2, 18, 6, 0),
  2006. datetime(1997, 9, 2, 18, 6, 1),
  2007. datetime(1997, 9, 2, 18, 6, 2)])
  2008. def testSecondlyByHourAndSecond(self):
  2009. self.assertEqual(list(rrule(SECONDLY,
  2010. count=3,
  2011. byhour=(6, 18),
  2012. bysecond=(6, 18),
  2013. dtstart=datetime(1997, 9, 2, 9, 0))),
  2014. [datetime(1997, 9, 2, 18, 0, 6),
  2015. datetime(1997, 9, 2, 18, 0, 18),
  2016. datetime(1997, 9, 2, 18, 1, 6)])
  2017. def testSecondlyByMinuteAndSecond(self):
  2018. self.assertEqual(list(rrule(SECONDLY,
  2019. count=3,
  2020. byminute=(6, 18),
  2021. bysecond=(6, 18),
  2022. dtstart=datetime(1997, 9, 2, 9, 0))),
  2023. [datetime(1997, 9, 2, 9, 6, 6),
  2024. datetime(1997, 9, 2, 9, 6, 18),
  2025. datetime(1997, 9, 2, 9, 18, 6)])
  2026. def testSecondlyByHourAndMinuteAndSecond(self):
  2027. self.assertEqual(list(rrule(SECONDLY,
  2028. count=3,
  2029. byhour=(6, 18),
  2030. byminute=(6, 18),
  2031. bysecond=(6, 18),
  2032. dtstart=datetime(1997, 9, 2, 9, 0))),
  2033. [datetime(1997, 9, 2, 18, 6, 6),
  2034. datetime(1997, 9, 2, 18, 6, 18),
  2035. datetime(1997, 9, 2, 18, 18, 6)])
  2036. def testSecondlyByHourAndMinuteAndSecondBug(self):
  2037. # This explores a bug found by Mathieu Bridon.
  2038. self.assertEqual(list(rrule(SECONDLY,
  2039. count=3,
  2040. bysecond=(0,),
  2041. byminute=(1,),
  2042. dtstart=datetime(2010, 3, 22, 12, 1))),
  2043. [datetime(2010, 3, 22, 12, 1),
  2044. datetime(2010, 3, 22, 13, 1),
  2045. datetime(2010, 3, 22, 14, 1)])
  2046. def testLongIntegers(self):
  2047. if PY2: # There are no longs in python3
  2048. self.assertEqual(list(rrule(MINUTELY,
  2049. count=long(2),
  2050. interval=long(2),
  2051. bymonth=long(2),
  2052. byweekday=long(3),
  2053. byhour=long(6),
  2054. byminute=long(6),
  2055. bysecond=long(6),
  2056. dtstart=datetime(1997, 9, 2, 9, 0))),
  2057. [datetime(1998, 2, 5, 6, 6, 6),
  2058. datetime(1998, 2, 12, 6, 6, 6)])
  2059. self.assertEqual(list(rrule(YEARLY,
  2060. count=long(2),
  2061. bymonthday=long(5),
  2062. byweekno=long(2),
  2063. dtstart=datetime(1997, 9, 2, 9, 0))),
  2064. [datetime(1998, 1, 5, 9, 0),
  2065. datetime(2004, 1, 5, 9, 0)])
  2066. def testHourlyBadRRule(self):
  2067. """
  2068. When `byhour` is specified with `freq=HOURLY`, there are certain
  2069. combinations of `dtstart` and `byhour` which result in an rrule with no
  2070. valid values.
  2071. See https://github.com/dateutil/dateutil/issues/4
  2072. """
  2073. self.assertRaises(ValueError, rrule, HOURLY,
  2074. **dict(interval=4, byhour=(7, 11, 15, 19),
  2075. dtstart=datetime(1997, 9, 2, 9, 0)))
  2076. def testMinutelyBadRRule(self):
  2077. """
  2078. See :func:`testHourlyBadRRule` for details.
  2079. """
  2080. self.assertRaises(ValueError, rrule, MINUTELY,
  2081. **dict(interval=12, byminute=(10, 11, 25, 39, 50),
  2082. dtstart=datetime(1997, 9, 2, 9, 0)))
  2083. def testSecondlyBadRRule(self):
  2084. """
  2085. See :func:`testHourlyBadRRule` for details.
  2086. """
  2087. self.assertRaises(ValueError, rrule, SECONDLY,
  2088. **dict(interval=10, bysecond=(2, 15, 37, 42, 59),
  2089. dtstart=datetime(1997, 9, 2, 9, 0)))
  2090. def testMinutelyBadComboRRule(self):
  2091. """
  2092. Certain values of :param:`interval` in :class:`rrule`, when combined
  2093. with certain values of :param:`byhour` create rules which apply to no
  2094. valid dates. The library should detect this case in the iterator and
  2095. raise a :exception:`ValueError`.
  2096. """
  2097. # In Python 2.7 you can use a context manager for this.
  2098. def make_bad_rrule():
  2099. list(rrule(MINUTELY, interval=120, byhour=(10, 12, 14, 16),
  2100. count=2, dtstart=datetime(1997, 9, 2, 9, 0)))
  2101. self.assertRaises(ValueError, make_bad_rrule)
  2102. def testSecondlyBadComboRRule(self):
  2103. """
  2104. See :func:`testMinutelyBadComboRRule' for details.
  2105. """
  2106. # In Python 2.7 you can use a context manager for this.
  2107. def make_bad_minute_rrule():
  2108. list(rrule(SECONDLY, interval=360, byminute=(10, 28, 49),
  2109. count=4, dtstart=datetime(1997, 9, 2, 9, 0)))
  2110. def make_bad_hour_rrule():
  2111. list(rrule(SECONDLY, interval=43200, byhour=(2, 10, 18, 23),
  2112. count=4, dtstart=datetime(1997, 9, 2, 9, 0)))
  2113. self.assertRaises(ValueError, make_bad_minute_rrule)
  2114. self.assertRaises(ValueError, make_bad_hour_rrule)
  2115. def testBadUntilCountRRule(self):
  2116. """
  2117. See rfc-5545 3.3.10 - This checks for the deprecation warning, and will
  2118. eventually check for an error.
  2119. """
  2120. with pytest.warns(DeprecationWarning):
  2121. rrule(DAILY, dtstart=datetime(1997, 9, 2, 9, 0),
  2122. count=3, until=datetime(1997, 9, 4, 9, 0))
  2123. def testUntilNotMatching(self):
  2124. self.assertEqual(list(rrule(DAILY,
  2125. dtstart=datetime(1997, 9, 2, 9, 0),
  2126. until=datetime(1997, 9, 5, 8, 0))),
  2127. [datetime(1997, 9, 2, 9, 0),
  2128. datetime(1997, 9, 3, 9, 0),
  2129. datetime(1997, 9, 4, 9, 0)])
  2130. def testUntilMatching(self):
  2131. self.assertEqual(list(rrule(DAILY,
  2132. dtstart=datetime(1997, 9, 2, 9, 0),
  2133. until=datetime(1997, 9, 4, 9, 0))),
  2134. [datetime(1997, 9, 2, 9, 0),
  2135. datetime(1997, 9, 3, 9, 0),
  2136. datetime(1997, 9, 4, 9, 0)])
  2137. def testUntilSingle(self):
  2138. self.assertEqual(list(rrule(DAILY,
  2139. dtstart=datetime(1997, 9, 2, 9, 0),
  2140. until=datetime(1997, 9, 2, 9, 0))),
  2141. [datetime(1997, 9, 2, 9, 0)])
  2142. def testUntilEmpty(self):
  2143. self.assertEqual(list(rrule(DAILY,
  2144. dtstart=datetime(1997, 9, 2, 9, 0),
  2145. until=datetime(1997, 9, 1, 9, 0))),
  2146. [])
  2147. def testUntilWithDate(self):
  2148. self.assertEqual(list(rrule(DAILY,
  2149. dtstart=datetime(1997, 9, 2, 9, 0),
  2150. until=date(1997, 9, 5))),
  2151. [datetime(1997, 9, 2, 9, 0),
  2152. datetime(1997, 9, 3, 9, 0),
  2153. datetime(1997, 9, 4, 9, 0)])
  2154. def testWkStIntervalMO(self):
  2155. self.assertEqual(list(rrule(WEEKLY,
  2156. count=3,
  2157. interval=2,
  2158. byweekday=(TU, SU),
  2159. wkst=MO,
  2160. dtstart=datetime(1997, 9, 2, 9, 0))),
  2161. [datetime(1997, 9, 2, 9, 0),
  2162. datetime(1997, 9, 7, 9, 0),
  2163. datetime(1997, 9, 16, 9, 0)])
  2164. def testWkStIntervalSU(self):
  2165. self.assertEqual(list(rrule(WEEKLY,
  2166. count=3,
  2167. interval=2,
  2168. byweekday=(TU, SU),
  2169. wkst=SU,
  2170. dtstart=datetime(1997, 9, 2, 9, 0))),
  2171. [datetime(1997, 9, 2, 9, 0),
  2172. datetime(1997, 9, 14, 9, 0),
  2173. datetime(1997, 9, 16, 9, 0)])
  2174. def testDTStartIsDate(self):
  2175. self.assertEqual(list(rrule(DAILY,
  2176. count=3,
  2177. dtstart=date(1997, 9, 2))),
  2178. [datetime(1997, 9, 2, 0, 0),
  2179. datetime(1997, 9, 3, 0, 0),
  2180. datetime(1997, 9, 4, 0, 0)])
  2181. def testDTStartWithMicroseconds(self):
  2182. self.assertEqual(list(rrule(DAILY,
  2183. count=3,
  2184. dtstart=datetime(1997, 9, 2, 9, 0, 0, 500000))),
  2185. [datetime(1997, 9, 2, 9, 0),
  2186. datetime(1997, 9, 3, 9, 0),
  2187. datetime(1997, 9, 4, 9, 0)])
  2188. def testMaxYear(self):
  2189. self.assertEqual(list(rrule(YEARLY,
  2190. count=3,
  2191. bymonth=2,
  2192. bymonthday=31,
  2193. dtstart=datetime(9997, 9, 2, 9, 0, 0))),
  2194. [])
  2195. def testGetItem(self):
  2196. self.assertEqual(rrule(DAILY,
  2197. count=3,
  2198. dtstart=datetime(1997, 9, 2, 9, 0))[0],
  2199. datetime(1997, 9, 2, 9, 0))
  2200. def testGetItemNeg(self):
  2201. self.assertEqual(rrule(DAILY,
  2202. count=3,
  2203. dtstart=datetime(1997, 9, 2, 9, 0))[-1],
  2204. datetime(1997, 9, 4, 9, 0))
  2205. def testGetItemSlice(self):
  2206. self.assertEqual(rrule(DAILY,
  2207. # count=3,
  2208. dtstart=datetime(1997, 9, 2, 9, 0))[1:2],
  2209. [datetime(1997, 9, 3, 9, 0)])
  2210. def testGetItemSliceEmpty(self):
  2211. self.assertEqual(rrule(DAILY,
  2212. count=3,
  2213. dtstart=datetime(1997, 9, 2, 9, 0))[:],
  2214. [datetime(1997, 9, 2, 9, 0),
  2215. datetime(1997, 9, 3, 9, 0),
  2216. datetime(1997, 9, 4, 9, 0)])
  2217. def testGetItemSliceStep(self):
  2218. self.assertEqual(rrule(DAILY,
  2219. count=3,
  2220. dtstart=datetime(1997, 9, 2, 9, 0))[::-2],
  2221. [datetime(1997, 9, 4, 9, 0),
  2222. datetime(1997, 9, 2, 9, 0)])
  2223. def testCount(self):
  2224. self.assertEqual(rrule(DAILY,
  2225. count=3,
  2226. dtstart=datetime(1997, 9, 2, 9, 0)).count(),
  2227. 3)
  2228. def testCountZero(self):
  2229. self.assertEqual(rrule(YEARLY,
  2230. count=0,
  2231. dtstart=datetime(1997, 9, 2, 9, 0)).count(),
  2232. 0)
  2233. def testContains(self):
  2234. rr = rrule(DAILY, count=3, dtstart=datetime(1997, 9, 2, 9, 0))
  2235. self.assertEqual(datetime(1997, 9, 3, 9, 0) in rr, True)
  2236. def testContainsNot(self):
  2237. rr = rrule(DAILY, count=3, dtstart=datetime(1997, 9, 2, 9, 0))
  2238. self.assertEqual(datetime(1997, 9, 3, 9, 0) not in rr, False)
  2239. def testBefore(self):
  2240. self.assertEqual(rrule(DAILY, # count=5
  2241. dtstart=datetime(1997, 9, 2, 9, 0)).before(datetime(1997, 9, 5, 9, 0)),
  2242. datetime(1997, 9, 4, 9, 0))
  2243. def testBeforeInc(self):
  2244. self.assertEqual(rrule(DAILY,
  2245. #count=5,
  2246. dtstart=datetime(1997, 9, 2, 9, 0))
  2247. .before(datetime(1997, 9, 5, 9, 0), inc=True),
  2248. datetime(1997, 9, 5, 9, 0))
  2249. def testAfter(self):
  2250. self.assertEqual(rrule(DAILY,
  2251. #count=5,
  2252. dtstart=datetime(1997, 9, 2, 9, 0))
  2253. .after(datetime(1997, 9, 4, 9, 0)),
  2254. datetime(1997, 9, 5, 9, 0))
  2255. def testAfterInc(self):
  2256. self.assertEqual(rrule(DAILY,
  2257. #count=5,
  2258. dtstart=datetime(1997, 9, 2, 9, 0))
  2259. .after(datetime(1997, 9, 4, 9, 0), inc=True),
  2260. datetime(1997, 9, 4, 9, 0))
  2261. def testXAfter(self):
  2262. self.assertEqual(list(rrule(DAILY,
  2263. dtstart=datetime(1997, 9, 2, 9, 0))
  2264. .xafter(datetime(1997, 9, 8, 9, 0), count=12)),
  2265. [datetime(1997, 9, 9, 9, 0),
  2266. datetime(1997, 9, 10, 9, 0),
  2267. datetime(1997, 9, 11, 9, 0),
  2268. datetime(1997, 9, 12, 9, 0),
  2269. datetime(1997, 9, 13, 9, 0),
  2270. datetime(1997, 9, 14, 9, 0),
  2271. datetime(1997, 9, 15, 9, 0),
  2272. datetime(1997, 9, 16, 9, 0),
  2273. datetime(1997, 9, 17, 9, 0),
  2274. datetime(1997, 9, 18, 9, 0),
  2275. datetime(1997, 9, 19, 9, 0),
  2276. datetime(1997, 9, 20, 9, 0)])
  2277. def testXAfterInc(self):
  2278. self.assertEqual(list(rrule(DAILY,
  2279. dtstart=datetime(1997, 9, 2, 9, 0))
  2280. .xafter(datetime(1997, 9, 8, 9, 0), count=12, inc=True)),
  2281. [datetime(1997, 9, 8, 9, 0),
  2282. datetime(1997, 9, 9, 9, 0),
  2283. datetime(1997, 9, 10, 9, 0),
  2284. datetime(1997, 9, 11, 9, 0),
  2285. datetime(1997, 9, 12, 9, 0),
  2286. datetime(1997, 9, 13, 9, 0),
  2287. datetime(1997, 9, 14, 9, 0),
  2288. datetime(1997, 9, 15, 9, 0),
  2289. datetime(1997, 9, 16, 9, 0),
  2290. datetime(1997, 9, 17, 9, 0),
  2291. datetime(1997, 9, 18, 9, 0),
  2292. datetime(1997, 9, 19, 9, 0)])
  2293. def testBetween(self):
  2294. self.assertEqual(rrule(DAILY,
  2295. #count=5,
  2296. dtstart=datetime(1997, 9, 2, 9, 0))
  2297. .between(datetime(1997, 9, 2, 9, 0),
  2298. datetime(1997, 9, 6, 9, 0)),
  2299. [datetime(1997, 9, 3, 9, 0),
  2300. datetime(1997, 9, 4, 9, 0),
  2301. datetime(1997, 9, 5, 9, 0)])
  2302. def testBetweenInc(self):
  2303. self.assertEqual(rrule(DAILY,
  2304. #count=5,
  2305. dtstart=datetime(1997, 9, 2, 9, 0))
  2306. .between(datetime(1997, 9, 2, 9, 0),
  2307. datetime(1997, 9, 6, 9, 0), inc=True),
  2308. [datetime(1997, 9, 2, 9, 0),
  2309. datetime(1997, 9, 3, 9, 0),
  2310. datetime(1997, 9, 4, 9, 0),
  2311. datetime(1997, 9, 5, 9, 0),
  2312. datetime(1997, 9, 6, 9, 0)])
  2313. def testCachePre(self):
  2314. rr = rrule(DAILY, count=15, cache=True,
  2315. dtstart=datetime(1997, 9, 2, 9, 0))
  2316. self.assertEqual(list(rr),
  2317. [datetime(1997, 9, 2, 9, 0),
  2318. datetime(1997, 9, 3, 9, 0),
  2319. datetime(1997, 9, 4, 9, 0),
  2320. datetime(1997, 9, 5, 9, 0),
  2321. datetime(1997, 9, 6, 9, 0),
  2322. datetime(1997, 9, 7, 9, 0),
  2323. datetime(1997, 9, 8, 9, 0),
  2324. datetime(1997, 9, 9, 9, 0),
  2325. datetime(1997, 9, 10, 9, 0),
  2326. datetime(1997, 9, 11, 9, 0),
  2327. datetime(1997, 9, 12, 9, 0),
  2328. datetime(1997, 9, 13, 9, 0),
  2329. datetime(1997, 9, 14, 9, 0),
  2330. datetime(1997, 9, 15, 9, 0),
  2331. datetime(1997, 9, 16, 9, 0)])
  2332. def testCachePost(self):
  2333. rr = rrule(DAILY, count=15, cache=True,
  2334. dtstart=datetime(1997, 9, 2, 9, 0))
  2335. for x in rr: pass
  2336. self.assertEqual(list(rr),
  2337. [datetime(1997, 9, 2, 9, 0),
  2338. datetime(1997, 9, 3, 9, 0),
  2339. datetime(1997, 9, 4, 9, 0),
  2340. datetime(1997, 9, 5, 9, 0),
  2341. datetime(1997, 9, 6, 9, 0),
  2342. datetime(1997, 9, 7, 9, 0),
  2343. datetime(1997, 9, 8, 9, 0),
  2344. datetime(1997, 9, 9, 9, 0),
  2345. datetime(1997, 9, 10, 9, 0),
  2346. datetime(1997, 9, 11, 9, 0),
  2347. datetime(1997, 9, 12, 9, 0),
  2348. datetime(1997, 9, 13, 9, 0),
  2349. datetime(1997, 9, 14, 9, 0),
  2350. datetime(1997, 9, 15, 9, 0),
  2351. datetime(1997, 9, 16, 9, 0)])
  2352. def testCachePostInternal(self):
  2353. rr = rrule(DAILY, count=15, cache=True,
  2354. dtstart=datetime(1997, 9, 2, 9, 0))
  2355. for x in rr: pass
  2356. self.assertEqual(rr._cache,
  2357. [datetime(1997, 9, 2, 9, 0),
  2358. datetime(1997, 9, 3, 9, 0),
  2359. datetime(1997, 9, 4, 9, 0),
  2360. datetime(1997, 9, 5, 9, 0),
  2361. datetime(1997, 9, 6, 9, 0),
  2362. datetime(1997, 9, 7, 9, 0),
  2363. datetime(1997, 9, 8, 9, 0),
  2364. datetime(1997, 9, 9, 9, 0),
  2365. datetime(1997, 9, 10, 9, 0),
  2366. datetime(1997, 9, 11, 9, 0),
  2367. datetime(1997, 9, 12, 9, 0),
  2368. datetime(1997, 9, 13, 9, 0),
  2369. datetime(1997, 9, 14, 9, 0),
  2370. datetime(1997, 9, 15, 9, 0),
  2371. datetime(1997, 9, 16, 9, 0)])
  2372. def testCachePreContains(self):
  2373. rr = rrule(DAILY, count=3, cache=True,
  2374. dtstart=datetime(1997, 9, 2, 9, 0))
  2375. self.assertEqual(datetime(1997, 9, 3, 9, 0) in rr, True)
  2376. def testCachePostContains(self):
  2377. rr = rrule(DAILY, count=3, cache=True,
  2378. dtstart=datetime(1997, 9, 2, 9, 0))
  2379. for x in rr: pass
  2380. self.assertEqual(datetime(1997, 9, 3, 9, 0) in rr, True)
  2381. def testStr(self):
  2382. self.assertEqual(list(rrulestr(
  2383. "DTSTART:19970902T090000\n"
  2384. "RRULE:FREQ=YEARLY;COUNT=3\n"
  2385. )),
  2386. [datetime(1997, 9, 2, 9, 0),
  2387. datetime(1998, 9, 2, 9, 0),
  2388. datetime(1999, 9, 2, 9, 0)])
  2389. def testStrWithTZID(self):
  2390. NYC = tz.gettz('America/New_York')
  2391. self.assertEqual(list(rrulestr(
  2392. "DTSTART;TZID=America/New_York:19970902T090000\n"
  2393. "RRULE:FREQ=YEARLY;COUNT=3\n"
  2394. )),
  2395. [datetime(1997, 9, 2, 9, 0, tzinfo=NYC),
  2396. datetime(1998, 9, 2, 9, 0, tzinfo=NYC),
  2397. datetime(1999, 9, 2, 9, 0, tzinfo=NYC)])
  2398. def testStrWithTZIDMapping(self):
  2399. rrstr = ("DTSTART;TZID=Eastern:19970902T090000\n" +
  2400. "RRULE:FREQ=YEARLY;COUNT=3")
  2401. NYC = tz.gettz('America/New_York')
  2402. rr = rrulestr(rrstr, tzids={'Eastern': NYC})
  2403. exp = [datetime(1997, 9, 2, 9, 0, tzinfo=NYC),
  2404. datetime(1998, 9, 2, 9, 0, tzinfo=NYC),
  2405. datetime(1999, 9, 2, 9, 0, tzinfo=NYC)]
  2406. self.assertEqual(list(rr), exp)
  2407. def testStrWithTZIDCallable(self):
  2408. rrstr = ('DTSTART;TZID=UTC+04:19970902T090000\n' +
  2409. 'RRULE:FREQ=YEARLY;COUNT=3')
  2410. TZ = tz.tzstr('UTC+04')
  2411. def parse_tzstr(tzstr):
  2412. if tzstr is None:
  2413. raise ValueError('Invalid tzstr')
  2414. return tz.tzstr(tzstr)
  2415. rr = rrulestr(rrstr, tzids=parse_tzstr)
  2416. exp = [datetime(1997, 9, 2, 9, 0, tzinfo=TZ),
  2417. datetime(1998, 9, 2, 9, 0, tzinfo=TZ),
  2418. datetime(1999, 9, 2, 9, 0, tzinfo=TZ),]
  2419. self.assertEqual(list(rr), exp)
  2420. def testStrWithTZIDCallableFailure(self):
  2421. rrstr = ('DTSTART;TZID=America/New_York:19970902T090000\n' +
  2422. 'RRULE:FREQ=YEARLY;COUNT=3')
  2423. class TzInfoError(Exception):
  2424. pass
  2425. def tzinfos(tzstr):
  2426. if tzstr == 'America/New_York':
  2427. raise TzInfoError('Invalid!')
  2428. return None
  2429. with self.assertRaises(TzInfoError):
  2430. rrulestr(rrstr, tzids=tzinfos)
  2431. def testStrWithConflictingTZID(self):
  2432. # RFC 5545 Section 3.3.5, FORM #2: DATE WITH UTC TIME
  2433. # https://tools.ietf.org/html/rfc5545#section-3.3.5
  2434. # The "TZID" property parameter MUST NOT be applied to DATE-TIME
  2435. with self.assertRaises(ValueError):
  2436. rrulestr("DTSTART;TZID=America/New_York:19970902T090000Z\n"+
  2437. "RRULE:FREQ=YEARLY;COUNT=3\n")
  2438. def testStrType(self):
  2439. self.assertEqual(isinstance(rrulestr(
  2440. "DTSTART:19970902T090000\n"
  2441. "RRULE:FREQ=YEARLY;COUNT=3\n"
  2442. ), rrule), True)
  2443. def testStrForceSetType(self):
  2444. self.assertEqual(isinstance(rrulestr(
  2445. "DTSTART:19970902T090000\n"
  2446. "RRULE:FREQ=YEARLY;COUNT=3\n"
  2447. , forceset=True), rruleset), True)
  2448. def testStrSetType(self):
  2449. self.assertEqual(isinstance(rrulestr(
  2450. "DTSTART:19970902T090000\n"
  2451. "RRULE:FREQ=YEARLY;COUNT=2;BYDAY=TU\n"
  2452. "RRULE:FREQ=YEARLY;COUNT=1;BYDAY=TH\n"
  2453. ), rruleset), True)
  2454. def testStrCase(self):
  2455. self.assertEqual(list(rrulestr(
  2456. "dtstart:19970902T090000\n"
  2457. "rrule:freq=yearly;count=3\n"
  2458. )),
  2459. [datetime(1997, 9, 2, 9, 0),
  2460. datetime(1998, 9, 2, 9, 0),
  2461. datetime(1999, 9, 2, 9, 0)])
  2462. def testStrSpaces(self):
  2463. self.assertEqual(list(rrulestr(
  2464. " DTSTART:19970902T090000 "
  2465. " RRULE:FREQ=YEARLY;COUNT=3 "
  2466. )),
  2467. [datetime(1997, 9, 2, 9, 0),
  2468. datetime(1998, 9, 2, 9, 0),
  2469. datetime(1999, 9, 2, 9, 0)])
  2470. def testStrSpacesAndLines(self):
  2471. self.assertEqual(list(rrulestr(
  2472. " DTSTART:19970902T090000 \n"
  2473. " \n"
  2474. " RRULE:FREQ=YEARLY;COUNT=3 \n"
  2475. )),
  2476. [datetime(1997, 9, 2, 9, 0),
  2477. datetime(1998, 9, 2, 9, 0),
  2478. datetime(1999, 9, 2, 9, 0)])
  2479. def testStrNoDTStart(self):
  2480. self.assertEqual(list(rrulestr(
  2481. "RRULE:FREQ=YEARLY;COUNT=3\n"
  2482. , dtstart=datetime(1997, 9, 2, 9, 0))),
  2483. [datetime(1997, 9, 2, 9, 0),
  2484. datetime(1998, 9, 2, 9, 0),
  2485. datetime(1999, 9, 2, 9, 0)])
  2486. def testStrValueOnly(self):
  2487. self.assertEqual(list(rrulestr(
  2488. "FREQ=YEARLY;COUNT=3\n"
  2489. , dtstart=datetime(1997, 9, 2, 9, 0))),
  2490. [datetime(1997, 9, 2, 9, 0),
  2491. datetime(1998, 9, 2, 9, 0),
  2492. datetime(1999, 9, 2, 9, 0)])
  2493. def testStrUnfold(self):
  2494. self.assertEqual(list(rrulestr(
  2495. "FREQ=YEA\n RLY;COUNT=3\n", unfold=True,
  2496. dtstart=datetime(1997, 9, 2, 9, 0))),
  2497. [datetime(1997, 9, 2, 9, 0),
  2498. datetime(1998, 9, 2, 9, 0),
  2499. datetime(1999, 9, 2, 9, 0)])
  2500. def testStrSet(self):
  2501. self.assertEqual(list(rrulestr(
  2502. "DTSTART:19970902T090000\n"
  2503. "RRULE:FREQ=YEARLY;COUNT=2;BYDAY=TU\n"
  2504. "RRULE:FREQ=YEARLY;COUNT=1;BYDAY=TH\n"
  2505. )),
  2506. [datetime(1997, 9, 2, 9, 0),
  2507. datetime(1997, 9, 4, 9, 0),
  2508. datetime(1997, 9, 9, 9, 0)])
  2509. def testStrSetDate(self):
  2510. self.assertEqual(list(rrulestr(
  2511. "DTSTART:19970902T090000\n"
  2512. "RRULE:FREQ=YEARLY;COUNT=1;BYDAY=TU\n"
  2513. "RDATE:19970904T090000\n"
  2514. "RDATE:19970909T090000\n"
  2515. )),
  2516. [datetime(1997, 9, 2, 9, 0),
  2517. datetime(1997, 9, 4, 9, 0),
  2518. datetime(1997, 9, 9, 9, 0)])
  2519. def testStrSetExRule(self):
  2520. self.assertEqual(list(rrulestr(
  2521. "DTSTART:19970902T090000\n"
  2522. "RRULE:FREQ=YEARLY;COUNT=6;BYDAY=TU,TH\n"
  2523. "EXRULE:FREQ=YEARLY;COUNT=3;BYDAY=TH\n"
  2524. )),
  2525. [datetime(1997, 9, 2, 9, 0),
  2526. datetime(1997, 9, 9, 9, 0),
  2527. datetime(1997, 9, 16, 9, 0)])
  2528. def testStrSetExDate(self):
  2529. self.assertEqual(list(rrulestr(
  2530. "DTSTART:19970902T090000\n"
  2531. "RRULE:FREQ=YEARLY;COUNT=6;BYDAY=TU,TH\n"
  2532. "EXDATE:19970904T090000\n"
  2533. "EXDATE:19970911T090000\n"
  2534. "EXDATE:19970918T090000\n"
  2535. )),
  2536. [datetime(1997, 9, 2, 9, 0),
  2537. datetime(1997, 9, 9, 9, 0),
  2538. datetime(1997, 9, 16, 9, 0)])
  2539. def testStrSetExDateMultiple(self):
  2540. rrstr = ("DTSTART:19970902T090000\n"
  2541. "RRULE:FREQ=YEARLY;COUNT=6;BYDAY=TU,TH\n"
  2542. "EXDATE:19970904T090000,19970911T090000,19970918T090000\n")
  2543. rr = rrulestr(rrstr)
  2544. assert list(rr) == [datetime(1997, 9, 2, 9, 0),
  2545. datetime(1997, 9, 9, 9, 0),
  2546. datetime(1997, 9, 16, 9, 0)]
  2547. def testStrSetExDateWithTZID(self):
  2548. BXL = tz.gettz('Europe/Brussels')
  2549. rr = rrulestr("DTSTART;TZID=Europe/Brussels:19970902T090000\n"
  2550. "RRULE:FREQ=YEARLY;COUNT=6;BYDAY=TU,TH\n"
  2551. "EXDATE;TZID=Europe/Brussels:19970904T090000\n"
  2552. "EXDATE;TZID=Europe/Brussels:19970911T090000\n"
  2553. "EXDATE;TZID=Europe/Brussels:19970918T090000\n")
  2554. assert list(rr) == [datetime(1997, 9, 2, 9, 0, tzinfo=BXL),
  2555. datetime(1997, 9, 9, 9, 0, tzinfo=BXL),
  2556. datetime(1997, 9, 16, 9, 0, tzinfo=BXL)]
  2557. def testStrSetExDateValueDateTimeNoTZID(self):
  2558. rrstr = '\n'.join([
  2559. "DTSTART:19970902T090000",
  2560. "RRULE:FREQ=YEARLY;COUNT=4;BYDAY=TU,TH",
  2561. "EXDATE;VALUE=DATE-TIME:19970902T090000",
  2562. "EXDATE;VALUE=DATE-TIME:19970909T090000",
  2563. ])
  2564. rr = rrulestr(rrstr)
  2565. assert list(rr) == [datetime(1997, 9, 4, 9), datetime(1997, 9, 11, 9)]
  2566. def testStrSetExDateValueMixDateTimeNoTZID(self):
  2567. rrstr = '\n'.join([
  2568. "DTSTART:19970902T090000",
  2569. "RRULE:FREQ=YEARLY;COUNT=4;BYDAY=TU,TH",
  2570. "EXDATE;VALUE=DATE-TIME:19970902T090000",
  2571. "EXDATE:19970909T090000",
  2572. ])
  2573. rr = rrulestr(rrstr)
  2574. assert list(rr) == [datetime(1997, 9, 4, 9), datetime(1997, 9, 11, 9)]
  2575. def testStrSetExDateValueDateTimeWithTZID(self):
  2576. BXL = tz.gettz('Europe/Brussels')
  2577. rrstr = '\n'.join([
  2578. "DTSTART;VALUE=DATE-TIME;TZID=Europe/Brussels:19970902T090000",
  2579. "RRULE:FREQ=YEARLY;COUNT=4;BYDAY=TU,TH",
  2580. "EXDATE;VALUE=DATE-TIME;TZID=Europe/Brussels:19970902T090000",
  2581. "EXDATE;VALUE=DATE-TIME;TZID=Europe/Brussels:19970909T090000",
  2582. ])
  2583. rr = rrulestr(rrstr)
  2584. assert list(rr) == [datetime(1997, 9, 4, 9, tzinfo=BXL),
  2585. datetime(1997, 9, 11, 9, tzinfo=BXL)]
  2586. def testStrSetExDateValueDate(self):
  2587. rrstr = '\n'.join([
  2588. "DTSTART;VALUE=DATE:19970902",
  2589. "RRULE:FREQ=YEARLY;COUNT=4;BYDAY=TU,TH",
  2590. "EXDATE;VALUE=DATE:19970902",
  2591. "EXDATE;VALUE=DATE:19970909",
  2592. ])
  2593. rr = rrulestr(rrstr)
  2594. assert list(rr) == [datetime(1997, 9, 4), datetime(1997, 9, 11)]
  2595. def testStrSetDateAndExDate(self):
  2596. self.assertEqual(list(rrulestr(
  2597. "DTSTART:19970902T090000\n"
  2598. "RDATE:19970902T090000\n"
  2599. "RDATE:19970904T090000\n"
  2600. "RDATE:19970909T090000\n"
  2601. "RDATE:19970911T090000\n"
  2602. "RDATE:19970916T090000\n"
  2603. "RDATE:19970918T090000\n"
  2604. "EXDATE:19970904T090000\n"
  2605. "EXDATE:19970911T090000\n"
  2606. "EXDATE:19970918T090000\n"
  2607. )),
  2608. [datetime(1997, 9, 2, 9, 0),
  2609. datetime(1997, 9, 9, 9, 0),
  2610. datetime(1997, 9, 16, 9, 0)])
  2611. def testStrSetDateAndExRule(self):
  2612. self.assertEqual(list(rrulestr(
  2613. "DTSTART:19970902T090000\n"
  2614. "RDATE:19970902T090000\n"
  2615. "RDATE:19970904T090000\n"
  2616. "RDATE:19970909T090000\n"
  2617. "RDATE:19970911T090000\n"
  2618. "RDATE:19970916T090000\n"
  2619. "RDATE:19970918T090000\n"
  2620. "EXRULE:FREQ=YEARLY;COUNT=3;BYDAY=TH\n"
  2621. )),
  2622. [datetime(1997, 9, 2, 9, 0),
  2623. datetime(1997, 9, 9, 9, 0),
  2624. datetime(1997, 9, 16, 9, 0)])
  2625. def testStrKeywords(self):
  2626. self.assertEqual(list(rrulestr(
  2627. "DTSTART:19970902T090000\n"
  2628. "RRULE:FREQ=YEARLY;COUNT=3;INTERVAL=3;"
  2629. "BYMONTH=3;BYWEEKDAY=TH;BYMONTHDAY=3;"
  2630. "BYHOUR=3;BYMINUTE=3;BYSECOND=3\n"
  2631. )),
  2632. [datetime(2033, 3, 3, 3, 3, 3),
  2633. datetime(2039, 3, 3, 3, 3, 3),
  2634. datetime(2072, 3, 3, 3, 3, 3)])
  2635. def testStrNWeekDay(self):
  2636. self.assertEqual(list(rrulestr(
  2637. "DTSTART:19970902T090000\n"
  2638. "RRULE:FREQ=YEARLY;COUNT=3;BYDAY=1TU,-1TH\n"
  2639. )),
  2640. [datetime(1997, 12, 25, 9, 0),
  2641. datetime(1998, 1, 6, 9, 0),
  2642. datetime(1998, 12, 31, 9, 0)])
  2643. def testStrUntil(self):
  2644. self.assertEqual(list(rrulestr(
  2645. "DTSTART:19970902T090000\n"
  2646. "RRULE:FREQ=YEARLY;"
  2647. "UNTIL=19990101T000000;BYDAY=1TU,-1TH\n"
  2648. )),
  2649. [datetime(1997, 12, 25, 9, 0),
  2650. datetime(1998, 1, 6, 9, 0),
  2651. datetime(1998, 12, 31, 9, 0)])
  2652. def testStrValueDatetime(self):
  2653. rr = rrulestr("DTSTART;VALUE=DATE-TIME:19970902T090000\n"
  2654. "RRULE:FREQ=YEARLY;COUNT=2")
  2655. self.assertEqual(list(rr), [datetime(1997, 9, 2, 9, 0, 0),
  2656. datetime(1998, 9, 2, 9, 0, 0)])
  2657. def testStrValueDate(self):
  2658. rr = rrulestr("DTSTART;VALUE=DATE:19970902\n"
  2659. "RRULE:FREQ=YEARLY;COUNT=2")
  2660. self.assertEqual(list(rr), [datetime(1997, 9, 2, 0, 0, 0),
  2661. datetime(1998, 9, 2, 0, 0, 0)])
  2662. def testStrMultipleDTStartComma(self):
  2663. with pytest.raises(ValueError):
  2664. rr = rrulestr("DTSTART:19970101T000000,19970202T000000\n"
  2665. "RRULE:FREQ=YEARLY;COUNT=1")
  2666. def testStrInvalidUntil(self):
  2667. with self.assertRaises(ValueError):
  2668. list(rrulestr("DTSTART:19970902T090000\n"
  2669. "RRULE:FREQ=YEARLY;"
  2670. "UNTIL=TheCowsComeHome;BYDAY=1TU,-1TH\n"))
  2671. def testStrUntilMustBeUTC(self):
  2672. with self.assertRaises(ValueError):
  2673. list(rrulestr("DTSTART;TZID=America/New_York:19970902T090000\n"
  2674. "RRULE:FREQ=YEARLY;"
  2675. "UNTIL=19990101T000000;BYDAY=1TU,-1TH\n"))
  2676. def testStrUntilWithTZ(self):
  2677. NYC = tz.gettz('America/New_York')
  2678. rr = list(rrulestr("DTSTART;TZID=America/New_York:19970101T000000\n"
  2679. "RRULE:FREQ=YEARLY;"
  2680. "UNTIL=19990101T000000Z\n"))
  2681. self.assertEqual(list(rr), [datetime(1997, 1, 1, 0, 0, 0, tzinfo=NYC),
  2682. datetime(1998, 1, 1, 0, 0, 0, tzinfo=NYC)])
  2683. def testStrEmptyByDay(self):
  2684. with self.assertRaises(ValueError):
  2685. list(rrulestr("DTSTART:19970902T090000\n"
  2686. "FREQ=WEEKLY;"
  2687. "BYDAY=;" # This part is invalid
  2688. "WKST=SU"))
  2689. def testStrInvalidByDay(self):
  2690. with self.assertRaises(ValueError):
  2691. list(rrulestr("DTSTART:19970902T090000\n"
  2692. "FREQ=WEEKLY;"
  2693. "BYDAY=-1OK;" # This part is invalid
  2694. "WKST=SU"))
  2695. def testBadBySetPos(self):
  2696. self.assertRaises(ValueError,
  2697. rrule, MONTHLY,
  2698. count=1,
  2699. bysetpos=0,
  2700. dtstart=datetime(1997, 9, 2, 9, 0))
  2701. def testBadBySetPosMany(self):
  2702. self.assertRaises(ValueError,
  2703. rrule, MONTHLY,
  2704. count=1,
  2705. bysetpos=(-1, 0, 1),
  2706. dtstart=datetime(1997, 9, 2, 9, 0))
  2707. # Tests to ensure that str(rrule) works
  2708. def testToStrYearly(self):
  2709. rule = rrule(YEARLY, count=3, dtstart=datetime(1997, 9, 2, 9, 0))
  2710. self._rrulestr_reverse_test(rule)
  2711. def testToStrYearlyInterval(self):
  2712. rule = rrule(YEARLY, count=3, interval=2,
  2713. dtstart=datetime(1997, 9, 2, 9, 0))
  2714. self._rrulestr_reverse_test(rule)
  2715. def testToStrYearlyByMonth(self):
  2716. self._rrulestr_reverse_test(rrule(YEARLY,
  2717. count=3,
  2718. bymonth=(1, 3),
  2719. dtstart=datetime(1997, 9, 2, 9, 0)))
  2720. def testToStrYearlyByMonthDay(self):
  2721. self._rrulestr_reverse_test(rrule(YEARLY,
  2722. count=3,
  2723. bymonthday=(1, 3),
  2724. dtstart=datetime(1997, 9, 2, 9, 0)))
  2725. def testToStrYearlyByMonthAndMonthDay(self):
  2726. self._rrulestr_reverse_test(rrule(YEARLY,
  2727. count=3,
  2728. bymonth=(1, 3),
  2729. bymonthday=(5, 7),
  2730. dtstart=datetime(1997, 9, 2, 9, 0)))
  2731. def testToStrYearlyByWeekDay(self):
  2732. self._rrulestr_reverse_test(rrule(YEARLY,
  2733. count=3,
  2734. byweekday=(TU, TH),
  2735. dtstart=datetime(1997, 9, 2, 9, 0)))
  2736. def testToStrYearlyByNWeekDay(self):
  2737. self._rrulestr_reverse_test(rrule(YEARLY,
  2738. count=3,
  2739. byweekday=(TU(1), TH(-1)),
  2740. dtstart=datetime(1997, 9, 2, 9, 0)))
  2741. def testToStrYearlyByNWeekDayLarge(self):
  2742. self._rrulestr_reverse_test(rrule(YEARLY,
  2743. count=3,
  2744. byweekday=(TU(3), TH(-3)),
  2745. dtstart=datetime(1997, 9, 2, 9, 0)))
  2746. def testToStrYearlyByMonthAndWeekDay(self):
  2747. self._rrulestr_reverse_test(rrule(YEARLY,
  2748. count=3,
  2749. bymonth=(1, 3),
  2750. byweekday=(TU, TH),
  2751. dtstart=datetime(1997, 9, 2, 9, 0)))
  2752. def testToStrYearlyByMonthAndNWeekDay(self):
  2753. self._rrulestr_reverse_test(rrule(YEARLY,
  2754. count=3,
  2755. bymonth=(1, 3),
  2756. byweekday=(TU(1), TH(-1)),
  2757. dtstart=datetime(1997, 9, 2, 9, 0)))
  2758. def testToStrYearlyByMonthAndNWeekDayLarge(self):
  2759. # This is interesting because the TH(-3) ends up before
  2760. # the TU(3).
  2761. self._rrulestr_reverse_test(rrule(YEARLY,
  2762. count=3,
  2763. bymonth=(1, 3),
  2764. byweekday=(TU(3), TH(-3)),
  2765. dtstart=datetime(1997, 9, 2, 9, 0)))
  2766. def testToStrYearlyByMonthDayAndWeekDay(self):
  2767. self._rrulestr_reverse_test(rrule(YEARLY,
  2768. count=3,
  2769. bymonthday=(1, 3),
  2770. byweekday=(TU, TH),
  2771. dtstart=datetime(1997, 9, 2, 9, 0)))
  2772. def testToStrYearlyByMonthAndMonthDayAndWeekDay(self):
  2773. self._rrulestr_reverse_test(rrule(YEARLY,
  2774. count=3,
  2775. bymonth=(1, 3),
  2776. bymonthday=(1, 3),
  2777. byweekday=(TU, TH),
  2778. dtstart=datetime(1997, 9, 2, 9, 0)))
  2779. def testToStrYearlyByYearDay(self):
  2780. self._rrulestr_reverse_test(rrule(YEARLY,
  2781. count=4,
  2782. byyearday=(1, 100, 200, 365),
  2783. dtstart=datetime(1997, 9, 2, 9, 0)))
  2784. def testToStrYearlyByYearDayNeg(self):
  2785. self._rrulestr_reverse_test(rrule(YEARLY,
  2786. count=4,
  2787. byyearday=(-365, -266, -166, -1),
  2788. dtstart=datetime(1997, 9, 2, 9, 0)))
  2789. def testToStrYearlyByMonthAndYearDay(self):
  2790. self._rrulestr_reverse_test(rrule(YEARLY,
  2791. count=4,
  2792. bymonth=(4, 7),
  2793. byyearday=(1, 100, 200, 365),
  2794. dtstart=datetime(1997, 9, 2, 9, 0)))
  2795. def testToStrYearlyByMonthAndYearDayNeg(self):
  2796. self._rrulestr_reverse_test(rrule(YEARLY,
  2797. count=4,
  2798. bymonth=(4, 7),
  2799. byyearday=(-365, -266, -166, -1),
  2800. dtstart=datetime(1997, 9, 2, 9, 0)))
  2801. def testToStrYearlyByWeekNo(self):
  2802. self._rrulestr_reverse_test(rrule(YEARLY,
  2803. count=3,
  2804. byweekno=20,
  2805. dtstart=datetime(1997, 9, 2, 9, 0)))
  2806. def testToStrYearlyByWeekNoAndWeekDay(self):
  2807. # That's a nice one. The first days of week number one
  2808. # may be in the last year.
  2809. self._rrulestr_reverse_test(rrule(YEARLY,
  2810. count=3,
  2811. byweekno=1,
  2812. byweekday=MO,
  2813. dtstart=datetime(1997, 9, 2, 9, 0)))
  2814. def testToStrYearlyByWeekNoAndWeekDayLarge(self):
  2815. # Another nice test. The last days of week number 52/53
  2816. # may be in the next year.
  2817. self._rrulestr_reverse_test(rrule(YEARLY,
  2818. count=3,
  2819. byweekno=52,
  2820. byweekday=SU,
  2821. dtstart=datetime(1997, 9, 2, 9, 0)))
  2822. def testToStrYearlyByWeekNoAndWeekDayLast(self):
  2823. self._rrulestr_reverse_test(rrule(YEARLY,
  2824. count=3,
  2825. byweekno=-1,
  2826. byweekday=SU,
  2827. dtstart=datetime(1997, 9, 2, 9, 0)))
  2828. def testToStrYearlyByEaster(self):
  2829. self._rrulestr_reverse_test(rrule(YEARLY,
  2830. count=3,
  2831. byeaster=0,
  2832. dtstart=datetime(1997, 9, 2, 9, 0)))
  2833. def testToStrYearlyByEasterPos(self):
  2834. self._rrulestr_reverse_test(rrule(YEARLY,
  2835. count=3,
  2836. byeaster=1,
  2837. dtstart=datetime(1997, 9, 2, 9, 0)))
  2838. def testToStrYearlyByEasterNeg(self):
  2839. self._rrulestr_reverse_test(rrule(YEARLY,
  2840. count=3,
  2841. byeaster=-1,
  2842. dtstart=datetime(1997, 9, 2, 9, 0)))
  2843. def testToStrYearlyByWeekNoAndWeekDay53(self):
  2844. self._rrulestr_reverse_test(rrule(YEARLY,
  2845. count=3,
  2846. byweekno=53,
  2847. byweekday=MO,
  2848. dtstart=datetime(1997, 9, 2, 9, 0)))
  2849. def testToStrYearlyByHour(self):
  2850. self._rrulestr_reverse_test(rrule(YEARLY,
  2851. count=3,
  2852. byhour=(6, 18),
  2853. dtstart=datetime(1997, 9, 2, 9, 0)))
  2854. def testToStrYearlyByMinute(self):
  2855. self._rrulestr_reverse_test(rrule(YEARLY,
  2856. count=3,
  2857. byminute=(6, 18),
  2858. dtstart=datetime(1997, 9, 2, 9, 0)))
  2859. def testToStrYearlyBySecond(self):
  2860. self._rrulestr_reverse_test(rrule(YEARLY,
  2861. count=3,
  2862. bysecond=(6, 18),
  2863. dtstart=datetime(1997, 9, 2, 9, 0)))
  2864. def testToStrYearlyByHourAndMinute(self):
  2865. self._rrulestr_reverse_test(rrule(YEARLY,
  2866. count=3,
  2867. byhour=(6, 18),
  2868. byminute=(6, 18),
  2869. dtstart=datetime(1997, 9, 2, 9, 0)))
  2870. def testToStrYearlyByHourAndSecond(self):
  2871. self._rrulestr_reverse_test(rrule(YEARLY,
  2872. count=3,
  2873. byhour=(6, 18),
  2874. bysecond=(6, 18),
  2875. dtstart=datetime(1997, 9, 2, 9, 0)))
  2876. def testToStrYearlyByMinuteAndSecond(self):
  2877. self._rrulestr_reverse_test(rrule(YEARLY,
  2878. count=3,
  2879. byminute=(6, 18),
  2880. bysecond=(6, 18),
  2881. dtstart=datetime(1997, 9, 2, 9, 0)))
  2882. def testToStrYearlyByHourAndMinuteAndSecond(self):
  2883. self._rrulestr_reverse_test(rrule(YEARLY,
  2884. count=3,
  2885. byhour=(6, 18),
  2886. byminute=(6, 18),
  2887. bysecond=(6, 18),
  2888. dtstart=datetime(1997, 9, 2, 9, 0)))
  2889. def testToStrYearlyBySetPos(self):
  2890. self._rrulestr_reverse_test(rrule(YEARLY,
  2891. count=3,
  2892. bymonthday=15,
  2893. byhour=(6, 18),
  2894. bysetpos=(3, -3),
  2895. dtstart=datetime(1997, 9, 2, 9, 0)))
  2896. def testToStrMonthly(self):
  2897. self._rrulestr_reverse_test(rrule(MONTHLY,
  2898. count=3,
  2899. dtstart=datetime(1997, 9, 2, 9, 0)))
  2900. def testToStrMonthlyInterval(self):
  2901. self._rrulestr_reverse_test(rrule(MONTHLY,
  2902. count=3,
  2903. interval=2,
  2904. dtstart=datetime(1997, 9, 2, 9, 0)))
  2905. def testToStrMonthlyIntervalLarge(self):
  2906. self._rrulestr_reverse_test(rrule(MONTHLY,
  2907. count=3,
  2908. interval=18,
  2909. dtstart=datetime(1997, 9, 2, 9, 0)))
  2910. def testToStrMonthlyByMonth(self):
  2911. self._rrulestr_reverse_test(rrule(MONTHLY,
  2912. count=3,
  2913. bymonth=(1, 3),
  2914. dtstart=datetime(1997, 9, 2, 9, 0)))
  2915. def testToStrMonthlyByMonthDay(self):
  2916. self._rrulestr_reverse_test(rrule(MONTHLY,
  2917. count=3,
  2918. bymonthday=(1, 3),
  2919. dtstart=datetime(1997, 9, 2, 9, 0)))
  2920. def testToStrMonthlyByMonthAndMonthDay(self):
  2921. self._rrulestr_reverse_test(rrule(MONTHLY,
  2922. count=3,
  2923. bymonth=(1, 3),
  2924. bymonthday=(5, 7),
  2925. dtstart=datetime(1997, 9, 2, 9, 0)))
  2926. def testToStrMonthlyByWeekDay(self):
  2927. self._rrulestr_reverse_test(rrule(MONTHLY,
  2928. count=3,
  2929. byweekday=(TU, TH),
  2930. dtstart=datetime(1997, 9, 2, 9, 0)))
  2931. # Third Monday of the month
  2932. self.assertEqual(rrule(MONTHLY,
  2933. byweekday=(MO(+3)),
  2934. dtstart=datetime(1997, 9, 1)).between(datetime(1997,
  2935. 9,
  2936. 1),
  2937. datetime(1997,
  2938. 12,
  2939. 1)),
  2940. [datetime(1997, 9, 15, 0, 0),
  2941. datetime(1997, 10, 20, 0, 0),
  2942. datetime(1997, 11, 17, 0, 0)])
  2943. def testToStrMonthlyByNWeekDay(self):
  2944. self._rrulestr_reverse_test(rrule(MONTHLY,
  2945. count=3,
  2946. byweekday=(TU(1), TH(-1)),
  2947. dtstart=datetime(1997, 9, 2, 9, 0)))
  2948. def testToStrMonthlyByNWeekDayLarge(self):
  2949. self._rrulestr_reverse_test(rrule(MONTHLY,
  2950. count=3,
  2951. byweekday=(TU(3), TH(-3)),
  2952. dtstart=datetime(1997, 9, 2, 9, 0)))
  2953. def testToStrMonthlyByMonthAndWeekDay(self):
  2954. self._rrulestr_reverse_test(rrule(MONTHLY,
  2955. count=3,
  2956. bymonth=(1, 3),
  2957. byweekday=(TU, TH),
  2958. dtstart=datetime(1997, 9, 2, 9, 0)))
  2959. def testToStrMonthlyByMonthAndNWeekDay(self):
  2960. self._rrulestr_reverse_test(rrule(MONTHLY,
  2961. count=3,
  2962. bymonth=(1, 3),
  2963. byweekday=(TU(1), TH(-1)),
  2964. dtstart=datetime(1997, 9, 2, 9, 0)))
  2965. def testToStrMonthlyByMonthAndNWeekDayLarge(self):
  2966. self._rrulestr_reverse_test(rrule(MONTHLY,
  2967. count=3,
  2968. bymonth=(1, 3),
  2969. byweekday=(TU(3), TH(-3)),
  2970. dtstart=datetime(1997, 9, 2, 9, 0)))
  2971. def testToStrMonthlyByMonthDayAndWeekDay(self):
  2972. self._rrulestr_reverse_test(rrule(MONTHLY,
  2973. count=3,
  2974. bymonthday=(1, 3),
  2975. byweekday=(TU, TH),
  2976. dtstart=datetime(1997, 9, 2, 9, 0)))
  2977. def testToStrMonthlyByMonthAndMonthDayAndWeekDay(self):
  2978. self._rrulestr_reverse_test(rrule(MONTHLY,
  2979. count=3,
  2980. bymonth=(1, 3),
  2981. bymonthday=(1, 3),
  2982. byweekday=(TU, TH),
  2983. dtstart=datetime(1997, 9, 2, 9, 0)))
  2984. def testToStrMonthlyByYearDay(self):
  2985. self._rrulestr_reverse_test(rrule(MONTHLY,
  2986. count=4,
  2987. byyearday=(1, 100, 200, 365),
  2988. dtstart=datetime(1997, 9, 2, 9, 0)))
  2989. def testToStrMonthlyByYearDayNeg(self):
  2990. self._rrulestr_reverse_test(rrule(MONTHLY,
  2991. count=4,
  2992. byyearday=(-365, -266, -166, -1),
  2993. dtstart=datetime(1997, 9, 2, 9, 0)))
  2994. def testToStrMonthlyByMonthAndYearDay(self):
  2995. self._rrulestr_reverse_test(rrule(MONTHLY,
  2996. count=4,
  2997. bymonth=(4, 7),
  2998. byyearday=(1, 100, 200, 365),
  2999. dtstart=datetime(1997, 9, 2, 9, 0)))
  3000. def testToStrMonthlyByMonthAndYearDayNeg(self):
  3001. self._rrulestr_reverse_test(rrule(MONTHLY,
  3002. count=4,
  3003. bymonth=(4, 7),
  3004. byyearday=(-365, -266, -166, -1),
  3005. dtstart=datetime(1997, 9, 2, 9, 0)))
  3006. def testToStrMonthlyByWeekNo(self):
  3007. self._rrulestr_reverse_test(rrule(MONTHLY,
  3008. count=3,
  3009. byweekno=20,
  3010. dtstart=datetime(1997, 9, 2, 9, 0)))
  3011. def testToStrMonthlyByWeekNoAndWeekDay(self):
  3012. # That's a nice one. The first days of week number one
  3013. # may be in the last year.
  3014. self._rrulestr_reverse_test(rrule(MONTHLY,
  3015. count=3,
  3016. byweekno=1,
  3017. byweekday=MO,
  3018. dtstart=datetime(1997, 9, 2, 9, 0)))
  3019. def testToStrMonthlyByWeekNoAndWeekDayLarge(self):
  3020. # Another nice test. The last days of week number 52/53
  3021. # may be in the next year.
  3022. self._rrulestr_reverse_test(rrule(MONTHLY,
  3023. count=3,
  3024. byweekno=52,
  3025. byweekday=SU,
  3026. dtstart=datetime(1997, 9, 2, 9, 0)))
  3027. def testToStrMonthlyByWeekNoAndWeekDayLast(self):
  3028. self._rrulestr_reverse_test(rrule(MONTHLY,
  3029. count=3,
  3030. byweekno=-1,
  3031. byweekday=SU,
  3032. dtstart=datetime(1997, 9, 2, 9, 0)))
  3033. def testToStrMonthlyByWeekNoAndWeekDay53(self):
  3034. self._rrulestr_reverse_test(rrule(MONTHLY,
  3035. count=3,
  3036. byweekno=53,
  3037. byweekday=MO,
  3038. dtstart=datetime(1997, 9, 2, 9, 0)))
  3039. def testToStrMonthlyByEaster(self):
  3040. self._rrulestr_reverse_test(rrule(MONTHLY,
  3041. count=3,
  3042. byeaster=0,
  3043. dtstart=datetime(1997, 9, 2, 9, 0)))
  3044. def testToStrMonthlyByEasterPos(self):
  3045. self._rrulestr_reverse_test(rrule(MONTHLY,
  3046. count=3,
  3047. byeaster=1,
  3048. dtstart=datetime(1997, 9, 2, 9, 0)))
  3049. def testToStrMonthlyByEasterNeg(self):
  3050. self._rrulestr_reverse_test(rrule(MONTHLY,
  3051. count=3,
  3052. byeaster=-1,
  3053. dtstart=datetime(1997, 9, 2, 9, 0)))
  3054. def testToStrMonthlyByHour(self):
  3055. self._rrulestr_reverse_test(rrule(MONTHLY,
  3056. count=3,
  3057. byhour=(6, 18),
  3058. dtstart=datetime(1997, 9, 2, 9, 0)))
  3059. def testToStrMonthlyByMinute(self):
  3060. self._rrulestr_reverse_test(rrule(MONTHLY,
  3061. count=3,
  3062. byminute=(6, 18),
  3063. dtstart=datetime(1997, 9, 2, 9, 0)))
  3064. def testToStrMonthlyBySecond(self):
  3065. self._rrulestr_reverse_test(rrule(MONTHLY,
  3066. count=3,
  3067. bysecond=(6, 18),
  3068. dtstart=datetime(1997, 9, 2, 9, 0)))
  3069. def testToStrMonthlyByHourAndMinute(self):
  3070. self._rrulestr_reverse_test(rrule(MONTHLY,
  3071. count=3,
  3072. byhour=(6, 18),
  3073. byminute=(6, 18),
  3074. dtstart=datetime(1997, 9, 2, 9, 0)))
  3075. def testToStrMonthlyByHourAndSecond(self):
  3076. self._rrulestr_reverse_test(rrule(MONTHLY,
  3077. count=3,
  3078. byhour=(6, 18),
  3079. bysecond=(6, 18),
  3080. dtstart=datetime(1997, 9, 2, 9, 0)))
  3081. def testToStrMonthlyByMinuteAndSecond(self):
  3082. self._rrulestr_reverse_test(rrule(MONTHLY,
  3083. count=3,
  3084. byminute=(6, 18),
  3085. bysecond=(6, 18),
  3086. dtstart=datetime(1997, 9, 2, 9, 0)))
  3087. def testToStrMonthlyByHourAndMinuteAndSecond(self):
  3088. self._rrulestr_reverse_test(rrule(MONTHLY,
  3089. count=3,
  3090. byhour=(6, 18),
  3091. byminute=(6, 18),
  3092. bysecond=(6, 18),
  3093. dtstart=datetime(1997, 9, 2, 9, 0)))
  3094. def testToStrMonthlyBySetPos(self):
  3095. self._rrulestr_reverse_test(rrule(MONTHLY,
  3096. count=3,
  3097. bymonthday=(13, 17),
  3098. byhour=(6, 18),
  3099. bysetpos=(3, -3),
  3100. dtstart=datetime(1997, 9, 2, 9, 0)))
  3101. def testToStrWeekly(self):
  3102. self._rrulestr_reverse_test(rrule(WEEKLY,
  3103. count=3,
  3104. dtstart=datetime(1997, 9, 2, 9, 0)))
  3105. def testToStrWeeklyInterval(self):
  3106. self._rrulestr_reverse_test(rrule(WEEKLY,
  3107. count=3,
  3108. interval=2,
  3109. dtstart=datetime(1997, 9, 2, 9, 0)))
  3110. def testToStrWeeklyIntervalLarge(self):
  3111. self._rrulestr_reverse_test(rrule(WEEKLY,
  3112. count=3,
  3113. interval=20,
  3114. dtstart=datetime(1997, 9, 2, 9, 0)))
  3115. def testToStrWeeklyByMonth(self):
  3116. self._rrulestr_reverse_test(rrule(WEEKLY,
  3117. count=3,
  3118. bymonth=(1, 3),
  3119. dtstart=datetime(1997, 9, 2, 9, 0)))
  3120. def testToStrWeeklyByMonthDay(self):
  3121. self._rrulestr_reverse_test(rrule(WEEKLY,
  3122. count=3,
  3123. bymonthday=(1, 3),
  3124. dtstart=datetime(1997, 9, 2, 9, 0)))
  3125. def testToStrWeeklyByMonthAndMonthDay(self):
  3126. self._rrulestr_reverse_test(rrule(WEEKLY,
  3127. count=3,
  3128. bymonth=(1, 3),
  3129. bymonthday=(5, 7),
  3130. dtstart=datetime(1997, 9, 2, 9, 0)))
  3131. def testToStrWeeklyByWeekDay(self):
  3132. self._rrulestr_reverse_test(rrule(WEEKLY,
  3133. count=3,
  3134. byweekday=(TU, TH),
  3135. dtstart=datetime(1997, 9, 2, 9, 0)))
  3136. def testToStrWeeklyByNWeekDay(self):
  3137. self._rrulestr_reverse_test(rrule(WEEKLY,
  3138. count=3,
  3139. byweekday=(TU(1), TH(-1)),
  3140. dtstart=datetime(1997, 9, 2, 9, 0)))
  3141. def testToStrWeeklyByMonthAndWeekDay(self):
  3142. # This test is interesting, because it crosses the year
  3143. # boundary in a weekly period to find day '1' as a
  3144. # valid recurrence.
  3145. self._rrulestr_reverse_test(rrule(WEEKLY,
  3146. count=3,
  3147. bymonth=(1, 3),
  3148. byweekday=(TU, TH),
  3149. dtstart=datetime(1997, 9, 2, 9, 0)))
  3150. def testToStrWeeklyByMonthAndNWeekDay(self):
  3151. self._rrulestr_reverse_test(rrule(WEEKLY,
  3152. count=3,
  3153. bymonth=(1, 3),
  3154. byweekday=(TU(1), TH(-1)),
  3155. dtstart=datetime(1997, 9, 2, 9, 0)))
  3156. def testToStrWeeklyByMonthDayAndWeekDay(self):
  3157. self._rrulestr_reverse_test(rrule(WEEKLY,
  3158. count=3,
  3159. bymonthday=(1, 3),
  3160. byweekday=(TU, TH),
  3161. dtstart=datetime(1997, 9, 2, 9, 0)))
  3162. def testToStrWeeklyByMonthAndMonthDayAndWeekDay(self):
  3163. self._rrulestr_reverse_test(rrule(WEEKLY,
  3164. count=3,
  3165. bymonth=(1, 3),
  3166. bymonthday=(1, 3),
  3167. byweekday=(TU, TH),
  3168. dtstart=datetime(1997, 9, 2, 9, 0)))
  3169. def testToStrWeeklyByYearDay(self):
  3170. self._rrulestr_reverse_test(rrule(WEEKLY,
  3171. count=4,
  3172. byyearday=(1, 100, 200, 365),
  3173. dtstart=datetime(1997, 9, 2, 9, 0)))
  3174. def testToStrWeeklyByYearDayNeg(self):
  3175. self._rrulestr_reverse_test(rrule(WEEKLY,
  3176. count=4,
  3177. byyearday=(-365, -266, -166, -1),
  3178. dtstart=datetime(1997, 9, 2, 9, 0)))
  3179. def testToStrWeeklyByMonthAndYearDay(self):
  3180. self._rrulestr_reverse_test(rrule(WEEKLY,
  3181. count=4,
  3182. bymonth=(1, 7),
  3183. byyearday=(1, 100, 200, 365),
  3184. dtstart=datetime(1997, 9, 2, 9, 0)))
  3185. def testToStrWeeklyByMonthAndYearDayNeg(self):
  3186. self._rrulestr_reverse_test(rrule(WEEKLY,
  3187. count=4,
  3188. bymonth=(1, 7),
  3189. byyearday=(-365, -266, -166, -1),
  3190. dtstart=datetime(1997, 9, 2, 9, 0)))
  3191. def testToStrWeeklyByWeekNo(self):
  3192. self._rrulestr_reverse_test(rrule(WEEKLY,
  3193. count=3,
  3194. byweekno=20,
  3195. dtstart=datetime(1997, 9, 2, 9, 0)))
  3196. def testToStrWeeklyByWeekNoAndWeekDay(self):
  3197. # That's a nice one. The first days of week number one
  3198. # may be in the last year.
  3199. self._rrulestr_reverse_test(rrule(WEEKLY,
  3200. count=3,
  3201. byweekno=1,
  3202. byweekday=MO,
  3203. dtstart=datetime(1997, 9, 2, 9, 0)))
  3204. def testToStrWeeklyByWeekNoAndWeekDayLarge(self):
  3205. # Another nice test. The last days of week number 52/53
  3206. # may be in the next year.
  3207. self._rrulestr_reverse_test(rrule(WEEKLY,
  3208. count=3,
  3209. byweekno=52,
  3210. byweekday=SU,
  3211. dtstart=datetime(1997, 9, 2, 9, 0)))
  3212. def testToStrWeeklyByWeekNoAndWeekDayLast(self):
  3213. self._rrulestr_reverse_test(rrule(WEEKLY,
  3214. count=3,
  3215. byweekno=-1,
  3216. byweekday=SU,
  3217. dtstart=datetime(1997, 9, 2, 9, 0)))
  3218. def testToStrWeeklyByWeekNoAndWeekDay53(self):
  3219. self._rrulestr_reverse_test(rrule(WEEKLY,
  3220. count=3,
  3221. byweekno=53,
  3222. byweekday=MO,
  3223. dtstart=datetime(1997, 9, 2, 9, 0)))
  3224. def testToStrWeeklyByEaster(self):
  3225. self._rrulestr_reverse_test(rrule(WEEKLY,
  3226. count=3,
  3227. byeaster=0,
  3228. dtstart=datetime(1997, 9, 2, 9, 0)))
  3229. def testToStrWeeklyByEasterPos(self):
  3230. self._rrulestr_reverse_test(rrule(WEEKLY,
  3231. count=3,
  3232. byeaster=1,
  3233. dtstart=datetime(1997, 9, 2, 9, 0)))
  3234. def testToStrWeeklyByEasterNeg(self):
  3235. self._rrulestr_reverse_test(rrule(WEEKLY,
  3236. count=3,
  3237. byeaster=-1,
  3238. dtstart=datetime(1997, 9, 2, 9, 0)))
  3239. def testToStrWeeklyByHour(self):
  3240. self._rrulestr_reverse_test(rrule(WEEKLY,
  3241. count=3,
  3242. byhour=(6, 18),
  3243. dtstart=datetime(1997, 9, 2, 9, 0)))
  3244. def testToStrWeeklyByMinute(self):
  3245. self._rrulestr_reverse_test(rrule(WEEKLY,
  3246. count=3,
  3247. byminute=(6, 18),
  3248. dtstart=datetime(1997, 9, 2, 9, 0)))
  3249. def testToStrWeeklyBySecond(self):
  3250. self._rrulestr_reverse_test(rrule(WEEKLY,
  3251. count=3,
  3252. bysecond=(6, 18),
  3253. dtstart=datetime(1997, 9, 2, 9, 0)))
  3254. def testToStrWeeklyByHourAndMinute(self):
  3255. self._rrulestr_reverse_test(rrule(WEEKLY,
  3256. count=3,
  3257. byhour=(6, 18),
  3258. byminute=(6, 18),
  3259. dtstart=datetime(1997, 9, 2, 9, 0)))
  3260. def testToStrWeeklyByHourAndSecond(self):
  3261. self._rrulestr_reverse_test(rrule(WEEKLY,
  3262. count=3,
  3263. byhour=(6, 18),
  3264. bysecond=(6, 18),
  3265. dtstart=datetime(1997, 9, 2, 9, 0)))
  3266. def testToStrWeeklyByMinuteAndSecond(self):
  3267. self._rrulestr_reverse_test(rrule(WEEKLY,
  3268. count=3,
  3269. byminute=(6, 18),
  3270. bysecond=(6, 18),
  3271. dtstart=datetime(1997, 9, 2, 9, 0)))
  3272. def testToStrWeeklyByHourAndMinuteAndSecond(self):
  3273. self._rrulestr_reverse_test(rrule(WEEKLY,
  3274. count=3,
  3275. byhour=(6, 18),
  3276. byminute=(6, 18),
  3277. bysecond=(6, 18),
  3278. dtstart=datetime(1997, 9, 2, 9, 0)))
  3279. def testToStrWeeklyBySetPos(self):
  3280. self._rrulestr_reverse_test(rrule(WEEKLY,
  3281. count=3,
  3282. byweekday=(TU, TH),
  3283. byhour=(6, 18),
  3284. bysetpos=(3, -3),
  3285. dtstart=datetime(1997, 9, 2, 9, 0)))
  3286. def testToStrDaily(self):
  3287. self._rrulestr_reverse_test(rrule(DAILY,
  3288. count=3,
  3289. dtstart=datetime(1997, 9, 2, 9, 0)))
  3290. def testToStrDailyInterval(self):
  3291. self._rrulestr_reverse_test(rrule(DAILY,
  3292. count=3,
  3293. interval=2,
  3294. dtstart=datetime(1997, 9, 2, 9, 0)))
  3295. def testToStrDailyIntervalLarge(self):
  3296. self._rrulestr_reverse_test(rrule(DAILY,
  3297. count=3,
  3298. interval=92,
  3299. dtstart=datetime(1997, 9, 2, 9, 0)))
  3300. def testToStrDailyByMonth(self):
  3301. self._rrulestr_reverse_test(rrule(DAILY,
  3302. count=3,
  3303. bymonth=(1, 3),
  3304. dtstart=datetime(1997, 9, 2, 9, 0)))
  3305. def testToStrDailyByMonthDay(self):
  3306. self._rrulestr_reverse_test(rrule(DAILY,
  3307. count=3,
  3308. bymonthday=(1, 3),
  3309. dtstart=datetime(1997, 9, 2, 9, 0)))
  3310. def testToStrDailyByMonthAndMonthDay(self):
  3311. self._rrulestr_reverse_test(rrule(DAILY,
  3312. count=3,
  3313. bymonth=(1, 3),
  3314. bymonthday=(5, 7),
  3315. dtstart=datetime(1997, 9, 2, 9, 0)))
  3316. def testToStrDailyByWeekDay(self):
  3317. self._rrulestr_reverse_test(rrule(DAILY,
  3318. count=3,
  3319. byweekday=(TU, TH),
  3320. dtstart=datetime(1997, 9, 2, 9, 0)))
  3321. def testToStrDailyByNWeekDay(self):
  3322. self._rrulestr_reverse_test(rrule(DAILY,
  3323. count=3,
  3324. byweekday=(TU(1), TH(-1)),
  3325. dtstart=datetime(1997, 9, 2, 9, 0)))
  3326. def testToStrDailyByMonthAndWeekDay(self):
  3327. self._rrulestr_reverse_test(rrule(DAILY,
  3328. count=3,
  3329. bymonth=(1, 3),
  3330. byweekday=(TU, TH),
  3331. dtstart=datetime(1997, 9, 2, 9, 0)))
  3332. def testToStrDailyByMonthAndNWeekDay(self):
  3333. self._rrulestr_reverse_test(rrule(DAILY,
  3334. count=3,
  3335. bymonth=(1, 3),
  3336. byweekday=(TU(1), TH(-1)),
  3337. dtstart=datetime(1997, 9, 2, 9, 0)))
  3338. def testToStrDailyByMonthDayAndWeekDay(self):
  3339. self._rrulestr_reverse_test(rrule(DAILY,
  3340. count=3,
  3341. bymonthday=(1, 3),
  3342. byweekday=(TU, TH),
  3343. dtstart=datetime(1997, 9, 2, 9, 0)))
  3344. def testToStrDailyByMonthAndMonthDayAndWeekDay(self):
  3345. self._rrulestr_reverse_test(rrule(DAILY,
  3346. count=3,
  3347. bymonth=(1, 3),
  3348. bymonthday=(1, 3),
  3349. byweekday=(TU, TH),
  3350. dtstart=datetime(1997, 9, 2, 9, 0)))
  3351. def testToStrDailyByYearDay(self):
  3352. self._rrulestr_reverse_test(rrule(DAILY,
  3353. count=4,
  3354. byyearday=(1, 100, 200, 365),
  3355. dtstart=datetime(1997, 9, 2, 9, 0)))
  3356. def testToStrDailyByYearDayNeg(self):
  3357. self._rrulestr_reverse_test(rrule(DAILY,
  3358. count=4,
  3359. byyearday=(-365, -266, -166, -1),
  3360. dtstart=datetime(1997, 9, 2, 9, 0)))
  3361. def testToStrDailyByMonthAndYearDay(self):
  3362. self._rrulestr_reverse_test(rrule(DAILY,
  3363. count=4,
  3364. bymonth=(1, 7),
  3365. byyearday=(1, 100, 200, 365),
  3366. dtstart=datetime(1997, 9, 2, 9, 0)))
  3367. def testToStrDailyByMonthAndYearDayNeg(self):
  3368. self._rrulestr_reverse_test(rrule(DAILY,
  3369. count=4,
  3370. bymonth=(1, 7),
  3371. byyearday=(-365, -266, -166, -1),
  3372. dtstart=datetime(1997, 9, 2, 9, 0)))
  3373. def testToStrDailyByWeekNo(self):
  3374. self._rrulestr_reverse_test(rrule(DAILY,
  3375. count=3,
  3376. byweekno=20,
  3377. dtstart=datetime(1997, 9, 2, 9, 0)))
  3378. def testToStrDailyByWeekNoAndWeekDay(self):
  3379. # That's a nice one. The first days of week number one
  3380. # may be in the last year.
  3381. self._rrulestr_reverse_test(rrule(DAILY,
  3382. count=3,
  3383. byweekno=1,
  3384. byweekday=MO,
  3385. dtstart=datetime(1997, 9, 2, 9, 0)))
  3386. def testToStrDailyByWeekNoAndWeekDayLarge(self):
  3387. # Another nice test. The last days of week number 52/53
  3388. # may be in the next year.
  3389. self._rrulestr_reverse_test(rrule(DAILY,
  3390. count=3,
  3391. byweekno=52,
  3392. byweekday=SU,
  3393. dtstart=datetime(1997, 9, 2, 9, 0)))
  3394. def testToStrDailyByWeekNoAndWeekDayLast(self):
  3395. self._rrulestr_reverse_test(rrule(DAILY,
  3396. count=3,
  3397. byweekno=-1,
  3398. byweekday=SU,
  3399. dtstart=datetime(1997, 9, 2, 9, 0)))
  3400. def testToStrDailyByWeekNoAndWeekDay53(self):
  3401. self._rrulestr_reverse_test(rrule(DAILY,
  3402. count=3,
  3403. byweekno=53,
  3404. byweekday=MO,
  3405. dtstart=datetime(1997, 9, 2, 9, 0)))
  3406. def testToStrDailyByEaster(self):
  3407. self._rrulestr_reverse_test(rrule(DAILY,
  3408. count=3,
  3409. byeaster=0,
  3410. dtstart=datetime(1997, 9, 2, 9, 0)))
  3411. def testToStrDailyByEasterPos(self):
  3412. self._rrulestr_reverse_test(rrule(DAILY,
  3413. count=3,
  3414. byeaster=1,
  3415. dtstart=datetime(1997, 9, 2, 9, 0)))
  3416. def testToStrDailyByEasterNeg(self):
  3417. self._rrulestr_reverse_test(rrule(DAILY,
  3418. count=3,
  3419. byeaster=-1,
  3420. dtstart=datetime(1997, 9, 2, 9, 0)))
  3421. def testToStrDailyByHour(self):
  3422. self._rrulestr_reverse_test(rrule(DAILY,
  3423. count=3,
  3424. byhour=(6, 18),
  3425. dtstart=datetime(1997, 9, 2, 9, 0)))
  3426. def testToStrDailyByMinute(self):
  3427. self._rrulestr_reverse_test(rrule(DAILY,
  3428. count=3,
  3429. byminute=(6, 18),
  3430. dtstart=datetime(1997, 9, 2, 9, 0)))
  3431. def testToStrDailyBySecond(self):
  3432. self._rrulestr_reverse_test(rrule(DAILY,
  3433. count=3,
  3434. bysecond=(6, 18),
  3435. dtstart=datetime(1997, 9, 2, 9, 0)))
  3436. def testToStrDailyByHourAndMinute(self):
  3437. self._rrulestr_reverse_test(rrule(DAILY,
  3438. count=3,
  3439. byhour=(6, 18),
  3440. byminute=(6, 18),
  3441. dtstart=datetime(1997, 9, 2, 9, 0)))
  3442. def testToStrDailyByHourAndSecond(self):
  3443. self._rrulestr_reverse_test(rrule(DAILY,
  3444. count=3,
  3445. byhour=(6, 18),
  3446. bysecond=(6, 18),
  3447. dtstart=datetime(1997, 9, 2, 9, 0)))
  3448. def testToStrDailyByMinuteAndSecond(self):
  3449. self._rrulestr_reverse_test(rrule(DAILY,
  3450. count=3,
  3451. byminute=(6, 18),
  3452. bysecond=(6, 18),
  3453. dtstart=datetime(1997, 9, 2, 9, 0)))
  3454. def testToStrDailyByHourAndMinuteAndSecond(self):
  3455. self._rrulestr_reverse_test(rrule(DAILY,
  3456. count=3,
  3457. byhour=(6, 18),
  3458. byminute=(6, 18),
  3459. bysecond=(6, 18),
  3460. dtstart=datetime(1997, 9, 2, 9, 0)))
  3461. def testToStrDailyBySetPos(self):
  3462. self._rrulestr_reverse_test(rrule(DAILY,
  3463. count=3,
  3464. byhour=(6, 18),
  3465. byminute=(15, 45),
  3466. bysetpos=(3, -3),
  3467. dtstart=datetime(1997, 9, 2, 9, 0)))
  3468. def testToStrHourly(self):
  3469. self._rrulestr_reverse_test(rrule(HOURLY,
  3470. count=3,
  3471. dtstart=datetime(1997, 9, 2, 9, 0)))
  3472. def testToStrHourlyInterval(self):
  3473. self._rrulestr_reverse_test(rrule(HOURLY,
  3474. count=3,
  3475. interval=2,
  3476. dtstart=datetime(1997, 9, 2, 9, 0)))
  3477. def testToStrHourlyIntervalLarge(self):
  3478. self._rrulestr_reverse_test(rrule(HOURLY,
  3479. count=3,
  3480. interval=769,
  3481. dtstart=datetime(1997, 9, 2, 9, 0)))
  3482. def testToStrHourlyByMonth(self):
  3483. self._rrulestr_reverse_test(rrule(HOURLY,
  3484. count=3,
  3485. bymonth=(1, 3),
  3486. dtstart=datetime(1997, 9, 2, 9, 0)))
  3487. def testToStrHourlyByMonthDay(self):
  3488. self._rrulestr_reverse_test(rrule(HOURLY,
  3489. count=3,
  3490. bymonthday=(1, 3),
  3491. dtstart=datetime(1997, 9, 2, 9, 0)))
  3492. def testToStrHourlyByMonthAndMonthDay(self):
  3493. self._rrulestr_reverse_test(rrule(HOURLY,
  3494. count=3,
  3495. bymonth=(1, 3),
  3496. bymonthday=(5, 7),
  3497. dtstart=datetime(1997, 9, 2, 9, 0)))
  3498. def testToStrHourlyByWeekDay(self):
  3499. self._rrulestr_reverse_test(rrule(HOURLY,
  3500. count=3,
  3501. byweekday=(TU, TH),
  3502. dtstart=datetime(1997, 9, 2, 9, 0)))
  3503. def testToStrHourlyByNWeekDay(self):
  3504. self._rrulestr_reverse_test(rrule(HOURLY,
  3505. count=3,
  3506. byweekday=(TU(1), TH(-1)),
  3507. dtstart=datetime(1997, 9, 2, 9, 0)))
  3508. def testToStrHourlyByMonthAndWeekDay(self):
  3509. self._rrulestr_reverse_test(rrule(HOURLY,
  3510. count=3,
  3511. bymonth=(1, 3),
  3512. byweekday=(TU, TH),
  3513. dtstart=datetime(1997, 9, 2, 9, 0)))
  3514. def testToStrHourlyByMonthAndNWeekDay(self):
  3515. self._rrulestr_reverse_test(rrule(HOURLY,
  3516. count=3,
  3517. bymonth=(1, 3),
  3518. byweekday=(TU(1), TH(-1)),
  3519. dtstart=datetime(1997, 9, 2, 9, 0)))
  3520. def testToStrHourlyByMonthDayAndWeekDay(self):
  3521. self._rrulestr_reverse_test(rrule(HOURLY,
  3522. count=3,
  3523. bymonthday=(1, 3),
  3524. byweekday=(TU, TH),
  3525. dtstart=datetime(1997, 9, 2, 9, 0)))
  3526. def testToStrHourlyByMonthAndMonthDayAndWeekDay(self):
  3527. self._rrulestr_reverse_test(rrule(HOURLY,
  3528. count=3,
  3529. bymonth=(1, 3),
  3530. bymonthday=(1, 3),
  3531. byweekday=(TU, TH),
  3532. dtstart=datetime(1997, 9, 2, 9, 0)))
  3533. def testToStrHourlyByYearDay(self):
  3534. self._rrulestr_reverse_test(rrule(HOURLY,
  3535. count=4,
  3536. byyearday=(1, 100, 200, 365),
  3537. dtstart=datetime(1997, 9, 2, 9, 0)))
  3538. def testToStrHourlyByYearDayNeg(self):
  3539. self._rrulestr_reverse_test(rrule(HOURLY,
  3540. count=4,
  3541. byyearday=(-365, -266, -166, -1),
  3542. dtstart=datetime(1997, 9, 2, 9, 0)))
  3543. def testToStrHourlyByMonthAndYearDay(self):
  3544. self._rrulestr_reverse_test(rrule(HOURLY,
  3545. count=4,
  3546. bymonth=(4, 7),
  3547. byyearday=(1, 100, 200, 365),
  3548. dtstart=datetime(1997, 9, 2, 9, 0)))
  3549. def testToStrHourlyByMonthAndYearDayNeg(self):
  3550. self._rrulestr_reverse_test(rrule(HOURLY,
  3551. count=4,
  3552. bymonth=(4, 7),
  3553. byyearday=(-365, -266, -166, -1),
  3554. dtstart=datetime(1997, 9, 2, 9, 0)))
  3555. def testToStrHourlyByWeekNo(self):
  3556. self._rrulestr_reverse_test(rrule(HOURLY,
  3557. count=3,
  3558. byweekno=20,
  3559. dtstart=datetime(1997, 9, 2, 9, 0)))
  3560. def testToStrHourlyByWeekNoAndWeekDay(self):
  3561. self._rrulestr_reverse_test(rrule(HOURLY,
  3562. count=3,
  3563. byweekno=1,
  3564. byweekday=MO,
  3565. dtstart=datetime(1997, 9, 2, 9, 0)))
  3566. def testToStrHourlyByWeekNoAndWeekDayLarge(self):
  3567. self._rrulestr_reverse_test(rrule(HOURLY,
  3568. count=3,
  3569. byweekno=52,
  3570. byweekday=SU,
  3571. dtstart=datetime(1997, 9, 2, 9, 0)))
  3572. def testToStrHourlyByWeekNoAndWeekDayLast(self):
  3573. self._rrulestr_reverse_test(rrule(HOURLY,
  3574. count=3,
  3575. byweekno=-1,
  3576. byweekday=SU,
  3577. dtstart=datetime(1997, 9, 2, 9, 0)))
  3578. def testToStrHourlyByWeekNoAndWeekDay53(self):
  3579. self._rrulestr_reverse_test(rrule(HOURLY,
  3580. count=3,
  3581. byweekno=53,
  3582. byweekday=MO,
  3583. dtstart=datetime(1997, 9, 2, 9, 0)))
  3584. def testToStrHourlyByEaster(self):
  3585. self._rrulestr_reverse_test(rrule(HOURLY,
  3586. count=3,
  3587. byeaster=0,
  3588. dtstart=datetime(1997, 9, 2, 9, 0)))
  3589. def testToStrHourlyByEasterPos(self):
  3590. self._rrulestr_reverse_test(rrule(HOURLY,
  3591. count=3,
  3592. byeaster=1,
  3593. dtstart=datetime(1997, 9, 2, 9, 0)))
  3594. def testToStrHourlyByEasterNeg(self):
  3595. self._rrulestr_reverse_test(rrule(HOURLY,
  3596. count=3,
  3597. byeaster=-1,
  3598. dtstart=datetime(1997, 9, 2, 9, 0)))
  3599. def testToStrHourlyByHour(self):
  3600. self._rrulestr_reverse_test(rrule(HOURLY,
  3601. count=3,
  3602. byhour=(6, 18),
  3603. dtstart=datetime(1997, 9, 2, 9, 0)))
  3604. def testToStrHourlyByMinute(self):
  3605. self._rrulestr_reverse_test(rrule(HOURLY,
  3606. count=3,
  3607. byminute=(6, 18),
  3608. dtstart=datetime(1997, 9, 2, 9, 0)))
  3609. def testToStrHourlyBySecond(self):
  3610. self._rrulestr_reverse_test(rrule(HOURLY,
  3611. count=3,
  3612. bysecond=(6, 18),
  3613. dtstart=datetime(1997, 9, 2, 9, 0)))
  3614. def testToStrHourlyByHourAndMinute(self):
  3615. self._rrulestr_reverse_test(rrule(HOURLY,
  3616. count=3,
  3617. byhour=(6, 18),
  3618. byminute=(6, 18),
  3619. dtstart=datetime(1997, 9, 2, 9, 0)))
  3620. def testToStrHourlyByHourAndSecond(self):
  3621. self._rrulestr_reverse_test(rrule(HOURLY,
  3622. count=3,
  3623. byhour=(6, 18),
  3624. bysecond=(6, 18),
  3625. dtstart=datetime(1997, 9, 2, 9, 0)))
  3626. def testToStrHourlyByMinuteAndSecond(self):
  3627. self._rrulestr_reverse_test(rrule(HOURLY,
  3628. count=3,
  3629. byminute=(6, 18),
  3630. bysecond=(6, 18),
  3631. dtstart=datetime(1997, 9, 2, 9, 0)))
  3632. def testToStrHourlyByHourAndMinuteAndSecond(self):
  3633. self._rrulestr_reverse_test(rrule(HOURLY,
  3634. count=3,
  3635. byhour=(6, 18),
  3636. byminute=(6, 18),
  3637. bysecond=(6, 18),
  3638. dtstart=datetime(1997, 9, 2, 9, 0)))
  3639. def testToStrHourlyBySetPos(self):
  3640. self._rrulestr_reverse_test(rrule(HOURLY,
  3641. count=3,
  3642. byminute=(15, 45),
  3643. bysecond=(15, 45),
  3644. bysetpos=(3, -3),
  3645. dtstart=datetime(1997, 9, 2, 9, 0)))
  3646. def testToStrMinutely(self):
  3647. self._rrulestr_reverse_test(rrule(MINUTELY,
  3648. count=3,
  3649. dtstart=datetime(1997, 9, 2, 9, 0)))
  3650. def testToStrMinutelyInterval(self):
  3651. self._rrulestr_reverse_test(rrule(MINUTELY,
  3652. count=3,
  3653. interval=2,
  3654. dtstart=datetime(1997, 9, 2, 9, 0)))
  3655. def testToStrMinutelyIntervalLarge(self):
  3656. self._rrulestr_reverse_test(rrule(MINUTELY,
  3657. count=3,
  3658. interval=1501,
  3659. dtstart=datetime(1997, 9, 2, 9, 0)))
  3660. def testToStrMinutelyByMonth(self):
  3661. self._rrulestr_reverse_test(rrule(MINUTELY,
  3662. count=3,
  3663. bymonth=(1, 3),
  3664. dtstart=datetime(1997, 9, 2, 9, 0)))
  3665. def testToStrMinutelyByMonthDay(self):
  3666. self._rrulestr_reverse_test(rrule(MINUTELY,
  3667. count=3,
  3668. bymonthday=(1, 3),
  3669. dtstart=datetime(1997, 9, 2, 9, 0)))
  3670. def testToStrMinutelyByMonthAndMonthDay(self):
  3671. self._rrulestr_reverse_test(rrule(MINUTELY,
  3672. count=3,
  3673. bymonth=(1, 3),
  3674. bymonthday=(5, 7),
  3675. dtstart=datetime(1997, 9, 2, 9, 0)))
  3676. def testToStrMinutelyByWeekDay(self):
  3677. self._rrulestr_reverse_test(rrule(MINUTELY,
  3678. count=3,
  3679. byweekday=(TU, TH),
  3680. dtstart=datetime(1997, 9, 2, 9, 0)))
  3681. def testToStrMinutelyByNWeekDay(self):
  3682. self._rrulestr_reverse_test(rrule(MINUTELY,
  3683. count=3,
  3684. byweekday=(TU(1), TH(-1)),
  3685. dtstart=datetime(1997, 9, 2, 9, 0)))
  3686. def testToStrMinutelyByMonthAndWeekDay(self):
  3687. self._rrulestr_reverse_test(rrule(MINUTELY,
  3688. count=3,
  3689. bymonth=(1, 3),
  3690. byweekday=(TU, TH),
  3691. dtstart=datetime(1997, 9, 2, 9, 0)))
  3692. def testToStrMinutelyByMonthAndNWeekDay(self):
  3693. self._rrulestr_reverse_test(rrule(MINUTELY,
  3694. count=3,
  3695. bymonth=(1, 3),
  3696. byweekday=(TU(1), TH(-1)),
  3697. dtstart=datetime(1997, 9, 2, 9, 0)))
  3698. def testToStrMinutelyByMonthDayAndWeekDay(self):
  3699. self._rrulestr_reverse_test(rrule(MINUTELY,
  3700. count=3,
  3701. bymonthday=(1, 3),
  3702. byweekday=(TU, TH),
  3703. dtstart=datetime(1997, 9, 2, 9, 0)))
  3704. def testToStrMinutelyByMonthAndMonthDayAndWeekDay(self):
  3705. self._rrulestr_reverse_test(rrule(MINUTELY,
  3706. count=3,
  3707. bymonth=(1, 3),
  3708. bymonthday=(1, 3),
  3709. byweekday=(TU, TH),
  3710. dtstart=datetime(1997, 9, 2, 9, 0)))
  3711. def testToStrMinutelyByYearDay(self):
  3712. self._rrulestr_reverse_test(rrule(MINUTELY,
  3713. count=4,
  3714. byyearday=(1, 100, 200, 365),
  3715. dtstart=datetime(1997, 9, 2, 9, 0)))
  3716. def testToStrMinutelyByYearDayNeg(self):
  3717. self._rrulestr_reverse_test(rrule(MINUTELY,
  3718. count=4,
  3719. byyearday=(-365, -266, -166, -1),
  3720. dtstart=datetime(1997, 9, 2, 9, 0)))
  3721. def testToStrMinutelyByMonthAndYearDay(self):
  3722. self._rrulestr_reverse_test(rrule(MINUTELY,
  3723. count=4,
  3724. bymonth=(4, 7),
  3725. byyearday=(1, 100, 200, 365),
  3726. dtstart=datetime(1997, 9, 2, 9, 0)))
  3727. def testToStrMinutelyByMonthAndYearDayNeg(self):
  3728. self._rrulestr_reverse_test(rrule(MINUTELY,
  3729. count=4,
  3730. bymonth=(4, 7),
  3731. byyearday=(-365, -266, -166, -1),
  3732. dtstart=datetime(1997, 9, 2, 9, 0)))
  3733. def testToStrMinutelyByWeekNo(self):
  3734. self._rrulestr_reverse_test(rrule(MINUTELY,
  3735. count=3,
  3736. byweekno=20,
  3737. dtstart=datetime(1997, 9, 2, 9, 0)))
  3738. def testToStrMinutelyByWeekNoAndWeekDay(self):
  3739. self._rrulestr_reverse_test(rrule(MINUTELY,
  3740. count=3,
  3741. byweekno=1,
  3742. byweekday=MO,
  3743. dtstart=datetime(1997, 9, 2, 9, 0)))
  3744. def testToStrMinutelyByWeekNoAndWeekDayLarge(self):
  3745. self._rrulestr_reverse_test(rrule(MINUTELY,
  3746. count=3,
  3747. byweekno=52,
  3748. byweekday=SU,
  3749. dtstart=datetime(1997, 9, 2, 9, 0)))
  3750. def testToStrMinutelyByWeekNoAndWeekDayLast(self):
  3751. self._rrulestr_reverse_test(rrule(MINUTELY,
  3752. count=3,
  3753. byweekno=-1,
  3754. byweekday=SU,
  3755. dtstart=datetime(1997, 9, 2, 9, 0)))
  3756. def testToStrMinutelyByWeekNoAndWeekDay53(self):
  3757. self._rrulestr_reverse_test(rrule(MINUTELY,
  3758. count=3,
  3759. byweekno=53,
  3760. byweekday=MO,
  3761. dtstart=datetime(1997, 9, 2, 9, 0)))
  3762. def testToStrMinutelyByEaster(self):
  3763. self._rrulestr_reverse_test(rrule(MINUTELY,
  3764. count=3,
  3765. byeaster=0,
  3766. dtstart=datetime(1997, 9, 2, 9, 0)))
  3767. def testToStrMinutelyByEasterPos(self):
  3768. self._rrulestr_reverse_test(rrule(MINUTELY,
  3769. count=3,
  3770. byeaster=1,
  3771. dtstart=datetime(1997, 9, 2, 9, 0)))
  3772. def testToStrMinutelyByEasterNeg(self):
  3773. self._rrulestr_reverse_test(rrule(MINUTELY,
  3774. count=3,
  3775. byeaster=-1,
  3776. dtstart=datetime(1997, 9, 2, 9, 0)))
  3777. def testToStrMinutelyByHour(self):
  3778. self._rrulestr_reverse_test(rrule(MINUTELY,
  3779. count=3,
  3780. byhour=(6, 18),
  3781. dtstart=datetime(1997, 9, 2, 9, 0)))
  3782. def testToStrMinutelyByMinute(self):
  3783. self._rrulestr_reverse_test(rrule(MINUTELY,
  3784. count=3,
  3785. byminute=(6, 18),
  3786. dtstart=datetime(1997, 9, 2, 9, 0)))
  3787. def testToStrMinutelyBySecond(self):
  3788. self._rrulestr_reverse_test(rrule(MINUTELY,
  3789. count=3,
  3790. bysecond=(6, 18),
  3791. dtstart=datetime(1997, 9, 2, 9, 0)))
  3792. def testToStrMinutelyByHourAndMinute(self):
  3793. self._rrulestr_reverse_test(rrule(MINUTELY,
  3794. count=3,
  3795. byhour=(6, 18),
  3796. byminute=(6, 18),
  3797. dtstart=datetime(1997, 9, 2, 9, 0)))
  3798. def testToStrMinutelyByHourAndSecond(self):
  3799. self._rrulestr_reverse_test(rrule(MINUTELY,
  3800. count=3,
  3801. byhour=(6, 18),
  3802. bysecond=(6, 18),
  3803. dtstart=datetime(1997, 9, 2, 9, 0)))
  3804. def testToStrMinutelyByMinuteAndSecond(self):
  3805. self._rrulestr_reverse_test(rrule(MINUTELY,
  3806. count=3,
  3807. byminute=(6, 18),
  3808. bysecond=(6, 18),
  3809. dtstart=datetime(1997, 9, 2, 9, 0)))
  3810. def testToStrMinutelyByHourAndMinuteAndSecond(self):
  3811. self._rrulestr_reverse_test(rrule(MINUTELY,
  3812. count=3,
  3813. byhour=(6, 18),
  3814. byminute=(6, 18),
  3815. bysecond=(6, 18),
  3816. dtstart=datetime(1997, 9, 2, 9, 0)))
  3817. def testToStrMinutelyBySetPos(self):
  3818. self._rrulestr_reverse_test(rrule(MINUTELY,
  3819. count=3,
  3820. bysecond=(15, 30, 45),
  3821. bysetpos=(3, -3),
  3822. dtstart=datetime(1997, 9, 2, 9, 0)))
  3823. def testToStrSecondly(self):
  3824. self._rrulestr_reverse_test(rrule(SECONDLY,
  3825. count=3,
  3826. dtstart=datetime(1997, 9, 2, 9, 0)))
  3827. def testToStrSecondlyInterval(self):
  3828. self._rrulestr_reverse_test(rrule(SECONDLY,
  3829. count=3,
  3830. interval=2,
  3831. dtstart=datetime(1997, 9, 2, 9, 0)))
  3832. def testToStrSecondlyIntervalLarge(self):
  3833. self._rrulestr_reverse_test(rrule(SECONDLY,
  3834. count=3,
  3835. interval=90061,
  3836. dtstart=datetime(1997, 9, 2, 9, 0)))
  3837. def testToStrSecondlyByMonth(self):
  3838. self._rrulestr_reverse_test(rrule(SECONDLY,
  3839. count=3,
  3840. bymonth=(1, 3),
  3841. dtstart=datetime(1997, 9, 2, 9, 0)))
  3842. def testToStrSecondlyByMonthDay(self):
  3843. self._rrulestr_reverse_test(rrule(SECONDLY,
  3844. count=3,
  3845. bymonthday=(1, 3),
  3846. dtstart=datetime(1997, 9, 2, 9, 0)))
  3847. def testToStrSecondlyByMonthAndMonthDay(self):
  3848. self._rrulestr_reverse_test(rrule(SECONDLY,
  3849. count=3,
  3850. bymonth=(1, 3),
  3851. bymonthday=(5, 7),
  3852. dtstart=datetime(1997, 9, 2, 9, 0)))
  3853. def testToStrSecondlyByWeekDay(self):
  3854. self._rrulestr_reverse_test(rrule(SECONDLY,
  3855. count=3,
  3856. byweekday=(TU, TH),
  3857. dtstart=datetime(1997, 9, 2, 9, 0)))
  3858. def testToStrSecondlyByNWeekDay(self):
  3859. self._rrulestr_reverse_test(rrule(SECONDLY,
  3860. count=3,
  3861. byweekday=(TU(1), TH(-1)),
  3862. dtstart=datetime(1997, 9, 2, 9, 0)))
  3863. def testToStrSecondlyByMonthAndWeekDay(self):
  3864. self._rrulestr_reverse_test(rrule(SECONDLY,
  3865. count=3,
  3866. bymonth=(1, 3),
  3867. byweekday=(TU, TH),
  3868. dtstart=datetime(1997, 9, 2, 9, 0)))
  3869. def testToStrSecondlyByMonthAndNWeekDay(self):
  3870. self._rrulestr_reverse_test(rrule(SECONDLY,
  3871. count=3,
  3872. bymonth=(1, 3),
  3873. byweekday=(TU(1), TH(-1)),
  3874. dtstart=datetime(1997, 9, 2, 9, 0)))
  3875. def testToStrSecondlyByMonthDayAndWeekDay(self):
  3876. self._rrulestr_reverse_test(rrule(SECONDLY,
  3877. count=3,
  3878. bymonthday=(1, 3),
  3879. byweekday=(TU, TH),
  3880. dtstart=datetime(1997, 9, 2, 9, 0)))
  3881. def testToStrSecondlyByMonthAndMonthDayAndWeekDay(self):
  3882. self._rrulestr_reverse_test(rrule(SECONDLY,
  3883. count=3,
  3884. bymonth=(1, 3),
  3885. bymonthday=(1, 3),
  3886. byweekday=(TU, TH),
  3887. dtstart=datetime(1997, 9, 2, 9, 0)))
  3888. def testToStrSecondlyByYearDay(self):
  3889. self._rrulestr_reverse_test(rrule(SECONDLY,
  3890. count=4,
  3891. byyearday=(1, 100, 200, 365),
  3892. dtstart=datetime(1997, 9, 2, 9, 0)))
  3893. def testToStrSecondlyByYearDayNeg(self):
  3894. self._rrulestr_reverse_test(rrule(SECONDLY,
  3895. count=4,
  3896. byyearday=(-365, -266, -166, -1),
  3897. dtstart=datetime(1997, 9, 2, 9, 0)))
  3898. def testToStrSecondlyByMonthAndYearDay(self):
  3899. self._rrulestr_reverse_test(rrule(SECONDLY,
  3900. count=4,
  3901. bymonth=(4, 7),
  3902. byyearday=(1, 100, 200, 365),
  3903. dtstart=datetime(1997, 9, 2, 9, 0)))
  3904. def testToStrSecondlyByMonthAndYearDayNeg(self):
  3905. self._rrulestr_reverse_test(rrule(SECONDLY,
  3906. count=4,
  3907. bymonth=(4, 7),
  3908. byyearday=(-365, -266, -166, -1),
  3909. dtstart=datetime(1997, 9, 2, 9, 0)))
  3910. def testToStrSecondlyByWeekNo(self):
  3911. self._rrulestr_reverse_test(rrule(SECONDLY,
  3912. count=3,
  3913. byweekno=20,
  3914. dtstart=datetime(1997, 9, 2, 9, 0)))
  3915. def testToStrSecondlyByWeekNoAndWeekDay(self):
  3916. self._rrulestr_reverse_test(rrule(SECONDLY,
  3917. count=3,
  3918. byweekno=1,
  3919. byweekday=MO,
  3920. dtstart=datetime(1997, 9, 2, 9, 0)))
  3921. def testToStrSecondlyByWeekNoAndWeekDayLarge(self):
  3922. self._rrulestr_reverse_test(rrule(SECONDLY,
  3923. count=3,
  3924. byweekno=52,
  3925. byweekday=SU,
  3926. dtstart=datetime(1997, 9, 2, 9, 0)))
  3927. def testToStrSecondlyByWeekNoAndWeekDayLast(self):
  3928. self._rrulestr_reverse_test(rrule(SECONDLY,
  3929. count=3,
  3930. byweekno=-1,
  3931. byweekday=SU,
  3932. dtstart=datetime(1997, 9, 2, 9, 0)))
  3933. def testToStrSecondlyByWeekNoAndWeekDay53(self):
  3934. self._rrulestr_reverse_test(rrule(SECONDLY,
  3935. count=3,
  3936. byweekno=53,
  3937. byweekday=MO,
  3938. dtstart=datetime(1997, 9, 2, 9, 0)))
  3939. def testToStrSecondlyByEaster(self):
  3940. self._rrulestr_reverse_test(rrule(SECONDLY,
  3941. count=3,
  3942. byeaster=0,
  3943. dtstart=datetime(1997, 9, 2, 9, 0)))
  3944. def testToStrSecondlyByEasterPos(self):
  3945. self._rrulestr_reverse_test(rrule(SECONDLY,
  3946. count=3,
  3947. byeaster=1,
  3948. dtstart=datetime(1997, 9, 2, 9, 0)))
  3949. def testToStrSecondlyByEasterNeg(self):
  3950. self._rrulestr_reverse_test(rrule(SECONDLY,
  3951. count=3,
  3952. byeaster=-1,
  3953. dtstart=datetime(1997, 9, 2, 9, 0)))
  3954. def testToStrSecondlyByHour(self):
  3955. self._rrulestr_reverse_test(rrule(SECONDLY,
  3956. count=3,
  3957. byhour=(6, 18),
  3958. dtstart=datetime(1997, 9, 2, 9, 0)))
  3959. def testToStrSecondlyByMinute(self):
  3960. self._rrulestr_reverse_test(rrule(SECONDLY,
  3961. count=3,
  3962. byminute=(6, 18),
  3963. dtstart=datetime(1997, 9, 2, 9, 0)))
  3964. def testToStrSecondlyBySecond(self):
  3965. self._rrulestr_reverse_test(rrule(SECONDLY,
  3966. count=3,
  3967. bysecond=(6, 18),
  3968. dtstart=datetime(1997, 9, 2, 9, 0)))
  3969. def testToStrSecondlyByHourAndMinute(self):
  3970. self._rrulestr_reverse_test(rrule(SECONDLY,
  3971. count=3,
  3972. byhour=(6, 18),
  3973. byminute=(6, 18),
  3974. dtstart=datetime(1997, 9, 2, 9, 0)))
  3975. def testToStrSecondlyByHourAndSecond(self):
  3976. self._rrulestr_reverse_test(rrule(SECONDLY,
  3977. count=3,
  3978. byhour=(6, 18),
  3979. bysecond=(6, 18),
  3980. dtstart=datetime(1997, 9, 2, 9, 0)))
  3981. def testToStrSecondlyByMinuteAndSecond(self):
  3982. self._rrulestr_reverse_test(rrule(SECONDLY,
  3983. count=3,
  3984. byminute=(6, 18),
  3985. bysecond=(6, 18),
  3986. dtstart=datetime(1997, 9, 2, 9, 0)))
  3987. def testToStrSecondlyByHourAndMinuteAndSecond(self):
  3988. self._rrulestr_reverse_test(rrule(SECONDLY,
  3989. count=3,
  3990. byhour=(6, 18),
  3991. byminute=(6, 18),
  3992. bysecond=(6, 18),
  3993. dtstart=datetime(1997, 9, 2, 9, 0)))
  3994. def testToStrSecondlyByHourAndMinuteAndSecondBug(self):
  3995. # This explores a bug found by Mathieu Bridon.
  3996. self._rrulestr_reverse_test(rrule(SECONDLY,
  3997. count=3,
  3998. bysecond=(0,),
  3999. byminute=(1,),
  4000. dtstart=datetime(2010, 3, 22, 12, 1)))
  4001. def testToStrWithWkSt(self):
  4002. self._rrulestr_reverse_test(rrule(WEEKLY,
  4003. count=3,
  4004. wkst=SU,
  4005. dtstart=datetime(1997, 9, 2, 9, 0)))
  4006. def testToStrLongIntegers(self):
  4007. if PY2: # There are no longs in python3
  4008. self._rrulestr_reverse_test(rrule(MINUTELY,
  4009. count=long(2),
  4010. interval=long(2),
  4011. bymonth=long(2),
  4012. byweekday=long(3),
  4013. byhour=long(6),
  4014. byminute=long(6),
  4015. bysecond=long(6),
  4016. dtstart=datetime(1997, 9, 2, 9, 0)))
  4017. self._rrulestr_reverse_test(rrule(YEARLY,
  4018. count=long(2),
  4019. bymonthday=long(5),
  4020. byweekno=long(2),
  4021. dtstart=datetime(1997, 9, 2, 9, 0)))
  4022. def testReplaceIfSet(self):
  4023. rr = rrule(YEARLY,
  4024. count=1,
  4025. bymonthday=5,
  4026. dtstart=datetime(1997, 1, 1))
  4027. newrr = rr.replace(bymonthday=6)
  4028. self.assertEqual(list(rr), [datetime(1997, 1, 5)])
  4029. self.assertEqual(list(newrr),
  4030. [datetime(1997, 1, 6)])
  4031. def testReplaceIfNotSet(self):
  4032. rr = rrule(YEARLY,
  4033. count=1,
  4034. dtstart=datetime(1997, 1, 1))
  4035. newrr = rr.replace(bymonthday=6)
  4036. self.assertEqual(list(rr), [datetime(1997, 1, 1)])
  4037. self.assertEqual(list(newrr),
  4038. [datetime(1997, 1, 6)])
  4039. @pytest.mark.rrule
  4040. @freeze_time(datetime(2018, 3, 6, 5, 36, tzinfo=tz.UTC))
  4041. def test_generated_aware_dtstart():
  4042. dtstart_exp = datetime(2018, 3, 6, 5, 36, tzinfo=tz.UTC)
  4043. UNTIL = datetime(2018, 3, 6, 8, 0, tzinfo=tz.UTC)
  4044. rule_without_dtstart = rrule(freq=HOURLY, until=UNTIL)
  4045. rule_with_dtstart = rrule(freq=HOURLY, dtstart=dtstart_exp, until=UNTIL)
  4046. assert list(rule_without_dtstart) == list(rule_with_dtstart)
  4047. @pytest.mark.rrule
  4048. @pytest.mark.rrulestr
  4049. @pytest.mark.xfail(reason="rrulestr loses time zone, gh issue #637")
  4050. @freeze_time(datetime(2018, 3, 6, 5, 36, tzinfo=tz.UTC))
  4051. def test_generated_aware_dtstart_rrulestr():
  4052. rrule_without_dtstart = rrule(freq=HOURLY,
  4053. until=datetime(2018, 3, 6, 8, 0,
  4054. tzinfo=tz.UTC))
  4055. rrule_r = rrulestr(str(rrule_without_dtstart))
  4056. assert list(rrule_r) == list(rrule_without_dtstart)
  4057. @pytest.mark.rruleset
  4058. class RRuleSetTest(unittest.TestCase):
  4059. def testSet(self):
  4060. rrset = rruleset()
  4061. rrset.rrule(rrule(YEARLY, count=2, byweekday=TU,
  4062. dtstart=datetime(1997, 9, 2, 9, 0)))
  4063. rrset.rrule(rrule(YEARLY, count=1, byweekday=TH,
  4064. dtstart=datetime(1997, 9, 2, 9, 0)))
  4065. self.assertEqual(list(rrset),
  4066. [datetime(1997, 9, 2, 9, 0),
  4067. datetime(1997, 9, 4, 9, 0),
  4068. datetime(1997, 9, 9, 9, 0)])
  4069. def testSetDate(self):
  4070. rrset = rruleset()
  4071. rrset.rrule(rrule(YEARLY, count=1, byweekday=TU,
  4072. dtstart=datetime(1997, 9, 2, 9, 0)))
  4073. rrset.rdate(datetime(1997, 9, 4, 9))
  4074. rrset.rdate(datetime(1997, 9, 9, 9))
  4075. self.assertEqual(list(rrset),
  4076. [datetime(1997, 9, 2, 9, 0),
  4077. datetime(1997, 9, 4, 9, 0),
  4078. datetime(1997, 9, 9, 9, 0)])
  4079. def testSetExRule(self):
  4080. rrset = rruleset()
  4081. rrset.rrule(rrule(YEARLY, count=6, byweekday=(TU, TH),
  4082. dtstart=datetime(1997, 9, 2, 9, 0)))
  4083. rrset.exrule(rrule(YEARLY, count=3, byweekday=TH,
  4084. dtstart=datetime(1997, 9, 2, 9, 0)))
  4085. self.assertEqual(list(rrset),
  4086. [datetime(1997, 9, 2, 9, 0),
  4087. datetime(1997, 9, 9, 9, 0),
  4088. datetime(1997, 9, 16, 9, 0)])
  4089. def testSetExDate(self):
  4090. rrset = rruleset()
  4091. rrset.rrule(rrule(YEARLY, count=6, byweekday=(TU, TH),
  4092. dtstart=datetime(1997, 9, 2, 9, 0)))
  4093. rrset.exdate(datetime(1997, 9, 4, 9))
  4094. rrset.exdate(datetime(1997, 9, 11, 9))
  4095. rrset.exdate(datetime(1997, 9, 18, 9))
  4096. self.assertEqual(list(rrset),
  4097. [datetime(1997, 9, 2, 9, 0),
  4098. datetime(1997, 9, 9, 9, 0),
  4099. datetime(1997, 9, 16, 9, 0)])
  4100. def testSetExDateRevOrder(self):
  4101. rrset = rruleset()
  4102. rrset.rrule(rrule(MONTHLY, count=5, bymonthday=10,
  4103. dtstart=datetime(2004, 1, 1, 9, 0)))
  4104. rrset.exdate(datetime(2004, 4, 10, 9, 0))
  4105. rrset.exdate(datetime(2004, 2, 10, 9, 0))
  4106. self.assertEqual(list(rrset),
  4107. [datetime(2004, 1, 10, 9, 0),
  4108. datetime(2004, 3, 10, 9, 0),
  4109. datetime(2004, 5, 10, 9, 0)])
  4110. def testSetDateAndExDate(self):
  4111. rrset = rruleset()
  4112. rrset.rdate(datetime(1997, 9, 2, 9))
  4113. rrset.rdate(datetime(1997, 9, 4, 9))
  4114. rrset.rdate(datetime(1997, 9, 9, 9))
  4115. rrset.rdate(datetime(1997, 9, 11, 9))
  4116. rrset.rdate(datetime(1997, 9, 16, 9))
  4117. rrset.rdate(datetime(1997, 9, 18, 9))
  4118. rrset.exdate(datetime(1997, 9, 4, 9))
  4119. rrset.exdate(datetime(1997, 9, 11, 9))
  4120. rrset.exdate(datetime(1997, 9, 18, 9))
  4121. self.assertEqual(list(rrset),
  4122. [datetime(1997, 9, 2, 9, 0),
  4123. datetime(1997, 9, 9, 9, 0),
  4124. datetime(1997, 9, 16, 9, 0)])
  4125. def testSetDateAndExRule(self):
  4126. rrset = rruleset()
  4127. rrset.rdate(datetime(1997, 9, 2, 9))
  4128. rrset.rdate(datetime(1997, 9, 4, 9))
  4129. rrset.rdate(datetime(1997, 9, 9, 9))
  4130. rrset.rdate(datetime(1997, 9, 11, 9))
  4131. rrset.rdate(datetime(1997, 9, 16, 9))
  4132. rrset.rdate(datetime(1997, 9, 18, 9))
  4133. rrset.exrule(rrule(YEARLY, count=3, byweekday=TH,
  4134. dtstart=datetime(1997, 9, 2, 9, 0)))
  4135. self.assertEqual(list(rrset),
  4136. [datetime(1997, 9, 2, 9, 0),
  4137. datetime(1997, 9, 9, 9, 0),
  4138. datetime(1997, 9, 16, 9, 0)])
  4139. def testSetCount(self):
  4140. rrset = rruleset()
  4141. rrset.rrule(rrule(YEARLY, count=6, byweekday=(TU, TH),
  4142. dtstart=datetime(1997, 9, 2, 9, 0)))
  4143. rrset.exrule(rrule(YEARLY, count=3, byweekday=TH,
  4144. dtstart=datetime(1997, 9, 2, 9, 0)))
  4145. self.assertEqual(rrset.count(), 3)
  4146. def testSetCachePre(self):
  4147. rrset = rruleset()
  4148. rrset.rrule(rrule(YEARLY, count=2, byweekday=TU,
  4149. dtstart=datetime(1997, 9, 2, 9, 0)))
  4150. rrset.rrule(rrule(YEARLY, count=1, byweekday=TH,
  4151. dtstart=datetime(1997, 9, 2, 9, 0)))
  4152. self.assertEqual(list(rrset),
  4153. [datetime(1997, 9, 2, 9, 0),
  4154. datetime(1997, 9, 4, 9, 0),
  4155. datetime(1997, 9, 9, 9, 0)])
  4156. def testSetCachePost(self):
  4157. rrset = rruleset(cache=True)
  4158. rrset.rrule(rrule(YEARLY, count=2, byweekday=TU,
  4159. dtstart=datetime(1997, 9, 2, 9, 0)))
  4160. rrset.rrule(rrule(YEARLY, count=1, byweekday=TH,
  4161. dtstart=datetime(1997, 9, 2, 9, 0)))
  4162. for x in rrset: pass
  4163. self.assertEqual(list(rrset),
  4164. [datetime(1997, 9, 2, 9, 0),
  4165. datetime(1997, 9, 4, 9, 0),
  4166. datetime(1997, 9, 9, 9, 0)])
  4167. def testSetCachePostInternal(self):
  4168. rrset = rruleset(cache=True)
  4169. rrset.rrule(rrule(YEARLY, count=2, byweekday=TU,
  4170. dtstart=datetime(1997, 9, 2, 9, 0)))
  4171. rrset.rrule(rrule(YEARLY, count=1, byweekday=TH,
  4172. dtstart=datetime(1997, 9, 2, 9, 0)))
  4173. for x in rrset: pass
  4174. self.assertEqual(list(rrset._cache),
  4175. [datetime(1997, 9, 2, 9, 0),
  4176. datetime(1997, 9, 4, 9, 0),
  4177. datetime(1997, 9, 9, 9, 0)])
  4178. def testSetRRuleCount(self):
  4179. # Test that the count is updated when an rrule is added
  4180. rrset = rruleset(cache=False)
  4181. for cache in (True, False):
  4182. rrset = rruleset(cache=cache)
  4183. rrset.rrule(rrule(YEARLY, count=2, byweekday=TH,
  4184. dtstart=datetime(1983, 4, 1)))
  4185. rrset.rrule(rrule(WEEKLY, count=4, byweekday=FR,
  4186. dtstart=datetime(1991, 6, 3)))
  4187. # Check the length twice - first one sets a cache, second reads it
  4188. self.assertEqual(rrset.count(), 6)
  4189. self.assertEqual(rrset.count(), 6)
  4190. # This should invalidate the cache and force an update
  4191. rrset.rrule(rrule(MONTHLY, count=3, dtstart=datetime(1994, 1, 3)))
  4192. self.assertEqual(rrset.count(), 9)
  4193. self.assertEqual(rrset.count(), 9)
  4194. def testSetRDateCount(self):
  4195. # Test that the count is updated when an rdate is added
  4196. rrset = rruleset(cache=False)
  4197. for cache in (True, False):
  4198. rrset = rruleset(cache=cache)
  4199. rrset.rrule(rrule(YEARLY, count=2, byweekday=TH,
  4200. dtstart=datetime(1983, 4, 1)))
  4201. rrset.rrule(rrule(WEEKLY, count=4, byweekday=FR,
  4202. dtstart=datetime(1991, 6, 3)))
  4203. # Check the length twice - first one sets a cache, second reads it
  4204. self.assertEqual(rrset.count(), 6)
  4205. self.assertEqual(rrset.count(), 6)
  4206. # This should invalidate the cache and force an update
  4207. rrset.rdate(datetime(1993, 2, 14))
  4208. self.assertEqual(rrset.count(), 7)
  4209. self.assertEqual(rrset.count(), 7)
  4210. def testSetExRuleCount(self):
  4211. # Test that the count is updated when an exrule is added
  4212. rrset = rruleset(cache=False)
  4213. for cache in (True, False):
  4214. rrset = rruleset(cache=cache)
  4215. rrset.rrule(rrule(YEARLY, count=2, byweekday=TH,
  4216. dtstart=datetime(1983, 4, 1)))
  4217. rrset.rrule(rrule(WEEKLY, count=4, byweekday=FR,
  4218. dtstart=datetime(1991, 6, 3)))
  4219. # Check the length twice - first one sets a cache, second reads it
  4220. self.assertEqual(rrset.count(), 6)
  4221. self.assertEqual(rrset.count(), 6)
  4222. # This should invalidate the cache and force an update
  4223. rrset.exrule(rrule(WEEKLY, count=2, interval=2,
  4224. dtstart=datetime(1991, 6, 14)))
  4225. self.assertEqual(rrset.count(), 4)
  4226. self.assertEqual(rrset.count(), 4)
  4227. def testSetExDateCount(self):
  4228. # Test that the count is updated when an rdate is added
  4229. for cache in (True, False):
  4230. rrset = rruleset(cache=cache)
  4231. rrset.rrule(rrule(YEARLY, count=2, byweekday=TH,
  4232. dtstart=datetime(1983, 4, 1)))
  4233. rrset.rrule(rrule(WEEKLY, count=4, byweekday=FR,
  4234. dtstart=datetime(1991, 6, 3)))
  4235. # Check the length twice - first one sets a cache, second reads it
  4236. self.assertEqual(rrset.count(), 6)
  4237. self.assertEqual(rrset.count(), 6)
  4238. # This should invalidate the cache and force an update
  4239. rrset.exdate(datetime(1991, 6, 28))
  4240. self.assertEqual(rrset.count(), 5)
  4241. self.assertEqual(rrset.count(), 5)
  4242. class WeekdayTest(unittest.TestCase):
  4243. def testInvalidNthWeekday(self):
  4244. with self.assertRaises(ValueError):
  4245. FR(0)
  4246. def testWeekdayCallable(self):
  4247. # Calling a weekday instance generates a new weekday instance with the
  4248. # value of n changed.
  4249. from dateutil.rrule import weekday
  4250. self.assertEqual(MO(1), weekday(0, 1))
  4251. # Calling a weekday instance with the identical n returns the original
  4252. # object
  4253. FR_3 = weekday(4, 3)
  4254. self.assertIs(FR_3(3), FR_3)
  4255. def testWeekdayEquality(self):
  4256. # Two weekday objects are not equal if they have different values for n
  4257. self.assertNotEqual(TH, TH(-1))
  4258. self.assertNotEqual(SA(3), SA(2))
  4259. def testWeekdayEqualitySubclass(self):
  4260. # Two weekday objects equal if their "weekday" and "n" attributes are
  4261. # available and the same
  4262. class BasicWeekday(object):
  4263. def __init__(self, weekday):
  4264. self.weekday = weekday
  4265. class BasicNWeekday(BasicWeekday):
  4266. def __init__(self, weekday, n=None):
  4267. super(BasicNWeekday, self).__init__(weekday)
  4268. self.n = n
  4269. MO_Basic = BasicWeekday(0)
  4270. self.assertNotEqual(MO, MO_Basic)
  4271. self.assertNotEqual(MO(1), MO_Basic)
  4272. TU_BasicN = BasicNWeekday(1)
  4273. self.assertEqual(TU, TU_BasicN)
  4274. self.assertNotEqual(TU(3), TU_BasicN)
  4275. WE_Basic3 = BasicNWeekday(2, 3)
  4276. self.assertEqual(WE(3), WE_Basic3)
  4277. self.assertNotEqual(WE(2), WE_Basic3)
  4278. def testWeekdayReprNoN(self):
  4279. no_n_reprs = ('MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU')
  4280. no_n_wdays = (MO, TU, WE, TH, FR, SA, SU)
  4281. for repstr, wday in zip(no_n_reprs, no_n_wdays):
  4282. self.assertEqual(repr(wday), repstr)
  4283. def testWeekdayReprWithN(self):
  4284. with_n_reprs = ('WE(+1)', 'TH(-2)', 'SU(+3)')
  4285. with_n_wdays = (WE(1), TH(-2), SU(+3))
  4286. for repstr, wday in zip(with_n_reprs, with_n_wdays):
  4287. self.assertEqual(repr(wday), repstr)