osem-fcy/app/helpers/date_time_helper.rb
luzpaz 7d9739349b Fix various typos
Fixes user-facing and non-user-facing typos

Found via `codespell -S "./vendor" -L ontext,rememberable,ridiculus,varius`
2025-10-15 11:15:47 +00:00

40 lines
812 B
Ruby

# frozen_string_literal: true
module DateTimeHelper
##
# Includes functions related to date or time manipulations
##
##
# Gets an EventType object, and returns its length in timestamp format (HH:MM)
# ====Gets
# * +Integer+ -> 30
# ====Returns
# * +String+ -> "00:30"
def length_timestamp(length)
[length / 60, length % 60].map { |t| t.to_s.rjust(2, '0') }.join(':')
end
##
# Gets a datetime object
# ====Returns
# * +String+ -> formatted datetime object
def format_datetime(obj)
return unless obj
obj.strftime('%Y-%m-%d %H:%M')
end
def show_time(length)
return '0 h 0 min' if length.blank?
h, min = length.divmod(60)
if h == 0
"#{min.round} min"
elsif min == 0
"#{h} h"
else
"#{h} h #{min.round} min"
end
end
end