Sha256: a1f498b30f736db69732ea0647f3d6b711a123729efd8ce01e06c497d34733da

Contents?: true

Size: 943 Bytes

Versions: 44

Compression:

Stored size: 943 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 the organization's time zone
      #
      # &action - a block of code to be wrapped around the time zone
      #
      # Returns nothing.
      def use_organization_time_zone(&action)
        Time.use_zone(organization_time_zone, &action)
      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

44 entries across 44 versions & 1 rubygems

Version Path
decidim-core-0.27.6 app/controllers/concerns/decidim/use_organization_time_zone.rb
decidim-core-0.26.10 app/controllers/concerns/decidim/use_organization_time_zone.rb
decidim-core-0.26.9 app/controllers/concerns/decidim/use_organization_time_zone.rb
decidim-core-0.27.5 app/controllers/concerns/decidim/use_organization_time_zone.rb
decidim-core-0.26.8 app/controllers/concerns/decidim/use_organization_time_zone.rb
decidim-core-0.27.4 app/controllers/concerns/decidim/use_organization_time_zone.rb
decidim-core-0.27.3 app/controllers/concerns/decidim/use_organization_time_zone.rb
decidim-core-0.26.7 app/controllers/concerns/decidim/use_organization_time_zone.rb
decidim-core-0.26.5 app/controllers/concerns/decidim/use_organization_time_zone.rb
decidim-core-0.27.2 app/controllers/concerns/decidim/use_organization_time_zone.rb
decidim-core-0.27.1 app/controllers/concerns/decidim/use_organization_time_zone.rb
decidim-core-0.26.4 app/controllers/concerns/decidim/use_organization_time_zone.rb
decidim-core-0.27.0 app/controllers/concerns/decidim/use_organization_time_zone.rb
decidim-core-0.26.3 app/controllers/concerns/decidim/use_organization_time_zone.rb
decidim-core-0.27.0.rc2 app/controllers/concerns/decidim/use_organization_time_zone.rb
decidim-core-0.27.0.rc1 app/controllers/concerns/decidim/use_organization_time_zone.rb
decidim-core-0.26.2 app/controllers/concerns/decidim/use_organization_time_zone.rb
decidim-core-0.26.1 app/controllers/concerns/decidim/use_organization_time_zone.rb
decidim-core-0.26.0 app/controllers/concerns/decidim/use_organization_time_zone.rb
decidim-core-0.26.0.rc2 app/controllers/concerns/decidim/use_organization_time_zone.rb