<p>This question is the other side of the question asking, "<a href="https://stackoverflow.com/questions/11/how-do-i-calculate-relative-time">How do I calculate relative time?</a>".</p>

<p>Given some human input for a relative time, how can you parse it?  By default you would offset from <code>DateTime.Now()</code>, but could optionally offset from another <code>DateTime</code>.</p>

<p>(Prefer answers in C#)</p>

<p>Example input:</p>

<ul>
<li>"in 20 minutes"</li>
<li>"5 hours ago"</li>
<li>"3h 2m"</li>
<li>"next week"</li>
</ul>

<p><strong>Edit:</strong>  Let's suppose we can define some limits on the input.  This sort of code would be a useful thing to have out on the web.</p>

That's building a DSL (Domain specific language) for date handling. I don't know if somebody has done one for .NET but the construction of a DSL is fairly straightforward:
Define the language precisely, which input forms you will accept and what will you do with ambiguities
Construct the grammar for the language
Build the finite state machine that parses your language into an actionable AST
You can do all that by yourself (with the help of
the Dragon Book
, for instance) or with the help of tools to the effect, as shown in this
link
.
Just by thinking hard about the possibilities you have a good chance, with the help of good UI examples, of covering more than half of the actual inputs your application will receive. If you aim to accept everything a human could possibly type, you can record the input determined as ambiguous and then add them to the grammar, whenever they can be interpreted, as there are things that will be inherently ambiguous.