Sha256: cd741b10bd76a308e281801d4470f6cfe6058e238e51056e22c937ed6731e569

Contents?: true

Size: 920 Bytes

Versions: 63

Compression:

Stored size: 920 Bytes

Contents

module CF
  typedef :pointer, :cfdateref
  typedef :double, :cfabsolutetime

  attach_function :CFDateCreate, [:pointer, :cfabsolutetime], :cfdateref
  attach_function :CFDateGetAbsoluteTime, [:cfdateref], :cfabsolutetime
  attach_variable :kCFAbsoluteTimeIntervalSince1970, :double

  # Wrapper for CFDateRef
  #
  #
  class Date < Base
    register_type 'CFDate'

    # constructs a CF::Date from a ruby time
    #
    # @param [Time] time
    # @return [CF::Date] a CF::Date instance that will be released on garbage collection
    def self.from_time(time)
      new(CF.CFDateCreate(nil, time.to_f - CF.kCFAbsoluteTimeIntervalSince1970)).release_on_gc
    end

    # returns a ruby Time instance corresponding to the same point in time
    #
    # @return [Time]
    def to_time
      Time.at(CF.CFDateGetAbsoluteTime(self) + CF.kCFAbsoluteTimeIntervalSince1970)
    end

    alias_method :to_ruby, :to_time
  end
end

Version data entries

63 entries across 20 versions & 3 rubygems

Version Path
og-corefoundation-0.2.3 lib/corefoundation/date.rb
og-corefoundation-0.2.2 lib/corefoundation/date.rb
og-corefoundation-0.2.1 lib/corefoundation/date.rb
yakg-0.1.11 vendor/gems/ruby/2.0.0/gems/corefoundation-0.2.0/lib/corefoundation/date.rb
yakg-0.1.11 vendor/gems/ruby/2.2.0/gems/corefoundation-0.2.0/lib/corefoundation/date.rb
yakg-0.1.11 vendor/gems/ruby/2.1.0/gems/corefoundation-0.2.0/lib/corefoundation/date.rb
yakg-0.1.11 vendor/gems/ruby/1.8/gems/corefoundation-0.2.0/lib/corefoundation/date.rb
yakg-0.1.11 vendor/gems/ruby/1.9.1/gems/corefoundation-0.2.0/lib/corefoundation/date.rb
yakg-0.1.10 vendor/gems/ruby/2.2.0/gems/corefoundation-0.2.0/lib/corefoundation/date.rb
yakg-0.1.10 vendor/gems/ruby/2.0.0/gems/corefoundation-0.2.0/lib/corefoundation/date.rb
yakg-0.1.10 vendor/gems/ruby/2.1.0/gems/corefoundation-0.2.0/lib/corefoundation/date.rb
yakg-0.1.10 vendor/gems/ruby/1.8/gems/corefoundation-0.2.0/lib/corefoundation/date.rb
yakg-0.1.10 vendor/gems/ruby/1.9.1/gems/corefoundation-0.2.0/lib/corefoundation/date.rb
yakg-0.1.9 vendor/gems/ruby/2.0.0/gems/corefoundation-0.2.0/lib/corefoundation/date.rb
yakg-0.1.9 vendor/gems/ruby/2.1.0/gems/corefoundation-0.2.0/lib/corefoundation/date.rb
yakg-0.1.9 vendor/gems/ruby/1.8/gems/corefoundation-0.2.0/lib/corefoundation/date.rb
yakg-0.1.9 vendor/gems/ruby/2.2.0/gems/corefoundation-0.2.0/lib/corefoundation/date.rb
yakg-0.1.9 vendor/gems/ruby/1.9.1/gems/corefoundation-0.2.0/lib/corefoundation/date.rb
yakg-0.1.8 vendor/gems/ruby/2.1.0/gems/corefoundation-0.2.0/lib/corefoundation/date.rb
yakg-0.1.8 vendor/gems/ruby/1.9.1/gems/corefoundation-0.2.0/lib/corefoundation/date.rb