package com.jonnyware.timetracker;

import org.joda.time.Duration;
import org.joda.time.Interval;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Collection;
import java.util.Map;

public class Main {
    public static void main(String[] args) throws FileNotFoundException {
        File file = new File(args[0]);
        YearParser parser = new YearParser(new FileInputStream(file));
        System.out.println("Year: " + parser.getYear());
        System.out.println("===========");

        Collection<Interval> entries = parser.listTimeEntries();
        IntervalGroupBy groupBy = new IntervalGroupBy(entries);

        for (Map.Entry<Integer, Collection<Interval>> week : groupBy.weekOfYear().entrySet()) {
            Duration d = new Duration(0);
            for (Interval interval : week.getValue()) {
                d = d.plus(interval.toDuration());
            }


            System.out.println("Week " + week.getKey() + ":\t" + d.getStandardHours() + "h");
        }
    }
}

@@ -528,19 +528,21 @@
 ln(%22
-===========
+-------------
 %22);%0A
@@ -668,24 +668,66 @@
 (entries);%0A%0A
+        Duration total = new Duration(0);%0A
         for 
@@ -831,17 +831,28 @@
 uration 
-d
+totalPerWeek
  = new D
@@ -939,13 +939,94 @@
     
-d = d
+totalPerWeek = totalPerWeek.plus(interval.toDuration());%0A                total = total
 .plu
@@ -1132,13 +1132,25 @@
 %22:%5Ct
+ 
 %22 + 
-d
+totalPerWeek
 .get
@@ -1183,16 +1183,135 @@
       %7D%0A
+        System.out.println(%22-------------%22);%0A        System.out.println(%22Total:%5Ct %22 + total.getStandardHours() + %22h%22);%0A
     %7D%0A%7D%0A

Include the total hours.