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.
This commit is contained in:
2023-10-06 22:38:48 +01:00
parent e6dcd8e6ec
commit a0918ce011
3 changed files with 46 additions and 11 deletions
+17
View File
@@ -1,2 +1,19 @@
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