Class: DateTime

Inherits:
Date
  • Object
show all
Defined in:
lib/glimmer-dsl-opal/ext/date.rb

Instance Method Summary collapse

Methods inherited from Date

#to_datetime

Constructor Details

#initialize(*args, &block) ⇒ DateTime

Returns a new instance of DateTime.


5
6
7
8
9
10
11
12
13
14
# File 'lib/glimmer-dsl-opal/ext/date.rb', line 5

def initialize(*args, &block)
  @time = Time.new(*args, &block)
  methods_to_exclude = [:to_date, :to_time, :==, :eql?, :class] + Object.new.methods
  methods_to_define = @time.methods - methods_to_exclude
  methods_to_define.each do |method_name|
    singleton_class.define_method(method_name) do |*args, &block|
      @time.send(method_name, *args, &block)
    end
  end
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?


24
25
26
27
28
29
30
31
32
# File 'lib/glimmer-dsl-opal/ext/date.rb', line 24

def ==(other)
  return false if other.class != self.class
  year == other.year and
    month == other.month and
    day == other.day and
    hour == other.hour and
    min == other.min and
    sec == other.sec
end

#to_dateObject


16
17
18
# File 'lib/glimmer-dsl-opal/ext/date.rb', line 16

def to_date
  @time.to_date
end

#to_timeObject


20
21
22
# File 'lib/glimmer-dsl-opal/ext/date.rb', line 20

def to_time
  @time
end