Class: Ole::Types::FileTime

### Home Classes Methods

### In Files

- lib/ole/types/base.rb

### Parent

DateTime

### Methods

- ::dump
- ::from_time
- ::load
- ::new
- ::now
- #inspect

### Files

- ChangeLog
- README

### Class/Module Index

Quicksearch

- Ole
- Ole::IOMode
- Ole::IOMode::Constants
- Ole::Storage
- Ole::Storage::AllocationTable
- Ole::Storage::AllocationTable::Big
- Ole::Storage::AllocationTable::Small
- Ole::Storage::DirClass
- Ole::Storage::DirClass::Dir
- Ole::Storage::Dirent
- Ole::Storage::FileClass
- Ole::Storage::FileClass::Stat
- Ole::Storage::Header
- Ole::Storage::MetaData
- Ole::Storage::RangesIOMigrateable
- Ole::Storage::RangesIOResizeable
- Ole::Types
- Ole::Types::Clsid
- Ole::Types::Data
- Ole::Types::FileTime
- Ole::Types::Lpstr
- Ole::Types::Lpwstr
- Ole::Types::PropertySet
- Ole::Types::PropertySet::Constants
- Ole::Types::PropertySet::Section
- Ole::Types::Variant
- Ole::Types::Variant::Constants
- RangesIO

No matching classes.

# Ole::Types::FileTime

for VT_FILETIME

### Constants

EPOCH
SIZE

### Public Class Methods

dump(time) click to toggle source

`time` should be able to be either a Time, Date, or DateTime.

    # File lib/ole/types/base.rb, line 140
    def self.dump time
      return 0.chr * SIZE unless time
      # convert whatever is given to be a datetime, to handle the large range
      case time
      when Date # this includes DateTime & FileTime
      when Time
        time = from_time time
      else
        raise ArgumentError, 'unknown time argument - %p' % [time]
      end
      # round to milliseconds (throwing away nanosecond precision) to
      # compensate for using Float-based DateTime
      nanoseconds = ((time - EPOCH).to_f * 864000000).round * 1000
      high, low = nanoseconds.divmod 1 << 32
      [low, high].pack 'V2'
    end

from_time(time) click to toggle source

    # File lib/ole/types/base.rb, line 110
    def self.from_time time
      new(*time.to_a[0, 6].reverse)
    end

load(str) click to toggle source

Create a `DateTime` object from a struct `FILETIME` (msdn2.microsoft.com/en-us/library/ms724284.aspx).

Converts `str` to two 32 bit time values, comprising the high and low 32 bits of the 100's of nanoseconds since 1st january 1601 (Epoch).

    # File lib/ole/types/base.rb, line 127
    def self.load str
      low, high = str.to_s.unpack 'V2'
      # we ignore these, without even warning about it
      return nil if low == 0 and high == 0
      # the + 0.00001 here stinks a bit...
      seconds = (high * (1 << 32) + low) / 1e7 + 0.00001
      obj = EPOCH + seconds / 86400 rescue return
      # work around home_run not preserving derived class
      obj = new! obj.jd + obj.day_fraction - 0.5, 0, ITALY unless FileTime === obj
      obj
    end

new(year, month, day, hour=0, min=0, sec=0) click to toggle source

DateTime.new is slow... faster version for FileTime

    # File lib/ole/types/base.rb, line 93
    def self.new year, month, day, hour=0, min=0, sec=0
      # DateTime will remove leap and leap-leap seconds
      sec = 59 if sec > 59
      if month <= 2
        month += 12
        year  -= 1
      end
      y   = year + 4800
      m   = month - 3
      jd  = day + (153 * m + 2).div(5) + 365 * y + y.div(4) - y.div(100) + y.div(400) - 32045
      fr  = hour / 24.0 + min / 1440.0 + sec / 86400.0
      # new! was actually new0 in older versions of ruby (<=1.8.4?)
      # see issue #4.
      msg = respond_to?(:new!) ? :new! : :new0
      send msg, jd + fr - 0.5, 0, ITALY
    end

now() click to toggle source

    # File lib/ole/types/base.rb, line 114
    def self.now
      from_time Time.now
    end

### Public Instance Methods

inspect() click to toggle source

    # File lib/ole/types/base.rb, line 157
    def inspect
      "#<#{self.class} #{to_s}>"
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.