You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: documents_helper.rb
    path of file: ./repos/ekylibre/app/helpers/backend
    
    the code of the file until where you have to start completion: module Backend
  module DocumentsHelper
    def document_period_crit(*args)
      arg_value = args.shift
      name = arg_value[:name] || :period
      label_name = arg_value[:label]
      options = (args[-1].is_a?(Hash) ? args.delete_at(-1) : {})

      # list of all options
      list = []
      list << ['', 'all']

      # Add year and month period
      first_date = Document.order(name).first[name] || Time.now - 2.years
      period = (first_date.year..Time.now.year).map { |p| p }

      period.reverse_each do |year|
        full_year = Time.new(year)
        list << [year, "#{full_year.to_date}_#{full_year.end_of_year.to_date}"]
        date = period.index(year) == 0 ? first_date.beginning_
    
    def document_period_crit(*args)
      arg_value = args.shift
      name = arg_value[:name] || :period
      label_name = arg_value[:label]
      options = (args[-1].is_a?(Hash) ? args.delete_at(-1) : {})

      # list of all options
      list = []
      list << ['', 'all']

      # Add year and month period
      first_date = Document.order(name).first[name] || Time.now - 2.years
      period = (first_date.year..Time.now.year).map { |p| p }

      period.reverse_each do |year|
        full_year = Time.new(year)
        list << [year, "#{full_year.to_date}_#{full_year.end_of_year.to_date}"]
        date = period.index(year) == 0 ? first_date.beginning_of_month : full_year
        list2 = []
        while date < full_year.end_of_year && date < Time.zone.today
          list2 << [l(date.to_date, format: :month), "#{date.to_date}_#{date.end_of_month.to_date}"]
          date += 1.month
        end
        list += list2.reverse
      end