class Pagy::Calendar::Unit

def page_at(time, **opts)

and returns the closest page to the passed time argument (first or last page)
In case of out of range time, the :fit_time option avoids the outOfRangeError
The page that includes time
def page_at(time, **opts)
  fit_time  = time
  fit_final = @final - 1
  unless time.between?(@initial, fit_final)
    raise OutOfRangeError.new(self, :time, "between #{@initial} and #{fit_final}", time) unless opts[:fit_time]
    if time < @final
      fit_time = @initial
      ordinal  = 'first'
    else
      fit_time = fit_final
      ordinal  = 'last'
    end
    warn "Pagy::Calendar#page_at: Rescued #{time} out of range by returning the #{ordinal} page."
  end
  offset = page_offset_at(fit_time)   # offset starts from 0
  @order == :asc ? offset + 1 : @last - offset
end