class MicroManager::CLI::RelativeDate
Public Class Methods
date_offset(num, modifier)
click to toggle source
# File lib/cli/relative_date.rb, line 21 def self.date_offset(num, modifier) modifier_days = { "day" => 1, "week" => 7, "month" => 30 } num.to_i * modifier_days[modifier] end
parse(string, *args)
click to toggle source
# File lib/cli/relative_date.rb, line 6 def self.parse(string, *args) date = parse_relative_date(string) return date if date Date.parse(string, *args) end
parse_relative_date(string)
click to toggle source
# File lib/cli/relative_date.rb, line 13 def self.parse_relative_date(string) regex = /(?<n>\d+)-(?<modifier>day|week|month)/ matches = string.match(regex) return unless matches Date.today + date_offset(matches[:n], matches[:modifier]) end