Method: Doing::ChronifyString#expand_date_tags
- Defined in:
- lib/doing/chronify/string.rb
#expand_date_tags(additional_tags = nil) ⇒ Object
Convert (chronify) natural language dates within configured date tags (tags whose value is expected to be a date). Modifies string in place.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/doing/chronify/string.rb', line 130 def ( = nil) iso_rx = /\d{4}-\d\d-\d\d \d\d:\d\d/ = [ 'start(?:ed)?', 'beg[ia]n', 'done', 'finished', 'completed?', 'waiting', 'defer(?:red)?' ] if = = .split(/ *, */) if .is_a?(String) .map! do |tag| tag.sub(/^@/, '').gsub(/\((?!\?:)(.*?)\)/, '(?:\1)').strip end .concat().uniq! end done_rx = /(?<=^| )@(?<tag>#{.join('|')})\((?<date>.*?)\)/i gsub!(done_rx) do m = Regexp.last_match t = m['tag'] d = m['date'] future = t =~ /^(done|complete)/ ? false : true parsed_date = d =~ iso_rx ? Time.parse(d) : d.chronify(guess: :begin, future: future) parsed_date.nil? ? m[0] : "@#{t}(#{parsed_date.strftime('%F %R')})" end end |