Back to our code

The first part of the process we need to tackle is parsing the user-provided string into something we can use programmatically. If you were to search for a parser generator, you would find a myriad of options, with tools such as Antlr and JavaCC showing up near the top. It's tempting to turn to one of these tools, but our purposes here are pretty simple, and the grammar is not all that complex. Our functional requirements include:

  • We want to be able to add/subtract time to/from a date or a time
  • We want to be able to subtract one date or time from another to get the difference between the two
  • We want to be able to convert a time from one timezone to another

For something as simple as this, a parser is far too expensive, ...

Get Java 9: Building Robust Modular Applications now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.