vContent

Annotated tests/qualifiers.py

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