1 00:00:06,570 --> 00:00:08,490 - Right, so the only thing we need to look 2 00:00:08,490 --> 00:00:11,649 at now is how do I actually calculate the number of days 3 00:00:11,649 --> 00:00:14,280 prior to a particular date. 4 00:00:14,280 --> 00:00:16,620 So I'm gonna do a quick drawing 5 00:00:16,620 --> 00:00:18,270 just to help you visualize 6 00:00:18,270 --> 00:00:20,940 what that calculation's gonna look like. 7 00:00:20,940 --> 00:00:23,370 And I'm gonna show the code for that function as well. 8 00:00:23,370 --> 00:00:27,240 And this will be the last bit of code 9 00:00:27,240 --> 00:00:29,313 we need to look at in the lesson. 10 00:00:30,810 --> 00:00:32,760 So let's bring up my whiteboard 11 00:00:32,760 --> 00:00:34,833 so we can just see this side by side. 12 00:00:36,390 --> 00:00:41,390 So imagine I'm looking at a particular date, okay? 13 00:00:41,970 --> 00:00:43,530 So it does it for every date, 14 00:00:43,530 --> 00:00:44,850 but let's say I'm looking at a particular date. 15 00:00:44,850 --> 00:00:49,503 Let's say I'm looking at the date is the 11th of August. 16 00:00:51,420 --> 00:00:53,763 So that's the date we're currently looking at. 17 00:00:54,601 --> 00:00:55,434 And it's trying to figure out how many days 18 00:00:55,434 --> 00:00:56,970 were you away in all the visits? 19 00:00:56,970 --> 00:01:00,210 How many days were you away before the 11th of August? 20 00:01:00,210 --> 00:01:02,223 So that's the window end date there. 21 00:01:03,641 --> 00:01:06,360 And obviously what it'll have to do 22 00:01:06,360 --> 00:01:11,100 is have to take that window end date and subtract 180 days. 23 00:01:11,100 --> 00:01:14,460 I've got a constant at the top which says it's 180 days 24 00:01:14,460 --> 00:01:15,540 which of interest. 25 00:01:15,540 --> 00:01:18,938 So it'll calculate the date, 180 days before 26 00:01:18,938 --> 00:01:22,140 the 11th of August would be, I dunno, 27 00:01:22,140 --> 00:01:24,873 something like the 11th of March, 28 00:01:26,070 --> 00:01:28,740 the 11th of month number three 29 00:01:28,740 --> 00:01:29,970 which is about six months 30 00:01:29,970 --> 00:01:33,543 before the 11th of month number eight, 31 00:01:35,213 --> 00:01:36,060 11th of February actually. 32 00:01:36,060 --> 00:01:39,030 February is six months 33 00:01:39,030 --> 00:01:43,101 before August, the 11th of February. 34 00:01:43,101 --> 00:01:47,703 So that is the window start date. 35 00:01:48,750 --> 00:01:51,030 That's the window start date, 36 00:01:51,030 --> 00:01:52,580 and that's the window end date. 37 00:01:53,970 --> 00:01:56,160 And what I do is I iterate over all my visits. 38 00:01:56,160 --> 00:01:57,780 Now, the visits, 39 00:01:57,780 --> 00:01:59,640 remember the visits will have been something like this. 40 00:01:59,640 --> 00:02:01,800 I might have had visits before 41 00:02:01,800 --> 00:02:04,620 the length of February, and like this, 42 00:02:04,620 --> 00:02:07,800 and I might have had a visit that overlapped it like that. 43 00:02:07,800 --> 00:02:10,770 And some other visits and some other visits, 44 00:02:10,770 --> 00:02:13,590 and some other visits and some other visits 45 00:02:13,590 --> 00:02:16,560 that partially overlapped and some other visits here. 46 00:02:16,560 --> 00:02:19,590 So for each of those visits, 47 00:02:19,590 --> 00:02:21,390 for each visit, 48 00:02:21,390 --> 00:02:25,800 let's say it'll take this visit initially. 49 00:02:25,800 --> 00:02:27,960 For that visit, it'll calculate, 50 00:02:27,960 --> 00:02:29,520 for that particular visit, 51 00:02:29,520 --> 00:02:33,030 how many days were you away that are relevant? 52 00:02:33,030 --> 00:02:35,193 We're only looking at this window here. 53 00:02:36,540 --> 00:02:39,060 That's the window that we're looking at at the moment. 54 00:02:39,060 --> 00:02:41,610 So relative to that window, 55 00:02:41,610 --> 00:02:43,665 how many days were you were you away 56 00:02:43,665 --> 00:02:47,100 that are relevant for that particular visit? 57 00:02:47,100 --> 00:02:48,690 And the answer would be zero. 58 00:02:48,690 --> 00:02:52,440 We spent some time looking at this function a bit earlier, 59 00:02:52,440 --> 00:02:53,943 using some maths, it'll realize 60 00:02:53,943 --> 00:02:58,230 that that visit is wholly outside the window of interest. 61 00:02:58,230 --> 00:03:02,973 So the get days in period in that case would return zero. 62 00:03:04,350 --> 00:03:08,193 As it would for this one as well. 63 00:03:09,300 --> 00:03:12,030 This one here would be a bit more interesting 64 00:03:12,030 --> 00:03:14,280 because it kind of straddles the boundary, 65 00:03:14,280 --> 00:03:16,710 but we've seen that the code caters 66 00:03:16,710 --> 00:03:18,210 for that possibility as well. 67 00:03:18,210 --> 00:03:21,630 For that visit, it'll say effectively 68 00:03:21,630 --> 00:03:24,693 the effective start date is kind of here. 69 00:03:25,920 --> 00:03:28,440 We can ignore the dates that appeared before that, 70 00:03:28,440 --> 00:03:31,800 ignore that, and it'll just look at this part of the visit 71 00:03:31,800 --> 00:03:34,410 and say maybe there were three days there 72 00:03:34,410 --> 00:03:35,430 that were relevant. 73 00:03:35,430 --> 00:03:38,310 And it'll add that visit and that visit and that visit. 74 00:03:38,310 --> 00:03:40,590 So for each of these functions, 75 00:03:40,590 --> 00:03:41,670 it'll tell me the number of days 76 00:03:41,670 --> 00:03:43,997 that are relevant for that visit. 77 00:03:43,997 --> 00:03:48,997 Like zero, zero, three, maybe seven for that one. 78 00:03:49,500 --> 00:03:51,900 Seven, seven, maybe three for that one, 79 00:03:51,900 --> 00:03:55,890 zero for that one because it's wholly after the period. 80 00:03:55,890 --> 00:03:59,190 So for each visit, it'll tell me how many days are relevant 81 00:03:59,190 --> 00:04:01,110 and then I just sum them up. 82 00:04:01,110 --> 00:04:02,880 There's a handy sum function. 83 00:04:02,880 --> 00:04:05,640 Having built a collection of numbers, days, 84 00:04:05,640 --> 00:04:07,590 I can just sum them up like so, 85 00:04:07,590 --> 00:04:09,150 and it'll tell me the total number 86 00:04:09,150 --> 00:04:13,890 of days that I was away from the 11th of August, 87 00:04:13,890 --> 00:04:16,680 the total number of days I was away would be, 88 00:04:16,680 --> 00:04:18,240 and it'll tell me the total days. 89 00:04:18,240 --> 00:04:22,053 So the 11th of August that would be come down here, 90 00:04:25,527 --> 00:04:28,380 well, those are then gonna get sorted of course, 91 00:04:28,380 --> 00:04:29,910 the whole point of this is that 92 00:04:29,910 --> 00:04:31,860 these dates here will be sorted, 93 00:04:31,860 --> 00:04:33,630 in the bit of output I'm looking at here. 94 00:04:33,630 --> 00:04:35,520 If I go to the first part of the output 95 00:04:35,520 --> 00:04:38,040 then it outputs 'em in reverse chronological order. 96 00:04:38,040 --> 00:04:40,690 It's easier to me for me to find a date, there we go. 97 00:04:42,207 --> 00:04:44,400 Okay, so the 11th of August 98 00:04:44,400 --> 00:04:47,160 and the 180 days previous, in other words, 99 00:04:47,160 --> 00:04:49,290 if you add up all the bits which are relevant here, 100 00:04:49,290 --> 00:04:53,760 so that bit, and that bit, and that bit, 101 00:04:53,760 --> 00:04:56,133 and that bit, and that bit. 102 00:04:57,330 --> 00:05:00,840 Then it would give you back the total number of 74. 103 00:05:00,840 --> 00:05:02,455 So I finished the lesson now. 104 00:05:02,455 --> 00:05:06,549 I had a lot of fun writing this demo. 105 00:05:06,549 --> 00:05:09,570 I'd rather hope that soon 106 00:05:09,570 --> 00:05:11,280 I won't need this application anymore 107 00:05:11,280 --> 00:05:15,063 because the UK has rejoined Europe, and we live in hope.