Module: HCl::Utility
Instance Method Summary collapse
-
#as_hours(hours) ⇒ String
Convert from decimal to a string of the form HH:MM.
-
#time2float(time_string) ⇒ #to_f
Convert from a time span in hour or decimal format to a float.
Instance Method Details
#as_hours(hours) ⇒ String
Convert from decimal to a string of the form HH:MM.
7 8 9 10 |
# File 'lib/hcl/utility.rb', line 7 def as_hours hours minutes = hours.to_f * 60.0 sprintf "%d:%02d", (minutes / 60).to_i, (minutes % 60).to_i end |
#time2float(time_string) ⇒ #to_f
Convert from a time span in hour or decimal format to a float.
16 17 18 19 20 21 22 23 |
# File 'lib/hcl/utility.rb', line 16 def time2float time_string if time_string =~ /:/ hours, minutes = time_string.split(':') hours.to_f + (minutes.to_f / 60.0) else time_string.to_f end end |