Sha256: f3402467c8966f08756fb8e980e364e0726a0f1c259c184a2c1185db2648b730
Contents?: true
Size: 1.39 KB
Versions: 4
Compression:
Stored size: 1.39 KB
Contents
require 'date' module Roo class Excelx class Cell class Time < Roo::Excelx::Cell::DateTime attr_reader :value, :formula, :format, :cell_value, :coordinate attr_reader_with_default default_type: :time def initialize(value, formula, excelx_type, style, link, base_date, coordinate) # NOTE: Pass all arguments to DateTime super class. super @format = excelx_type.last @datetime = create_datetime(base_date, value) @value = link ? Roo::Link.new(link, value) : (value.to_f * 86_400).round.to_i end def formatted_value formatter = @format.gsub(/#{TIME_FORMATS.keys.join('|')}/, TIME_FORMATS) @datetime.strftime(formatter) end alias_method :to_s, :formatted_value private # def create_datetime(base_date, value) # date = base_date + value.to_f.round(6) # datetime_string = date.strftime('%Y-%m-%d %H:%M:%S.%N') # t = round_datetime(datetime_string) # # ::DateTime.civil(t.year, t.month, t.day, t.hour, t.min, t.sec) # end # def round_datetime(datetime_string) # /(?<yyyy>\d+)-(?<mm>\d+)-(?<dd>\d+) (?<hh>\d+):(?<mi>\d+):(?<ss>\d+.\d+)/ =~ datetime_string # # ::Time.new(yyyy.to_i, mm.to_i, dd.to_i, hh.to_i, mi.to_i, ss.to_r).round(0) # end end end end end
Version data entries
4 entries across 4 versions & 2 rubygems
Version | Path |
---|---|
roo-2.10.1 | lib/roo/excelx/cell/time.rb |
roo-2.10.0 | lib/roo/excelx/cell/time.rb |
roo-2.9.0 | lib/roo/excelx/cell/time.rb |
ruh-roo-3.0.1 | lib/roo/excelx/cell/time.rb |