Sha256: 2c9a941812c0663a92b0377e3adea3407707ff9fc3c3b4328359d81675721489

Contents?: true

Size: 1.38 KB

Versions: 1

Compression:

Stored size: 1.38 KB

Contents

#==============================================================================#
# $Id: datetime.rb 22 2007-08-15 12:34:58Z yuyakato $
#==============================================================================#

require "kagemusha/date"
require "kagemusha/time"

#==============================================================================#

class Kagemusha #:nodoc:
  class DateTime #:nodoc:
    def initialize(mock1, mock2)
      @mock1, @mock2 = mock1, mock2
    end

    def self.at(time_or_year, mon = 1, mday = 1, hour = 0, min = 0, sec = 0)
      case time_or_year
      when ::Time
        time = time_or_year
        date = ::Date.new(time.year, time.mon, time.mday)
      when ::Date
        date = time_or_year
        time = ::Time.local(date.year, date.mon, date.mday)
      when ::Integer
        time = ::Time.local(time_or_year, mon, mday, hour, min, sec)
        date = ::Date.new(time_or_year, mon, mday)
      else raise(ArgumentError, "?") # FIXME: message
      end

      datemusha = Kagemusha::Date.on(date)
      timemusha = Kagemusha::Time.at(time)
    
      return self.new(datemusha, timemusha)
    end

    def swap
      @mock1.swap {
        @mock2.swap {
          return yield
        }
      }
    end
  end
end

#==============================================================================#
#==============================================================================#

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kagemusha-0.0.1 lib/kagemusha/datetime.rb