Browse Source

fix calc hours from timestamps

main
Christoph Marzell 1 week ago
parent
commit
b375516006
  1. 4
      app/controllers/entries_controller.rb
  2. 10
      app/models/entry.rb

4
app/controllers/entries_controller.rb

@ -251,7 +251,9 @@ class EntriesController < ApplicationController
:distance_km, :distance_km,
:beschreibung, :beschreibung,
:kosten, :kosten,
:zaehlt_als_fortbildung
:zaehlt_als_fortbildung,
:start_time,
:end_time
) )
end end

10
app/models/entry.rb

@ -137,11 +137,17 @@ class Entry < ApplicationRecord
private private
def normalize_time def normalize_time
if (hours.to_i + minutes.to_i) == 0 && start_time.present? && end_time.present?
total_minutes_worked = total_minutes_including_break
if total_minutes_worked
self.hours = total_minutes_worked / 60
self.minutes = total_minutes_worked % 60
end
else
self.minutes ||= 0 self.minutes ||= 0
self.hours ||= 0 self.hours ||= 0
self.hours += minutes / 60 self.hours += minutes / 60
self.minutes = minutes % 60 self.minutes = minutes % 60
end end
end end
end
Loading…
Cancel
Save