Sha256: 16020a8d2430c8c586b614bbf79325a1709e0dd523621730bf15640ef0eb3757

Contents?: true

Size: 560 Bytes

Versions: 3

Compression:

Stored size: 560 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, ::Time.zone.name || "UTC")
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
administrate-1.0.0.beta3 lib/administrate/field/date_time.rb
administrate-1.0.0.beta2 lib/administrate/field/date_time.rb
administrate-1.0.0.beta1 lib/administrate/field/date_time.rb