Sha256: 585fbd5c54619c5828645baa3759319a290254f933bd58f7d46520d4ed29983a

Contents?: true

Size: 542 Bytes

Versions: 2

Compression:

Stored size: 542 Bytes

Contents

require_relative "base"

module Administrate
  module Field
    class DateTime < Base
      def date
        I18n.localize(
          data.in_time_zone(timezone).to_date,
          format: format,
        )
      end

      def datetime
        I18n.localize(
          data.in_time_zone(timezone),
          format: format,
          default: data,
        )
      end

      private

      def format
        options.fetch(:format, :default)
      end

      def timezone
        options.fetch(:timezone, "UTC")
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
semantic-administrate-0.1.1 lib/administrate/field/date_time.rb
administrate-0.9.0 lib/administrate/field/date_time.rb