Sha256: b613455b61f78576f1de4ce5f2cd55047bd216c144d8ab585213775ba8b3851c

Contents?: true

Size: 600 Bytes

Versions: 13

Compression:

Stored size: 600 Bytes

Contents

# frozen_string_literals: true

module Lumberjack
  class Formatter
    # Format a Date, Time, or DateTime object. If you don't specify a format in the constructor,
    # it will use the ISO-8601 format.
    class DateTimeFormatter
      attr_reader :format

      def initialize(format = nil)
        @format = format.dup.to_s.freeze unless format.nil?
      end

      def call(obj)
        if @format && obj.respond_to?(:strftime)
          obj.strftime(@format)
        elsif obj.respond_to?(:iso8601)
          obj.iso8601
        else
          obj.to_s
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 3 rubygems

Version Path
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/lumberjack-1.2.8/lib/lumberjack/formatter/date_time_formatter.rb
qiita_org-0.1.35 gems/ruby/2.7.0/gems/lumberjack-1.2.8/lib/lumberjack/formatter/date_time_formatter.rb
qiita_org-0.1.34 gems/ruby/2.7.0/gems/lumberjack-1.2.8/lib/lumberjack/formatter/date_time_formatter.rb
qiita_org-0.1.33 gems/ruby/2.7.0/gems/lumberjack-1.2.8/lib/lumberjack/formatter/date_time_formatter.rb
qiita_org-0.1.32 gems/ruby/2.7.0/gems/lumberjack-1.2.8/lib/lumberjack/formatter/date_time_formatter.rb
qiita_org-0.1.31 gems/ruby/2.7.0/gems/lumberjack-1.2.8/lib/lumberjack/formatter/date_time_formatter.rb
qiita_org-0.1.30 gems/ruby/2.7.0/gems/lumberjack-1.2.8/lib/lumberjack/formatter/date_time_formatter.rb
qiita_org-0.1.29 gems/ruby/2.7.0/gems/lumberjack-1.2.8/lib/lumberjack/formatter/date_time_formatter.rb
qiita_org-0.1.28 gems/ruby/2.7.0/gems/lumberjack-1.2.8/lib/lumberjack/formatter/date_time_formatter.rb
qiita_org-0.1.27 gems/ruby/2.7.0/gems/lumberjack-1.2.8/lib/lumberjack/formatter/date_time_formatter.rb
qiita_org-0.1.26 gems/ruby/2.7.0/gems/lumberjack-1.2.8/lib/lumberjack/formatter/date_time_formatter.rb
qiita_org-0.1.25 gems/ruby/2.7.0/gems/lumberjack-1.2.8/lib/lumberjack/formatter/date_time_formatter.rb
lumberjack-1.2.8 lib/lumberjack/formatter/date_time_formatter.rb