Sha256: 65ac8379087d567b475f8a2f767c74b6885bba0d336587e5d5534884c805fd2d
Contents?: true
Size: 1.09 KB
Versions: 6
Compression:
Stored size: 1.09 KB
Contents
# frozen_string_literal: true module Dsu module Support module TimesSortable module_function def times_sort(times:, entries_display_order: nil) entries_display_order ||= 'asc' unless %w[asc desc].include? entries_display_order raise "Invalid entries_display_order: #{entries_display_order}" end if entries_display_order == 'asc' times.sort # sort ascending elsif entries_display_order == 'desc' times.sort.reverse # sort descending end end # TODO: Do we have something else we can use here? def times_for(times:) start_date = times.max return times unless start_date.monday? || start_date.on_weekend? # If the start_date is a weekend or a Monday, then we need to include # start_date along with all the dates up to and including the previous # Monday. (0..3).filter_map do |num| time = start_date - num.days next unless time == start_date || time.on_weekend? || time.friday? time end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems