diff options
| -rw-r--r-- | lib/hcl.rb | 10 | ||||
| -rw-r--r-- | lib/hcl/day_entry.rb | 13 | 
2 files changed, 14 insertions, 9 deletions
@@ -213,17 +213,11 @@ EOM      total_hours = 0.0      DayEntry.all(date).each do |day|        running = day.running? ? '(running) ' : '' -      puts "\t#{as_hours day.hours}\t#{running}#{day.project} #{day.notes}"[0..78] +      puts "\t#{day.formatted_hours}\t#{running}#{day.project} #{day.notes}"[0..78]        total_hours = total_hours + day.hours.to_f      end      puts "\t" + '-' * 13 -    puts "\t#{as_hours total_hours}\ttotal" -  end - -  # Convert from decimal to a string of the form HH:MM. -  def as_hours hours -    minutes = hours.to_f * 60.0 -    sprintf "%d:%02d", (minutes / 60).to_i, (minutes % 60).to_i +    puts "\t#{HCl::DayEntry.as_hours total_hours}\ttotal"    end  end diff --git a/lib/hcl/day_entry.rb b/lib/hcl/day_entry.rb index a79ea2c..6e5f7bc 100644 --- a/lib/hcl/day_entry.rb +++ b/lib/hcl/day_entry.rb @@ -9,7 +9,7 @@ class HCl      end      def to_s -      "#{client} #{project} #{task} (#{hours})" +      "#{client} #{project} #{task} (#{formatted_hours})"      end      def self.from_xml xml @@ -49,5 +49,16 @@ class HCl        DayEntry.get("daily/timer/#{id}")        self      end + +    # Returns the hours formatted as "HH:MM" +    def formatted_hours +      self.class.as_hours hours +    end + +    # Convert from decimal to a string of the form HH:MM. +    def self.as_hours hours +      minutes = hours.to_f * 60.0 +      sprintf "%d:%02d", (minutes / 60).to_i, (minutes % 60).to_i +    end    end  end  | 
