1 #!/usr/bin/env python 2 3 """ 4 Test qualifiers for recurring events. 5 6 Copyright (C) 2014, 2015, 2017 Paul Boddie <paul@boddie.org.uk> 7 8 This program is free software; you can redistribute it and/or modify it under 9 the terms of the GNU General Public License as published by the Free Software 10 Foundation; either version 3 of the License, or (at your option) any later 11 version. 12 13 This program is distributed in the hope that it will be useful, but WITHOUT 14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 15 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 16 details. 17 18 You should have received a copy of the GNU General Public License along with 19 this program. If not, see <http://www.gnu.org/licenses/>. 20 """ 21 22 from vRecurrence import * 23 24 def show(l): 25 for x in l: 26 print x 27 print 28 29 qualifiers = [ 30 ("YEARLY", {"interval" : 1}) 31 ] 32 33 l = order_qualifiers(qualifiers) 34 show(l) 35 dt = (1997, 11, 2) 36 l = get_datetime_structure(dt) 37 show(l) 38 l = combine_datetime_with_qualifiers(dt, qualifiers) 39 show(l) 40 41 s = get_selector(dt, qualifiers) 42 l = s.materialise(dt, (2003, 12, 24)) 43 print len(l) == 7, 7, len(l) 44 print l[0] == (1997, 11, 2), (1997, 11, 2), l[0] 45 print l[-1] == (2003, 11, 2), (2003, 11, 2), l[-1] 46 print 47 48 qualifiers = [ 49 ("YEARLY", {"interval" : 2}), 50 ("BYMONTH", {"values" : [1]}), 51 ("BYDAY", {"values" : [(6, None)]}), 52 ("BYHOUR", {"values" : [8, 9]}), 53 ("BYMINUTE", {"values" : [30]}) 54 ] 55 56 l = order_qualifiers(qualifiers) 57 show(l) 58 dt = (1997, 1, 5, 8, 30, 0) 59 l = get_datetime_structure(dt) 60 show(l) 61 l = combine_datetime_with_qualifiers(dt, qualifiers) 62 show(l) 63 64 s = get_selector(dt, qualifiers) 65 l = s.materialise(dt, (2003, 12, 24, 0, 0, 0)) 66 print len(l) == 32, 32, len(l) 67 print l[0] == (1997, 1, 11, 8, 30, 0), (1997, 1, 11, 8, 30, 0), l[0] 68 print l[-1] == (2003, 1, 25, 9, 30, 0), (2003, 1, 25, 9, 30, 0), l[-1] 69 print 70 71 qualifiers = [ 72 ("DAILY", {"interval" : 1}), 73 ("COUNT", {"values" : [10]}) 74 ] 75 76 l = order_qualifiers(qualifiers) 77 show(l) 78 dt = (1997, 9, 2, 9, 0, 0) 79 l = get_datetime_structure(dt) 80 show(l) 81 l = combine_datetime_with_qualifiers(dt, qualifiers) 82 show(l) 83 84 s = get_selector(dt, qualifiers) 85 l = s.materialise(dt, (1997, 12, 24)) 86 print len(l) == 10, 10, len(l) 87 print l[0] == (1997, 9, 2, 9, 0, 0), (1997, 9, 2, 9, 0, 0), l[0] 88 print l[-1] == (1997, 9, 11, 9, 0, 0), (1997, 9, 11, 9, 0, 0), l[-1] 89 print 90 91 qualifiers = [ 92 ("DAILY", {"interval" : 1}) 93 ] 94 95 l = order_qualifiers(qualifiers) 96 show(l) 97 dt = (1997, 9, 2, 9, 0, 0) 98 l = get_datetime_structure(dt) 99 show(l) 100 l = combine_datetime_with_qualifiers(dt, qualifiers) 101 show(l) 102 103 s = get_selector(dt, qualifiers) 104 l = s.materialise(dt, (1997, 12, 24, 0, 0, 0)) 105 print len(l) == 113, 113, len(l) 106 print l[0] == (1997, 9, 2, 9, 0, 0), (1997, 9, 2, 9, 0, 0), l[0] 107 print l[-1] == (1997, 12, 23, 9, 0, 0), (1997, 12, 23, 9, 0, 0), l[-1] 108 print 109 110 qualifiers = [ 111 ("DAILY", {"interval" : 2}) 112 ] 113 114 l = order_qualifiers(qualifiers) 115 show(l) 116 dt = (1997, 9, 2, 9, 0, 0) 117 l = get_datetime_structure(dt) 118 show(l) 119 l = combine_datetime_with_qualifiers(dt, qualifiers) 120 show(l) 121 122 s = get_selector(dt, qualifiers) 123 l = s.materialise(dt, (1997, 12, 24, 0, 0, 0)) 124 print len(l) == 57, 57, len(l) 125 print l[0] == (1997, 9, 2, 9, 0, 0), (1997, 9, 2, 9, 0, 0), l[0] 126 print l[-1] == (1997, 12, 23, 9, 0, 0), (1997, 12, 23, 9, 0, 0), l[-1] 127 print 128 129 qualifiers = [ 130 ("WEEKLY", {"interval" : 1}) 131 ] 132 133 l = order_qualifiers(qualifiers) 134 show(l) 135 dt = (1997, 9, 2, 9, 0, 0) 136 l = get_datetime_structure(dt) 137 show(l) 138 l = combine_datetime_with_qualifiers(dt, qualifiers) 139 show(l) 140 141 s = get_selector(dt, qualifiers) 142 l = s.materialise(dt, (1997, 12, 24, 0, 0, 0)) 143 print len(l) == 17, 17, len(l) 144 print l[0] == (1997, 9, 2, 9, 0, 0), (1997, 9, 2, 9, 0, 0), l[0] 145 print l[-1] == (1997, 12, 23, 9, 0, 0), (1997, 12, 23, 9, 0, 0), l[-1] 146 print 147 148 qualifiers = [ 149 ("DAILY", {"interval" : 10}), 150 ("COUNT", {"values" : [5]}) 151 ] 152 153 l = order_qualifiers(qualifiers) 154 show(l) 155 dt = (1997, 9, 2, 9, 0, 0) 156 l = get_datetime_structure(dt) 157 show(l) 158 l = combine_datetime_with_qualifiers(dt, qualifiers) 159 show(l) 160 161 s = get_selector(dt, qualifiers) 162 l = s.materialise(dt, (1997, 12, 24, 0, 0, 0)) 163 print len(l) == 5, 5, len(l) 164 print l[0] == (1997, 9, 2, 9, 0, 0), (1997, 9, 2, 9, 0, 0), l[0] 165 print l[-1] == (1997, 10, 12, 9, 0, 0), (1997, 10, 12, 9, 0, 0), l[-1] 166 print 167 168 qualifiers = [ 169 ("YEARLY", {"interval" : 1}), 170 ("BYMONTH", {"values" : [1]}), 171 ("BYDAY", {"values" : [(1, None), (2, None), (3, None), (4, None), (5, None), (6, None), (7, None)]}) 172 ] 173 174 l = order_qualifiers(qualifiers) 175 show(l) 176 dt = (1998, 1, 1, 9, 0, 0) 177 l = get_datetime_structure(dt) 178 show(l) 179 l = combine_datetime_with_qualifiers(dt, qualifiers) 180 show(l) 181 182 s = get_selector(dt, qualifiers) 183 l = s.materialise(dt, (2000, 1, 31, 14, 0, 0)) 184 print len(l) == 93, 93, len(l) 185 print l[0] == (1998, 1, 1, 9, 0, 0), (1998, 1, 1, 9, 0, 0), l[0] 186 print l[-1] == (2000, 1, 31, 9, 0, 0), (2000, 1, 31, 9, 0, 0), l[-1] 187 print 188 189 qualifiers = [ 190 ("DAILY", {"interval" : 1}), 191 ("BYMONTH", {"values" : [1]}) 192 ] 193 194 l = order_qualifiers(qualifiers) 195 show(l) 196 dt = (1998, 1, 1, 9, 0, 0) 197 l = get_datetime_structure(dt) 198 show(l) 199 l = combine_datetime_with_qualifiers(dt, qualifiers) 200 show(l) 201 202 s = get_selector(dt, qualifiers) 203 l = s.materialise(dt, (2000, 1, 31, 14, 0, 0)) 204 print len(l) == 93, 93, len(l) 205 print l[0] == (1998, 1, 1, 9, 0, 0), (1998, 1, 1, 9, 0, 0), l[0] 206 print l[-1] == (2000, 1, 31, 9, 0, 0), (2000, 1, 31, 9, 0, 0), l[-1] 207 print 208 209 qualifiers = [ 210 ("WEEKLY", {"interval" : 1}), 211 ("COUNT", {"values" : [10]}) 212 ] 213 214 l = order_qualifiers(qualifiers) 215 show(l) 216 dt = (1997, 9, 2, 9, 0, 0) 217 l = get_datetime_structure(dt) 218 show(l) 219 l = combine_datetime_with_qualifiers(dt, qualifiers) 220 show(l) 221 222 s = get_selector(dt, qualifiers) 223 l = s.materialise(dt, (1997, 12, 24, 0, 0, 0)) 224 print len(l) == 10, 10, len(l) 225 print l[0] == (1997, 9, 2, 9, 0, 0), (1997, 9, 2, 9, 0, 0), l[0] 226 print l[-1] == (1997, 11, 4, 9, 0, 0), (1997, 11, 4, 9, 0, 0), l[-1] 227 print 228 229 qualifiers = [ 230 ("WEEKLY", {"interval" : 1}) 231 ] 232 233 l = order_qualifiers(qualifiers) 234 show(l) 235 dt = (1997, 9, 2, 9, 0, 0) 236 l = get_datetime_structure(dt) 237 show(l) 238 l = combine_datetime_with_qualifiers(dt, qualifiers) 239 show(l) 240 241 s = get_selector(dt, qualifiers) 242 l = s.materialise(dt, (1997, 12, 24, 0, 0, 0)) 243 print len(l) == 17, 17, len(l) 244 print l[0] == (1997, 9, 2, 9, 0, 0), (1997, 9, 2, 9, 0, 0), l[0] 245 print l[-1] == (1997, 12, 23, 9, 0, 0), (1997, 12, 23, 9, 0, 0), l[-1] 246 print 247 248 qualifiers = [ 249 ("WEEKLY", {"interval" : 1}) 250 ] 251 252 l = order_qualifiers(qualifiers) 253 show(l) 254 dt = (1997, 9, 2) 255 l = get_datetime_structure(dt) 256 show(l) 257 l = combine_datetime_with_qualifiers(dt, qualifiers) 258 show(l) 259 260 s = get_selector(dt, qualifiers) 261 l = s.materialise(dt, (1997, 12, 24, 0, 0, 0)) 262 print len(l) == 17, 17, len(l) 263 print l[0] == (1997, 9, 2), (1997, 9, 2), l[0] 264 print l[-1] == (1997, 12, 23), (1997, 12, 23), l[-1] 265 print 266 267 qualifiers = [ 268 ("WEEKLY", {"interval" : 2}) 269 ] 270 271 l = order_qualifiers(qualifiers) 272 show(l) 273 dt = (1997, 9, 2, 9, 0, 0) 274 l = get_datetime_structure(dt) 275 show(l) 276 l = combine_datetime_with_qualifiers(dt, qualifiers) 277 show(l) 278 279 s = get_selector(dt, qualifiers) 280 l = s.materialise(dt, (1998, 2, 20, 0, 0, 0)) 281 print len(l) == 13, 13, len(l) 282 print l[0] == (1997, 9, 2, 9, 0, 0), (1997, 9, 2, 9, 0, 0), l[0] 283 print l[-1] == (1998, 2, 17, 9, 0, 0), (1998, 2, 17, 9, 0, 0), l[-1] 284 print 285 286 qualifiers = [ 287 ("WEEKLY", {"interval" : 1}), 288 ("BYDAY", {"values" : [(2, None), (4, None)]}) 289 ] 290 291 l = order_qualifiers(qualifiers) 292 show(l) 293 dt = (1997, 9, 2, 9, 0, 0) 294 l = get_datetime_structure(dt) 295 show(l) 296 l = combine_datetime_with_qualifiers(dt, qualifiers) 297 show(l) 298 299 s = get_selector(dt, qualifiers) 300 l = s.materialise(dt, (1997, 10, 7, 9, 0, 0)) 301 print len(l) == 10, 10, len(l) 302 print l[0] == (1997, 9, 2, 9, 0, 0), (1997, 9, 2, 9, 0, 0), l[0] 303 print l[-1] == (1997, 10, 2, 9, 0, 0), (1997, 10, 2, 9, 0, 0), l[-1] 304 print 305 306 qualifiers = [ 307 ("WEEKLY", {"interval" : 1}), 308 ("BYDAY", {"values" : [(2, None), (4, None)]}), 309 ("COUNT", {"values" : [10]}) 310 ] 311 312 l = order_qualifiers(qualifiers) 313 show(l) 314 dt = (1997, 9, 2, 9, 0, 0) 315 l = get_datetime_structure(dt) 316 show(l) 317 l = combine_datetime_with_qualifiers(dt, qualifiers) 318 show(l) 319 320 s = get_selector(dt, qualifiers) 321 l = s.materialise(dt, (1997, 12, 24, 0, 0, 0)) 322 print len(l) == 10, 10, len(l) 323 print l[0] == (1997, 9, 2, 9, 0, 0), (1997, 9, 2, 9, 0, 0), l[0] 324 print l[-1] == (1997, 10, 2, 9, 0, 0), (1997, 10, 2, 9, 0, 0), l[-1] 325 print 326 327 qualifiers = [ 328 ("WEEKLY", {"interval" : 2}), 329 ("BYDAY", {"values" : [(1, None), (3, None), (5, None)]}) 330 ] 331 332 l = order_qualifiers(qualifiers) 333 show(l) 334 dt = (1997, 9, 1, 9, 0, 0) 335 l = get_datetime_structure(dt) 336 show(l) 337 l = combine_datetime_with_qualifiers(dt, qualifiers) 338 show(l) 339 340 s = get_selector(dt, qualifiers) 341 l = s.materialise(dt, (1997, 12, 24, 0, 0, 0)) 342 print len(l) == 25, 25, len(l) 343 print l[0] == (1997, 9, 1, 9, 0, 0), (1997, 9, 1, 9, 0, 0), l[0] 344 print l[-1] == (1997, 12, 22, 9, 0, 0), (1997, 12, 22, 9, 0, 0), l[-1] 345 print 346 347 qualifiers = [ 348 ("WEEKLY", {"interval" : 2}), 349 ("BYDAY", {"values" : [(2, None), (4, None)]}), 350 ("COUNT", {"values" : [8]}) 351 ] 352 353 l = order_qualifiers(qualifiers) 354 show(l) 355 dt = (1997, 9, 2, 9, 0, 0) 356 l = get_datetime_structure(dt) 357 show(l) 358 l = combine_datetime_with_qualifiers(dt, qualifiers) 359 show(l) 360 361 s = get_selector(dt, qualifiers) 362 l = s.materialise(dt, (1997, 12, 24, 0, 0, 0)) 363 print len(l) == 8, 8, len(l) 364 print l[0] == (1997, 9, 2, 9, 0, 0), (1997, 9, 2, 9, 0, 0), l[0] 365 print l[-1] == (1997, 10, 16, 9, 0, 0), (1997, 10, 16, 9, 0, 0), l[-1] 366 print 367 368 qualifiers = [ 369 ("MONTHLY", {"interval" : 1}), 370 ("BYDAY", {"values" : [(5, 1)]}), 371 ("COUNT", {"values" : [10]}) 372 ] 373 374 l = order_qualifiers(qualifiers) 375 show(l) 376 dt = (1997, 9, 5, 9, 0, 0) 377 l = get_datetime_structure(dt) 378 show(l) 379 l = combine_datetime_with_qualifiers(dt, qualifiers) 380 show(l) 381 382 s = get_selector(dt, qualifiers) 383 l = s.materialise(dt, (1998, 12, 24, 0, 0, 0)) 384 print len(l) == 10, 10, len(l) 385 print l[0] == (1997, 9, 5, 9, 0, 0), (1997, 9, 5, 9, 0, 0), l[0] 386 print l[-1] == (1998, 6, 5, 9, 0, 0), (1998, 6, 5, 9, 0, 0), l[-1] 387 print 388 389 qualifiers = [ 390 ("MONTHLY", {"interval" : 1}), 391 ("BYDAY", {"values" : [(5, 1)]}) 392 ] 393 394 l = order_qualifiers(qualifiers) 395 show(l) 396 dt = (1997, 9, 5, 9, 0, 0) 397 l = get_datetime_structure(dt) 398 show(l) 399 l = combine_datetime_with_qualifiers(dt, qualifiers) 400 show(l) 401 402 s = get_selector(dt, qualifiers) 403 l = s.materialise(dt, (1997, 12, 24, 0, 0, 0)) 404 print len(l) == 4, 4, len(l) 405 print l[0] == (1997, 9, 5, 9, 0, 0), (1997, 9, 5, 9, 0, 0), l[0] 406 print l[-1] == (1997, 12, 5, 9, 0, 0), (1997, 12, 5, 9, 0, 0), l[-1] 407 print 408 409 qualifiers = [ 410 ("MONTHLY", {"interval" : 2}), 411 ("BYDAY", {"values" : [(7, 1), (7, -1)]}), 412 ("COUNT", {"values" : [10]}) 413 ] 414 415 l = order_qualifiers(qualifiers) 416 show(l) 417 dt = (1997, 9, 7, 9, 0, 0) 418 l = get_datetime_structure(dt) 419 show(l) 420 l = combine_datetime_with_qualifiers(dt, qualifiers) 421 show(l) 422 423 s = get_selector(dt, qualifiers) 424 l = s.materialise(dt, (1998, 12, 24, 0, 0, 0)) 425 print len(l) == 10, 10, len(l) 426 print l[0] == (1997, 9, 7, 9, 0, 0), (1997, 9, 7, 9, 0, 0), l[0] 427 print l[-1] == (1998, 5, 31, 9, 0, 0), (1998, 5, 31, 9, 0, 0), l[-1] 428 print 429 430 qualifiers = [ 431 ("MONTHLY", {"interval" : 1}), 432 ("BYDAY", {"values" : [(1, -2)]}), 433 ("COUNT", {"values" : [6]}) 434 ] 435 436 l = order_qualifiers(qualifiers) 437 show(l) 438 dt = (1997, 9, 22, 9, 0, 0) 439 l = get_datetime_structure(dt) 440 show(l) 441 l = combine_datetime_with_qualifiers(dt, qualifiers) 442 show(l) 443 444 s = get_selector(dt, qualifiers) 445 l = s.materialise(dt, (1998, 12, 24, 0, 0, 0)) 446 print len(l) == 6, 6, len(l) 447 print l[0] == (1997, 9, 22, 9, 0, 0), (1997, 9, 22, 9, 0, 0), l[0] 448 print l[-1] == (1998, 2, 16, 9, 0, 0), (1998, 2, 16, 9, 0, 0), l[-1] 449 print 450 451 qualifiers = [ 452 ("MONTHLY", {"interval" : 1}), 453 ("BYMONTHDAY", {"values" : [-3]}), 454 ("COUNT", {"values" : [6]}) 455 ] 456 457 l = order_qualifiers(qualifiers) 458 show(l) 459 dt = (1997, 9, 28, 9, 0, 0) 460 l = get_datetime_structure(dt) 461 show(l) 462 l = combine_datetime_with_qualifiers(dt, qualifiers) 463 show(l) 464 465 s = get_selector(dt, qualifiers) 466 l = s.materialise(dt, (1998, 12, 24, 0, 0, 0)) 467 print len(l) == 6, 6, len(l) 468 print l[0] == (1997, 9, 28, 9, 0, 0), (1997, 9, 28, 9, 0, 0), l[0] 469 print l[-1] == (1998, 2, 26, 9, 0, 0), (1998, 2, 26, 9, 0, 0), l[-1] 470 print 471 472 qualifiers = [ 473 ("MONTHLY", {"interval" : 1}), 474 ("BYMONTHDAY", {"values" : [15, 2]}), # test ordering 475 ("COUNT", {"values" : [10]}) 476 ] 477 478 l = order_qualifiers(qualifiers) 479 show(l) 480 dt = (1997, 9, 2, 9, 0, 0) 481 l = get_datetime_structure(dt) 482 show(l) 483 l = combine_datetime_with_qualifiers(dt, qualifiers) 484 show(l) 485 486 s = get_selector(dt, qualifiers) 487 l = s.materialise(dt, (1998, 12, 24, 0, 0, 0)) 488 print len(l) == 10, 10, len(l) 489 print l[0] == (1997, 9, 2, 9, 0, 0), (1997, 9, 2, 9, 0, 0), l[0] 490 print l[-1] == (1998, 1, 15, 9, 0, 0), (1998, 1, 15, 9, 0, 0), l[-1] 491 print 492 493 qualifiers = [ 494 ("MONTHLY", {"interval" : 1}), 495 ("BYMONTHDAY", {"values" : [1, -1]}), 496 ("COUNT", {"values" : [10]}) 497 ] 498 499 l = order_qualifiers(qualifiers) 500 show(l) 501 dt = (1997, 9, 30, 9, 0, 0) 502 l = get_datetime_structure(dt) 503 show(l) 504 l = combine_datetime_with_qualifiers(dt, qualifiers) 505 show(l) 506 507 s = get_selector(dt, qualifiers) 508 l = s.materialise(dt, (1998, 12, 24, 0, 0, 0)) 509 print len(l) == 10, 10, len(l) 510 print l[0] == (1997, 9, 30, 9, 0, 0), (1997, 9, 30, 9, 0, 0), l[0] 511 print l[-1] == (1998, 2, 1, 9, 0, 0), (1998, 2, 1, 9, 0, 0), l[-1] 512 print 513 514 qualifiers = [ 515 ("MONTHLY", {"interval" : 18}), 516 ("BYMONTHDAY", {"values" : [10, 11, 12, 13, 14, 15]}), 517 ("COUNT", {"values" : [10]}) 518 ] 519 520 l = order_qualifiers(qualifiers) 521 show(l) 522 dt = (1997, 9, 10, 9, 0, 0) 523 l = get_datetime_structure(dt) 524 show(l) 525 l = combine_datetime_with_qualifiers(dt, qualifiers) 526 show(l) 527 528 s = get_selector(dt, qualifiers) 529 l = s.materialise(dt, (1999, 12, 24, 0, 0, 0)) 530 print len(l) == 10, 10, len(l) 531 print l[0] == (1997, 9, 10, 9, 0, 0), (1997, 9, 10, 9, 0, 0), l[0] 532 print l[-1] == (1999, 3, 13, 9, 0, 0), (1999, 3, 13, 9, 0, 0), l[-1] 533 print 534 535 qualifiers = [ 536 ("MONTHLY", {"interval" : 2}), 537 ("BYDAY", {"values" : [(2, None)]}) 538 ] 539 540 l = order_qualifiers(qualifiers) 541 show(l) 542 dt = (1997, 9, 2, 9, 0, 0) 543 l = get_datetime_structure(dt) 544 show(l) 545 l = combine_datetime_with_qualifiers(dt, qualifiers) 546 show(l) 547 548 s = get_selector(dt, qualifiers) 549 l = s.materialise(dt, (1998, 4, 1, 0, 0, 0)) 550 print len(l) == 18, 18, len(l) 551 print l[0] == (1997, 9, 2, 9, 0, 0), (1997, 9, 2, 9, 0, 0), l[0] 552 print l[-1] == (1998, 3, 31, 9, 0, 0), (1998, 3, 31, 9, 0, 0), l[-1] 553 print 554 555 qualifiers = [ 556 ("YEARLY", {"interval" : 1}), 557 ("BYMONTH", {"values" : [6, 7]}), 558 ("COUNT", {"values" : [10]}) 559 ] 560 561 l = order_qualifiers(qualifiers) 562 show(l) 563 dt = (1997, 6, 10, 9, 0, 0) 564 l = get_datetime_structure(dt) 565 show(l) 566 l = combine_datetime_with_qualifiers(dt, qualifiers) 567 show(l) 568 569 s = get_selector(dt, qualifiers) 570 l = s.materialise(dt, (2001, 12, 24, 0, 0, 0)) 571 print len(l) == 10, 10, len(l) 572 print l[0] == (1997, 6, 10, 9, 0, 0), (1997, 6, 10, 9, 0, 0), l[0] 573 print l[-1] == (2001, 7, 10, 9, 0, 0), (2001, 7, 10, 9, 0, 0), l[-1] 574 print 575 576 qualifiers = [ 577 ("YEARLY", {"interval" : 2}), 578 ("BYMONTH", {"values" : [1, 2, 3]}), 579 ("COUNT", {"values" : [10]}) 580 ] 581 582 l = order_qualifiers(qualifiers) 583 show(l) 584 dt = (1997, 3, 10, 9, 0, 0) 585 l = get_datetime_structure(dt) 586 show(l) 587 l = combine_datetime_with_qualifiers(dt, qualifiers) 588 show(l) 589 590 s = get_selector(dt, qualifiers) 591 l = s.materialise(dt, (2003, 12, 24, 0, 0, 0)) 592 print len(l) == 10, 10, len(l) 593 print l[0] == (1997, 3, 10, 9, 0, 0), (1997, 3, 10, 9, 0, 0), l[0] 594 print l[-1] == (2003, 3, 10, 9, 0, 0), (2003, 3, 10, 9, 0, 0), l[-1] 595 print 596 597 qualifiers = [ 598 ("YEARLY", {"interval" : 3}), 599 ("BYYEARDAY", {"values" : [1, 100, 200]}), 600 ("COUNT", {"values" : [10]}) 601 ] 602 603 l = order_qualifiers(qualifiers) 604 show(l) 605 dt = (1997, 1, 1, 9, 0, 0) 606 l = get_datetime_structure(dt) 607 show(l) 608 l = combine_datetime_with_qualifiers(dt, qualifiers) 609 show(l) 610 611 s = get_selector(dt, qualifiers) 612 l = s.materialise(dt, (2006, 2, 1, 0, 0, 0)) 613 print len(l) == 10, 10, len(l) 614 print l[0] == (1997, 1, 1, 9, 0, 0), (1997, 1, 1, 9, 0, 0), l[0] 615 print l[-1] == (2006, 1, 1, 9, 0, 0), (2006, 1, 1, 9, 0, 0), l[-1] 616 print 617 618 qualifiers = [ 619 ("YEARLY", {"interval" : 1}), 620 ("BYDAY", {"values" : [(1, 20)]}) 621 ] 622 623 l = order_qualifiers(qualifiers) 624 show(l) 625 dt = (1997, 5, 19, 9, 0, 0) 626 l = get_datetime_structure(dt) 627 show(l) 628 l = combine_datetime_with_qualifiers(dt, qualifiers) 629 show(l) 630 631 s = get_selector(dt, qualifiers) 632 l = s.materialise(dt, (1999, 12, 24, 0, 0, 0)) 633 print len(l) == 3, 3, len(l) 634 print l[0] == (1997, 5, 19, 9, 0, 0), (1997, 5, 19, 9, 0, 0), l[0] 635 print l[-1] == (1999, 5, 17, 9, 0, 0), (1999, 5, 17, 9, 0, 0), l[-1] 636 print 637 638 """ 639 qualifiers = [ 640 ("YEARLY", {"interval" : 1}), 641 ("BYWEEKNO", {"values" : [20]}), 642 ("BYDAY", {"values" : [(1, None)]}) 643 ] 644 645 l = order_qualifiers(qualifiers) 646 show(l) 647 dt = (1997, 5, 12, 9, 0, 0) 648 l = get_datetime_structure(dt) 649 show(l) 650 l = combine_datetime_with_qualifiers(dt, qualifiers) 651 show(l) 652 653 s = get_selector(dt, qualifiers) 654 l = s.materialise(dt, (1999, 12, 24, 0, 0, 0)) 655 print len(l) == 3, 3, len(l) 656 print l[0] == (1997, 5, 12, 9, 0, 0), (1997, 5, 12, 9, 0, 0), l[0] 657 print l[-1] == (1999, 5, 17, 9, 0, 0), (1999, 5, 17, 9, 0, 0), l[-1] 658 print 659 """ 660 661 qualifiers = [ 662 ("YEARLY", {"interval" : 1}), 663 ("BYMONTH", {"values" : [3]}), 664 ("BYDAY", {"values" : [(4, None)]}) 665 ] 666 667 l = order_qualifiers(qualifiers) 668 show(l) 669 dt = (1997, 3, 13, 9, 0, 0) 670 l = get_datetime_structure(dt) 671 show(l) 672 l = combine_datetime_with_qualifiers(dt, qualifiers) 673 show(l) 674 675 s = get_selector(dt, qualifiers) 676 l = s.materialise(dt, (1999, 12, 24, 0, 0, 0)) 677 print len(l) == 11, 11, len(l) 678 print l[0] == (1997, 3, 13, 9, 0, 0), (1997, 3, 13, 9, 0, 0), l[0] 679 print l[-1] == (1999, 3, 25, 9, 0, 0), (1999, 3, 25, 9, 0, 0), l[-1] 680 print 681 682 qualifiers = [ 683 ("YEARLY", {"interval" : 1}), 684 ("BYMONTH", {"values" : [6, 7, 8]}), 685 ("BYDAY", {"values" : [(4, None)]}) 686 ] 687 688 l = order_qualifiers(qualifiers) 689 show(l) 690 dt = (1997, 6, 5, 9, 0, 0) 691 l = get_datetime_structure(dt) 692 show(l) 693 l = combine_datetime_with_qualifiers(dt, qualifiers) 694 show(l) 695 696 s = get_selector(dt, qualifiers) 697 l = s.materialise(dt, (1999, 12, 24, 0, 0, 0)) 698 print len(l) == 39, 39, len(l) 699 print l[0] == (1997, 6, 5, 9, 0, 0), (1997, 6, 5, 9, 0, 0), l[0] 700 print l[-1] == (1999, 8, 26, 9, 0, 0), (1999, 8, 26, 9, 0, 0), l[-1] 701 print 702 703 qualifiers = [ 704 ("MONTHLY", {"interval" : 1}), 705 ("BYMONTHDAY", {"values" : [13]}), 706 ("BYDAY", {"values" : [(5, None)]}) 707 ] 708 709 l = order_qualifiers(qualifiers) 710 show(l) 711 dt = (1997, 9, 2, 9, 0, 0) 712 l = get_datetime_structure(dt) 713 show(l) 714 l = combine_datetime_with_qualifiers(dt, qualifiers) 715 show(l) 716 717 s = get_selector(dt, qualifiers) 718 l = s.materialise(dt, (2000, 12, 24, 0, 0, 0)) 719 print len(l) == 5, 5, len(l) 720 print l[0] == (1998, 2, 13, 9, 0, 0), (1998, 2, 13, 9, 0, 0), l[0] 721 print l[-1] == (2000, 10, 13, 9, 0, 0), (2000, 10, 13, 9, 0, 0), l[-1] 722 print 723 724 qualifiers = [ 725 ("MONTHLY", {"interval" : 1}), 726 ("BYMONTHDAY", {"values" : [7, 8, 9, 10, 11, 12, 13]}), 727 ("BYDAY", {"values" : [(6, None)]}) 728 ] 729 730 l = order_qualifiers(qualifiers) 731 show(l) 732 dt = (1997, 9, 13, 9, 0, 0) 733 l = get_datetime_structure(dt) 734 show(l) 735 l = combine_datetime_with_qualifiers(dt, qualifiers) 736 show(l) 737 738 s = get_selector(dt, qualifiers) 739 l = s.materialise(dt, (1998, 6, 30, 0, 0, 0)) 740 print len(l) == 10, 10, len(l) 741 print l[0] == (1997, 9, 13, 9, 0, 0), (1997, 9, 13, 9, 0, 0), l[0] 742 print l[-1] == (1998, 6, 13, 9, 0, 0), (1998, 6, 13, 9, 0, 0), l[-1] 743 print 744 745 qualifiers = [ 746 ("YEARLY", {"interval" : 4}), 747 ("BYMONTH", {"values" : [11]}), 748 ("BYMONTHDAY", {"values" : [2, 3, 4, 5, 6, 7, 8]}), 749 ("BYDAY", {"values" : [(2, None)]}) 750 ] 751 752 l = order_qualifiers(qualifiers) 753 show(l) 754 dt = (1996, 11, 5, 9, 0, 0) 755 l = get_datetime_structure(dt) 756 show(l) 757 l = combine_datetime_with_qualifiers(dt, qualifiers) 758 show(l) 759 760 s = get_selector(dt, qualifiers) 761 l = s.materialise(dt, (2004, 12, 24, 0, 0, 0)) 762 print len(l) == 3, 3, len(l) 763 print l[0] == (1996, 11, 5, 9, 0, 0), (1996, 11, 5, 9, 0, 0), l[0] 764 print l[-1] == (2004, 11, 2, 9, 0, 0), (2004, 11, 2, 9, 0, 0), l[-1] 765 print 766 767 qualifiers = [ 768 ("MONTHLY", {"interval" : 1}), 769 ("BYDAY", {"values" : [(2, None), (3, None), (4, None)]}), 770 ("BYSETPOS", {"values" : [3]}), 771 ("COUNT", {"values" : [3]}) 772 ] 773 774 l = order_qualifiers(qualifiers) 775 show(l) 776 dt = (1997, 9, 4, 9, 0, 0) 777 l = get_datetime_structure(dt) 778 show(l) 779 l = combine_datetime_with_qualifiers(dt, qualifiers) 780 show(l) 781 782 s = get_selector(dt, qualifiers) 783 l = s.materialise(dt, (1997, 12, 24, 0, 0, 0)) 784 print len(l) == 3, 3, len(l) 785 print l[0] == (1997, 9, 4, 9, 0, 0), (1997, 9, 4, 9, 0, 0), l[0] 786 print l[-1] == (1997, 11, 6, 9, 0, 0), (1997, 11, 6, 9, 0, 0), l[-1] 787 print 788 789 l2 = l 790 791 qualifiers = [ 792 ("MONTHLY", {"interval" : 1}), 793 ("BYDAY", {"values" : [(1, None), (2, None), (3, None), (4, None), (5, None)]}), 794 ("BYSETPOS", {"values" : [-2]}) 795 ] 796 797 l = order_qualifiers(qualifiers) 798 show(l) 799 dt = (1997, 9, 29, 9, 0, 0) 800 l = get_datetime_structure(dt) 801 show(l) 802 l = combine_datetime_with_qualifiers(dt, qualifiers) 803 show(l) 804 805 s = get_selector(dt, qualifiers) 806 l = s.materialise(dt, (1998, 4, 1, 0, 0, 0)) 807 print len(l) == 7, 7, len(l) 808 print l[0] == (1997, 9, 29, 9, 0, 0), (1997, 9, 29, 9, 0, 0), l[0] 809 print l[-1] == (1998, 3, 30, 9, 0, 0), (1998, 3, 30, 9, 0, 0), l[-1] 810 print 811 812 qualifiers = get_qualifiers(["FREQ=MONTHLY", "BYMONTHDAY=5", "FREQ=HOURLY", "INTERVAL=12"]) 813 814 l = order_qualifiers(qualifiers) 815 show(l) 816 dt = (2017, 6, 13) 817 l = get_datetime_structure(dt) 818 show(l) 819 l = combine_datetime_with_qualifiers(dt, qualifiers) 820 show(l) 821 822 s = get_selector(dt, qualifiers) 823 l = s.materialise(dt, (2019, 1, 1)) 824 print len(l) == 36 825 print l[0] == (2017, 7, 5, 0), (2017, 7, 5, 0), l[0] 826 print l[-1] == (2018, 12, 5, 12), (2018, 12, 5, 12), l[-1] 827 828 qualifiers = get_qualifiers(["FREQ=DAILY", "BYMONTH=1"]) 829 830 l = order_qualifiers(qualifiers) 831 show(l) 832 dt = (2017, 6, 13) 833 l = get_datetime_structure(dt) 834 show(l) 835 l = combine_datetime_with_qualifiers(dt, qualifiers) 836 show(l) 837 838 s = get_selector(dt, qualifiers) 839 l = s.materialise(dt, (2019, 1, 1)) 840 print len(l) == 31 841 print l[0] == (2018, 1, 1), (2018, 1, 1), l[0] 842 print l[-1] == (2018, 1, 31), (2018, 1, 31), l[-1] 843 844 qualifiers = get_qualifiers(["FREQ=MONTHLY", "BYDAY=WE,1FR,2MO,2FR"]) 845 846 l = order_qualifiers(qualifiers) 847 show(l) 848 dt = (2017, 10, 15) 849 l = get_datetime_structure(dt) 850 show(l) 851 l = combine_datetime_with_qualifiers(dt, qualifiers) 852 show(l) 853 854 s = get_selector(dt, qualifiers) 855 l = s.materialise(dt, (2018, 1, 1)) 856 print len(l) == 17 857 print l[0] == (2017, 10, 18), (2017, 10, 18), l[0] 858 print l[-1] == (2017, 12, 27), (2017, 12, 27), l[-1] 859 860 # vim: tabstop=4 expandtab shiftwidth=4