Sha256: aaf0e121c12cdf62401332186dd703c43df61670fa5fb7de1a9fb2b4dbaada8c

Contents?: true

Size: 950 Bytes

Versions: 23

Compression:

Stored size: 950 Bytes

Contents

# frozen_string_literal: true

# MessagePack extention packer and unpacker for built-in Time class
module MessagePack
  module Time
    # 3-arg Time.at is available Ruby >= 2.5
    TIME_AT_3_AVAILABLE = begin
                            !!::Time.at(0, 0, :nanosecond)
                          rescue ArgumentError
                            false
                          end

    Unpacker = if TIME_AT_3_AVAILABLE
                 lambda do |payload|
                   tv = MessagePack::Timestamp.from_msgpack_ext(payload)
                   ::Time.at(tv.sec, tv.nsec, :nanosecond)
                 end
               else
                 lambda do |payload|
                   tv = MessagePack::Timestamp.from_msgpack_ext(payload)
                   ::Time.at(tv.sec, tv.nsec / 1000.0)
                 end
               end

    Packer = lambda { |time|
      MessagePack::Timestamp.to_msgpack_ext(time.tv_sec, time.tv_nsec)
    }
  end
end

Version data entries

23 entries across 23 versions & 2 rubygems

Version Path
msgpack-1.4.2-java lib/msgpack/time.rb
msgpack-1.4.2 lib/msgpack/time.rb
msgpack-1.4.1-java lib/msgpack/time.rb
msgpack-1.4.0-java lib/msgpack/time.rb
msgpack-1.4.0.pre1 lib/msgpack/time.rb
msgpack-1.3.3-x64-mingw32 lib/msgpack/time.rb
msgpack-1.3.3-x86-mingw32 lib/msgpack/time.rb
msgpack-1.3.3-java lib/msgpack/time.rb
msgpack-1.3.3 lib/msgpack/time.rb
msgpack-1.3.2-x64-mingw32 lib/msgpack/time.rb
msgpack-1.3.2-x86-mingw32 lib/msgpack/time.rb
msgpack-1.3.2-java lib/msgpack/time.rb
msgpack-1.3.2 lib/msgpack/time.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/msgpack-1.3.1/lib/msgpack/time.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/msgpack-1.3.1/lib/msgpack/time.rb
msgpack-1.3.1-java lib/msgpack/time.rb
msgpack-1.3.1-x64-mingw32 lib/msgpack/time.rb
msgpack-1.3.1-x86-mingw32 lib/msgpack/time.rb
msgpack-1.3.1 lib/msgpack/time.rb
msgpack-1.3.0-x64-mingw32 lib/msgpack/time.rb