Sha256: 4e3ea261e6d12216fd97d5e58938fa0643b82f8b29503c1291331b144f4caee8

Contents?: true

Size: 928 Bytes

Versions: 10

Compression:

Stored size: 928 Bytes

Contents

# frozen_string_literal: true

require "active_support/concern"

module Decidim
  # When included in a controller this concern will wrap any action
  # in the context of the organization configured time zone
  module UseOrganizationTimeZone
    extend ActiveSupport::Concern

    included do
      around_action :use_organization_time_zone
      helper_method :organization_time_zone

      # Executes a block of code in the context of the organization's time zone
      #
      # &action - a block of code to be wrapped around the time zone
      #
      # Returns nothing.
      def use_organization_time_zone(&)
        Time.use_zone(organization_time_zone, &)
      end

      # The current time zone from the organization. Available as a helper for the views.
      #
      # Returns a String.
      def organization_time_zone
        @organization_time_zone ||= current_organization&.time_zone
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
decidim-core-0.30.0.rc3 app/controllers/concerns/decidim/use_organization_time_zone.rb
decidim-core-0.30.0.rc2 app/controllers/concerns/decidim/use_organization_time_zone.rb
decidim-core-0.30.0.rc1 app/controllers/concerns/decidim/use_organization_time_zone.rb
decidim-core-0.29.2 app/controllers/concerns/decidim/use_organization_time_zone.rb
decidim-core-0.29.1 app/controllers/concerns/decidim/use_organization_time_zone.rb
decidim-core-0.29.0 app/controllers/concerns/decidim/use_organization_time_zone.rb
decidim-core-0.29.0.rc4 app/controllers/concerns/decidim/use_organization_time_zone.rb
decidim-core-0.29.0.rc3 app/controllers/concerns/decidim/use_organization_time_zone.rb
decidim-core-0.29.0.rc2 app/controllers/concerns/decidim/use_organization_time_zone.rb
decidim-core-0.29.0.rc1 app/controllers/concerns/decidim/use_organization_time_zone.rb