Sha256: a135d3089ca1893b3c49f90a5c9d2e71f3ad5e9ac088ca78af04ddab9fca0584

Contents?: true

Size: 641 Bytes

Versions: 1

Compression:

Stored size: 641 Bytes

Contents

require 'time'

module Grpc
  module ORiN3
    module Provider
      class DateTimeConverter
        TICKS_PER_SECOND = 10_000_000
        EPOCH = Time.utc(1, 1, 1, 0, 0, 0)

        def self.to_int64(time)
          utc_time = time.utc
          ticks = ((utc_time - EPOCH) * TICKS_PER_SECOND).to_i
          return ticks & 0x3FFFFFFFFFFFFFFF
        end
  
        def self.from_int64(int64)
          filter = 0x3FFFFFFFFFFFFFFF
          datetime_num = int64 & filter
          seconds_since_windows_epoch = datetime_num.to_f / TICKS_PER_SECOND
          return EPOCH + seconds_since_windows_epoch
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
grpc-orin3-provider-1.0.0 lib/grpc/orin3/provider/date_time_converter.rb