Sha256: 6162fec09e4d4f7009fdcbe3b64cc74ade24a1d34c7191a855abf491bb52f008

Contents?: true

Size: 998 Bytes

Versions: 74

Compression:

Stored size: 998 Bytes

Contents

#This class helps handeling time-columns in databases.
class Knj::Db::Dbtime
  #These variables return information about the object.
  attr_reader :hours, :mins, :secs, :total_secs
  
  #Initializes the object from arguments useually given by Knj::Datarow.
  def initialize(args)
    args = {:time => args} if args.is_a?(String)
    
    raise "Invalid arguments given." if !args.is_a?(Hash)
    raise "No time given." if !args[:time]
    raise "Invalid time given." if !args[:time].is_a?(String)
    
    match = args[:time].match(/^(\d+):(\d+):(\d+)$/)
    raise "Could not understand time format." if !match
    
    @hours = match[1].to_i
    @mins = match[2].to_i
    @secs = match[3].to_i
    
    @total_secs = @hours * 3600
    @total_secs += @mins * 60
    @total_secs += @secs
  end
  
  #Returns the total amount of hours.
  def hours_total
    return (@total_secs.to_f / 3600)
  end
  
  #Return the total amount of minutes.
  def mins_total
    return (@total_secs.to_f / 60)
  end
end

Version data entries

74 entries across 74 versions & 1 rubygems

Version Path
knjrbfw-0.0.110 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.109 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.108 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.107 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.105 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.104 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.103 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.102 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.101 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.100 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.99 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.98 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.97 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.96 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.95 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.94 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.93 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.92 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.91 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.90 lib/knj/knjdb/dbtime.rb