require "attentive/entities/core/time/duration" require "date" require "time" Attentive::Entity.define "core.time", "noon", "midnight", %q{(?:(?\d\d?):(?\d\d)\s*(?pm?))}, %q{(?:(?\d\d?)\s*(?:am?|(?pm?)))}, %q{(?:(?\d\d?):(?\d\d))} do |match| minutes = 0 if match.matched?("hours") hours = match["hours"].to_i hours += 12 if match.matched?("pm") minutes = match["minutes"].to_i if match.matched?("minutes") else case match.to_s when "noon" then hours = 12 when "midnight" then hours = 0 else nomatch! end end nomatch! if hours < 0 || hours > 24 nomatch! if minutes < 0 || minutes > 60 today = Date.today; Time.new(today.year, today.month, today.day, hours, minutes) end