diff options
| author | Zack Hobson | 2009-07-30 10:30:59 -0700 | 
|---|---|---|
| committer | Zack Hobson | 2009-07-30 10:30:59 -0700 | 
| commit | 31a3a51bf078cb771dbdf44985a1f4e9121ff5c4 (patch) | |
| tree | eb75f8d9153b6dbc853a9c3b9f62677824c162e4 | |
| parent | 711945bc67f2787e2d2d06b75989eadb503ae810 (diff) | |
| download | hcl-31a3a51bf078cb771dbdf44985a1f4e9121ff5c4.tar.bz2 | |
Always display hours as HH:MM, closes #22.
| -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 | 
