Sha256: 5ec35769bb55e678275f61616e8aa64dd45d02aa58ceb1f1e431334a4efdbab3

Contents?: true

Size: 1.06 KB

Versions: 16

Compression:

Stored size: 1.06 KB

Contents

# See Pagy::Countless API documentation: https://ddnexus.github.io/pagy/docs/api/calendar
# frozen_string_literal: true

class Pagy # :nodoc:
  class Calendar # :nodoc:
    # Day unit subclass
    class Day < Unit
      DEFAULT = { size:   31,   # rubocop:disable Style/MutableConstant
                  ends: false,
                  order:  :asc,
                  format: '%d' }

      protected

      # Setup the calendar variables
      def assign_unit_vars
        super
        @initial = @starting.beginning_of_day
        @final   = @ending.tomorrow.beginning_of_day
        @last    = page_offset(@initial, @final)
        @from    = starting_time_for(@page)
        @to      = @from.tomorrow
      end

      # Starting time for the page
      def starting_time_for(page)
        @initial.days_since(time_offset_for(page))
      end

      def page_offset_at(time)
        page_offset(@initial, time.beginning_of_day)
      end

      private

      def page_offset(time_a, time_b)  # remove in 6.0
        (time_b.time - time_a.time).to_i / 1.day
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
pagy-9.3.0 lib/pagy/calendar/day.rb
pagy-9.2.2 lib/pagy/calendar/day.rb
pagy-9.2.1 lib/pagy/calendar/day.rb
pagy-9.2.0 lib/pagy/calendar/day.rb
pagy-9.1.1 lib/pagy/calendar/day.rb
pagy-9.1.0 lib/pagy/calendar/day.rb
pagy-9.0.9 lib/pagy/calendar/day.rb
pagy-9.0.8 lib/pagy/calendar/day.rb
pagy-9.0.7 lib/pagy/calendar/day.rb
pagy-9.0.6 lib/pagy/calendar/day.rb
pagy-9.0.5 lib/pagy/calendar/day.rb
pagy-9.0.4 lib/pagy/calendar/day.rb
pagy-9.0.3 lib/pagy/calendar/day.rb
pagy-9.0.2 lib/pagy/calendar/day.rb
pagy-9.0.1 lib/pagy/calendar/day.rb
pagy-9.0.0 lib/pagy/calendar/day.rb