Module: NginxTail::TimeLocal
- Defined in:
- lib/ntail/time_local.rb
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
:nodoc:
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ntail/time_local.rb', line 6 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 |
Instance Method Details
#to_date ⇒ Object
29 30 31 |
# File 'lib/ntail/time_local.rb', line 29 def to_date self.class.to_date(self.time_local) end |
#to_date_s ⇒ Object
33 34 35 |
# File 'lib/ntail/time_local.rb', line 33 def to_date_s self.class.to_date_s(self.time_local) end |