Method: OLEStorageLite#localDate2OLE

Defined in:
lib/WriteExcel/storage_lite.rb

#localDate2OLE(localtime) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/WriteExcel/storage_lite.rb', line 21

def localDate2OLE(localtime)
  return "\x00" * 8 unless localtime

  # Convert from localtime (actually gmtime) to seconds.
  args = localtime.reverse
  args[0] += 1900   # year
  args[1] += 1      # month
  time = Time.gm(*args)
  
  # Add the number of seconds between the 1601 and 1970 epochs.
  time = time.to_i + 11644473600

  # The FILETIME seconds are in units of 100 nanoseconds.
  nanoseconds = time * 1E7

  # Pack the total nanoseconds into 64 bits...
  hi, lo = nanoseconds.divmod 1 << 32

  oletime = [lo, hi].pack("VV")
  return oletime
end