Sha256: c10a92e74bef716a5589c7400dd04da8f41ba5075d8288c2f6bdb8eb53148661
Contents?: true
Size: 1.25 KB
Versions: 1
Compression:
Stored size: 1.25 KB
Contents
require 'date' require 'time' class DateTime < Date def initialize(*args, &block) @time = Time.new(*args, &block) methods_to_exclude = [:to_date, :to_time, :==, :eql?, :class] methods_to_define = @time.methods - methods_to_exclude methods_to_define.each do |method| singleton_class.define_method(method) do |*args, &block| @time.send(method, *args, &block) end end end def to_date @time.to_date end def to_time @time end 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 alias eql? == end class Date def to_datetime # TODO support timezone DateTime.new(year, month, day, hour, min, sec) end end class Time class << self alias new_original new def new(*args) if args.size >= 7 puts "Dropped timezone #{args[6]} from Time.new(#{args.map(&:to_s)}) constructor arguments since Opal does not support it!" args = args[0...6] end new_original(*args) end end def to_datetime # TODO support timezone DateTime.new(year, month, day, hour, min, sec) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
glimmer-dsl-opal-0.7.0 | lib/glimmer-dsl-opal/ext/date.rb |