Sha256: f76a692f997323b4f96ff4d60376a6f42c55be44138714851cbf7cf0668d1575

Contents?: true

Size: 1.33 KB

Versions: 5

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

require_relative 'time'
require_relative 'time_mneumonic'
require_relative 'time_mneumonics'

module Dsu
  module Support
    module CommandOptions
      module DsuTimes
        include Time
        include TimeMneumonic
        include TimeMneumonics

        # Returns an array of Time objects. The first element is the from time. The second element is the to time.
        # Both arguments are expected to be command options that are time strings, time or relative time mneumonics.
        def dsu_times_from!(from_command_option:, to_command_option:)
          times = begin
            from_time = time_from_mneumonic(command_option: from_command_option) if time_mneumonic?(from_command_option)
            from_time ||= time_from_date_string(command_option: from_command_option)

            to_time = if relative_time_mneumonic?(to_command_option)
              time_from_mneumonic(command_option: to_command_option, relative_time: from_time)
            elsif time_mneumonic?(to_command_option)
              time_from_mneumonic(command_option: to_command_option)
            end
            to_time ||= time_from_date_string(command_option: to_command_option)

            [from_time, to_time].sort
          end

          (times.min.to_date..times.max.to_date).map(&:to_time)
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dsu-1.2.1 lib/dsu/support/command_options/dsu_times.rb
dsu-1.2.0 lib/dsu/support/command_options/dsu_times.rb
dsu-1.1.2 lib/dsu/support/command_options/dsu_times.rb
dsu-1.1.1 lib/dsu/support/command_options/dsu_times.rb
dsu-1.1.0.alpha.2 lib/dsu/support/command_options/dsu_times.rb