Class: Time

Inherits:
Object
  • Object
show all
Defined in:
lib/rcs-common/time.rb

Overview

Helper methods for decoding Windows FILETIME structs.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_filetime(high, low) ⇒ Object

Create a time object from the FILETIME format, a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC).



17
18
19
20
21
22
23
# File 'lib/rcs-common/time.rb', line 17

def self.from_filetime(high, low)
  wtime = Float((high << 32) | low)
  unix_hundreds_nanosec = wtime - 116_444_736_000_000_000
  seconds_with_frac = unix_hundreds_nanosec / 10_000_000
  
  return Time.at(seconds_with_frac).getutc
end

Instance Method Details

#to_filetimeObject

Convert the time to the FILETIME format, a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC).



8
9
10
11
12
13
# File 'lib/rcs-common/time.rb', line 8

def to_filetime
  t = self.to_f + 11644473600
  t *= 10000000
  t = t.to_i
  return (t & 0xFFFFFFFF), (t & 0xFFFFFFFF00000000) >> 32
end