File tree Expand file tree Collapse file tree 2 files changed +18
-7
lines changed Expand file tree Collapse file tree 2 files changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -16,8 +16,20 @@ impl Merger {
1616 Merger { state }
1717 }
1818
19- fn merge_single ( & mut self , single : ParseState ) -> Result < ( ) > {
20- self . state = single;
19+ fn merge_timeline ( & mut self , timeline : & Timeline ) -> Result < ( ) > {
20+ for contribution in & timeline. contributions {
21+ let date = contribution. date . clone ( ) ;
22+ let date = self . state . parse_date ( & date) ?;
23+ let count = contribution. count ;
24+
25+ if let Some ( date) = date {
26+ // Kinda ineffective to call these update functions in a loop
27+ for _ in 0 ..count {
28+ self . state . update_years ( date) ;
29+ self . state . update_days ( date) ;
30+ }
31+ }
32+ }
2133 Ok ( ( ) )
2234 }
2335
@@ -26,8 +38,7 @@ impl Merger {
2638 /// the individual results.
2739 pub fn merge ( & mut self , timelines : & [ Timeline ] ) -> Result < Timeline > {
2840 for timeline in timelines {
29- let single = ParseState :: try_from ( timeline. clone ( ) ) ?;
30- self . merge_single ( single) ?;
41+ self . merge_timeline ( timeline) ?
3142 }
3243 Ok ( Timeline :: try_from ( & self . state ) ?)
3344 }
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ pub struct ParseState {
1313
1414impl ParseState {
1515 /// Add a single day to the map of years
16- fn update_years ( & mut self , date : NaiveDate ) {
16+ pub fn update_years ( & mut self , date : NaiveDate ) {
1717 let y = date. year ( ) ;
1818 let mut year = self . years_map . entry ( y) . or_insert ( Year {
1919 year : y. to_string ( ) ,
@@ -32,11 +32,11 @@ impl ParseState {
3232 }
3333
3434 /// Add a single day to the map of days
35- fn update_days ( & mut self , date : NaiveDate ) {
35+ pub fn update_days ( & mut self , date : NaiveDate ) {
3636 * self . days . entry ( date) . or_insert ( 0 ) += 1 ;
3737 }
3838
39- fn parse_date ( & self , line : & str ) -> Result < Option < NaiveDate > > {
39+ pub fn parse_date ( & self , line : & str ) -> Result < Option < NaiveDate > > {
4040 if line. trim ( ) . is_empty ( ) {
4141 // Empty lines are allowed, but skipped
4242 return Ok ( None ) ;
You can’t perform that action at this time.
0 commit comments