Sha256: 4e16b1285846c78d6b873cbc9dad23a0dd91479e5813e43fcb4c390555ba9832

Contents?: true

Size: 625 Bytes

Versions: 13

Compression:

Stored size: 625 Bytes

Contents

class String

  # Form can be either :utc (default) or :local.
  def to_time(form = :utc)
    return nil if self.blank?
    Timeliness::Parser.parse(self, :datetime, :zone => form)
  end

  def to_date
    return nil if self.blank?
    values = Timeliness::Parser._parse(self, :date).map { |arg| arg || 0 }
    ::Date.new(*values[0..2])
  end

  def to_datetime
    return nil if self.blank?
    values = Timeliness::Parser._parse(self, :datetime).map { |arg| arg || 0 }
    values[7] = values[7]/24.hours.to_f if values[7] != 0
    values[5] += Rational(values.delete_at(6), 1000000)
    ::DateTime.civil(*values)
  end
end

Version data entries

13 entries across 13 versions & 3 rubygems

Version Path
timeliness-0.4.3 lib/timeliness/core_ext/string.rb
timeliness-0.4.2 lib/timeliness/core_ext/string.rb
timeliness-0.4.1 lib/timeliness/core_ext/string.rb
timeliness-0.4.0 lib/timeliness/core_ext/string.rb
timeliness-0.3.10 lib/timeliness/core_ext/string.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/timeliness-0.3.8/lib/timeliness/core_ext/string.rb
timeliness-0.3.8 lib/timeliness/core_ext/string.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/timeliness-0.3.7/lib/timeliness/core_ext/string.rb
timeliness-0.3.7 lib/timeliness/core_ext/string.rb
timeliness-0.3.6 lib/timeliness/core_ext/string.rb
timeliness-0.3.5 lib/timeliness/core_ext/string.rb
timeliness-0.3.4 lib/timeliness/core_ext/string.rb
timeliness-0.3.3 lib/timeliness/core_ext/string.rb