1 00:00:06,510 --> 00:00:09,120 - But I've also got a structure called Record, okay? 2 00:00:09,120 --> 00:00:12,360 Now you might wonder why I need two structures. 3 00:00:12,360 --> 00:00:16,260 The Record structure, oh, it implements equality 4 00:00:16,260 --> 00:00:18,870 and partial equality traits. 5 00:00:18,870 --> 00:00:20,700 That's an interesting observation. 6 00:00:20,700 --> 00:00:25,410 A Record is a kind of like a summary of a visit. 7 00:00:25,410 --> 00:00:29,730 It just says what date did the visit start 8 00:00:29,730 --> 00:00:32,220 and how many days was it, like so. 9 00:00:32,220 --> 00:00:35,250 So if you compare a visit structure, 10 00:00:35,250 --> 00:00:37,080 and a record structure to see what they contain 11 00:00:37,080 --> 00:00:38,230 let's think about that. 12 00:00:39,210 --> 00:00:43,680 So a visit structure will contain the start date, 13 00:00:43,680 --> 00:00:48,680 like the, we went skiing on the 1st of April, 2023 to 14 00:00:49,020 --> 00:00:51,750 St. Anton in Austria, what a beautiful place. 15 00:00:51,750 --> 00:00:53,400 We were only there for a week, unfortunately. 16 00:00:53,400 --> 00:00:58,400 We came back on the 8th of April 23 and it was to St. Anton. 17 00:00:59,340 --> 00:01:00,960 That's my favorite ski resort. 18 00:01:00,960 --> 00:01:02,190 That would be a visit. 19 00:01:02,190 --> 00:01:04,290 A record on the other hand, 20 00:01:04,290 --> 00:01:06,043 would kind of be a summary of that. 21 00:01:06,043 --> 00:01:09,510 A record would just say it was the 1st of April 22 00:01:09,510 --> 00:01:11,690 when you went, 23. 23 00:01:11,690 --> 00:01:13,950 So it says basically the the date when 24 00:01:13,950 --> 00:01:16,950 the visit started and the number of days that you were away. 25 00:01:16,950 --> 00:01:18,390 So the number of days I've been away 26 00:01:18,390 --> 00:01:20,580 would be seven, isn't it? 27 00:01:20,580 --> 00:01:21,673 I think. 28 00:01:21,673 --> 00:01:23,880 Seven days away like that. 29 00:01:23,880 --> 00:01:28,880 So the visit information is what I read from a file. 30 00:01:29,160 --> 00:01:32,730 So on my file system I'll read visit information, 31 00:01:32,730 --> 00:01:34,770 but it's the record that I'm going to use 32 00:01:34,770 --> 00:01:36,620 in all of my work ins. 33 00:01:36,620 --> 00:01:40,760 When I say, when I'm trying to calculate 34 00:01:40,760 --> 00:01:43,608 the total number of days I've been away, 35 00:01:43,608 --> 00:01:46,804 it'll be this number that I'm going to use. 36 00:01:46,804 --> 00:01:49,800 This record is like a summary of the visit, 37 00:01:49,800 --> 00:01:53,540 and it's only this number really that matters. 38 00:01:53,540 --> 00:01:56,280 And when I output all the information 39 00:01:56,280 --> 00:01:58,110 about how many days I've been away, 40 00:01:58,110 --> 00:02:00,720 it's this record information that'll be displayed. 41 00:02:00,720 --> 00:02:02,820 It'll say you were away on the 42 00:02:02,820 --> 00:02:07,820 1st of April 23 for seven days. 43 00:02:07,860 --> 00:02:10,020 So it's like a simplified summary. 44 00:02:10,020 --> 00:02:12,300 I didn't envisage having this record structure. 45 00:02:12,300 --> 00:02:14,790 Initially I envisaged just using visit, 46 00:02:14,790 --> 00:02:16,860 but then I kept on having to do lots of 47 00:02:16,860 --> 00:02:19,650 like give me the number of days between the start and end. 48 00:02:19,650 --> 00:02:20,970 And I thought I may as well just calculate 49 00:02:20,970 --> 00:02:23,730 that once and store it in here. 50 00:02:23,730 --> 00:02:25,020 So that's the purpose, 51 00:02:25,020 --> 00:02:26,940 the implementation is actually really simple. 52 00:02:26,940 --> 00:02:29,760 I've just got a effectively a constructor 53 00:02:29,760 --> 00:02:32,703 to initialize the date and the number of days, 54 00:02:33,630 --> 00:02:35,610 it implements the display trait. 55 00:02:35,610 --> 00:02:38,640 So it can output a record using the default formatter, 56 00:02:38,640 --> 00:02:42,120 number of days, what date did you start. 57 00:02:42,120 --> 00:02:46,800 It also implements the odd trait and the partial odd trait. 58 00:02:46,800 --> 00:02:48,300 Remember those? 59 00:02:48,300 --> 00:02:51,960 The partial odd trait basically means that you can say, 60 00:02:51,960 --> 00:02:52,950 you could say something like this. 61 00:02:52,950 --> 00:02:57,530 You could say record one, less than record two, like that. 62 00:02:58,771 --> 00:03:02,190 Or record one greater than equal to record two. 63 00:03:02,190 --> 00:03:04,880 So when you implement the partial comp, 64 00:03:04,880 --> 00:03:08,040 it basically, the algorithm here will allow 65 00:03:08,040 --> 00:03:09,840 records to be compared for equality, 66 00:03:09,840 --> 00:03:11,850 less than equal to, I should say. 67 00:03:11,850 --> 00:03:14,760 And then the odd trait above it. 68 00:03:14,760 --> 00:03:17,880 The odd trait, basically it has a max function, 69 00:03:17,880 --> 00:03:21,120 and a min function and a clamp function, remember that? 70 00:03:21,120 --> 00:03:22,740 Where you can bound a value 71 00:03:22,740 --> 00:03:26,310 to be within a certain range, a given maximum and a minimum. 72 00:03:26,310 --> 00:03:28,643 So you could say, for example, something like 73 00:03:28,643 --> 00:03:33,643 if I have record one, and I call max a record two, 74 00:03:33,660 --> 00:03:35,310 it will gimme back the larger 75 00:03:35,310 --> 00:03:37,983 of the two or the smaller of the two. 76 00:03:38,970 --> 00:03:41,610 So this record structure turned out to be 77 00:03:41,610 --> 00:03:46,610 quite useful actually, as we will see in the code. 78 00:03:46,883 --> 00:03:48,663 So there we are. 79 00:03:48,663 --> 00:03:53,663 It's quite, it's not difficult really. 80 00:03:54,270 --> 00:03:57,750 I think it's just tricky rather than being difficult. 81 00:03:57,750 --> 00:04:01,380 And you need to have a look online at the documentation 82 00:04:01,380 --> 00:04:05,610 for NaiveDate to see what options and functions you've got. 83 00:04:05,610 --> 00:04:07,860 So here is the documentation for NaiveDate. 84 00:04:07,860 --> 00:04:10,200 It's the NaiveDate structure 85 00:04:10,200 --> 00:04:13,740 in the Naive Module in the Chrono Crate. 86 00:04:13,740 --> 00:04:16,410 And you can see all the different functions it has here, 87 00:04:16,410 --> 00:04:19,590 for doing date time related operations. 88 00:04:19,590 --> 00:04:23,283 So the function that we called was signed duration since, 89 00:04:24,480 --> 00:04:28,290 you can give it one NaiveDate and another NaiveDate, 90 00:04:28,290 --> 00:04:30,810 and it returns a duration, okay? 91 00:04:30,810 --> 00:04:34,050 And the duration basically allows you to convert 92 00:04:34,050 --> 00:04:36,480 to days and minutes and such like. 93 00:04:36,480 --> 00:04:38,190 So there we are. 94 00:04:38,190 --> 00:04:40,350 That's good coverage, I think, 95 00:04:40,350 --> 00:04:43,323 of how to do date handling in Rust.