Class: Oletime::Time

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

Overview

Holds time value and converts to and from ole float value

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(year = nil, month = nil, day = nil, hour = nil, minute = nil, second = nil, utc_offset = nil) ⇒ Time

Returns a new instance of Time.



7
8
9
10
11
12
13
14
# File 'lib/oletime.rb', line 7

def initialize(year = nil, month = nil, day = nil, hour = nil, minute = nil,
               second = nil, utc_offset = nil)
  if year
    @time = ::Time.new(year, month, day, hour, minute, second, utc_offset)
  else
    @time = ::Time.new.utc
  end
end

Instance Attribute Details

#timeObject

Returns the value of attribute time.



6
7
8
# File 'lib/oletime.rb', line 6

def time
  @time
end

Class Method Details

.from_ole(value) ⇒ Object



16
17
18
19
20
# File 'lib/oletime.rb', line 16

def self.from_ole(value)
  new(::Time.now.year).tap do |t|
    t.time = ::Time.at((value - 25_569) * 86_400).utc
  end
end

Instance Method Details

#to_oleObject



22
23
24
# File 'lib/oletime.rb', line 22

def to_ole
  (@time.to_f / 86_400) + 25_569
end

#to_sObject



26
27
28
# File 'lib/oletime.rb', line 26

def to_s
  @time.to_s
end