Sha256: 26d1440109ce012284c90a2755077cc8cac148396540c9b98923943ce4a4f89c

Contents?: true

Size: 1.86 KB

Versions: 8

Compression:

Stored size: 1.86 KB

Contents

class Time < `Date`
  include Comparable

  def self.at(seconds, frac = 0)
    `new Date(seconds * 1000 + frac)`
  end

  def self.new(year, month, day, hour, minute, second, millisecond)
    %x{
      switch (arguments.length) {
        case 1:
          return new Date(year);
        case 2:
          return new Date(year, month - 1);
        case 3:
          return new Date(year, month - 1, day);
        case 4:
          return new Date(year, month - 1, day, hour);
        case 5:
          return new Date(year, month - 1, day, hour, minute);
        case 6:
          return new Date(year, month - 1, day, hour, minute, second);
        case 7:
          return new Date(year, month - 1, day, hour, minute, second, millisecond);
        default:
          return new Date();
      }
    }
  end

  def self.now
    `new Date()`
  end

  def +(other)
    Time.allocate(self.to_f + other.to_f)
  end

  def -(other)
    Time.allocate(self.to_f - other.to_f)
  end

  def <=>(other)
    to_f <=> other.to_f
  end

  alias_native :day, :getDate

  def eql?(other)
    other.is_a?(Time) && (self <=> other).zero?
  end

  def friday?
    `#{self}.getDay() === 5`
  end

  alias_native :hour, :getHours

  alias_native :inspect, :toString

  alias mday day

  alias_native :min, :getMinutes

  def mon
    `#{self}.getMonth() + 1`
  end

  def monday?
    `#{self}.getDay() === 1`
  end

  alias month mon

  def saturday?
    `#{self}.getDay() === 6`
  end

  alias_native :sec, :getSeconds

  def sunday?
    `#{self}.getDay() === 0`
  end

  def thursday?
    `#{self}.getDay() === 4`
  end

  def to_f
    `#{self}.getTime() / 1000`
  end

  def to_i
    `parseInt(#{self}.getTime() / 1000)`
  end

  alias to_s inspect

  def tuesday?
    `#{self}.getDay() === 2`
  end

  alias_native :wday, :getDay

  def wednesday?
    `#{self}.getDay() === 3`
  end

  alias_native :year, :getFullYear
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
opal-0.3.37 lib/assets/javascripts/opal/time.rb
opal-0.3.36 lib/assets/javascripts/opal/time.rb
opal-0.3.35 lib/assets/javascripts/opal/time.rb
opal-0.3.34 lib/assets/javascripts/opal/time.rb
opal-0.3.33 core/time.rb
opal-0.3.32 core/time.rb
opal-0.3.31 core/time.rb
opal-0.3.30 core/time.rb