Permalink
Browse files

Horas sempre contabilizadas somente até o Time.now

  • Loading branch information...
bernardo committed Dec 2, 2011
1 parent f7c4d57 commit e8db2d5a14c6d5a499b9dea22306bdceafb0fac0
Showing with 5 additions and 2 deletions.
  1. +2 −2 app/controllers/stats_controller.rb
  2. +3 −0 app/models/user.rb
@@ -34,9 +34,9 @@ def index
{:name => u.name, :data => hours}
end
- @pie_series = @users.map { |u|
+ @pie_series = @users.map do |u|
{:y => u.hours_worked(start..finish).round, :name => u.name}
- }
+ end
end
View
@@ -28,6 +28,9 @@ def hours_today
end
def hours_worked(datetime_range)
+ #don't consider future time
+ datetime_range = datetime_range.begin..(datetime_range.end < Time.now ? datetime_range.end : Time.now)
+
punches_in_range = self.punches.where('punched_at >= ? and punched_at <= ?', datetime_range.begin, datetime_range.end).order('punched_at ASC').all
return 0 if punches_in_range.empty?

0 comments on commit e8db2d5

Please sign in to comment.