lecture-attendance-manager/app/helpers/application_helper.rb
Joshua Coles a0918ce011 Add total lecture time and improve time representation
In the attendance tracker view, the total times for preparation, in lecture, and review have been humanized for better readability. Also, total time spent on lectures for each week has been included for a quicker overview. A helper method 'humanise_duration' has been added in application helper to convert time into a more readable format. Changes have been done in 'lecture' model for calculation of total time.
2023-10-06 22:38:48 +01:00

20 lines
465 B
Ruby

module ApplicationHelper
def humanise_duration(duration)
raise ArgumentError, "Duration must be a number" unless duration.is_a? ActiveSupport::Duration
seconds = duration.in_seconds
minutes = seconds / 60
hours = minutes / 60
remaining_minutes = minutes % 60
if hours > 0
"#{hours.floor}h #{remaining_minutes.floor}m"
elsif minutes > 0
"#{remaining_minutes.floor} minutes"
else
"#{seconds}s"
end
end
end