Class: Time

Inherits:
Object
  • Object
show all
Defined in:
lib/winft/time.rb

Overview

Extend Time functionality

Constant Summary collapse

WINFT_MULTIPLIER =

Multiplier from milliseconds to 100 nanoseconds

10_000_000.0
WINFT_EPOCH =
"01/01/1601"
WINFT_OFFSET =

Date.parse(WINFT_EPOCH).strftime(‘s’).to_i * WIN32FT_MULTIPLIER

> -11644473600 * 10_000_000.0

> -116444736000000000

-116_444_736_000_000_000

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.at_winft(timestamp) ⇒ Time

parse windows FILETIME

Examples:

Convert WINFT to Time

Time.at_winft(133999948130000000) #=> 2025-08-18 08:46:53 -0400

Parameters:

  • the number of 100-nanosecond intervals since Windows epoch.

Returns:

  • the corresponding local time.



38
39
40
# File 'lib/winft/time.rb', line 38

def self.at_winft(timestamp)
  at((timestamp.to_i + WINFT_OFFSET) / WINFT_MULTIPLIER)
end

Instance Method Details

#to_winftInteger

A Windows file time is a 64-bit value that represents the number of 100-nanosecond intervals that have elapsed since 12:00 midnight, January 1, 1601 A.D. (C.E.) Coordinated Universal Time (UTC). Windows uses a file time to record when an application creates, accesses, or writes to a file.

convert Time to windows FILETIME integer

Examples:

Convert Time to WINFT

now = Time.now #=> 2025-08-18 08:49:51.671107 -0400
now.to_winft #=> 133999949910000000

# And to convert it back...
Time.at_winft(133999949910000000) #=> 2025-08-18 08:49:51 -0400

Returns:

  • the number of 100-nanosecond intervals since Windows epoch.



28
29
30
# File 'lib/winft/time.rb', line 28

def to_winft
  ((to_i * WINFT_MULTIPLIER) - WINFT_OFFSET).to_i
end