Skip to content

Instantly share code, notes, and snippets.

@timothee-alby
Created October 20, 2015 13:59
Show Gist options
  • Save timothee-alby/39765a57d4afa42a141e to your computer and use it in GitHub Desktop.
Save timothee-alby/39765a57d4afa42a141e to your computer and use it in GitHub Desktop.
Programming Challenge - Overleaf - 2015-10-20

Programming challenge

A natural language time parser

You are a developer on a task manager app. Your users can create tasks and those tasks, in particular, have a time and date.

To provide a enhanced experience to your users upon task creation, you want the task date to be a free text field. A user would input strings such as in 2 days, 3 hours ago, tomorrow, on december 5th at noon, and you would save that information as a date object in the system.

Challenge

Parse a user input and return a Date object representing the date / time expressed by the user input.

Example:

Input

tomorrow
in 3 hours
2 weeks ago
last month

(current date: 2015-12-25 14:00:00)

Output

2015-12-26 14:00:00
2015-12-25 17:00:00
2015-12-11 14:00:00
2015-11-25 14:00:00

Solution

We don't expect a complete solution, covering all possible imputs one can imagine. The solution should handle some cases as you see fit, including at least the ones in the previous example input.

You should focus on creating a well-designed solution that could easily be exented to support new inputs.

Language

You can implement the solution in any programming language.

A JS or Ruby solution would be preferable if one of those language is part of your skillset, but you should prefer a language you know well enough, so you can show off your skills :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment