1 #!/usr/bin/env python 2 3 """ 4 Test periods. 5 6 Copyright (C) 2016 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 imiptools.dates import format_datetime 23 from imiptools.period import Period, get_overlapping 24 25 l1 = [ 26 Period("20160501T020000Z", "20160501T045000Z"), 27 Period("20160501T023000Z", "20160501T030000Z"), 28 Period("20160501T024500Z", "20160501T031500Z"), 29 Period("20160501T040000Z", "20160501T043000Z"), 30 Period("20160501T050000Z", "20160501T060000Z"), 31 Period("20160501T051500Z", "20160501T054500Z"), 32 Period("20160501T052000Z", "20160501T053000Z"), 33 Period("20160501T090000Z", "20160501T093000Z"), 34 Period("20160501T094000Z", "20160501T104000Z"), 35 Period("20160501T100000Z", "20160501T110000Z"), 36 ] 37 38 l2 = [ 39 Period("20160501T010000Z", "20160501T020000Z"), 40 Period("20160501T013000Z", "20160501T014000Z"), 41 Period("20160501T014000Z", "20160501T015000Z"), 42 Period("20160501T020000Z", "20160501T033000Z"), 43 Period("20160501T040000Z", "20160501T044000Z"), 44 Period("20160501T050000Z", "20160501T051000Z"), 45 Period("20160501T052000Z", "20160501T053000Z"), 46 Period("20160501T085900Z", "20160501T090000Z"), 47 Period("20160501T085900Z", "20160501T090100Z"), 48 Period("20160501T100000Z", "20160501T110000Z"), 49 ] 50 51 o1 = [ 52 Period("20160501T020000Z", "20160501T045000Z"), 53 Period("20160501T023000Z", "20160501T030000Z"), 54 Period("20160501T024500Z", "20160501T031500Z"), 55 Period("20160501T040000Z", "20160501T043000Z"), 56 Period("20160501T050000Z", "20160501T060000Z"), 57 Period("20160501T051500Z", "20160501T054500Z"), 58 Period("20160501T052000Z", "20160501T053000Z"), 59 Period("20160501T090000Z", "20160501T093000Z"), 60 Period("20160501T094000Z", "20160501T104000Z"), 61 Period("20160501T100000Z", "20160501T110000Z"), 62 ] 63 64 o2 = [ 65 Period("20160501T020000Z", "20160501T033000Z"), 66 Period("20160501T040000Z", "20160501T044000Z"), 67 Period("20160501T050000Z", "20160501T051000Z"), 68 Period("20160501T052000Z", "20160501T053000Z"), 69 Period("20160501T085900Z", "20160501T090100Z"), 70 Period("20160501T100000Z", "20160501T110000Z"), 71 ] 72 73 print o1 == get_overlapping(l1, l2) 74 75 for p in get_overlapping(l1, l2): 76 print format_datetime(p.get_start_point()), format_datetime(p.get_end_point()) 77 78 print "----" 79 80 print o2 == get_overlapping(l2, l1) 81 82 for p in get_overlapping(l2, l1): 83 print format_datetime(p.get_start_point()), format_datetime(p.get_end_point()) 84 85 print "----" 86 87 l1[0] = Period("20160501T020000Z", "20160501T120000Z") 88 o1[0] = l1[0] 89 print o1 == get_overlapping(l1, l2) 90 91 for p in get_overlapping(l1, l2): 92 print format_datetime(p.get_start_point()), format_datetime(p.get_end_point()) 93 94 print "----" 95 96 o2 = l2[3:] 97 print o2 == get_overlapping(l2, l1) 98 99 for p in get_overlapping(l2, l1): 100 print format_datetime(p.get_start_point()), format_datetime(p.get_end_point()) 101 102 # vim: tabstop=4 expandtab shiftwidth=4