Sha256: 9870800ae3fd36b2c6267d75bb9a971c955326655cad0154900965b541ca85f0
Contents?: true
Size: 1008 Bytes
Versions: 1
Compression:
Stored size: 1008 Bytes
Contents
require 'date' module NginxTail module TimeLocal def self.included(base) # :nodoc: base.class_eval do # >> DateTime.strptime("13/Apr/2010:04:45:51 +0100", '%d/%b/%Y:%T %z').to_s # => "2010-04-13T04:45:51+01:00" # >> DateTime.strptime("13/Apr/2010:04:45:51 +0100", '%d/%b/%Y:%H:%M:%S %z').to_s # => "2010-04-13T04:45:51+01:00" # >> _ def self.to_date(time_local) DateTime.strptime(time_local, '%d/%b/%Y:%T %z') end def self.to_date_s(time_local, format = "%Y-%m-%d %X") self.to_date(time_local).strftime(format) end # this ensures the below module methods actually make sense... raise "Class #{base.name} should implement instance method 'time_local'" unless base.instance_methods.map(&:to_s).include? 'time_local' end end def to_date self.class.to_date(self.time_local) end def to_date_s self.class.to_date_s(self.time_local) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ntail-1.3.2 | lib/ntail/time_local.rb |