@@ -61,11 +61,10 @@ fn collect_dates_from_file(date_regex: &Regex, text: &str) -> Vec<(usize, Date)>
61
61
} ,
62
62
)
63
63
} ) {
64
- for chr in text[ end_of_last_cap..byte_range. end ] . chars ( ) {
65
- if chr == '\n' {
66
- line += 1 ;
67
- }
68
- }
64
+ line += text[ end_of_last_cap..byte_range. end ]
65
+ . chars ( )
66
+ . filter ( |c| * c == '\n' )
67
+ . count ( ) ;
69
68
dates. push ( ( line, date) ) ;
70
69
end_of_last_cap = byte_range. end ;
71
70
}
@@ -87,6 +86,7 @@ fn collect_dates(paths: impl Iterator<Item = PathBuf>) -> BTreeMap<PathBuf, Vec<
87
86
88
87
fn filter_dates (
89
88
current_month : Date ,
89
+ min_months_since : u32 ,
90
90
dates_by_file : impl Iterator < Item = ( PathBuf , Vec < ( usize , Date ) > ) > ,
91
91
) -> impl Iterator < Item = ( PathBuf , Vec < ( usize , Date ) > ) > {
92
92
dates_by_file
@@ -99,7 +99,7 @@ fn filter_dates(
99
99
current_month
100
100
. months_since ( * date)
101
101
. expect ( "found date that is after current month" )
102
- >= 6
102
+ >= min_months_since
103
103
} )
104
104
. collect :: < Vec < _ > > ( ) ,
105
105
)
@@ -121,7 +121,7 @@ fn main() {
121
121
122
122
let dates_by_file = collect_dates ( glob ( & glob_pat) . unwrap ( ) . map ( Result :: unwrap) ) ;
123
123
let dates_by_file: BTreeMap < _ , _ > =
124
- filter_dates ( current_month, dates_by_file. into_iter ( ) ) . collect ( ) ;
124
+ filter_dates ( current_month, 6 , dates_by_file. into_iter ( ) ) . collect ( ) ;
125
125
126
126
if dates_by_file. is_empty ( ) {
127
127
println ! ( "empty" ) ;
@@ -167,8 +167,14 @@ mod tests {
167
167
168
168
#[ test]
169
169
fn test_months_since ( ) {
170
- let date1 = Date { year : 2020 , month : 3 } ;
171
- let date2 = Date { year : 2021 , month : 1 } ;
170
+ let date1 = Date {
171
+ year : 2020 ,
172
+ month : 3 ,
173
+ } ;
174
+ let date2 = Date {
175
+ year : 2021 ,
176
+ month : 1 ,
177
+ } ;
172
178
assert_eq ! ( date2. months_since( date1) , Some ( 10 ) ) ;
173
179
}
174
180
0 commit comments