Sha256: ff7c62d0ee330849f1b79bc4baa335db9db8a42a82004a07ea115dad32b997de

Contents?: true

Size: 1.46 KB

Versions: 18

Compression:

Stored size: 1.46 KB

Contents

module DBI
    #
    # Represents a Time
    #
    # DEPRECATED: Please use a regular Time or DateTime object.
   class Time
      attr_accessor :hour, :minute, :second

      private
      # DBI::Time.new(hour = 0, minute = 0, second = 0)
      # DBI::Time.new(Time)
      #
      # Creates and returns a new DBI::Time object.  Unlike the Time object
      # in the standard library, accepts an hour, minute and second, or a
      # Time object.
      def initialize(hour=0, minute=0, second=0)
         case hour
            when ::Time
               @hour, @minute, @second = hour.hour, hour.min, hour.sec
               @original_time = hour
            else
               @hour, @minute, @second = hour, minute, second
         end
      end

      public
      
      deprecate :initialize, :public

      alias :min :minute
      alias :min= :minute=
      alias :sec :second
      alias :sec= :second=

      # Returns a new Time object based on the hour, minute and second, using
      # the current year, month and day.  If a Time object was passed to the
      # constructor, returns that object instead.
      def to_time
         if @original_time
            @original_time
         else
            t = ::Time.now
            ::Time.local(t.year, t.month, t.day, @hour, @minute, @second)
         end
      end

      # Returns a DBI::Time object as a string in HH:MM:SS format.
      def to_s
         sprintf("%02d:%02d:%02d", @hour, @minute, @second)
      end
   end
end

Version data entries

18 entries across 18 versions & 3 rubygems

Version Path
ydbi-0.6.0 lib/dbi/utils/time.rb
ydbi-0.5.9 lib/dbi/utils/time.rb
ydbi-0.5.8 lib/dbi/utils/time.rb
ydbi-0.5.7 lib/dbi/utils/time.rb
ydbi-0.5.6 lib/dbi/utils/time.rb
ydbi-0.5.5 lib/dbi/utils/time.rb
ydbi-0.5.4 lib/dbi/utils/time.rb
ydbi-0.5.3 lib/dbi/utils/time.rb
ydbi-0.5.2 lib/dbi/utils/time.rb
ydbi-0.5.1 lib/dbi/utils/time.rb
ydbi-0.5.0 lib/dbi/utils/time.rb
rails-dbi-0.1.0 lib/dbi/utils/time.rb
dbi-0.4.5 lib/dbi/utils/time.rb
dbi-0.4.4 lib/dbi/utils/time.rb
dbi-0.4.3 lib/dbi/utils/time.rb
dbi-0.4.2 lib/dbi/utils/time.rb
dbi-0.4.1 lib/dbi/utils/time.rb
dbi-0.4.0 lib/dbi/utils/time.rb