lib/cureutils/logic/date_logic.rb in cureutils-1.1.0 vs lib/cureutils/logic/date_logic.rb in cureutils-1.1.1

- old
+ new

@@ -1,7 +1,7 @@ # frozen_string_literal: true -# coding: utf-8 + require 'cureutils/logic/base_logic' require 'date' # # Date class supports the precure format @@ -18,25 +18,28 @@ @format = '+%F %H:%M:%S @P' end def opt_date(given_datetime) return if given_datetime.nil? + @opt_date = true @in = [] @in << given_datetime end def opt_file(filename) return if filename.nil? + @opt_file = true source_input(filename) end attr_writer :format def print_results return 1 unless check_opts + @in.each do |line| given_date = line ? natural_lang2time(line) : Time.now updated_fmt = update_fmt(given_date, @format) if given_date @out.puts given_date.strftime(updated_fmt) if updated_fmt end @@ -46,20 +49,21 @@ private def check_opts # Either option must be true, but both must NOT be same. return true unless @opt_date && @opt_file + @err.puts <<-EOS cure date: the options to specify dates for printing are mutually exclusive. EOS false end def validate_date_str(str) Date.parse(str) rescue ArgumentError => e @err.puts "cure date: #{e.message} '#{str.chomp}'" - return false + false end def natural_lang2time(time_str) updated_fmt = time_str.dup updated_fmt.gsub!(/yesterday/, '1 day ago')